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

Side by Side Diff: mojo/edk/system/simple_dispatcher_unittest.cc

Issue 728043002: Revert of Update mojo sdk to rev afb4440fd5a10cba980878c326180b7ad7960480 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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 | « mojo/edk/system/shared_buffer_dispatcher_unittest.cc ('k') | mojo/edk/system/test_utils.h » ('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 // NOTE(vtl): Some of these tests are inherently flaky (e.g., if run on a 5 // NOTE(vtl): Some of these tests are inherently flaky (e.g., if run on a
6 // heavily-loaded system). Sorry. |test::EpsilonTimeout()| may be increased to 6 // heavily-loaded system). Sorry. |test::EpsilonTimeout()| may be increased to
7 // increase tolerance and reduce observed flakiness (though doing so reduces the 7 // increase tolerance and reduce observed flakiness (though doing so reduces the
8 // meaningfulness of the test). 8 // meaningfulness of the test).
9 9
10 #include "mojo/edk/system/simple_dispatcher.h" 10 #include "mojo/edk/system/simple_dispatcher.h"
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 bool did_wait; 336 bool did_wait;
337 MojoResult result; 337 MojoResult result;
338 uint32_t context; 338 uint32_t context;
339 HandleSignalsState hss; 339 HandleSignalsState hss;
340 340
341 // Wait for readable (already readable). 341 // Wait for readable (already readable).
342 { 342 {
343 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher()); 343 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher());
344 { 344 {
345 d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_READABLE); 345 d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_READABLE);
346 test::WaiterThread thread(d, MOJO_HANDLE_SIGNAL_READABLE, 346 test::WaiterThread thread(d,
347 MOJO_DEADLINE_INDEFINITE, 1, &did_wait, &result, 347 MOJO_HANDLE_SIGNAL_READABLE,
348 &context, &hss); 348 MOJO_DEADLINE_INDEFINITE,
349 1,
350 &did_wait,
351 &result,
352 &context,
353 &hss);
349 stopwatch.Start(); 354 stopwatch.Start();
350 thread.Start(); 355 thread.Start();
351 } // Joins the thread. 356 } // Joins the thread.
352 // If we closed earlier, then probably we'd get a |MOJO_RESULT_CANCELLED|. 357 // If we closed earlier, then probably we'd get a |MOJO_RESULT_CANCELLED|.
353 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); 358 EXPECT_EQ(MOJO_RESULT_OK, d->Close());
354 } 359 }
355 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); 360 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout());
356 EXPECT_FALSE(did_wait); 361 EXPECT_FALSE(did_wait);
357 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, result); 362 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, result);
358 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals); 363 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals);
359 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 364 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
360 hss.satisfiable_signals); 365 hss.satisfiable_signals);
361 366
362 // Wait for readable and becomes readable after some time. 367 // Wait for readable and becomes readable after some time.
363 { 368 {
364 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher()); 369 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher());
365 { 370 {
366 test::WaiterThread thread(d, MOJO_HANDLE_SIGNAL_READABLE, 371 test::WaiterThread thread(d,
367 MOJO_DEADLINE_INDEFINITE, 2, &did_wait, &result, 372 MOJO_HANDLE_SIGNAL_READABLE,
368 &context, &hss); 373 MOJO_DEADLINE_INDEFINITE,
374 2,
375 &did_wait,
376 &result,
377 &context,
378 &hss);
369 stopwatch.Start(); 379 stopwatch.Start();
370 thread.Start(); 380 thread.Start();
371 base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); 381 base::PlatformThread::Sleep(2 * test::EpsilonTimeout());
372 d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_READABLE); 382 d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_READABLE);
373 } // Joins the thread. 383 } // Joins the thread.
374 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); 384 EXPECT_EQ(MOJO_RESULT_OK, d->Close());
375 } 385 }
376 base::TimeDelta elapsed = stopwatch.Elapsed(); 386 base::TimeDelta elapsed = stopwatch.Elapsed();
377 EXPECT_GT(elapsed, (2 - 1) * test::EpsilonTimeout()); 387 EXPECT_GT(elapsed, (2 - 1) * test::EpsilonTimeout());
378 EXPECT_LT(elapsed, (2 + 1) * test::EpsilonTimeout()); 388 EXPECT_LT(elapsed, (2 + 1) * test::EpsilonTimeout());
379 EXPECT_TRUE(did_wait); 389 EXPECT_TRUE(did_wait);
380 EXPECT_EQ(MOJO_RESULT_OK, result); 390 EXPECT_EQ(MOJO_RESULT_OK, result);
381 EXPECT_EQ(2u, context); 391 EXPECT_EQ(2u, context);
382 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals); 392 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals);
383 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 393 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
384 hss.satisfiable_signals); 394 hss.satisfiable_signals);
385 395
386 // Wait for readable and becomes never-readable after some time. 396 // Wait for readable and becomes never-readable after some time.
387 { 397 {
388 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher()); 398 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher());
389 { 399 {
390 test::WaiterThread thread(d, MOJO_HANDLE_SIGNAL_READABLE, 400 test::WaiterThread thread(d,
391 MOJO_DEADLINE_INDEFINITE, 3, &did_wait, &result, 401 MOJO_HANDLE_SIGNAL_READABLE,
392 &context, &hss); 402 MOJO_DEADLINE_INDEFINITE,
403 3,
404 &did_wait,
405 &result,
406 &context,
407 &hss);
393 stopwatch.Start(); 408 stopwatch.Start();
394 thread.Start(); 409 thread.Start();
395 base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); 410 base::PlatformThread::Sleep(2 * test::EpsilonTimeout());
396 d->SetSatisfiableSignals(MOJO_HANDLE_SIGNAL_NONE); 411 d->SetSatisfiableSignals(MOJO_HANDLE_SIGNAL_NONE);
397 } // Joins the thread. 412 } // Joins the thread.
398 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); 413 EXPECT_EQ(MOJO_RESULT_OK, d->Close());
399 } 414 }
400 elapsed = stopwatch.Elapsed(); 415 elapsed = stopwatch.Elapsed();
401 EXPECT_GT(elapsed, (2 - 1) * test::EpsilonTimeout()); 416 EXPECT_GT(elapsed, (2 - 1) * test::EpsilonTimeout());
402 EXPECT_LT(elapsed, (2 + 1) * test::EpsilonTimeout()); 417 EXPECT_LT(elapsed, (2 + 1) * test::EpsilonTimeout());
403 EXPECT_TRUE(did_wait); 418 EXPECT_TRUE(did_wait);
404 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result); 419 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result);
405 EXPECT_EQ(3u, context); 420 EXPECT_EQ(3u, context);
406 EXPECT_EQ(0u, hss.satisfied_signals); 421 EXPECT_EQ(0u, hss.satisfied_signals);
407 EXPECT_EQ(0u, hss.satisfiable_signals); 422 EXPECT_EQ(0u, hss.satisfiable_signals);
408 423
409 // Wait for readable and dispatcher gets closed. 424 // Wait for readable and dispatcher gets closed.
410 { 425 {
411 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher()); 426 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher());
412 test::WaiterThread thread(d, MOJO_HANDLE_SIGNAL_READABLE, 427 test::WaiterThread thread(d,
413 MOJO_DEADLINE_INDEFINITE, 4, &did_wait, &result, 428 MOJO_HANDLE_SIGNAL_READABLE,
414 &context, &hss); 429 MOJO_DEADLINE_INDEFINITE,
430 4,
431 &did_wait,
432 &result,
433 &context,
434 &hss);
415 stopwatch.Start(); 435 stopwatch.Start();
416 thread.Start(); 436 thread.Start();
417 base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); 437 base::PlatformThread::Sleep(2 * test::EpsilonTimeout());
418 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); 438 EXPECT_EQ(MOJO_RESULT_OK, d->Close());
419 } // Joins the thread. 439 } // Joins the thread.
420 elapsed = stopwatch.Elapsed(); 440 elapsed = stopwatch.Elapsed();
421 EXPECT_GT(elapsed, (2 - 1) * test::EpsilonTimeout()); 441 EXPECT_GT(elapsed, (2 - 1) * test::EpsilonTimeout());
422 EXPECT_LT(elapsed, (2 + 1) * test::EpsilonTimeout()); 442 EXPECT_LT(elapsed, (2 + 1) * test::EpsilonTimeout());
423 EXPECT_TRUE(did_wait); 443 EXPECT_TRUE(did_wait);
424 EXPECT_EQ(MOJO_RESULT_CANCELLED, result); 444 EXPECT_EQ(MOJO_RESULT_CANCELLED, result);
425 EXPECT_EQ(4u, context); 445 EXPECT_EQ(4u, context);
426 EXPECT_EQ(0u, hss.satisfied_signals); 446 EXPECT_EQ(0u, hss.satisfied_signals);
427 EXPECT_EQ(0u, hss.satisfiable_signals); 447 EXPECT_EQ(0u, hss.satisfiable_signals);
428 448
429 // Wait for readable and times out. 449 // Wait for readable and times out.
430 { 450 {
431 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher()); 451 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher());
432 { 452 {
433 test::WaiterThread thread(d, MOJO_HANDLE_SIGNAL_READABLE, 453 test::WaiterThread thread(d,
434 2 * test::EpsilonTimeout().InMicroseconds(), 5, 454 MOJO_HANDLE_SIGNAL_READABLE,
435 &did_wait, &result, &context, &hss); 455 2 * test::EpsilonTimeout().InMicroseconds(),
456 5,
457 &did_wait,
458 &result,
459 &context,
460 &hss);
436 stopwatch.Start(); 461 stopwatch.Start();
437 thread.Start(); 462 thread.Start();
438 base::PlatformThread::Sleep(1 * test::EpsilonTimeout()); 463 base::PlatformThread::Sleep(1 * test::EpsilonTimeout());
439 // Not what we're waiting for. 464 // Not what we're waiting for.
440 d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_WRITABLE); 465 d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_WRITABLE);
441 } // Joins the thread (after its wait times out). 466 } // Joins the thread (after its wait times out).
442 // If we closed earlier, then probably we'd get a |MOJO_RESULT_CANCELLED|. 467 // If we closed earlier, then probably we'd get a |MOJO_RESULT_CANCELLED|.
443 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); 468 EXPECT_EQ(MOJO_RESULT_OK, d->Close());
444 } 469 }
445 elapsed = stopwatch.Elapsed(); 470 elapsed = stopwatch.Elapsed();
(...skipping 18 matching lines...) Expand all
464 bool did_wait[kNumWaiters]; 489 bool did_wait[kNumWaiters];
465 MojoResult result[kNumWaiters]; 490 MojoResult result[kNumWaiters];
466 uint32_t context[kNumWaiters]; 491 uint32_t context[kNumWaiters];
467 HandleSignalsState hss[kNumWaiters]; 492 HandleSignalsState hss[kNumWaiters];
468 493
469 // All wait for readable and becomes readable after some time. 494 // All wait for readable and becomes readable after some time.
470 { 495 {
471 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher()); 496 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher());
472 ScopedVector<test::WaiterThread> threads; 497 ScopedVector<test::WaiterThread> threads;
473 for (uint32_t i = 0; i < kNumWaiters; i++) { 498 for (uint32_t i = 0; i < kNumWaiters; i++) {
474 threads.push_back(new test::WaiterThread( 499 threads.push_back(new test::WaiterThread(d,
475 d, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE, i, 500 MOJO_HANDLE_SIGNAL_READABLE,
476 &did_wait[i], &result[i], &context[i], &hss[i])); 501 MOJO_DEADLINE_INDEFINITE,
502 i,
503 &did_wait[i],
504 &result[i],
505 &context[i],
506 &hss[i]));
477 threads.back()->Start(); 507 threads.back()->Start();
478 } 508 }
479 base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); 509 base::PlatformThread::Sleep(2 * test::EpsilonTimeout());
480 d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_READABLE); 510 d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_READABLE);
481 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); 511 EXPECT_EQ(MOJO_RESULT_OK, d->Close());
482 } // Joins the threads. 512 } // Joins the threads.
483 for (uint32_t i = 0; i < kNumWaiters; i++) { 513 for (uint32_t i = 0; i < kNumWaiters; i++) {
484 EXPECT_TRUE(did_wait[i]) << i; 514 EXPECT_TRUE(did_wait[i]) << i;
485 EXPECT_EQ(MOJO_RESULT_OK, result[i]) << i; 515 EXPECT_EQ(MOJO_RESULT_OK, result[i]) << i;
486 EXPECT_EQ(i, context[i]) << i; 516 EXPECT_EQ(i, context[i]) << i;
487 // Since we closed before joining, we can't say much about what each thread 517 // Since we closed before joining, we can't say much about what each thread
488 // saw as the state. 518 // saw as the state.
489 } 519 }
490 520
491 // Some wait for readable, some for writable, and becomes readable after some 521 // Some wait for readable, some for writable, and becomes readable after some
492 // time. 522 // time.
493 { 523 {
494 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher()); 524 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher());
495 ScopedVector<test::WaiterThread> threads; 525 ScopedVector<test::WaiterThread> threads;
496 for (uint32_t i = 0; i < kNumWaiters / 2; i++) { 526 for (uint32_t i = 0; i < kNumWaiters / 2; i++) {
497 threads.push_back(new test::WaiterThread( 527 threads.push_back(new test::WaiterThread(d,
498 d, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE, i, 528 MOJO_HANDLE_SIGNAL_READABLE,
499 &did_wait[i], &result[i], &context[i], &hss[i])); 529 MOJO_DEADLINE_INDEFINITE,
530 i,
531 &did_wait[i],
532 &result[i],
533 &context[i],
534 &hss[i]));
500 threads.back()->Start(); 535 threads.back()->Start();
501 } 536 }
502 for (uint32_t i = kNumWaiters / 2; i < kNumWaiters; i++) { 537 for (uint32_t i = kNumWaiters / 2; i < kNumWaiters; i++) {
503 threads.push_back(new test::WaiterThread( 538 threads.push_back(new test::WaiterThread(d,
504 d, MOJO_HANDLE_SIGNAL_WRITABLE, MOJO_DEADLINE_INDEFINITE, i, 539 MOJO_HANDLE_SIGNAL_WRITABLE,
505 &did_wait[i], &result[i], &context[i], &hss[i])); 540 MOJO_DEADLINE_INDEFINITE,
541 i,
542 &did_wait[i],
543 &result[i],
544 &context[i],
545 &hss[i]));
506 threads.back()->Start(); 546 threads.back()->Start();
507 } 547 }
508 base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); 548 base::PlatformThread::Sleep(2 * test::EpsilonTimeout());
509 d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_READABLE); 549 d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_READABLE);
510 // This will wake up the ones waiting to write. 550 // This will wake up the ones waiting to write.
511 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); 551 EXPECT_EQ(MOJO_RESULT_OK, d->Close());
512 } // Joins the threads. 552 } // Joins the threads.
513 for (uint32_t i = 0; i < kNumWaiters / 2; i++) { 553 for (uint32_t i = 0; i < kNumWaiters / 2; i++) {
514 EXPECT_TRUE(did_wait[i]) << i; 554 EXPECT_TRUE(did_wait[i]) << i;
515 EXPECT_EQ(MOJO_RESULT_OK, result[i]) << i; 555 EXPECT_EQ(MOJO_RESULT_OK, result[i]) << i;
516 EXPECT_EQ(i, context[i]) << i; 556 EXPECT_EQ(i, context[i]) << i;
517 // Since we closed before joining, we can't say much about what each thread 557 // Since we closed before joining, we can't say much about what each thread
518 // saw as the state. 558 // saw as the state.
519 } 559 }
520 for (uint32_t i = kNumWaiters / 2; i < kNumWaiters; i++) { 560 for (uint32_t i = kNumWaiters / 2; i < kNumWaiters; i++) {
521 EXPECT_TRUE(did_wait[i]) << i; 561 EXPECT_TRUE(did_wait[i]) << i;
522 EXPECT_EQ(MOJO_RESULT_CANCELLED, result[i]) << i; 562 EXPECT_EQ(MOJO_RESULT_CANCELLED, result[i]) << i;
523 EXPECT_EQ(i, context[i]) << i; 563 EXPECT_EQ(i, context[i]) << i;
524 // Since we closed before joining, we can't say much about what each thread 564 // Since we closed before joining, we can't say much about what each thread
525 // saw as the state. 565 // saw as the state.
526 } 566 }
527 567
528 // Some wait for readable, some for writable, and becomes readable and 568 // Some wait for readable, some for writable, and becomes readable and
529 // never-writable after some time. 569 // never-writable after some time.
530 { 570 {
531 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher()); 571 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher());
532 ScopedVector<test::WaiterThread> threads; 572 ScopedVector<test::WaiterThread> threads;
533 for (uint32_t i = 0; i < kNumWaiters / 2; i++) { 573 for (uint32_t i = 0; i < kNumWaiters / 2; i++) {
534 threads.push_back(new test::WaiterThread( 574 threads.push_back(new test::WaiterThread(d,
535 d, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE, i, 575 MOJO_HANDLE_SIGNAL_READABLE,
536 &did_wait[i], &result[i], &context[i], &hss[i])); 576 MOJO_DEADLINE_INDEFINITE,
577 i,
578 &did_wait[i],
579 &result[i],
580 &context[i],
581 &hss[i]));
537 threads.back()->Start(); 582 threads.back()->Start();
538 } 583 }
539 for (uint32_t i = kNumWaiters / 2; i < kNumWaiters; i++) { 584 for (uint32_t i = kNumWaiters / 2; i < kNumWaiters; i++) {
540 threads.push_back(new test::WaiterThread( 585 threads.push_back(new test::WaiterThread(d,
541 d, MOJO_HANDLE_SIGNAL_WRITABLE, MOJO_DEADLINE_INDEFINITE, i, 586 MOJO_HANDLE_SIGNAL_WRITABLE,
542 &did_wait[i], &result[i], &context[i], &hss[i])); 587 MOJO_DEADLINE_INDEFINITE,
588 i,
589 &did_wait[i],
590 &result[i],
591 &context[i],
592 &hss[i]));
543 threads.back()->Start(); 593 threads.back()->Start();
544 } 594 }
545 base::PlatformThread::Sleep(1 * test::EpsilonTimeout()); 595 base::PlatformThread::Sleep(1 * test::EpsilonTimeout());
546 d->SetSatisfiableSignals(MOJO_HANDLE_SIGNAL_READABLE); 596 d->SetSatisfiableSignals(MOJO_HANDLE_SIGNAL_READABLE);
547 base::PlatformThread::Sleep(1 * test::EpsilonTimeout()); 597 base::PlatformThread::Sleep(1 * test::EpsilonTimeout());
548 d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_READABLE); 598 d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_READABLE);
549 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); 599 EXPECT_EQ(MOJO_RESULT_OK, d->Close());
550 } // Joins the threads. 600 } // Joins the threads.
551 for (uint32_t i = 0; i < kNumWaiters / 2; i++) { 601 for (uint32_t i = 0; i < kNumWaiters / 2; i++) {
552 EXPECT_TRUE(did_wait[i]) << i; 602 EXPECT_TRUE(did_wait[i]) << i;
553 EXPECT_EQ(MOJO_RESULT_OK, result[i]) << i; 603 EXPECT_EQ(MOJO_RESULT_OK, result[i]) << i;
554 EXPECT_EQ(i, context[i]) << i; 604 EXPECT_EQ(i, context[i]) << i;
555 // Since we closed before joining, we can't say much about what each thread 605 // Since we closed before joining, we can't say much about what each thread
556 // saw as the state. 606 // saw as the state.
557 } 607 }
558 for (uint32_t i = kNumWaiters / 2; i < kNumWaiters; i++) { 608 for (uint32_t i = kNumWaiters / 2; i < kNumWaiters; i++) {
559 EXPECT_TRUE(did_wait[i]) << i; 609 EXPECT_TRUE(did_wait[i]) << i;
560 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result[i]) << i; 610 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result[i]) << i;
561 EXPECT_EQ(i, context[i]) << i; 611 EXPECT_EQ(i, context[i]) << i;
562 // Since we closed before joining, we can't say much about what each thread 612 // Since we closed before joining, we can't say much about what each thread
563 // saw as the state. 613 // saw as the state.
564 } 614 }
565 615
566 // Some wait for readable, some for writable, and becomes readable after some 616 // Some wait for readable, some for writable, and becomes readable after some
567 // time. 617 // time.
568 { 618 {
569 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher()); 619 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher());
570 ScopedVector<test::WaiterThread> threads; 620 ScopedVector<test::WaiterThread> threads;
571 for (uint32_t i = 0; i < kNumWaiters / 2; i++) { 621 for (uint32_t i = 0; i < kNumWaiters / 2; i++) {
572 threads.push_back(new test::WaiterThread( 622 threads.push_back(
573 d, MOJO_HANDLE_SIGNAL_READABLE, 623 new test::WaiterThread(d,
574 3 * test::EpsilonTimeout().InMicroseconds(), i, &did_wait[i], 624 MOJO_HANDLE_SIGNAL_READABLE,
575 &result[i], &context[i], &hss[i])); 625 3 * test::EpsilonTimeout().InMicroseconds(),
626 i,
627 &did_wait[i],
628 &result[i],
629 &context[i],
630 &hss[i]));
576 threads.back()->Start(); 631 threads.back()->Start();
577 } 632 }
578 for (uint32_t i = kNumWaiters / 2; i < kNumWaiters; i++) { 633 for (uint32_t i = kNumWaiters / 2; i < kNumWaiters; i++) {
579 threads.push_back(new test::WaiterThread( 634 threads.push_back(
580 d, MOJO_HANDLE_SIGNAL_WRITABLE, 635 new test::WaiterThread(d,
581 1 * test::EpsilonTimeout().InMicroseconds(), i, &did_wait[i], 636 MOJO_HANDLE_SIGNAL_WRITABLE,
582 &result[i], &context[i], &hss[i])); 637 1 * test::EpsilonTimeout().InMicroseconds(),
638 i,
639 &did_wait[i],
640 &result[i],
641 &context[i],
642 &hss[i]));
583 threads.back()->Start(); 643 threads.back()->Start();
584 } 644 }
585 base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); 645 base::PlatformThread::Sleep(2 * test::EpsilonTimeout());
586 d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_READABLE); 646 d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_READABLE);
587 // All those waiting for writable should have timed out. 647 // All those waiting for writable should have timed out.
588 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); 648 EXPECT_EQ(MOJO_RESULT_OK, d->Close());
589 } // Joins the threads. 649 } // Joins the threads.
590 for (uint32_t i = 0; i < kNumWaiters / 2; i++) { 650 for (uint32_t i = 0; i < kNumWaiters / 2; i++) {
591 EXPECT_TRUE(did_wait[i]) << i; 651 EXPECT_TRUE(did_wait[i]) << i;
592 EXPECT_EQ(MOJO_RESULT_OK, result[i]) << i; 652 EXPECT_EQ(MOJO_RESULT_OK, result[i]) << i;
593 EXPECT_EQ(i, context[i]) << i; 653 EXPECT_EQ(i, context[i]) << i;
594 // Since we closed before joining, we can't say much about what each thread 654 // Since we closed before joining, we can't say much about what each thread
595 // saw as the state. 655 // saw as the state.
596 } 656 }
597 for (uint32_t i = kNumWaiters / 2; i < kNumWaiters; i++) { 657 for (uint32_t i = kNumWaiters / 2; i < kNumWaiters; i++) {
598 EXPECT_TRUE(did_wait[i]) << i; 658 EXPECT_TRUE(did_wait[i]) << i;
599 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, result[i]) << i; 659 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, result[i]) << i;
600 // Since we closed before joining, we can't say much about what each thread 660 // Since we closed before joining, we can't say much about what each thread
601 // saw as the state. 661 // saw as the state.
602 } 662 }
603 } 663 }
604 664
605 // TODO(vtl): Stress test? 665 // TODO(vtl): Stress test?
606 666
607 } // namespace 667 } // namespace
608 } // namespace system 668 } // namespace system
609 } // namespace mojo 669 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/shared_buffer_dispatcher_unittest.cc ('k') | mojo/edk/system/test_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698