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

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

Issue 505863002: Mojo: Add static factory functions to MessagePipe. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 6 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
« no previous file with comments | « mojo/system/message_pipe_dispatcher.cc ('k') | mojo/system/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 // 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/system/message_pipe_dispatcher.h" 10 #include "mojo/system/message_pipe_dispatcher.h"
(...skipping 25 matching lines...) Expand all
36 uint32_t buffer_size; 36 uint32_t buffer_size;
37 37
38 // Run this test both with |d0| as port 0, |d1| as port 1 and vice versa. 38 // Run this test both with |d0| as port 0, |d1| as port 1 and vice versa.
39 for (unsigned i = 0; i < 2; i++) { 39 for (unsigned i = 0; i < 2; i++) {
40 scoped_refptr<MessagePipeDispatcher> d0(new MessagePipeDispatcher( 40 scoped_refptr<MessagePipeDispatcher> d0(new MessagePipeDispatcher(
41 MessagePipeDispatcher::kDefaultCreateOptions)); 41 MessagePipeDispatcher::kDefaultCreateOptions));
42 EXPECT_EQ(Dispatcher::kTypeMessagePipe, d0->GetType()); 42 EXPECT_EQ(Dispatcher::kTypeMessagePipe, d0->GetType());
43 scoped_refptr<MessagePipeDispatcher> d1(new MessagePipeDispatcher( 43 scoped_refptr<MessagePipeDispatcher> d1(new MessagePipeDispatcher(
44 MessagePipeDispatcher::kDefaultCreateOptions)); 44 MessagePipeDispatcher::kDefaultCreateOptions));
45 { 45 {
46 scoped_refptr<MessagePipe> mp(new MessagePipe()); 46 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalLocal());
47 d0->Init(mp, i); // 0, 1. 47 d0->Init(mp, i); // 0, 1.
48 d1->Init(mp, i ^ 1); // 1, 0. 48 d1->Init(mp, i ^ 1); // 1, 0.
49 } 49 }
50 Waiter w; 50 Waiter w;
51 uint32_t context = 0; 51 uint32_t context = 0;
52 HandleSignalsState hss; 52 HandleSignalsState hss;
53 53
54 // Try adding a writable waiter when already writable. 54 // Try adding a writable waiter when already writable.
55 w.Init(); 55 w.Init();
56 hss = HandleSignalsState(); 56 hss = HandleSignalsState();
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 } 141 }
142 142
143 TEST(MessagePipeDispatcherTest, InvalidParams) { 143 TEST(MessagePipeDispatcherTest, InvalidParams) {
144 char buffer[1]; 144 char buffer[1];
145 145
146 scoped_refptr<MessagePipeDispatcher> d0( 146 scoped_refptr<MessagePipeDispatcher> d0(
147 new MessagePipeDispatcher(MessagePipeDispatcher::kDefaultCreateOptions)); 147 new MessagePipeDispatcher(MessagePipeDispatcher::kDefaultCreateOptions));
148 scoped_refptr<MessagePipeDispatcher> d1( 148 scoped_refptr<MessagePipeDispatcher> d1(
149 new MessagePipeDispatcher(MessagePipeDispatcher::kDefaultCreateOptions)); 149 new MessagePipeDispatcher(MessagePipeDispatcher::kDefaultCreateOptions));
150 { 150 {
151 scoped_refptr<MessagePipe> mp(new MessagePipe()); 151 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalLocal());
152 d0->Init(mp, 0); 152 d0->Init(mp, 0);
153 d1->Init(mp, 1); 153 d1->Init(mp, 1);
154 } 154 }
155 155
156 // |WriteMessage|: 156 // |WriteMessage|:
157 // Huge buffer size. 157 // Huge buffer size.
158 EXPECT_EQ(MOJO_RESULT_RESOURCE_EXHAUSTED, 158 EXPECT_EQ(MOJO_RESULT_RESOURCE_EXHAUSTED,
159 d0->WriteMessage(UserPointer<const void>(buffer), 159 d0->WriteMessage(UserPointer<const void>(buffer),
160 std::numeric_limits<uint32_t>::max(), 160 std::numeric_limits<uint32_t>::max(),
161 NULL, 161 NULL,
(...skipping 10 matching lines...) Expand all
172 // (for required pointer arguments) will still cause death, but perhaps not 172 // (for required pointer arguments) will still cause death, but perhaps not
173 // predictably. 173 // predictably.
174 TEST(MessagePipeDispatcherTest, InvalidParamsDeath) { 174 TEST(MessagePipeDispatcherTest, InvalidParamsDeath) {
175 const char kMemoryCheckFailedRegex[] = "Check failed"; 175 const char kMemoryCheckFailedRegex[] = "Check failed";
176 176
177 scoped_refptr<MessagePipeDispatcher> d0( 177 scoped_refptr<MessagePipeDispatcher> d0(
178 new MessagePipeDispatcher(MessagePipeDispatcher::kDefaultCreateOptions)); 178 new MessagePipeDispatcher(MessagePipeDispatcher::kDefaultCreateOptions));
179 scoped_refptr<MessagePipeDispatcher> d1( 179 scoped_refptr<MessagePipeDispatcher> d1(
180 new MessagePipeDispatcher(MessagePipeDispatcher::kDefaultCreateOptions)); 180 new MessagePipeDispatcher(MessagePipeDispatcher::kDefaultCreateOptions));
181 { 181 {
182 scoped_refptr<MessagePipe> mp(new MessagePipe()); 182 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalLocal());
183 d0->Init(mp, 0); 183 d0->Init(mp, 0);
184 d1->Init(mp, 1); 184 d1->Init(mp, 1);
185 } 185 }
186 186
187 // |WriteMessage|: 187 // |WriteMessage|:
188 // Null buffer with nonzero buffer size. 188 // Null buffer with nonzero buffer size.
189 EXPECT_DEATH_IF_SUPPORTED( 189 EXPECT_DEATH_IF_SUPPORTED(
190 d0->WriteMessage( 190 d0->WriteMessage(
191 NullUserPointer(), 1, NULL, MOJO_WRITE_MESSAGE_FLAG_NONE), 191 NullUserPointer(), 1, NULL, MOJO_WRITE_MESSAGE_FLAG_NONE),
192 kMemoryCheckFailedRegex); 192 kMemoryCheckFailedRegex);
(...skipping 23 matching lines...) Expand all
216 const uint32_t kBufferSize = static_cast<uint32_t>(sizeof(buffer)); 216 const uint32_t kBufferSize = static_cast<uint32_t>(sizeof(buffer));
217 uint32_t buffer_size; 217 uint32_t buffer_size;
218 218
219 // Run this test both with |d0| as port 0, |d1| as port 1 and vice versa. 219 // Run this test both with |d0| as port 0, |d1| as port 1 and vice versa.
220 for (unsigned i = 0; i < 2; i++) { 220 for (unsigned i = 0; i < 2; i++) {
221 scoped_refptr<MessagePipeDispatcher> d0(new MessagePipeDispatcher( 221 scoped_refptr<MessagePipeDispatcher> d0(new MessagePipeDispatcher(
222 MessagePipeDispatcher::kDefaultCreateOptions)); 222 MessagePipeDispatcher::kDefaultCreateOptions));
223 scoped_refptr<MessagePipeDispatcher> d1(new MessagePipeDispatcher( 223 scoped_refptr<MessagePipeDispatcher> d1(new MessagePipeDispatcher(
224 MessagePipeDispatcher::kDefaultCreateOptions)); 224 MessagePipeDispatcher::kDefaultCreateOptions));
225 { 225 {
226 scoped_refptr<MessagePipe> mp(new MessagePipe()); 226 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalLocal());
227 d0->Init(mp, i); // 0, 1. 227 d0->Init(mp, i); // 0, 1.
228 d1->Init(mp, i ^ 1); // 1, 0. 228 d1->Init(mp, i ^ 1); // 1, 0.
229 } 229 }
230 Waiter w; 230 Waiter w;
231 HandleSignalsState hss; 231 HandleSignalsState hss;
232 232
233 // Write (twice) to |d1|. 233 // Write (twice) to |d1|.
234 buffer[0] = 123456789; 234 buffer[0] = 123456789;
235 EXPECT_EQ(MOJO_RESULT_OK, 235 EXPECT_EQ(MOJO_RESULT_OK,
236 d1->WriteMessage(UserPointer<const void>(buffer), 236 d1->WriteMessage(UserPointer<const void>(buffer),
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 uint32_t context; 363 uint32_t context;
364 HandleSignalsState hss; 364 HandleSignalsState hss;
365 365
366 // Run this test both with |d0| as port 0, |d1| as port 1 and vice versa. 366 // Run this test both with |d0| as port 0, |d1| as port 1 and vice versa.
367 for (unsigned i = 0; i < 2; i++) { 367 for (unsigned i = 0; i < 2; i++) {
368 scoped_refptr<MessagePipeDispatcher> d0(new MessagePipeDispatcher( 368 scoped_refptr<MessagePipeDispatcher> d0(new MessagePipeDispatcher(
369 MessagePipeDispatcher::kDefaultCreateOptions)); 369 MessagePipeDispatcher::kDefaultCreateOptions));
370 scoped_refptr<MessagePipeDispatcher> d1(new MessagePipeDispatcher( 370 scoped_refptr<MessagePipeDispatcher> d1(new MessagePipeDispatcher(
371 MessagePipeDispatcher::kDefaultCreateOptions)); 371 MessagePipeDispatcher::kDefaultCreateOptions));
372 { 372 {
373 scoped_refptr<MessagePipe> mp(new MessagePipe()); 373 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalLocal());
374 d0->Init(mp, i); // 0, 1. 374 d0->Init(mp, i); // 0, 1.
375 d1->Init(mp, i ^ 1); // 1, 0. 375 d1->Init(mp, i ^ 1); // 1, 0.
376 } 376 }
377 377
378 // Wait for readable on |d1|, which will become readable after some time. 378 // Wait for readable on |d1|, which will become readable after some time.
379 { 379 {
380 test::WaiterThread thread(d1, 380 test::WaiterThread thread(d1,
381 MOJO_HANDLE_SIGNAL_READABLE, 381 MOJO_HANDLE_SIGNAL_READABLE,
382 MOJO_DEADLINE_INDEFINITE, 382 MOJO_DEADLINE_INDEFINITE,
383 1, 383 1,
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 467
468 EXPECT_EQ(MOJO_RESULT_OK, d1->Close()); 468 EXPECT_EQ(MOJO_RESULT_OK, d1->Close());
469 } 469 }
470 470
471 for (unsigned i = 0; i < 2; i++) { 471 for (unsigned i = 0; i < 2; i++) {
472 scoped_refptr<MessagePipeDispatcher> d0(new MessagePipeDispatcher( 472 scoped_refptr<MessagePipeDispatcher> d0(new MessagePipeDispatcher(
473 MessagePipeDispatcher::kDefaultCreateOptions)); 473 MessagePipeDispatcher::kDefaultCreateOptions));
474 scoped_refptr<MessagePipeDispatcher> d1(new MessagePipeDispatcher( 474 scoped_refptr<MessagePipeDispatcher> d1(new MessagePipeDispatcher(
475 MessagePipeDispatcher::kDefaultCreateOptions)); 475 MessagePipeDispatcher::kDefaultCreateOptions));
476 { 476 {
477 scoped_refptr<MessagePipe> mp(new MessagePipe()); 477 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalLocal());
478 d0->Init(mp, i); // 0, 1. 478 d0->Init(mp, i); // 0, 1.
479 d1->Init(mp, i ^ 1); // 1, 0. 479 d1->Init(mp, i ^ 1); // 1, 0.
480 } 480 }
481 481
482 // Wait for readable on |d1| and close |d1| after some time, which should 482 // Wait for readable on |d1| and close |d1| after some time, which should
483 // cancel that wait. 483 // cancel that wait.
484 { 484 {
485 test::WaiterThread thread(d1, 485 test::WaiterThread thread(d1,
486 MOJO_HANDLE_SIGNAL_READABLE, 486 MOJO_HANDLE_SIGNAL_READABLE,
487 MOJO_DEADLINE_INDEFINITE, 487 MOJO_DEADLINE_INDEFINITE,
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 657
658 TEST(MessagePipeDispatcherTest, Stress) { 658 TEST(MessagePipeDispatcherTest, Stress) {
659 static const size_t kNumWriters = 30; 659 static const size_t kNumWriters = 30;
660 static const size_t kNumReaders = kNumWriters; 660 static const size_t kNumReaders = kNumWriters;
661 661
662 scoped_refptr<MessagePipeDispatcher> d_write( 662 scoped_refptr<MessagePipeDispatcher> d_write(
663 new MessagePipeDispatcher(MessagePipeDispatcher::kDefaultCreateOptions)); 663 new MessagePipeDispatcher(MessagePipeDispatcher::kDefaultCreateOptions));
664 scoped_refptr<MessagePipeDispatcher> d_read( 664 scoped_refptr<MessagePipeDispatcher> d_read(
665 new MessagePipeDispatcher(MessagePipeDispatcher::kDefaultCreateOptions)); 665 new MessagePipeDispatcher(MessagePipeDispatcher::kDefaultCreateOptions));
666 { 666 {
667 scoped_refptr<MessagePipe> mp(new MessagePipe()); 667 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalLocal());
668 d_write->Init(mp, 0); 668 d_write->Init(mp, 0);
669 d_read->Init(mp, 1); 669 d_read->Init(mp, 1);
670 } 670 }
671 671
672 size_t messages_written[kNumWriters]; 672 size_t messages_written[kNumWriters];
673 size_t bytes_written[kNumWriters]; 673 size_t bytes_written[kNumWriters];
674 size_t messages_read[kNumReaders]; 674 size_t messages_read[kNumReaders];
675 size_t bytes_read[kNumReaders]; 675 size_t bytes_read[kNumReaders];
676 { 676 {
677 // Make writers. 677 // Make writers.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 EXPECT_EQ(total_messages_written, total_messages_read); 719 EXPECT_EQ(total_messages_written, total_messages_read);
720 EXPECT_EQ(total_bytes_written, total_bytes_read); 720 EXPECT_EQ(total_bytes_written, total_bytes_read);
721 721
722 EXPECT_EQ(MOJO_RESULT_OK, d_write->Close()); 722 EXPECT_EQ(MOJO_RESULT_OK, d_write->Close());
723 EXPECT_EQ(MOJO_RESULT_OK, d_read->Close()); 723 EXPECT_EQ(MOJO_RESULT_OK, d_read->Close());
724 } 724 }
725 725
726 } // namespace 726 } // namespace
727 } // namespace system 727 } // namespace system
728 } // namespace mojo 728 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/system/message_pipe_dispatcher.cc ('k') | mojo/system/message_pipe_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698