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

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

Issue 1361143004: EDK: Add a mojo::test::SimpleTestThread (and use it). (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 3 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
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::EpsilonDeadline()| may be increased to 6 // heavily-loaded system). Sorry. |test::EpsilonDeadline()| 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/message_pipe_dispatcher.h" 10 #include "mojo/edk/system/message_pipe_dispatcher.h"
11 11
12 #include <string.h> 12 #include <string.h>
13 13
14 #include <limits> 14 #include <limits>
15 15
16 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
17 #include "base/memory/scoped_vector.h" 17 #include "base/memory/scoped_vector.h"
18 #include "base/threading/simple_thread.h"
19 #include "mojo/edk/system/message_pipe.h" 18 #include "mojo/edk/system/message_pipe.h"
20 #include "mojo/edk/system/test_utils.h" 19 #include "mojo/edk/system/test_utils.h"
21 #include "mojo/edk/system/waiter.h" 20 #include "mojo/edk/system/waiter.h"
22 #include "mojo/edk/system/waiter_test_utils.h" 21 #include "mojo/edk/system/waiter_test_utils.h"
22 #include "mojo/edk/test/simple_test_thread.h"
23 #include "mojo/public/cpp/system/macros.h" 23 #include "mojo/public/cpp/system/macros.h"
24 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
25 25
26 namespace mojo { 26 namespace mojo {
27 namespace system { 27 namespace system {
28 namespace { 28 namespace {
29 29
30 const MojoHandleSignals kAllSignals = MOJO_HANDLE_SIGNAL_READABLE | 30 const MojoHandleSignals kAllSignals = MOJO_HANDLE_SIGNAL_READABLE |
31 MOJO_HANDLE_SIGNAL_WRITABLE | 31 MOJO_HANDLE_SIGNAL_WRITABLE |
32 MOJO_HANDLE_SIGNAL_PEER_CLOSED; 32 MOJO_HANDLE_SIGNAL_PEER_CLOSED;
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 EXPECT_EQ(0u, hss.satisfiable_signals); 465 EXPECT_EQ(0u, hss.satisfiable_signals);
466 466
467 EXPECT_EQ(MOJO_RESULT_OK, d0->Close()); 467 EXPECT_EQ(MOJO_RESULT_OK, d0->Close());
468 } 468 }
469 } 469 }
470 470
471 // Stress test ----------------------------------------------------------------- 471 // Stress test -----------------------------------------------------------------
472 472
473 const size_t kMaxMessageSize = 2000; 473 const size_t kMaxMessageSize = 2000;
474 474
475 class WriterThread : public base::SimpleThread { 475 class WriterThread : public mojo::test::SimpleTestThread {
476 public: 476 public:
477 // |*messages_written| and |*bytes_written| belong to the thread while it's 477 // |*messages_written| and |*bytes_written| belong to the thread while it's
478 // alive. 478 // alive.
479 WriterThread(scoped_refptr<Dispatcher> write_dispatcher, 479 WriterThread(scoped_refptr<Dispatcher> write_dispatcher,
480 size_t* messages_written, 480 size_t* messages_written,
481 size_t* bytes_written) 481 size_t* bytes_written)
482 : base::SimpleThread("writer_thread"), 482 : write_dispatcher_(write_dispatcher),
483 write_dispatcher_(write_dispatcher),
484 messages_written_(messages_written), 483 messages_written_(messages_written),
485 bytes_written_(bytes_written) { 484 bytes_written_(bytes_written) {
486 *messages_written_ = 0; 485 *messages_written_ = 0;
487 *bytes_written_ = 0; 486 *bytes_written_ = 0;
488 } 487 }
489 488
490 ~WriterThread() override { Join(); } 489 ~WriterThread() override { Join(); }
491 490
492 private: 491 private:
493 void Run() override { 492 void Run() override {
(...skipping 22 matching lines...) Expand all
516 MOJO_WRITE_MESSAGE_FLAG_NONE)); 515 MOJO_WRITE_MESSAGE_FLAG_NONE));
517 } 516 }
518 517
519 const scoped_refptr<Dispatcher> write_dispatcher_; 518 const scoped_refptr<Dispatcher> write_dispatcher_;
520 size_t* const messages_written_; 519 size_t* const messages_written_;
521 size_t* const bytes_written_; 520 size_t* const bytes_written_;
522 521
523 MOJO_DISALLOW_COPY_AND_ASSIGN(WriterThread); 522 MOJO_DISALLOW_COPY_AND_ASSIGN(WriterThread);
524 }; 523 };
525 524
526 class ReaderThread : public base::SimpleThread { 525 class ReaderThread : public mojo::test::SimpleTestThread {
527 public: 526 public:
528 // |*messages_read| and |*bytes_read| belong to the thread while it's alive. 527 // |*messages_read| and |*bytes_read| belong to the thread while it's alive.
529 ReaderThread(scoped_refptr<Dispatcher> read_dispatcher, 528 ReaderThread(scoped_refptr<Dispatcher> read_dispatcher,
530 size_t* messages_read, 529 size_t* messages_read,
531 size_t* bytes_read) 530 size_t* bytes_read)
532 : base::SimpleThread("reader_thread"), 531 : read_dispatcher_(read_dispatcher),
533 read_dispatcher_(read_dispatcher),
534 messages_read_(messages_read), 532 messages_read_(messages_read),
535 bytes_read_(bytes_read) { 533 bytes_read_(bytes_read) {
536 *messages_read_ = 0; 534 *messages_read_ = 0;
537 *bytes_read_ = 0; 535 *bytes_read_ = 0;
538 } 536 }
539 537
540 ~ReaderThread() override { Join(); } 538 ~ReaderThread() override { Join(); }
541 539
542 private: 540 private:
543 void Run() override { 541 void Run() override {
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 EXPECT_EQ(total_messages_written, total_messages_read); 672 EXPECT_EQ(total_messages_written, total_messages_read);
675 EXPECT_EQ(total_bytes_written, total_bytes_read); 673 EXPECT_EQ(total_bytes_written, total_bytes_read);
676 674
677 EXPECT_EQ(MOJO_RESULT_OK, d_write->Close()); 675 EXPECT_EQ(MOJO_RESULT_OK, d_write->Close());
678 EXPECT_EQ(MOJO_RESULT_OK, d_read->Close()); 676 EXPECT_EQ(MOJO_RESULT_OK, d_read->Close());
679 } 677 }
680 678
681 } // namespace 679 } // namespace
682 } // namespace system 680 } // namespace system
683 } // namespace mojo 681 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698