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.
5 #include "mojo/edk/test/multiprocess_test_helper.h"
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"
17 MultiprocessTestHelper::MultiprocessTestHelper()
18 : test_child_handle_(base::kNullProcessHandle
) {
19 platform_channel_pair_
.reset(new embedder::PlatformChannelPair());
20 server_platform_handle
= platform_channel_pair_
->PassServerHandle();
23 MultiprocessTestHelper::~MultiprocessTestHelper() {
24 CHECK_EQ(test_child_handle_
, base::kNullProcessHandle
);
25 server_platform_handle
.reset();
26 platform_channel_pair_
.reset();
29 void MultiprocessTestHelper::StartChild(const std::string
& test_child_name
) {
30 CHECK(platform_channel_pair_
);
31 CHECK(!test_child_name
.empty());
32 CHECK_EQ(test_child_handle_
, base::kNullProcessHandle
);
34 std::string test_child_main
= test_child_name
+ "TestChildMain";
36 base::CommandLine
command_line(
37 base::GetMultiProcessTestChildBaseCommandLine());
38 embedder::HandlePassingInformation handle_passing_info
;
39 platform_channel_pair_
->PrepareToPassClientHandleToChildProcess(
40 &command_line
, &handle_passing_info
);
42 base::LaunchOptions options
;
44 options
.fds_to_remap
= &handle_passing_info
;
46 options
.start_hidden
= true;
47 options
.handles_to_inherit
= &handle_passing_info
;
49 #error "Not supported yet."
53 base::SpawnMultiProcessTestChild(test_child_main
, command_line
, options
);
54 platform_channel_pair_
->ChildProcessLaunched();
56 CHECK_NE(test_child_handle_
, base::kNullProcessHandle
);
59 int MultiprocessTestHelper::WaitForChildShutdown() {
60 CHECK_NE(test_child_handle_
, base::kNullProcessHandle
);
63 CHECK(base::WaitForExitCodeWithTimeout(test_child_handle_
, &rv
,
64 TestTimeouts::action_timeout()));
65 base::CloseProcessHandle(test_child_handle_
);
66 test_child_handle_
= base::kNullProcessHandle
;
70 bool MultiprocessTestHelper::WaitForChildTestShutdown() {
71 return WaitForChildShutdown() == 0;
75 void MultiprocessTestHelper::ChildSetup() {
76 CHECK(base::CommandLine::InitializedForCurrentProcess());
77 client_platform_handle
=
78 embedder::PlatformChannelPair::PassClientHandleFromParentProcess(
79 *base::CommandLine::ForCurrentProcess());
83 embedder::ScopedPlatformHandle
MultiprocessTestHelper::client_platform_handle
;