| 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 <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 <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 14 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
| 15 #include "base/files/scoped_file.h" | 15 #include "base/files/scoped_file.h" |
| 16 #include "base/files/scoped_temp_dir.h" | 16 #include "base/files/scoped_temp_dir.h" |
| 17 #include "base/location.h" | 17 #include "base/location.h" |
| 18 #include "base/logging.h" | 18 #include "base/logging.h" |
| 19 #include "base/test/test_io_thread.h" | 19 #include "build/build_config.h" |
| 20 #include "build/build_config.h" // TODO(vtl): Remove this. | |
| 21 #include "mojo/edk/embedder/embedder.h" | 20 #include "mojo/edk/embedder/embedder.h" |
| 22 #include "mojo/edk/embedder/platform_channel_pair.h" | 21 #include "mojo/edk/embedder/platform_channel_pair.h" |
| 23 #include "mojo/edk/embedder/platform_shared_buffer.h" | 22 #include "mojo/edk/embedder/platform_shared_buffer.h" |
| 24 #include "mojo/edk/embedder/scoped_platform_handle.h" | 23 #include "mojo/edk/embedder/scoped_platform_handle.h" |
| 25 #include "mojo/edk/system/dispatcher.h" | 24 #include "mojo/edk/system/dispatcher.h" |
| 26 #include "mojo/edk/system/message_pipe_test_utils.h" | 25 #include "mojo/edk/system/message_pipe_test_utils.h" |
| 27 #include "mojo/edk/system/platform_handle_dispatcher.h" | 26 #include "mojo/edk/system/platform_handle_dispatcher.h" |
| 28 #include "mojo/edk/system/raw_channel.h" | 27 #include "mojo/edk/system/raw_channel.h" |
| 29 #include "mojo/edk/system/shared_buffer_dispatcher.h" | 28 #include "mojo/edk/system/shared_buffer_dispatcher.h" |
| 30 #include "mojo/edk/system/test_utils.h" | 29 #include "mojo/edk/system/test_utils.h" |
| 31 #include "mojo/edk/test/test_utils.h" | 30 #include "mojo/edk/test/test_utils.h" |
| 32 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
| 33 | 32 |
| 34 | 33 |
| 35 namespace mojo { | 34 namespace mojo { |
| 36 namespace edk { | 35 namespace edk { |
| 37 namespace { | 36 namespace { |
| 38 | 37 |
| 39 class MultiprocessMessagePipeTest | 38 class MultiprocessMessagePipeTest |
| 40 : public test::MultiprocessMessagePipeTestBase {}; | 39 : public test::MultiprocessMessagePipeTestBase {}; |
| 41 | 40 |
| 42 // For each message received, sends a reply message with the same contents | 41 // For each message received, sends a reply message with the same contents |
| 43 // repeated twice, until the other end is closed or it receives "quitquitquit" | 42 // repeated twice, until the other end is closed or it receives "quitquitquit" |
| 44 // (which it doesn't reply to). It'll return the number of messages received, | 43 // (which it doesn't reply to). It'll return the number of messages received, |
| 45 // not including any "quitquitquit" message, modulo 100. | 44 // not including any "quitquitquit" message, modulo 100. |
| 46 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(EchoEcho) { | 45 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(EchoEcho) { |
| 47 SimplePlatformSupport platform_support; | |
| 48 base::MessageLoop message_loop; | |
| 49 base::TestIOThread test_io_thread(base::TestIOThread::kAutoStart); | |
| 50 test::ScopedIPCSupport ipc_support(test_io_thread.task_runner()); | |
| 51 | |
| 52 ScopedPlatformHandle client_platform_handle = | 46 ScopedPlatformHandle client_platform_handle = |
| 53 test::MultiprocessTestHelper::client_platform_handle.Pass(); | 47 test::MultiprocessTestHelper::client_platform_handle.Pass(); |
| 54 CHECK(client_platform_handle.is_valid()); | 48 CHECK(client_platform_handle.is_valid()); |
| 55 ScopedMessagePipeHandle mp = | 49 ScopedMessagePipeHandle mp = |
| 56 CreateMessagePipe(client_platform_handle.Pass()); | 50 CreateMessagePipe(client_platform_handle.Pass()); |
| 57 | 51 |
| 58 const std::string quitquitquit("quitquitquit"); | 52 const std::string quitquitquit("quitquitquit"); |
| 59 int rv = 0; | 53 int rv = 0; |
| 60 for (;; rv = (rv + 1) % 100) { | 54 for (;; rv = (rv + 1) % 100) { |
| 61 // Wait for our end of the message pipe to be readable. | 55 // Wait for our end of the message pipe to be readable. |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 MojoWait(mp.get().value(), MOJO_HANDLE_SIGNAL_READABLE, | 195 MojoWait(mp.get().value(), MOJO_HANDLE_SIGNAL_READABLE, |
| 202 MOJO_DEADLINE_INDEFINITE, &hss)); | 196 MOJO_DEADLINE_INDEFINITE, &hss)); |
| 203 ASSERT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfied_signals); | 197 ASSERT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfied_signals); |
| 204 ASSERT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfiable_signals); | 198 ASSERT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfiable_signals); |
| 205 | 199 |
| 206 ASSERT_EQ(static_cast<int>(kNumMessages % 100), | 200 ASSERT_EQ(static_cast<int>(kNumMessages % 100), |
| 207 helper()->WaitForChildShutdown()); | 201 helper()->WaitForChildShutdown()); |
| 208 } | 202 } |
| 209 | 203 |
| 210 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(CheckSharedBuffer) { | 204 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(CheckSharedBuffer) { |
| 211 SimplePlatformSupport platform_support; | |
| 212 base::MessageLoop message_loop; | |
| 213 base::TestIOThread test_io_thread(base::TestIOThread::kAutoStart); | |
| 214 test::ScopedIPCSupport ipc_support(test_io_thread.task_runner()); | |
| 215 | |
| 216 ScopedPlatformHandle client_platform_handle = | 205 ScopedPlatformHandle client_platform_handle = |
| 217 test::MultiprocessTestHelper::client_platform_handle.Pass(); | 206 test::MultiprocessTestHelper::client_platform_handle.Pass(); |
| 218 CHECK(client_platform_handle.is_valid()); | 207 CHECK(client_platform_handle.is_valid()); |
| 219 ScopedMessagePipeHandle mp = | 208 ScopedMessagePipeHandle mp = |
| 220 CreateMessagePipe(client_platform_handle.Pass()); | 209 CreateMessagePipe(client_platform_handle.Pass()); |
| 221 | 210 |
| 222 // Wait for the first message from our parent. | 211 // Wait for the first message from our parent. |
| 223 HandleSignalsState hss; | 212 HandleSignalsState hss; |
| 224 CHECK_EQ(MojoWait(mp.get().value(), MOJO_HANDLE_SIGNAL_READABLE, | 213 CHECK_EQ(MojoWait(mp.get().value(), MOJO_HANDLE_SIGNAL_READABLE, |
| 225 MOJO_DEADLINE_INDEFINITE, &hss), | 214 MOJO_DEADLINE_INDEFINITE, &hss), |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 MOJO_DEADLINE_INDEFINITE, &hss)); | 364 MOJO_DEADLINE_INDEFINITE, &hss)); |
| 376 ASSERT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfied_signals); | 365 ASSERT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfied_signals); |
| 377 ASSERT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfiable_signals); | 366 ASSERT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfiable_signals); |
| 378 | 367 |
| 379 MojoClose(mp.release().value()); | 368 MojoClose(mp.release().value()); |
| 380 | 369 |
| 381 ASSERT_EQ(0, helper()->WaitForChildShutdown()); | 370 ASSERT_EQ(0, helper()->WaitForChildShutdown()); |
| 382 } | 371 } |
| 383 | 372 |
| 384 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(CheckPlatformHandleFile) { | 373 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(CheckPlatformHandleFile) { |
| 385 SimplePlatformSupport platform_support; | |
| 386 base::MessageLoop message_loop; | |
| 387 base::TestIOThread test_io_thread(base::TestIOThread::kAutoStart); | |
| 388 test::ScopedIPCSupport ipc_support(test_io_thread.task_runner()); | |
| 389 | |
| 390 ScopedPlatformHandle client_platform_handle = | 374 ScopedPlatformHandle client_platform_handle = |
| 391 test::MultiprocessTestHelper::client_platform_handle.Pass(); | 375 test::MultiprocessTestHelper::client_platform_handle.Pass(); |
| 392 CHECK(client_platform_handle.is_valid()); | 376 CHECK(client_platform_handle.is_valid()); |
| 393 ScopedMessagePipeHandle mp = | 377 ScopedMessagePipeHandle mp = |
| 394 CreateMessagePipe(client_platform_handle.Pass()); | 378 CreateMessagePipe(client_platform_handle.Pass()); |
| 395 | 379 |
| 396 HandleSignalsState hss; | 380 HandleSignalsState hss; |
| 397 CHECK_EQ(MojoWait(mp.get().value(), MOJO_HANDLE_SIGNAL_READABLE, | 381 CHECK_EQ(MojoWait(mp.get().value(), MOJO_HANDLE_SIGNAL_READABLE, |
| 398 MOJO_DEADLINE_INDEFINITE, &hss), | 382 MOJO_DEADLINE_INDEFINITE, &hss), |
| 399 MOJO_RESULT_OK); | 383 MOJO_RESULT_OK); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 } | 478 } |
| 495 | 479 |
| 496 // Android multi-process tests are not executing the new process. This is flaky. | 480 // Android multi-process tests are not executing the new process. This is flaky. |
| 497 #if !defined(OS_ANDROID) | 481 #if !defined(OS_ANDROID) |
| 498 INSTANTIATE_TEST_CASE_P(PipeCount, | 482 INSTANTIATE_TEST_CASE_P(PipeCount, |
| 499 MultiprocessMessagePipeTestWithPipeCount, | 483 MultiprocessMessagePipeTestWithPipeCount, |
| 500 testing::Values(1u, 128u, 140u)); | 484 testing::Values(1u, 128u, 140u)); |
| 501 #endif | 485 #endif |
| 502 | 486 |
| 503 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(CheckMessagePipe) { | 487 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(CheckMessagePipe) { |
| 504 SimplePlatformSupport platform_support; | |
| 505 base::MessageLoop message_loop; | |
| 506 base::TestIOThread test_io_thread(base::TestIOThread::kAutoStart); | |
| 507 test::ScopedIPCSupport ipc_support(test_io_thread.task_runner()); | |
| 508 | |
| 509 ScopedPlatformHandle client_platform_handle = | 488 ScopedPlatformHandle client_platform_handle = |
| 510 test::MultiprocessTestHelper::client_platform_handle.Pass(); | 489 test::MultiprocessTestHelper::client_platform_handle.Pass(); |
| 511 CHECK(client_platform_handle.is_valid()); | 490 CHECK(client_platform_handle.is_valid()); |
| 512 | 491 |
| 513 ScopedMessagePipeHandle mp = | 492 ScopedMessagePipeHandle mp = |
| 514 CreateMessagePipe(client_platform_handle.Pass()); | 493 CreateMessagePipe(client_platform_handle.Pass()); |
| 515 | 494 |
| 516 // Wait for the first message from our parent. | 495 // Wait for the first message from our parent. |
| 517 HandleSignalsState hss; | 496 HandleSignalsState hss; |
| 518 CHECK_EQ(MojoWait(mp.get().value(), MOJO_HANDLE_SIGNAL_READABLE, | 497 CHECK_EQ(MojoWait(mp.get().value(), MOJO_HANDLE_SIGNAL_READABLE, |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 659 MOJO_RESULT_OK); | 638 MOJO_RESULT_OK); |
| 660 read_buffer.resize(read_buffer_size); | 639 read_buffer.resize(read_buffer_size); |
| 661 CHECK_EQ(read_buffer, std::string("world")); | 640 CHECK_EQ(read_buffer, std::string("world")); |
| 662 | 641 |
| 663 MojoClose(mp.release().value()); | 642 MojoClose(mp.release().value()); |
| 664 | 643 |
| 665 ASSERT_EQ(0, helper()->WaitForChildShutdown()); | 644 ASSERT_EQ(0, helper()->WaitForChildShutdown()); |
| 666 } | 645 } |
| 667 | 646 |
| 668 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(DataPipeConsumer) { | 647 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(DataPipeConsumer) { |
| 669 SimplePlatformSupport platform_support; | |
| 670 base::MessageLoop message_loop; | |
| 671 base::TestIOThread test_io_thread(base::TestIOThread::kAutoStart); | |
| 672 test::ScopedIPCSupport ipc_support(test_io_thread.task_runner()); | |
| 673 | |
| 674 ScopedPlatformHandle client_platform_handle = | 648 ScopedPlatformHandle client_platform_handle = |
| 675 test::MultiprocessTestHelper::client_platform_handle.Pass(); | 649 test::MultiprocessTestHelper::client_platform_handle.Pass(); |
| 676 CHECK(client_platform_handle.is_valid()); | 650 CHECK(client_platform_handle.is_valid()); |
| 677 | 651 |
| 678 ScopedMessagePipeHandle mp = | 652 ScopedMessagePipeHandle mp = |
| 679 CreateMessagePipe(client_platform_handle.Pass()); | 653 CreateMessagePipe(client_platform_handle.Pass()); |
| 680 | 654 |
| 681 // Wait for the first message from our parent. | 655 // Wait for the first message from our parent. |
| 682 HandleSignalsState hss; | 656 HandleSignalsState hss; |
| 683 CHECK_EQ(MojoWait(mp.get().value(), MOJO_HANDLE_SIGNAL_READABLE, | 657 CHECK_EQ(MojoWait(mp.get().value(), MOJO_HANDLE_SIGNAL_READABLE, |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 777 | 751 |
| 778 MojoClose(mp1); | 752 MojoClose(mp1); |
| 779 MojoClose(mp.release().value()); | 753 MojoClose(mp.release().value()); |
| 780 | 754 |
| 781 ASSERT_EQ(0, helper()->WaitForChildShutdown()); | 755 ASSERT_EQ(0, helper()->WaitForChildShutdown()); |
| 782 } | 756 } |
| 783 | 757 |
| 784 } // namespace | 758 } // namespace |
| 785 } // namespace edk | 759 } // namespace edk |
| 786 } // namespace mojo | 760 } // namespace mojo |
| OLD | NEW |