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

Side by Side Diff: mojo/system/multiprocess_message_pipe_unittest.cc

Issue 417303002: Convert ReadMessage...() to use the new user pointer handling (see r285350). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: hmm Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « mojo/system/message_pipe_unittest.cc ('k') | mojo/system/remote_message_pipe_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 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 <stdint.h> 5 #include <stdint.h>
6 #include <stdio.h> 6 #include <stdio.h>
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 // Wait for our end of the message pipe to be readable. 162 // Wait for our end of the message pipe to be readable.
163 MojoResult result = WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE); 163 MojoResult result = WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE);
164 if (result != MOJO_RESULT_OK) { 164 if (result != MOJO_RESULT_OK) {
165 // It was closed, probably. 165 // It was closed, probably.
166 CHECK_EQ(result, MOJO_RESULT_FAILED_PRECONDITION); 166 CHECK_EQ(result, MOJO_RESULT_FAILED_PRECONDITION);
167 break; 167 break;
168 } 168 }
169 169
170 std::string read_buffer(1000, '\0'); 170 std::string read_buffer(1000, '\0');
171 uint32_t read_buffer_size = static_cast<uint32_t>(read_buffer.size()); 171 uint32_t read_buffer_size = static_cast<uint32_t>(read_buffer.size());
172 CHECK_EQ(mp->ReadMessage(0, 172 CHECK_EQ(mp->ReadMessage(0, UserPointer<void>(&read_buffer[0]),
173 &read_buffer[0], &read_buffer_size, 173 MakeUserPointer(&read_buffer_size), NULL, NULL,
174 NULL, NULL,
175 MOJO_READ_MESSAGE_FLAG_NONE), 174 MOJO_READ_MESSAGE_FLAG_NONE),
176 MOJO_RESULT_OK); 175 MOJO_RESULT_OK);
177 read_buffer.resize(read_buffer_size); 176 read_buffer.resize(read_buffer_size);
178 VLOG(2) << "Child got: " << read_buffer; 177 VLOG(2) << "Child got: " << read_buffer;
179 178
180 if (read_buffer == quitquitquit) { 179 if (read_buffer == quitquitquit) {
181 VLOG(2) << "Child quitting."; 180 VLOG(2) << "Child quitting.";
182 break; 181 break;
183 } 182 }
184 183
(...skipping 23 matching lines...) Expand all
208 EXPECT_EQ(MOJO_RESULT_OK, 207 EXPECT_EQ(MOJO_RESULT_OK,
209 mp->WriteMessage(0, 208 mp->WriteMessage(0,
210 hello.data(), static_cast<uint32_t>(hello.size()), 209 hello.data(), static_cast<uint32_t>(hello.size()),
211 NULL, 210 NULL,
212 MOJO_WRITE_MESSAGE_FLAG_NONE)); 211 MOJO_WRITE_MESSAGE_FLAG_NONE));
213 212
214 EXPECT_EQ(MOJO_RESULT_OK, WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE)); 213 EXPECT_EQ(MOJO_RESULT_OK, WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE));
215 214
216 std::string read_buffer(1000, '\0'); 215 std::string read_buffer(1000, '\0');
217 uint32_t read_buffer_size = static_cast<uint32_t>(read_buffer.size()); 216 uint32_t read_buffer_size = static_cast<uint32_t>(read_buffer.size());
218 CHECK_EQ(mp->ReadMessage(0, 217 CHECK_EQ(mp->ReadMessage(0, UserPointer<void>(&read_buffer[0]),
219 &read_buffer[0], &read_buffer_size, 218 MakeUserPointer(&read_buffer_size), NULL, NULL,
220 NULL, NULL,
221 MOJO_READ_MESSAGE_FLAG_NONE), 219 MOJO_READ_MESSAGE_FLAG_NONE),
222 MOJO_RESULT_OK); 220 MOJO_RESULT_OK);
223 read_buffer.resize(read_buffer_size); 221 read_buffer.resize(read_buffer_size);
224 VLOG(2) << "Parent got: " << read_buffer; 222 VLOG(2) << "Parent got: " << read_buffer;
225 EXPECT_EQ(hello + hello, read_buffer); 223 EXPECT_EQ(hello + hello, read_buffer);
226 224
227 mp->Close(0); 225 mp->Close(0);
228 226
229 // We sent one message. 227 // We sent one message.
230 EXPECT_EQ(1 % 100, helper()->WaitForChildShutdown()); 228 EXPECT_EQ(1 % 100, helper()->WaitForChildShutdown());
(...skipping 26 matching lines...) Expand all
257 quitquitquit.data(), 255 quitquitquit.data(),
258 static_cast<uint32_t>(quitquitquit.size()), 256 static_cast<uint32_t>(quitquitquit.size()),
259 NULL, 257 NULL,
260 MOJO_WRITE_MESSAGE_FLAG_NONE)); 258 MOJO_WRITE_MESSAGE_FLAG_NONE));
261 259
262 for (size_t i = 0; i < kNumMessages; i++) { 260 for (size_t i = 0; i < kNumMessages; i++) {
263 EXPECT_EQ(MOJO_RESULT_OK, WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE)); 261 EXPECT_EQ(MOJO_RESULT_OK, WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE));
264 262
265 std::string read_buffer(kNumMessages * 2, '\0'); 263 std::string read_buffer(kNumMessages * 2, '\0');
266 uint32_t read_buffer_size = static_cast<uint32_t>(read_buffer.size()); 264 uint32_t read_buffer_size = static_cast<uint32_t>(read_buffer.size());
267 CHECK_EQ(mp->ReadMessage(0, 265 CHECK_EQ(mp->ReadMessage(0, UserPointer<void>(&read_buffer[0]),
268 &read_buffer[0], &read_buffer_size, 266 MakeUserPointer(&read_buffer_size), NULL, NULL,
269 NULL, NULL,
270 MOJO_READ_MESSAGE_FLAG_NONE), 267 MOJO_READ_MESSAGE_FLAG_NONE),
271 MOJO_RESULT_OK); 268 MOJO_RESULT_OK);
272 read_buffer.resize(read_buffer_size); 269 read_buffer.resize(read_buffer_size);
273 270
274 EXPECT_EQ(std::string(i * 2, 'A' + (i % 26)), read_buffer); 271 EXPECT_EQ(std::string(i * 2, 'A' + (i % 26)), read_buffer);
275 } 272 }
276 273
277 // Wait for it to become readable, which should fail (since we sent 274 // Wait for it to become readable, which should fail (since we sent
278 // "quitquitquit"). 275 // "quitquitquit").
279 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, 276 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
(...skipping 16 matching lines...) Expand all
296 channel_thread.Start(client_platform_handle.Pass(), mp); 293 channel_thread.Start(client_platform_handle.Pass(), mp);
297 294
298 // Wait for the first message from our parent. 295 // Wait for the first message from our parent.
299 CHECK_EQ(WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE), MOJO_RESULT_OK); 296 CHECK_EQ(WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE), MOJO_RESULT_OK);
300 297
301 // It should have a shared buffer. 298 // It should have a shared buffer.
302 std::string read_buffer(100, '\0'); 299 std::string read_buffer(100, '\0');
303 uint32_t num_bytes = static_cast<uint32_t>(read_buffer.size()); 300 uint32_t num_bytes = static_cast<uint32_t>(read_buffer.size());
304 DispatcherVector dispatchers; 301 DispatcherVector dispatchers;
305 uint32_t num_dispatchers = 10; // Maximum number to receive. 302 uint32_t num_dispatchers = 10; // Maximum number to receive.
306 CHECK_EQ(mp->ReadMessage(0, 303 CHECK_EQ(mp->ReadMessage(0, UserPointer<void>(&read_buffer[0]),
307 &read_buffer[0], &num_bytes, 304 MakeUserPointer(&num_bytes), &dispatchers,
308 &dispatchers, &num_dispatchers, 305 &num_dispatchers, MOJO_READ_MESSAGE_FLAG_NONE),
309 MOJO_READ_MESSAGE_FLAG_NONE),
310 MOJO_RESULT_OK); 306 MOJO_RESULT_OK);
311 read_buffer.resize(num_bytes); 307 read_buffer.resize(num_bytes);
312 CHECK_EQ(read_buffer, std::string("go 1")); 308 CHECK_EQ(read_buffer, std::string("go 1"));
313 CHECK_EQ(num_dispatchers, 1u); 309 CHECK_EQ(num_dispatchers, 1u);
314 310
315 CHECK_EQ(dispatchers[0]->GetType(), Dispatcher::kTypeSharedBuffer); 311 CHECK_EQ(dispatchers[0]->GetType(), Dispatcher::kTypeSharedBuffer);
316 312
317 scoped_refptr<SharedBufferDispatcher> dispatcher( 313 scoped_refptr<SharedBufferDispatcher> dispatcher(
318 static_cast<SharedBufferDispatcher*>(dispatchers[0].get())); 314 static_cast<SharedBufferDispatcher*>(dispatchers[0].get()));
319 315
(...skipping 19 matching lines...) Expand all
339 static_cast<uint32_t>(go2.size()), 335 static_cast<uint32_t>(go2.size()),
340 NULL, 336 NULL,
341 MOJO_WRITE_MESSAGE_FLAG_NONE), 337 MOJO_WRITE_MESSAGE_FLAG_NONE),
342 MOJO_RESULT_OK); 338 MOJO_RESULT_OK);
343 339
344 // Now wait for our parent to send us a message. 340 // Now wait for our parent to send us a message.
345 CHECK_EQ(WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE), MOJO_RESULT_OK); 341 CHECK_EQ(WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE), MOJO_RESULT_OK);
346 342
347 read_buffer = std::string(100, '\0'); 343 read_buffer = std::string(100, '\0');
348 num_bytes = static_cast<uint32_t>(read_buffer.size()); 344 num_bytes = static_cast<uint32_t>(read_buffer.size());
349 CHECK_EQ(mp->ReadMessage(0, 345 CHECK_EQ(mp->ReadMessage(0, UserPointer<void>(&read_buffer[0]),
350 &read_buffer[0], &num_bytes, 346 MakeUserPointer(&num_bytes), NULL, NULL,
351 NULL, NULL,
352 MOJO_READ_MESSAGE_FLAG_NONE), 347 MOJO_READ_MESSAGE_FLAG_NONE),
353 MOJO_RESULT_OK); 348 MOJO_RESULT_OK);
354 read_buffer.resize(num_bytes); 349 read_buffer.resize(num_bytes);
355 CHECK_EQ(read_buffer, std::string("go 3")); 350 CHECK_EQ(read_buffer, std::string("go 3"));
356 351
357 // It should have written something to the shared buffer. 352 // It should have written something to the shared buffer.
358 static const char kWorld[] = "world!!!"; 353 static const char kWorld[] = "world!!!";
359 CHECK_EQ(memcmp(mapping->base(), kWorld, sizeof(kWorld)), 0); 354 CHECK_EQ(memcmp(mapping->base(), kWorld, sizeof(kWorld)), 0);
360 355
361 // And we're done. 356 // And we're done.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 407
413 EXPECT_TRUE(dispatcher->HasOneRef()); 408 EXPECT_TRUE(dispatcher->HasOneRef());
414 dispatcher = NULL; 409 dispatcher = NULL;
415 410
416 // Wait for a message from the child. 411 // Wait for a message from the child.
417 EXPECT_EQ(MOJO_RESULT_OK, WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE)); 412 EXPECT_EQ(MOJO_RESULT_OK, WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE));
418 413
419 std::string read_buffer(100, '\0'); 414 std::string read_buffer(100, '\0');
420 uint32_t num_bytes = static_cast<uint32_t>(read_buffer.size()); 415 uint32_t num_bytes = static_cast<uint32_t>(read_buffer.size());
421 EXPECT_EQ(MOJO_RESULT_OK, 416 EXPECT_EQ(MOJO_RESULT_OK,
422 mp->ReadMessage(0, 417 mp->ReadMessage(0, UserPointer<void>(&read_buffer[0]),
423 &read_buffer[0], &num_bytes, 418 MakeUserPointer(&num_bytes), NULL, NULL,
424 NULL, NULL,
425 MOJO_READ_MESSAGE_FLAG_NONE)); 419 MOJO_READ_MESSAGE_FLAG_NONE));
426 read_buffer.resize(num_bytes); 420 read_buffer.resize(num_bytes);
427 EXPECT_EQ(std::string("go 2"), read_buffer); 421 EXPECT_EQ(std::string("go 2"), read_buffer);
428 422
429 // After we get it, the child should have written something to the shared 423 // After we get it, the child should have written something to the shared
430 // buffer. 424 // buffer.
431 static const char kHello[] = "hello"; 425 static const char kHello[] = "hello";
432 EXPECT_EQ(0, memcmp(mapping->base(), kHello, sizeof(kHello))); 426 EXPECT_EQ(0, memcmp(mapping->base(), kHello, sizeof(kHello)));
433 427
434 // Now we'll write some stuff to the shared buffer. 428 // Now we'll write some stuff to the shared buffer.
(...skipping 27 matching lines...) Expand all
462 scoped_ptr<MessagePipeEndpoint>(new LocalMessagePipeEndpoint()), 456 scoped_ptr<MessagePipeEndpoint>(new LocalMessagePipeEndpoint()),
463 scoped_ptr<MessagePipeEndpoint>(new ProxyMessagePipeEndpoint()))); 457 scoped_ptr<MessagePipeEndpoint>(new ProxyMessagePipeEndpoint())));
464 channel_thread.Start(client_platform_handle.Pass(), mp); 458 channel_thread.Start(client_platform_handle.Pass(), mp);
465 459
466 CHECK_EQ(WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE), MOJO_RESULT_OK); 460 CHECK_EQ(WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE), MOJO_RESULT_OK);
467 461
468 std::string read_buffer(100, '\0'); 462 std::string read_buffer(100, '\0');
469 uint32_t num_bytes = static_cast<uint32_t>(read_buffer.size()); 463 uint32_t num_bytes = static_cast<uint32_t>(read_buffer.size());
470 DispatcherVector dispatchers; 464 DispatcherVector dispatchers;
471 uint32_t num_dispatchers = 10; // Maximum number to receive. 465 uint32_t num_dispatchers = 10; // Maximum number to receive.
472 CHECK_EQ(mp->ReadMessage(0, 466 CHECK_EQ(mp->ReadMessage(0, UserPointer<void>(&read_buffer[0]),
473 &read_buffer[0], &num_bytes, 467 MakeUserPointer(&num_bytes), &dispatchers,
474 &dispatchers, &num_dispatchers, 468 &num_dispatchers, MOJO_READ_MESSAGE_FLAG_NONE),
475 MOJO_READ_MESSAGE_FLAG_NONE),
476 MOJO_RESULT_OK); 469 MOJO_RESULT_OK);
477 mp->Close(0); 470 mp->Close(0);
478 471
479 read_buffer.resize(num_bytes); 472 read_buffer.resize(num_bytes);
480 CHECK_EQ(read_buffer, std::string("hello")); 473 CHECK_EQ(read_buffer, std::string("hello"));
481 CHECK_EQ(num_dispatchers, 1u); 474 CHECK_EQ(num_dispatchers, 1u);
482 475
483 CHECK_EQ(dispatchers[0]->GetType(), Dispatcher::kTypePlatformHandle); 476 CHECK_EQ(dispatchers[0]->GetType(), Dispatcher::kTypePlatformHandle);
484 477
485 scoped_refptr<PlatformHandleDispatcher> dispatcher( 478 scoped_refptr<PlatformHandleDispatcher> dispatcher(
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE)); 544 WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE));
552 545
553 mp->Close(0); 546 mp->Close(0);
554 547
555 EXPECT_EQ(0, helper()->WaitForChildShutdown()); 548 EXPECT_EQ(0, helper()->WaitForChildShutdown());
556 } 549 }
557 550
558 } // namespace 551 } // namespace
559 } // namespace system 552 } // namespace system
560 } // namespace mojo 553 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/system/message_pipe_unittest.cc ('k') | mojo/system/remote_message_pipe_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698