From 0a6edf3ca757a742f2adeb4623f625c6118e0fd7 Mon Sep 17 00:00:00 2001 From: Fabrice de Gans-Riberi Date: Wed, 30 May 2018 18:16:44 -0700 Subject: [PATCH 1/2] Remvoe launchpad dependency from Fuchsia. --- googletest/src/gtest-death-test.cc | 45 ++++++++++++++++-------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/googletest/src/gtest-death-test.cc b/googletest/src/gtest-death-test.cc index b3979924..03adccef 100644 --- a/googletest/src/gtest-death-test.cc +++ b/googletest/src/gtest-death-test.cc @@ -64,7 +64,8 @@ # if GTEST_OS_FUCHSIA # include -# include +# include +# include # include # endif // GTEST_OS_FUCHSIA @@ -926,29 +927,31 @@ DeathTest::TestRole FuchsiaDeathTest::AssumeRole() { args.AddArgument(filter_flag.c_str()); args.AddArgument(internal_flag.c_str()); - // Build the child process launcher. - zx_status_t status; - launchpad_t* lp; - status = launchpad_create(ZX_HANDLE_INVALID, args.Argv()[0], &lp); - GTEST_DEATH_TEST_CHECK_(status == ZX_OK); - // Build the pipe for communication with the child. - int read_fd; - status = launchpad_add_pipe(lp, &read_fd, kFuchsiaReadPipeFd); - GTEST_DEATH_TEST_CHECK_(status == ZX_OK); - set_read_fd(read_fd); + zx_status_t status; + zx_handle_t child_pipe_handle; + uint32_t type; + status = fdio_pipe_half(&child_pipe_handle, &type); + GTEST_DEATH_TEST_CHECK_(status >= 0); + set_read_fd(status); - // Set the command line arguments. - status = launchpad_load_from_file(lp, args.Argv()[0]); - GTEST_DEATH_TEST_CHECK_(status == ZX_OK); - status = launchpad_set_args(lp, args.size(), args.Argv()); - GTEST_DEATH_TEST_CHECK_(status == ZX_OK); + // Set the pipe handle for the child. + fdio_spawn_action_t add_handle_action = { + .action = FDIO_SPAWN_ACTION_ADD_HANDLE, + .h = { + .id = PA_HND(type, kFuchsiaReadPipeFd), + .handle = child_pipe_handle + } + }; - // Clone all the things (environment, stdio, namespace, ...). - launchpad_clone(lp, LP_CLONE_ALL); - - // Launch the child process. - status = launchpad_go(lp, &child_process_, nullptr); + // Spawn the child process. + char err_msg[255]; + status = fdio_spawn_etc(ZX_HANDLE_INVALID, FDIO_SPAWN_CLONE_ALL, + args.Argv()[0], args.Argv(), nullptr, 1, + &add_handle_action, &child_process_, err_msg); + if (status != ZX_OK) { + GTEST_LOG_(ERROR) << err_msg; + } GTEST_DEATH_TEST_CHECK_(status == ZX_OK); set_spawned(true); From 93e267a999a3528b21ce0e51412e889f87288f24 Mon Sep 17 00:00:00 2001 From: Fabrice de Gans-Riberi Date: Thu, 31 May 2018 11:21:01 -0700 Subject: [PATCH 2/2] Clean up --- googletest/src/gtest-death-test.cc | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/googletest/src/gtest-death-test.cc b/googletest/src/gtest-death-test.cc index 03adccef..e5b4e09e 100644 --- a/googletest/src/gtest-death-test.cc +++ b/googletest/src/gtest-death-test.cc @@ -945,13 +945,9 @@ DeathTest::TestRole FuchsiaDeathTest::AssumeRole() { }; // Spawn the child process. - char err_msg[255]; status = fdio_spawn_etc(ZX_HANDLE_INVALID, FDIO_SPAWN_CLONE_ALL, args.Argv()[0], args.Argv(), nullptr, 1, - &add_handle_action, &child_process_, err_msg); - if (status != ZX_OK) { - GTEST_LOG_(ERROR) << err_msg; - } + &add_handle_action, &child_process_, nullptr); GTEST_DEATH_TEST_CHECK_(status == ZX_OK); set_spawned(true);