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/common/test/multiprocess_test_base.h" | 5 #include "mojo/common/test/multiprocess_test_helper.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/process/kill.h" | 9 #include "base/process/kill.h" |
10 #include "base/process/process_handle.h" | 10 #include "base/process/process_handle.h" |
11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
12 #include "mojo/system/embedder/platform_channel_pair.h" | 12 #include "mojo/system/embedder/platform_channel_pair.h" |
13 | 13 |
14 namespace mojo { | 14 namespace mojo { |
15 namespace test { | 15 namespace test { |
16 | 16 |
17 MultiprocessTestBase::MultiprocessTestBase() | 17 MultiprocessTestHelper::MultiprocessTestHelper() |
18 : test_child_handle_(base::kNullProcessHandle) { | 18 : test_child_handle_(base::kNullProcessHandle) { |
19 } | |
20 | |
21 MultiprocessTestBase::~MultiprocessTestBase() { | |
22 CHECK_EQ(test_child_handle_, base::kNullProcessHandle); | |
23 } | |
24 | |
25 void MultiprocessTestBase::SetUp() { | |
26 CHECK_EQ(test_child_handle_, base::kNullProcessHandle); | |
27 | |
28 MultiProcessTest::SetUp(); | |
29 | |
30 platform_channel_pair_.reset(new embedder::PlatformChannelPair()); | 19 platform_channel_pair_.reset(new embedder::PlatformChannelPair()); |
31 server_platform_handle = platform_channel_pair_->PassServerHandle(); | 20 server_platform_handle = platform_channel_pair_->PassServerHandle(); |
32 } | 21 } |
33 | 22 |
34 void MultiprocessTestBase::TearDown() { | 23 MultiprocessTestHelper::~MultiprocessTestHelper() { |
35 CHECK_EQ(test_child_handle_, base::kNullProcessHandle); | 24 CHECK_EQ(test_child_handle_, base::kNullProcessHandle); |
36 | |
37 server_platform_handle.reset(); | 25 server_platform_handle.reset(); |
38 platform_channel_pair_.reset(); | 26 platform_channel_pair_.reset(); |
39 | |
40 MultiProcessTest::TearDown(); | |
41 } | 27 } |
42 | 28 |
43 void MultiprocessTestBase::StartChild(const std::string& test_child_name) { | 29 void MultiprocessTestHelper::StartChild(const std::string& test_child_name) { |
44 CHECK(platform_channel_pair_.get()); | 30 CHECK(platform_channel_pair_.get()); |
45 CHECK(!test_child_name.empty()); | 31 CHECK(!test_child_name.empty()); |
46 CHECK_EQ(test_child_handle_, base::kNullProcessHandle); | 32 CHECK_EQ(test_child_handle_, base::kNullProcessHandle); |
47 | 33 |
48 std::string test_child_main = test_child_name + "TestChildMain"; | 34 std::string test_child_main = test_child_name + "TestChildMain"; |
49 | 35 |
50 CommandLine unused(CommandLine::NO_PROGRAM); | 36 CommandLine command_line(base::GetMultiProcessTestChildBaseCommandLine()); |
51 embedder::HandlePassingInformation handle_passing_info; | 37 embedder::HandlePassingInformation handle_passing_info; |
52 platform_channel_pair_->PrepareToPassClientHandleToChildProcess( | 38 platform_channel_pair_->PrepareToPassClientHandleToChildProcess( |
53 &unused, &handle_passing_info); | 39 &command_line, &handle_passing_info); |
54 | 40 |
55 base::LaunchOptions options; | 41 base::LaunchOptions options; |
56 #if defined(OS_POSIX) | 42 #if defined(OS_POSIX) |
57 options.fds_to_remap = &handle_passing_info; | 43 options.fds_to_remap = &handle_passing_info; |
58 #elif defined(OS_WIN) | 44 #elif defined(OS_WIN) |
59 options.start_hidden = true; | 45 options.start_hidden = true; |
60 options.handles_to_inherit = &handle_passing_info; | 46 options.handles_to_inherit = &handle_passing_info; |
61 #else | 47 #else |
62 #error "Not supported yet." | 48 #error "Not supported yet." |
63 #endif | 49 #endif |
64 | 50 |
65 test_child_handle_ = SpawnChildWithOptions(test_child_main, options, false); | 51 test_child_handle_ = base::SpawnMultiProcessTestChild( |
| 52 test_child_main, command_line, options, false); |
66 platform_channel_pair_->ChildProcessLaunched(); | 53 platform_channel_pair_->ChildProcessLaunched(); |
67 | 54 |
68 CHECK_NE(test_child_handle_, base::kNullProcessHandle); | 55 CHECK_NE(test_child_handle_, base::kNullProcessHandle); |
69 } | 56 } |
70 | 57 |
71 int MultiprocessTestBase::WaitForChildShutdown() { | 58 int MultiprocessTestHelper::WaitForChildShutdown() { |
72 CHECK_NE(test_child_handle_, base::kNullProcessHandle); | 59 CHECK_NE(test_child_handle_, base::kNullProcessHandle); |
73 | 60 |
74 static const int kTimeoutSeconds = 5; | |
75 int rv = -1; | 61 int rv = -1; |
76 CHECK(base::WaitForExitCodeWithTimeout( | 62 CHECK(base::WaitForExitCodeWithTimeout( |
77 test_child_handle_, &rv, base::TimeDelta::FromSeconds(kTimeoutSeconds))); | 63 test_child_handle_, &rv, TestTimeouts::action_timeout())); |
78 base::CloseProcessHandle(test_child_handle_); | 64 base::CloseProcessHandle(test_child_handle_); |
79 test_child_handle_ = base::kNullProcessHandle; | 65 test_child_handle_ = base::kNullProcessHandle; |
80 return rv; | 66 return rv; |
81 } | 67 } |
82 | 68 |
83 CommandLine MultiprocessTestBase::MakeCmdLine(const std::string& procname, | |
84 bool debug_on_start) { | |
85 CHECK(platform_channel_pair_.get()); | |
86 | |
87 CommandLine command_line = | |
88 base::MultiProcessTest::MakeCmdLine(procname, debug_on_start); | |
89 embedder::HandlePassingInformation unused; | |
90 platform_channel_pair_->PrepareToPassClientHandleToChildProcess(&command_line, | |
91 &unused); | |
92 | |
93 return command_line; | |
94 } | |
95 | |
96 // static | 69 // static |
97 void MultiprocessTestBase::ChildSetup() { | 70 void MultiprocessTestHelper::ChildSetup() { |
98 CHECK(CommandLine::InitializedForCurrentProcess()); | 71 CHECK(CommandLine::InitializedForCurrentProcess()); |
99 client_platform_handle = | 72 client_platform_handle = |
100 embedder::PlatformChannelPair::PassClientHandleFromParentProcess( | 73 embedder::PlatformChannelPair::PassClientHandleFromParentProcess( |
101 *CommandLine::ForCurrentProcess()); | 74 *CommandLine::ForCurrentProcess()); |
102 } | 75 } |
103 | 76 |
104 // static | 77 // static |
105 embedder::ScopedPlatformHandle MultiprocessTestBase::client_platform_handle; | 78 embedder::ScopedPlatformHandle MultiprocessTestHelper::client_platform_handle; |
106 | 79 |
107 } // namespace test | 80 } // namespace test |
108 } // namespace mojo | 81 } // namespace mojo |
OLD | NEW |