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