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

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

Issue 2515043002: Mojo EDK: Fix race in named pipe creation for tests (Closed)
Patch Set: . Created 4 years, 1 month 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 | « no previous file | no next file » | 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 <functional> 7 #include <functional>
8 #include <set> 8 #include <set>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 #elif defined(OS_WIN) 133 #elif defined(OS_WIN)
134 options.start_hidden = true; 134 options.start_hidden = true;
135 if (base::win::GetVersion() >= base::win::VERSION_VISTA) 135 if (base::win::GetVersion() >= base::win::VERSION_VISTA)
136 options.handles_to_inherit = &handle_passing_info; 136 options.handles_to_inherit = &handle_passing_info;
137 else 137 else
138 options.inherit_handles = true; 138 options.inherit_handles = true;
139 #else 139 #else
140 #error "Not supported yet." 140 #error "Not supported yet."
141 #endif 141 #endif
142 142
143 // NOTE: In the case of named pipes, it's important that the server handle be
144 // created before the child process is launched; otherwise the server binding
145 // the pipe path can race with child's connection to the pipe.
146 ScopedPlatformHandle server_handle;
147 if (launch_type == LaunchType::CHILD || launch_type == LaunchType::PEER) {
148 server_handle = channel.PassServerHandle();
149 } else if (launch_type == LaunchType::NAMED_CHILD ||
150 launch_type == LaunchType::NAMED_PEER) {
151 server_handle = CreateServerHandle(named_pipe);
152 }
153
143 ScopedMessagePipeHandle pipe; 154 ScopedMessagePipeHandle pipe;
144 std::string child_token = mojo::edk::GenerateRandomToken(); 155 std::string child_token = mojo::edk::GenerateRandomToken();
145 if (launch_type == LaunchType::CHILD || 156 if (launch_type == LaunchType::CHILD ||
146 launch_type == LaunchType::NAMED_CHILD) { 157 launch_type == LaunchType::NAMED_CHILD) {
147 pipe = CreateParentMessagePipe(pipe_token, child_token); 158 pipe = CreateParentMessagePipe(pipe_token, child_token);
148 } else if (launch_type == LaunchType::PEER) { 159 } else if (launch_type == LaunchType::PEER ||
160 launch_type == LaunchType::NAMED_PEER) {
149 peer_token_ = mojo::edk::GenerateRandomToken(); 161 peer_token_ = mojo::edk::GenerateRandomToken();
150 pipe = ConnectToPeerProcess(channel.PassServerHandle(), peer_token_); 162 pipe = ConnectToPeerProcess(std::move(server_handle), peer_token_);
151 } else if (launch_type == LaunchType::NAMED_PEER) {
152 peer_token_ = mojo::edk::GenerateRandomToken();
153 pipe = ConnectToPeerProcess(CreateServerHandle(named_pipe), peer_token_);
154 } 163 }
155 164
156 test_child_ = 165 test_child_ =
157 base::SpawnMultiProcessTestChild(test_child_main, command_line, options); 166 base::SpawnMultiProcessTestChild(test_child_main, command_line, options);
158 if (launch_type == LaunchType::CHILD || launch_type == LaunchType::PEER) 167 if (launch_type == LaunchType::CHILD || launch_type == LaunchType::PEER)
159 channel.ChildProcessLaunched(); 168 channel.ChildProcessLaunched();
160 169
161 if (launch_type == LaunchType::CHILD) { 170 if (launch_type == LaunchType::CHILD ||
162 ChildProcessLaunched(test_child_.Handle(), channel.PassServerHandle(), 171 launch_type == LaunchType::NAMED_CHILD) {
163 child_token, process_error_callback_); 172 DCHECK(server_handle.is_valid());
164 } else if (launch_type == LaunchType::NAMED_CHILD) { 173 ChildProcessLaunched(test_child_.Handle(), std::move(server_handle),
165 ChildProcessLaunched(test_child_.Handle(), CreateServerHandle(named_pipe),
166 child_token, process_error_callback_); 174 child_token, process_error_callback_);
167 } 175 }
168 176
169 CHECK(test_child_.IsValid()); 177 CHECK(test_child_.IsValid());
170 return pipe; 178 return pipe;
171 } 179 }
172 180
173 int MultiprocessTestHelper::WaitForChildShutdown() { 181 int MultiprocessTestHelper::WaitForChildShutdown() {
174 CHECK(test_child_.IsValid()); 182 CHECK(test_child_.IsValid());
175 183
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 ::testing::Test::HasNonfatalFailure()) ? 1 : 0; 254 ::testing::Test::HasNonfatalFailure()) ? 1 : 0;
247 }); 255 });
248 } 256 }
249 257
250 // static 258 // static
251 mojo::ScopedMessagePipeHandle MultiprocessTestHelper::primordial_pipe; 259 mojo::ScopedMessagePipeHandle MultiprocessTestHelper::primordial_pipe;
252 260
253 } // namespace test 261 } // namespace test
254 } // namespace edk 262 } // namespace edk
255 } // namespace mojo 263 } // namespace mojo
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698