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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 return p; | 61 return p; |
62 } | 62 } |
63 | 63 |
64 void Exit() { WriteMessage(h_, "exit"); } | 64 void Exit() { WriteMessage(h_, "exit"); } |
65 | 65 |
66 private: | 66 private: |
67 MojoHandle h_; | 67 MojoHandle h_; |
68 }; | 68 }; |
69 }; | 69 }; |
70 | 70 |
| 71 class MultiprocessMessagePipeTestWithPeerSupport |
| 72 : public MultiprocessMessagePipeTest, |
| 73 public testing::WithParamInterface<test::MojoTestBase::LaunchType> { |
| 74 protected: |
| 75 void SetUp() override { |
| 76 test::MojoTestBase::SetUp(); |
| 77 set_launch_type(GetParam()); |
| 78 } |
| 79 }; |
| 80 |
71 // For each message received, sends a reply message with the same contents | 81 // For each message received, sends a reply message with the same contents |
72 // repeated twice, until the other end is closed or it receives "quitquitquit" | 82 // repeated twice, until the other end is closed or it receives "quitquitquit" |
73 // (which it doesn't reply to). It'll return the number of messages received, | 83 // (which it doesn't reply to). It'll return the number of messages received, |
74 // not including any "quitquitquit" message, modulo 100. | 84 // not including any "quitquitquit" message, modulo 100. |
75 DEFINE_TEST_CLIENT_WITH_PIPE(EchoEcho, MultiprocessMessagePipeTest, h) { | 85 DEFINE_TEST_CLIENT_WITH_PIPE(EchoEcho, MultiprocessMessagePipeTest, h) { |
76 const std::string quitquitquit("quitquitquit"); | 86 const std::string quitquitquit("quitquitquit"); |
77 int rv = 0; | 87 int rv = 0; |
78 for (;; rv = (rv + 1) % 100) { | 88 for (;; rv = (rv + 1) % 100) { |
79 // Wait for our end of the message pipe to be readable. | 89 // Wait for our end of the message pipe to be readable. |
80 HandleSignalsState hss; | 90 HandleSignalsState hss; |
(...skipping 28 matching lines...) Expand all Loading... |
109 std::string write_buffer = read_buffer + read_buffer; | 119 std::string write_buffer = read_buffer + read_buffer; |
110 CHECK_EQ(MojoWriteMessage(h, write_buffer.data(), | 120 CHECK_EQ(MojoWriteMessage(h, write_buffer.data(), |
111 static_cast<uint32_t>(write_buffer.size()), | 121 static_cast<uint32_t>(write_buffer.size()), |
112 nullptr, 0u, MOJO_WRITE_MESSAGE_FLAG_NONE), | 122 nullptr, 0u, MOJO_WRITE_MESSAGE_FLAG_NONE), |
113 MOJO_RESULT_OK); | 123 MOJO_RESULT_OK); |
114 } | 124 } |
115 | 125 |
116 return rv; | 126 return rv; |
117 } | 127 } |
118 | 128 |
119 TEST_F(MultiprocessMessagePipeTest, Basic) { | 129 TEST_P(MultiprocessMessagePipeTestWithPeerSupport, Basic) { |
120 RUN_CHILD_ON_PIPE(EchoEcho, h) | 130 RUN_CHILD_ON_PIPE(EchoEcho, h) |
121 std::string hello("hello"); | 131 std::string hello("hello"); |
122 ASSERT_EQ(MOJO_RESULT_OK, | 132 ASSERT_EQ(MOJO_RESULT_OK, |
123 MojoWriteMessage(h, hello.data(), | 133 MojoWriteMessage(h, hello.data(), |
124 static_cast<uint32_t>(hello.size()), nullptr, 0u, | 134 static_cast<uint32_t>(hello.size()), nullptr, 0u, |
125 MOJO_WRITE_MESSAGE_FLAG_NONE)); | 135 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
126 | 136 |
127 HandleSignalsState hss; | 137 HandleSignalsState hss; |
128 ASSERT_EQ(MOJO_RESULT_OK, | 138 ASSERT_EQ(MOJO_RESULT_OK, |
129 MojoWait(h, MOJO_HANDLE_SIGNAL_READABLE, | 139 MojoWait(h, MOJO_HANDLE_SIGNAL_READABLE, |
(...skipping 15 matching lines...) Expand all Loading... |
145 ASSERT_EQ(hello + hello, read_buffer); | 155 ASSERT_EQ(hello + hello, read_buffer); |
146 | 156 |
147 std::string quitquitquit("quitquitquit"); | 157 std::string quitquitquit("quitquitquit"); |
148 CHECK_EQ(MojoWriteMessage(h, quitquitquit.data(), | 158 CHECK_EQ(MojoWriteMessage(h, quitquitquit.data(), |
149 static_cast<uint32_t>(quitquitquit.size()), | 159 static_cast<uint32_t>(quitquitquit.size()), |
150 nullptr, 0u, MOJO_WRITE_MESSAGE_FLAG_NONE), | 160 nullptr, 0u, MOJO_WRITE_MESSAGE_FLAG_NONE), |
151 MOJO_RESULT_OK); | 161 MOJO_RESULT_OK); |
152 END_CHILD_AND_EXPECT_EXIT_CODE(1 % 100); | 162 END_CHILD_AND_EXPECT_EXIT_CODE(1 % 100); |
153 } | 163 } |
154 | 164 |
155 TEST_F(MultiprocessMessagePipeTest, QueueMessages) { | 165 TEST_P(MultiprocessMessagePipeTestWithPeerSupport, QueueMessages) { |
156 static const size_t kNumMessages = 1001; | 166 static const size_t kNumMessages = 1001; |
157 RUN_CHILD_ON_PIPE(EchoEcho, h) | 167 RUN_CHILD_ON_PIPE(EchoEcho, h) |
158 for (size_t i = 0; i < kNumMessages; i++) { | 168 for (size_t i = 0; i < kNumMessages; i++) { |
159 std::string write_buffer(i, 'A' + (i % 26)); | 169 std::string write_buffer(i, 'A' + (i % 26)); |
160 ASSERT_EQ(MOJO_RESULT_OK, | 170 ASSERT_EQ(MOJO_RESULT_OK, |
161 MojoWriteMessage(h, write_buffer.data(), | 171 MojoWriteMessage(h, write_buffer.data(), |
162 static_cast<uint32_t>(write_buffer.size()), | 172 static_cast<uint32_t>(write_buffer.size()), |
163 nullptr, 0u, MOJO_WRITE_MESSAGE_FLAG_NONE)); | 173 nullptr, 0u, MOJO_WRITE_MESSAGE_FLAG_NONE)); |
164 } | 174 } |
165 | 175 |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 // Now write some data into the message pipe. | 512 // Now write some data into the message pipe. |
503 std::string write_buffer = "world"; | 513 std::string write_buffer = "world"; |
504 CHECK_EQ(MojoWriteMessage(handles[0], write_buffer.data(), | 514 CHECK_EQ(MojoWriteMessage(handles[0], write_buffer.data(), |
505 static_cast<uint32_t>(write_buffer.size()), nullptr, | 515 static_cast<uint32_t>(write_buffer.size()), nullptr, |
506 0u, MOJO_WRITE_MESSAGE_FLAG_NONE), | 516 0u, MOJO_WRITE_MESSAGE_FLAG_NONE), |
507 MOJO_RESULT_OK); | 517 MOJO_RESULT_OK); |
508 MojoClose(handles[0]); | 518 MojoClose(handles[0]); |
509 return 0; | 519 return 0; |
510 } | 520 } |
511 | 521 |
512 TEST_F(MultiprocessMessagePipeTest, MessagePipePassing) { | 522 TEST_P(MultiprocessMessagePipeTestWithPeerSupport, MessagePipePassing) { |
513 RUN_CHILD_ON_PIPE(CheckMessagePipe, h) | 523 RUN_CHILD_ON_PIPE(CheckMessagePipe, h) |
514 MojoCreateSharedBufferOptions options; | 524 MojoCreateSharedBufferOptions options; |
515 options.struct_size = sizeof(options); | 525 options.struct_size = sizeof(options); |
516 options.flags = MOJO_CREATE_SHARED_BUFFER_OPTIONS_FLAG_NONE; | 526 options.flags = MOJO_CREATE_SHARED_BUFFER_OPTIONS_FLAG_NONE; |
517 | 527 |
518 MojoHandle mp1, mp2; | 528 MojoHandle mp1, mp2; |
519 ASSERT_EQ(MOJO_RESULT_OK, | 529 ASSERT_EQ(MOJO_RESULT_OK, |
520 MojoCreateMessagePipe(nullptr, &mp1, &mp2)); | 530 MojoCreateMessagePipe(nullptr, &mp1, &mp2)); |
521 | 531 |
522 // Write a string into one end of the new message pipe and send the other | 532 // Write a string into one end of the new message pipe and send the other |
(...skipping 21 matching lines...) Expand all Loading... |
544 &read_buffer_size, nullptr, | 554 &read_buffer_size, nullptr, |
545 0, MOJO_READ_MESSAGE_FLAG_NONE), | 555 0, MOJO_READ_MESSAGE_FLAG_NONE), |
546 MOJO_RESULT_OK); | 556 MOJO_RESULT_OK); |
547 read_buffer.resize(read_buffer_size); | 557 read_buffer.resize(read_buffer_size); |
548 CHECK_EQ(read_buffer, std::string("world")); | 558 CHECK_EQ(read_buffer, std::string("world")); |
549 | 559 |
550 MojoClose(mp1); | 560 MojoClose(mp1); |
551 END_CHILD() | 561 END_CHILD() |
552 } | 562 } |
553 | 563 |
554 TEST_F(MultiprocessMessagePipeTest, MessagePipeTwoPassing) { | 564 TEST_P(MultiprocessMessagePipeTestWithPeerSupport, MessagePipeTwoPassing) { |
555 RUN_CHILD_ON_PIPE(CheckMessagePipe, h) | 565 RUN_CHILD_ON_PIPE(CheckMessagePipe, h) |
556 MojoHandle mp1, mp2; | 566 MojoHandle mp1, mp2; |
557 ASSERT_EQ(MOJO_RESULT_OK, | 567 ASSERT_EQ(MOJO_RESULT_OK, |
558 MojoCreateMessagePipe(nullptr, &mp2, &mp1)); | 568 MojoCreateMessagePipe(nullptr, &mp2, &mp1)); |
559 | 569 |
560 // Write a string into one end of the new message pipe and send the other | 570 // Write a string into one end of the new message pipe and send the other |
561 // end. | 571 // end. |
562 const std::string hello("hello"); | 572 const std::string hello("hello"); |
563 ASSERT_EQ(MOJO_RESULT_OK, | 573 ASSERT_EQ(MOJO_RESULT_OK, |
564 MojoWriteMessage(mp1, &hello[0], | 574 MojoWriteMessage(mp1, &hello[0], |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
674 &read_buffer_size, nullptr, | 684 &read_buffer_size, nullptr, |
675 0, MOJO_READ_MESSAGE_FLAG_NONE), | 685 0, MOJO_READ_MESSAGE_FLAG_NONE), |
676 MOJO_RESULT_OK); | 686 MOJO_RESULT_OK); |
677 read_buffer.resize(read_buffer_size); | 687 read_buffer.resize(read_buffer_size); |
678 CHECK_EQ(read_buffer, std::string("world")); | 688 CHECK_EQ(read_buffer, std::string("world")); |
679 | 689 |
680 MojoClose(mp1); | 690 MojoClose(mp1); |
681 END_CHILD(); | 691 END_CHILD(); |
682 } | 692 } |
683 | 693 |
684 TEST_F(MultiprocessMessagePipeTest, CreateMessagePipe) { | 694 TEST_P(MultiprocessMessagePipeTestWithPeerSupport, CreateMessagePipe) { |
685 MojoHandle p0, p1; | 695 MojoHandle p0, p1; |
686 CreateMessagePipe(&p0, &p1); | 696 CreateMessagePipe(&p0, &p1); |
687 VerifyTransmission(p0, p1, "hey man"); | 697 VerifyTransmission(p0, p1, "hey man"); |
688 VerifyTransmission(p1, p0, "slow down"); | 698 VerifyTransmission(p1, p0, "slow down"); |
689 VerifyTransmission(p0, p1, std::string(10 * 1024 * 1024, 'a')); | 699 VerifyTransmission(p0, p1, std::string(10 * 1024 * 1024, 'a')); |
690 VerifyTransmission(p1, p0, std::string(10 * 1024 * 1024, 'e')); | 700 VerifyTransmission(p1, p0, std::string(10 * 1024 * 1024, 'e')); |
691 | 701 |
692 CloseHandle(p0); | 702 CloseHandle(p0); |
693 CloseHandle(p1); | 703 CloseHandle(p1); |
694 } | 704 } |
695 | 705 |
696 TEST_F(MultiprocessMessagePipeTest, PassMessagePipeLocal) { | 706 TEST_P(MultiprocessMessagePipeTestWithPeerSupport, PassMessagePipeLocal) { |
697 MojoHandle p0, p1; | 707 MojoHandle p0, p1; |
698 CreateMessagePipe(&p0, &p1); | 708 CreateMessagePipe(&p0, &p1); |
699 VerifyTransmission(p0, p1, "testing testing"); | 709 VerifyTransmission(p0, p1, "testing testing"); |
700 VerifyTransmission(p1, p0, "one two three"); | 710 VerifyTransmission(p1, p0, "one two three"); |
701 | 711 |
702 MojoHandle p2, p3; | 712 MojoHandle p2, p3; |
703 | 713 |
704 CreateMessagePipe(&p2, &p3); | 714 CreateMessagePipe(&p2, &p3); |
705 VerifyTransmission(p2, p3, "testing testing"); | 715 VerifyTransmission(p2, p3, "testing testing"); |
706 VerifyTransmission(p3, p2, "one two three"); | 716 VerifyTransmission(p3, p2, "one two three"); |
(...skipping 19 matching lines...) Expand all Loading... |
726 h) { | 736 h) { |
727 for (;;) { | 737 for (;;) { |
728 std::string message = ReadMessage(h); | 738 std::string message = ReadMessage(h); |
729 if (message == "exit") | 739 if (message == "exit") |
730 break; | 740 break; |
731 WriteMessage(h, message); | 741 WriteMessage(h, message); |
732 } | 742 } |
733 return 0; | 743 return 0; |
734 } | 744 } |
735 | 745 |
736 TEST_F(MultiprocessMessagePipeTest, MultiprocessChannelPipe) { | 746 TEST_P(MultiprocessMessagePipeTestWithPeerSupport, MultiprocessChannelPipe) { |
737 RUN_CHILD_ON_PIPE(ChannelEchoClient, h) | 747 RUN_CHILD_ON_PIPE(ChannelEchoClient, h) |
738 VerifyEcho(h, "in an interstellar burst"); | 748 VerifyEcho(h, "in an interstellar burst"); |
739 VerifyEcho(h, "i am back to save the universe"); | 749 VerifyEcho(h, "i am back to save the universe"); |
740 VerifyEcho(h, std::string(10 * 1024 * 1024, 'o')); | 750 VerifyEcho(h, std::string(10 * 1024 * 1024, 'o')); |
741 | 751 |
742 WriteMessage(h, "exit"); | 752 WriteMessage(h, "exit"); |
743 END_CHILD() | 753 END_CHILD() |
744 } | 754 } |
745 | 755 |
746 // Receives a pipe handle from the primordial channel and echos on it until | 756 // Receives a pipe handle from the primordial channel and echos on it until |
747 // "exit". Used to test simple pipe transfer across processes via channels. | 757 // "exit". Used to test simple pipe transfer across processes via channels. |
748 DEFINE_TEST_CLIENT_WITH_PIPE(EchoServiceClient, MultiprocessMessagePipeTest, | 758 DEFINE_TEST_CLIENT_WITH_PIPE(EchoServiceClient, MultiprocessMessagePipeTest, |
749 h) { | 759 h) { |
750 MojoHandle p; | 760 MojoHandle p; |
751 ReadMessageWithHandles(h, &p, 1); | 761 ReadMessageWithHandles(h, &p, 1); |
752 for (;;) { | 762 for (;;) { |
753 std::string message = ReadMessage(p); | 763 std::string message = ReadMessage(p); |
754 if (message == "exit") | 764 if (message == "exit") |
755 break; | 765 break; |
756 WriteMessage(p, message); | 766 WriteMessage(p, message); |
757 } | 767 } |
758 return 0; | 768 return 0; |
759 } | 769 } |
760 | 770 |
761 TEST_F(MultiprocessMessagePipeTest, PassMessagePipeCrossProcess) { | 771 TEST_P(MultiprocessMessagePipeTestWithPeerSupport, |
| 772 PassMessagePipeCrossProcess) { |
762 MojoHandle p0, p1; | 773 MojoHandle p0, p1; |
763 CreateMessagePipe(&p0, &p1); | 774 CreateMessagePipe(&p0, &p1); |
764 RUN_CHILD_ON_PIPE(EchoServiceClient, h) | 775 RUN_CHILD_ON_PIPE(EchoServiceClient, h) |
765 | 776 |
766 // Pass one end of the pipe to the other process. | 777 // Pass one end of the pipe to the other process. |
767 WriteMessageWithHandles(h, "here take this", &p1, 1); | 778 WriteMessageWithHandles(h, "here take this", &p1, 1); |
768 | 779 |
769 VerifyEcho(p0, "and you may ask yourself"); | 780 VerifyEcho(p0, "and you may ask yourself"); |
770 VerifyEcho(p0, "where does that highway go?"); | 781 VerifyEcho(p0, "where does that highway go?"); |
771 VerifyEcho(p0, std::string(20 * 1024 * 1024, 'i')); | 782 VerifyEcho(p0, std::string(20 * 1024 * 1024, 'i')); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
808 WriteMessage(handles[index], ReadMessage(handles[index])); | 819 WriteMessage(handles[index], ReadMessage(handles[index])); |
809 } | 820 } |
810 } | 821 } |
811 | 822 |
812 for (size_t i = 1; i < handles.size(); ++i) | 823 for (size_t i = 1; i < handles.size(); ++i) |
813 CloseHandle(handles[i]); | 824 CloseHandle(handles[i]); |
814 | 825 |
815 return 0; | 826 return 0; |
816 } | 827 } |
817 | 828 |
818 TEST_F(MultiprocessMessagePipeTest, PassMoarMessagePipesCrossProcess) { | 829 TEST_P(MultiprocessMessagePipeTestWithPeerSupport, |
| 830 PassMoarMessagePipesCrossProcess) { |
819 MojoHandle echo_factory_proxy, echo_factory_request; | 831 MojoHandle echo_factory_proxy, echo_factory_request; |
820 CreateMessagePipe(&echo_factory_proxy, &echo_factory_request); | 832 CreateMessagePipe(&echo_factory_proxy, &echo_factory_request); |
821 | 833 |
822 MojoHandle echo_proxy_a, echo_request_a; | 834 MojoHandle echo_proxy_a, echo_request_a; |
823 CreateMessagePipe(&echo_proxy_a, &echo_request_a); | 835 CreateMessagePipe(&echo_proxy_a, &echo_request_a); |
824 | 836 |
825 MojoHandle echo_proxy_b, echo_request_b; | 837 MojoHandle echo_proxy_b, echo_request_b; |
826 CreateMessagePipe(&echo_proxy_b, &echo_request_b); | 838 CreateMessagePipe(&echo_proxy_b, &echo_request_b); |
827 | 839 |
828 MojoHandle echo_proxy_c, echo_request_c; | 840 MojoHandle echo_proxy_c, echo_request_c; |
(...skipping 24 matching lines...) Expand all Loading... |
853 | 865 |
854 WriteMessage(h, "exit"); | 866 WriteMessage(h, "exit"); |
855 END_CHILD() | 867 END_CHILD() |
856 | 868 |
857 CloseHandle(echo_factory_proxy); | 869 CloseHandle(echo_factory_proxy); |
858 CloseHandle(echo_proxy_a); | 870 CloseHandle(echo_proxy_a); |
859 CloseHandle(echo_proxy_b); | 871 CloseHandle(echo_proxy_b); |
860 CloseHandle(echo_proxy_c); | 872 CloseHandle(echo_proxy_c); |
861 } | 873 } |
862 | 874 |
863 TEST_F(MultiprocessMessagePipeTest, ChannelPipesWithMultipleChildren) { | 875 TEST_P(MultiprocessMessagePipeTestWithPeerSupport, |
| 876 ChannelPipesWithMultipleChildren) { |
864 RUN_CHILD_ON_PIPE(ChannelEchoClient, a) | 877 RUN_CHILD_ON_PIPE(ChannelEchoClient, a) |
865 RUN_CHILD_ON_PIPE(ChannelEchoClient, b) | 878 RUN_CHILD_ON_PIPE(ChannelEchoClient, b) |
866 VerifyEcho(a, "hello child 0"); | 879 VerifyEcho(a, "hello child 0"); |
867 VerifyEcho(b, "hello child 1"); | 880 VerifyEcho(b, "hello child 1"); |
868 | 881 |
869 WriteMessage(a, "exit"); | 882 WriteMessage(a, "exit"); |
870 WriteMessage(b, "exit"); | 883 WriteMessage(b, "exit"); |
871 END_CHILD() | 884 END_CHILD() |
872 END_CHILD() | 885 END_CHILD() |
873 } | 886 } |
874 | 887 |
875 // Reads and turns a pipe handle some number of times to create lots of | 888 // Reads and turns a pipe handle some number of times to create lots of |
876 // transient proxies. | 889 // transient proxies. |
877 DEFINE_TEST_CLIENT_TEST_WITH_PIPE(PingPongPipeClient, | 890 DEFINE_TEST_CLIENT_TEST_WITH_PIPE(PingPongPipeClient, |
878 MultiprocessMessagePipeTest, h) { | 891 MultiprocessMessagePipeTest, h) { |
879 const size_t kNumBounces = 50; | 892 const size_t kNumBounces = 50; |
880 MojoHandle p0, p1; | 893 MojoHandle p0, p1; |
881 ReadMessageWithHandles(h, &p0, 1); | 894 ReadMessageWithHandles(h, &p0, 1); |
882 ReadMessageWithHandles(h, &p1, 1); | 895 ReadMessageWithHandles(h, &p1, 1); |
883 for (size_t i = 0; i < kNumBounces; ++i) { | 896 for (size_t i = 0; i < kNumBounces; ++i) { |
884 WriteMessageWithHandles(h, "", &p1, 1); | 897 WriteMessageWithHandles(h, "", &p1, 1); |
885 ReadMessageWithHandles(h, &p1, 1); | 898 ReadMessageWithHandles(h, &p1, 1); |
886 } | 899 } |
887 WriteMessageWithHandles(h, "", &p0, 1); | 900 WriteMessageWithHandles(h, "", &p0, 1); |
888 WriteMessage(p1, "bye"); | 901 WriteMessage(p1, "bye"); |
889 MojoClose(p1); | 902 MojoClose(p1); |
890 EXPECT_EQ("quit", ReadMessage(h)); | 903 EXPECT_EQ("quit", ReadMessage(h)); |
891 } | 904 } |
892 | 905 |
893 TEST_F(MultiprocessMessagePipeTest, PingPongPipe) { | 906 TEST_P(MultiprocessMessagePipeTestWithPeerSupport, PingPongPipe) { |
894 MojoHandle p0, p1; | 907 MojoHandle p0, p1; |
895 CreateMessagePipe(&p0, &p1); | 908 CreateMessagePipe(&p0, &p1); |
896 | 909 |
897 RUN_CHILD_ON_PIPE(PingPongPipeClient, h) | 910 RUN_CHILD_ON_PIPE(PingPongPipeClient, h) |
898 const size_t kNumBounces = 50; | 911 const size_t kNumBounces = 50; |
899 WriteMessageWithHandles(h, "", &p0, 1); | 912 WriteMessageWithHandles(h, "", &p0, 1); |
900 WriteMessageWithHandles(h, "", &p1, 1); | 913 WriteMessageWithHandles(h, "", &p1, 1); |
901 for (size_t i = 0; i < kNumBounces; ++i) { | 914 for (size_t i = 0; i < kNumBounces; ++i) { |
902 ReadMessageWithHandles(h, &p1, 1); | 915 ReadMessageWithHandles(h, &p1, 1); |
903 WriteMessageWithHandles(h, "", &p1, 1); | 916 WriteMessageWithHandles(h, "", &p1, 1); |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1089 END_CHILD() | 1102 END_CHILD() |
1090 END_CHILD() | 1103 END_CHILD() |
1091 END_CHILD() | 1104 END_CHILD() |
1092 } | 1105 } |
1093 | 1106 |
1094 DEFINE_TEST_CLIENT_TEST_WITH_PIPE(ReceivePipeWithClosedPeer, | 1107 DEFINE_TEST_CLIENT_TEST_WITH_PIPE(ReceivePipeWithClosedPeer, |
1095 MultiprocessMessagePipeTest, h) { | 1108 MultiprocessMessagePipeTest, h) { |
1096 MojoHandle p; | 1109 MojoHandle p; |
1097 EXPECT_EQ("foo", ReadMessageWithHandles(h, &p, 1)); | 1110 EXPECT_EQ("foo", ReadMessageWithHandles(h, &p, 1)); |
1098 | 1111 |
1099 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(p, MOJO_HANDLE_SIGNAL_PEER_CLOSED, | 1112 auto result = MojoWait(p, MOJO_HANDLE_SIGNAL_PEER_CLOSED, |
1100 MOJO_DEADLINE_INDEFINITE, nullptr)); | 1113 MOJO_DEADLINE_INDEFINITE, nullptr); |
| 1114 EXPECT_EQ(MOJO_RESULT_OK, result); |
1101 } | 1115 } |
1102 | 1116 |
1103 TEST_F(MultiprocessMessagePipeTest, SendPipeThenClosePeer) { | 1117 TEST_P(MultiprocessMessagePipeTestWithPeerSupport, SendPipeThenClosePeer) { |
1104 RUN_CHILD_ON_PIPE(ReceivePipeWithClosedPeer, h) | 1118 RUN_CHILD_ON_PIPE(ReceivePipeWithClosedPeer, h) |
1105 MojoHandle a, b; | 1119 MojoHandle a, b; |
1106 CreateMessagePipe(&a, &b); | 1120 CreateMessagePipe(&a, &b); |
1107 | 1121 |
1108 // Send |a| and immediately close |b|. The child should observe closure. | 1122 // Send |a| and immediately close |b|. The child should observe closure. |
1109 WriteMessageWithHandles(h, "foo", &a, 1); | 1123 WriteMessageWithHandles(h, "foo", &a, 1); |
1110 MojoClose(b); | 1124 MojoClose(b); |
1111 END_CHILD() | 1125 END_CHILD() |
1112 } | 1126 } |
1113 | 1127 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1169 EXPECT_EQ("c2a plz", | 1183 EXPECT_EQ("c2a plz", |
1170 ReadMessageWithHandles(kid_a, &application_request, 1)); | 1184 ReadMessageWithHandles(kid_a, &application_request, 1)); |
1171 | 1185 |
1172 WriteMessageWithHandles(kid_b, "c2a", &application_request, 1); | 1186 WriteMessageWithHandles(kid_b, "c2a", &application_request, 1); |
1173 END_CHILD() | 1187 END_CHILD() |
1174 | 1188 |
1175 WriteMessage(kid_a, "quit"); | 1189 WriteMessage(kid_a, "quit"); |
1176 END_CHILD() | 1190 END_CHILD() |
1177 } | 1191 } |
1178 | 1192 |
1179 | 1193 TEST_P(MultiprocessMessagePipeTestWithPeerSupport, SendClosePeerSend) { |
1180 TEST_F(MultiprocessMessagePipeTest, SendClosePeerSend) { | |
1181 MojoHandle a, b; | 1194 MojoHandle a, b; |
1182 CreateMessagePipe(&a, &b); | 1195 CreateMessagePipe(&a, &b); |
1183 | 1196 |
1184 MojoHandle c, d; | 1197 MojoHandle c, d; |
1185 CreateMessagePipe(&c, &d); | 1198 CreateMessagePipe(&c, &d); |
1186 | 1199 |
1187 // Send |a| over |c|, immediately close |b|, then send |a| back over |d|. | 1200 // Send |a| over |c|, immediately close |b|, then send |a| back over |d|. |
1188 WriteMessageWithHandles(c, "foo", &a, 1); | 1201 WriteMessageWithHandles(c, "foo", &a, 1); |
1189 EXPECT_EQ("foo", ReadMessageWithHandles(d, &a, 1)); | 1202 EXPECT_EQ("foo", ReadMessageWithHandles(d, &a, 1)); |
1190 WriteMessageWithHandles(d, "bar", &a, 1); | 1203 WriteMessageWithHandles(d, "bar", &a, 1); |
(...skipping 22 matching lines...) Expand all Loading... |
1213 // the parent, just for some extra proxying goodness. | 1226 // the parent, just for some extra proxying goodness. |
1214 WriteMessageWithHandles(c, "foo", &pipe[1], 1); | 1227 WriteMessageWithHandles(c, "foo", &pipe[1], 1); |
1215 EXPECT_EQ("foo", ReadMessageWithHandles(d, &pipe[1], 1)); | 1228 EXPECT_EQ("foo", ReadMessageWithHandles(d, &pipe[1], 1)); |
1216 | 1229 |
1217 // And finally pass it back to the parent. | 1230 // And finally pass it back to the parent. |
1218 WriteMessageWithHandles(h, "bar", &pipe[1], 1); | 1231 WriteMessageWithHandles(h, "bar", &pipe[1], 1); |
1219 | 1232 |
1220 EXPECT_EQ("quit", ReadMessage(h)); | 1233 EXPECT_EQ("quit", ReadMessage(h)); |
1221 } | 1234 } |
1222 | 1235 |
1223 TEST_F(MultiprocessMessagePipeTest, WriteCloseSendPeer) { | 1236 TEST_P(MultiprocessMessagePipeTestWithPeerSupport, WriteCloseSendPeer) { |
1224 MojoHandle pipe[2]; | 1237 MojoHandle pipe[2]; |
1225 CreateMessagePipe(&pipe[0], &pipe[1]); | 1238 CreateMessagePipe(&pipe[0], &pipe[1]); |
1226 | 1239 |
1227 RUN_CHILD_ON_PIPE(WriteCloseSendPeerClient, h) | 1240 RUN_CHILD_ON_PIPE(WriteCloseSendPeerClient, h) |
1228 // Pass the pipe to the child. | 1241 // Pass the pipe to the child. |
1229 WriteMessageWithHandles(h, "foo", pipe, 2); | 1242 WriteMessageWithHandles(h, "foo", pipe, 2); |
1230 | 1243 |
1231 // Read back an endpoint which should have messages on it. | 1244 // Read back an endpoint which should have messages on it. |
1232 MojoHandle p; | 1245 MojoHandle p; |
1233 EXPECT_EQ("bar", ReadMessageWithHandles(h, &p, 1)); | 1246 EXPECT_EQ("bar", ReadMessageWithHandles(h, &p, 1)); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1338 WriteMessage(child2, "bye"); | 1351 WriteMessage(child2, "bye"); |
1339 END_CHILD(); | 1352 END_CHILD(); |
1340 | 1353 |
1341 WriteMessage(child1, "bye"); | 1354 WriteMessage(child1, "bye"); |
1342 END_CHILD() | 1355 END_CHILD() |
1343 | 1356 |
1344 // The error messages should match the processes which triggered them. | 1357 // The error messages should match the processes which triggered them. |
1345 EXPECT_NE(std::string::npos, first_process_error.find(kFirstErrorMessage)); | 1358 EXPECT_NE(std::string::npos, first_process_error.find(kFirstErrorMessage)); |
1346 EXPECT_NE(std::string::npos, second_process_error.find(kSecondErrorMessage)); | 1359 EXPECT_NE(std::string::npos, second_process_error.find(kSecondErrorMessage)); |
1347 } | 1360 } |
1348 | 1361 INSTANTIATE_TEST_CASE_P(, |
| 1362 MultiprocessMessagePipeTestWithPeerSupport, |
| 1363 testing::Values(test::MojoTestBase::LaunchType::CHILD, |
| 1364 test::MojoTestBase::LaunchType::PEER)); |
1349 } // namespace | 1365 } // namespace |
1350 } // namespace edk | 1366 } // namespace edk |
1351 } // namespace mojo | 1367 } // namespace mojo |
OLD | NEW |