| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 ScopedMessagePipeHandle pipe = | 51 ScopedMessagePipeHandle pipe = |
| 52 std::move(MultiprocessTestHelper::primordial_pipe); | 52 std::move(MultiprocessTestHelper::primordial_pipe); |
| 53 return handler(pipe.get().value()); | 53 return handler(pipe.get().value()); |
| 54 } | 54 } |
| 55 | 55 |
| 56 } // namespace | 56 } // namespace |
| 57 | 57 |
| 58 MultiprocessTestHelper::MultiprocessTestHelper() {} | 58 MultiprocessTestHelper::MultiprocessTestHelper() {} |
| 59 | 59 |
| 60 MultiprocessTestHelper::~MultiprocessTestHelper() { | 60 MultiprocessTestHelper::~MultiprocessTestHelper() { |
| 61 CHECK(!test_child_.IsValid()); | 61 CHECK(!test_child_.process.IsValid()); |
| 62 } | 62 } |
| 63 | 63 |
| 64 ScopedMessagePipeHandle MultiprocessTestHelper::StartChild( | 64 ScopedMessagePipeHandle MultiprocessTestHelper::StartChild( |
| 65 const std::string& test_child_name, | 65 const std::string& test_child_name, |
| 66 LaunchType launch_type) { | 66 LaunchType launch_type) { |
| 67 return StartChildWithExtraSwitch(test_child_name, std::string(), | 67 return StartChildWithExtraSwitch(test_child_name, std::string(), |
| 68 std::string(), launch_type); | 68 std::string(), launch_type); |
| 69 } | 69 } |
| 70 | 70 |
| 71 ScopedMessagePipeHandle MultiprocessTestHelper::StartChildWithExtraSwitch( | 71 ScopedMessagePipeHandle MultiprocessTestHelper::StartChildWithExtraSwitch( |
| 72 const std::string& test_child_name, | 72 const std::string& test_child_name, |
| 73 const std::string& switch_string, | 73 const std::string& switch_string, |
| 74 const std::string& switch_value, | 74 const std::string& switch_value, |
| 75 LaunchType launch_type) { | 75 LaunchType launch_type) { |
| 76 CHECK(!test_child_name.empty()); | 76 CHECK(!test_child_name.empty()); |
| 77 CHECK(!test_child_.IsValid()); | 77 CHECK(!test_child_.process.IsValid()); |
| 78 | 78 |
| 79 std::string test_child_main = test_child_name + "TestChildMain"; | 79 std::string test_child_main = test_child_name + "TestChildMain"; |
| 80 | 80 |
| 81 // Manually construct the new child's commandline to avoid copying unwanted | 81 // Manually construct the new child's commandline to avoid copying unwanted |
| 82 // values. | 82 // values. |
| 83 base::CommandLine command_line( | 83 base::CommandLine command_line( |
| 84 base::GetMultiProcessTestChildBaseCommandLine().GetProgram()); | 84 base::GetMultiProcessTestChildBaseCommandLine().GetProgram()); |
| 85 | 85 |
| 86 std::set<std::string> uninherited_args; | 86 std::set<std::string> uninherited_args; |
| 87 uninherited_args.insert("mojo-platform-channel-handle"); | 87 uninherited_args.insert("mojo-platform-channel-handle"); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 } | 161 } |
| 162 | 162 |
| 163 test_child_ = | 163 test_child_ = |
| 164 base::SpawnMultiProcessTestChild(test_child_main, command_line, options); | 164 base::SpawnMultiProcessTestChild(test_child_main, command_line, options); |
| 165 if (launch_type == LaunchType::CHILD || launch_type == LaunchType::PEER) | 165 if (launch_type == LaunchType::CHILD || launch_type == LaunchType::PEER) |
| 166 channel.ChildProcessLaunched(); | 166 channel.ChildProcessLaunched(); |
| 167 | 167 |
| 168 if (launch_type == LaunchType::CHILD || | 168 if (launch_type == LaunchType::CHILD || |
| 169 launch_type == LaunchType::NAMED_CHILD) { | 169 launch_type == LaunchType::NAMED_CHILD) { |
| 170 DCHECK(server_handle.is_valid()); | 170 DCHECK(server_handle.is_valid()); |
| 171 process.Connect(test_child_.Handle(), | 171 process.Connect(test_child_.process.Handle(), |
| 172 ConnectionParams(std::move(server_handle)), | 172 ConnectionParams(std::move(server_handle)), |
| 173 process_error_callback_); | 173 process_error_callback_); |
| 174 } | 174 } |
| 175 | 175 |
| 176 CHECK(test_child_.IsValid()); | 176 CHECK(test_child_.process.IsValid()); |
| 177 return pipe; | 177 return pipe; |
| 178 } | 178 } |
| 179 | 179 |
| 180 int MultiprocessTestHelper::WaitForChildShutdown() { | 180 int MultiprocessTestHelper::WaitForChildShutdown() { |
| 181 CHECK(test_child_.IsValid()); | 181 CHECK(test_child_.process.IsValid()); |
| 182 | 182 |
| 183 int rv = -1; | 183 int rv = -1; |
| 184 WaitForMultiprocessTestChildExit(test_child_, TestTimeouts::action_timeout(), | 184 WaitForMultiprocessTestChildExit(test_child_.process, |
| 185 &rv); | 185 TestTimeouts::action_timeout(), &rv); |
| 186 test_child_.Close(); | 186 test_child_.process.Close(); |
| 187 return rv; | 187 return rv; |
| 188 } | 188 } |
| 189 | 189 |
| 190 void MultiprocessTestHelper::ClosePeerConnection() { | 190 void MultiprocessTestHelper::ClosePeerConnection() { |
| 191 DCHECK(!peer_token_.empty()); | 191 DCHECK(!peer_token_.empty()); |
| 192 ::mojo::edk::ClosePeerConnection(peer_token_); | 192 ::mojo::edk::ClosePeerConnection(peer_token_); |
| 193 peer_token_.clear(); | 193 peer_token_.clear(); |
| 194 } | 194 } |
| 195 | 195 |
| 196 bool MultiprocessTestHelper::WaitForChildTestShutdown() { | 196 bool MultiprocessTestHelper::WaitForChildTestShutdown() { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 ::testing::Test::HasNonfatalFailure()) ? 1 : 0; | 247 ::testing::Test::HasNonfatalFailure()) ? 1 : 0; |
| 248 }); | 248 }); |
| 249 } | 249 } |
| 250 | 250 |
| 251 // static | 251 // static |
| 252 mojo::ScopedMessagePipeHandle MultiprocessTestHelper::primordial_pipe; | 252 mojo::ScopedMessagePipeHandle MultiprocessTestHelper::primordial_pipe; |
| 253 | 253 |
| 254 } // namespace test | 254 } // namespace test |
| 255 } // namespace edk | 255 } // namespace edk |
| 256 } // namespace mojo | 256 } // namespace mojo |
| OLD | NEW |