OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "mojo/edk/test/multiprocess_test_helper.h" | |
6 | |
7 #include "base/command_line.h" | |
8 #include "base/logging.h" | |
9 #include "base/process/kill.h" | |
10 #include "base/process/process_handle.h" | |
11 #include "build/build_config.h" | |
12 #include "mojo/edk/embedder/platform_channel_pair.h" | |
13 | |
14 namespace mojo { | |
15 namespace test { | |
16 | |
17 MultiprocessTestHelper::MultiprocessTestHelper() { | |
18 platform_channel_pair_.reset(new embedder::PlatformChannelPair()); | |
19 server_platform_handle = platform_channel_pair_->PassServerHandle(); | |
20 } | |
21 | |
22 MultiprocessTestHelper::~MultiprocessTestHelper() { | |
23 CHECK(!test_child_.IsValid()); | |
24 server_platform_handle.reset(); | |
25 platform_channel_pair_.reset(); | |
26 } | |
27 | |
28 void MultiprocessTestHelper::StartChild(const std::string& test_child_name) { | |
29 CHECK(platform_channel_pair_); | |
30 CHECK(!test_child_name.empty()); | |
31 CHECK(!test_child_.IsValid()); | |
32 | |
33 std::string test_child_main = test_child_name + "TestChildMain"; | |
34 | |
35 base::CommandLine command_line( | |
36 base::GetMultiProcessTestChildBaseCommandLine()); | |
37 embedder::HandlePassingInformation handle_passing_info; | |
38 platform_channel_pair_->PrepareToPassClientHandleToChildProcess( | |
39 &command_line, &handle_passing_info); | |
40 | |
41 base::LaunchOptions options; | |
42 #if defined(OS_POSIX) | |
43 options.fds_to_remap = &handle_passing_info; | |
44 #elif defined(OS_WIN) | |
45 options.start_hidden = true; | |
46 options.handles_to_inherit = &handle_passing_info; | |
47 #else | |
48 #error "Not supported yet." | |
49 #endif | |
50 | |
51 test_child_ = | |
52 base::SpawnMultiProcessTestChild(test_child_main, command_line, options); | |
53 platform_channel_pair_->ChildProcessLaunched(); | |
54 | |
55 CHECK(test_child_.IsValid()); | |
56 } | |
57 | |
58 int MultiprocessTestHelper::WaitForChildShutdown() { | |
59 CHECK(test_child_.IsValid()); | |
60 | |
61 int rv = -1; | |
62 CHECK( | |
63 test_child_.WaitForExitWithTimeout(TestTimeouts::action_timeout(), &rv)); | |
64 test_child_.Close(); | |
65 return rv; | |
66 } | |
67 | |
68 bool MultiprocessTestHelper::WaitForChildTestShutdown() { | |
69 return WaitForChildShutdown() == 0; | |
70 } | |
71 | |
72 // static | |
73 void MultiprocessTestHelper::ChildSetup() { | |
74 CHECK(base::CommandLine::InitializedForCurrentProcess()); | |
75 client_platform_handle = | |
76 embedder::PlatformChannelPair::PassClientHandleFromParentProcess( | |
77 *base::CommandLine::ForCurrentProcess()); | |
78 } | |
79 | |
80 // static | |
81 embedder::ScopedPlatformHandle MultiprocessTestHelper::client_platform_handle; | |
82 | |
83 } // namespace test | |
84 } // namespace mojo | |
OLD | NEW |