Test that all threads in thread group terminate

Tests that when one thread calls `_exit()`, all threads in the
thread group are terminated.

PiperOrigin-RevId: 433052210
This commit is contained in:
gVisor bot
2022-03-07 15:17:07 -08:00
parent 4c7dba96f8
commit 261f9c7e6c
2 changed files with 41 additions and 1 deletions
+3 -1
View File
@@ -749,10 +749,12 @@ cc_binary(
linkstatic = 1,
deps = [
"//test/util:file_descriptor",
"@com_google_absl//absl/flags:flag",
"@com_google_absl//absl/time",
gtest,
"//test/util:test_main",
"//test/util:multiprocess_util",
"//test/util:test_util",
"//test/util:thread_util",
"//test/util:time_util",
],
)
+38
View File
@@ -16,11 +16,17 @@
#include <unistd.h>
#include "gtest/gtest.h"
#include "absl/flags/flag.h"
#include "absl/time/time.h"
#include "test/util/file_descriptor.h"
#include "test/util/multiprocess_util.h"
#include "test/util/test_util.h"
#include "test/util/thread_util.h"
#include "test/util/time_util.h"
ABSL_FLAG(bool, test_child, false,
"If true, run the ExitAllThreads child workload.");
namespace gvisor {
namespace testing {
@@ -72,7 +78,39 @@ TEST(ExitTest, CloseFds) {
SyscallSucceedsWithValue(0));
}
TEST(ExitTest, ExitAllThreads) {
pid_t child_pid = -1;
int execve_errno = 0;
auto cleanup = ASSERT_NO_ERRNO_AND_VALUE(
ForkAndExec("/proc/self/exe", {"/proc/self/exe", "--test_child"}, {},
nullptr, &child_pid, &execve_errno));
ASSERT_GT(child_pid, 0);
ASSERT_EQ(execve_errno, 0);
int status;
EXPECT_THAT(RetryEINTR(waitpid)(child_pid, &status, 0), SyscallSucceeds());
EXPECT_TRUE(WIFEXITED(status) && WEXITSTATUS(status) == 0) << status;
}
void RunChild() {
ScopedThread t([] { _exit(0); });
t.Join();
// Should not be reached
abort();
}
} // namespace
} // namespace testing
} // namespace gvisor
int main(int argc, char** argv) {
gvisor::testing::TestInit(&argc, &argv);
if (absl::GetFlag(FLAGS_test_child)) {
gvisor::testing::RunChild();
return 1;
}
return gvisor::testing::RunAllTests();
}