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 1240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1251 EXPECT_EQ("qux", ReadMessage(p)); | 1251 EXPECT_EQ("qux", ReadMessage(p)); |
1252 | 1252 |
1253 // Expect to have peer closure signaled. | 1253 // Expect to have peer closure signaled. |
1254 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(p, MOJO_HANDLE_SIGNAL_PEER_CLOSED, | 1254 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(p, MOJO_HANDLE_SIGNAL_PEER_CLOSED, |
1255 MOJO_DEADLINE_INDEFINITE, nullptr)); | 1255 MOJO_DEADLINE_INDEFINITE, nullptr)); |
1256 | 1256 |
1257 WriteMessage(h, "quit"); | 1257 WriteMessage(h, "quit"); |
1258 END_CHILD() | 1258 END_CHILD() |
1259 } | 1259 } |
1260 | 1260 |
1261 DEFINE_TEST_CLIENT_TEST_WITH_PIPE(BootstrapMessagePipeAsyncClient, | |
1262 MultiprocessMessagePipeTest, parent) { | |
1263 // Receive one end of a platform channel from the parent. | |
1264 MojoHandle channel_handle; | |
1265 EXPECT_EQ("hi", ReadMessageWithHandles(parent, &channel_handle, 1)); | |
1266 ScopedPlatformHandle channel; | |
1267 EXPECT_EQ(MOJO_RESULT_OK, | |
1268 edk::PassWrappedPlatformHandle(channel_handle, &channel)); | |
1269 ASSERT_TRUE(channel.is_valid()); | |
1270 | |
1271 // Create a new pipe using our end of the channel. | |
1272 ScopedMessagePipeHandle pipe = edk::CreateMessagePipe(std::move(channel)); | |
1273 | |
1274 // Ensure that we can read and write on the new pipe. | |
1275 VerifyEcho(pipe.get().value(), "goodbye"); | |
1276 } | |
1277 | |
1278 TEST_F(MultiprocessMessagePipeTest, BootstrapMessagePipeAsync) { | |
1279 // Tests that new cross-process message pipes can be created synchronously | |
1280 // using asynchronous negotiation over an arbitrary platform channel. | |
1281 RUN_CHILD_ON_PIPE(BootstrapMessagePipeAsyncClient, child) | |
1282 // Pass one end of a platform channel to the child. | |
1283 PlatformChannelPair platform_channel; | |
1284 MojoHandle client_channel_handle; | |
1285 EXPECT_EQ(MOJO_RESULT_OK, | |
1286 CreatePlatformHandleWrapper(platform_channel.PassClientHandle(), | |
1287 &client_channel_handle)); | |
1288 WriteMessageWithHandles(child, "hi", &client_channel_handle, 1); | |
1289 | |
1290 // Create a new pipe using our end of the channel. | |
1291 ScopedMessagePipeHandle pipe = | |
1292 edk::CreateMessagePipe(platform_channel.PassServerHandle()); | |
1293 | |
1294 // Ensure that we can read and write on the new pipe. | |
1295 VerifyEcho(pipe.get().value(), "goodbye"); | |
1296 END_CHILD() | |
1297 } | |
1298 | |
1299 DEFINE_TEST_CLIENT_TEST_WITH_PIPE(MessagePipeStatusChangeInTransitClient, | 1261 DEFINE_TEST_CLIENT_TEST_WITH_PIPE(MessagePipeStatusChangeInTransitClient, |
1300 MultiprocessMessagePipeTest, parent) { | 1262 MultiprocessMessagePipeTest, parent) { |
1301 // This test verifies that peer closure is detectable through various | 1263 // This test verifies that peer closure is detectable through various |
1302 // mechanisms when it races with handle transfer. | 1264 // mechanisms when it races with handle transfer. |
1303 MojoHandle handles[4]; | 1265 MojoHandle handles[4]; |
1304 EXPECT_EQ("o_O", ReadMessageWithHandles(parent, handles, 4)); | 1266 EXPECT_EQ("o_O", ReadMessageWithHandles(parent, handles, 4)); |
1305 | 1267 |
1306 // Wait on handle 0 using MojoWait. | 1268 // Wait on handle 0 using MojoWait. |
1307 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(handles[0], MOJO_HANDLE_SIGNAL_PEER_CLOSED, | 1269 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(handles[0], MOJO_HANDLE_SIGNAL_PEER_CLOSED, |
1308 MOJO_DEADLINE_INDEFINITE, nullptr)); | 1270 MOJO_DEADLINE_INDEFINITE, nullptr)); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1421 INSTANTIATE_TEST_CASE_P( | 1383 INSTANTIATE_TEST_CASE_P( |
1422 , | 1384 , |
1423 MultiprocessMessagePipeTestWithPeerSupport, | 1385 MultiprocessMessagePipeTestWithPeerSupport, |
1424 testing::Values(test::MojoTestBase::LaunchType::CHILD, | 1386 testing::Values(test::MojoTestBase::LaunchType::CHILD, |
1425 test::MojoTestBase::LaunchType::PEER, | 1387 test::MojoTestBase::LaunchType::PEER, |
1426 test::MojoTestBase::LaunchType::NAMED_CHILD, | 1388 test::MojoTestBase::LaunchType::NAMED_CHILD, |
1427 test::MojoTestBase::LaunchType::NAMED_PEER)); | 1389 test::MojoTestBase::LaunchType::NAMED_PEER)); |
1428 } // namespace | 1390 } // namespace |
1429 } // namespace edk | 1391 } // namespace edk |
1430 } // namespace mojo | 1392 } // namespace mojo |
OLD | NEW |