OLD | NEW |
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 "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 | 360 |
361 // Read one element. | 361 // Read one element. |
362 elements[0] = -1; | 362 elements[0] = -1; |
363 elements[1] = -1; | 363 elements[1] = -1; |
364 num_bytes = static_cast<uint32_t>(1u * sizeof(elements[0])); | 364 num_bytes = static_cast<uint32_t>(1u * sizeof(elements[0])); |
365 ASSERT_EQ(MOJO_RESULT_OK, ReadData(elements, &num_bytes, true, false)); | 365 ASSERT_EQ(MOJO_RESULT_OK, ReadData(elements, &num_bytes, true, false)); |
366 ASSERT_EQ(static_cast<uint32_t>(1u * sizeof(elements[0])), num_bytes); | 366 ASSERT_EQ(static_cast<uint32_t>(1u * sizeof(elements[0])), num_bytes); |
367 ASSERT_EQ(123, elements[0]); | 367 ASSERT_EQ(123, elements[0]); |
368 ASSERT_EQ(-1, elements[1]); | 368 ASSERT_EQ(-1, elements[1]); |
369 | 369 |
| 370 // Wait until we can write. |
| 371 hss = MojoHandleSignalsState(); |
| 372 ASSERT_EQ(MOJO_RESULT_OK, MojoWait(producer_, MOJO_HANDLE_SIGNAL_WRITABLE, |
| 373 MOJO_DEADLINE_INDEFINITE, &hss)); |
| 374 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals); |
| 375 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, |
| 376 hss.satisfiable_signals); |
| 377 |
370 // Try writing, using a two-phase write. | 378 // Try writing, using a two-phase write. |
371 void* buffer = nullptr; | 379 void* buffer = nullptr; |
372 num_bytes = static_cast<uint32_t>(3u * sizeof(elements[0])); | 380 num_bytes = static_cast<uint32_t>(3u * sizeof(elements[0])); |
373 ASSERT_EQ(MOJO_RESULT_OK, BeginWriteData(&buffer, &num_bytes)); | 381 ASSERT_EQ(MOJO_RESULT_OK, BeginWriteData(&buffer, &num_bytes)); |
374 EXPECT_TRUE(buffer); | 382 EXPECT_TRUE(buffer); |
375 ASSERT_GE(num_bytes, static_cast<uint32_t>(1u * sizeof(elements[0]))); | 383 ASSERT_GE(num_bytes, static_cast<uint32_t>(1u * sizeof(elements[0]))); |
376 | 384 |
377 static_cast<int32_t*>(buffer)[0] = 789; | 385 static_cast<int32_t*>(buffer)[0] = 789; |
378 ASSERT_EQ(MOJO_RESULT_OK, EndWriteData(static_cast<uint32_t>( | 386 ASSERT_EQ(MOJO_RESULT_OK, EndWriteData(static_cast<uint32_t>( |
379 1u * sizeof(elements[0])))); | 387 1u * sizeof(elements[0])))); |
380 | 388 |
381 // Read one element, using a two-phase read. | 389 // Read one element, using a two-phase read. |
382 const void* read_buffer = nullptr; | 390 const void* read_buffer = nullptr; |
383 num_bytes = 0u; | 391 num_bytes = 0u; |
384 ASSERT_EQ(MOJO_RESULT_OK, | 392 ASSERT_EQ(MOJO_RESULT_OK, |
385 BeginReadData(&read_buffer, &num_bytes, false)); | 393 BeginReadData(&read_buffer, &num_bytes, false)); |
386 EXPECT_TRUE(read_buffer); | 394 EXPECT_TRUE(read_buffer); |
387 // Since we only read one element (after having written three in all), the | 395 // Since we only read one element (after having written three in all), the |
388 // two-phase read should only allow us to read one. This checks an | 396 // two-phase read should only allow us to read one. This checks an |
389 // implementation detail! | 397 // implementation detail! |
390 ASSERT_EQ(static_cast<uint32_t>(1u * sizeof(elements[0])), num_bytes); | 398 ASSERT_EQ(static_cast<uint32_t>(1u * sizeof(elements[0])), num_bytes); |
391 ASSERT_EQ(456, static_cast<const int32_t*>(read_buffer)[0]); | 399 ASSERT_EQ(456, static_cast<const int32_t*>(read_buffer)[0]); |
392 ASSERT_EQ(MOJO_RESULT_OK, EndReadData(static_cast<uint32_t>( | 400 ASSERT_EQ(MOJO_RESULT_OK, EndReadData(static_cast<uint32_t>( |
393 1u * sizeof(elements[0])))); | 401 1u * sizeof(elements[0])))); |
394 | 402 |
| 403 // Wait until we can write. |
| 404 hss = MojoHandleSignalsState(); |
| 405 ASSERT_EQ(MOJO_RESULT_OK, MojoWait(producer_, MOJO_HANDLE_SIGNAL_WRITABLE, |
| 406 MOJO_DEADLINE_INDEFINITE, &hss)); |
| 407 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals); |
| 408 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, |
| 409 hss.satisfiable_signals); |
| 410 |
395 // Write one element. | 411 // Write one element. |
396 elements[0] = 123; | 412 elements[0] = 123; |
397 num_bytes = static_cast<uint32_t>(1u * sizeof(elements[0])); | 413 num_bytes = static_cast<uint32_t>(1u * sizeof(elements[0])); |
398 ASSERT_EQ(MOJO_RESULT_OK, WriteData(elements, &num_bytes)); | 414 ASSERT_EQ(MOJO_RESULT_OK, WriteData(elements, &num_bytes)); |
399 ASSERT_EQ(static_cast<uint32_t>(1u * sizeof(elements[0])), num_bytes); | 415 ASSERT_EQ(static_cast<uint32_t>(1u * sizeof(elements[0])), num_bytes); |
400 | 416 |
401 // Close the consumer. | 417 // Close the consumer. |
402 CloseConsumer(); | 418 CloseConsumer(); |
403 | 419 |
404 // It should now be never-writable. | 420 // It should now be never-writable. |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 MOJO_DEADLINE_INDEFINITE, &hss)); | 571 MOJO_DEADLINE_INDEFINITE, &hss)); |
556 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals); | 572 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals); |
557 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, | 573 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, |
558 hss.satisfiable_signals); | 574 hss.satisfiable_signals); |
559 | 575 |
560 // Wait for the peer closed signal. | 576 // Wait for the peer closed signal. |
561 hss = MojoHandleSignalsState(); | 577 hss = MojoHandleSignalsState(); |
562 ASSERT_EQ(MOJO_RESULT_OK, | 578 ASSERT_EQ(MOJO_RESULT_OK, |
563 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_PEER_CLOSED, | 579 MojoWait(consumer_, MOJO_HANDLE_SIGNAL_PEER_CLOSED, |
564 MOJO_DEADLINE_INDEFINITE, &hss)); | 580 MOJO_DEADLINE_INDEFINITE, &hss)); |
565 ASSERT_TRUE((hss.satisfied_signals & MOJO_HANDLE_SIGNAL_PEER_CLOSED) != 0); | 581 ASSERT_NE(0u, hss.satisfied_signals & MOJO_HANDLE_SIGNAL_PEER_CLOSED); |
566 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, | 582 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, |
567 hss.satisfiable_signals); | 583 hss.satisfiable_signals); |
568 | 584 |
569 // Read one element. | 585 // Read one element. |
570 elements[0] = -1; | 586 elements[0] = -1; |
571 elements[1] = -1; | 587 elements[1] = -1; |
572 num_bytes = static_cast<uint32_t>(1u * sizeof(elements[0])); | 588 num_bytes = static_cast<uint32_t>(1u * sizeof(elements[0])); |
573 ASSERT_EQ(MOJO_RESULT_OK, ReadData(elements, &num_bytes, true)); | 589 ASSERT_EQ(MOJO_RESULT_OK, ReadData(elements, &num_bytes, true)); |
574 ASSERT_EQ(static_cast<uint32_t>(1u * sizeof(elements[0])), num_bytes); | 590 ASSERT_EQ(static_cast<uint32_t>(1u * sizeof(elements[0])), num_bytes); |
575 ASSERT_EQ(789, elements[0]); | 591 ASSERT_EQ(789, elements[0]); |
(...skipping 1046 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1622 ASSERT_EQ(sizeof(read_data), num_bytes); | 1638 ASSERT_EQ(sizeof(read_data), num_bytes); |
1623 ASSERT_EQ(data, read_data); | 1639 ASSERT_EQ(data, read_data); |
1624 | 1640 |
1625 ASSERT_EQ(MOJO_RESULT_OK, MojoClose(pipe0)); | 1641 ASSERT_EQ(MOJO_RESULT_OK, MojoClose(pipe0)); |
1626 ASSERT_EQ(MOJO_RESULT_OK, MojoClose(pipe1)); | 1642 ASSERT_EQ(MOJO_RESULT_OK, MojoClose(pipe1)); |
1627 } | 1643 } |
1628 | 1644 |
1629 } // namespace | 1645 } // namespace |
1630 } // namespace edk | 1646 } // namespace edk |
1631 } // namespace mojo | 1647 } // namespace mojo |
OLD | NEW |