| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "mojo/edk/embedder/multiprocess_embedder.h" | 5 #include "mojo/edk/embedder/multiprocess_embedder.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "mojo/edk/embedder/platform_channel_pair.h" | |
| 13 #include "mojo/edk/embedder/test_embedder.h" | 12 #include "mojo/edk/embedder/test_embedder.h" |
| 13 #include "mojo/edk/platform/platform_pipe.h" |
| 14 #include "mojo/edk/system/test/test_command_line.h" | 14 #include "mojo/edk/system/test/test_command_line.h" |
| 15 #include "mojo/edk/system/test/test_io_thread.h" | 15 #include "mojo/edk/system/test/test_io_thread.h" |
| 16 #include "mojo/edk/system/test/timeouts.h" | 16 #include "mojo/edk/system/test/timeouts.h" |
| 17 #include "mojo/edk/test/multiprocess_test_helper.h" | 17 #include "mojo/edk/test/multiprocess_test_helper.h" |
| 18 #include "mojo/edk/test/scoped_ipc_support.h" | 18 #include "mojo/edk/test/scoped_ipc_support.h" |
| 19 #include "mojo/edk/util/command_line.h" | 19 #include "mojo/edk/util/command_line.h" |
| 20 #include "mojo/edk/util/ref_ptr.h" | 20 #include "mojo/edk/util/ref_ptr.h" |
| 21 #include "mojo/edk/util/waitable_event.h" | 21 #include "mojo/edk/util/waitable_event.h" |
| 22 #include "mojo/public/c/system/functions.h" | 22 #include "mojo/public/c/system/functions.h" |
| 23 #include "mojo/public/c/system/types.h" | 23 #include "mojo/public/c/system/types.h" |
| 24 #include "mojo/public/cpp/system/handle.h" | 24 #include "mojo/public/cpp/system/handle.h" |
| 25 #include "mojo/public/cpp/system/macros.h" | 25 #include "mojo/public/cpp/system/macros.h" |
| 26 #include "mojo/public/cpp/system/message_pipe.h" | 26 #include "mojo/public/cpp/system/message_pipe.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| 28 | 28 |
| 29 using mojo::platform::PlatformHandleWatcher; | 29 using mojo::platform::PlatformHandleWatcher; |
| 30 using mojo::platform::PlatformPipe; |
| 30 using mojo::platform::ScopedPlatformHandle; | 31 using mojo::platform::ScopedPlatformHandle; |
| 31 using mojo::platform::TaskRunner; | 32 using mojo::platform::TaskRunner; |
| 32 using mojo::system::test::TestIOThread; | 33 using mojo::system::test::TestIOThread; |
| 33 using mojo::util::ManualResetWaitableEvent; | 34 using mojo::util::ManualResetWaitableEvent; |
| 34 using mojo::util::RefPtr; | 35 using mojo::util::RefPtr; |
| 35 | 36 |
| 36 namespace mojo { | 37 namespace mojo { |
| 37 namespace embedder { | 38 namespace embedder { |
| 38 namespace { | 39 namespace { |
| 39 | 40 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 | 141 |
| 141 TestIOThread test_io_thread_; | 142 TestIOThread test_io_thread_; |
| 142 | 143 |
| 143 MOJO_DISALLOW_COPY_AND_ASSIGN(MultiprocessEmbedderTest); | 144 MOJO_DISALLOW_COPY_AND_ASSIGN(MultiprocessEmbedderTest); |
| 144 }; | 145 }; |
| 145 | 146 |
| 146 TEST_F(MultiprocessEmbedderTest, ChannelsBasic) { | 147 TEST_F(MultiprocessEmbedderTest, ChannelsBasic) { |
| 147 mojo::test::ScopedIPCSupport ipc_support(test_io_task_runner().Clone(), | 148 mojo::test::ScopedIPCSupport ipc_support(test_io_task_runner().Clone(), |
| 148 test_io_watcher()); | 149 test_io_watcher()); |
| 149 | 150 |
| 150 PlatformChannelPair channel_pair; | 151 PlatformPipe channel_pair; |
| 151 ScopedTestChannel server_channel(channel_pair.handle0.Pass()); | 152 ScopedTestChannel server_channel(channel_pair.handle0.Pass()); |
| 152 MojoHandle server_mp = server_channel.bootstrap_message_pipe(); | 153 MojoHandle server_mp = server_channel.bootstrap_message_pipe(); |
| 153 EXPECT_NE(server_mp, MOJO_HANDLE_INVALID); | 154 EXPECT_NE(server_mp, MOJO_HANDLE_INVALID); |
| 154 ScopedTestChannel client_channel(channel_pair.handle1.Pass()); | 155 ScopedTestChannel client_channel(channel_pair.handle1.Pass()); |
| 155 MojoHandle client_mp = client_channel.bootstrap_message_pipe(); | 156 MojoHandle client_mp = client_channel.bootstrap_message_pipe(); |
| 156 EXPECT_NE(client_mp, MOJO_HANDLE_INVALID); | 157 EXPECT_NE(client_mp, MOJO_HANDLE_INVALID); |
| 157 | 158 |
| 158 // We can write to a message pipe handle immediately. | 159 // We can write to a message pipe handle immediately. |
| 159 const char kHello[] = "hello"; | 160 const char kHello[] = "hello"; |
| 160 EXPECT_EQ( | 161 EXPECT_EQ( |
| (...skipping 25 matching lines...) Expand all Loading... |
| 186 server_channel.WaitForChannelCreationCompletion(); | 187 server_channel.WaitForChannelCreationCompletion(); |
| 187 client_channel.WaitForChannelCreationCompletion(); | 188 client_channel.WaitForChannelCreationCompletion(); |
| 188 EXPECT_TRUE(server_channel.channel_info()); | 189 EXPECT_TRUE(server_channel.channel_info()); |
| 189 EXPECT_TRUE(client_channel.channel_info()); | 190 EXPECT_TRUE(client_channel.channel_info()); |
| 190 } | 191 } |
| 191 | 192 |
| 192 TEST_F(MultiprocessEmbedderTest, ChannelsHandlePassing) { | 193 TEST_F(MultiprocessEmbedderTest, ChannelsHandlePassing) { |
| 193 mojo::test::ScopedIPCSupport ipc_support(test_io_task_runner().Clone(), | 194 mojo::test::ScopedIPCSupport ipc_support(test_io_task_runner().Clone(), |
| 194 test_io_watcher()); | 195 test_io_watcher()); |
| 195 | 196 |
| 196 PlatformChannelPair channel_pair; | 197 PlatformPipe channel_pair; |
| 197 ScopedTestChannel server_channel(channel_pair.handle0.Pass()); | 198 ScopedTestChannel server_channel(channel_pair.handle0.Pass()); |
| 198 MojoHandle server_mp = server_channel.bootstrap_message_pipe(); | 199 MojoHandle server_mp = server_channel.bootstrap_message_pipe(); |
| 199 EXPECT_NE(server_mp, MOJO_HANDLE_INVALID); | 200 EXPECT_NE(server_mp, MOJO_HANDLE_INVALID); |
| 200 ScopedTestChannel client_channel(channel_pair.handle1.Pass()); | 201 ScopedTestChannel client_channel(channel_pair.handle1.Pass()); |
| 201 MojoHandle client_mp = client_channel.bootstrap_message_pipe(); | 202 MojoHandle client_mp = client_channel.bootstrap_message_pipe(); |
| 202 EXPECT_NE(client_mp, MOJO_HANDLE_INVALID); | 203 EXPECT_NE(client_mp, MOJO_HANDLE_INVALID); |
| 203 | 204 |
| 204 MojoHandle h0, h1; | 205 MojoHandle h0, h1; |
| 205 EXPECT_EQ(MOJO_RESULT_OK, MojoCreateMessagePipe(nullptr, &h0, &h1)); | 206 EXPECT_EQ(MOJO_RESULT_OK, MojoCreateMessagePipe(nullptr, &h0, &h1)); |
| 206 | 207 |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 test_io_thread().PostTaskAndWait( | 362 test_io_thread().PostTaskAndWait( |
| 362 [channel_info]() { DestroyChannelOnIOThread(channel_info); }); | 363 [channel_info]() { DestroyChannelOnIOThread(channel_info); }); |
| 363 } | 364 } |
| 364 | 365 |
| 365 TEST_F(MultiprocessEmbedderTest, ChannelShutdownRace_MessagePipeClose) { | 366 TEST_F(MultiprocessEmbedderTest, ChannelShutdownRace_MessagePipeClose) { |
| 366 const size_t kIterations = 1000; | 367 const size_t kIterations = 1000; |
| 367 mojo::test::ScopedIPCSupport ipc_support(test_io_task_runner().Clone(), | 368 mojo::test::ScopedIPCSupport ipc_support(test_io_task_runner().Clone(), |
| 368 test_io_watcher()); | 369 test_io_watcher()); |
| 369 | 370 |
| 370 for (size_t i = 0; i < kIterations; i++) { | 371 for (size_t i = 0; i < kIterations; i++) { |
| 371 PlatformChannelPair channel_pair; | 372 PlatformPipe channel_pair; |
| 372 std::unique_ptr<ScopedTestChannel> server_channel( | 373 std::unique_ptr<ScopedTestChannel> server_channel( |
| 373 new ScopedTestChannel(channel_pair.handle0.Pass())); | 374 new ScopedTestChannel(channel_pair.handle0.Pass())); |
| 374 server_channel->WaitForChannelCreationCompletion(); | 375 server_channel->WaitForChannelCreationCompletion(); |
| 375 server_channel->NoWaitOnShutdown(); | 376 server_channel->NoWaitOnShutdown(); |
| 376 | 377 |
| 377 MojoHandle server_mp = server_channel->bootstrap_message_pipe(); | 378 MojoHandle server_mp = server_channel->bootstrap_message_pipe(); |
| 378 EXPECT_NE(server_mp, MOJO_HANDLE_INVALID); | 379 EXPECT_NE(server_mp, MOJO_HANDLE_INVALID); |
| 379 | 380 |
| 380 // Race between channel shutdown and closing a message pipe. The message | 381 // Race between channel shutdown and closing a message pipe. The message |
| 381 // pipe doesn't have to be the bootstrap pipe. It just has to be bound to | 382 // pipe doesn't have to be the bootstrap pipe. It just has to be bound to |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 | 699 |
| 699 EXPECT_TRUE(test::Shutdown()); | 700 EXPECT_TRUE(test::Shutdown()); |
| 700 } | 701 } |
| 701 | 702 |
| 702 // TODO(vtl): Test immediate write & close. | 703 // TODO(vtl): Test immediate write & close. |
| 703 // TODO(vtl): Test broken-connection cases. | 704 // TODO(vtl): Test broken-connection cases. |
| 704 | 705 |
| 705 } // namespace | 706 } // namespace |
| 706 } // namespace embedder | 707 } // namespace embedder |
| 707 } // namespace mojo | 708 } // namespace mojo |
| OLD | NEW |