| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 std::string write_buffer = read_buffer + read_buffer; | 108 std::string write_buffer = read_buffer + read_buffer; |
| 109 CHECK_EQ(MojoWriteMessage(h, write_buffer.data(), | 109 CHECK_EQ(MojoWriteMessage(h, write_buffer.data(), |
| 110 static_cast<uint32_t>(write_buffer.size()), | 110 static_cast<uint32_t>(write_buffer.size()), |
| 111 nullptr, 0u, MOJO_WRITE_MESSAGE_FLAG_NONE), | 111 nullptr, 0u, MOJO_WRITE_MESSAGE_FLAG_NONE), |
| 112 MOJO_RESULT_OK); | 112 MOJO_RESULT_OK); |
| 113 } | 113 } |
| 114 | 114 |
| 115 return rv; | 115 return rv; |
| 116 } | 116 } |
| 117 | 117 |
| 118 // Sends "hello" to child, and expects "hellohello" back. | 118 TEST_F(MultiprocessMessagePipeTest, Basic) { |
| 119 #if defined(OS_ANDROID) | |
| 120 // Android multi-process tests are not executing the new process. This is flaky. | |
| 121 #define MAYBE_Basic DISABLED_Basic | |
| 122 #else | |
| 123 #define MAYBE_Basic Basic | |
| 124 #endif // defined(OS_ANDROID) | |
| 125 TEST_F(MultiprocessMessagePipeTest, MAYBE_Basic) { | |
| 126 RUN_CHILD_ON_PIPE(EchoEcho, h) | 119 RUN_CHILD_ON_PIPE(EchoEcho, h) |
| 127 std::string hello("hello"); | 120 std::string hello("hello"); |
| 128 ASSERT_EQ(MOJO_RESULT_OK, | 121 ASSERT_EQ(MOJO_RESULT_OK, |
| 129 MojoWriteMessage(h, hello.data(), | 122 MojoWriteMessage(h, hello.data(), |
| 130 static_cast<uint32_t>(hello.size()), nullptr, 0u, | 123 static_cast<uint32_t>(hello.size()), nullptr, 0u, |
| 131 MOJO_WRITE_MESSAGE_FLAG_NONE)); | 124 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
| 132 | 125 |
| 133 HandleSignalsState hss; | 126 HandleSignalsState hss; |
| 134 ASSERT_EQ(MOJO_RESULT_OK, | 127 ASSERT_EQ(MOJO_RESULT_OK, |
| 135 MojoWait(h, MOJO_HANDLE_SIGNAL_READABLE, | 128 MojoWait(h, MOJO_HANDLE_SIGNAL_READABLE, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 151 ASSERT_EQ(hello + hello, read_buffer); | 144 ASSERT_EQ(hello + hello, read_buffer); |
| 152 | 145 |
| 153 std::string quitquitquit("quitquitquit"); | 146 std::string quitquitquit("quitquitquit"); |
| 154 CHECK_EQ(MojoWriteMessage(h, quitquitquit.data(), | 147 CHECK_EQ(MojoWriteMessage(h, quitquitquit.data(), |
| 155 static_cast<uint32_t>(quitquitquit.size()), | 148 static_cast<uint32_t>(quitquitquit.size()), |
| 156 nullptr, 0u, MOJO_WRITE_MESSAGE_FLAG_NONE), | 149 nullptr, 0u, MOJO_WRITE_MESSAGE_FLAG_NONE), |
| 157 MOJO_RESULT_OK); | 150 MOJO_RESULT_OK); |
| 158 END_CHILD_AND_EXPECT_EXIT_CODE(1 % 100); | 151 END_CHILD_AND_EXPECT_EXIT_CODE(1 % 100); |
| 159 } | 152 } |
| 160 | 153 |
| 161 // Sends a bunch of messages to the child. Expects them "repeated" back. Waits | 154 TEST_F(MultiprocessMessagePipeTest, QueueMessages) { |
| 162 // for the child to close its end before quitting. | |
| 163 #if defined(OS_ANDROID) | |
| 164 // Android multi-process tests are not executing the new process. This is flaky. | |
| 165 #define MAYBE_QueueMessages DISABLED_QueueMessages | |
| 166 #else | |
| 167 #define MAYBE_QueueMessages QueueMessages | |
| 168 #endif // defined(OS_ANDROID) | |
| 169 TEST_F(MultiprocessMessagePipeTest, MAYBE_QueueMessages) { | |
| 170 static const size_t kNumMessages = 1001; | 155 static const size_t kNumMessages = 1001; |
| 171 RUN_CHILD_ON_PIPE(EchoEcho, h) | 156 RUN_CHILD_ON_PIPE(EchoEcho, h) |
| 172 for (size_t i = 0; i < kNumMessages; i++) { | 157 for (size_t i = 0; i < kNumMessages; i++) { |
| 173 std::string write_buffer(i, 'A' + (i % 26)); | 158 std::string write_buffer(i, 'A' + (i % 26)); |
| 174 ASSERT_EQ(MOJO_RESULT_OK, | 159 ASSERT_EQ(MOJO_RESULT_OK, |
| 175 MojoWriteMessage(h, write_buffer.data(), | 160 MojoWriteMessage(h, write_buffer.data(), |
| 176 static_cast<uint32_t>(write_buffer.size()), | 161 static_cast<uint32_t>(write_buffer.size()), |
| 177 nullptr, 0u, MOJO_WRITE_MESSAGE_FLAG_NONE)); | 162 nullptr, 0u, MOJO_WRITE_MESSAGE_FLAG_NONE)); |
| 178 } | 163 } |
| 179 | 164 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 | 270 |
| 286 // It should have written something to the shared buffer. | 271 // It should have written something to the shared buffer. |
| 287 static const char kWorld[] = "world!!!"; | 272 static const char kWorld[] = "world!!!"; |
| 288 CHECK_EQ(memcmp(buffer, kWorld, sizeof(kWorld)), 0); | 273 CHECK_EQ(memcmp(buffer, kWorld, sizeof(kWorld)), 0); |
| 289 | 274 |
| 290 // And we're done. | 275 // And we're done. |
| 291 | 276 |
| 292 return 0; | 277 return 0; |
| 293 } | 278 } |
| 294 | 279 |
| 295 #if defined(OS_ANDROID) | 280 TEST_F(MultiprocessMessagePipeTest, SharedBufferPassing) { |
| 296 // Android multi-process tests are not executing the new process. This is flaky. | |
| 297 #define MAYBE_SharedBufferPassing DISABLED_SharedBufferPassing | |
| 298 #else | |
| 299 #define MAYBE_SharedBufferPassing SharedBufferPassing | |
| 300 #endif | |
| 301 TEST_F(MultiprocessMessagePipeTest, MAYBE_SharedBufferPassing) { | |
| 302 RUN_CHILD_ON_PIPE(CheckSharedBuffer, h) | 281 RUN_CHILD_ON_PIPE(CheckSharedBuffer, h) |
| 303 // Make a shared buffer. | 282 // Make a shared buffer. |
| 304 MojoCreateSharedBufferOptions options; | 283 MojoCreateSharedBufferOptions options; |
| 305 options.struct_size = sizeof(options); | 284 options.struct_size = sizeof(options); |
| 306 options.flags = MOJO_CREATE_SHARED_BUFFER_OPTIONS_FLAG_NONE; | 285 options.flags = MOJO_CREATE_SHARED_BUFFER_OPTIONS_FLAG_NONE; |
| 307 | 286 |
| 308 MojoHandle shared_buffer; | 287 MojoHandle shared_buffer; |
| 309 ASSERT_EQ(MOJO_RESULT_OK, | 288 ASSERT_EQ(MOJO_RESULT_OK, |
| 310 MojoCreateSharedBuffer(&options, 100, &shared_buffer)); | 289 MojoCreateSharedBuffer(&options, 100, &shared_buffer)); |
| 311 | 290 |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 // Now write some data into the message pipe. | 501 // Now write some data into the message pipe. |
| 523 std::string write_buffer = "world"; | 502 std::string write_buffer = "world"; |
| 524 CHECK_EQ(MojoWriteMessage(handles[0], write_buffer.data(), | 503 CHECK_EQ(MojoWriteMessage(handles[0], write_buffer.data(), |
| 525 static_cast<uint32_t>(write_buffer.size()), nullptr, | 504 static_cast<uint32_t>(write_buffer.size()), nullptr, |
| 526 0u, MOJO_WRITE_MESSAGE_FLAG_NONE), | 505 0u, MOJO_WRITE_MESSAGE_FLAG_NONE), |
| 527 MOJO_RESULT_OK); | 506 MOJO_RESULT_OK); |
| 528 MojoClose(handles[0]); | 507 MojoClose(handles[0]); |
| 529 return 0; | 508 return 0; |
| 530 } | 509 } |
| 531 | 510 |
| 532 #if defined(OS_ANDROID) | 511 TEST_F(MultiprocessMessagePipeTest, MessagePipePassing) { |
| 533 // Android multi-process tests are not executing the new process. This is flaky. | |
| 534 #define MAYBE_MessagePipePassing DISABLED_MessagePipePassing | |
| 535 #else | |
| 536 #define MAYBE_MessagePipePassing MessagePipePassing | |
| 537 #endif | |
| 538 TEST_F(MultiprocessMessagePipeTest, MAYBE_MessagePipePassing) { | |
| 539 RUN_CHILD_ON_PIPE(CheckMessagePipe, h) | 512 RUN_CHILD_ON_PIPE(CheckMessagePipe, h) |
| 540 MojoCreateSharedBufferOptions options; | 513 MojoCreateSharedBufferOptions options; |
| 541 options.struct_size = sizeof(options); | 514 options.struct_size = sizeof(options); |
| 542 options.flags = MOJO_CREATE_SHARED_BUFFER_OPTIONS_FLAG_NONE; | 515 options.flags = MOJO_CREATE_SHARED_BUFFER_OPTIONS_FLAG_NONE; |
| 543 | 516 |
| 544 MojoHandle mp1, mp2; | 517 MojoHandle mp1, mp2; |
| 545 ASSERT_EQ(MOJO_RESULT_OK, | 518 ASSERT_EQ(MOJO_RESULT_OK, |
| 546 MojoCreateMessagePipe(nullptr, &mp1, &mp2)); | 519 MojoCreateMessagePipe(nullptr, &mp1, &mp2)); |
| 547 | 520 |
| 548 // Write a string into one end of the new message pipe and send the other | 521 // Write a string into one end of the new message pipe and send the other |
| (...skipping 21 matching lines...) Expand all Loading... |
| 570 &read_buffer_size, nullptr, | 543 &read_buffer_size, nullptr, |
| 571 0, MOJO_READ_MESSAGE_FLAG_NONE), | 544 0, MOJO_READ_MESSAGE_FLAG_NONE), |
| 572 MOJO_RESULT_OK); | 545 MOJO_RESULT_OK); |
| 573 read_buffer.resize(read_buffer_size); | 546 read_buffer.resize(read_buffer_size); |
| 574 CHECK_EQ(read_buffer, std::string("world")); | 547 CHECK_EQ(read_buffer, std::string("world")); |
| 575 | 548 |
| 576 MojoClose(mp1); | 549 MojoClose(mp1); |
| 577 END_CHILD() | 550 END_CHILD() |
| 578 } | 551 } |
| 579 | 552 |
| 580 // Like above test, but verifies passing the other MP handle works as well. | 553 TEST_F(MultiprocessMessagePipeTest, MessagePipeTwoPassing) { |
| 581 #if defined(OS_ANDROID) | |
| 582 // Android multi-process tests are not executing the new process. This is flaky. | |
| 583 #define MAYBE_MessagePipeTwoPassing DISABLED_MessagePipeTwoPassing | |
| 584 #else | |
| 585 #define MAYBE_MessagePipeTwoPassing MessagePipeTwoPassing | |
| 586 #endif | |
| 587 TEST_F(MultiprocessMessagePipeTest, MAYBE_MessagePipeTwoPassing) { | |
| 588 RUN_CHILD_ON_PIPE(CheckMessagePipe, h) | 554 RUN_CHILD_ON_PIPE(CheckMessagePipe, h) |
| 589 MojoHandle mp1, mp2; | 555 MojoHandle mp1, mp2; |
| 590 ASSERT_EQ(MOJO_RESULT_OK, | 556 ASSERT_EQ(MOJO_RESULT_OK, |
| 591 MojoCreateMessagePipe(nullptr, &mp2, &mp1)); | 557 MojoCreateMessagePipe(nullptr, &mp2, &mp1)); |
| 592 | 558 |
| 593 // Write a string into one end of the new message pipe and send the other | 559 // Write a string into one end of the new message pipe and send the other |
| 594 // end. | 560 // end. |
| 595 const std::string hello("hello"); | 561 const std::string hello("hello"); |
| 596 ASSERT_EQ(MOJO_RESULT_OK, | 562 ASSERT_EQ(MOJO_RESULT_OK, |
| 597 MojoWriteMessage(mp1, &hello[0], | 563 MojoWriteMessage(mp1, &hello[0], |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 // Now write some data into the message pipe. | 631 // Now write some data into the message pipe. |
| 666 std::string write_buffer = "world"; | 632 std::string write_buffer = "world"; |
| 667 CHECK_EQ(MojoWriteMessage(handles[0], write_buffer.data(), | 633 CHECK_EQ(MojoWriteMessage(handles[0], write_buffer.data(), |
| 668 static_cast<uint32_t>(write_buffer.size()), | 634 static_cast<uint32_t>(write_buffer.size()), |
| 669 nullptr, 0u, MOJO_WRITE_MESSAGE_FLAG_NONE), | 635 nullptr, 0u, MOJO_WRITE_MESSAGE_FLAG_NONE), |
| 670 MOJO_RESULT_OK); | 636 MOJO_RESULT_OK); |
| 671 MojoClose(handles[0]); | 637 MojoClose(handles[0]); |
| 672 return 0; | 638 return 0; |
| 673 } | 639 } |
| 674 | 640 |
| 675 #if defined(OS_ANDROID) | 641 TEST_F(MultiprocessMessagePipeTest, DataPipeConsumer) { |
| 676 // Android multi-process tests are not executing the new process. This is flaky. | |
| 677 #define MAYBE_DataPipeConsumer DISABLED_DataPipeConsumer | |
| 678 #else | |
| 679 #define MAYBE_DataPipeConsumer DataPipeConsumer | |
| 680 #endif | |
| 681 TEST_F(MultiprocessMessagePipeTest, MAYBE_DataPipeConsumer) { | |
| 682 RUN_CHILD_ON_PIPE(DataPipeConsumer, h) | 642 RUN_CHILD_ON_PIPE(DataPipeConsumer, h) |
| 683 MojoCreateSharedBufferOptions options; | 643 MojoCreateSharedBufferOptions options; |
| 684 options.struct_size = sizeof(options); | 644 options.struct_size = sizeof(options); |
| 685 options.flags = MOJO_CREATE_SHARED_BUFFER_OPTIONS_FLAG_NONE; | 645 options.flags = MOJO_CREATE_SHARED_BUFFER_OPTIONS_FLAG_NONE; |
| 686 | 646 |
| 687 MojoHandle mp1, mp2; | 647 MojoHandle mp1, mp2; |
| 688 ASSERT_EQ(MOJO_RESULT_OK, | 648 ASSERT_EQ(MOJO_RESULT_OK, |
| 689 MojoCreateMessagePipe(nullptr, &mp2, &mp1)); | 649 MojoCreateMessagePipe(nullptr, &mp2, &mp1)); |
| 690 | 650 |
| 691 // Write a string into one end of the new message pipe and send the other | 651 // Write a string into one end of the new message pipe and send the other |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 765 h) { | 725 h) { |
| 766 for (;;) { | 726 for (;;) { |
| 767 std::string message = ReadMessage(h); | 727 std::string message = ReadMessage(h); |
| 768 if (message == "exit") | 728 if (message == "exit") |
| 769 break; | 729 break; |
| 770 WriteMessage(h, message); | 730 WriteMessage(h, message); |
| 771 } | 731 } |
| 772 return 0; | 732 return 0; |
| 773 } | 733 } |
| 774 | 734 |
| 775 #if defined(OS_ANDROID) | 735 TEST_F(MultiprocessMessagePipeTest, MultiprocessChannelPipe) { |
| 776 // Android multi-process tests are not executing the new process. This is flaky. | |
| 777 #define MAYBE_MultiprocessChannelPipe DISABLED_MultiprocessChannelPipe | |
| 778 #else | |
| 779 #define MAYBE_MultiprocessChannelPipe MultiprocessChannelPipe | |
| 780 #endif | |
| 781 TEST_F(MultiprocessMessagePipeTest, MAYBE_MultiprocessChannelPipe) { | |
| 782 RUN_CHILD_ON_PIPE(ChannelEchoClient, h) | 736 RUN_CHILD_ON_PIPE(ChannelEchoClient, h) |
| 783 VerifyEcho(h, "in an interstellar burst"); | 737 VerifyEcho(h, "in an interstellar burst"); |
| 784 VerifyEcho(h, "i am back to save the universe"); | 738 VerifyEcho(h, "i am back to save the universe"); |
| 785 VerifyEcho(h, std::string(10 * 1024 * 1024, 'o')); | 739 VerifyEcho(h, std::string(10 * 1024 * 1024, 'o')); |
| 786 | 740 |
| 787 WriteMessage(h, "exit"); | 741 WriteMessage(h, "exit"); |
| 788 END_CHILD() | 742 END_CHILD() |
| 789 } | 743 } |
| 790 | 744 |
| 791 // Receives a pipe handle from the primordial channel and echos on it until | 745 // Receives a pipe handle from the primordial channel and echos on it until |
| 792 // "exit". Used to test simple pipe transfer across processes via channels. | 746 // "exit". Used to test simple pipe transfer across processes via channels. |
| 793 DEFINE_TEST_CLIENT_WITH_PIPE(EchoServiceClient, MultiprocessMessagePipeTest, | 747 DEFINE_TEST_CLIENT_WITH_PIPE(EchoServiceClient, MultiprocessMessagePipeTest, |
| 794 h) { | 748 h) { |
| 795 MojoHandle p; | 749 MojoHandle p; |
| 796 ReadMessageWithHandles(h, &p, 1); | 750 ReadMessageWithHandles(h, &p, 1); |
| 797 for (;;) { | 751 for (;;) { |
| 798 std::string message = ReadMessage(p); | 752 std::string message = ReadMessage(p); |
| 799 if (message == "exit") | 753 if (message == "exit") |
| 800 break; | 754 break; |
| 801 WriteMessage(p, message); | 755 WriteMessage(p, message); |
| 802 } | 756 } |
| 803 return 0; | 757 return 0; |
| 804 } | 758 } |
| 805 | 759 |
| 806 #if defined(OS_ANDROID) | 760 TEST_F(MultiprocessMessagePipeTest, PassMessagePipeCrossProcess) { |
| 807 // Android multi-process tests are not executing the new process. This is flaky. | |
| 808 #define MAYBE_PassMessagePipeCrossProcess DISABLED_PassMessagePipeCrossProcess | |
| 809 #else | |
| 810 #define MAYBE_PassMessagePipeCrossProcess PassMessagePipeCrossProcess | |
| 811 #endif | |
| 812 TEST_F(MultiprocessMessagePipeTest, MAYBE_PassMessagePipeCrossProcess) { | |
| 813 MojoHandle p0, p1; | 761 MojoHandle p0, p1; |
| 814 CreateMessagePipe(&p0, &p1); | 762 CreateMessagePipe(&p0, &p1); |
| 815 RUN_CHILD_ON_PIPE(EchoServiceClient, h) | 763 RUN_CHILD_ON_PIPE(EchoServiceClient, h) |
| 816 | 764 |
| 817 // Pass one end of the pipe to the other process. | 765 // Pass one end of the pipe to the other process. |
| 818 WriteMessageWithHandles(h, "here take this", &p1, 1); | 766 WriteMessageWithHandles(h, "here take this", &p1, 1); |
| 819 | 767 |
| 820 VerifyEcho(p0, "and you may ask yourself"); | 768 VerifyEcho(p0, "and you may ask yourself"); |
| 821 VerifyEcho(p0, "where does that highway go?"); | 769 VerifyEcho(p0, "where does that highway go?"); |
| 822 VerifyEcho(p0, std::string(20 * 1024 * 1024, 'i')); | 770 VerifyEcho(p0, std::string(20 * 1024 * 1024, 'i')); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 859 WriteMessage(handles[index], ReadMessage(handles[index])); | 807 WriteMessage(handles[index], ReadMessage(handles[index])); |
| 860 } | 808 } |
| 861 } | 809 } |
| 862 | 810 |
| 863 for (size_t i = 1; i < handles.size(); ++i) | 811 for (size_t i = 1; i < handles.size(); ++i) |
| 864 CloseHandle(handles[i]); | 812 CloseHandle(handles[i]); |
| 865 | 813 |
| 866 return 0; | 814 return 0; |
| 867 } | 815 } |
| 868 | 816 |
| 869 #if defined(OS_ANDROID) | 817 TEST_F(MultiprocessMessagePipeTest, PassMoarMessagePipesCrossProcess) { |
| 870 // Android multi-process tests are not executing the new process. This is flaky. | |
| 871 #define MAYBE_PassMoarMessagePipesCrossProcess \ | |
| 872 DISABLED_PassMoarMessagePipesCrossProcess | |
| 873 #else | |
| 874 #define MAYBE_PassMoarMessagePipesCrossProcess PassMoarMessagePipesCrossProcess | |
| 875 #endif | |
| 876 TEST_F(MultiprocessMessagePipeTest, MAYBE_PassMoarMessagePipesCrossProcess) { | |
| 877 MojoHandle echo_factory_proxy, echo_factory_request; | 818 MojoHandle echo_factory_proxy, echo_factory_request; |
| 878 CreateMessagePipe(&echo_factory_proxy, &echo_factory_request); | 819 CreateMessagePipe(&echo_factory_proxy, &echo_factory_request); |
| 879 | 820 |
| 880 MojoHandle echo_proxy_a, echo_request_a; | 821 MojoHandle echo_proxy_a, echo_request_a; |
| 881 CreateMessagePipe(&echo_proxy_a, &echo_request_a); | 822 CreateMessagePipe(&echo_proxy_a, &echo_request_a); |
| 882 | 823 |
| 883 MojoHandle echo_proxy_b, echo_request_b; | 824 MojoHandle echo_proxy_b, echo_request_b; |
| 884 CreateMessagePipe(&echo_proxy_b, &echo_request_b); | 825 CreateMessagePipe(&echo_proxy_b, &echo_request_b); |
| 885 | 826 |
| 886 MojoHandle echo_proxy_c, echo_request_c; | 827 MojoHandle echo_proxy_c, echo_request_c; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 911 | 852 |
| 912 WriteMessage(h, "exit"); | 853 WriteMessage(h, "exit"); |
| 913 END_CHILD() | 854 END_CHILD() |
| 914 | 855 |
| 915 CloseHandle(echo_factory_proxy); | 856 CloseHandle(echo_factory_proxy); |
| 916 CloseHandle(echo_proxy_a); | 857 CloseHandle(echo_proxy_a); |
| 917 CloseHandle(echo_proxy_b); | 858 CloseHandle(echo_proxy_b); |
| 918 CloseHandle(echo_proxy_c); | 859 CloseHandle(echo_proxy_c); |
| 919 } | 860 } |
| 920 | 861 |
| 921 #if defined(OS_ANDROID) | 862 TEST_F(MultiprocessMessagePipeTest, ChannelPipesWithMultipleChildren) { |
| 922 // Android multi-process tests are not executing the new process. This is flaky. | |
| 923 #define MAYBE_ChannelPipesWithMultipleChildren \ | |
| 924 DISABLED_ChannelPipesWithMultipleChildren | |
| 925 #else | |
| 926 #define MAYBE_ChannelPipesWithMultipleChildren ChannelPipesWithMultipleChildren | |
| 927 #endif | |
| 928 TEST_F(MultiprocessMessagePipeTest, MAYBE_ChannelPipesWithMultipleChildren) { | |
| 929 RUN_CHILD_ON_PIPE(ChannelEchoClient, a) | 863 RUN_CHILD_ON_PIPE(ChannelEchoClient, a) |
| 930 RUN_CHILD_ON_PIPE(ChannelEchoClient, b) | 864 RUN_CHILD_ON_PIPE(ChannelEchoClient, b) |
| 931 VerifyEcho(a, "hello child 0"); | 865 VerifyEcho(a, "hello child 0"); |
| 932 VerifyEcho(b, "hello child 1"); | 866 VerifyEcho(b, "hello child 1"); |
| 933 | 867 |
| 934 WriteMessage(a, "exit"); | 868 WriteMessage(a, "exit"); |
| 935 WriteMessage(b, "exit"); | 869 WriteMessage(b, "exit"); |
| 936 END_CHILD() | 870 END_CHILD() |
| 937 END_CHILD() | 871 END_CHILD() |
| 938 } | 872 } |
| 939 | 873 |
| 940 // Reads and turns a pipe handle some number of times to create lots of | 874 // Reads and turns a pipe handle some number of times to create lots of |
| 941 // transient proxies. | 875 // transient proxies. |
| 942 DEFINE_TEST_CLIENT_TEST_WITH_PIPE(PingPongPipeClient, | 876 DEFINE_TEST_CLIENT_TEST_WITH_PIPE(PingPongPipeClient, |
| 943 MultiprocessMessagePipeTest, h) { | 877 MultiprocessMessagePipeTest, h) { |
| 944 const size_t kNumBounces = 50; | 878 const size_t kNumBounces = 50; |
| 945 MojoHandle p0, p1; | 879 MojoHandle p0, p1; |
| 946 ReadMessageWithHandles(h, &p0, 1); | 880 ReadMessageWithHandles(h, &p0, 1); |
| 947 ReadMessageWithHandles(h, &p1, 1); | 881 ReadMessageWithHandles(h, &p1, 1); |
| 948 for (size_t i = 0; i < kNumBounces; ++i) { | 882 for (size_t i = 0; i < kNumBounces; ++i) { |
| 949 WriteMessageWithHandles(h, "", &p1, 1); | 883 WriteMessageWithHandles(h, "", &p1, 1); |
| 950 ReadMessageWithHandles(h, &p1, 1); | 884 ReadMessageWithHandles(h, &p1, 1); |
| 951 } | 885 } |
| 952 WriteMessageWithHandles(h, "", &p0, 1); | 886 WriteMessageWithHandles(h, "", &p0, 1); |
| 953 WriteMessage(p1, "bye"); | 887 WriteMessage(p1, "bye"); |
| 954 MojoClose(p1); | 888 MojoClose(p1); |
| 955 EXPECT_EQ("quit", ReadMessage(h)); | 889 EXPECT_EQ("quit", ReadMessage(h)); |
| 956 } | 890 } |
| 957 | 891 |
| 958 #if defined(OS_ANDROID) | 892 TEST_F(MultiprocessMessagePipeTest, PingPongPipe) { |
| 959 // Android multi-process tests are not executing the new process. This is flaky. | |
| 960 #define MAYBE_PingPongPipe DISABLED_PingPongPipe | |
| 961 #else | |
| 962 #define MAYBE_PingPongPipe PingPongPipe | |
| 963 #endif | |
| 964 TEST_F(MultiprocessMessagePipeTest, MAYBE_PingPongPipe) { | |
| 965 MojoHandle p0, p1; | 893 MojoHandle p0, p1; |
| 966 CreateMessagePipe(&p0, &p1); | 894 CreateMessagePipe(&p0, &p1); |
| 967 | 895 |
| 968 RUN_CHILD_ON_PIPE(PingPongPipeClient, h) | 896 RUN_CHILD_ON_PIPE(PingPongPipeClient, h) |
| 969 const size_t kNumBounces = 50; | 897 const size_t kNumBounces = 50; |
| 970 WriteMessageWithHandles(h, "", &p0, 1); | 898 WriteMessageWithHandles(h, "", &p0, 1); |
| 971 WriteMessageWithHandles(h, "", &p1, 1); | 899 WriteMessageWithHandles(h, "", &p1, 1); |
| 972 for (size_t i = 0; i < kNumBounces; ++i) { | 900 for (size_t i = 0; i < kNumBounces; ++i) { |
| 973 ReadMessageWithHandles(h, &p1, 1); | 901 ReadMessageWithHandles(h, &p1, 1); |
| 974 WriteMessageWithHandles(h, "", &p1, 1); | 902 WriteMessageWithHandles(h, "", &p1, 1); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1053 break; | 981 break; |
| 1054 } | 982 } |
| 1055 } | 983 } |
| 1056 | 984 |
| 1057 for (auto& pipe: named_pipes) | 985 for (auto& pipe: named_pipes) |
| 1058 CloseHandle(pipe.second); | 986 CloseHandle(pipe.second); |
| 1059 | 987 |
| 1060 return 0; | 988 return 0; |
| 1061 } | 989 } |
| 1062 | 990 |
| 1063 #if defined(OS_ANDROID) | 991 TEST_F(MultiprocessMessagePipeTest, ChildToChildPipes) { |
| 1064 // Android multi-process tests are not executing the new process. This is flaky. | |
| 1065 #define MAYBE_ChildToChildPipes DISABLED_ChildToChildPipes | |
| 1066 #else | |
| 1067 #define MAYBE_ChildToChildPipes ChildToChildPipes | |
| 1068 #endif | |
| 1069 TEST_F(MultiprocessMessagePipeTest, MAYBE_ChildToChildPipes) { | |
| 1070 RUN_CHILD_ON_PIPE(CommandDrivenClient, h0) | 992 RUN_CHILD_ON_PIPE(CommandDrivenClient, h0) |
| 1071 RUN_CHILD_ON_PIPE(CommandDrivenClient, h1) | 993 RUN_CHILD_ON_PIPE(CommandDrivenClient, h1) |
| 1072 CommandDrivenClientController a(h0); | 994 CommandDrivenClientController a(h0); |
| 1073 CommandDrivenClientController b(h1); | 995 CommandDrivenClientController b(h1); |
| 1074 | 996 |
| 1075 // Create a pipe and pass each end to a different client. | 997 // Create a pipe and pass each end to a different client. |
| 1076 MojoHandle p0, p1; | 998 MojoHandle p0, p1; |
| 1077 CreateMessagePipe(&p0, &p1); | 999 CreateMessagePipe(&p0, &p1); |
| 1078 a.SendHandle("x", p0); | 1000 a.SendHandle("x", p0); |
| 1079 b.SendHandle("y", p1); | 1001 b.SendHandle("y", p1); |
| 1080 | 1002 |
| 1081 // Make sure they can talk. | 1003 // Make sure they can talk. |
| 1082 a.Send("say:x:hello sir"); | 1004 a.Send("say:x:hello sir"); |
| 1083 b.Send("hear:y:hello sir"); | 1005 b.Send("hear:y:hello sir"); |
| 1084 | 1006 |
| 1085 b.Send("say:y:i love multiprocess pipes!"); | 1007 b.Send("say:y:i love multiprocess pipes!"); |
| 1086 a.Send("hear:x:i love multiprocess pipes!"); | 1008 a.Send("hear:x:i love multiprocess pipes!"); |
| 1087 | 1009 |
| 1088 a.Exit(); | 1010 a.Exit(); |
| 1089 b.Exit(); | 1011 b.Exit(); |
| 1090 END_CHILD() | 1012 END_CHILD() |
| 1091 END_CHILD() | 1013 END_CHILD() |
| 1092 } | 1014 } |
| 1093 | 1015 |
| 1094 #if defined(OS_ANDROID) | 1016 TEST_F(MultiprocessMessagePipeTest, MoreChildToChildPipes) { |
| 1095 // Android multi-process tests are not executing the new process. This is flaky. | |
| 1096 #define MAYBE_MoreChildToChildPipes DISABLED_MoreChildToChildPipes | |
| 1097 #else | |
| 1098 #define MAYBE_MoreChildToChildPipes MoreChildToChildPipes | |
| 1099 #endif | |
| 1100 TEST_F(MultiprocessMessagePipeTest, MAYBE_MoreChildToChildPipes) { | |
| 1101 RUN_CHILD_ON_PIPE(CommandDrivenClient, h0) | 1017 RUN_CHILD_ON_PIPE(CommandDrivenClient, h0) |
| 1102 RUN_CHILD_ON_PIPE(CommandDrivenClient, h1) | 1018 RUN_CHILD_ON_PIPE(CommandDrivenClient, h1) |
| 1103 RUN_CHILD_ON_PIPE(CommandDrivenClient, h2) | 1019 RUN_CHILD_ON_PIPE(CommandDrivenClient, h2) |
| 1104 RUN_CHILD_ON_PIPE(CommandDrivenClient, h3) | 1020 RUN_CHILD_ON_PIPE(CommandDrivenClient, h3) |
| 1105 CommandDrivenClientController a(h0), b(h1), c(h2), d(h3); | 1021 CommandDrivenClientController a(h0), b(h1), c(h2), d(h3); |
| 1106 | 1022 |
| 1107 // Connect a to b and c to d | 1023 // Connect a to b and c to d |
| 1108 | 1024 |
| 1109 MojoHandle p0, p1; | 1025 MojoHandle p0, p1; |
| 1110 | 1026 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1176 | 1092 |
| 1177 DEFINE_TEST_CLIENT_TEST_WITH_PIPE(ReceivePipeWithClosedPeer, | 1093 DEFINE_TEST_CLIENT_TEST_WITH_PIPE(ReceivePipeWithClosedPeer, |
| 1178 MultiprocessMessagePipeTest, h) { | 1094 MultiprocessMessagePipeTest, h) { |
| 1179 MojoHandle p; | 1095 MojoHandle p; |
| 1180 EXPECT_EQ("foo", ReadMessageWithHandles(h, &p, 1)); | 1096 EXPECT_EQ("foo", ReadMessageWithHandles(h, &p, 1)); |
| 1181 | 1097 |
| 1182 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(p, MOJO_HANDLE_SIGNAL_PEER_CLOSED, | 1098 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(p, MOJO_HANDLE_SIGNAL_PEER_CLOSED, |
| 1183 MOJO_DEADLINE_INDEFINITE, nullptr)); | 1099 MOJO_DEADLINE_INDEFINITE, nullptr)); |
| 1184 } | 1100 } |
| 1185 | 1101 |
| 1186 #if defined(OS_ANDROID) | 1102 TEST_F(MultiprocessMessagePipeTest, SendPipeThenClosePeer) { |
| 1187 // Android multi-process tests are not executing the new process. This is flaky. | |
| 1188 #define MAYBE_SendPipeThenClosePeer DISABLED_SendPipeThenClosePeer | |
| 1189 #else | |
| 1190 #define MAYBE_SendPipeThenClosePeer SendPipeThenClosePeer | |
| 1191 #endif | |
| 1192 TEST_F(MultiprocessMessagePipeTest, MAYBE_SendPipeThenClosePeer) { | |
| 1193 RUN_CHILD_ON_PIPE(ReceivePipeWithClosedPeer, h) | 1103 RUN_CHILD_ON_PIPE(ReceivePipeWithClosedPeer, h) |
| 1194 MojoHandle a, b; | 1104 MojoHandle a, b; |
| 1195 CreateMessagePipe(&a, &b); | 1105 CreateMessagePipe(&a, &b); |
| 1196 | 1106 |
| 1197 // Send |a| and immediately close |b|. The child should observe closure. | 1107 // Send |a| and immediately close |b|. The child should observe closure. |
| 1198 WriteMessageWithHandles(h, "foo", &a, 1); | 1108 WriteMessageWithHandles(h, "foo", &a, 1); |
| 1199 MojoClose(b); | 1109 MojoClose(b); |
| 1200 END_CHILD() | 1110 END_CHILD() |
| 1201 } | 1111 } |
| 1202 | 1112 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1259 ReadMessageWithHandles(kid_a, &application_request, 1)); | 1169 ReadMessageWithHandles(kid_a, &application_request, 1)); |
| 1260 | 1170 |
| 1261 WriteMessageWithHandles(kid_b, "c2a", &application_request, 1); | 1171 WriteMessageWithHandles(kid_b, "c2a", &application_request, 1); |
| 1262 END_CHILD() | 1172 END_CHILD() |
| 1263 | 1173 |
| 1264 WriteMessage(kid_a, "quit"); | 1174 WriteMessage(kid_a, "quit"); |
| 1265 END_CHILD() | 1175 END_CHILD() |
| 1266 } | 1176 } |
| 1267 | 1177 |
| 1268 | 1178 |
| 1269 #if defined(OS_ANDROID) | 1179 TEST_F(MultiprocessMessagePipeTest, SendClosePeerSend) { |
| 1270 // Android multi-process tests are not executing the new process. This is flaky. | |
| 1271 #define MAYBE_SendClosePeerSend DISABLED_SendClosePeerSend | |
| 1272 #else | |
| 1273 #define MAYBE_SendClosePeerSend SendClosePeerSend | |
| 1274 #endif | |
| 1275 TEST_F(MultiprocessMessagePipeTest, MAYBE_SendClosePeerSend) { | |
| 1276 MojoHandle a, b; | 1180 MojoHandle a, b; |
| 1277 CreateMessagePipe(&a, &b); | 1181 CreateMessagePipe(&a, &b); |
| 1278 | 1182 |
| 1279 MojoHandle c, d; | 1183 MojoHandle c, d; |
| 1280 CreateMessagePipe(&c, &d); | 1184 CreateMessagePipe(&c, &d); |
| 1281 | 1185 |
| 1282 // Send |a| over |c|, immediately close |b|, then send |a| back over |d|. | 1186 // Send |a| over |c|, immediately close |b|, then send |a| back over |d|. |
| 1283 WriteMessageWithHandles(c, "foo", &a, 1); | 1187 WriteMessageWithHandles(c, "foo", &a, 1); |
| 1284 EXPECT_EQ("foo", ReadMessageWithHandles(d, &a, 1)); | 1188 EXPECT_EQ("foo", ReadMessageWithHandles(d, &a, 1)); |
| 1285 WriteMessageWithHandles(d, "bar", &a, 1); | 1189 WriteMessageWithHandles(d, "bar", &a, 1); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1308 // the parent, just for some extra proxying goodness. | 1212 // the parent, just for some extra proxying goodness. |
| 1309 WriteMessageWithHandles(c, "foo", &pipe[1], 1); | 1213 WriteMessageWithHandles(c, "foo", &pipe[1], 1); |
| 1310 EXPECT_EQ("foo", ReadMessageWithHandles(d, &pipe[1], 1)); | 1214 EXPECT_EQ("foo", ReadMessageWithHandles(d, &pipe[1], 1)); |
| 1311 | 1215 |
| 1312 // And finally pass it back to the parent. | 1216 // And finally pass it back to the parent. |
| 1313 WriteMessageWithHandles(h, "bar", &pipe[1], 1); | 1217 WriteMessageWithHandles(h, "bar", &pipe[1], 1); |
| 1314 | 1218 |
| 1315 EXPECT_EQ("quit", ReadMessage(h)); | 1219 EXPECT_EQ("quit", ReadMessage(h)); |
| 1316 } | 1220 } |
| 1317 | 1221 |
| 1318 #if defined(OS_ANDROID) | 1222 TEST_F(MultiprocessMessagePipeTest, WriteCloseSendPeer) { |
| 1319 // Android multi-process tests are not executing the new process. This is flaky. | |
| 1320 #define MAYBE_WriteCloseSendPeer DISABLED_WriteCloseSendPeer | |
| 1321 #else | |
| 1322 #define MAYBE_WriteCloseSendPeer WriteCloseSendPeer | |
| 1323 #endif | |
| 1324 TEST_F(MultiprocessMessagePipeTest, MAYBE_WriteCloseSendPeer) { | |
| 1325 MojoHandle pipe[2]; | 1223 MojoHandle pipe[2]; |
| 1326 CreateMessagePipe(&pipe[0], &pipe[1]); | 1224 CreateMessagePipe(&pipe[0], &pipe[1]); |
| 1327 | 1225 |
| 1328 RUN_CHILD_ON_PIPE(WriteCloseSendPeerClient, h) | 1226 RUN_CHILD_ON_PIPE(WriteCloseSendPeerClient, h) |
| 1329 // Pass the pipe to the child. | 1227 // Pass the pipe to the child. |
| 1330 WriteMessageWithHandles(h, "foo", pipe, 2); | 1228 WriteMessageWithHandles(h, "foo", pipe, 2); |
| 1331 | 1229 |
| 1332 // Read back an endpoint which should have messages on it. | 1230 // Read back an endpoint which should have messages on it. |
| 1333 MojoHandle p; | 1231 MojoHandle p; |
| 1334 EXPECT_EQ("bar", ReadMessageWithHandles(h, &p, 1)); | 1232 EXPECT_EQ("bar", ReadMessageWithHandles(h, &p, 1)); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1354 edk::PassWrappedPlatformHandle(channel_handle, &channel)); | 1252 edk::PassWrappedPlatformHandle(channel_handle, &channel)); |
| 1355 ASSERT_TRUE(channel.is_valid()); | 1253 ASSERT_TRUE(channel.is_valid()); |
| 1356 | 1254 |
| 1357 // Create a new pipe using our end of the channel. | 1255 // Create a new pipe using our end of the channel. |
| 1358 ScopedMessagePipeHandle pipe = edk::CreateMessagePipe(std::move(channel)); | 1256 ScopedMessagePipeHandle pipe = edk::CreateMessagePipe(std::move(channel)); |
| 1359 | 1257 |
| 1360 // Ensure that we can read and write on the new pipe. | 1258 // Ensure that we can read and write on the new pipe. |
| 1361 VerifyEcho(pipe.get().value(), "goodbye"); | 1259 VerifyEcho(pipe.get().value(), "goodbye"); |
| 1362 } | 1260 } |
| 1363 | 1261 |
| 1364 #if defined(OS_ANDROID) | 1262 TEST_F(MultiprocessMessagePipeTest, BootstrapMessagePipeAsync) { |
| 1365 // Android multi-process tests are not executing the new process. This is flaky. | |
| 1366 #define MAYBE_BootstrapMessagePipeAsync DISABLED_BootstrapMessagePipeAsync | |
| 1367 #else | |
| 1368 #define MAYBE_BootstrapMessagePipeAsync BootstrapMessagePipeAsync | |
| 1369 #endif | |
| 1370 TEST_F(MultiprocessMessagePipeTest, MAYBE_BootstrapMessagePipeAsync) { | |
| 1371 // Tests that new cross-process message pipes can be created synchronously | 1263 // Tests that new cross-process message pipes can be created synchronously |
| 1372 // using asynchronous negotiation over an arbitrary platform channel. | 1264 // using asynchronous negotiation over an arbitrary platform channel. |
| 1373 RUN_CHILD_ON_PIPE(BootstrapMessagePipeAsyncClient, child) | 1265 RUN_CHILD_ON_PIPE(BootstrapMessagePipeAsyncClient, child) |
| 1374 // Pass one end of a platform channel to the child. | 1266 // Pass one end of a platform channel to the child. |
| 1375 PlatformChannelPair platform_channel; | 1267 PlatformChannelPair platform_channel; |
| 1376 MojoHandle client_channel_handle; | 1268 MojoHandle client_channel_handle; |
| 1377 EXPECT_EQ(MOJO_RESULT_OK, | 1269 EXPECT_EQ(MOJO_RESULT_OK, |
| 1378 CreatePlatformHandleWrapper(platform_channel.PassClientHandle(), | 1270 CreatePlatformHandleWrapper(platform_channel.PassClientHandle(), |
| 1379 &client_channel_handle)); | 1271 &client_channel_handle)); |
| 1380 WriteMessageWithHandles(child, "hi", &client_channel_handle, 1); | 1272 WriteMessageWithHandles(child, "hi", &client_channel_handle, 1); |
| 1381 | 1273 |
| 1382 // Create a new pipe using our end of the channel. | 1274 // Create a new pipe using our end of the channel. |
| 1383 ScopedMessagePipeHandle pipe = | 1275 ScopedMessagePipeHandle pipe = |
| 1384 edk::CreateMessagePipe(platform_channel.PassServerHandle()); | 1276 edk::CreateMessagePipe(platform_channel.PassServerHandle()); |
| 1385 | 1277 |
| 1386 // Ensure that we can read and write on the new pipe. | 1278 // Ensure that we can read and write on the new pipe. |
| 1387 VerifyEcho(pipe.get().value(), "goodbye"); | 1279 VerifyEcho(pipe.get().value(), "goodbye"); |
| 1388 END_CHILD() | 1280 END_CHILD() |
| 1389 } | 1281 } |
| 1390 | 1282 |
| 1391 } // namespace | 1283 } // namespace |
| 1392 } // namespace edk | 1284 } // namespace edk |
| 1393 } // namespace mojo | 1285 } // namespace mojo |
| OLD | NEW |