From 71d4fc8d76ebd539440aff5cfc873be9b50f202b Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Tue, 30 Oct 2018 17:29:30 -0400 Subject: Googletest export [Fuchsia] Create the death test child process in a separate job. This creates a separate job to launch the child process into. The exception port can then be attached to the new job before the child process is launched, solving a potential race condition. PiperOrigin-RevId: 219366531 --- googletest/src/gtest-death-test.cc | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/googletest/src/gtest-death-test.cc b/googletest/src/gtest-death-test.cc index c4f6270..febd5b5 100644 --- a/googletest/src/gtest-death-test.cc +++ b/googletest/src/gtest-death-test.cc @@ -70,6 +70,7 @@ # include # include # include +# include # include # endif // GTEST_OS_FUCHSIA @@ -1023,19 +1024,29 @@ DeathTest::TestRole FuchsiaDeathTest::AssumeRole() { add_stderr_action->fd.local_fd = stderr_producer_fd; add_stderr_action->fd.target_fd = STDERR_FILENO; - // Spawn the child process. - status = fdio_spawn_etc( - ZX_HANDLE_INVALID, FDIO_SPAWN_CLONE_ALL, args.Argv()[0], args.Argv(), - nullptr, 2, spawn_actions, child_process_.reset_and_get_address(), - nullptr); + // Create a child job. + zx_handle_t child_job = ZX_HANDLE_INVALID; + status = zx_job_create(zx_job_default(), 0, & child_job); + GTEST_DEATH_TEST_CHECK_(status == ZX_OK); + zx_policy_basic_t policy; + policy.condition = ZX_POL_NEW_ANY; + policy.policy = ZX_POL_ACTION_ALLOW; + status = zx_job_set_policy( + child_job, ZX_JOB_POL_RELATIVE, ZX_JOB_POL_BASIC, &policy, 1); GTEST_DEATH_TEST_CHECK_(status == ZX_OK); - // Create an exception port and attach it to the |child_process_|, to allow + // Create an exception port and attach it to the |child_job|, to allow // us to suppress the system default exception handler from firing. status = zx::port::create(0, &port_); GTEST_DEATH_TEST_CHECK_(status == ZX_OK); - status = child_process_.bind_exception_port( - port_, 0 /* key */, 0 /*options */); + status = zx_task_bind_exception_port( + child_job, port_.get(), 0 /* key */, 0 /*options */); + GTEST_DEATH_TEST_CHECK_(status == ZX_OK); + + // Spawn the child process. + status = fdio_spawn_etc( + child_job, FDIO_SPAWN_CLONE_ALL, args.Argv()[0], args.Argv(), nullptr, + 2, spawn_actions, child_process_.reset_and_get_address(), nullptr); GTEST_DEATH_TEST_CHECK_(status == ZX_OK); set_spawned(true); -- cgit v0.12