Detect failures in forked function

EXPECT*/ASSERT* functions are not async-signal-safe and should not
be called from the function passed to InForkedProcess. However,
these happen accidentally sometimes but do no cause InForkedProcess
to fail.

Detect and notify in such cases.

PiperOrigin-RevId: 353354540
This commit is contained in:
Fabricio Voznika
2021-01-22 18:06:09 -08:00
committed by gVisor bot
parent 99aa5eedcf
commit cac70c65e6
2 changed files with 4 additions and 0 deletions
+1
View File
@@ -172,6 +172,7 @@ cc_library(
":posix_error",
":save_util",
":test_util",
gtest,
"@com_google_absl//absl/strings",
],
)
+3
View File
@@ -154,6 +154,9 @@ PosixErrorOr<int> InForkedProcess(const std::function<void()>& fn) {
pid_t pid = fork();
if (pid == 0) {
fn();
TEST_CHECK_MSG(!::testing::Test::HasFailure(),
"EXPECT*/ASSERT* failed. These are not async-signal-safe "
"and must not be called from fn.");
_exit(0);
}
MaybeSave();