| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stdint.h> | 5 #include <stdint.h> |
| 6 #include <stdio.h> | 6 #include <stdio.h> |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 MOJO_DISALLOW_COPY_AND_ASSIGN(RemoteMessagePipeTest); | 171 MOJO_DISALLOW_COPY_AND_ASSIGN(RemoteMessagePipeTest); |
| 172 }; | 172 }; |
| 173 | 173 |
| 174 TEST_F(RemoteMessagePipeTest, Basic) { | 174 TEST_F(RemoteMessagePipeTest, Basic) { |
| 175 static const char kHello[] = "hello"; | 175 static const char kHello[] = "hello"; |
| 176 static const char kWorld[] = "world!!!1!!!1!"; | 176 static const char kWorld[] = "world!!!1!!!1!"; |
| 177 char buffer[100] = {0}; | 177 char buffer[100] = {0}; |
| 178 uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer)); | 178 uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer)); |
| 179 Waiter waiter; | 179 Waiter waiter; |
| 180 HandleSignalsState hss; | 180 HandleSignalsState hss; |
| 181 uint32_t context = 0; | 181 uint64_t context = 0; |
| 182 | 182 |
| 183 // Connect message pipes. MP 0, port 1 will be attached to channel 0 and | 183 // Connect message pipes. MP 0, port 1 will be attached to channel 0 and |
| 184 // connected to MP 1, port 0, which will be attached to channel 1. This leaves | 184 // connected to MP 1, port 0, which will be attached to channel 1. This leaves |
| 185 // MP 0, port 0 and MP 1, port 1 as the "user-facing" endpoints. | 185 // MP 0, port 0 and MP 1, port 1 as the "user-facing" endpoints. |
| 186 | 186 |
| 187 RefPtr<ChannelEndpoint> ep0; | 187 RefPtr<ChannelEndpoint> ep0; |
| 188 auto mp0 = MessagePipe::CreateLocalProxy(&ep0); | 188 auto mp0 = MessagePipe::CreateLocalProxy(&ep0); |
| 189 RefPtr<ChannelEndpoint> ep1; | 189 RefPtr<ChannelEndpoint> ep1; |
| 190 auto mp1 = MessagePipe::CreateProxyLocal(&ep1); | 190 auto mp1 = MessagePipe::CreateProxyLocal(&ep1); |
| 191 BootstrapChannelEndpoints(std::move(ep0), std::move(ep1)); | 191 BootstrapChannelEndpoints(std::move(ep0), std::move(ep1)); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfied_signals); | 274 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfied_signals); |
| 275 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfiable_signals); | 275 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfiable_signals); |
| 276 | 276 |
| 277 // And MP 1, port 1. | 277 // And MP 1, port 1. |
| 278 mp1->Close(1); | 278 mp1->Close(1); |
| 279 } | 279 } |
| 280 | 280 |
| 281 TEST_F(RemoteMessagePipeTest, PeerClosed) { | 281 TEST_F(RemoteMessagePipeTest, PeerClosed) { |
| 282 Waiter waiter; | 282 Waiter waiter; |
| 283 HandleSignalsState hss; | 283 HandleSignalsState hss; |
| 284 uint32_t context = 0; | 284 uint64_t context = 0; |
| 285 | 285 |
| 286 // Connect message pipes. MP 0, port 1 will be attached to channel 0 and | 286 // Connect message pipes. MP 0, port 1 will be attached to channel 0 and |
| 287 // connected to MP 1, port 0, which will be attached to channel 1. This leaves | 287 // connected to MP 1, port 0, which will be attached to channel 1. This leaves |
| 288 // MP 0, port 0 and MP 1, port 1 as the "user-facing" endpoints. | 288 // MP 0, port 0 and MP 1, port 1 as the "user-facing" endpoints. |
| 289 | 289 |
| 290 RefPtr<ChannelEndpoint> ep0; | 290 RefPtr<ChannelEndpoint> ep0; |
| 291 auto mp0 = MessagePipe::CreateLocalProxy(&ep0); | 291 auto mp0 = MessagePipe::CreateLocalProxy(&ep0); |
| 292 RefPtr<ChannelEndpoint> ep1; | 292 RefPtr<ChannelEndpoint> ep1; |
| 293 auto mp1 = MessagePipe::CreateProxyLocal(&ep1); | 293 auto mp1 = MessagePipe::CreateProxyLocal(&ep1); |
| 294 BootstrapChannelEndpoints(std::move(ep0), std::move(ep1)); | 294 BootstrapChannelEndpoints(std::move(ep0), std::move(ep1)); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 314 mp1->Close(1); | 314 mp1->Close(1); |
| 315 } | 315 } |
| 316 | 316 |
| 317 TEST_F(RemoteMessagePipeTest, Multiplex) { | 317 TEST_F(RemoteMessagePipeTest, Multiplex) { |
| 318 static const char kHello[] = "hello"; | 318 static const char kHello[] = "hello"; |
| 319 static const char kWorld[] = "world!!!1!!!1!"; | 319 static const char kWorld[] = "world!!!1!!!1!"; |
| 320 char buffer[100] = {0}; | 320 char buffer[100] = {0}; |
| 321 uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer)); | 321 uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer)); |
| 322 Waiter waiter; | 322 Waiter waiter; |
| 323 HandleSignalsState hss; | 323 HandleSignalsState hss; |
| 324 uint32_t context = 0; | 324 uint64_t context = 0; |
| 325 | 325 |
| 326 // Connect message pipes as in the |Basic| test. | 326 // Connect message pipes as in the |Basic| test. |
| 327 | 327 |
| 328 RefPtr<ChannelEndpoint> ep0; | 328 RefPtr<ChannelEndpoint> ep0; |
| 329 auto mp0 = MessagePipe::CreateLocalProxy(&ep0); | 329 auto mp0 = MessagePipe::CreateLocalProxy(&ep0); |
| 330 RefPtr<ChannelEndpoint> ep1; | 330 RefPtr<ChannelEndpoint> ep1; |
| 331 auto mp1 = MessagePipe::CreateProxyLocal(&ep1); | 331 auto mp1 = MessagePipe::CreateProxyLocal(&ep1); |
| 332 BootstrapChannelEndpoints(std::move(ep0), std::move(ep1)); | 332 BootstrapChannelEndpoints(std::move(ep0), std::move(ep1)); |
| 333 | 333 |
| 334 // Now put another message pipe on the channel. | 334 // Now put another message pipe on the channel. |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 mp2->Close(0); | 490 mp2->Close(0); |
| 491 mp3->Close(0); | 491 mp3->Close(0); |
| 492 } | 492 } |
| 493 | 493 |
| 494 TEST_F(RemoteMessagePipeTest, CloseBeforeAttachAndRun) { | 494 TEST_F(RemoteMessagePipeTest, CloseBeforeAttachAndRun) { |
| 495 static const char kHello[] = "hello"; | 495 static const char kHello[] = "hello"; |
| 496 char buffer[100] = {0}; | 496 char buffer[100] = {0}; |
| 497 uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer)); | 497 uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer)); |
| 498 Waiter waiter; | 498 Waiter waiter; |
| 499 HandleSignalsState hss; | 499 HandleSignalsState hss; |
| 500 uint32_t context = 0; | 500 uint64_t context = 0; |
| 501 | 501 |
| 502 // Connect message pipes. MP 0, port 1 will be attached to channel 0 and | 502 // Connect message pipes. MP 0, port 1 will be attached to channel 0 and |
| 503 // connected to MP 1, port 0, which will be attached to channel 1. This leaves | 503 // connected to MP 1, port 0, which will be attached to channel 1. This leaves |
| 504 // MP 0, port 0 and MP 1, port 1 as the "user-facing" endpoints. | 504 // MP 0, port 0 and MP 1, port 1 as the "user-facing" endpoints. |
| 505 | 505 |
| 506 RefPtr<ChannelEndpoint> ep0; | 506 RefPtr<ChannelEndpoint> ep0; |
| 507 auto mp0 = MessagePipe::CreateLocalProxy(&ep0); | 507 auto mp0 = MessagePipe::CreateLocalProxy(&ep0); |
| 508 | 508 |
| 509 // Write to MP 0, port 0. | 509 // Write to MP 0, port 0. |
| 510 EXPECT_EQ( | 510 EXPECT_EQ( |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 // And MP 1, port 1. | 552 // And MP 1, port 1. |
| 553 mp1->Close(1); | 553 mp1->Close(1); |
| 554 } | 554 } |
| 555 | 555 |
| 556 TEST_F(RemoteMessagePipeTest, CloseBeforeConnect) { | 556 TEST_F(RemoteMessagePipeTest, CloseBeforeConnect) { |
| 557 static const char kHello[] = "hello"; | 557 static const char kHello[] = "hello"; |
| 558 char buffer[100] = {0}; | 558 char buffer[100] = {0}; |
| 559 uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer)); | 559 uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer)); |
| 560 Waiter waiter; | 560 Waiter waiter; |
| 561 HandleSignalsState hss; | 561 HandleSignalsState hss; |
| 562 uint32_t context = 0; | 562 uint64_t context = 0; |
| 563 | 563 |
| 564 // Connect message pipes. MP 0, port 1 will be attached to channel 0 and | 564 // Connect message pipes. MP 0, port 1 will be attached to channel 0 and |
| 565 // connected to MP 1, port 0, which will be attached to channel 1. This leaves | 565 // connected to MP 1, port 0, which will be attached to channel 1. This leaves |
| 566 // MP 0, port 0 and MP 1, port 1 as the "user-facing" endpoints. | 566 // MP 0, port 0 and MP 1, port 1 as the "user-facing" endpoints. |
| 567 | 567 |
| 568 RefPtr<ChannelEndpoint> ep0; | 568 RefPtr<ChannelEndpoint> ep0; |
| 569 auto mp0 = MessagePipe::CreateLocalProxy(&ep0); | 569 auto mp0 = MessagePipe::CreateLocalProxy(&ep0); |
| 570 | 570 |
| 571 // Write to MP 0, port 0. | 571 // Write to MP 0, port 0. |
| 572 EXPECT_EQ( | 572 EXPECT_EQ( |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 612 EXPECT_STREQ(kHello, buffer); | 612 EXPECT_STREQ(kHello, buffer); |
| 613 | 613 |
| 614 // And MP 1, port 1. | 614 // And MP 1, port 1. |
| 615 mp1->Close(1); | 615 mp1->Close(1); |
| 616 } | 616 } |
| 617 | 617 |
| 618 TEST_F(RemoteMessagePipeTest, HandlePassing) { | 618 TEST_F(RemoteMessagePipeTest, HandlePassing) { |
| 619 static const char kHello[] = "hello"; | 619 static const char kHello[] = "hello"; |
| 620 Waiter waiter; | 620 Waiter waiter; |
| 621 HandleSignalsState hss; | 621 HandleSignalsState hss; |
| 622 uint32_t context = 0; | 622 uint64_t context = 0; |
| 623 | 623 |
| 624 RefPtr<ChannelEndpoint> ep0; | 624 RefPtr<ChannelEndpoint> ep0; |
| 625 auto mp0 = MessagePipe::CreateLocalProxy(&ep0); | 625 auto mp0 = MessagePipe::CreateLocalProxy(&ep0); |
| 626 RefPtr<ChannelEndpoint> ep1; | 626 RefPtr<ChannelEndpoint> ep1; |
| 627 auto mp1 = MessagePipe::CreateProxyLocal(&ep1); | 627 auto mp1 = MessagePipe::CreateProxyLocal(&ep1); |
| 628 BootstrapChannelEndpoints(std::move(ep0), std::move(ep1)); | 628 BootstrapChannelEndpoints(std::move(ep0), std::move(ep1)); |
| 629 | 629 |
| 630 // We'll try to pass this dispatcher. | 630 // We'll try to pass this dispatcher. |
| 631 auto dispatcher = MessagePipeDispatcher::Create( | 631 auto dispatcher = MessagePipeDispatcher::Create( |
| 632 MessagePipeDispatcher::kDefaultCreateOptions); | 632 MessagePipeDispatcher::kDefaultCreateOptions); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); | 772 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); |
| 773 // Note that |local_mp|'s port 0 belong to |dispatcher|, which was closed. | 773 // Note that |local_mp|'s port 0 belong to |dispatcher|, which was closed. |
| 774 local_mp->Close(1); | 774 local_mp->Close(1); |
| 775 } | 775 } |
| 776 | 776 |
| 777 TEST_F(RemoteMessagePipeTest, HandlePassingHalfClosed) { | 777 TEST_F(RemoteMessagePipeTest, HandlePassingHalfClosed) { |
| 778 static const char kHello[] = "hello"; | 778 static const char kHello[] = "hello"; |
| 779 static const char kWorld[] = "world!"; | 779 static const char kWorld[] = "world!"; |
| 780 Waiter waiter; | 780 Waiter waiter; |
| 781 HandleSignalsState hss; | 781 HandleSignalsState hss; |
| 782 uint32_t context = 0; | 782 uint64_t context = 0; |
| 783 | 783 |
| 784 // We'll try to pass this dispatcher. | 784 // We'll try to pass this dispatcher. |
| 785 auto dispatcher = MessagePipeDispatcher::Create( | 785 auto dispatcher = MessagePipeDispatcher::Create( |
| 786 MessagePipeDispatcher::kDefaultCreateOptions); | 786 MessagePipeDispatcher::kDefaultCreateOptions); |
| 787 auto local_mp = MessagePipe::CreateLocalLocal(); | 787 auto local_mp = MessagePipe::CreateLocalLocal(); |
| 788 dispatcher->Init(local_mp.Clone(), 0); | 788 dispatcher->Init(local_mp.Clone(), 0); |
| 789 Handle handle(std::move(dispatcher), | 789 Handle handle(std::move(dispatcher), |
| 790 MessagePipeDispatcher::kDefaultHandleRights); | 790 MessagePipeDispatcher::kDefaultHandleRights); |
| 791 | 791 |
| 792 hss = local_mp->GetHandleSignalsState(0); | 792 hss = local_mp->GetHandleSignalsState(0); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 923 // Close everything that belongs to us. | 923 // Close everything that belongs to us. |
| 924 mp0->Close(0); | 924 mp0->Close(0); |
| 925 mp1->Close(1); | 925 mp1->Close(1); |
| 926 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); | 926 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); |
| 927 } | 927 } |
| 928 | 928 |
| 929 TEST_F(RemoteMessagePipeTest, SharedBufferPassing) { | 929 TEST_F(RemoteMessagePipeTest, SharedBufferPassing) { |
| 930 static const char kHello[] = "hello"; | 930 static const char kHello[] = "hello"; |
| 931 Waiter waiter; | 931 Waiter waiter; |
| 932 HandleSignalsState hss; | 932 HandleSignalsState hss; |
| 933 uint32_t context = 0; | 933 uint64_t context = 0; |
| 934 | 934 |
| 935 RefPtr<ChannelEndpoint> ep0; | 935 RefPtr<ChannelEndpoint> ep0; |
| 936 auto mp0 = MessagePipe::CreateLocalProxy(&ep0); | 936 auto mp0 = MessagePipe::CreateLocalProxy(&ep0); |
| 937 RefPtr<ChannelEndpoint> ep1; | 937 RefPtr<ChannelEndpoint> ep1; |
| 938 auto mp1 = MessagePipe::CreateProxyLocal(&ep1); | 938 auto mp1 = MessagePipe::CreateProxyLocal(&ep1); |
| 939 BootstrapChannelEndpoints(std::move(ep0), std::move(ep1)); | 939 BootstrapChannelEndpoints(std::move(ep0), std::move(ep1)); |
| 940 | 940 |
| 941 // We'll try to pass this dispatcher. | 941 // We'll try to pass this dispatcher. |
| 942 MojoResult result = MOJO_RESULT_INTERNAL; | 942 MojoResult result = MOJO_RESULT_INTERNAL; |
| 943 auto dispatcher = SharedBufferDispatcher::Create( | 943 auto dispatcher = SharedBufferDispatcher::Create( |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1049 // The second mapping should still be good. | 1049 // The second mapping should still be good. |
| 1050 EXPECT_EQ('x', static_cast<char*>(mapping1->GetBase())[1]); | 1050 EXPECT_EQ('x', static_cast<char*>(mapping1->GetBase())[1]); |
| 1051 } | 1051 } |
| 1052 | 1052 |
| 1053 TEST_F(RemoteMessagePipeTest, PlatformHandlePassing) { | 1053 TEST_F(RemoteMessagePipeTest, PlatformHandlePassing) { |
| 1054 test::ScopedTestDir test_dir; | 1054 test::ScopedTestDir test_dir; |
| 1055 | 1055 |
| 1056 static const char kHello[] = "hello"; | 1056 static const char kHello[] = "hello"; |
| 1057 static const char kWorld[] = "world"; | 1057 static const char kWorld[] = "world"; |
| 1058 Waiter waiter; | 1058 Waiter waiter; |
| 1059 uint32_t context = 0; | 1059 uint64_t context = 0; |
| 1060 HandleSignalsState hss; | 1060 HandleSignalsState hss; |
| 1061 | 1061 |
| 1062 RefPtr<ChannelEndpoint> ep0; | 1062 RefPtr<ChannelEndpoint> ep0; |
| 1063 auto mp0 = MessagePipe::CreateLocalProxy(&ep0); | 1063 auto mp0 = MessagePipe::CreateLocalProxy(&ep0); |
| 1064 RefPtr<ChannelEndpoint> ep1; | 1064 RefPtr<ChannelEndpoint> ep1; |
| 1065 auto mp1 = MessagePipe::CreateProxyLocal(&ep1); | 1065 auto mp1 = MessagePipe::CreateProxyLocal(&ep1); |
| 1066 BootstrapChannelEndpoints(std::move(ep0), std::move(ep1)); | 1066 BootstrapChannelEndpoints(std::move(ep0), std::move(ep1)); |
| 1067 | 1067 |
| 1068 util::ScopedFILE fp(test_dir.CreateFile()); | 1068 util::ScopedFILE fp(test_dir.CreateFile()); |
| 1069 EXPECT_EQ(sizeof(kHello), fwrite(kHello, 1, sizeof(kHello), fp.get())); | 1069 EXPECT_EQ(sizeof(kHello), fwrite(kHello, 1, sizeof(kHello), fp.get())); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1191 } | 1191 } |
| 1192 | 1192 |
| 1193 // Tests passing an end of a message pipe over a remote message pipe, and then | 1193 // Tests passing an end of a message pipe over a remote message pipe, and then |
| 1194 // passing that end back. | 1194 // passing that end back. |
| 1195 // TODO(vtl): Also test passing a message pipe across two remote message pipes. | 1195 // TODO(vtl): Also test passing a message pipe across two remote message pipes. |
| 1196 TEST_F(RemoteMessagePipeTest, PassMessagePipeHandleAcrossAndBack) { | 1196 TEST_F(RemoteMessagePipeTest, PassMessagePipeHandleAcrossAndBack) { |
| 1197 static const char kHello[] = "hello"; | 1197 static const char kHello[] = "hello"; |
| 1198 static const char kWorld[] = "world"; | 1198 static const char kWorld[] = "world"; |
| 1199 Waiter waiter; | 1199 Waiter waiter; |
| 1200 HandleSignalsState hss; | 1200 HandleSignalsState hss; |
| 1201 uint32_t context = 0; | 1201 uint64_t context = 0; |
| 1202 | 1202 |
| 1203 RefPtr<ChannelEndpoint> ep0; | 1203 RefPtr<ChannelEndpoint> ep0; |
| 1204 auto mp0 = MessagePipe::CreateLocalProxy(&ep0); | 1204 auto mp0 = MessagePipe::CreateLocalProxy(&ep0); |
| 1205 RefPtr<ChannelEndpoint> ep1; | 1205 RefPtr<ChannelEndpoint> ep1; |
| 1206 auto mp1 = MessagePipe::CreateProxyLocal(&ep1); | 1206 auto mp1 = MessagePipe::CreateProxyLocal(&ep1); |
| 1207 BootstrapChannelEndpoints(std::move(ep0), std::move(ep1)); | 1207 BootstrapChannelEndpoints(std::move(ep0), std::move(ep1)); |
| 1208 | 1208 |
| 1209 // We'll try to pass this dispatcher. | 1209 // We'll try to pass this dispatcher. |
| 1210 auto dispatcher = MessagePipeDispatcher::Create( | 1210 auto dispatcher = MessagePipeDispatcher::Create( |
| 1211 MessagePipeDispatcher::kDefaultCreateOptions); | 1211 MessagePipeDispatcher::kDefaultCreateOptions); |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1407 mp0->Close(0); | 1407 mp0->Close(0); |
| 1408 mp1->Close(1); | 1408 mp1->Close(1); |
| 1409 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); | 1409 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); |
| 1410 // Note that |local_mp|'s port 0 belong to |dispatcher|, which was closed. | 1410 // Note that |local_mp|'s port 0 belong to |dispatcher|, which was closed. |
| 1411 local_mp->Close(1); | 1411 local_mp->Close(1); |
| 1412 } | 1412 } |
| 1413 | 1413 |
| 1414 } // namespace | 1414 } // namespace |
| 1415 } // namespace system | 1415 } // namespace system |
| 1416 } // namespace mojo | 1416 } // namespace mojo |
| OLD | NEW |