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

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

Issue 2741353002: Mojo: Add signal for new data pipe consumer data (Closed)
Patch Set: rebase Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 24 matching lines...) Expand all
35 // certain amount of data to be available). This is the maximum number of 35 // certain amount of data to be available). This is the maximum number of
36 // iterations (separated by a short sleep). 36 // iterations (separated by a short sleep).
37 // TODO(vtl): Get rid of this. 37 // TODO(vtl): Get rid of this.
38 const size_t kMaxPoll = 100; 38 const size_t kMaxPoll = 100;
39 39
40 // Used in Multiprocess test. 40 // Used in Multiprocess test.
41 const size_t kMultiprocessCapacity = 37; 41 const size_t kMultiprocessCapacity = 37;
42 const char kMultiprocessTestData[] = "hello i'm a string that is 36 bytes"; 42 const char kMultiprocessTestData[] = "hello i'm a string that is 36 bytes";
43 const int kMultiprocessMaxIter = 5; 43 const int kMultiprocessMaxIter = 5;
44 44
45 // TODO(rockot): There are many uses of ASSERT where EXPECT would be more
46 // appropriate. Fix this.
47
45 class DataPipeTest : public test::MojoTestBase { 48 class DataPipeTest : public test::MojoTestBase {
46 public: 49 public:
47 DataPipeTest() : producer_(MOJO_HANDLE_INVALID), 50 DataPipeTest() : producer_(MOJO_HANDLE_INVALID),
48 consumer_(MOJO_HANDLE_INVALID) {} 51 consumer_(MOJO_HANDLE_INVALID) {}
49 52
50 ~DataPipeTest() override { 53 ~DataPipeTest() override {
51 if (producer_ != MOJO_HANDLE_INVALID) 54 if (producer_ != MOJO_HANDLE_INVALID)
52 CHECK_EQ(MOJO_RESULT_OK, MojoClose(producer_)); 55 CHECK_EQ(MOJO_RESULT_OK, MojoClose(producer_));
53 if (consumer_ != MOJO_HANDLE_INVALID) 56 if (consumer_ != MOJO_HANDLE_INVALID)
54 CHECK_EQ(MOJO_RESULT_OK, MojoClose(consumer_)); 57 CHECK_EQ(MOJO_RESULT_OK, MojoClose(consumer_));
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 elements[0] = 123; 157 elements[0] = 123;
155 elements[1] = 456; 158 elements[1] = 456;
156 num_bytes = static_cast<uint32_t>(2u * sizeof(elements[0])); 159 num_bytes = static_cast<uint32_t>(2u * sizeof(elements[0]));
157 ASSERT_EQ(MOJO_RESULT_OK, WriteData(&elements[0], &num_bytes)); 160 ASSERT_EQ(MOJO_RESULT_OK, WriteData(&elements[0], &num_bytes));
158 161
159 // Now wait for the other side to become readable. 162 // Now wait for the other side to become readable.
160 MojoHandleSignalsState state; 163 MojoHandleSignalsState state;
161 ASSERT_EQ(MOJO_RESULT_OK, 164 ASSERT_EQ(MOJO_RESULT_OK,
162 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_READABLE, 165 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_READABLE,
163 MOJO_DEADLINE_INDEFINITE, &state)); 166 MOJO_DEADLINE_INDEFINITE, &state));
164 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE, state.satisfied_signals); 167 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
168 state.satisfied_signals);
165 169
166 elements[0] = -1; 170 elements[0] = -1;
167 elements[1] = -1; 171 elements[1] = -1;
168 ASSERT_EQ(MOJO_RESULT_OK, ReadData(&elements[0], &num_bytes)); 172 ASSERT_EQ(MOJO_RESULT_OK, ReadData(&elements[0], &num_bytes));
169 ASSERT_EQ(static_cast<uint32_t>(2u * sizeof(elements[0])), num_bytes); 173 ASSERT_EQ(static_cast<uint32_t>(2u * sizeof(elements[0])), num_bytes);
170 ASSERT_EQ(elements[0], 123); 174 ASSERT_EQ(elements[0], 123);
171 ASSERT_EQ(elements[1], 456); 175 ASSERT_EQ(elements[1], 456);
172 } 176 }
173 177
174 // Tests creation of data pipes with various (valid) options. 178 // Tests creation of data pipes with various (valid) options.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 elements[1] = 456; 244 elements[1] = 456;
241 num_bytes = static_cast<uint32_t>(2u * sizeof(elements[0])); 245 num_bytes = static_cast<uint32_t>(2u * sizeof(elements[0]));
242 ASSERT_EQ(MOJO_RESULT_OK, WriteData(elements, &num_bytes)); 246 ASSERT_EQ(MOJO_RESULT_OK, WriteData(elements, &num_bytes));
243 // It should have written everything (even without "all or none"). 247 // It should have written everything (even without "all or none").
244 ASSERT_EQ(2u * sizeof(elements[0]), num_bytes); 248 ASSERT_EQ(2u * sizeof(elements[0]), num_bytes);
245 249
246 // Wait. 250 // Wait.
247 ASSERT_EQ(MOJO_RESULT_OK, 251 ASSERT_EQ(MOJO_RESULT_OK,
248 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_READABLE, 252 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_READABLE,
249 MOJO_DEADLINE_INDEFINITE, &hss)); 253 MOJO_DEADLINE_INDEFINITE, &hss));
250 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals); 254 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
251 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, 255 hss.satisfied_signals);
256 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED |
257 MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
252 hss.satisfiable_signals); 258 hss.satisfiable_signals);
253 259
254 // Query. 260 // Query.
255 // TODO(vtl): It's theoretically possible (though not with the current 261 // TODO(vtl): It's theoretically possible (though not with the current
256 // implementation/configured limits) that not all the data has arrived yet. 262 // implementation/configured limits) that not all the data has arrived yet.
257 // (The theoretically-correct assertion here is that |num_bytes| is |1 * ...| 263 // (The theoretically-correct assertion here is that |num_bytes| is |1 * ...|
258 // or |2 * ...|.) 264 // or |2 * ...|.)
259 num_bytes = 0; 265 num_bytes = 0;
260 ASSERT_EQ(MOJO_RESULT_OK, QueryData(&num_bytes)); 266 ASSERT_EQ(MOJO_RESULT_OK, QueryData(&num_bytes));
261 ASSERT_EQ(2 * sizeof(elements[0]), num_bytes); 267 ASSERT_EQ(2 * sizeof(elements[0]), num_bytes);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 // Write two elements. 353 // Write two elements.
348 int32_t elements[2] = {123, 456}; 354 int32_t elements[2] = {123, 456};
349 uint32_t num_bytes = static_cast<uint32_t>(2u * sizeof(elements[0])); 355 uint32_t num_bytes = static_cast<uint32_t>(2u * sizeof(elements[0]));
350 ASSERT_EQ(MOJO_RESULT_OK, WriteData(elements, &num_bytes, true)); 356 ASSERT_EQ(MOJO_RESULT_OK, WriteData(elements, &num_bytes, true));
351 ASSERT_EQ(static_cast<uint32_t>(2u * sizeof(elements[0])), num_bytes); 357 ASSERT_EQ(static_cast<uint32_t>(2u * sizeof(elements[0])), num_bytes);
352 358
353 // Wait for data to become available to the consumer. 359 // Wait for data to become available to the consumer.
354 ASSERT_EQ(MOJO_RESULT_OK, 360 ASSERT_EQ(MOJO_RESULT_OK,
355 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_READABLE, 361 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_READABLE,
356 MOJO_DEADLINE_INDEFINITE, &hss)); 362 MOJO_DEADLINE_INDEFINITE, &hss));
357 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals); 363 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
358 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, 364 hss.satisfied_signals);
365 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED |
366 MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
359 hss.satisfiable_signals); 367 hss.satisfiable_signals);
360 368
361 // Peek one element. 369 // Peek one element.
362 elements[0] = -1; 370 elements[0] = -1;
363 elements[1] = -1; 371 elements[1] = -1;
364 num_bytes = static_cast<uint32_t>(1u * sizeof(elements[0])); 372 num_bytes = static_cast<uint32_t>(1u * sizeof(elements[0]));
365 ASSERT_EQ(MOJO_RESULT_OK, ReadData(elements, &num_bytes, true, true)); 373 ASSERT_EQ(MOJO_RESULT_OK, ReadData(elements, &num_bytes, true, true));
366 ASSERT_EQ(static_cast<uint32_t>(1u * sizeof(elements[0])), num_bytes); 374 ASSERT_EQ(static_cast<uint32_t>(1u * sizeof(elements[0])), num_bytes);
367 ASSERT_EQ(123, elements[0]); 375 ASSERT_EQ(123, elements[0]);
368 ASSERT_EQ(-1, elements[1]); 376 ASSERT_EQ(-1, elements[1]);
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 1000 * sizeof(int32_t) // |capacity_num_bytes|. 480 1000 * sizeof(int32_t) // |capacity_num_bytes|.
473 }; 481 };
474 ASSERT_EQ(MOJO_RESULT_OK, Create(&options)); 482 ASSERT_EQ(MOJO_RESULT_OK, Create(&options));
475 MojoHandleSignalsState hss; 483 MojoHandleSignalsState hss;
476 484
477 // Never writable. 485 // Never writable.
478 hss = MojoHandleSignalsState(); 486 hss = MojoHandleSignalsState();
479 ASSERT_EQ(MOJO_RESULT_FAILED_PRECONDITION, 487 ASSERT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
480 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_WRITABLE, 488 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_WRITABLE,
481 MOJO_DEADLINE_INDEFINITE, &hss)); 489 MOJO_DEADLINE_INDEFINITE, &hss));
482 ASSERT_EQ(0u, hss.satisfied_signals); 490 EXPECT_EQ(0u, hss.satisfied_signals);
483 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, 491 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED |
492 MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
484 hss.satisfiable_signals); 493 hss.satisfiable_signals);
485 494
486 // Write two elements. 495 // Write two elements.
487 int32_t elements[2] = {123, 456}; 496 int32_t elements[2] = {123, 456};
488 uint32_t num_bytes = static_cast<uint32_t>(2u * sizeof(elements[0])); 497 uint32_t num_bytes = static_cast<uint32_t>(2u * sizeof(elements[0]));
489 ASSERT_EQ(MOJO_RESULT_OK, WriteData(elements, &num_bytes, true)); 498 ASSERT_EQ(MOJO_RESULT_OK, WriteData(elements, &num_bytes, true));
490 499
491 // Wait for readability. 500 // Wait for readability.
492 hss = MojoHandleSignalsState(); 501 hss = MojoHandleSignalsState();
493 ASSERT_EQ(MOJO_RESULT_OK, 502 ASSERT_EQ(MOJO_RESULT_OK,
494 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_READABLE, 503 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_READABLE,
495 MOJO_DEADLINE_INDEFINITE, &hss)); 504 MOJO_DEADLINE_INDEFINITE, &hss));
496 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals); 505 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
497 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, 506 hss.satisfied_signals);
507 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED |
508 MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
498 hss.satisfiable_signals); 509 hss.satisfiable_signals);
499 510
500 // Discard one element. 511 // Discard one element.
501 num_bytes = static_cast<uint32_t>(1u * sizeof(elements[0])); 512 num_bytes = static_cast<uint32_t>(1u * sizeof(elements[0]));
502 ASSERT_EQ(MOJO_RESULT_OK, DiscardData(&num_bytes, true)); 513 ASSERT_EQ(MOJO_RESULT_OK, DiscardData(&num_bytes, true));
503 ASSERT_EQ(static_cast<uint32_t>(1u * sizeof(elements[0])), num_bytes); 514 ASSERT_EQ(static_cast<uint32_t>(1u * sizeof(elements[0])), num_bytes);
504 515
505 // Should still be readable. 516 // Should still be readable.
506 hss = MojoHandleSignalsState(); 517 hss = MojoHandleSignalsState();
507 ASSERT_EQ(MOJO_RESULT_OK, 518 ASSERT_EQ(MOJO_RESULT_OK,
508 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_READABLE, 519 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_READABLE,
509 MOJO_DEADLINE_INDEFINITE, &hss)); 520 MOJO_DEADLINE_INDEFINITE, &hss));
510 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals); 521 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals);
511 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, 522 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED |
523 MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
512 hss.satisfiable_signals); 524 hss.satisfiable_signals);
513 525
514 // Peek one element. 526 // Peek one element.
515 elements[0] = -1; 527 elements[0] = -1;
516 elements[1] = -1; 528 elements[1] = -1;
517 num_bytes = static_cast<uint32_t>(1u * sizeof(elements[0])); 529 num_bytes = static_cast<uint32_t>(1u * sizeof(elements[0]));
518 ASSERT_EQ(MOJO_RESULT_OK, ReadData(elements, &num_bytes, true, true)); 530 ASSERT_EQ(MOJO_RESULT_OK, ReadData(elements, &num_bytes, true, true));
519 ASSERT_EQ(456, elements[0]); 531 ASSERT_EQ(456, elements[0]);
520 ASSERT_EQ(-1, elements[1]); 532 ASSERT_EQ(-1, elements[1]);
521 533
522 // Should still be readable. 534 // Should still be readable.
523 hss = MojoHandleSignalsState(); 535 hss = MojoHandleSignalsState();
524 ASSERT_EQ(MOJO_RESULT_OK, 536 ASSERT_EQ(MOJO_RESULT_OK,
525 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_READABLE, 537 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_READABLE,
526 MOJO_DEADLINE_INDEFINITE, &hss)); 538 MOJO_DEADLINE_INDEFINITE, &hss));
527 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals); 539 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals);
528 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, 540 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED |
541 MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
529 hss.satisfiable_signals); 542 hss.satisfiable_signals);
530 543
531 // Read one element. 544 // Read one element.
532 elements[0] = -1; 545 elements[0] = -1;
533 elements[1] = -1; 546 elements[1] = -1;
534 num_bytes = static_cast<uint32_t>(1u * sizeof(elements[0])); 547 num_bytes = static_cast<uint32_t>(1u * sizeof(elements[0]));
535 ASSERT_EQ(MOJO_RESULT_OK, ReadData(elements, &num_bytes, true)); 548 ASSERT_EQ(MOJO_RESULT_OK, ReadData(elements, &num_bytes, true));
536 ASSERT_EQ(static_cast<uint32_t>(1u * sizeof(elements[0])), num_bytes); 549 ASSERT_EQ(static_cast<uint32_t>(1u * sizeof(elements[0])), num_bytes);
537 ASSERT_EQ(456, elements[0]); 550 ASSERT_EQ(456, elements[0]);
538 ASSERT_EQ(-1, elements[1]); 551 ASSERT_EQ(-1, elements[1]);
539 552
540 // Write one element. 553 // Write one element.
541 elements[0] = 789; 554 elements[0] = 789;
542 elements[1] = -1; 555 elements[1] = -1;
543 num_bytes = static_cast<uint32_t>(1u * sizeof(elements[0])); 556 num_bytes = static_cast<uint32_t>(1u * sizeof(elements[0]));
544 ASSERT_EQ(MOJO_RESULT_OK, WriteData(elements, &num_bytes, true)); 557 ASSERT_EQ(MOJO_RESULT_OK, WriteData(elements, &num_bytes, true));
545 558
546 // Waiting should now succeed. 559 // Waiting should now succeed.
547 hss = MojoHandleSignalsState(); 560 hss = MojoHandleSignalsState();
548 ASSERT_EQ(MOJO_RESULT_OK, 561 ASSERT_EQ(MOJO_RESULT_OK,
549 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_READABLE, 562 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_READABLE,
550 MOJO_DEADLINE_INDEFINITE, &hss)); 563 MOJO_DEADLINE_INDEFINITE, &hss));
551 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals); 564 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
552 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, 565 hss.satisfied_signals);
566 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED |
567 MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
553 hss.satisfiable_signals); 568 hss.satisfiable_signals);
554 569
555 // Close the producer. 570 // Close the producer.
556 CloseProducer(); 571 CloseProducer();
557 572
558 // Should still be readable. 573 // Should still be readable.
559 hss = MojoHandleSignalsState(); 574 hss = MojoHandleSignalsState();
560 ASSERT_EQ(MOJO_RESULT_OK, 575 ASSERT_EQ(MOJO_RESULT_OK,
561 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_READABLE, 576 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_READABLE,
562 MOJO_DEADLINE_INDEFINITE, &hss)); 577 MOJO_DEADLINE_INDEFINITE, &hss));
563 ASSERT_TRUE((hss.satisfied_signals & MOJO_HANDLE_SIGNAL_READABLE) != 0); 578 EXPECT_TRUE(hss.satisfied_signals & (MOJO_HANDLE_SIGNAL_READABLE |
564 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, 579 MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE));
580 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED |
581 MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
565 hss.satisfiable_signals); 582 hss.satisfiable_signals);
566 583
567 // Wait for the peer closed signal. 584 // Wait for the peer closed signal.
568 hss = MojoHandleSignalsState(); 585 hss = MojoHandleSignalsState();
569 ASSERT_EQ(MOJO_RESULT_OK, 586 ASSERT_EQ(MOJO_RESULT_OK,
570 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_PEER_CLOSED, 587 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_PEER_CLOSED,
571 MOJO_DEADLINE_INDEFINITE, &hss)); 588 MOJO_DEADLINE_INDEFINITE, &hss));
572 ASSERT_TRUE((hss.satisfied_signals & MOJO_HANDLE_SIGNAL_PEER_CLOSED) != 0); 589 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE |
573 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, 590 MOJO_HANDLE_SIGNAL_PEER_CLOSED,
591 hss.satisfied_signals);
592 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED |
593 MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
574 hss.satisfiable_signals); 594 hss.satisfiable_signals);
575 595
576 // Read one element. 596 // Read one element.
577 elements[0] = -1; 597 elements[0] = -1;
578 elements[1] = -1; 598 elements[1] = -1;
579 num_bytes = static_cast<uint32_t>(1u * sizeof(elements[0])); 599 num_bytes = static_cast<uint32_t>(1u * sizeof(elements[0]));
580 ASSERT_EQ(MOJO_RESULT_OK, ReadData(elements, &num_bytes, true)); 600 ASSERT_EQ(MOJO_RESULT_OK, ReadData(elements, &num_bytes, true));
581 ASSERT_EQ(static_cast<uint32_t>(1u * sizeof(elements[0])), num_bytes); 601 ASSERT_EQ(static_cast<uint32_t>(1u * sizeof(elements[0])), num_bytes);
582 ASSERT_EQ(789, elements[0]); 602 ASSERT_EQ(789, elements[0]);
583 ASSERT_EQ(-1, elements[1]); 603 ASSERT_EQ(-1, elements[1]);
584 604
585 // Should be never-readable. 605 // Should be never-readable.
586 hss = MojoHandleSignalsState(); 606 hss = MojoHandleSignalsState();
587 ASSERT_EQ(MOJO_RESULT_FAILED_PRECONDITION, 607 ASSERT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
588 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_READABLE, 608 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_READABLE,
589 MOJO_DEADLINE_INDEFINITE, &hss)); 609 MOJO_DEADLINE_INDEFINITE, &hss));
590 ASSERT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfied_signals); 610 ASSERT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfied_signals);
591 ASSERT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfiable_signals); 611 ASSERT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfiable_signals);
592 } 612 }
593 613
614 TEST_F(DataPipeTest, ConsumerNewDataReadable) {
615 const MojoCreateDataPipeOptions options = {
616 kSizeOfOptions, // |struct_size|.
617 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|.
618 static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|.
619 1000 * sizeof(int32_t) // |capacity_num_bytes|.
620 };
621 EXPECT_EQ(MOJO_RESULT_OK, Create(&options));
622
623 int32_t elements[2] = {123, 456};
624 uint32_t num_bytes = static_cast<uint32_t>(2u * sizeof(elements[0]));
625 EXPECT_EQ(MOJO_RESULT_OK, WriteData(elements, &num_bytes, true));
626
627 // The consumer handle should appear to be readable and have new data.
628 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(consumer_, MOJO_HANDLE_SIGNAL_READABLE,
629 MOJO_DEADLINE_INDEFINITE, nullptr));
630 EXPECT_EQ(MOJO_RESULT_OK,
631 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
632 MOJO_DEADLINE_INDEFINITE, nullptr));
633
634 // Now try to read a minimum of 6 elements.
635 int32_t read_elements[6];
636 uint32_t num_read_bytes = sizeof(read_elements);
637 EXPECT_EQ(MOJO_RESULT_OUT_OF_RANGE,
638 MojoReadData(consumer_, read_elements, &num_read_bytes,
639 MOJO_READ_DATA_FLAG_ALL_OR_NONE));
640
641 // The consumer should still appear to be readable, but not with new data.
642 EXPECT_EQ(MOJO_RESULT_OK,
643 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_READABLE, 0, nullptr));
644 EXPECT_EQ(
645 MOJO_RESULT_DEADLINE_EXCEEDED,
646 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE, 0, nullptr));
647
648 // Write four more elements.
649 EXPECT_EQ(MOJO_RESULT_OK, WriteData(elements, &num_bytes, true));
650 EXPECT_EQ(MOJO_RESULT_OK, WriteData(elements, &num_bytes, true));
651
652 // The consumer handle should once again appear to be readable with new data.
653 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(consumer_, MOJO_HANDLE_SIGNAL_READABLE,
654 MOJO_DEADLINE_INDEFINITE, nullptr));
655 EXPECT_EQ(MOJO_RESULT_OK,
656 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
657 MOJO_DEADLINE_INDEFINITE, nullptr));
658
659 // Read should succeed this time.
660 EXPECT_EQ(MOJO_RESULT_OK,
661 MojoReadData(consumer_, read_elements, &num_read_bytes,
662 MOJO_READ_DATA_FLAG_ALL_OR_NONE));
663
664 // And once again the consumer is unreadable.
665 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED,
666 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_READABLE, 0, nullptr));
667 EXPECT_EQ(
668 MOJO_RESULT_DEADLINE_EXCEEDED,
669 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE, 0, nullptr));
670 }
671
594 // Test with two-phase APIs and also closing the producer with an active 672 // Test with two-phase APIs and also closing the producer with an active
595 // consumer waiter. 673 // consumer waiter.
596 TEST_F(DataPipeTest, ConsumerWaitingTwoPhase) { 674 TEST_F(DataPipeTest, ConsumerWaitingTwoPhase) {
597 const MojoCreateDataPipeOptions options = { 675 const MojoCreateDataPipeOptions options = {
598 kSizeOfOptions, // |struct_size|. 676 kSizeOfOptions, // |struct_size|.
599 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|. 677 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|.
600 static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|. 678 static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|.
601 1000 * sizeof(int32_t) // |capacity_num_bytes|. 679 1000 * sizeof(int32_t) // |capacity_num_bytes|.
602 }; 680 };
603 ASSERT_EQ(MOJO_RESULT_OK, Create(&options)); 681 ASSERT_EQ(MOJO_RESULT_OK, Create(&options));
604 MojoHandleSignalsState hss; 682 MojoHandleSignalsState hss;
605 683
606 // Write two elements. 684 // Write two elements.
607 int32_t* elements = nullptr; 685 int32_t* elements = nullptr;
608 void* buffer = nullptr; 686 void* buffer = nullptr;
609 // Request room for three (but we'll only write two). 687 // Request room for three (but we'll only write two).
610 uint32_t num_bytes = static_cast<uint32_t>(3u * sizeof(elements[0])); 688 uint32_t num_bytes = static_cast<uint32_t>(3u * sizeof(elements[0]));
611 ASSERT_EQ(MOJO_RESULT_OK, BeginWriteData(&buffer, &num_bytes, true)); 689 ASSERT_EQ(MOJO_RESULT_OK, BeginWriteData(&buffer, &num_bytes, false));
612 EXPECT_TRUE(buffer); 690 EXPECT_TRUE(buffer);
613 EXPECT_GE(num_bytes, static_cast<uint32_t>(3u * sizeof(elements[0]))); 691 EXPECT_GE(num_bytes, static_cast<uint32_t>(3u * sizeof(elements[0])));
614 elements = static_cast<int32_t*>(buffer); 692 elements = static_cast<int32_t*>(buffer);
615 elements[0] = 123; 693 elements[0] = 123;
616 elements[1] = 456; 694 elements[1] = 456;
617 ASSERT_EQ(MOJO_RESULT_OK, EndWriteData(2u * sizeof(elements[0]))); 695 ASSERT_EQ(MOJO_RESULT_OK, EndWriteData(2u * sizeof(elements[0])));
618 696
619 // Wait for readability. 697 // Wait for readability.
620 hss = MojoHandleSignalsState(); 698 hss = MojoHandleSignalsState();
621 ASSERT_EQ(MOJO_RESULT_OK, 699 ASSERT_EQ(MOJO_RESULT_OK,
622 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_READABLE, 700 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_READABLE,
623 MOJO_DEADLINE_INDEFINITE, &hss)); 701 MOJO_DEADLINE_INDEFINITE, &hss));
624 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals); 702 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
625 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, 703 hss.satisfied_signals);
704 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED |
705 MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
626 hss.satisfiable_signals); 706 hss.satisfiable_signals);
627 707
628 // Read one element. 708 // Read one element.
629 // Request two in all-or-none mode, but only read one. 709 // Request two in all-or-none mode, but only read one.
630 const void* read_buffer = nullptr; 710 const void* read_buffer = nullptr;
631 num_bytes = static_cast<uint32_t>(2u * sizeof(elements[0])); 711 num_bytes = static_cast<uint32_t>(2u * sizeof(elements[0]));
632 ASSERT_EQ(MOJO_RESULT_OK, BeginReadData(&read_buffer, &num_bytes, true)); 712 ASSERT_EQ(MOJO_RESULT_OK, BeginReadData(&read_buffer, &num_bytes, true));
633 EXPECT_TRUE(read_buffer); 713 EXPECT_TRUE(read_buffer);
634 ASSERT_EQ(static_cast<uint32_t>(2u * sizeof(elements[0])), num_bytes); 714 ASSERT_EQ(static_cast<uint32_t>(2u * sizeof(elements[0])), num_bytes);
635 const int32_t* read_elements = static_cast<const int32_t*>(read_buffer); 715 const int32_t* read_elements = static_cast<const int32_t*>(read_buffer);
636 ASSERT_EQ(123, read_elements[0]); 716 ASSERT_EQ(123, read_elements[0]);
637 ASSERT_EQ(MOJO_RESULT_OK, EndReadData(1u * sizeof(elements[0]))); 717 ASSERT_EQ(MOJO_RESULT_OK, EndReadData(1u * sizeof(elements[0])));
638 718
639 // Should still be readable. 719 // Should still be readable.
640 hss = MojoHandleSignalsState(); 720 hss = MojoHandleSignalsState();
641 ASSERT_EQ(MOJO_RESULT_OK, 721 ASSERT_EQ(MOJO_RESULT_OK,
642 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_READABLE, 722 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_READABLE,
643 MOJO_DEADLINE_INDEFINITE, &hss)); 723 MOJO_DEADLINE_INDEFINITE, &hss));
644 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals); 724 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals);
645 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, 725 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED |
726 MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
646 hss.satisfiable_signals); 727 hss.satisfiable_signals);
647 728
648 // Read one element. 729 // Read one element.
649 // Request three, but not in all-or-none mode. 730 // Request three, but not in all-or-none mode.
650 read_buffer = nullptr; 731 read_buffer = nullptr;
651 num_bytes = static_cast<uint32_t>(3u * sizeof(elements[0])); 732 num_bytes = static_cast<uint32_t>(3u * sizeof(elements[0]));
652 ASSERT_EQ(MOJO_RESULT_OK, BeginReadData(&read_buffer, &num_bytes)); 733 ASSERT_EQ(MOJO_RESULT_OK, BeginReadData(&read_buffer, &num_bytes));
653 EXPECT_TRUE(read_buffer); 734 EXPECT_TRUE(read_buffer);
654 ASSERT_EQ(static_cast<uint32_t>(1u * sizeof(elements[0])), num_bytes); 735 ASSERT_EQ(static_cast<uint32_t>(1u * sizeof(elements[0])), num_bytes);
655 read_elements = static_cast<const int32_t*>(read_buffer); 736 read_elements = static_cast<const int32_t*>(read_buffer);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 MojoWait(producer_, MOJO_HANDLE_SIGNAL_WRITABLE, 0, &hss)); 780 MojoWait(producer_, MOJO_HANDLE_SIGNAL_WRITABLE, 0, &hss));
700 ASSERT_EQ(0u, hss.satisfied_signals); 781 ASSERT_EQ(0u, hss.satisfied_signals);
701 ASSERT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, 782 ASSERT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED,
702 hss.satisfiable_signals); 783 hss.satisfiable_signals);
703 784
704 // It shouldn't be readable yet either (we'll wait later). 785 // It shouldn't be readable yet either (we'll wait later).
705 hss = MojoHandleSignalsState(); 786 hss = MojoHandleSignalsState();
706 ASSERT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, 787 ASSERT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED,
707 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_READABLE, 0, &hss)); 788 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_READABLE, 0, &hss));
708 ASSERT_EQ(0u, hss.satisfied_signals); 789 ASSERT_EQ(0u, hss.satisfied_signals);
709 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, 790 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED |
791 MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
710 hss.satisfiable_signals); 792 hss.satisfiable_signals);
711 793
712 static_cast<int32_t*>(write_ptr)[0] = 123; 794 static_cast<int32_t*>(write_ptr)[0] = 123;
713 ASSERT_EQ(MOJO_RESULT_OK, EndWriteData(1u * sizeof(int32_t))); 795 ASSERT_EQ(MOJO_RESULT_OK, EndWriteData(1u * sizeof(int32_t)));
714 796
715 // It should immediately be writable again. 797 // It should immediately be writable again.
716 hss = MojoHandleSignalsState(); 798 hss = MojoHandleSignalsState();
717 ASSERT_EQ(MOJO_RESULT_OK, 799 ASSERT_EQ(MOJO_RESULT_OK,
718 MojoWait(producer_, MOJO_HANDLE_SIGNAL_WRITABLE, 0, &hss)); 800 MojoWait(producer_, MOJO_HANDLE_SIGNAL_WRITABLE, 0, &hss));
719 ASSERT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals); 801 ASSERT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals);
720 ASSERT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, 802 ASSERT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED,
721 hss.satisfiable_signals); 803 hss.satisfiable_signals);
722 804
723 // It should become readable. 805 // It should become readable.
724 hss = MojoHandleSignalsState(); 806 hss = MojoHandleSignalsState();
725 ASSERT_EQ(MOJO_RESULT_OK, 807 ASSERT_EQ(MOJO_RESULT_OK,
726 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_READABLE, 808 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_READABLE,
727 MOJO_DEADLINE_INDEFINITE, &hss)); 809 MOJO_DEADLINE_INDEFINITE, &hss));
728 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals); 810 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
729 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, 811 hss.satisfied_signals);
812 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED |
813 MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
730 hss.satisfiable_signals); 814 hss.satisfiable_signals);
731 815
732 // Start another two-phase write and check that it's readable even in the 816 // Start another two-phase write and check that it's readable even in the
733 // middle of it. 817 // middle of it.
734 num_bytes = static_cast<uint32_t>(1u * sizeof(int32_t)); 818 num_bytes = static_cast<uint32_t>(1u * sizeof(int32_t));
735 write_ptr = nullptr; 819 write_ptr = nullptr;
736 ASSERT_EQ(MOJO_RESULT_OK, BeginWriteData(&write_ptr, &num_bytes)); 820 ASSERT_EQ(MOJO_RESULT_OK, BeginWriteData(&write_ptr, &num_bytes));
737 EXPECT_TRUE(write_ptr); 821 EXPECT_TRUE(write_ptr);
738 EXPECT_GE(num_bytes, static_cast<uint32_t>(1u * sizeof(int32_t))); 822 EXPECT_GE(num_bytes, static_cast<uint32_t>(1u * sizeof(int32_t)));
739 823
740 // It should be readable. 824 // It should be readable.
741 hss = MojoHandleSignalsState(); 825 hss = MojoHandleSignalsState();
742 ASSERT_EQ(MOJO_RESULT_OK, 826 ASSERT_EQ(MOJO_RESULT_OK,
743 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_READABLE, 827 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_READABLE,
744 MOJO_DEADLINE_INDEFINITE, &hss)); 828 MOJO_DEADLINE_INDEFINITE, &hss));
745 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals); 829 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
746 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, 830 hss.satisfied_signals);
831 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED |
832 MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
747 hss.satisfiable_signals); 833 hss.satisfiable_signals);
748 834
749 // End the two-phase write without writing anything. 835 // End the two-phase write without writing anything.
750 ASSERT_EQ(MOJO_RESULT_OK, EndWriteData(0u)); 836 ASSERT_EQ(MOJO_RESULT_OK, EndWriteData(0u));
751 837
752 // Start a two-phase read. 838 // Start a two-phase read.
753 num_bytes = static_cast<uint32_t>(1u * sizeof(int32_t)); 839 num_bytes = static_cast<uint32_t>(1u * sizeof(int32_t));
754 const void* read_ptr = nullptr; 840 const void* read_ptr = nullptr;
755 ASSERT_EQ(MOJO_RESULT_OK, BeginReadData(&read_ptr, &num_bytes)); 841 ASSERT_EQ(MOJO_RESULT_OK, BeginReadData(&read_ptr, &num_bytes));
756 EXPECT_TRUE(read_ptr); 842 EXPECT_TRUE(read_ptr);
757 ASSERT_EQ(static_cast<uint32_t>(1u * sizeof(int32_t)), num_bytes); 843 ASSERT_EQ(static_cast<uint32_t>(1u * sizeof(int32_t)), num_bytes);
758 844
759 // At this point, it should still be writable. 845 // At this point, it should still be writable.
760 hss = MojoHandleSignalsState(); 846 hss = MojoHandleSignalsState();
761 ASSERT_EQ(MOJO_RESULT_OK, 847 ASSERT_EQ(MOJO_RESULT_OK,
762 MojoWait(producer_, MOJO_HANDLE_SIGNAL_WRITABLE, 0, &hss)); 848 MojoWait(producer_, MOJO_HANDLE_SIGNAL_WRITABLE, 0, &hss));
763 ASSERT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals); 849 ASSERT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals);
764 ASSERT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, 850 ASSERT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED,
765 hss.satisfiable_signals); 851 hss.satisfiable_signals);
766 852
767 // But not readable. 853 // But not readable.
768 hss = MojoHandleSignalsState(); 854 hss = MojoHandleSignalsState();
769 ASSERT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, 855 ASSERT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED,
770 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_READABLE, 0, &hss)); 856 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_READABLE, 0, &hss));
771 ASSERT_EQ(0u, hss.satisfied_signals); 857 ASSERT_EQ(0u, hss.satisfied_signals);
772 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, 858 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED |
859 MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
773 hss.satisfiable_signals); 860 hss.satisfiable_signals);
774 861
775 // End the two-phase read without reading anything. 862 // End the two-phase read without reading anything.
776 ASSERT_EQ(MOJO_RESULT_OK, EndReadData(0u)); 863 ASSERT_EQ(MOJO_RESULT_OK, EndReadData(0u));
777 864
778 // It should be readable again. 865 // It should be readable again.
779 hss = MojoHandleSignalsState(); 866 hss = MojoHandleSignalsState();
780 ASSERT_EQ(MOJO_RESULT_OK, 867 ASSERT_EQ(MOJO_RESULT_OK,
781 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_READABLE, 0, &hss)); 868 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_READABLE, 0, &hss));
782 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals); 869 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals);
783 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, 870 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED |
871 MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
784 hss.satisfiable_signals); 872 hss.satisfiable_signals);
785 } 873 }
786 874
787 void Seq(int32_t start, size_t count, int32_t* out) { 875 void Seq(int32_t start, size_t count, int32_t* out) {
788 for (size_t i = 0; i < count; i++) 876 for (size_t i = 0; i < count; i++)
789 out[i] = start + static_cast<int32_t>(i); 877 out[i] = start + static_cast<int32_t>(i);
790 } 878 }
791 879
792 TEST_F(DataPipeTest, AllOrNone) { 880 TEST_F(DataPipeTest, AllOrNone) {
793 const MojoCreateDataPipeOptions options = { 881 const MojoCreateDataPipeOptions options = {
(...skipping 24 matching lines...) Expand all
818 906
819 // Wait for data. 907 // Wait for data.
820 // TODO(vtl): There's no real guarantee that all the data will become 908 // TODO(vtl): There's no real guarantee that all the data will become
821 // available at once (except that in current implementations, with reasonable 909 // available at once (except that in current implementations, with reasonable
822 // limits, it will). Eventually, we'll be able to wait for a specified amount 910 // limits, it will). Eventually, we'll be able to wait for a specified amount
823 // of data to become available. 911 // of data to become available.
824 hss = MojoHandleSignalsState(); 912 hss = MojoHandleSignalsState();
825 ASSERT_EQ(MOJO_RESULT_OK, 913 ASSERT_EQ(MOJO_RESULT_OK,
826 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_READABLE, 914 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_READABLE,
827 MOJO_DEADLINE_INDEFINITE, &hss)); 915 MOJO_DEADLINE_INDEFINITE, &hss));
828 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals); 916 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
829 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, 917 hss.satisfied_signals);
918 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE |
919 MOJO_HANDLE_SIGNAL_PEER_CLOSED,
830 hss.satisfiable_signals); 920 hss.satisfiable_signals);
831 921
832 // Half full. 922 // Half full.
833 num_bytes = 0u; 923 num_bytes = 0u;
834 ASSERT_EQ(MOJO_RESULT_OK, QueryData(&num_bytes)); 924 ASSERT_EQ(MOJO_RESULT_OK, QueryData(&num_bytes));
835 ASSERT_EQ(5u * sizeof(int32_t), num_bytes); 925 ASSERT_EQ(5u * sizeof(int32_t), num_bytes);
836 926
837 // Try writing more than the available capacity of the pipe, but less than the 927 // Try writing more than the available capacity of the pipe, but less than the
838 // total capacity. 928 // total capacity.
839 num_bytes = 6u * sizeof(int32_t); 929 num_bytes = 6u * sizeof(int32_t);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 ASSERT_EQ(3u * sizeof(int32_t), num_bytes); 997 ASSERT_EQ(3u * sizeof(int32_t), num_bytes);
908 998
909 // Close the producer, then test producer-closed cases. 999 // Close the producer, then test producer-closed cases.
910 CloseProducer(); 1000 CloseProducer();
911 1001
912 // Wait. 1002 // Wait.
913 hss = MojoHandleSignalsState(); 1003 hss = MojoHandleSignalsState();
914 ASSERT_EQ(MOJO_RESULT_OK, 1004 ASSERT_EQ(MOJO_RESULT_OK,
915 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_PEER_CLOSED, 1005 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_PEER_CLOSED,
916 MOJO_DEADLINE_INDEFINITE, &hss)); 1006 MOJO_DEADLINE_INDEFINITE, &hss));
917 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, 1007 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED,
918 hss.satisfied_signals); 1008 hss.satisfied_signals);
919 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, 1009 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED,
920 hss.satisfiable_signals); 1010 hss.satisfiable_signals);
921 1011
922 // Try reading too much; "failed precondition" since the producer is closed. 1012 // Try reading too much; "failed precondition" since the producer is closed.
923 num_bytes = 4u * sizeof(int32_t); 1013 num_bytes = 4u * sizeof(int32_t);
924 memset(buffer, 0xab, sizeof(buffer)); 1014 memset(buffer, 0xab, sizeof(buffer));
925 ASSERT_EQ(MOJO_RESULT_FAILED_PRECONDITION, 1015 ASSERT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
926 ReadData(buffer, &num_bytes, true)); 1016 ReadData(buffer, &num_bytes, true));
927 memset(expected_buffer, 0xab, sizeof(expected_buffer)); 1017 memset(expected_buffer, 0xab, sizeof(expected_buffer));
928 ASSERT_EQ(0, memcmp(buffer, expected_buffer, sizeof(buffer))); 1018 ASSERT_EQ(0, memcmp(buffer, expected_buffer, sizeof(buffer)));
929 1019
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
972 1062
973 // Write 20 bytes. 1063 // Write 20 bytes.
974 uint32_t num_bytes = 20u; 1064 uint32_t num_bytes = 20u;
975 ASSERT_EQ(MOJO_RESULT_OK, WriteData(&test_data[0], &num_bytes, true)); 1065 ASSERT_EQ(MOJO_RESULT_OK, WriteData(&test_data[0], &num_bytes, true));
976 ASSERT_EQ(20u, num_bytes); 1066 ASSERT_EQ(20u, num_bytes);
977 1067
978 // Wait for data. 1068 // Wait for data.
979 ASSERT_EQ(MOJO_RESULT_OK, 1069 ASSERT_EQ(MOJO_RESULT_OK,
980 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_READABLE, 1070 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_READABLE,
981 MOJO_DEADLINE_INDEFINITE, &hss)); 1071 MOJO_DEADLINE_INDEFINITE, &hss));
982 ASSERT_TRUE((hss.satisfied_signals & MOJO_HANDLE_SIGNAL_READABLE) != 0); 1072 EXPECT_TRUE(hss.satisfied_signals & MOJO_HANDLE_SIGNAL_READABLE);
983 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, 1073 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED |
1074 MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
984 hss.satisfiable_signals); 1075 hss.satisfiable_signals);
985 1076
986 // Read 10 bytes. 1077 // Read 10 bytes.
987 unsigned char read_buffer[1000] = {0}; 1078 unsigned char read_buffer[1000] = {0};
988 num_bytes = 10u; 1079 num_bytes = 10u;
989 ASSERT_EQ(MOJO_RESULT_OK, ReadData(read_buffer, &num_bytes, true)); 1080 ASSERT_EQ(MOJO_RESULT_OK, ReadData(read_buffer, &num_bytes, true));
990 ASSERT_EQ(10u, num_bytes); 1081 ASSERT_EQ(10u, num_bytes);
991 ASSERT_EQ(0, memcmp(read_buffer, &test_data[0], 10u)); 1082 ASSERT_EQ(0, memcmp(read_buffer, &test_data[0], 10u));
992 1083
993 // Check that a two-phase write can now only write (at most) 80 bytes. (This 1084 // Check that a two-phase write can now only write (at most) 80 bytes. (This
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
1135 ASSERT_EQ(MOJO_RESULT_OK, BeginWriteData(&write_buffer_ptr, &num_bytes)); 1226 ASSERT_EQ(MOJO_RESULT_OK, BeginWriteData(&write_buffer_ptr, &num_bytes));
1136 EXPECT_TRUE(write_buffer_ptr); 1227 EXPECT_TRUE(write_buffer_ptr);
1137 ASSERT_GT(num_bytes, kTestDataSize); 1228 ASSERT_GT(num_bytes, kTestDataSize);
1138 1229
1139 // Wait for data. 1230 // Wait for data.
1140 // TODO(vtl): (See corresponding TODO in AllOrNone.) 1231 // TODO(vtl): (See corresponding TODO in AllOrNone.)
1141 hss = MojoHandleSignalsState(); 1232 hss = MojoHandleSignalsState();
1142 ASSERT_EQ(MOJO_RESULT_OK, 1233 ASSERT_EQ(MOJO_RESULT_OK,
1143 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_READABLE, 1234 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_READABLE,
1144 MOJO_DEADLINE_INDEFINITE, &hss)); 1235 MOJO_DEADLINE_INDEFINITE, &hss));
1145 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals); 1236 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
1146 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, 1237 hss.satisfied_signals);
1238 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED |
1239 MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
1147 hss.satisfiable_signals); 1240 hss.satisfiable_signals);
1148 1241
1149 // Start two-phase read. 1242 // Start two-phase read.
1150 const void* read_buffer_ptr = nullptr; 1243 const void* read_buffer_ptr = nullptr;
1151 num_bytes = 0u; 1244 num_bytes = 0u;
1152 ASSERT_EQ(MOJO_RESULT_OK, BeginReadData(&read_buffer_ptr, &num_bytes)); 1245 ASSERT_EQ(MOJO_RESULT_OK, BeginReadData(&read_buffer_ptr, &num_bytes));
1153 EXPECT_TRUE(read_buffer_ptr); 1246 EXPECT_TRUE(read_buffer_ptr);
1154 ASSERT_EQ(kTestDataSize, num_bytes); 1247 ASSERT_EQ(kTestDataSize, num_bytes);
1155 1248
1156 // Close the consumer. 1249 // Close the consumer.
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1225 1318
1226 // Close the producer. 1319 // Close the producer.
1227 CloseProducer(); 1320 CloseProducer();
1228 1321
1229 // Wait. (Note that once the consumer knows that the producer is closed, it 1322 // Wait. (Note that once the consumer knows that the producer is closed, it
1230 // must also know about all the data that was sent.) 1323 // must also know about all the data that was sent.)
1231 hss = MojoHandleSignalsState(); 1324 hss = MojoHandleSignalsState();
1232 ASSERT_EQ(MOJO_RESULT_OK, 1325 ASSERT_EQ(MOJO_RESULT_OK,
1233 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_PEER_CLOSED, 1326 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_PEER_CLOSED,
1234 MOJO_DEADLINE_INDEFINITE, &hss)); 1327 MOJO_DEADLINE_INDEFINITE, &hss));
1235 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, 1328 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED |
1329 MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
1236 hss.satisfied_signals); 1330 hss.satisfied_signals);
1237 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, 1331 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED |
1332 MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
1238 hss.satisfiable_signals); 1333 hss.satisfiable_signals);
1239 1334
1240 // Peek that data. 1335 // Peek that data.
1241 char buffer[1000]; 1336 char buffer[1000];
1242 num_bytes = static_cast<uint32_t>(sizeof(buffer)); 1337 num_bytes = static_cast<uint32_t>(sizeof(buffer));
1243 ASSERT_EQ(MOJO_RESULT_OK, ReadData(buffer, &num_bytes, false, true)); 1338 ASSERT_EQ(MOJO_RESULT_OK, ReadData(buffer, &num_bytes, false, true));
1244 ASSERT_EQ(kTestDataSize, num_bytes); 1339 ASSERT_EQ(kTestDataSize, num_bytes);
1245 ASSERT_EQ(0, memcmp(buffer, kTestData, kTestDataSize)); 1340 ASSERT_EQ(0, memcmp(buffer, kTestData, kTestDataSize));
1246 1341
1247 // Read that data. 1342 // Read that data.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1284 // Write some data. 1379 // Write some data.
1285 uint32_t num_bytes = kTestDataSize; 1380 uint32_t num_bytes = kTestDataSize;
1286 ASSERT_EQ(MOJO_RESULT_OK, WriteData(kTestData, &num_bytes)); 1381 ASSERT_EQ(MOJO_RESULT_OK, WriteData(kTestData, &num_bytes));
1287 ASSERT_EQ(kTestDataSize, num_bytes); 1382 ASSERT_EQ(kTestDataSize, num_bytes);
1288 1383
1289 // Wait for the data. 1384 // Wait for the data.
1290 hss = MojoHandleSignalsState(); 1385 hss = MojoHandleSignalsState();
1291 ASSERT_EQ(MOJO_RESULT_OK, 1386 ASSERT_EQ(MOJO_RESULT_OK,
1292 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_READABLE, 1387 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_READABLE,
1293 MOJO_DEADLINE_INDEFINITE, &hss)); 1388 MOJO_DEADLINE_INDEFINITE, &hss));
1294 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals); 1389 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
1295 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, 1390 hss.satisfied_signals);
1391 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED |
1392 MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
1296 hss.satisfiable_signals); 1393 hss.satisfiable_signals);
1297 1394
1298 // Begin a two-phase read. 1395 // Begin a two-phase read.
1299 const void* read_buffer_ptr = nullptr; 1396 const void* read_buffer_ptr = nullptr;
1300 uint32_t read_buffer_size = 0u; 1397 uint32_t read_buffer_size = 0u;
1301 ASSERT_EQ(MOJO_RESULT_OK, BeginReadData(&read_buffer_ptr, &read_buffer_size)); 1398 ASSERT_EQ(MOJO_RESULT_OK, BeginReadData(&read_buffer_ptr, &read_buffer_size));
1302 1399
1303 // Write more data. 1400 // Write more data.
1304 const char kExtraData[] = "bye world"; 1401 const char kExtraData[] = "bye world";
1305 const uint32_t kExtraDataSize = static_cast<uint32_t>(sizeof(kExtraData)); 1402 const uint32_t kExtraDataSize = static_cast<uint32_t>(sizeof(kExtraData));
1306 num_bytes = kExtraDataSize; 1403 num_bytes = kExtraDataSize;
1307 ASSERT_EQ(MOJO_RESULT_OK, WriteData(kExtraData, &num_bytes)); 1404 ASSERT_EQ(MOJO_RESULT_OK, WriteData(kExtraData, &num_bytes));
1308 ASSERT_EQ(kExtraDataSize, num_bytes); 1405 ASSERT_EQ(kExtraDataSize, num_bytes);
1309 1406
1310 // Close the producer. 1407 // Close the producer.
1311 CloseProducer(); 1408 CloseProducer();
1312 1409
1313 // Wait. (Note that once the consumer knows that the producer is closed, it 1410 // Wait. (Note that once the consumer knows that the producer is closed, it
1314 // must also have received the extra data). 1411 // must also have received the extra data).
1315 hss = MojoHandleSignalsState(); 1412 hss = MojoHandleSignalsState();
1316 ASSERT_EQ(MOJO_RESULT_OK, 1413 ASSERT_EQ(MOJO_RESULT_OK,
1317 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_PEER_CLOSED, 1414 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_PEER_CLOSED,
1318 MOJO_DEADLINE_INDEFINITE, &hss)); 1415 MOJO_DEADLINE_INDEFINITE, &hss));
1319 ASSERT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfied_signals); 1416 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfied_signals);
1320 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, 1417 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED |
1418 MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
1321 hss.satisfiable_signals); 1419 hss.satisfiable_signals);
1322 1420
1323 // Read the two phase memory to check it's still valid. 1421 // Read the two phase memory to check it's still valid.
1324 ASSERT_EQ(0, memcmp(read_buffer_ptr, kTestData, kTestDataSize)); 1422 ASSERT_EQ(0, memcmp(read_buffer_ptr, kTestData, kTestDataSize));
1325 EndReadData(read_buffer_size); 1423 EndReadData(read_buffer_size);
1326 } 1424 }
1327 1425
1328 // Test that two-phase reads/writes behave correctly when given invalid 1426 // Test that two-phase reads/writes behave correctly when given invalid
1329 // arguments. 1427 // arguments.
1330 TEST_F(DataPipeTest, TwoPhaseMoreInvalidArguments) { 1428 TEST_F(DataPipeTest, TwoPhaseMoreInvalidArguments) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1396 int32_t element = 123; 1494 int32_t element = 123;
1397 num_bytes = 1u * sizeof(int32_t); 1495 num_bytes = 1u * sizeof(int32_t);
1398 ASSERT_EQ(MOJO_RESULT_OK, WriteData(&element, &num_bytes)); 1496 ASSERT_EQ(MOJO_RESULT_OK, WriteData(&element, &num_bytes));
1399 1497
1400 // Wait for data. 1498 // Wait for data.
1401 // TODO(vtl): (See corresponding TODO in AllOrNone.) 1499 // TODO(vtl): (See corresponding TODO in AllOrNone.)
1402 hss = MojoHandleSignalsState(); 1500 hss = MojoHandleSignalsState();
1403 ASSERT_EQ(MOJO_RESULT_OK, 1501 ASSERT_EQ(MOJO_RESULT_OK,
1404 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_READABLE, 1502 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_READABLE,
1405 MOJO_DEADLINE_INDEFINITE, &hss)); 1503 MOJO_DEADLINE_INDEFINITE, &hss));
1406 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals); 1504 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
1407 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, 1505 hss.satisfied_signals);
1506 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED |
1507 MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
1408 hss.satisfiable_signals); 1508 hss.satisfiable_signals);
1409 1509
1410 // One element available. 1510 // One element available.
1411 num_bytes = 0u; 1511 num_bytes = 0u;
1412 ASSERT_EQ(MOJO_RESULT_OK, QueryData(&num_bytes)); 1512 ASSERT_EQ(MOJO_RESULT_OK, QueryData(&num_bytes));
1413 ASSERT_EQ(1u * sizeof(int32_t), num_bytes); 1513 ASSERT_EQ(1u * sizeof(int32_t), num_bytes);
1414 1514
1415 // Try "ending" a two-phase read when one isn't active. 1515 // Try "ending" a two-phase read when one isn't active.
1416 ASSERT_EQ(MOJO_RESULT_FAILED_PRECONDITION, EndReadData(1u * sizeof(int32_t))); 1516 ASSERT_EQ(MOJO_RESULT_FAILED_PRECONDITION, EndReadData(1u * sizeof(int32_t)));
1417 1517
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1464 // Write some data. 1564 // Write some data.
1465 uint32_t num_bytes = kTestDataSize; 1565 uint32_t num_bytes = kTestDataSize;
1466 ASSERT_EQ(MOJO_RESULT_OK, WriteData(kTestData, &num_bytes)); 1566 ASSERT_EQ(MOJO_RESULT_OK, WriteData(kTestData, &num_bytes));
1467 ASSERT_EQ(kTestDataSize, num_bytes); 1567 ASSERT_EQ(kTestDataSize, num_bytes);
1468 1568
1469 // Wait for the data. 1569 // Wait for the data.
1470 hss = MojoHandleSignalsState(); 1570 hss = MojoHandleSignalsState();
1471 ASSERT_EQ(MOJO_RESULT_OK, 1571 ASSERT_EQ(MOJO_RESULT_OK,
1472 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_READABLE, 1572 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_READABLE,
1473 MOJO_DEADLINE_INDEFINITE, &hss)); 1573 MOJO_DEADLINE_INDEFINITE, &hss));
1474 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals); 1574 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
1475 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, 1575 hss.satisfied_signals);
1576 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED |
1577 MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
1476 hss.satisfiable_signals); 1578 hss.satisfiable_signals);
1477 1579
1478 // Check the data. 1580 // Check the data.
1479 const void* read_buffer = nullptr; 1581 const void* read_buffer = nullptr;
1480 num_bytes = 0u; 1582 num_bytes = 0u;
1481 ASSERT_EQ(MOJO_RESULT_OK, 1583 ASSERT_EQ(MOJO_RESULT_OK,
1482 BeginReadData(&read_buffer, &num_bytes, false)); 1584 BeginReadData(&read_buffer, &num_bytes, false));
1483 ASSERT_EQ(0, memcmp(read_buffer, kTestData, kTestDataSize)); 1585 ASSERT_EQ(0, memcmp(read_buffer, kTestData, kTestDataSize));
1484 EndReadData(num_bytes); 1586 EndReadData(num_bytes);
1485 1587
(...skipping 19 matching lines...) Expand all
1505 const uint32_t kExtraDataSize = static_cast<uint32_t>(sizeof(kExtraData)); 1607 const uint32_t kExtraDataSize = static_cast<uint32_t>(sizeof(kExtraData));
1506 num_bytes = kExtraDataSize; 1608 num_bytes = kExtraDataSize;
1507 ASSERT_EQ(MOJO_RESULT_OK, WriteData(kExtraData, &num_bytes)); 1609 ASSERT_EQ(MOJO_RESULT_OK, WriteData(kExtraData, &num_bytes));
1508 ASSERT_EQ(kExtraDataSize, num_bytes); 1610 ASSERT_EQ(kExtraDataSize, num_bytes);
1509 1611
1510 // Wait for it. 1612 // Wait for it.
1511 hss = MojoHandleSignalsState(); 1613 hss = MojoHandleSignalsState();
1512 ASSERT_EQ(MOJO_RESULT_OK, 1614 ASSERT_EQ(MOJO_RESULT_OK,
1513 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_READABLE, 1615 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_READABLE,
1514 MOJO_DEADLINE_INDEFINITE, &hss)); 1616 MOJO_DEADLINE_INDEFINITE, &hss));
1515 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals); 1617 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
1516 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, 1618 hss.satisfied_signals);
1619 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED |
1620 MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
1517 hss.satisfiable_signals); 1621 hss.satisfiable_signals);
1518 1622
1519 // Check the second write. 1623 // Check the second write.
1520 num_bytes = 0u; 1624 num_bytes = 0u;
1521 ASSERT_EQ(MOJO_RESULT_OK, 1625 ASSERT_EQ(MOJO_RESULT_OK,
1522 BeginReadData(&read_buffer, &num_bytes, false)); 1626 BeginReadData(&read_buffer, &num_bytes, false));
1523 ASSERT_EQ(0, memcmp(read_buffer, kExtraData, kExtraDataSize)); 1627 ASSERT_EQ(0, memcmp(read_buffer, kExtraData, kExtraDataSize));
1524 EndReadData(num_bytes); 1628 EndReadData(num_bytes);
1525 1629
1526 ASSERT_EQ(MOJO_RESULT_OK, MojoClose(pipe0)); 1630 ASSERT_EQ(MOJO_RESULT_OK, MojoClose(pipe0));
(...skipping 17 matching lines...) Expand all
1544 int32_t data = 123; 1648 int32_t data = 123;
1545 uint32_t num_bytes = sizeof(data); 1649 uint32_t num_bytes = sizeof(data);
1546 ASSERT_EQ(MOJO_RESULT_OK, WriteData(&data, &num_bytes)); 1650 ASSERT_EQ(MOJO_RESULT_OK, WriteData(&data, &num_bytes));
1547 ASSERT_EQ(MOJO_RESULT_OK, CloseProducer()); 1651 ASSERT_EQ(MOJO_RESULT_OK, CloseProducer());
1548 1652
1549 // Now wait for the other side to become readable and to see the peer closed. 1653 // Now wait for the other side to become readable and to see the peer closed.
1550 MojoHandleSignalsState state; 1654 MojoHandleSignalsState state;
1551 ASSERT_EQ(MOJO_RESULT_OK, 1655 ASSERT_EQ(MOJO_RESULT_OK,
1552 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_PEER_CLOSED, 1656 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_PEER_CLOSED,
1553 MOJO_DEADLINE_INDEFINITE, &state)); 1657 MOJO_DEADLINE_INDEFINITE, &state));
1554 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, 1658 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED |
1659 MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
1555 state.satisfied_signals); 1660 state.satisfied_signals);
1556 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, 1661 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED |
1662 MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
1557 state.satisfiable_signals); 1663 state.satisfiable_signals);
1558 1664
1559 // Now send the consumer over a MP so that it's serialized. 1665 // Now send the consumer over a MP so that it's serialized.
1560 MojoHandle pipe0, pipe1; 1666 MojoHandle pipe0, pipe1;
1561 ASSERT_EQ(MOJO_RESULT_OK, 1667 ASSERT_EQ(MOJO_RESULT_OK,
1562 MojoCreateMessagePipe(nullptr, &pipe0, &pipe1)); 1668 MojoCreateMessagePipe(nullptr, &pipe0, &pipe1));
1563 1669
1564 ASSERT_EQ(MOJO_RESULT_OK, 1670 ASSERT_EQ(MOJO_RESULT_OK,
1565 MojoWriteMessage(pipe0, nullptr, 0, &consumer_, 1, 1671 MojoWriteMessage(pipe0, nullptr, 0, &consumer_, 1,
1566 MOJO_WRITE_MESSAGE_FLAG_NONE)); 1672 MOJO_WRITE_MESSAGE_FLAG_NONE));
1567 consumer_ = MOJO_HANDLE_INVALID; 1673 consumer_ = MOJO_HANDLE_INVALID;
1568 ASSERT_EQ(MOJO_RESULT_OK, MojoWait(pipe1, MOJO_HANDLE_SIGNAL_READABLE, 1674 ASSERT_EQ(MOJO_RESULT_OK, MojoWait(pipe1, MOJO_HANDLE_SIGNAL_READABLE,
1569 MOJO_DEADLINE_INDEFINITE, &state)); 1675 MOJO_DEADLINE_INDEFINITE, &state));
1570 uint32_t num_handles = 1; 1676 uint32_t num_handles = 1;
1571 ASSERT_EQ(MOJO_RESULT_OK, 1677 ASSERT_EQ(MOJO_RESULT_OK,
1572 MojoReadMessage(pipe1, nullptr, 0, &consumer_, &num_handles, 1678 MojoReadMessage(pipe1, nullptr, 0, &consumer_, &num_handles,
1573 MOJO_READ_MESSAGE_FLAG_NONE)); 1679 MOJO_READ_MESSAGE_FLAG_NONE));
1574 ASSERT_EQ(num_handles, 1u); 1680 ASSERT_EQ(num_handles, 1u);
1575 1681
1576 ASSERT_EQ(MOJO_RESULT_OK, 1682 ASSERT_EQ(MOJO_RESULT_OK,
1577 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_PEER_CLOSED, 1683 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_PEER_CLOSED,
1578 MOJO_DEADLINE_INDEFINITE, &state)); 1684 MOJO_DEADLINE_INDEFINITE, &state));
1579 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, 1685 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED |
1686 MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
1580 state.satisfied_signals); 1687 state.satisfied_signals);
1581 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, 1688 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED |
1689 MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
1582 state.satisfiable_signals); 1690 state.satisfiable_signals);
1583 1691
1584 int32_t read_data; 1692 int32_t read_data;
1585 ASSERT_EQ(MOJO_RESULT_OK, ReadData(&read_data, &num_bytes)); 1693 ASSERT_EQ(MOJO_RESULT_OK, ReadData(&read_data, &num_bytes));
1586 ASSERT_EQ(sizeof(read_data), num_bytes); 1694 ASSERT_EQ(sizeof(read_data), num_bytes);
1587 ASSERT_EQ(data, read_data); 1695 ASSERT_EQ(data, read_data);
1588 1696
1589 ASSERT_EQ(MOJO_RESULT_OK, MojoClose(pipe0)); 1697 ASSERT_EQ(MOJO_RESULT_OK, MojoClose(pipe0));
1590 ASSERT_EQ(MOJO_RESULT_OK, MojoClose(pipe1)); 1698 ASSERT_EQ(MOJO_RESULT_OK, MojoClose(pipe1));
1591 } 1699 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1643 } 1751 }
1644 } else { 1752 } else {
1645 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT, result); 1753 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT, result);
1646 } 1754 }
1647 1755
1648 MojoHandleSignalsState hss = MojoHandleSignalsState(); 1756 MojoHandleSignalsState hss = MojoHandleSignalsState();
1649 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(consumer, MOJO_HANDLE_SIGNAL_READABLE, 1757 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(consumer, MOJO_HANDLE_SIGNAL_READABLE,
1650 MOJO_DEADLINE_INDEFINITE, &hss)); 1758 MOJO_DEADLINE_INDEFINITE, &hss));
1651 // Peer could have become closed while we're still waiting for data. 1759 // Peer could have become closed while we're still waiting for data.
1652 EXPECT_TRUE(MOJO_HANDLE_SIGNAL_READABLE & hss.satisfied_signals); 1760 EXPECT_TRUE(MOJO_HANDLE_SIGNAL_READABLE & hss.satisfied_signals);
1653 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, 1761 EXPECT_TRUE(hss.satisfiable_signals & MOJO_HANDLE_SIGNAL_READABLE);
1654 hss.satisfiable_signals); 1762 EXPECT_TRUE(hss.satisfiable_signals & MOJO_HANDLE_SIGNAL_PEER_CLOSED);
1655 } 1763 }
1656 1764
1657 return num_bytes == 0; 1765 return num_bytes == 0;
1658 } 1766 }
1659 1767
1660 #if !defined(OS_IOS) 1768 #if !defined(OS_IOS)
1661 1769
1662 TEST_F(DataPipeTest, Multiprocess) { 1770 TEST_F(DataPipeTest, Multiprocess) {
1663 const uint32_t kTestDataSize = 1771 const uint32_t kTestDataSize =
1664 static_cast<uint32_t>(sizeof(kMultiprocessTestData)); 1772 static_cast<uint32_t>(sizeof(kMultiprocessTestData));
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
1981 for (size_t i = 3; i < 6; ++i) 2089 for (size_t i = 3; i < 6; ++i)
1982 CloseHandle(producers[i]); 2090 CloseHandle(producers[i]);
1983 END_CHILD() 2091 END_CHILD()
1984 } 2092 }
1985 2093
1986 #endif // !defined(OS_IOS) 2094 #endif // !defined(OS_IOS)
1987 2095
1988 } // namespace 2096 } // namespace
1989 } // namespace edk 2097 } // namespace edk
1990 } // namespace mojo 2098 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/data_pipe_consumer_dispatcher.cc ('k') | mojo/public/c/system/tests/core_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698