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:
parent
d16e734273
commit
0ccf4bfab5
@ -166,6 +166,12 @@ static void SetArgvFromEnv(absl::string_view envvar, EnvArgv* a) {
|
|||||||
}
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
ParseArgvFromString(str, a);
|
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.
|
AppendToEnvArgv(nullptr, 0, nullptr, 0, a); // add trailing nullptr to *a.
|
||||||
|
@ -127,8 +127,11 @@ TEST(ParseFlagsFromEnv, EnvAndFlag) {
|
|||||||
{"--int_flag=3", "--int_flag=2", "2\n"}, // flag beats environment
|
{"--int_flag=3", "--int_flag=2", "2\n"}, // flag beats environment
|
||||||
};
|
};
|
||||||
for (int i = 0; i != TF_ARRAYSIZE(test); i++) {
|
for (int i = 0; i != TF_ARRAYSIZE(test); i++) {
|
||||||
if (test[i].env != nullptr) {
|
if (test[i].env == nullptr) {
|
||||||
tensorflow::setenv("TF_XLA_FLAGS", test[i].env, true /*overwrite*/);
|
// 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;
|
tensorflow::SubProcess child;
|
||||||
std::vector<string> argv;
|
std::vector<string> argv;
|
||||||
@ -139,10 +142,14 @@ TEST(ParseFlagsFromEnv, EnvAndFlag) {
|
|||||||
}
|
}
|
||||||
child.SetProgram(binary_name, argv);
|
child.SetProgram(binary_name, argv);
|
||||||
child.SetChannelAction(tensorflow::CHAN_STDOUT, tensorflow::ACTION_PIPE);
|
child.SetChannelAction(tensorflow::CHAN_STDOUT, tensorflow::ACTION_PIPE);
|
||||||
|
child.SetChannelAction(tensorflow::CHAN_STDERR, tensorflow::ACTION_PIPE);
|
||||||
CHECK(child.Start()) << "test " << i;
|
CHECK(child.Start()) << "test " << i;
|
||||||
string stdout_str;
|
string stdout_str;
|
||||||
int child_status = child.Communicate(nullptr, &stdout_str, nullptr);
|
string stderr_str;
|
||||||
CHECK_EQ(child_status, 0) << "test " << i;
|
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.
|
// On windows, we get CR characters. Remove them.
|
||||||
stdout_str.erase(std::remove(stdout_str.begin(), stdout_str.end(), '\r'),
|
stdout_str.erase(std::remove(stdout_str.begin(), stdout_str.end(), '\r'),
|
||||||
stdout_str.end());
|
stdout_str.end());
|
||||||
|
Loading…
Reference in New Issue
Block a user