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

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

Issue 728553002: 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/raw_channel_win.cc ('k') | mojo/edk/system/run_all_unittests.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include <stdint.h> 5 #include <stdint.h>
6 #include <stdio.h> 6 #include <stdio.h>
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <vector> 9 #include <vector>
10 10
(...skipping 30 matching lines...) Expand all
41 namespace system { 41 namespace system {
42 namespace { 42 namespace {
43 43
44 class RemoteMessagePipeTest : public testing::Test { 44 class RemoteMessagePipeTest : public testing::Test {
45 public: 45 public:
46 RemoteMessagePipeTest() : io_thread_(base::TestIOThread::kAutoStart) {} 46 RemoteMessagePipeTest() : io_thread_(base::TestIOThread::kAutoStart) {}
47 ~RemoteMessagePipeTest() override {} 47 ~RemoteMessagePipeTest() override {}
48 48
49 void SetUp() override { 49 void SetUp() override {
50 io_thread_.PostTaskAndWait( 50 io_thread_.PostTaskAndWait(
51 FROM_HERE, 51 FROM_HERE, base::Bind(&RemoteMessagePipeTest::SetUpOnIOThread,
52 base::Bind(&RemoteMessagePipeTest::SetUpOnIOThread, 52 base::Unretained(this)));
53 base::Unretained(this)));
54 } 53 }
55 54
56 void TearDown() override { 55 void TearDown() override {
57 io_thread_.PostTaskAndWait( 56 io_thread_.PostTaskAndWait(
58 FROM_HERE, 57 FROM_HERE, base::Bind(&RemoteMessagePipeTest::TearDownOnIOThread,
59 base::Bind(&RemoteMessagePipeTest::TearDownOnIOThread, 58 base::Unretained(this)));
60 base::Unretained(this)));
61 } 59 }
62 60
63 protected: 61 protected:
64 // This connects the two given |ChannelEndpoint|s. It assumes/requires that 62 // This connects the two given |ChannelEndpoint|s. It assumes/requires that
65 // this is the bootstrap case (i.e., no other message pipes have ever been 63 // this is the bootstrap case (i.e., no other message pipes have ever been
66 // hosted on the channel). 64 // hosted on the channel).
67 void BootstrapChannelEndpoints(scoped_refptr<ChannelEndpoint> ep0, 65 void BootstrapChannelEndpoints(scoped_refptr<ChannelEndpoint> ep0,
68 scoped_refptr<ChannelEndpoint> ep1) { 66 scoped_refptr<ChannelEndpoint> ep1) {
69 io_thread_.PostTaskAndWait( 67 io_thread_.PostTaskAndWait(
70 FROM_HERE, 68 FROM_HERE,
71 base::Bind(&RemoteMessagePipeTest::BootstrapChannelEndpointsOnIOThread, 69 base::Bind(&RemoteMessagePipeTest::BootstrapChannelEndpointsOnIOThread,
72 base::Unretained(this), 70 base::Unretained(this), ep0, ep1));
73 ep0,
74 ep1));
75 } 71 }
76 72
77 // This bootstraps |ep| on |channels_[channel_index]|. It assumes/requires 73 // This bootstraps |ep| on |channels_[channel_index]|. It assumes/requires
78 // that this is the bootstrap case (i.e., no message pipes have ever been 74 // that this is the bootstrap case (i.e., no message pipes have ever been
79 // hosted on the channel). This returns *without* waiting. 75 // hosted on the channel). This returns *without* waiting.
80 void BootstrapChannelEndpointNoWait(unsigned channel_index, 76 void BootstrapChannelEndpointNoWait(unsigned channel_index,
81 scoped_refptr<ChannelEndpoint> ep) { 77 scoped_refptr<ChannelEndpoint> ep) {
82 io_thread_.PostTask( 78 io_thread_.PostTask(
83 FROM_HERE, 79 FROM_HERE,
84 base::Bind(&RemoteMessagePipeTest::BootstrapChannelEndpointOnIOThread, 80 base::Bind(&RemoteMessagePipeTest::BootstrapChannelEndpointOnIOThread,
85 base::Unretained(this), 81 base::Unretained(this), channel_index, ep));
86 channel_index,
87 ep));
88 } 82 }
89 83
90 void RestoreInitialState() { 84 void RestoreInitialState() {
91 io_thread_.PostTaskAndWait( 85 io_thread_.PostTaskAndWait(
92 FROM_HERE, 86 FROM_HERE,
93 base::Bind(&RemoteMessagePipeTest::RestoreInitialStateOnIOThread, 87 base::Bind(&RemoteMessagePipeTest::RestoreInitialStateOnIOThread,
94 base::Unretained(this))); 88 base::Unretained(this)));
95 } 89 }
96 90
97 embedder::PlatformSupport* platform_support() { return &platform_support_; } 91 embedder::PlatformSupport* platform_support() { return &platform_support_; }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 // Write in one direction: MP 0, port 0 -> ... -> MP 1, port 1. 185 // Write in one direction: MP 0, port 0 -> ... -> MP 1, port 1.
192 186
193 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do 187 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do
194 // it later, it might already be readable.) 188 // it later, it might already be readable.)
195 waiter.Init(); 189 waiter.Init();
196 ASSERT_EQ( 190 ASSERT_EQ(
197 MOJO_RESULT_OK, 191 MOJO_RESULT_OK,
198 mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); 192 mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr));
199 193
200 // Write to MP 0, port 0. 194 // Write to MP 0, port 0.
201 EXPECT_EQ(MOJO_RESULT_OK, 195 EXPECT_EQ(
202 mp0->WriteMessage(0, 196 MOJO_RESULT_OK,
203 UserPointer<const void>(kHello), 197 mp0->WriteMessage(0, UserPointer<const void>(kHello), sizeof(kHello),
204 sizeof(kHello), 198 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
205 nullptr,
206 MOJO_WRITE_MESSAGE_FLAG_NONE));
207 199
208 // Wait. 200 // Wait.
209 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); 201 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context));
210 EXPECT_EQ(123u, context); 202 EXPECT_EQ(123u, context);
211 hss = HandleSignalsState(); 203 hss = HandleSignalsState();
212 mp1->RemoveWaiter(1, &waiter, &hss); 204 mp1->RemoveWaiter(1, &waiter, &hss);
213 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 205 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
214 hss.satisfied_signals); 206 hss.satisfied_signals);
215 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 207 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
216 hss.satisfiable_signals); 208 hss.satisfiable_signals);
217 209
218 // Read from MP 1, port 1. 210 // Read from MP 1, port 1.
219 EXPECT_EQ(MOJO_RESULT_OK, 211 EXPECT_EQ(MOJO_RESULT_OK,
220 mp1->ReadMessage(1, 212 mp1->ReadMessage(1, UserPointer<void>(buffer),
221 UserPointer<void>(buffer), 213 MakeUserPointer(&buffer_size), nullptr, nullptr,
222 MakeUserPointer(&buffer_size),
223 nullptr,
224 nullptr,
225 MOJO_READ_MESSAGE_FLAG_NONE)); 214 MOJO_READ_MESSAGE_FLAG_NONE));
226 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(buffer_size)); 215 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(buffer_size));
227 EXPECT_STREQ(kHello, buffer); 216 EXPECT_STREQ(kHello, buffer);
228 217
229 // Write in the other direction: MP 1, port 1 -> ... -> MP 0, port 0. 218 // Write in the other direction: MP 1, port 1 -> ... -> MP 0, port 0.
230 219
231 waiter.Init(); 220 waiter.Init();
232 ASSERT_EQ( 221 ASSERT_EQ(
233 MOJO_RESULT_OK, 222 MOJO_RESULT_OK,
234 mp0->AddWaiter(0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 456, nullptr)); 223 mp0->AddWaiter(0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 456, nullptr));
235 224
236 EXPECT_EQ(MOJO_RESULT_OK, 225 EXPECT_EQ(
237 mp1->WriteMessage(1, 226 MOJO_RESULT_OK,
238 UserPointer<const void>(kWorld), 227 mp1->WriteMessage(1, UserPointer<const void>(kWorld), sizeof(kWorld),
239 sizeof(kWorld), 228 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
240 nullptr,
241 MOJO_WRITE_MESSAGE_FLAG_NONE));
242 229
243 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); 230 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context));
244 EXPECT_EQ(456u, context); 231 EXPECT_EQ(456u, context);
245 hss = HandleSignalsState(); 232 hss = HandleSignalsState();
246 mp0->RemoveWaiter(0, &waiter, &hss); 233 mp0->RemoveWaiter(0, &waiter, &hss);
247 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 234 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
248 hss.satisfied_signals); 235 hss.satisfied_signals);
249 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 236 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
250 hss.satisfiable_signals); 237 hss.satisfiable_signals);
251 238
252 buffer_size = static_cast<uint32_t>(sizeof(buffer)); 239 buffer_size = static_cast<uint32_t>(sizeof(buffer));
253 EXPECT_EQ(MOJO_RESULT_OK, 240 EXPECT_EQ(MOJO_RESULT_OK,
254 mp0->ReadMessage(0, 241 mp0->ReadMessage(0, UserPointer<void>(buffer),
255 UserPointer<void>(buffer), 242 MakeUserPointer(&buffer_size), nullptr, nullptr,
256 MakeUserPointer(&buffer_size),
257 nullptr,
258 nullptr,
259 MOJO_READ_MESSAGE_FLAG_NONE)); 243 MOJO_READ_MESSAGE_FLAG_NONE));
260 EXPECT_EQ(sizeof(kWorld), static_cast<size_t>(buffer_size)); 244 EXPECT_EQ(sizeof(kWorld), static_cast<size_t>(buffer_size));
261 EXPECT_STREQ(kWorld, buffer); 245 EXPECT_STREQ(kWorld, buffer);
262 246
263 // Close MP 0, port 0. 247 // Close MP 0, port 0.
264 mp0->Close(0); 248 mp0->Close(0);
265 249
266 // Try to wait for MP 1, port 1 to become readable. This will eventually fail 250 // Try to wait for MP 1, port 1 to become readable. This will eventually fail
267 // when it realizes that MP 0, port 0 has been closed. (It may also fail 251 // when it realizes that MP 0, port 0 has been closed. (It may also fail
268 // immediately.) 252 // immediately.)
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 ASSERT_TRUE(channels(0)); 297 ASSERT_TRUE(channels(0));
314 ChannelEndpointId remote_id = channels(0)->AttachAndRunEndpoint(ep2, false); 298 ChannelEndpointId remote_id = channels(0)->AttachAndRunEndpoint(ep2, false);
315 EXPECT_TRUE(remote_id.is_remote()); 299 EXPECT_TRUE(remote_id.is_remote());
316 300
317 waiter.Init(); 301 waiter.Init();
318 ASSERT_EQ( 302 ASSERT_EQ(
319 MOJO_RESULT_OK, 303 MOJO_RESULT_OK,
320 mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); 304 mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr));
321 305
322 EXPECT_EQ(MOJO_RESULT_OK, 306 EXPECT_EQ(MOJO_RESULT_OK,
323 mp0->WriteMessage(0, 307 mp0->WriteMessage(0, UserPointer<const void>(&remote_id),
324 UserPointer<const void>(&remote_id), 308 sizeof(remote_id), nullptr,
325 sizeof(remote_id),
326 nullptr,
327 MOJO_WRITE_MESSAGE_FLAG_NONE)); 309 MOJO_WRITE_MESSAGE_FLAG_NONE));
328 310
329 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); 311 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context));
330 EXPECT_EQ(123u, context); 312 EXPECT_EQ(123u, context);
331 hss = HandleSignalsState(); 313 hss = HandleSignalsState();
332 mp1->RemoveWaiter(1, &waiter, &hss); 314 mp1->RemoveWaiter(1, &waiter, &hss);
333 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 315 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
334 hss.satisfied_signals); 316 hss.satisfied_signals);
335 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 317 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
336 hss.satisfiable_signals); 318 hss.satisfiable_signals);
337 319
338 ChannelEndpointId received_id; 320 ChannelEndpointId received_id;
339 buffer_size = static_cast<uint32_t>(sizeof(received_id)); 321 buffer_size = static_cast<uint32_t>(sizeof(received_id));
340 EXPECT_EQ(MOJO_RESULT_OK, 322 EXPECT_EQ(MOJO_RESULT_OK,
341 mp1->ReadMessage(1, 323 mp1->ReadMessage(1, UserPointer<void>(&received_id),
342 UserPointer<void>(&received_id), 324 MakeUserPointer(&buffer_size), nullptr, nullptr,
343 MakeUserPointer(&buffer_size),
344 nullptr,
345 nullptr,
346 MOJO_READ_MESSAGE_FLAG_NONE)); 325 MOJO_READ_MESSAGE_FLAG_NONE));
347 EXPECT_EQ(sizeof(received_id), static_cast<size_t>(buffer_size)); 326 EXPECT_EQ(sizeof(received_id), static_cast<size_t>(buffer_size));
348 EXPECT_EQ(remote_id, received_id); 327 EXPECT_EQ(remote_id, received_id);
349 328
350 // Warning: The local side of mp3 is port 0, not port 1. 329 // Warning: The local side of mp3 is port 0, not port 1.
351 scoped_refptr<MessagePipe> mp3 = 330 scoped_refptr<MessagePipe> mp3 =
352 channels(1)->PassIncomingMessagePipe(received_id); 331 channels(1)->PassIncomingMessagePipe(received_id);
353 ASSERT_TRUE(mp3.get()); 332 ASSERT_TRUE(mp3.get());
354 333
355 // Write: MP 2, port 0 -> MP 3, port 1. 334 // Write: MP 2, port 0 -> MP 3, port 1.
356 335
357 waiter.Init(); 336 waiter.Init();
358 ASSERT_EQ( 337 ASSERT_EQ(
359 MOJO_RESULT_OK, 338 MOJO_RESULT_OK,
360 mp3->AddWaiter(0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 789, nullptr)); 339 mp3->AddWaiter(0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 789, nullptr));
361 340
362 EXPECT_EQ(MOJO_RESULT_OK, 341 EXPECT_EQ(
363 mp2->WriteMessage(0, 342 MOJO_RESULT_OK,
364 UserPointer<const void>(kHello), 343 mp2->WriteMessage(0, UserPointer<const void>(kHello), sizeof(kHello),
365 sizeof(kHello), 344 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
366 nullptr,
367 MOJO_WRITE_MESSAGE_FLAG_NONE));
368 345
369 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); 346 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context));
370 EXPECT_EQ(789u, context); 347 EXPECT_EQ(789u, context);
371 hss = HandleSignalsState(); 348 hss = HandleSignalsState();
372 mp3->RemoveWaiter(0, &waiter, &hss); 349 mp3->RemoveWaiter(0, &waiter, &hss);
373 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 350 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
374 hss.satisfied_signals); 351 hss.satisfied_signals);
375 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 352 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
376 hss.satisfiable_signals); 353 hss.satisfiable_signals);
377 354
378 // Make sure there's nothing on MP 0, port 0 or MP 1, port 1 or MP 2, port 0. 355 // Make sure there's nothing on MP 0, port 0 or MP 1, port 1 or MP 2, port 0.
379 buffer_size = static_cast<uint32_t>(sizeof(buffer)); 356 buffer_size = static_cast<uint32_t>(sizeof(buffer));
380 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT, 357 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT,
381 mp0->ReadMessage(0, 358 mp0->ReadMessage(0, UserPointer<void>(buffer),
382 UserPointer<void>(buffer), 359 MakeUserPointer(&buffer_size), nullptr, nullptr,
383 MakeUserPointer(&buffer_size),
384 nullptr,
385 nullptr,
386 MOJO_READ_MESSAGE_FLAG_NONE)); 360 MOJO_READ_MESSAGE_FLAG_NONE));
387 buffer_size = static_cast<uint32_t>(sizeof(buffer)); 361 buffer_size = static_cast<uint32_t>(sizeof(buffer));
388 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT, 362 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT,
389 mp1->ReadMessage(1, 363 mp1->ReadMessage(1, UserPointer<void>(buffer),
390 UserPointer<void>(buffer), 364 MakeUserPointer(&buffer_size), nullptr, nullptr,
391 MakeUserPointer(&buffer_size),
392 nullptr,
393 nullptr,
394 MOJO_READ_MESSAGE_FLAG_NONE)); 365 MOJO_READ_MESSAGE_FLAG_NONE));
395 buffer_size = static_cast<uint32_t>(sizeof(buffer)); 366 buffer_size = static_cast<uint32_t>(sizeof(buffer));
396 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT, 367 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT,
397 mp2->ReadMessage(0, 368 mp2->ReadMessage(0, UserPointer<void>(buffer),
398 UserPointer<void>(buffer), 369 MakeUserPointer(&buffer_size), nullptr, nullptr,
399 MakeUserPointer(&buffer_size),
400 nullptr,
401 nullptr,
402 MOJO_READ_MESSAGE_FLAG_NONE)); 370 MOJO_READ_MESSAGE_FLAG_NONE));
403 371
404 // Read from MP 3, port 1. 372 // Read from MP 3, port 1.
405 buffer_size = static_cast<uint32_t>(sizeof(buffer)); 373 buffer_size = static_cast<uint32_t>(sizeof(buffer));
406 EXPECT_EQ(MOJO_RESULT_OK, 374 EXPECT_EQ(MOJO_RESULT_OK,
407 mp3->ReadMessage(0, 375 mp3->ReadMessage(0, UserPointer<void>(buffer),
408 UserPointer<void>(buffer), 376 MakeUserPointer(&buffer_size), nullptr, nullptr,
409 MakeUserPointer(&buffer_size),
410 nullptr,
411 nullptr,
412 MOJO_READ_MESSAGE_FLAG_NONE)); 377 MOJO_READ_MESSAGE_FLAG_NONE));
413 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(buffer_size)); 378 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(buffer_size));
414 EXPECT_STREQ(kHello, buffer); 379 EXPECT_STREQ(kHello, buffer);
415 380
416 // Write: MP 0, port 0 -> MP 1, port 1 again. 381 // Write: MP 0, port 0 -> MP 1, port 1 again.
417 382
418 waiter.Init(); 383 waiter.Init();
419 ASSERT_EQ( 384 ASSERT_EQ(
420 MOJO_RESULT_OK, 385 MOJO_RESULT_OK,
421 mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); 386 mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr));
422 387
423 EXPECT_EQ(MOJO_RESULT_OK, 388 EXPECT_EQ(
424 mp0->WriteMessage(0, 389 MOJO_RESULT_OK,
425 UserPointer<const void>(kWorld), 390 mp0->WriteMessage(0, UserPointer<const void>(kWorld), sizeof(kWorld),
426 sizeof(kWorld), 391 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
427 nullptr,
428 MOJO_WRITE_MESSAGE_FLAG_NONE));
429 392
430 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); 393 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context));
431 EXPECT_EQ(123u, context); 394 EXPECT_EQ(123u, context);
432 hss = HandleSignalsState(); 395 hss = HandleSignalsState();
433 mp1->RemoveWaiter(1, &waiter, &hss); 396 mp1->RemoveWaiter(1, &waiter, &hss);
434 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 397 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
435 hss.satisfied_signals); 398 hss.satisfied_signals);
436 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 399 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
437 hss.satisfiable_signals); 400 hss.satisfiable_signals);
438 401
439 // Make sure there's nothing on the other ports. 402 // Make sure there's nothing on the other ports.
440 buffer_size = static_cast<uint32_t>(sizeof(buffer)); 403 buffer_size = static_cast<uint32_t>(sizeof(buffer));
441 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT, 404 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT,
442 mp0->ReadMessage(0, 405 mp0->ReadMessage(0, UserPointer<void>(buffer),
443 UserPointer<void>(buffer), 406 MakeUserPointer(&buffer_size), nullptr, nullptr,
444 MakeUserPointer(&buffer_size),
445 nullptr,
446 nullptr,
447 MOJO_READ_MESSAGE_FLAG_NONE)); 407 MOJO_READ_MESSAGE_FLAG_NONE));
448 buffer_size = static_cast<uint32_t>(sizeof(buffer)); 408 buffer_size = static_cast<uint32_t>(sizeof(buffer));
449 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT, 409 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT,
450 mp2->ReadMessage(0, 410 mp2->ReadMessage(0, UserPointer<void>(buffer),
451 UserPointer<void>(buffer), 411 MakeUserPointer(&buffer_size), nullptr, nullptr,
452 MakeUserPointer(&buffer_size),
453 nullptr,
454 nullptr,
455 MOJO_READ_MESSAGE_FLAG_NONE)); 412 MOJO_READ_MESSAGE_FLAG_NONE));
456 buffer_size = static_cast<uint32_t>(sizeof(buffer)); 413 buffer_size = static_cast<uint32_t>(sizeof(buffer));
457 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT, 414 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT,
458 mp3->ReadMessage(0, 415 mp3->ReadMessage(0, UserPointer<void>(buffer),
459 UserPointer<void>(buffer), 416 MakeUserPointer(&buffer_size), nullptr, nullptr,
460 MakeUserPointer(&buffer_size),
461 nullptr,
462 nullptr,
463 MOJO_READ_MESSAGE_FLAG_NONE)); 417 MOJO_READ_MESSAGE_FLAG_NONE));
464 418
465 buffer_size = static_cast<uint32_t>(sizeof(buffer)); 419 buffer_size = static_cast<uint32_t>(sizeof(buffer));
466 EXPECT_EQ(MOJO_RESULT_OK, 420 EXPECT_EQ(MOJO_RESULT_OK,
467 mp1->ReadMessage(1, 421 mp1->ReadMessage(1, UserPointer<void>(buffer),
468 UserPointer<void>(buffer), 422 MakeUserPointer(&buffer_size), nullptr, nullptr,
469 MakeUserPointer(&buffer_size),
470 nullptr,
471 nullptr,
472 MOJO_READ_MESSAGE_FLAG_NONE)); 423 MOJO_READ_MESSAGE_FLAG_NONE));
473 EXPECT_EQ(sizeof(kWorld), static_cast<size_t>(buffer_size)); 424 EXPECT_EQ(sizeof(kWorld), static_cast<size_t>(buffer_size));
474 EXPECT_STREQ(kWorld, buffer); 425 EXPECT_STREQ(kWorld, buffer);
475 426
476 mp0->Close(0); 427 mp0->Close(0);
477 mp1->Close(1); 428 mp1->Close(1);
478 mp2->Close(0); 429 mp2->Close(0);
479 mp3->Close(0); 430 mp3->Close(0);
480 } 431 }
481 432
482 TEST_F(RemoteMessagePipeTest, CloseBeforeAttachAndRun) { 433 TEST_F(RemoteMessagePipeTest, CloseBeforeAttachAndRun) {
483 static const char kHello[] = "hello"; 434 static const char kHello[] = "hello";
484 char buffer[100] = {0}; 435 char buffer[100] = {0};
485 uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer)); 436 uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer));
486 Waiter waiter; 437 Waiter waiter;
487 HandleSignalsState hss; 438 HandleSignalsState hss;
488 uint32_t context = 0; 439 uint32_t context = 0;
489 440
490 // Connect message pipes. MP 0, port 1 will be attached to channel 0 and 441 // Connect message pipes. MP 0, port 1 will be attached to channel 0 and
491 // connected to MP 1, port 0, which will be attached to channel 1. This leaves 442 // connected to MP 1, port 0, which will be attached to channel 1. This leaves
492 // MP 0, port 0 and MP 1, port 1 as the "user-facing" endpoints. 443 // MP 0, port 0 and MP 1, port 1 as the "user-facing" endpoints.
493 444
494 scoped_refptr<ChannelEndpoint> ep0; 445 scoped_refptr<ChannelEndpoint> ep0;
495 scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy(&ep0)); 446 scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy(&ep0));
496 447
497 // Write to MP 0, port 0. 448 // Write to MP 0, port 0.
498 EXPECT_EQ(MOJO_RESULT_OK, 449 EXPECT_EQ(
499 mp0->WriteMessage(0, 450 MOJO_RESULT_OK,
500 UserPointer<const void>(kHello), 451 mp0->WriteMessage(0, UserPointer<const void>(kHello), sizeof(kHello),
501 sizeof(kHello), 452 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
502 nullptr,
503 MOJO_WRITE_MESSAGE_FLAG_NONE));
504 453
505 // Close MP 0, port 0 before it's even been attached to the channel and run. 454 // Close MP 0, port 0 before it's even been attached to the channel and run.
506 mp0->Close(0); 455 mp0->Close(0);
507 456
508 BootstrapChannelEndpointNoWait(0, ep0); 457 BootstrapChannelEndpointNoWait(0, ep0);
509 458
510 scoped_refptr<ChannelEndpoint> ep1; 459 scoped_refptr<ChannelEndpoint> ep1;
511 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1)); 460 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1));
512 461
513 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do 462 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do
(...skipping 12 matching lines...) Expand all
526 // Note: MP 1, port 1 should definitely should be readable, but it may or may 475 // Note: MP 1, port 1 should definitely should be readable, but it may or may
527 // not appear as writable (there's a race, and it may not have noticed that 476 // not appear as writable (there's a race, and it may not have noticed that
528 // the other side was closed yet -- e.g., inserting a sleep here would make it 477 // the other side was closed yet -- e.g., inserting a sleep here would make it
529 // much more likely to notice that it's no longer writable). 478 // much more likely to notice that it's no longer writable).
530 mp1->RemoveWaiter(1, &waiter, &hss); 479 mp1->RemoveWaiter(1, &waiter, &hss);
531 EXPECT_TRUE((hss.satisfied_signals & MOJO_HANDLE_SIGNAL_READABLE)); 480 EXPECT_TRUE((hss.satisfied_signals & MOJO_HANDLE_SIGNAL_READABLE));
532 EXPECT_TRUE((hss.satisfiable_signals & MOJO_HANDLE_SIGNAL_READABLE)); 481 EXPECT_TRUE((hss.satisfiable_signals & MOJO_HANDLE_SIGNAL_READABLE));
533 482
534 // Read from MP 1, port 1. 483 // Read from MP 1, port 1.
535 EXPECT_EQ(MOJO_RESULT_OK, 484 EXPECT_EQ(MOJO_RESULT_OK,
536 mp1->ReadMessage(1, 485 mp1->ReadMessage(1, UserPointer<void>(buffer),
537 UserPointer<void>(buffer), 486 MakeUserPointer(&buffer_size), nullptr, nullptr,
538 MakeUserPointer(&buffer_size),
539 nullptr,
540 nullptr,
541 MOJO_READ_MESSAGE_FLAG_NONE)); 487 MOJO_READ_MESSAGE_FLAG_NONE));
542 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(buffer_size)); 488 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(buffer_size));
543 EXPECT_STREQ(kHello, buffer); 489 EXPECT_STREQ(kHello, buffer);
544 490
545 // And MP 1, port 1. 491 // And MP 1, port 1.
546 mp1->Close(1); 492 mp1->Close(1);
547 } 493 }
548 494
549 TEST_F(RemoteMessagePipeTest, CloseBeforeConnect) { 495 TEST_F(RemoteMessagePipeTest, CloseBeforeConnect) {
550 static const char kHello[] = "hello"; 496 static const char kHello[] = "hello";
551 char buffer[100] = {0}; 497 char buffer[100] = {0};
552 uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer)); 498 uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer));
553 Waiter waiter; 499 Waiter waiter;
554 HandleSignalsState hss; 500 HandleSignalsState hss;
555 uint32_t context = 0; 501 uint32_t context = 0;
556 502
557 // Connect message pipes. MP 0, port 1 will be attached to channel 0 and 503 // Connect message pipes. MP 0, port 1 will be attached to channel 0 and
558 // connected to MP 1, port 0, which will be attached to channel 1. This leaves 504 // connected to MP 1, port 0, which will be attached to channel 1. This leaves
559 // MP 0, port 0 and MP 1, port 1 as the "user-facing" endpoints. 505 // MP 0, port 0 and MP 1, port 1 as the "user-facing" endpoints.
560 506
561 scoped_refptr<ChannelEndpoint> ep0; 507 scoped_refptr<ChannelEndpoint> ep0;
562 scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy(&ep0)); 508 scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy(&ep0));
563 509
564 // Write to MP 0, port 0. 510 // Write to MP 0, port 0.
565 EXPECT_EQ(MOJO_RESULT_OK, 511 EXPECT_EQ(
566 mp0->WriteMessage(0, 512 MOJO_RESULT_OK,
567 UserPointer<const void>(kHello), 513 mp0->WriteMessage(0, UserPointer<const void>(kHello), sizeof(kHello),
568 sizeof(kHello), 514 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
569 nullptr,
570 MOJO_WRITE_MESSAGE_FLAG_NONE));
571 515
572 BootstrapChannelEndpointNoWait(0, ep0); 516 BootstrapChannelEndpointNoWait(0, ep0);
573 517
574 // Close MP 0, port 0 before channel 1 is even connected. 518 // Close MP 0, port 0 before channel 1 is even connected.
575 mp0->Close(0); 519 mp0->Close(0);
576 520
577 scoped_refptr<ChannelEndpoint> ep1; 521 scoped_refptr<ChannelEndpoint> ep1;
578 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1)); 522 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1));
579 523
580 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do 524 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do
(...skipping 12 matching lines...) Expand all
593 // Note: MP 1, port 1 should definitely should be readable, but it may or may 537 // Note: MP 1, port 1 should definitely should be readable, but it may or may
594 // not appear as writable (there's a race, and it may not have noticed that 538 // not appear as writable (there's a race, and it may not have noticed that
595 // the other side was closed yet -- e.g., inserting a sleep here would make it 539 // the other side was closed yet -- e.g., inserting a sleep here would make it
596 // much more likely to notice that it's no longer writable). 540 // much more likely to notice that it's no longer writable).
597 mp1->RemoveWaiter(1, &waiter, &hss); 541 mp1->RemoveWaiter(1, &waiter, &hss);
598 EXPECT_TRUE((hss.satisfied_signals & MOJO_HANDLE_SIGNAL_READABLE)); 542 EXPECT_TRUE((hss.satisfied_signals & MOJO_HANDLE_SIGNAL_READABLE));
599 EXPECT_TRUE((hss.satisfiable_signals & MOJO_HANDLE_SIGNAL_READABLE)); 543 EXPECT_TRUE((hss.satisfiable_signals & MOJO_HANDLE_SIGNAL_READABLE));
600 544
601 // Read from MP 1, port 1. 545 // Read from MP 1, port 1.
602 EXPECT_EQ(MOJO_RESULT_OK, 546 EXPECT_EQ(MOJO_RESULT_OK,
603 mp1->ReadMessage(1, 547 mp1->ReadMessage(1, UserPointer<void>(buffer),
604 UserPointer<void>(buffer), 548 MakeUserPointer(&buffer_size), nullptr, nullptr,
605 MakeUserPointer(&buffer_size),
606 nullptr,
607 nullptr,
608 MOJO_READ_MESSAGE_FLAG_NONE)); 549 MOJO_READ_MESSAGE_FLAG_NONE));
609 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(buffer_size)); 550 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(buffer_size));
610 EXPECT_STREQ(kHello, buffer); 551 EXPECT_STREQ(kHello, buffer);
611 552
612 // And MP 1, port 1. 553 // And MP 1, port 1.
613 mp1->Close(1); 554 mp1->Close(1);
614 } 555 }
615 556
616 TEST_F(RemoteMessagePipeTest, HandlePassing) { 557 TEST_F(RemoteMessagePipeTest, HandlePassing) {
617 static const char kHello[] = "hello"; 558 static const char kHello[] = "hello";
(...skipping 21 matching lines...) Expand all
639 mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); 580 mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr));
640 581
641 // Write to MP 0, port 0. 582 // Write to MP 0, port 0.
642 { 583 {
643 DispatcherTransport transport( 584 DispatcherTransport transport(
644 test::DispatcherTryStartTransport(dispatcher.get())); 585 test::DispatcherTryStartTransport(dispatcher.get()));
645 EXPECT_TRUE(transport.is_valid()); 586 EXPECT_TRUE(transport.is_valid());
646 587
647 std::vector<DispatcherTransport> transports; 588 std::vector<DispatcherTransport> transports;
648 transports.push_back(transport); 589 transports.push_back(transport);
649 EXPECT_EQ(MOJO_RESULT_OK, 590 EXPECT_EQ(
650 mp0->WriteMessage(0, 591 MOJO_RESULT_OK,
651 UserPointer<const void>(kHello), 592 mp0->WriteMessage(0, UserPointer<const void>(kHello), sizeof(kHello),
652 sizeof(kHello), 593 &transports, MOJO_WRITE_MESSAGE_FLAG_NONE));
653 &transports,
654 MOJO_WRITE_MESSAGE_FLAG_NONE));
655 transport.End(); 594 transport.End();
656 595
657 // |dispatcher| should have been closed. This is |DCHECK()|ed when the 596 // |dispatcher| should have been closed. This is |DCHECK()|ed when the
658 // |dispatcher| is destroyed. 597 // |dispatcher| is destroyed.
659 EXPECT_TRUE(dispatcher->HasOneRef()); 598 EXPECT_TRUE(dispatcher->HasOneRef());
660 dispatcher = nullptr; 599 dispatcher = nullptr;
661 } 600 }
662 601
663 // Wait. 602 // Wait.
664 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); 603 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context));
665 EXPECT_EQ(123u, context); 604 EXPECT_EQ(123u, context);
666 hss = HandleSignalsState(); 605 hss = HandleSignalsState();
667 mp1->RemoveWaiter(1, &waiter, &hss); 606 mp1->RemoveWaiter(1, &waiter, &hss);
668 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 607 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
669 hss.satisfied_signals); 608 hss.satisfied_signals);
670 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 609 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
671 hss.satisfiable_signals); 610 hss.satisfiable_signals);
672 611
673 // Read from MP 1, port 1. 612 // Read from MP 1, port 1.
674 char read_buffer[100] = {0}; 613 char read_buffer[100] = {0};
675 uint32_t read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer)); 614 uint32_t read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer));
676 DispatcherVector read_dispatchers; 615 DispatcherVector read_dispatchers;
677 uint32_t read_num_dispatchers = 10; // Maximum to get. 616 uint32_t read_num_dispatchers = 10; // Maximum to get.
678 EXPECT_EQ(MOJO_RESULT_OK, 617 EXPECT_EQ(
679 mp1->ReadMessage(1, 618 MOJO_RESULT_OK,
680 UserPointer<void>(read_buffer), 619 mp1->ReadMessage(1, UserPointer<void>(read_buffer),
681 MakeUserPointer(&read_buffer_size), 620 MakeUserPointer(&read_buffer_size), &read_dispatchers,
682 &read_dispatchers, 621 &read_num_dispatchers, MOJO_READ_MESSAGE_FLAG_NONE));
683 &read_num_dispatchers,
684 MOJO_READ_MESSAGE_FLAG_NONE));
685 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size)); 622 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size));
686 EXPECT_STREQ(kHello, read_buffer); 623 EXPECT_STREQ(kHello, read_buffer);
687 EXPECT_EQ(1u, read_dispatchers.size()); 624 EXPECT_EQ(1u, read_dispatchers.size());
688 EXPECT_EQ(1u, read_num_dispatchers); 625 EXPECT_EQ(1u, read_num_dispatchers);
689 ASSERT_TRUE(read_dispatchers[0].get()); 626 ASSERT_TRUE(read_dispatchers[0].get());
690 EXPECT_TRUE(read_dispatchers[0]->HasOneRef()); 627 EXPECT_TRUE(read_dispatchers[0]->HasOneRef());
691 628
692 EXPECT_EQ(Dispatcher::kTypeMessagePipe, read_dispatchers[0]->GetType()); 629 EXPECT_EQ(Dispatcher::kTypeMessagePipe, read_dispatchers[0]->GetType());
693 dispatcher = static_cast<MessagePipeDispatcher*>(read_dispatchers[0].get()); 630 dispatcher = static_cast<MessagePipeDispatcher*>(read_dispatchers[0].get());
694 631
695 // Add the waiter now, before it becomes readable to avoid a race. 632 // Add the waiter now, before it becomes readable to avoid a race.
696 waiter.Init(); 633 waiter.Init();
697 ASSERT_EQ(MOJO_RESULT_OK, 634 ASSERT_EQ(MOJO_RESULT_OK,
698 dispatcher->AddWaiter( 635 dispatcher->AddWaiter(&waiter, MOJO_HANDLE_SIGNAL_READABLE, 456,
699 &waiter, MOJO_HANDLE_SIGNAL_READABLE, 456, nullptr)); 636 nullptr));
700 637
701 // Write to "local_mp", port 1. 638 // Write to "local_mp", port 1.
702 EXPECT_EQ(MOJO_RESULT_OK, 639 EXPECT_EQ(
703 local_mp->WriteMessage(1, 640 MOJO_RESULT_OK,
704 UserPointer<const void>(kHello), 641 local_mp->WriteMessage(1, UserPointer<const void>(kHello), sizeof(kHello),
705 sizeof(kHello), 642 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
706 nullptr,
707 MOJO_WRITE_MESSAGE_FLAG_NONE));
708 643
709 // TODO(vtl): FIXME -- We (racily) crash if I close |dispatcher| immediately 644 // TODO(vtl): FIXME -- We (racily) crash if I close |dispatcher| immediately
710 // here. (We don't crash if I sleep and then close.) 645 // here. (We don't crash if I sleep and then close.)
711 646
712 // Wait for the dispatcher to become readable. 647 // Wait for the dispatcher to become readable.
713 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); 648 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context));
714 EXPECT_EQ(456u, context); 649 EXPECT_EQ(456u, context);
715 hss = HandleSignalsState(); 650 hss = HandleSignalsState();
716 dispatcher->RemoveWaiter(&waiter, &hss); 651 dispatcher->RemoveWaiter(&waiter, &hss);
717 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 652 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
718 hss.satisfied_signals); 653 hss.satisfied_signals);
719 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 654 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
720 hss.satisfiable_signals); 655 hss.satisfiable_signals);
721 656
722 // Read from the dispatcher. 657 // Read from the dispatcher.
723 memset(read_buffer, 0, sizeof(read_buffer)); 658 memset(read_buffer, 0, sizeof(read_buffer));
724 read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer)); 659 read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer));
725 EXPECT_EQ(MOJO_RESULT_OK, 660 EXPECT_EQ(MOJO_RESULT_OK,
726 dispatcher->ReadMessage(UserPointer<void>(read_buffer), 661 dispatcher->ReadMessage(UserPointer<void>(read_buffer),
727 MakeUserPointer(&read_buffer_size), 662 MakeUserPointer(&read_buffer_size), 0,
728 0, 663 nullptr, MOJO_READ_MESSAGE_FLAG_NONE));
729 nullptr,
730 MOJO_READ_MESSAGE_FLAG_NONE));
731 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size)); 664 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size));
732 EXPECT_STREQ(kHello, read_buffer); 665 EXPECT_STREQ(kHello, read_buffer);
733 666
734 // Prepare to wait on "local_mp", port 1. 667 // Prepare to wait on "local_mp", port 1.
735 waiter.Init(); 668 waiter.Init();
736 ASSERT_EQ(MOJO_RESULT_OK, 669 ASSERT_EQ(MOJO_RESULT_OK,
737 local_mp->AddWaiter( 670 local_mp->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 789,
738 1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 789, nullptr)); 671 nullptr));
739 672
740 // Write to the dispatcher. 673 // Write to the dispatcher.
741 EXPECT_EQ(MOJO_RESULT_OK, 674 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->WriteMessage(
742 dispatcher->WriteMessage(UserPointer<const void>(kHello), 675 UserPointer<const void>(kHello), sizeof(kHello),
743 sizeof(kHello), 676 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
744 nullptr,
745 MOJO_WRITE_MESSAGE_FLAG_NONE));
746 677
747 // Wait. 678 // Wait.
748 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); 679 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context));
749 EXPECT_EQ(789u, context); 680 EXPECT_EQ(789u, context);
750 hss = HandleSignalsState(); 681 hss = HandleSignalsState();
751 local_mp->RemoveWaiter(1, &waiter, &hss); 682 local_mp->RemoveWaiter(1, &waiter, &hss);
752 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 683 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
753 hss.satisfied_signals); 684 hss.satisfied_signals);
754 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 685 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
755 hss.satisfiable_signals); 686 hss.satisfiable_signals);
756 687
757 // Read from "local_mp", port 1. 688 // Read from "local_mp", port 1.
758 memset(read_buffer, 0, sizeof(read_buffer)); 689 memset(read_buffer, 0, sizeof(read_buffer));
759 read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer)); 690 read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer));
760 EXPECT_EQ(MOJO_RESULT_OK, 691 EXPECT_EQ(MOJO_RESULT_OK,
761 local_mp->ReadMessage(1, 692 local_mp->ReadMessage(1, UserPointer<void>(read_buffer),
762 UserPointer<void>(read_buffer), 693 MakeUserPointer(&read_buffer_size), nullptr,
763 MakeUserPointer(&read_buffer_size), 694 nullptr, MOJO_READ_MESSAGE_FLAG_NONE));
764 nullptr,
765 nullptr,
766 MOJO_READ_MESSAGE_FLAG_NONE));
767 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size)); 695 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size));
768 EXPECT_STREQ(kHello, read_buffer); 696 EXPECT_STREQ(kHello, read_buffer);
769 697
770 // TODO(vtl): Also test that messages queued up before the handle was sent are 698 // TODO(vtl): Also test that messages queued up before the handle was sent are
771 // delivered properly. 699 // delivered properly.
772 700
773 // Close everything that belongs to us. 701 // Close everything that belongs to us.
774 mp0->Close(0); 702 mp0->Close(0);
775 mp1->Close(1); 703 mp1->Close(1);
776 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); 704 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close());
(...skipping 12 matching lines...) Expand all
789 scoped_refptr<MessagePipeDispatcher> dispatcher( 717 scoped_refptr<MessagePipeDispatcher> dispatcher(
790 new MessagePipeDispatcher(MessagePipeDispatcher::kDefaultCreateOptions)); 718 new MessagePipeDispatcher(MessagePipeDispatcher::kDefaultCreateOptions));
791 scoped_refptr<MessagePipe> local_mp(MessagePipe::CreateLocalLocal()); 719 scoped_refptr<MessagePipe> local_mp(MessagePipe::CreateLocalLocal());
792 dispatcher->Init(local_mp, 0); 720 dispatcher->Init(local_mp, 0);
793 721
794 hss = local_mp->GetHandleSignalsState(0); 722 hss = local_mp->GetHandleSignalsState(0);
795 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals); 723 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals);
796 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 724 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
797 hss.satisfiable_signals); 725 hss.satisfiable_signals);
798 // Write to the other end (|local_mp|, port 1), and then close it. 726 // Write to the other end (|local_mp|, port 1), and then close it.
799 EXPECT_EQ(MOJO_RESULT_OK, 727 EXPECT_EQ(
800 local_mp->WriteMessage(1, 728 MOJO_RESULT_OK,
801 UserPointer<const void>(kHello), 729 local_mp->WriteMessage(1, UserPointer<const void>(kHello), sizeof(kHello),
802 sizeof(kHello), 730 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
803 nullptr,
804 MOJO_WRITE_MESSAGE_FLAG_NONE));
805 hss = local_mp->GetHandleSignalsState(0); 731 hss = local_mp->GetHandleSignalsState(0);
806 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 732 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
807 hss.satisfied_signals); 733 hss.satisfied_signals);
808 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 734 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
809 hss.satisfiable_signals); 735 hss.satisfiable_signals);
810 // Then the second message.... 736 // Then the second message....
811 EXPECT_EQ(MOJO_RESULT_OK, 737 EXPECT_EQ(
812 local_mp->WriteMessage(1, 738 MOJO_RESULT_OK,
813 UserPointer<const void>(kWorld), 739 local_mp->WriteMessage(1, UserPointer<const void>(kWorld), sizeof(kWorld),
814 sizeof(kWorld), 740 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
815 nullptr,
816 MOJO_WRITE_MESSAGE_FLAG_NONE));
817 hss = local_mp->GetHandleSignalsState(0); 741 hss = local_mp->GetHandleSignalsState(0);
818 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 742 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
819 hss.satisfied_signals); 743 hss.satisfied_signals);
820 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 744 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
821 hss.satisfiable_signals); 745 hss.satisfiable_signals);
822 // Then close it. 746 // Then close it.
823 local_mp->Close(1); 747 local_mp->Close(1);
824 748
825 scoped_refptr<ChannelEndpoint> ep0; 749 scoped_refptr<ChannelEndpoint> ep0;
826 scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy(&ep0)); 750 scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy(&ep0));
827 scoped_refptr<ChannelEndpoint> ep1; 751 scoped_refptr<ChannelEndpoint> ep1;
828 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1)); 752 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1));
829 BootstrapChannelEndpoints(ep0, ep1); 753 BootstrapChannelEndpoints(ep0, ep1);
830 754
831 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do 755 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do
832 // it later, it might already be readable.) 756 // it later, it might already be readable.)
833 waiter.Init(); 757 waiter.Init();
834 ASSERT_EQ( 758 ASSERT_EQ(
835 MOJO_RESULT_OK, 759 MOJO_RESULT_OK,
836 mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); 760 mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr));
837 761
838 // Write to MP 0, port 0. 762 // Write to MP 0, port 0.
839 { 763 {
840 DispatcherTransport transport( 764 DispatcherTransport transport(
841 test::DispatcherTryStartTransport(dispatcher.get())); 765 test::DispatcherTryStartTransport(dispatcher.get()));
842 EXPECT_TRUE(transport.is_valid()); 766 EXPECT_TRUE(transport.is_valid());
843 767
844 std::vector<DispatcherTransport> transports; 768 std::vector<DispatcherTransport> transports;
845 transports.push_back(transport); 769 transports.push_back(transport);
846 EXPECT_EQ(MOJO_RESULT_OK, 770 EXPECT_EQ(
847 mp0->WriteMessage(0, 771 MOJO_RESULT_OK,
848 UserPointer<const void>(kHello), 772 mp0->WriteMessage(0, UserPointer<const void>(kHello), sizeof(kHello),
849 sizeof(kHello), 773 &transports, MOJO_WRITE_MESSAGE_FLAG_NONE));
850 &transports,
851 MOJO_WRITE_MESSAGE_FLAG_NONE));
852 transport.End(); 774 transport.End();
853 775
854 // |dispatcher| should have been closed. This is |DCHECK()|ed when the 776 // |dispatcher| should have been closed. This is |DCHECK()|ed when the
855 // |dispatcher| is destroyed. 777 // |dispatcher| is destroyed.
856 EXPECT_TRUE(dispatcher->HasOneRef()); 778 EXPECT_TRUE(dispatcher->HasOneRef());
857 dispatcher = nullptr; 779 dispatcher = nullptr;
858 } 780 }
859 781
860 // Wait. 782 // Wait.
861 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); 783 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context));
862 EXPECT_EQ(123u, context); 784 EXPECT_EQ(123u, context);
863 hss = HandleSignalsState(); 785 hss = HandleSignalsState();
864 mp1->RemoveWaiter(1, &waiter, &hss); 786 mp1->RemoveWaiter(1, &waiter, &hss);
865 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 787 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
866 hss.satisfied_signals); 788 hss.satisfied_signals);
867 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 789 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
868 hss.satisfiable_signals); 790 hss.satisfiable_signals);
869 791
870 // Read from MP 1, port 1. 792 // Read from MP 1, port 1.
871 char read_buffer[100] = {0}; 793 char read_buffer[100] = {0};
872 uint32_t read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer)); 794 uint32_t read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer));
873 DispatcherVector read_dispatchers; 795 DispatcherVector read_dispatchers;
874 uint32_t read_num_dispatchers = 10; // Maximum to get. 796 uint32_t read_num_dispatchers = 10; // Maximum to get.
875 EXPECT_EQ(MOJO_RESULT_OK, 797 EXPECT_EQ(
876 mp1->ReadMessage(1, 798 MOJO_RESULT_OK,
877 UserPointer<void>(read_buffer), 799 mp1->ReadMessage(1, UserPointer<void>(read_buffer),
878 MakeUserPointer(&read_buffer_size), 800 MakeUserPointer(&read_buffer_size), &read_dispatchers,
879 &read_dispatchers, 801 &read_num_dispatchers, MOJO_READ_MESSAGE_FLAG_NONE));
880 &read_num_dispatchers,
881 MOJO_READ_MESSAGE_FLAG_NONE));
882 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size)); 802 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size));
883 EXPECT_STREQ(kHello, read_buffer); 803 EXPECT_STREQ(kHello, read_buffer);
884 EXPECT_EQ(1u, read_dispatchers.size()); 804 EXPECT_EQ(1u, read_dispatchers.size());
885 EXPECT_EQ(1u, read_num_dispatchers); 805 EXPECT_EQ(1u, read_num_dispatchers);
886 ASSERT_TRUE(read_dispatchers[0].get()); 806 ASSERT_TRUE(read_dispatchers[0].get());
887 EXPECT_TRUE(read_dispatchers[0]->HasOneRef()); 807 EXPECT_TRUE(read_dispatchers[0]->HasOneRef());
888 808
889 EXPECT_EQ(Dispatcher::kTypeMessagePipe, read_dispatchers[0]->GetType()); 809 EXPECT_EQ(Dispatcher::kTypeMessagePipe, read_dispatchers[0]->GetType());
890 dispatcher = static_cast<MessagePipeDispatcher*>(read_dispatchers[0].get()); 810 dispatcher = static_cast<MessagePipeDispatcher*>(read_dispatchers[0].get());
891 811
892 // |dispatcher| should already be readable and not writable. 812 // |dispatcher| should already be readable and not writable.
893 hss = dispatcher->GetHandleSignalsState(); 813 hss = dispatcher->GetHandleSignalsState();
894 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals); 814 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals);
895 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfiable_signals); 815 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfiable_signals);
896 // So read from it. 816 // So read from it.
897 memset(read_buffer, 0, sizeof(read_buffer)); 817 memset(read_buffer, 0, sizeof(read_buffer));
898 read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer)); 818 read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer));
899 EXPECT_EQ(MOJO_RESULT_OK, 819 EXPECT_EQ(MOJO_RESULT_OK,
900 dispatcher->ReadMessage(UserPointer<void>(read_buffer), 820 dispatcher->ReadMessage(UserPointer<void>(read_buffer),
901 MakeUserPointer(&read_buffer_size), 821 MakeUserPointer(&read_buffer_size), 0,
902 0, 822 nullptr, MOJO_READ_MESSAGE_FLAG_NONE));
903 nullptr,
904 MOJO_READ_MESSAGE_FLAG_NONE));
905 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size)); 823 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size));
906 EXPECT_STREQ(kHello, read_buffer); 824 EXPECT_STREQ(kHello, read_buffer);
907 // It should still be readable. 825 // It should still be readable.
908 hss = dispatcher->GetHandleSignalsState(); 826 hss = dispatcher->GetHandleSignalsState();
909 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals); 827 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals);
910 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfiable_signals); 828 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfiable_signals);
911 // So read from it. 829 // So read from it.
912 memset(read_buffer, 0, sizeof(read_buffer)); 830 memset(read_buffer, 0, sizeof(read_buffer));
913 read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer)); 831 read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer));
914 EXPECT_EQ(MOJO_RESULT_OK, 832 EXPECT_EQ(MOJO_RESULT_OK,
915 dispatcher->ReadMessage(UserPointer<void>(read_buffer), 833 dispatcher->ReadMessage(UserPointer<void>(read_buffer),
916 MakeUserPointer(&read_buffer_size), 834 MakeUserPointer(&read_buffer_size), 0,
917 0, 835 nullptr, MOJO_READ_MESSAGE_FLAG_NONE));
918 nullptr,
919 MOJO_READ_MESSAGE_FLAG_NONE));
920 EXPECT_EQ(sizeof(kWorld), static_cast<size_t>(read_buffer_size)); 836 EXPECT_EQ(sizeof(kWorld), static_cast<size_t>(read_buffer_size));
921 EXPECT_STREQ(kWorld, read_buffer); 837 EXPECT_STREQ(kWorld, read_buffer);
922 // Now it should no longer be readable. 838 // Now it should no longer be readable.
923 hss = dispatcher->GetHandleSignalsState(); 839 hss = dispatcher->GetHandleSignalsState();
924 EXPECT_EQ(MOJO_HANDLE_SIGNAL_NONE, hss.satisfied_signals); 840 EXPECT_EQ(MOJO_HANDLE_SIGNAL_NONE, hss.satisfied_signals);
925 EXPECT_EQ(MOJO_HANDLE_SIGNAL_NONE, hss.satisfiable_signals); 841 EXPECT_EQ(MOJO_HANDLE_SIGNAL_NONE, hss.satisfiable_signals);
926 842
927 // Close everything that belongs to us. 843 // Close everything that belongs to us.
928 mp0->Close(0); 844 mp0->Close(0);
929 mp1->Close(1); 845 mp1->Close(1);
(...skipping 13 matching lines...) Expand all
943 uint32_t context = 0; 859 uint32_t context = 0;
944 860
945 scoped_refptr<ChannelEndpoint> ep0; 861 scoped_refptr<ChannelEndpoint> ep0;
946 scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy(&ep0)); 862 scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy(&ep0));
947 scoped_refptr<ChannelEndpoint> ep1; 863 scoped_refptr<ChannelEndpoint> ep1;
948 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1)); 864 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1));
949 BootstrapChannelEndpoints(ep0, ep1); 865 BootstrapChannelEndpoints(ep0, ep1);
950 866
951 // We'll try to pass this dispatcher. 867 // We'll try to pass this dispatcher.
952 scoped_refptr<SharedBufferDispatcher> dispatcher; 868 scoped_refptr<SharedBufferDispatcher> dispatcher;
953 EXPECT_EQ(MOJO_RESULT_OK, 869 EXPECT_EQ(MOJO_RESULT_OK, SharedBufferDispatcher::Create(
954 SharedBufferDispatcher::Create( 870 platform_support(),
955 platform_support(), 871 SharedBufferDispatcher::kDefaultCreateOptions,
956 SharedBufferDispatcher::kDefaultCreateOptions, 872 100, &dispatcher));
957 100,
958 &dispatcher));
959 ASSERT_TRUE(dispatcher.get()); 873 ASSERT_TRUE(dispatcher.get());
960 874
961 // Make a mapping. 875 // Make a mapping.
962 scoped_ptr<embedder::PlatformSharedBufferMapping> mapping0; 876 scoped_ptr<embedder::PlatformSharedBufferMapping> mapping0;
963 EXPECT_EQ( 877 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->MapBuffer(
964 MOJO_RESULT_OK, 878 0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping0));
965 dispatcher->MapBuffer(0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping0));
966 ASSERT_TRUE(mapping0); 879 ASSERT_TRUE(mapping0);
967 ASSERT_TRUE(mapping0->GetBase()); 880 ASSERT_TRUE(mapping0->GetBase());
968 ASSERT_EQ(100u, mapping0->GetLength()); 881 ASSERT_EQ(100u, mapping0->GetLength());
969 static_cast<char*>(mapping0->GetBase())[0] = 'A'; 882 static_cast<char*>(mapping0->GetBase())[0] = 'A';
970 static_cast<char*>(mapping0->GetBase())[50] = 'B'; 883 static_cast<char*>(mapping0->GetBase())[50] = 'B';
971 static_cast<char*>(mapping0->GetBase())[99] = 'C'; 884 static_cast<char*>(mapping0->GetBase())[99] = 'C';
972 885
973 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do 886 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do
974 // it later, it might already be readable.) 887 // it later, it might already be readable.)
975 waiter.Init(); 888 waiter.Init();
976 ASSERT_EQ( 889 ASSERT_EQ(
977 MOJO_RESULT_OK, 890 MOJO_RESULT_OK,
978 mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); 891 mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr));
979 892
980 // Write to MP 0, port 0. 893 // Write to MP 0, port 0.
981 { 894 {
982 DispatcherTransport transport( 895 DispatcherTransport transport(
983 test::DispatcherTryStartTransport(dispatcher.get())); 896 test::DispatcherTryStartTransport(dispatcher.get()));
984 EXPECT_TRUE(transport.is_valid()); 897 EXPECT_TRUE(transport.is_valid());
985 898
986 std::vector<DispatcherTransport> transports; 899 std::vector<DispatcherTransport> transports;
987 transports.push_back(transport); 900 transports.push_back(transport);
988 EXPECT_EQ(MOJO_RESULT_OK, 901 EXPECT_EQ(
989 mp0->WriteMessage(0, 902 MOJO_RESULT_OK,
990 UserPointer<const void>(kHello), 903 mp0->WriteMessage(0, UserPointer<const void>(kHello), sizeof(kHello),
991 sizeof(kHello), 904 &transports, MOJO_WRITE_MESSAGE_FLAG_NONE));
992 &transports,
993 MOJO_WRITE_MESSAGE_FLAG_NONE));
994 transport.End(); 905 transport.End();
995 906
996 // |dispatcher| should have been closed. This is |DCHECK()|ed when the 907 // |dispatcher| should have been closed. This is |DCHECK()|ed when the
997 // |dispatcher| is destroyed. 908 // |dispatcher| is destroyed.
998 EXPECT_TRUE(dispatcher->HasOneRef()); 909 EXPECT_TRUE(dispatcher->HasOneRef());
999 dispatcher = nullptr; 910 dispatcher = nullptr;
1000 } 911 }
1001 912
1002 // Wait. 913 // Wait.
1003 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); 914 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context));
1004 EXPECT_EQ(123u, context); 915 EXPECT_EQ(123u, context);
1005 hss = HandleSignalsState(); 916 hss = HandleSignalsState();
1006 mp1->RemoveWaiter(1, &waiter, &hss); 917 mp1->RemoveWaiter(1, &waiter, &hss);
1007 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 918 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
1008 hss.satisfied_signals); 919 hss.satisfied_signals);
1009 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 920 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
1010 hss.satisfiable_signals); 921 hss.satisfiable_signals);
1011 922
1012 // Read from MP 1, port 1. 923 // Read from MP 1, port 1.
1013 char read_buffer[100] = {0}; 924 char read_buffer[100] = {0};
1014 uint32_t read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer)); 925 uint32_t read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer));
1015 DispatcherVector read_dispatchers; 926 DispatcherVector read_dispatchers;
1016 uint32_t read_num_dispatchers = 10; // Maximum to get. 927 uint32_t read_num_dispatchers = 10; // Maximum to get.
1017 EXPECT_EQ(MOJO_RESULT_OK, 928 EXPECT_EQ(
1018 mp1->ReadMessage(1, 929 MOJO_RESULT_OK,
1019 UserPointer<void>(read_buffer), 930 mp1->ReadMessage(1, UserPointer<void>(read_buffer),
1020 MakeUserPointer(&read_buffer_size), 931 MakeUserPointer(&read_buffer_size), &read_dispatchers,
1021 &read_dispatchers, 932 &read_num_dispatchers, MOJO_READ_MESSAGE_FLAG_NONE));
1022 &read_num_dispatchers,
1023 MOJO_READ_MESSAGE_FLAG_NONE));
1024 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size)); 933 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size));
1025 EXPECT_STREQ(kHello, read_buffer); 934 EXPECT_STREQ(kHello, read_buffer);
1026 EXPECT_EQ(1u, read_dispatchers.size()); 935 EXPECT_EQ(1u, read_dispatchers.size());
1027 EXPECT_EQ(1u, read_num_dispatchers); 936 EXPECT_EQ(1u, read_num_dispatchers);
1028 ASSERT_TRUE(read_dispatchers[0].get()); 937 ASSERT_TRUE(read_dispatchers[0].get());
1029 EXPECT_TRUE(read_dispatchers[0]->HasOneRef()); 938 EXPECT_TRUE(read_dispatchers[0]->HasOneRef());
1030 939
1031 EXPECT_EQ(Dispatcher::kTypeSharedBuffer, read_dispatchers[0]->GetType()); 940 EXPECT_EQ(Dispatcher::kTypeSharedBuffer, read_dispatchers[0]->GetType());
1032 dispatcher = static_cast<SharedBufferDispatcher*>(read_dispatchers[0].get()); 941 dispatcher = static_cast<SharedBufferDispatcher*>(read_dispatchers[0].get());
1033 942
1034 // Make another mapping. 943 // Make another mapping.
1035 scoped_ptr<embedder::PlatformSharedBufferMapping> mapping1; 944 scoped_ptr<embedder::PlatformSharedBufferMapping> mapping1;
1036 EXPECT_EQ( 945 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->MapBuffer(
1037 MOJO_RESULT_OK, 946 0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping1));
1038 dispatcher->MapBuffer(0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping1));
1039 ASSERT_TRUE(mapping1); 947 ASSERT_TRUE(mapping1);
1040 ASSERT_TRUE(mapping1->GetBase()); 948 ASSERT_TRUE(mapping1->GetBase());
1041 ASSERT_EQ(100u, mapping1->GetLength()); 949 ASSERT_EQ(100u, mapping1->GetLength());
1042 EXPECT_NE(mapping1->GetBase(), mapping0->GetBase()); 950 EXPECT_NE(mapping1->GetBase(), mapping0->GetBase());
1043 EXPECT_EQ('A', static_cast<char*>(mapping1->GetBase())[0]); 951 EXPECT_EQ('A', static_cast<char*>(mapping1->GetBase())[0]);
1044 EXPECT_EQ('B', static_cast<char*>(mapping1->GetBase())[50]); 952 EXPECT_EQ('B', static_cast<char*>(mapping1->GetBase())[50]);
1045 EXPECT_EQ('C', static_cast<char*>(mapping1->GetBase())[99]); 953 EXPECT_EQ('C', static_cast<char*>(mapping1->GetBase())[99]);
1046 954
1047 // Write stuff either way. 955 // Write stuff either way.
1048 static_cast<char*>(mapping1->GetBase())[1] = 'x'; 956 static_cast<char*>(mapping1->GetBase())[1] = 'x';
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1103 mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); 1011 mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr));
1104 1012
1105 // Write to MP 0, port 0. 1013 // Write to MP 0, port 0.
1106 { 1014 {
1107 DispatcherTransport transport( 1015 DispatcherTransport transport(
1108 test::DispatcherTryStartTransport(dispatcher.get())); 1016 test::DispatcherTryStartTransport(dispatcher.get()));
1109 EXPECT_TRUE(transport.is_valid()); 1017 EXPECT_TRUE(transport.is_valid());
1110 1018
1111 std::vector<DispatcherTransport> transports; 1019 std::vector<DispatcherTransport> transports;
1112 transports.push_back(transport); 1020 transports.push_back(transport);
1113 EXPECT_EQ(MOJO_RESULT_OK, 1021 EXPECT_EQ(
1114 mp0->WriteMessage(0, 1022 MOJO_RESULT_OK,
1115 UserPointer<const void>(kWorld), 1023 mp0->WriteMessage(0, UserPointer<const void>(kWorld), sizeof(kWorld),
1116 sizeof(kWorld), 1024 &transports, MOJO_WRITE_MESSAGE_FLAG_NONE));
1117 &transports,
1118 MOJO_WRITE_MESSAGE_FLAG_NONE));
1119 transport.End(); 1025 transport.End();
1120 1026
1121 // |dispatcher| should have been closed. This is |DCHECK()|ed when the 1027 // |dispatcher| should have been closed. This is |DCHECK()|ed when the
1122 // |dispatcher| is destroyed. 1028 // |dispatcher| is destroyed.
1123 EXPECT_TRUE(dispatcher->HasOneRef()); 1029 EXPECT_TRUE(dispatcher->HasOneRef());
1124 dispatcher = nullptr; 1030 dispatcher = nullptr;
1125 } 1031 }
1126 1032
1127 // Wait. 1033 // Wait.
1128 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); 1034 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context));
1129 EXPECT_EQ(123u, context); 1035 EXPECT_EQ(123u, context);
1130 hss = HandleSignalsState(); 1036 hss = HandleSignalsState();
1131 mp1->RemoveWaiter(1, &waiter, &hss); 1037 mp1->RemoveWaiter(1, &waiter, &hss);
1132 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 1038 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
1133 hss.satisfied_signals); 1039 hss.satisfied_signals);
1134 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 1040 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
1135 hss.satisfiable_signals); 1041 hss.satisfiable_signals);
1136 1042
1137 // Read from MP 1, port 1. 1043 // Read from MP 1, port 1.
1138 char read_buffer[100] = {0}; 1044 char read_buffer[100] = {0};
1139 uint32_t read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer)); 1045 uint32_t read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer));
1140 DispatcherVector read_dispatchers; 1046 DispatcherVector read_dispatchers;
1141 uint32_t read_num_dispatchers = 10; // Maximum to get. 1047 uint32_t read_num_dispatchers = 10; // Maximum to get.
1142 EXPECT_EQ(MOJO_RESULT_OK, 1048 EXPECT_EQ(
1143 mp1->ReadMessage(1, 1049 MOJO_RESULT_OK,
1144 UserPointer<void>(read_buffer), 1050 mp1->ReadMessage(1, UserPointer<void>(read_buffer),
1145 MakeUserPointer(&read_buffer_size), 1051 MakeUserPointer(&read_buffer_size), &read_dispatchers,
1146 &read_dispatchers, 1052 &read_num_dispatchers, MOJO_READ_MESSAGE_FLAG_NONE));
1147 &read_num_dispatchers,
1148 MOJO_READ_MESSAGE_FLAG_NONE));
1149 EXPECT_EQ(sizeof(kWorld), static_cast<size_t>(read_buffer_size)); 1053 EXPECT_EQ(sizeof(kWorld), static_cast<size_t>(read_buffer_size));
1150 EXPECT_STREQ(kWorld, read_buffer); 1054 EXPECT_STREQ(kWorld, read_buffer);
1151 EXPECT_EQ(1u, read_dispatchers.size()); 1055 EXPECT_EQ(1u, read_dispatchers.size());
1152 EXPECT_EQ(1u, read_num_dispatchers); 1056 EXPECT_EQ(1u, read_num_dispatchers);
1153 ASSERT_TRUE(read_dispatchers[0].get()); 1057 ASSERT_TRUE(read_dispatchers[0].get());
1154 EXPECT_TRUE(read_dispatchers[0]->HasOneRef()); 1058 EXPECT_TRUE(read_dispatchers[0]->HasOneRef());
1155 1059
1156 EXPECT_EQ(Dispatcher::kTypePlatformHandle, read_dispatchers[0]->GetType()); 1060 EXPECT_EQ(Dispatcher::kTypePlatformHandle, read_dispatchers[0]->GetType());
1157 dispatcher = 1061 dispatcher =
1158 static_cast<PlatformHandleDispatcher*>(read_dispatchers[0].get()); 1062 static_cast<PlatformHandleDispatcher*>(read_dispatchers[0].get());
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1245 mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); 1149 mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr));
1246 1150
1247 // Write to MP 0, port 0. 1151 // Write to MP 0, port 0.
1248 { 1152 {
1249 DispatcherTransport transport( 1153 DispatcherTransport transport(
1250 test::DispatcherTryStartTransport(dispatcher.get())); 1154 test::DispatcherTryStartTransport(dispatcher.get()));
1251 EXPECT_TRUE(transport.is_valid()); 1155 EXPECT_TRUE(transport.is_valid());
1252 1156
1253 std::vector<DispatcherTransport> transports; 1157 std::vector<DispatcherTransport> transports;
1254 transports.push_back(transport); 1158 transports.push_back(transport);
1255 EXPECT_EQ(MOJO_RESULT_OK, 1159 EXPECT_EQ(
1256 mp0->WriteMessage(0, 1160 MOJO_RESULT_OK,
1257 UserPointer<const void>(kHello), 1161 mp0->WriteMessage(0, UserPointer<const void>(kHello), sizeof(kHello),
1258 sizeof(kHello), 1162 &transports, MOJO_WRITE_MESSAGE_FLAG_NONE));
1259 &transports,
1260 MOJO_WRITE_MESSAGE_FLAG_NONE));
1261 transport.End(); 1163 transport.End();
1262 1164
1263 // |dispatcher| should have been closed. This is |DCHECK()|ed when the 1165 // |dispatcher| should have been closed. This is |DCHECK()|ed when the
1264 // |dispatcher| is destroyed. 1166 // |dispatcher| is destroyed.
1265 EXPECT_TRUE(dispatcher->HasOneRef()); 1167 EXPECT_TRUE(dispatcher->HasOneRef());
1266 dispatcher = nullptr; 1168 dispatcher = nullptr;
1267 } 1169 }
1268 1170
1269 // Wait. 1171 // Wait.
1270 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); 1172 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context));
1271 EXPECT_EQ(123u, context); 1173 EXPECT_EQ(123u, context);
1272 hss = HandleSignalsState(); 1174 hss = HandleSignalsState();
1273 mp1->RemoveWaiter(1, &waiter, &hss); 1175 mp1->RemoveWaiter(1, &waiter, &hss);
1274 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 1176 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
1275 hss.satisfied_signals); 1177 hss.satisfied_signals);
1276 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 1178 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
1277 hss.satisfiable_signals); 1179 hss.satisfiable_signals);
1278 1180
1279 // Read from MP 1, port 1. 1181 // Read from MP 1, port 1.
1280 char read_buffer[100] = {0}; 1182 char read_buffer[100] = {0};
1281 uint32_t read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer)); 1183 uint32_t read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer));
1282 DispatcherVector read_dispatchers; 1184 DispatcherVector read_dispatchers;
1283 uint32_t read_num_dispatchers = 10; // Maximum to get. 1185 uint32_t read_num_dispatchers = 10; // Maximum to get.
1284 EXPECT_EQ(MOJO_RESULT_OK, 1186 EXPECT_EQ(
1285 mp1->ReadMessage(1, 1187 MOJO_RESULT_OK,
1286 UserPointer<void>(read_buffer), 1188 mp1->ReadMessage(1, UserPointer<void>(read_buffer),
1287 MakeUserPointer(&read_buffer_size), 1189 MakeUserPointer(&read_buffer_size), &read_dispatchers,
1288 &read_dispatchers, 1190 &read_num_dispatchers, MOJO_READ_MESSAGE_FLAG_NONE));
1289 &read_num_dispatchers,
1290 MOJO_READ_MESSAGE_FLAG_NONE));
1291 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size)); 1191 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size));
1292 EXPECT_STREQ(kHello, read_buffer); 1192 EXPECT_STREQ(kHello, read_buffer);
1293 EXPECT_EQ(1u, read_dispatchers.size()); 1193 EXPECT_EQ(1u, read_dispatchers.size());
1294 EXPECT_EQ(1u, read_num_dispatchers); 1194 EXPECT_EQ(1u, read_num_dispatchers);
1295 ASSERT_TRUE(read_dispatchers[0].get()); 1195 ASSERT_TRUE(read_dispatchers[0].get());
1296 EXPECT_TRUE(read_dispatchers[0]->HasOneRef()); 1196 EXPECT_TRUE(read_dispatchers[0]->HasOneRef());
1297 1197
1298 EXPECT_EQ(Dispatcher::kTypeMessagePipe, read_dispatchers[0]->GetType()); 1198 EXPECT_EQ(Dispatcher::kTypeMessagePipe, read_dispatchers[0]->GetType());
1299 dispatcher = static_cast<MessagePipeDispatcher*>(read_dispatchers[0].get()); 1199 dispatcher = static_cast<MessagePipeDispatcher*>(read_dispatchers[0].get());
1300 read_dispatchers.clear(); 1200 read_dispatchers.clear();
1301 1201
1302 // Now pass it back. 1202 // Now pass it back.
1303 1203
1304 // Prepare to wait on MP 0, port 0. (Add the waiter now. Otherwise, if we do 1204 // Prepare to wait on MP 0, port 0. (Add the waiter now. Otherwise, if we do
1305 // it later, it might already be readable.) 1205 // it later, it might already be readable.)
1306 waiter.Init(); 1206 waiter.Init();
1307 ASSERT_EQ( 1207 ASSERT_EQ(
1308 MOJO_RESULT_OK, 1208 MOJO_RESULT_OK,
1309 mp0->AddWaiter(0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 456, nullptr)); 1209 mp0->AddWaiter(0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 456, nullptr));
1310 1210
1311 // Write to MP 1, port 1. 1211 // Write to MP 1, port 1.
1312 { 1212 {
1313 DispatcherTransport transport( 1213 DispatcherTransport transport(
1314 test::DispatcherTryStartTransport(dispatcher.get())); 1214 test::DispatcherTryStartTransport(dispatcher.get()));
1315 EXPECT_TRUE(transport.is_valid()); 1215 EXPECT_TRUE(transport.is_valid());
1316 1216
1317 std::vector<DispatcherTransport> transports; 1217 std::vector<DispatcherTransport> transports;
1318 transports.push_back(transport); 1218 transports.push_back(transport);
1319 EXPECT_EQ(MOJO_RESULT_OK, 1219 EXPECT_EQ(
1320 mp1->WriteMessage(1, 1220 MOJO_RESULT_OK,
1321 UserPointer<const void>(kWorld), 1221 mp1->WriteMessage(1, UserPointer<const void>(kWorld), sizeof(kWorld),
1322 sizeof(kWorld), 1222 &transports, MOJO_WRITE_MESSAGE_FLAG_NONE));
1323 &transports,
1324 MOJO_WRITE_MESSAGE_FLAG_NONE));
1325 transport.End(); 1223 transport.End();
1326 1224
1327 // |dispatcher| should have been closed. This is |DCHECK()|ed when the 1225 // |dispatcher| should have been closed. This is |DCHECK()|ed when the
1328 // |dispatcher| is destroyed. 1226 // |dispatcher| is destroyed.
1329 EXPECT_TRUE(dispatcher->HasOneRef()); 1227 EXPECT_TRUE(dispatcher->HasOneRef());
1330 dispatcher = nullptr; 1228 dispatcher = nullptr;
1331 } 1229 }
1332 1230
1333 // Wait. 1231 // Wait.
1334 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); 1232 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context));
1335 EXPECT_EQ(456u, context); 1233 EXPECT_EQ(456u, context);
1336 hss = HandleSignalsState(); 1234 hss = HandleSignalsState();
1337 mp0->RemoveWaiter(0, &waiter, &hss); 1235 mp0->RemoveWaiter(0, &waiter, &hss);
1338 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 1236 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
1339 hss.satisfied_signals); 1237 hss.satisfied_signals);
1340 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 1238 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
1341 hss.satisfiable_signals); 1239 hss.satisfiable_signals);
1342 1240
1343 // Read from MP 0, port 0. 1241 // Read from MP 0, port 0.
1344 read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer)); 1242 read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer));
1345 read_num_dispatchers = 10; // Maximum to get. 1243 read_num_dispatchers = 10; // Maximum to get.
1346 EXPECT_EQ(MOJO_RESULT_OK, 1244 EXPECT_EQ(
1347 mp0->ReadMessage(0, 1245 MOJO_RESULT_OK,
1348 UserPointer<void>(read_buffer), 1246 mp0->ReadMessage(0, UserPointer<void>(read_buffer),
1349 MakeUserPointer(&read_buffer_size), 1247 MakeUserPointer(&read_buffer_size), &read_dispatchers,
1350 &read_dispatchers, 1248 &read_num_dispatchers, MOJO_READ_MESSAGE_FLAG_NONE));
1351 &read_num_dispatchers,
1352 MOJO_READ_MESSAGE_FLAG_NONE));
1353 EXPECT_EQ(sizeof(kWorld), static_cast<size_t>(read_buffer_size)); 1249 EXPECT_EQ(sizeof(kWorld), static_cast<size_t>(read_buffer_size));
1354 EXPECT_STREQ(kWorld, read_buffer); 1250 EXPECT_STREQ(kWorld, read_buffer);
1355 EXPECT_EQ(1u, read_dispatchers.size()); 1251 EXPECT_EQ(1u, read_dispatchers.size());
1356 EXPECT_EQ(1u, read_num_dispatchers); 1252 EXPECT_EQ(1u, read_num_dispatchers);
1357 ASSERT_TRUE(read_dispatchers[0].get()); 1253 ASSERT_TRUE(read_dispatchers[0].get());
1358 EXPECT_TRUE(read_dispatchers[0]->HasOneRef()); 1254 EXPECT_TRUE(read_dispatchers[0]->HasOneRef());
1359 1255
1360 EXPECT_EQ(Dispatcher::kTypeMessagePipe, read_dispatchers[0]->GetType()); 1256 EXPECT_EQ(Dispatcher::kTypeMessagePipe, read_dispatchers[0]->GetType());
1361 dispatcher = static_cast<MessagePipeDispatcher*>(read_dispatchers[0].get()); 1257 dispatcher = static_cast<MessagePipeDispatcher*>(read_dispatchers[0].get());
1362 read_dispatchers.clear(); 1258 read_dispatchers.clear();
1363 1259
1364 // Add the waiter now, before it becomes readable to avoid a race. 1260 // Add the waiter now, before it becomes readable to avoid a race.
1365 waiter.Init(); 1261 waiter.Init();
1366 ASSERT_EQ(MOJO_RESULT_OK, 1262 ASSERT_EQ(MOJO_RESULT_OK,
1367 dispatcher->AddWaiter( 1263 dispatcher->AddWaiter(&waiter, MOJO_HANDLE_SIGNAL_READABLE, 789,
1368 &waiter, MOJO_HANDLE_SIGNAL_READABLE, 789, nullptr)); 1264 nullptr));
1369 1265
1370 // Write to "local_mp", port 1. 1266 // Write to "local_mp", port 1.
1371 EXPECT_EQ(MOJO_RESULT_OK, 1267 EXPECT_EQ(
1372 local_mp->WriteMessage(1, 1268 MOJO_RESULT_OK,
1373 UserPointer<const void>(kHello), 1269 local_mp->WriteMessage(1, UserPointer<const void>(kHello), sizeof(kHello),
1374 sizeof(kHello), 1270 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
1375 nullptr,
1376 MOJO_WRITE_MESSAGE_FLAG_NONE));
1377 1271
1378 // Wait for the dispatcher to become readable. 1272 // Wait for the dispatcher to become readable.
1379 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); 1273 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context));
1380 EXPECT_EQ(789u, context); 1274 EXPECT_EQ(789u, context);
1381 hss = HandleSignalsState(); 1275 hss = HandleSignalsState();
1382 dispatcher->RemoveWaiter(&waiter, &hss); 1276 dispatcher->RemoveWaiter(&waiter, &hss);
1383 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 1277 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
1384 hss.satisfied_signals); 1278 hss.satisfied_signals);
1385 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 1279 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
1386 hss.satisfiable_signals); 1280 hss.satisfiable_signals);
1387 1281
1388 // Read from the dispatcher. 1282 // Read from the dispatcher.
1389 memset(read_buffer, 0, sizeof(read_buffer)); 1283 memset(read_buffer, 0, sizeof(read_buffer));
1390 read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer)); 1284 read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer));
1391 EXPECT_EQ(MOJO_RESULT_OK, 1285 EXPECT_EQ(MOJO_RESULT_OK,
1392 dispatcher->ReadMessage(UserPointer<void>(read_buffer), 1286 dispatcher->ReadMessage(UserPointer<void>(read_buffer),
1393 MakeUserPointer(&read_buffer_size), 1287 MakeUserPointer(&read_buffer_size), 0,
1394 0, 1288 nullptr, MOJO_READ_MESSAGE_FLAG_NONE));
1395 nullptr,
1396 MOJO_READ_MESSAGE_FLAG_NONE));
1397 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size)); 1289 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size));
1398 EXPECT_STREQ(kHello, read_buffer); 1290 EXPECT_STREQ(kHello, read_buffer);
1399 1291
1400 // Prepare to wait on "local_mp", port 1. 1292 // Prepare to wait on "local_mp", port 1.
1401 waiter.Init(); 1293 waiter.Init();
1402 ASSERT_EQ(MOJO_RESULT_OK, 1294 ASSERT_EQ(MOJO_RESULT_OK,
1403 local_mp->AddWaiter( 1295 local_mp->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 789,
1404 1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 789, nullptr)); 1296 nullptr));
1405 1297
1406 // Write to the dispatcher. 1298 // Write to the dispatcher.
1407 EXPECT_EQ(MOJO_RESULT_OK, 1299 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->WriteMessage(
1408 dispatcher->WriteMessage(UserPointer<const void>(kHello), 1300 UserPointer<const void>(kHello), sizeof(kHello),
1409 sizeof(kHello), 1301 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
1410 nullptr,
1411 MOJO_WRITE_MESSAGE_FLAG_NONE));
1412 1302
1413 // Wait. 1303 // Wait.
1414 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); 1304 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context));
1415 EXPECT_EQ(789u, context); 1305 EXPECT_EQ(789u, context);
1416 hss = HandleSignalsState(); 1306 hss = HandleSignalsState();
1417 local_mp->RemoveWaiter(1, &waiter, &hss); 1307 local_mp->RemoveWaiter(1, &waiter, &hss);
1418 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 1308 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
1419 hss.satisfied_signals); 1309 hss.satisfied_signals);
1420 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 1310 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
1421 hss.satisfiable_signals); 1311 hss.satisfiable_signals);
1422 1312
1423 // Read from "local_mp", port 1. 1313 // Read from "local_mp", port 1.
1424 memset(read_buffer, 0, sizeof(read_buffer)); 1314 memset(read_buffer, 0, sizeof(read_buffer));
1425 read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer)); 1315 read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer));
1426 EXPECT_EQ(MOJO_RESULT_OK, 1316 EXPECT_EQ(MOJO_RESULT_OK,
1427 local_mp->ReadMessage(1, 1317 local_mp->ReadMessage(1, UserPointer<void>(read_buffer),
1428 UserPointer<void>(read_buffer), 1318 MakeUserPointer(&read_buffer_size), nullptr,
1429 MakeUserPointer(&read_buffer_size), 1319 nullptr, MOJO_READ_MESSAGE_FLAG_NONE));
1430 nullptr,
1431 nullptr,
1432 MOJO_READ_MESSAGE_FLAG_NONE));
1433 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size)); 1320 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size));
1434 EXPECT_STREQ(kHello, read_buffer); 1321 EXPECT_STREQ(kHello, read_buffer);
1435 1322
1436 // TODO(vtl): Also test the cases where messages are written and read (at 1323 // TODO(vtl): Also test the cases where messages are written and read (at
1437 // various points) on the message pipe being passed around. 1324 // various points) on the message pipe being passed around.
1438 1325
1439 // Close everything that belongs to us. 1326 // Close everything that belongs to us.
1440 mp0->Close(0); 1327 mp0->Close(0);
1441 mp1->Close(1); 1328 mp1->Close(1);
1442 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); 1329 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close());
1443 // Note that |local_mp|'s port 0 belong to |dispatcher|, which was closed. 1330 // Note that |local_mp|'s port 0 belong to |dispatcher|, which was closed.
1444 local_mp->Close(1); 1331 local_mp->Close(1);
1445 } 1332 }
1446 1333
1447 } // namespace 1334 } // namespace
1448 } // namespace system 1335 } // namespace system
1449 } // namespace mojo 1336 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/raw_channel_win.cc ('k') | mojo/edk/system/run_all_unittests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698