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

Side by Side Diff: ipc/ipc_test_base.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 | « ipc/ipc_test_base.h ('k') | ipc/mojo/ipc_channel_mojo_unittest.cc » ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #include "ipc/ipc_test_base.h" 7 #include "ipc/ipc_test_base.h"
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/process/kill.h" 10 #include "base/process/kill.h"
11 #include "base/threading/thread.h" 11 #include "base/threading/thread.h"
12 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "ipc/ipc_descriptors.h" 13 #include "ipc/ipc_descriptors.h"
14 14
15 #if defined(OS_POSIX) 15 #if defined(OS_POSIX)
16 #include "base/posix/global_descriptors.h" 16 #include "base/posix/global_descriptors.h"
17 #endif 17 #endif
18 18
19 // static 19 // static
20 std::string IPCTestBase::GetChannelName(const std::string& test_client_name) { 20 std::string IPCTestBase::GetChannelName(const std::string& test_client_name) {
21 DCHECK(!test_client_name.empty()); 21 DCHECK(!test_client_name.empty());
22 return test_client_name + "__Channel"; 22 return test_client_name + "__Channel";
23 } 23 }
24 24
25 IPCTestBase::IPCTestBase() 25 IPCTestBase::IPCTestBase() {
26 : client_process_(base::kNullProcessHandle) {
27 } 26 }
28 27
29 IPCTestBase::~IPCTestBase() { 28 IPCTestBase::~IPCTestBase() {
30 } 29 }
31 30
32 void IPCTestBase::TearDown() { 31 void IPCTestBase::TearDown() {
33 message_loop_.reset(); 32 message_loop_.reset();
34 MultiProcessTest::TearDown(); 33 MultiProcessTest::TearDown();
35 } 34 }
36 35
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 void IPCTestBase::DestroyChannelProxy() { 96 void IPCTestBase::DestroyChannelProxy() {
98 CHECK(channel_proxy_.get()); 97 CHECK(channel_proxy_.get());
99 channel_proxy_.reset(); 98 channel_proxy_.reset();
100 } 99 }
101 100
102 std::string IPCTestBase::GetTestMainName() const { 101 std::string IPCTestBase::GetTestMainName() const {
103 return test_client_name_ + "TestClientMain"; 102 return test_client_name_ + "TestClientMain";
104 } 103 }
105 104
106 bool IPCTestBase::DidStartClient() { 105 bool IPCTestBase::DidStartClient() {
107 DCHECK_NE(base::kNullProcessHandle, client_process_); 106 DCHECK(client_process_.IsValid());
108 return client_process_ != base::kNullProcessHandle; 107 return client_process_.IsValid();
109 } 108 }
110 109
111 #if defined(OS_POSIX) 110 #if defined(OS_POSIX)
112 111
113 bool IPCTestBase::StartClient() { 112 bool IPCTestBase::StartClient() {
114 return StartClientWithFD(channel_ 113 return StartClientWithFD(channel_
115 ? channel_->GetClientFileDescriptor() 114 ? channel_->GetClientFileDescriptor()
116 : channel_proxy_->GetClientFileDescriptor()); 115 : channel_proxy_->GetClientFileDescriptor());
117 } 116 }
118 117
119 bool IPCTestBase::StartClientWithFD(int ipcfd) { 118 bool IPCTestBase::StartClientWithFD(int ipcfd) {
120 DCHECK_EQ(client_process_, base::kNullProcessHandle); 119 DCHECK(!client_process_.IsValid());
121 120
122 base::FileHandleMappingVector fds_to_map; 121 base::FileHandleMappingVector fds_to_map;
123 if (ipcfd > -1) 122 if (ipcfd > -1)
124 fds_to_map.push_back(std::pair<int, int>(ipcfd, 123 fds_to_map.push_back(std::pair<int, int>(ipcfd,
125 kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor)); 124 kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor));
126 base::LaunchOptions options; 125 base::LaunchOptions options;
127 options.fds_to_remap = &fds_to_map; 126 options.fds_to_remap = &fds_to_map;
128 client_process_ = SpawnChildWithOptions(GetTestMainName(), options); 127 client_process_ = SpawnChildWithOptions(GetTestMainName(), options);
129 128
130 return DidStartClient(); 129 return DidStartClient();
131 } 130 }
132 131
133 #elif defined(OS_WIN) 132 #elif defined(OS_WIN)
134 133
135 bool IPCTestBase::StartClient() { 134 bool IPCTestBase::StartClient() {
136 DCHECK_EQ(client_process_, base::kNullProcessHandle); 135 DCHECK(!client_process_.IsValid());
137 client_process_ = SpawnChild(GetTestMainName()); 136 client_process_ = SpawnChild(GetTestMainName());
138 return DidStartClient(); 137 return DidStartClient();
139 } 138 }
140 139
141 #endif 140 #endif
142 141
143 bool IPCTestBase::WaitForClientShutdown() { 142 bool IPCTestBase::WaitForClientShutdown() {
144 DCHECK(client_process_ != base::kNullProcessHandle); 143 DCHECK(client_process_.IsValid());
145 144
146 bool rv = base::WaitForSingleProcess(client_process_, 145 bool rv = base::WaitForSingleProcess(client_process_.Handle(),
147 base::TimeDelta::FromSeconds(5)); 146 base::TimeDelta::FromSeconds(5));
148 base::CloseProcessHandle(client_process_); 147 client_process_.Close();
149 client_process_ = base::kNullProcessHandle;
150 return rv; 148 return rv;
151 } 149 }
152 150
153 IPC::ChannelHandle IPCTestBase::GetTestChannelHandle() { 151 IPC::ChannelHandle IPCTestBase::GetTestChannelHandle() {
154 return GetChannelName(test_client_name_); 152 return GetChannelName(test_client_name_);
155 } 153 }
156 154
157 scoped_refptr<base::TaskRunner> IPCTestBase::task_runner() { 155 scoped_refptr<base::TaskRunner> IPCTestBase::task_runner() {
158 return message_loop_->message_loop_proxy(); 156 return message_loop_->message_loop_proxy();
159 } 157 }
160 158
161 scoped_ptr<IPC::ChannelFactory> IPCTestBase::CreateChannelFactory( 159 scoped_ptr<IPC::ChannelFactory> IPCTestBase::CreateChannelFactory(
162 const IPC::ChannelHandle& handle, 160 const IPC::ChannelHandle& handle,
163 base::TaskRunner* runner) { 161 base::TaskRunner* runner) {
164 return IPC::ChannelFactory::Create(handle, IPC::Channel::MODE_SERVER); 162 return IPC::ChannelFactory::Create(handle, IPC::Channel::MODE_SERVER);
165 } 163 }
OLDNEW
« no previous file with comments | « ipc/ipc_test_base.h ('k') | ipc/mojo/ipc_channel_mojo_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698