Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: mojo/edk/test/multiprocess_test_helper.cc

Issue 843113003: MultiProcessTest: Update SpawnChild* to return a Process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/edk/test/multiprocess_test_helper.h ('k') | sandbox/mac/bootstrap_sandbox_unittest.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "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/edk/embedder/platform_channel_pair.h" 12 #include "mojo/edk/embedder/platform_channel_pair.h"
13 13
14 namespace mojo { 14 namespace mojo {
15 namespace test { 15 namespace test {
16 16
17 MultiprocessTestHelper::MultiprocessTestHelper() 17 MultiprocessTestHelper::MultiprocessTestHelper() {
18 : test_child_handle_(base::kNullProcessHandle) {
19 platform_channel_pair_.reset(new embedder::PlatformChannelPair()); 18 platform_channel_pair_.reset(new embedder::PlatformChannelPair());
20 server_platform_handle = platform_channel_pair_->PassServerHandle(); 19 server_platform_handle = platform_channel_pair_->PassServerHandle();
21 } 20 }
22 21
23 MultiprocessTestHelper::~MultiprocessTestHelper() { 22 MultiprocessTestHelper::~MultiprocessTestHelper() {
24 CHECK_EQ(test_child_handle_, base::kNullProcessHandle); 23 CHECK(!test_child_.IsValid());
25 server_platform_handle.reset(); 24 server_platform_handle.reset();
26 platform_channel_pair_.reset(); 25 platform_channel_pair_.reset();
27 } 26 }
28 27
29 void MultiprocessTestHelper::StartChild(const std::string& test_child_name) { 28 void MultiprocessTestHelper::StartChild(const std::string& test_child_name) {
30 CHECK(platform_channel_pair_); 29 CHECK(platform_channel_pair_);
31 CHECK(!test_child_name.empty()); 30 CHECK(!test_child_name.empty());
32 CHECK_EQ(test_child_handle_, base::kNullProcessHandle); 31 CHECK(!test_child_.IsValid());
33 32
34 std::string test_child_main = test_child_name + "TestChildMain"; 33 std::string test_child_main = test_child_name + "TestChildMain";
35 34
36 base::CommandLine command_line( 35 base::CommandLine command_line(
37 base::GetMultiProcessTestChildBaseCommandLine()); 36 base::GetMultiProcessTestChildBaseCommandLine());
38 embedder::HandlePassingInformation handle_passing_info; 37 embedder::HandlePassingInformation handle_passing_info;
39 platform_channel_pair_->PrepareToPassClientHandleToChildProcess( 38 platform_channel_pair_->PrepareToPassClientHandleToChildProcess(
40 &command_line, &handle_passing_info); 39 &command_line, &handle_passing_info);
41 40
42 base::LaunchOptions options; 41 base::LaunchOptions options;
43 #if defined(OS_POSIX) 42 #if defined(OS_POSIX)
44 options.fds_to_remap = &handle_passing_info; 43 options.fds_to_remap = &handle_passing_info;
45 #elif defined(OS_WIN) 44 #elif defined(OS_WIN)
46 options.start_hidden = true; 45 options.start_hidden = true;
47 options.handles_to_inherit = &handle_passing_info; 46 options.handles_to_inherit = &handle_passing_info;
48 #else 47 #else
49 #error "Not supported yet." 48 #error "Not supported yet."
50 #endif 49 #endif
51 50
52 test_child_handle_ = 51 test_child_ =
53 base::SpawnMultiProcessTestChild(test_child_main, command_line, options); 52 base::SpawnMultiProcessTestChild(test_child_main, command_line, options);
54 platform_channel_pair_->ChildProcessLaunched(); 53 platform_channel_pair_->ChildProcessLaunched();
55 54
56 CHECK_NE(test_child_handle_, base::kNullProcessHandle); 55 CHECK(test_child_.IsValid());
57 } 56 }
58 57
59 int MultiprocessTestHelper::WaitForChildShutdown() { 58 int MultiprocessTestHelper::WaitForChildShutdown() {
60 CHECK_NE(test_child_handle_, base::kNullProcessHandle); 59 CHECK(test_child_.IsValid());
61 60
62 int rv = -1; 61 int rv = -1;
63 CHECK(base::WaitForExitCodeWithTimeout(test_child_handle_, &rv, 62 CHECK(test_child_.WaitForExitWithTimeout(TestTimeouts::action_timeout(),
64 TestTimeouts::action_timeout())); 63 &rv));
65 base::CloseProcessHandle(test_child_handle_); 64 test_child_.Close();
66 test_child_handle_ = base::kNullProcessHandle;
67 return rv; 65 return rv;
68 } 66 }
69 67
70 bool MultiprocessTestHelper::WaitForChildTestShutdown() { 68 bool MultiprocessTestHelper::WaitForChildTestShutdown() {
71 return WaitForChildShutdown() == 0; 69 return WaitForChildShutdown() == 0;
72 } 70 }
73 71
74 // static 72 // static
75 void MultiprocessTestHelper::ChildSetup() { 73 void MultiprocessTestHelper::ChildSetup() {
76 CHECK(base::CommandLine::InitializedForCurrentProcess()); 74 CHECK(base::CommandLine::InitializedForCurrentProcess());
77 client_platform_handle = 75 client_platform_handle =
78 embedder::PlatformChannelPair::PassClientHandleFromParentProcess( 76 embedder::PlatformChannelPair::PassClientHandleFromParentProcess(
79 *base::CommandLine::ForCurrentProcess()); 77 *base::CommandLine::ForCurrentProcess());
80 } 78 }
81 79
82 // static 80 // static
83 embedder::ScopedPlatformHandle MultiprocessTestHelper::client_platform_handle; 81 embedder::ScopedPlatformHandle MultiprocessTestHelper::client_platform_handle;
84 82
85 } // namespace test 83 } // namespace test
86 } // namespace mojo 84 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/test/multiprocess_test_helper.h ('k') | sandbox/mac/bootstrap_sandbox_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698