| 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::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 #include <memory> | 15 #include <memory> |
| 16 #include <utility> | 16 #include <utility> |
| 17 #include <vector> | 17 #include <vector> |
| 18 | 18 |
| 19 #include "base/memory/ref_counted.h" | |
| 20 #include "mojo/edk/system/message_pipe.h" | 19 #include "mojo/edk/system/message_pipe.h" |
| 20 #include "mojo/edk/system/ref_ptr.h" |
| 21 #include "mojo/edk/system/test_utils.h" | 21 #include "mojo/edk/system/test_utils.h" |
| 22 #include "mojo/edk/system/waiter.h" | 22 #include "mojo/edk/system/waiter.h" |
| 23 #include "mojo/edk/system/waiter_test_utils.h" | 23 #include "mojo/edk/system/waiter_test_utils.h" |
| 24 #include "mojo/edk/test/simple_test_thread.h" | 24 #include "mojo/edk/test/simple_test_thread.h" |
| 25 #include "mojo/edk/util/make_unique.h" | 25 #include "mojo/edk/util/make_unique.h" |
| 26 #include "mojo/public/cpp/system/macros.h" | 26 #include "mojo/public/cpp/system/macros.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| 28 | 28 |
| 29 namespace mojo { | 29 namespace mojo { |
| 30 namespace system { | 30 namespace system { |
| 31 namespace { | 31 namespace { |
| 32 | 32 |
| 33 const MojoHandleSignals kAllSignals = MOJO_HANDLE_SIGNAL_READABLE | | 33 const MojoHandleSignals kAllSignals = MOJO_HANDLE_SIGNAL_READABLE | |
| 34 MOJO_HANDLE_SIGNAL_WRITABLE | | 34 MOJO_HANDLE_SIGNAL_WRITABLE | |
| 35 MOJO_HANDLE_SIGNAL_PEER_CLOSED; | 35 MOJO_HANDLE_SIGNAL_PEER_CLOSED; |
| 36 | 36 |
| 37 TEST(MessagePipeDispatcherTest, Basic) { | 37 TEST(MessagePipeDispatcherTest, Basic) { |
| 38 test::Stopwatch stopwatch; | 38 test::Stopwatch stopwatch; |
| 39 int32_t buffer[1]; | 39 int32_t buffer[1]; |
| 40 const uint32_t kBufferSize = static_cast<uint32_t>(sizeof(buffer)); | 40 const uint32_t kBufferSize = static_cast<uint32_t>(sizeof(buffer)); |
| 41 uint32_t buffer_size; | 41 uint32_t buffer_size; |
| 42 | 42 |
| 43 // Run this test both with |d0| as port 0, |d1| as port 1 and vice versa. | 43 // Run this test both with |d0| as port 0, |d1| as port 1 and vice versa. |
| 44 for (unsigned i = 0; i < 2; i++) { | 44 for (unsigned i = 0; i < 2; i++) { |
| 45 scoped_refptr<MessagePipeDispatcher> d0 = MessagePipeDispatcher::Create( | 45 auto d0 = MessagePipeDispatcher::Create( |
| 46 MessagePipeDispatcher::kDefaultCreateOptions); | 46 MessagePipeDispatcher::kDefaultCreateOptions); |
| 47 EXPECT_EQ(Dispatcher::Type::MESSAGE_PIPE, d0->GetType()); | 47 EXPECT_EQ(Dispatcher::Type::MESSAGE_PIPE, d0->GetType()); |
| 48 scoped_refptr<MessagePipeDispatcher> d1 = MessagePipeDispatcher::Create( | 48 auto d1 = MessagePipeDispatcher::Create( |
| 49 MessagePipeDispatcher::kDefaultCreateOptions); | 49 MessagePipeDispatcher::kDefaultCreateOptions); |
| 50 { | 50 { |
| 51 auto mp = MessagePipe::CreateLocalLocal(); | 51 auto mp = MessagePipe::CreateLocalLocal(); |
| 52 d0->Init(mp.Clone(), i); // 0, 1. | 52 d0->Init(mp.Clone(), i); // 0, 1. |
| 53 d1->Init(std::move(mp), i ^ 1); // 1, 0. | 53 d1->Init(std::move(mp), i ^ 1); // 1, 0. |
| 54 } | 54 } |
| 55 Waiter w; | 55 Waiter w; |
| 56 uint32_t context = 0; | 56 uint32_t context = 0; |
| 57 HandleSignalsState hss; | 57 HandleSignalsState hss; |
| 58 | 58 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfied_signals); | 147 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfied_signals); |
| 148 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfiable_signals); | 148 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfiable_signals); |
| 149 | 149 |
| 150 EXPECT_EQ(MOJO_RESULT_OK, d0->Close()); | 150 EXPECT_EQ(MOJO_RESULT_OK, d0->Close()); |
| 151 } | 151 } |
| 152 } | 152 } |
| 153 | 153 |
| 154 TEST(MessagePipeDispatcherTest, InvalidParams) { | 154 TEST(MessagePipeDispatcherTest, InvalidParams) { |
| 155 char buffer[1]; | 155 char buffer[1]; |
| 156 | 156 |
| 157 scoped_refptr<MessagePipeDispatcher> d0 = MessagePipeDispatcher::Create( | 157 auto d0 = MessagePipeDispatcher::Create( |
| 158 MessagePipeDispatcher::kDefaultCreateOptions); | 158 MessagePipeDispatcher::kDefaultCreateOptions); |
| 159 scoped_refptr<MessagePipeDispatcher> d1 = MessagePipeDispatcher::Create( | 159 auto d1 = MessagePipeDispatcher::Create( |
| 160 MessagePipeDispatcher::kDefaultCreateOptions); | 160 MessagePipeDispatcher::kDefaultCreateOptions); |
| 161 { | 161 { |
| 162 auto mp = MessagePipe::CreateLocalLocal(); | 162 auto mp = MessagePipe::CreateLocalLocal(); |
| 163 d0->Init(mp.Clone(), 0); | 163 d0->Init(mp.Clone(), 0); |
| 164 d1->Init(std::move(mp), 1); | 164 d1->Init(std::move(mp), 1); |
| 165 } | 165 } |
| 166 | 166 |
| 167 // |WriteMessage|: | 167 // |WriteMessage|: |
| 168 // Huge buffer size. | 168 // Huge buffer size. |
| 169 EXPECT_EQ(MOJO_RESULT_RESOURCE_EXHAUSTED, | 169 EXPECT_EQ(MOJO_RESULT_RESOURCE_EXHAUSTED, |
| 170 d0->WriteMessage(UserPointer<const void>(buffer), | 170 d0->WriteMessage(UserPointer<const void>(buffer), |
| 171 std::numeric_limits<uint32_t>::max(), nullptr, | 171 std::numeric_limits<uint32_t>::max(), nullptr, |
| 172 MOJO_WRITE_MESSAGE_FLAG_NONE)); | 172 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
| 173 | 173 |
| 174 EXPECT_EQ(MOJO_RESULT_OK, d0->Close()); | 174 EXPECT_EQ(MOJO_RESULT_OK, d0->Close()); |
| 175 EXPECT_EQ(MOJO_RESULT_OK, d1->Close()); | 175 EXPECT_EQ(MOJO_RESULT_OK, d1->Close()); |
| 176 } | 176 } |
| 177 | 177 |
| 178 // These test invalid arguments that should cause death if we're being paranoid | 178 // These test invalid arguments that should cause death if we're being paranoid |
| 179 // about checking arguments (which we would want to do if, e.g., we were in a | 179 // about checking arguments (which we would want to do if, e.g., we were in a |
| 180 // true "kernel" situation, but we might not want to do otherwise for | 180 // true "kernel" situation, but we might not want to do otherwise for |
| 181 // performance reasons). Probably blatant errors like passing in null pointers | 181 // performance reasons). Probably blatant errors like passing in null pointers |
| 182 // (for required pointer arguments) will still cause death, but perhaps not | 182 // (for required pointer arguments) will still cause death, but perhaps not |
| 183 // predictably. | 183 // predictably. |
| 184 TEST(MessagePipeDispatcherTest, InvalidParamsDeath) { | 184 TEST(MessagePipeDispatcherTest, InvalidParamsDeath) { |
| 185 const char kMemoryCheckFailedRegex[] = "Check failed"; | 185 const char kMemoryCheckFailedRegex[] = "Check failed"; |
| 186 | 186 |
| 187 scoped_refptr<MessagePipeDispatcher> d0 = MessagePipeDispatcher::Create( | 187 auto d0 = MessagePipeDispatcher::Create( |
| 188 MessagePipeDispatcher::kDefaultCreateOptions); | 188 MessagePipeDispatcher::kDefaultCreateOptions); |
| 189 scoped_refptr<MessagePipeDispatcher> d1 = MessagePipeDispatcher::Create( | 189 auto d1 = MessagePipeDispatcher::Create( |
| 190 MessagePipeDispatcher::kDefaultCreateOptions); | 190 MessagePipeDispatcher::kDefaultCreateOptions); |
| 191 { | 191 { |
| 192 auto mp = MessagePipe::CreateLocalLocal(); | 192 auto mp = MessagePipe::CreateLocalLocal(); |
| 193 d0->Init(mp.Clone(), 0); | 193 d0->Init(mp.Clone(), 0); |
| 194 d1->Init(std::move(mp), 1); | 194 d1->Init(std::move(mp), 1); |
| 195 } | 195 } |
| 196 | 196 |
| 197 // |WriteMessage|: | 197 // |WriteMessage|: |
| 198 // Null buffer with nonzero buffer size. | 198 // Null buffer with nonzero buffer size. |
| 199 EXPECT_DEATH_IF_SUPPORTED(d0->WriteMessage(NullUserPointer(), 1, nullptr, | 199 EXPECT_DEATH_IF_SUPPORTED(d0->WriteMessage(NullUserPointer(), 1, nullptr, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 217 } | 217 } |
| 218 | 218 |
| 219 // Test what happens when one end is closed (single-threaded test). | 219 // Test what happens when one end is closed (single-threaded test). |
| 220 TEST(MessagePipeDispatcherTest, BasicClosed) { | 220 TEST(MessagePipeDispatcherTest, BasicClosed) { |
| 221 int32_t buffer[1]; | 221 int32_t buffer[1]; |
| 222 const uint32_t kBufferSize = static_cast<uint32_t>(sizeof(buffer)); | 222 const uint32_t kBufferSize = static_cast<uint32_t>(sizeof(buffer)); |
| 223 uint32_t buffer_size; | 223 uint32_t buffer_size; |
| 224 | 224 |
| 225 // Run this test both with |d0| as port 0, |d1| as port 1 and vice versa. | 225 // Run this test both with |d0| as port 0, |d1| as port 1 and vice versa. |
| 226 for (unsigned i = 0; i < 2; i++) { | 226 for (unsigned i = 0; i < 2; i++) { |
| 227 scoped_refptr<MessagePipeDispatcher> d0 = MessagePipeDispatcher::Create( | 227 auto d0 = MessagePipeDispatcher::Create( |
| 228 MessagePipeDispatcher::kDefaultCreateOptions); | 228 MessagePipeDispatcher::kDefaultCreateOptions); |
| 229 scoped_refptr<MessagePipeDispatcher> d1 = MessagePipeDispatcher::Create( | 229 auto d1 = MessagePipeDispatcher::Create( |
| 230 MessagePipeDispatcher::kDefaultCreateOptions); | 230 MessagePipeDispatcher::kDefaultCreateOptions); |
| 231 { | 231 { |
| 232 auto mp = MessagePipe::CreateLocalLocal(); | 232 auto mp = MessagePipe::CreateLocalLocal(); |
| 233 d0->Init(mp.Clone(), i); // 0, 1. | 233 d0->Init(mp.Clone(), i); // 0, 1. |
| 234 d1->Init(std::move(mp), i ^ 1); // 1, 0. | 234 d1->Init(std::move(mp), i ^ 1); // 1, 0. |
| 235 } | 235 } |
| 236 Waiter w; | 236 Waiter w; |
| 237 HandleSignalsState hss; | 237 HandleSignalsState hss; |
| 238 | 238 |
| 239 // Write (twice) to |d1|. | 239 // Write (twice) to |d1|. |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 const uint32_t kBufferSize = static_cast<uint32_t>(sizeof(buffer)); | 347 const uint32_t kBufferSize = static_cast<uint32_t>(sizeof(buffer)); |
| 348 uint32_t buffer_size; | 348 uint32_t buffer_size; |
| 349 MojoDeadline elapsed; | 349 MojoDeadline elapsed; |
| 350 bool did_wait; | 350 bool did_wait; |
| 351 MojoResult result; | 351 MojoResult result; |
| 352 uint32_t context; | 352 uint32_t context; |
| 353 HandleSignalsState hss; | 353 HandleSignalsState hss; |
| 354 | 354 |
| 355 // Run this test both with |d0| as port 0, |d1| as port 1 and vice versa. | 355 // Run this test both with |d0| as port 0, |d1| as port 1 and vice versa. |
| 356 for (unsigned i = 0; i < 2; i++) { | 356 for (unsigned i = 0; i < 2; i++) { |
| 357 scoped_refptr<MessagePipeDispatcher> d0 = MessagePipeDispatcher::Create( | 357 auto d0 = MessagePipeDispatcher::Create( |
| 358 MessagePipeDispatcher::kDefaultCreateOptions); | 358 MessagePipeDispatcher::kDefaultCreateOptions); |
| 359 scoped_refptr<MessagePipeDispatcher> d1 = MessagePipeDispatcher::Create( | 359 auto d1 = MessagePipeDispatcher::Create( |
| 360 MessagePipeDispatcher::kDefaultCreateOptions); | 360 MessagePipeDispatcher::kDefaultCreateOptions); |
| 361 { | 361 { |
| 362 auto mp = MessagePipe::CreateLocalLocal(); | 362 auto mp = MessagePipe::CreateLocalLocal(); |
| 363 d0->Init(mp.Clone(), i); // 0, 1. | 363 d0->Init(mp.Clone(), i); // 0, 1. |
| 364 d1->Init(std::move(mp), i ^ 1); // 1, 0. | 364 d1->Init(std::move(mp), i ^ 1); // 1, 0. |
| 365 } | 365 } |
| 366 | 366 |
| 367 // Wait for readable on |d1|, which will become readable after some time. | 367 // Wait for readable on |d1|, which will become readable after some time. |
| 368 { | 368 { |
| 369 test::WaiterThread thread(d1, MOJO_HANDLE_SIGNAL_READABLE, | 369 test::WaiterThread thread(d1, MOJO_HANDLE_SIGNAL_READABLE, |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 EXPECT_TRUE(did_wait); | 430 EXPECT_TRUE(did_wait); |
| 431 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result); | 431 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result); |
| 432 EXPECT_EQ(3u, context); | 432 EXPECT_EQ(3u, context); |
| 433 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfied_signals); | 433 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfied_signals); |
| 434 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfiable_signals); | 434 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfiable_signals); |
| 435 | 435 |
| 436 EXPECT_EQ(MOJO_RESULT_OK, d1->Close()); | 436 EXPECT_EQ(MOJO_RESULT_OK, d1->Close()); |
| 437 } | 437 } |
| 438 | 438 |
| 439 for (unsigned i = 0; i < 2; i++) { | 439 for (unsigned i = 0; i < 2; i++) { |
| 440 scoped_refptr<MessagePipeDispatcher> d0 = MessagePipeDispatcher::Create( | 440 auto d0 = MessagePipeDispatcher::Create( |
| 441 MessagePipeDispatcher::kDefaultCreateOptions); | 441 MessagePipeDispatcher::kDefaultCreateOptions); |
| 442 scoped_refptr<MessagePipeDispatcher> d1 = MessagePipeDispatcher::Create( | 442 auto d1 = MessagePipeDispatcher::Create( |
| 443 MessagePipeDispatcher::kDefaultCreateOptions); | 443 MessagePipeDispatcher::kDefaultCreateOptions); |
| 444 { | 444 { |
| 445 auto mp = MessagePipe::CreateLocalLocal(); | 445 auto mp = MessagePipe::CreateLocalLocal(); |
| 446 d0->Init(mp.Clone(), i); // 0, 1. | 446 d0->Init(mp.Clone(), i); // 0, 1. |
| 447 d1->Init(std::move(mp), i ^ 1); // 1, 0. | 447 d1->Init(std::move(mp), i ^ 1); // 1, 0. |
| 448 } | 448 } |
| 449 | 449 |
| 450 // Wait for readable on |d1| and close |d1| after some time, which should | 450 // Wait for readable on |d1| and close |d1| after some time, which should |
| 451 // cancel that wait. | 451 // cancel that wait. |
| 452 { | 452 { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 472 } | 472 } |
| 473 | 473 |
| 474 // Stress test ----------------------------------------------------------------- | 474 // Stress test ----------------------------------------------------------------- |
| 475 | 475 |
| 476 const size_t kMaxMessageSize = 2000; | 476 const size_t kMaxMessageSize = 2000; |
| 477 | 477 |
| 478 class WriterThread : public mojo::test::SimpleTestThread { | 478 class WriterThread : public mojo::test::SimpleTestThread { |
| 479 public: | 479 public: |
| 480 // |*messages_written| and |*bytes_written| belong to the thread while it's | 480 // |*messages_written| and |*bytes_written| belong to the thread while it's |
| 481 // alive. | 481 // alive. |
| 482 WriterThread(scoped_refptr<Dispatcher> write_dispatcher, | 482 WriterThread(RefPtr<Dispatcher> write_dispatcher, |
| 483 size_t* messages_written, | 483 size_t* messages_written, |
| 484 size_t* bytes_written) | 484 size_t* bytes_written) |
| 485 : write_dispatcher_(write_dispatcher), | 485 : write_dispatcher_(write_dispatcher), |
| 486 messages_written_(messages_written), | 486 messages_written_(messages_written), |
| 487 bytes_written_(bytes_written) { | 487 bytes_written_(bytes_written) { |
| 488 *messages_written_ = 0; | 488 *messages_written_ = 0; |
| 489 *bytes_written_ = 0; | 489 *bytes_written_ = 0; |
| 490 } | 490 } |
| 491 | 491 |
| 492 ~WriterThread() override { Join(); } | 492 ~WriterThread() override { Join(); } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 511 MOJO_WRITE_MESSAGE_FLAG_NONE)); | 511 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
| 512 *bytes_written_ += bytes_to_write; | 512 *bytes_written_ += bytes_to_write; |
| 513 } | 513 } |
| 514 | 514 |
| 515 // Write one last "quit" message. | 515 // Write one last "quit" message. |
| 516 EXPECT_EQ(MOJO_RESULT_OK, write_dispatcher_->WriteMessage( | 516 EXPECT_EQ(MOJO_RESULT_OK, write_dispatcher_->WriteMessage( |
| 517 UserPointer<const void>("quit"), 4, nullptr, | 517 UserPointer<const void>("quit"), 4, nullptr, |
| 518 MOJO_WRITE_MESSAGE_FLAG_NONE)); | 518 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
| 519 } | 519 } |
| 520 | 520 |
| 521 const scoped_refptr<Dispatcher> write_dispatcher_; | 521 const RefPtr<Dispatcher> write_dispatcher_; |
| 522 size_t* const messages_written_; | 522 size_t* const messages_written_; |
| 523 size_t* const bytes_written_; | 523 size_t* const bytes_written_; |
| 524 | 524 |
| 525 MOJO_DISALLOW_COPY_AND_ASSIGN(WriterThread); | 525 MOJO_DISALLOW_COPY_AND_ASSIGN(WriterThread); |
| 526 }; | 526 }; |
| 527 | 527 |
| 528 class ReaderThread : public mojo::test::SimpleTestThread { | 528 class ReaderThread : public mojo::test::SimpleTestThread { |
| 529 public: | 529 public: |
| 530 // |*messages_read| and |*bytes_read| belong to the thread while it's alive. | 530 // |*messages_read| and |*bytes_read| belong to the thread while it's alive. |
| 531 ReaderThread(scoped_refptr<Dispatcher> read_dispatcher, | 531 ReaderThread(RefPtr<Dispatcher> read_dispatcher, |
| 532 size_t* messages_read, | 532 size_t* messages_read, |
| 533 size_t* bytes_read) | 533 size_t* bytes_read) |
| 534 : read_dispatcher_(read_dispatcher), | 534 : read_dispatcher_(read_dispatcher), |
| 535 messages_read_(messages_read), | 535 messages_read_(messages_read), |
| 536 bytes_read_(bytes_read) { | 536 bytes_read_(bytes_read) { |
| 537 *messages_read_ = 0; | 537 *messages_read_ = 0; |
| 538 *bytes_read_ = 0; | 538 *bytes_read_ = 0; |
| 539 } | 539 } |
| 540 | 540 |
| 541 ~ReaderThread() override { Join(); } | 541 ~ReaderThread() override { Join(); } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 return false; | 597 return false; |
| 598 } | 598 } |
| 599 // Check that the remaining bytes weren't stomped on. | 599 // Check that the remaining bytes weren't stomped on. |
| 600 for (; i < kMaxMessageSize; i++) { | 600 for (; i < kMaxMessageSize; i++) { |
| 601 if (buffer[i] != 0) | 601 if (buffer[i] != 0) |
| 602 return false; | 602 return false; |
| 603 } | 603 } |
| 604 return true; | 604 return true; |
| 605 } | 605 } |
| 606 | 606 |
| 607 const scoped_refptr<Dispatcher> read_dispatcher_; | 607 const RefPtr<Dispatcher> read_dispatcher_; |
| 608 size_t* const messages_read_; | 608 size_t* const messages_read_; |
| 609 size_t* const bytes_read_; | 609 size_t* const bytes_read_; |
| 610 | 610 |
| 611 MOJO_DISALLOW_COPY_AND_ASSIGN(ReaderThread); | 611 MOJO_DISALLOW_COPY_AND_ASSIGN(ReaderThread); |
| 612 }; | 612 }; |
| 613 | 613 |
| 614 TEST(MessagePipeDispatcherTest, Stress) { | 614 TEST(MessagePipeDispatcherTest, Stress) { |
| 615 static const size_t kNumWriters = 30; | 615 static const size_t kNumWriters = 30; |
| 616 static const size_t kNumReaders = kNumWriters; | 616 static const size_t kNumReaders = kNumWriters; |
| 617 | 617 |
| 618 scoped_refptr<MessagePipeDispatcher> d_write = MessagePipeDispatcher::Create( | 618 auto d_write = MessagePipeDispatcher::Create( |
| 619 MessagePipeDispatcher::kDefaultCreateOptions); | 619 MessagePipeDispatcher::kDefaultCreateOptions); |
| 620 scoped_refptr<MessagePipeDispatcher> d_read = MessagePipeDispatcher::Create( | 620 auto d_read = MessagePipeDispatcher::Create( |
| 621 MessagePipeDispatcher::kDefaultCreateOptions); | 621 MessagePipeDispatcher::kDefaultCreateOptions); |
| 622 { | 622 { |
| 623 auto mp = MessagePipe::CreateLocalLocal(); | 623 auto mp = MessagePipe::CreateLocalLocal(); |
| 624 d_write->Init(mp.Clone(), 0); | 624 d_write->Init(mp.Clone(), 0); |
| 625 d_read->Init(std::move(mp), 1); | 625 d_read->Init(std::move(mp), 1); |
| 626 } | 626 } |
| 627 | 627 |
| 628 size_t messages_written[kNumWriters]; | 628 size_t messages_written[kNumWriters]; |
| 629 size_t bytes_written[kNumWriters]; | 629 size_t bytes_written[kNumWriters]; |
| 630 size_t messages_read[kNumReaders]; | 630 size_t messages_read[kNumReaders]; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 EXPECT_EQ(total_messages_written, total_messages_read); | 675 EXPECT_EQ(total_messages_written, total_messages_read); |
| 676 EXPECT_EQ(total_bytes_written, total_bytes_read); | 676 EXPECT_EQ(total_bytes_written, total_bytes_read); |
| 677 | 677 |
| 678 EXPECT_EQ(MOJO_RESULT_OK, d_write->Close()); | 678 EXPECT_EQ(MOJO_RESULT_OK, d_write->Close()); |
| 679 EXPECT_EQ(MOJO_RESULT_OK, d_read->Close()); | 679 EXPECT_EQ(MOJO_RESULT_OK, d_read->Close()); |
| 680 } | 680 } |
| 681 | 681 |
| 682 } // namespace | 682 } // namespace |
| 683 } // namespace system | 683 } // namespace system |
| 684 } // namespace mojo | 684 } // namespace mojo |
| OLD | NEW |