| 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 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 #else | 139 #else |
| 140 #error "Not supported yet." | 140 #error "Not supported yet." |
| 141 #endif | 141 #endif |
| 142 | 142 |
| 143 ScopedMessagePipeHandle pipe; | 143 ScopedMessagePipeHandle pipe; |
| 144 std::string child_token = mojo::edk::GenerateRandomToken(); | 144 std::string child_token = mojo::edk::GenerateRandomToken(); |
| 145 if (launch_type == LaunchType::CHILD || | 145 if (launch_type == LaunchType::CHILD || |
| 146 launch_type == LaunchType::NAMED_CHILD) { | 146 launch_type == LaunchType::NAMED_CHILD) { |
| 147 pipe = CreateParentMessagePipe(pipe_token, child_token); | 147 pipe = CreateParentMessagePipe(pipe_token, child_token); |
| 148 } else if (launch_type == LaunchType::PEER) { | 148 } else if (launch_type == LaunchType::PEER) { |
| 149 pipe = ConnectToPeerProcess(channel.PassServerHandle()); | 149 peer_token_ = mojo::edk::GenerateRandomToken(); |
| 150 pipe = ConnectToPeerProcess(channel.PassServerHandle(), peer_token_); |
| 150 } else if (launch_type == LaunchType::NAMED_PEER) { | 151 } else if (launch_type == LaunchType::NAMED_PEER) { |
| 151 pipe = ConnectToPeerProcess(CreateServerHandle(named_pipe)); | 152 peer_token_ = mojo::edk::GenerateRandomToken(); |
| 153 pipe = ConnectToPeerProcess(CreateServerHandle(named_pipe), peer_token_); |
| 152 } | 154 } |
| 153 | 155 |
| 154 test_child_ = | 156 test_child_ = |
| 155 base::SpawnMultiProcessTestChild(test_child_main, command_line, options); | 157 base::SpawnMultiProcessTestChild(test_child_main, command_line, options); |
| 156 if (launch_type == LaunchType::CHILD || launch_type == LaunchType::PEER) | 158 if (launch_type == LaunchType::CHILD || launch_type == LaunchType::PEER) |
| 157 channel.ChildProcessLaunched(); | 159 channel.ChildProcessLaunched(); |
| 158 | 160 |
| 159 if (launch_type == LaunchType::CHILD) { | 161 if (launch_type == LaunchType::CHILD) { |
| 160 ChildProcessLaunched(test_child_.Handle(), channel.PassServerHandle(), | 162 ChildProcessLaunched(test_child_.Handle(), channel.PassServerHandle(), |
| 161 child_token, process_error_callback_); | 163 child_token, process_error_callback_); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 177 CHECK(AndroidWaitForChildExitWithTimeout( | 179 CHECK(AndroidWaitForChildExitWithTimeout( |
| 178 test_child_, TestTimeouts::action_timeout(), &rv)); | 180 test_child_, TestTimeouts::action_timeout(), &rv)); |
| 179 #else | 181 #else |
| 180 CHECK( | 182 CHECK( |
| 181 test_child_.WaitForExitWithTimeout(TestTimeouts::action_timeout(), &rv)); | 183 test_child_.WaitForExitWithTimeout(TestTimeouts::action_timeout(), &rv)); |
| 182 #endif | 184 #endif |
| 183 test_child_.Close(); | 185 test_child_.Close(); |
| 184 return rv; | 186 return rv; |
| 185 } | 187 } |
| 186 | 188 |
| 189 void MultiprocessTestHelper::ClosePeerConnection() { |
| 190 DCHECK(!peer_token_.empty()); |
| 191 ::mojo::edk::ClosePeerConnection(peer_token_); |
| 192 peer_token_.clear(); |
| 193 } |
| 194 |
| 187 bool MultiprocessTestHelper::WaitForChildTestShutdown() { | 195 bool MultiprocessTestHelper::WaitForChildTestShutdown() { |
| 188 return WaitForChildShutdown() == 0; | 196 return WaitForChildShutdown() == 0; |
| 189 } | 197 } |
| 190 | 198 |
| 191 // static | 199 // static |
| 192 void MultiprocessTestHelper::ChildSetup() { | 200 void MultiprocessTestHelper::ChildSetup() { |
| 193 CHECK(base::CommandLine::InitializedForCurrentProcess()); | 201 CHECK(base::CommandLine::InitializedForCurrentProcess()); |
| 194 | 202 |
| 195 std::string primordial_pipe_token = | 203 std::string primordial_pipe_token = |
| 196 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 204 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 ::testing::Test::HasNonfatalFailure()) ? 1 : 0; | 246 ::testing::Test::HasNonfatalFailure()) ? 1 : 0; |
| 239 }); | 247 }); |
| 240 } | 248 } |
| 241 | 249 |
| 242 // static | 250 // static |
| 243 mojo::ScopedMessagePipeHandle MultiprocessTestHelper::primordial_pipe; | 251 mojo::ScopedMessagePipeHandle MultiprocessTestHelper::primordial_pipe; |
| 244 | 252 |
| 245 } // namespace test | 253 } // namespace test |
| 246 } // namespace edk | 254 } // namespace edk |
| 247 } // namespace mojo | 255 } // namespace mojo |
| OLD | NEW |