summaryrefslogtreecommitdiffstats
path: root/googletest
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2018-10-30 17:29:30 -0400
committerGennadiy Civil <misterg@google.com>2018-10-30 21:20:50 -0400
commit71d4fc8d76ebd539440aff5cfc873be9b50f202b (patch)
treef8836c071a40dcc65188dc5aca034fbc97bf643f /googletest
parente857f9cdd998136b9aad634272301f5b2d0476ea (diff)
downloadgoogletest-71d4fc8d76ebd539440aff5cfc873be9b50f202b.tar.gz
googletest-71d4fc8d76ebd539440aff5cfc873be9b50f202b.zip
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
Diffstat (limited to 'googletest')
-rw-r--r--googletest/src/gtest-death-test.cc27
1 files changed, 19 insertions, 8 deletions
diff --git a/googletest/src/gtest-death-test.cc b/googletest/src/gtest-death-test.cc
index c4f6270a..febd5b5d 100644
--- a/googletest/src/gtest-death-test.cc
+++ b/googletest/src/gtest-death-test.cc
@@ -70,6 +70,7 @@
# include <lib/zx/process.h>
# include <zircon/processargs.h>
# include <zircon/syscalls.h>
+# include <zircon/syscalls/policy.h>
# include <zircon/syscalls/port.h>
# 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);
OpenPOWER on IntegriCloud