| 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 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 TestIOThread test_io_thread_; | 141 TestIOThread test_io_thread_; |
| 142 | 142 |
| 143 MOJO_DISALLOW_COPY_AND_ASSIGN(MultiprocessEmbedderTest); | 143 MOJO_DISALLOW_COPY_AND_ASSIGN(MultiprocessEmbedderTest); |
| 144 }; | 144 }; |
| 145 | 145 |
| 146 TEST_F(MultiprocessEmbedderTest, ChannelsBasic) { | 146 TEST_F(MultiprocessEmbedderTest, ChannelsBasic) { |
| 147 mojo::test::ScopedIPCSupport ipc_support(test_io_task_runner().Clone(), | 147 mojo::test::ScopedIPCSupport ipc_support(test_io_task_runner().Clone(), |
| 148 test_io_watcher()); | 148 test_io_watcher()); |
| 149 | 149 |
| 150 PlatformChannelPair channel_pair; | 150 PlatformChannelPair channel_pair; |
| 151 ScopedTestChannel server_channel(channel_pair.PassServerHandle()); | 151 ScopedTestChannel server_channel(channel_pair.handle0.Pass()); |
| 152 MojoHandle server_mp = server_channel.bootstrap_message_pipe(); | 152 MojoHandle server_mp = server_channel.bootstrap_message_pipe(); |
| 153 EXPECT_NE(server_mp, MOJO_HANDLE_INVALID); | 153 EXPECT_NE(server_mp, MOJO_HANDLE_INVALID); |
| 154 ScopedTestChannel client_channel(channel_pair.PassClientHandle()); | 154 ScopedTestChannel client_channel(channel_pair.handle1.Pass()); |
| 155 MojoHandle client_mp = client_channel.bootstrap_message_pipe(); | 155 MojoHandle client_mp = client_channel.bootstrap_message_pipe(); |
| 156 EXPECT_NE(client_mp, MOJO_HANDLE_INVALID); | 156 EXPECT_NE(client_mp, MOJO_HANDLE_INVALID); |
| 157 | 157 |
| 158 // We can write to a message pipe handle immediately. | 158 // We can write to a message pipe handle immediately. |
| 159 const char kHello[] = "hello"; | 159 const char kHello[] = "hello"; |
| 160 EXPECT_EQ( | 160 EXPECT_EQ( |
| 161 MOJO_RESULT_OK, | 161 MOJO_RESULT_OK, |
| 162 MojoWriteMessage(server_mp, kHello, static_cast<uint32_t>(sizeof(kHello)), | 162 MojoWriteMessage(server_mp, kHello, static_cast<uint32_t>(sizeof(kHello)), |
| 163 nullptr, 0, MOJO_WRITE_MESSAGE_FLAG_NONE)); | 163 nullptr, 0, MOJO_WRITE_MESSAGE_FLAG_NONE)); |
| 164 | 164 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 187 client_channel.WaitForChannelCreationCompletion(); | 187 client_channel.WaitForChannelCreationCompletion(); |
| 188 EXPECT_TRUE(server_channel.channel_info()); | 188 EXPECT_TRUE(server_channel.channel_info()); |
| 189 EXPECT_TRUE(client_channel.channel_info()); | 189 EXPECT_TRUE(client_channel.channel_info()); |
| 190 } | 190 } |
| 191 | 191 |
| 192 TEST_F(MultiprocessEmbedderTest, ChannelsHandlePassing) { | 192 TEST_F(MultiprocessEmbedderTest, ChannelsHandlePassing) { |
| 193 mojo::test::ScopedIPCSupport ipc_support(test_io_task_runner().Clone(), | 193 mojo::test::ScopedIPCSupport ipc_support(test_io_task_runner().Clone(), |
| 194 test_io_watcher()); | 194 test_io_watcher()); |
| 195 | 195 |
| 196 PlatformChannelPair channel_pair; | 196 PlatformChannelPair channel_pair; |
| 197 ScopedTestChannel server_channel(channel_pair.PassServerHandle()); | 197 ScopedTestChannel server_channel(channel_pair.handle0.Pass()); |
| 198 MojoHandle server_mp = server_channel.bootstrap_message_pipe(); | 198 MojoHandle server_mp = server_channel.bootstrap_message_pipe(); |
| 199 EXPECT_NE(server_mp, MOJO_HANDLE_INVALID); | 199 EXPECT_NE(server_mp, MOJO_HANDLE_INVALID); |
| 200 ScopedTestChannel client_channel(channel_pair.PassClientHandle()); | 200 ScopedTestChannel client_channel(channel_pair.handle1.Pass()); |
| 201 MojoHandle client_mp = client_channel.bootstrap_message_pipe(); | 201 MojoHandle client_mp = client_channel.bootstrap_message_pipe(); |
| 202 EXPECT_NE(client_mp, MOJO_HANDLE_INVALID); | 202 EXPECT_NE(client_mp, MOJO_HANDLE_INVALID); |
| 203 | 203 |
| 204 MojoHandle h0, h1; | 204 MojoHandle h0, h1; |
| 205 EXPECT_EQ(MOJO_RESULT_OK, MojoCreateMessagePipe(nullptr, &h0, &h1)); | 205 EXPECT_EQ(MOJO_RESULT_OK, MojoCreateMessagePipe(nullptr, &h0, &h1)); |
| 206 | 206 |
| 207 // Write a message to |h0| (attaching nothing). | 207 // Write a message to |h0| (attaching nothing). |
| 208 const char kHello[] = "hello"; | 208 const char kHello[] = "hello"; |
| 209 EXPECT_EQ(MOJO_RESULT_OK, | 209 EXPECT_EQ(MOJO_RESULT_OK, |
| 210 MojoWriteMessage(h0, kHello, static_cast<uint32_t>(sizeof(kHello)), | 210 MojoWriteMessage(h0, kHello, static_cast<uint32_t>(sizeof(kHello)), |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 } | 363 } |
| 364 | 364 |
| 365 TEST_F(MultiprocessEmbedderTest, ChannelShutdownRace_MessagePipeClose) { | 365 TEST_F(MultiprocessEmbedderTest, ChannelShutdownRace_MessagePipeClose) { |
| 366 const size_t kIterations = 1000; | 366 const size_t kIterations = 1000; |
| 367 mojo::test::ScopedIPCSupport ipc_support(test_io_task_runner().Clone(), | 367 mojo::test::ScopedIPCSupport ipc_support(test_io_task_runner().Clone(), |
| 368 test_io_watcher()); | 368 test_io_watcher()); |
| 369 | 369 |
| 370 for (size_t i = 0; i < kIterations; i++) { | 370 for (size_t i = 0; i < kIterations; i++) { |
| 371 PlatformChannelPair channel_pair; | 371 PlatformChannelPair channel_pair; |
| 372 std::unique_ptr<ScopedTestChannel> server_channel( | 372 std::unique_ptr<ScopedTestChannel> server_channel( |
| 373 new ScopedTestChannel(channel_pair.PassServerHandle())); | 373 new ScopedTestChannel(channel_pair.handle0.Pass())); |
| 374 server_channel->WaitForChannelCreationCompletion(); | 374 server_channel->WaitForChannelCreationCompletion(); |
| 375 server_channel->NoWaitOnShutdown(); | 375 server_channel->NoWaitOnShutdown(); |
| 376 | 376 |
| 377 MojoHandle server_mp = server_channel->bootstrap_message_pipe(); | 377 MojoHandle server_mp = server_channel->bootstrap_message_pipe(); |
| 378 EXPECT_NE(server_mp, MOJO_HANDLE_INVALID); | 378 EXPECT_NE(server_mp, MOJO_HANDLE_INVALID); |
| 379 | 379 |
| 380 // Race between channel shutdown and closing a message pipe. The message | 380 // 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 | 381 // pipe doesn't have to be the bootstrap pipe. It just has to be bound to |
| 382 // the channel. | 382 // the channel. |
| 383 server_channel.reset(); | 383 server_channel.reset(); |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 | 698 |
| 699 EXPECT_TRUE(test::Shutdown()); | 699 EXPECT_TRUE(test::Shutdown()); |
| 700 } | 700 } |
| 701 | 701 |
| 702 // TODO(vtl): Test immediate write & close. | 702 // TODO(vtl): Test immediate write & close. |
| 703 // TODO(vtl): Test broken-connection cases. | 703 // TODO(vtl): Test broken-connection cases. |
| 704 | 704 |
| 705 } // namespace | 705 } // namespace |
| 706 } // namespace embedder | 706 } // namespace embedder |
| 707 } // namespace mojo | 707 } // namespace mojo |
| OLD | NEW |