| 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 14 matching lines...) Expand all Loading... |
| 25 #include "mojo/edk/embedder/platform_channel_pair.h" | 25 #include "mojo/edk/embedder/platform_channel_pair.h" |
| 26 #include "mojo/edk/embedder/scoped_platform_handle.h" | 26 #include "mojo/edk/embedder/scoped_platform_handle.h" |
| 27 #include "mojo/edk/system/handle_signals_state.h" | 27 #include "mojo/edk/system/handle_signals_state.h" |
| 28 #include "mojo/edk/system/test_utils.h" | 28 #include "mojo/edk/system/test_utils.h" |
| 29 #include "mojo/edk/test/mojo_test_base.h" | 29 #include "mojo/edk/test/mojo_test_base.h" |
| 30 #include "mojo/edk/test/test_utils.h" | 30 #include "mojo/edk/test/test_utils.h" |
| 31 #include "mojo/public/c/system/buffer.h" | 31 #include "mojo/public/c/system/buffer.h" |
| 32 #include "mojo/public/c/system/functions.h" | 32 #include "mojo/public/c/system/functions.h" |
| 33 #include "mojo/public/c/system/types.h" | 33 #include "mojo/public/c/system/types.h" |
| 34 #include "mojo/public/cpp/system/simple_watcher.h" | 34 #include "mojo/public/cpp/system/simple_watcher.h" |
| 35 #include "mojo/public/cpp/system/wait.h" |
| 35 #include "testing/gtest/include/gtest/gtest.h" | 36 #include "testing/gtest/include/gtest/gtest.h" |
| 36 | 37 |
| 37 | 38 |
| 38 namespace mojo { | 39 namespace mojo { |
| 39 namespace edk { | 40 namespace edk { |
| 40 namespace { | 41 namespace { |
| 41 | 42 |
| 42 class MultiprocessMessagePipeTest : public test::MojoTestBase { | 43 class MultiprocessMessagePipeTest : public test::MojoTestBase { |
| 43 protected: | 44 protected: |
| 44 // Convenience class for tests which will control command-driven children. | 45 // Convenience class for tests which will control command-driven children. |
| (...skipping 725 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 770 CloseHandle(p0); | 771 CloseHandle(p0); |
| 771 } | 772 } |
| 772 | 773 |
| 773 // Receives a pipe handle from the primordial channel and reads new handles | 774 // Receives a pipe handle from the primordial channel and reads new handles |
| 774 // from it. Each read handle establishes a new echo channel. | 775 // from it. Each read handle establishes a new echo channel. |
| 775 DEFINE_TEST_CLIENT_WITH_PIPE(EchoServiceFactoryClient, | 776 DEFINE_TEST_CLIENT_WITH_PIPE(EchoServiceFactoryClient, |
| 776 MultiprocessMessagePipeTest, h) { | 777 MultiprocessMessagePipeTest, h) { |
| 777 MojoHandle p; | 778 MojoHandle p; |
| 778 ReadMessageWithHandles(h, &p, 1); | 779 ReadMessageWithHandles(h, &p, 1); |
| 779 | 780 |
| 780 std::vector<MojoHandle> handles(2); | 781 std::vector<Handle> handles(2); |
| 781 handles[0] = h; | 782 handles[0] = Handle(h); |
| 782 handles[1] = p; | 783 handles[1] = Handle(p); |
| 783 std::vector<MojoHandleSignals> signals(2, MOJO_HANDLE_SIGNAL_READABLE); | 784 std::vector<MojoHandleSignals> signals(2, MOJO_HANDLE_SIGNAL_READABLE); |
| 784 for (;;) { | 785 for (;;) { |
| 785 uint32_t index; | 786 size_t index; |
| 786 CHECK_EQ(MojoWaitMany(handles.data(), signals.data(), | 787 CHECK_EQ( |
| 787 static_cast<uint32_t>(handles.size()), | 788 mojo::WaitMany(handles.data(), signals.data(), handles.size(), &index), |
| 788 MOJO_DEADLINE_INDEFINITE, &index, nullptr), | 789 MOJO_RESULT_OK); |
| 789 MOJO_RESULT_OK); | |
| 790 DCHECK_LE(index, handles.size()); | 790 DCHECK_LE(index, handles.size()); |
| 791 if (index == 0) { | 791 if (index == 0) { |
| 792 // If data is available on the first pipe, it should be an exit command. | 792 // If data is available on the first pipe, it should be an exit command. |
| 793 EXPECT_EQ(std::string("exit"), ReadMessage(h)); | 793 EXPECT_EQ(std::string("exit"), ReadMessage(h)); |
| 794 break; | 794 break; |
| 795 } else if (index == 1) { | 795 } else if (index == 1) { |
| 796 // If the second pipe, it should be a new handle requesting echo service. | 796 // If the second pipe, it should be a new handle requesting echo service. |
| 797 MojoHandle echo_request; | 797 MojoHandle echo_request; |
| 798 ReadMessageWithHandles(p, &echo_request, 1); | 798 ReadMessageWithHandles(p, &echo_request, 1); |
| 799 handles.push_back(echo_request); | 799 handles.push_back(Handle(echo_request)); |
| 800 signals.push_back(MOJO_HANDLE_SIGNAL_READABLE); | 800 signals.push_back(MOJO_HANDLE_SIGNAL_READABLE); |
| 801 } else { | 801 } else { |
| 802 // Otherwise it was one of our established echo pipes. Echo! | 802 // Otherwise it was one of our established echo pipes. Echo! |
| 803 WriteMessage(handles[index], ReadMessage(handles[index])); | 803 WriteMessage(handles[index].value(), ReadMessage(handles[index].value())); |
| 804 } | 804 } |
| 805 } | 805 } |
| 806 | 806 |
| 807 for (size_t i = 1; i < handles.size(); ++i) | 807 for (size_t i = 1; i < handles.size(); ++i) |
| 808 CloseHandle(handles[i]); | 808 CloseHandle(handles[i].value()); |
| 809 | 809 |
| 810 return 0; | 810 return 0; |
| 811 } | 811 } |
| 812 | 812 |
| 813 TEST_P(MultiprocessMessagePipeTestWithPeerSupport, | 813 TEST_P(MultiprocessMessagePipeTestWithPeerSupport, |
| 814 PassMoarMessagePipesCrossProcess) { | 814 PassMoarMessagePipesCrossProcess) { |
| 815 MojoHandle echo_factory_proxy, echo_factory_request; | 815 MojoHandle echo_factory_proxy, echo_factory_request; |
| 816 CreateMessagePipe(&echo_factory_proxy, &echo_factory_request); | 816 CreateMessagePipe(&echo_factory_proxy, &echo_factory_request); |
| 817 | 817 |
| 818 MojoHandle echo_proxy_a, echo_request_a; | 818 MojoHandle echo_proxy_a, echo_request_a; |
| (...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1357 INSTANTIATE_TEST_CASE_P( | 1357 INSTANTIATE_TEST_CASE_P( |
| 1358 , | 1358 , |
| 1359 MultiprocessMessagePipeTestWithPeerSupport, | 1359 MultiprocessMessagePipeTestWithPeerSupport, |
| 1360 testing::Values(test::MojoTestBase::LaunchType::CHILD, | 1360 testing::Values(test::MojoTestBase::LaunchType::CHILD, |
| 1361 test::MojoTestBase::LaunchType::PEER, | 1361 test::MojoTestBase::LaunchType::PEER, |
| 1362 test::MojoTestBase::LaunchType::NAMED_CHILD, | 1362 test::MojoTestBase::LaunchType::NAMED_CHILD, |
| 1363 test::MojoTestBase::LaunchType::NAMED_PEER)); | 1363 test::MojoTestBase::LaunchType::NAMED_PEER)); |
| 1364 } // namespace | 1364 } // namespace |
| 1365 } // namespace edk | 1365 } // namespace edk |
| 1366 } // namespace mojo | 1366 } // namespace mojo |
| OLD | NEW |