| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "mojo/edk/test/multiprocess_test_helper.h" | 5 #include "mojo/edk/test/multiprocess_test_helper.h" |
| 6 | 6 |
| 7 #include <functional> | 7 #include <functional> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/base_paths.h" | 11 #include "base/base_paths.h" |
| 12 #include "base/base_switches.h" | 12 #include "base/base_switches.h" |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 18 #include "base/path_service.h" | 18 #include "base/path_service.h" |
| 19 #include "base/process/kill.h" | 19 #include "base/process/kill.h" |
| 20 #include "base/process/process_handle.h" | 20 #include "base/process/process_handle.h" |
| 21 #include "base/run_loop.h" | 21 #include "base/run_loop.h" |
| 22 #include "base/strings/stringprintf.h" | 22 #include "base/strings/stringprintf.h" |
| 23 #include "base/task_runner.h" | 23 #include "base/task_runner.h" |
| 24 #include "base/threading/thread_task_runner_handle.h" | 24 #include "base/threading/thread_task_runner_handle.h" |
| 25 #include "build/build_config.h" | 25 #include "build/build_config.h" |
| 26 #include "mojo/edk/embedder/embedder.h" | 26 #include "mojo/edk/embedder/embedder.h" |
| 27 #include "mojo/edk/embedder/named_platform_handle.h" | 27 #include "mojo/edk/embedder/named_platform_handle.h" |
| 28 #include "mojo/edk/embedder/named_platform_handle_utils.h" | 28 #include "mojo/edk/embedder/named_platform_handle_utils.h" |
| 29 #include "mojo/edk/embedder/pending_process_connection.h" |
| 29 #include "mojo/edk/embedder/platform_channel_pair.h" | 30 #include "mojo/edk/embedder/platform_channel_pair.h" |
| 30 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
| 31 | 32 |
| 32 #if defined(OS_WIN) | 33 #if defined(OS_WIN) |
| 33 #include "base/win/windows_version.h" | 34 #include "base/win/windows_version.h" |
| 34 #elif defined(OS_MACOSX) && !defined(OS_IOS) | 35 #elif defined(OS_MACOSX) && !defined(OS_IOS) |
| 35 #include "base/mac/mach_port_broker.h" | 36 #include "base/mac/mach_port_broker.h" |
| 36 #endif | 37 #endif |
| 37 | 38 |
| 38 namespace mojo { | 39 namespace mojo { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 base::FilePath temp_dir; | 108 base::FilePath temp_dir; |
| 108 CHECK(base::PathService::Get(base::DIR_TEMP, &temp_dir)); | 109 CHECK(base::PathService::Get(base::DIR_TEMP, &temp_dir)); |
| 109 named_pipe = NamedPlatformHandle( | 110 named_pipe = NamedPlatformHandle( |
| 110 temp_dir.AppendASCII(GenerateRandomToken()).value()); | 111 temp_dir.AppendASCII(GenerateRandomToken()).value()); |
| 111 #else | 112 #else |
| 112 named_pipe = NamedPlatformHandle(GenerateRandomToken()); | 113 named_pipe = NamedPlatformHandle(GenerateRandomToken()); |
| 113 #endif | 114 #endif |
| 114 command_line.AppendSwitchNative(kMojoNamedPipeName, named_pipe.name); | 115 command_line.AppendSwitchNative(kMojoNamedPipeName, named_pipe.name); |
| 115 } | 116 } |
| 116 | 117 |
| 117 std::string pipe_token = mojo::edk::GenerateRandomToken(); | |
| 118 if (launch_type == LaunchType::CHILD || | |
| 119 launch_type == LaunchType::NAMED_CHILD) | |
| 120 command_line.AppendSwitchASCII(kMojoPrimordialPipeToken, pipe_token); | |
| 121 | |
| 122 if (!switch_string.empty()) { | 118 if (!switch_string.empty()) { |
| 123 CHECK(!command_line.HasSwitch(switch_string)); | 119 CHECK(!command_line.HasSwitch(switch_string)); |
| 124 if (!switch_value.empty()) | 120 if (!switch_value.empty()) |
| 125 command_line.AppendSwitchASCII(switch_string, switch_value); | 121 command_line.AppendSwitchASCII(switch_string, switch_value); |
| 126 else | 122 else |
| 127 command_line.AppendSwitch(switch_string); | 123 command_line.AppendSwitch(switch_string); |
| 128 } | 124 } |
| 129 | 125 |
| 130 base::LaunchOptions options; | 126 base::LaunchOptions options; |
| 131 #if defined(OS_POSIX) | 127 #if defined(OS_POSIX) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 144 // created before the child process is launched; otherwise the server binding | 140 // created before the child process is launched; otherwise the server binding |
| 145 // the pipe path can race with child's connection to the pipe. | 141 // the pipe path can race with child's connection to the pipe. |
| 146 ScopedPlatformHandle server_handle; | 142 ScopedPlatformHandle server_handle; |
| 147 if (launch_type == LaunchType::CHILD || launch_type == LaunchType::PEER) { | 143 if (launch_type == LaunchType::CHILD || launch_type == LaunchType::PEER) { |
| 148 server_handle = channel.PassServerHandle(); | 144 server_handle = channel.PassServerHandle(); |
| 149 } else if (launch_type == LaunchType::NAMED_CHILD || | 145 } else if (launch_type == LaunchType::NAMED_CHILD || |
| 150 launch_type == LaunchType::NAMED_PEER) { | 146 launch_type == LaunchType::NAMED_PEER) { |
| 151 server_handle = CreateServerHandle(named_pipe); | 147 server_handle = CreateServerHandle(named_pipe); |
| 152 } | 148 } |
| 153 | 149 |
| 150 PendingProcessConnection process; |
| 154 ScopedMessagePipeHandle pipe; | 151 ScopedMessagePipeHandle pipe; |
| 155 std::string child_token = mojo::edk::GenerateRandomToken(); | |
| 156 if (launch_type == LaunchType::CHILD || | 152 if (launch_type == LaunchType::CHILD || |
| 157 launch_type == LaunchType::NAMED_CHILD) { | 153 launch_type == LaunchType::NAMED_CHILD) { |
| 158 pipe = CreateParentMessagePipe(pipe_token, child_token); | 154 std::string pipe_token; |
| 155 pipe = process.CreateMessagePipe(&pipe_token); |
| 156 command_line.AppendSwitchASCII(kMojoPrimordialPipeToken, pipe_token); |
| 159 } else if (launch_type == LaunchType::PEER || | 157 } else if (launch_type == LaunchType::PEER || |
| 160 launch_type == LaunchType::NAMED_PEER) { | 158 launch_type == LaunchType::NAMED_PEER) { |
| 161 peer_token_ = mojo::edk::GenerateRandomToken(); | 159 peer_token_ = mojo::edk::GenerateRandomToken(); |
| 162 pipe = ConnectToPeerProcess(std::move(server_handle), peer_token_); | 160 pipe = ConnectToPeerProcess(std::move(server_handle), peer_token_); |
| 163 } | 161 } |
| 164 | 162 |
| 165 test_child_ = | 163 test_child_ = |
| 166 base::SpawnMultiProcessTestChild(test_child_main, command_line, options); | 164 base::SpawnMultiProcessTestChild(test_child_main, command_line, options); |
| 167 if (launch_type == LaunchType::CHILD || launch_type == LaunchType::PEER) | 165 if (launch_type == LaunchType::CHILD || launch_type == LaunchType::PEER) |
| 168 channel.ChildProcessLaunched(); | 166 channel.ChildProcessLaunched(); |
| 169 | 167 |
| 170 if (launch_type == LaunchType::CHILD || | 168 if (launch_type == LaunchType::CHILD || |
| 171 launch_type == LaunchType::NAMED_CHILD) { | 169 launch_type == LaunchType::NAMED_CHILD) { |
| 172 DCHECK(server_handle.is_valid()); | 170 DCHECK(server_handle.is_valid()); |
| 173 ChildProcessLaunched(test_child_.Handle(), std::move(server_handle), | 171 process.Connect(test_child_.Handle(), std::move(server_handle), |
| 174 child_token, process_error_callback_); | 172 process_error_callback_); |
| 175 } | 173 } |
| 176 | 174 |
| 177 CHECK(test_child_.IsValid()); | 175 CHECK(test_child_.IsValid()); |
| 178 return pipe; | 176 return pipe; |
| 179 } | 177 } |
| 180 | 178 |
| 181 int MultiprocessTestHelper::WaitForChildShutdown() { | 179 int MultiprocessTestHelper::WaitForChildShutdown() { |
| 182 CHECK(test_child_.IsValid()); | 180 CHECK(test_child_.IsValid()); |
| 183 | 181 |
| 184 int rv = -1; | 182 int rv = -1; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 ::testing::Test::HasNonfatalFailure()) ? 1 : 0; | 246 ::testing::Test::HasNonfatalFailure()) ? 1 : 0; |
| 249 }); | 247 }); |
| 250 } | 248 } |
| 251 | 249 |
| 252 // static | 250 // static |
| 253 mojo::ScopedMessagePipeHandle MultiprocessTestHelper::primordial_pipe; | 251 mojo::ScopedMessagePipeHandle MultiprocessTestHelper::primordial_pipe; |
| 254 | 252 |
| 255 } // namespace test | 253 } // namespace test |
| 256 } // namespace edk | 254 } // namespace edk |
| 257 } // namespace mojo | 255 } // namespace mojo |
| OLD | NEW |