Crash if XLA flags are to be read from a file but we could not open the file

PiperOrigin-RevId: 349601577
Change-Id: Id094dabb1ccb03e633d472bbee9bc1f48604c0ba
This commit is contained in:
Sanjoy Das 2020-12-30 14:19:00 -08:00 committed by TensorFlower Gardener
parent d16e734273
commit 0ccf4bfab5
2 changed files with 17 additions and 4 deletions

View File

@ -166,6 +166,12 @@ static void SetArgvFromEnv(absl::string_view envvar, EnvArgv* a) {
}
fclose(fp);
ParseArgvFromString(str, a);
} else {
LOG(QFATAL)
<< "Could not open file \"" << env
<< "\" to read flags for environment variable \"" << envvar
<< "\". (We assumed \"" << env
<< "\" was a file name because it did not start with a \"--\".)";
}
}
AppendToEnvArgv(nullptr, 0, nullptr, 0, a); // add trailing nullptr to *a.

View File

@ -127,8 +127,11 @@ TEST(ParseFlagsFromEnv, EnvAndFlag) {
{"--int_flag=3", "--int_flag=2", "2\n"}, // flag beats environment
};
for (int i = 0; i != TF_ARRAYSIZE(test); i++) {
if (test[i].env != nullptr) {
tensorflow::setenv("TF_XLA_FLAGS", test[i].env, true /*overwrite*/);
if (test[i].env == nullptr) {
// Might be set from previous tests.
tensorflow::unsetenv("TF_XLA_FLAGS");
} else {
tensorflow::setenv("TF_XLA_FLAGS", test[i].env, /*overwrite=*/true);
}
tensorflow::SubProcess child;
std::vector<string> argv;
@ -139,10 +142,14 @@ TEST(ParseFlagsFromEnv, EnvAndFlag) {
}
child.SetProgram(binary_name, argv);
child.SetChannelAction(tensorflow::CHAN_STDOUT, tensorflow::ACTION_PIPE);
child.SetChannelAction(tensorflow::CHAN_STDERR, tensorflow::ACTION_PIPE);
CHECK(child.Start()) << "test " << i;
string stdout_str;
int child_status = child.Communicate(nullptr, &stdout_str, nullptr);
CHECK_EQ(child_status, 0) << "test " << i;
string stderr_str;
int child_status = child.Communicate(nullptr, &stdout_str, &stderr_str);
CHECK_EQ(child_status, 0) << "test " << i << "\nstdout\n"
<< stdout_str << "\nstderr\n"
<< stderr_str;
// On windows, we get CR characters. Remove them.
stdout_str.erase(std::remove(stdout_str.begin(), stdout_str.end(), '\r'),
stdout_str.end());