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/macros.h" | 19 #include "base/macros.h" |
20 #include "build/build_config.h" // TODO(vtl): Remove this. | 20 #include "build/build_config.h" // TODO(vtl): Remove this. |
21 #include "mojo/common/test/test_utils.h" | 21 #include "mojo/common/test/test_utils.h" |
22 #include "mojo/embedder/platform_shared_buffer.h" | 22 #include "mojo/embedder/platform_shared_buffer.h" |
23 #include "mojo/embedder/scoped_platform_handle.h" | 23 #include "mojo/embedder/scoped_platform_handle.h" |
24 #include "mojo/system/channel.h" | 24 #include "mojo/system/channel.h" |
25 #include "mojo/system/dispatcher.h" | 25 #include "mojo/system/dispatcher.h" |
26 #include "mojo/system/message_pipe.h" | 26 #include "mojo/system/message_pipe.h" |
27 #include "mojo/system/message_pipe_test_utils.h" | 27 #include "mojo/system/message_pipe_test_utils.h" |
28 #include "mojo/system/platform_handle_dispatcher.h" | 28 #include "mojo/system/platform_handle_dispatcher.h" |
29 #include "mojo/system/raw_channel.h" | 29 #include "mojo/system/raw_channel.h" |
30 #include "mojo/system/shared_buffer_dispatcher.h" | 30 #include "mojo/system/shared_buffer_dispatcher.h" |
(...skipping 10 matching lines...) Expand all Loading... |
41 // 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 |
42 // 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" |
43 // (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, |
44 // not including any "quitquitquit" message, modulo 100. | 44 // not including any "quitquitquit" message, modulo 100. |
45 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(EchoEcho) { | 45 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(EchoEcho) { |
46 embedder::SimplePlatformSupport platform_support; | 46 embedder::SimplePlatformSupport platform_support; |
47 test::ChannelThread channel_thread(&platform_support); | 47 test::ChannelThread channel_thread(&platform_support); |
48 embedder::ScopedPlatformHandle client_platform_handle = | 48 embedder::ScopedPlatformHandle client_platform_handle = |
49 mojo::test::MultiprocessTestHelper::client_platform_handle.Pass(); | 49 mojo::test::MultiprocessTestHelper::client_platform_handle.Pass(); |
50 CHECK(client_platform_handle.is_valid()); | 50 CHECK(client_platform_handle.is_valid()); |
51 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalProxy()); | 51 scoped_refptr<ChannelEndpoint> ep; |
52 channel_thread.Start(client_platform_handle.Pass(), mp); | 52 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalProxy(&ep)); |
| 53 channel_thread.Start(client_platform_handle.Pass(), ep); |
53 | 54 |
54 const std::string quitquitquit("quitquitquit"); | 55 const std::string quitquitquit("quitquitquit"); |
55 int rv = 0; | 56 int rv = 0; |
56 for (;; rv = (rv + 1) % 100) { | 57 for (;; rv = (rv + 1) % 100) { |
57 // Wait for our end of the message pipe to be readable. | 58 // Wait for our end of the message pipe to be readable. |
58 HandleSignalsState hss; | 59 HandleSignalsState hss; |
59 MojoResult result = | 60 MojoResult result = |
60 test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss); | 61 test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss); |
61 if (result != MOJO_RESULT_OK) { | 62 if (result != MOJO_RESULT_OK) { |
62 // It was closed, probably. | 63 // It was closed, probably. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 } | 97 } |
97 | 98 |
98 mp->Close(0); | 99 mp->Close(0); |
99 return rv; | 100 return rv; |
100 } | 101 } |
101 | 102 |
102 // Sends "hello" to child, and expects "hellohello" back. | 103 // Sends "hello" to child, and expects "hellohello" back. |
103 TEST_F(MultiprocessMessagePipeTest, Basic) { | 104 TEST_F(MultiprocessMessagePipeTest, Basic) { |
104 helper()->StartChild("EchoEcho"); | 105 helper()->StartChild("EchoEcho"); |
105 | 106 |
106 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalProxy()); | 107 scoped_refptr<ChannelEndpoint> ep; |
107 Init(mp); | 108 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalProxy(&ep)); |
| 109 Init(ep); |
108 | 110 |
109 std::string hello("hello"); | 111 std::string hello("hello"); |
110 EXPECT_EQ(MOJO_RESULT_OK, | 112 EXPECT_EQ(MOJO_RESULT_OK, |
111 mp->WriteMessage(0, | 113 mp->WriteMessage(0, |
112 UserPointer<const void>(hello.data()), | 114 UserPointer<const void>(hello.data()), |
113 static_cast<uint32_t>(hello.size()), | 115 static_cast<uint32_t>(hello.size()), |
114 NULL, | 116 NULL, |
115 MOJO_WRITE_MESSAGE_FLAG_NONE)); | 117 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
116 | 118 |
117 HandleSignalsState hss; | 119 HandleSignalsState hss; |
(...skipping 22 matching lines...) Expand all Loading... |
140 | 142 |
141 // We sent one message. | 143 // We sent one message. |
142 EXPECT_EQ(1 % 100, helper()->WaitForChildShutdown()); | 144 EXPECT_EQ(1 % 100, helper()->WaitForChildShutdown()); |
143 } | 145 } |
144 | 146 |
145 // Sends a bunch of messages to the child. Expects them "repeated" back. Waits | 147 // Sends a bunch of messages to the child. Expects them "repeated" back. Waits |
146 // for the child to close its end before quitting. | 148 // for the child to close its end before quitting. |
147 TEST_F(MultiprocessMessagePipeTest, QueueMessages) { | 149 TEST_F(MultiprocessMessagePipeTest, QueueMessages) { |
148 helper()->StartChild("EchoEcho"); | 150 helper()->StartChild("EchoEcho"); |
149 | 151 |
150 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalProxy()); | 152 scoped_refptr<ChannelEndpoint> ep; |
151 Init(mp); | 153 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalProxy(&ep)); |
| 154 Init(ep); |
152 | 155 |
153 static const size_t kNumMessages = 1001; | 156 static const size_t kNumMessages = 1001; |
154 for (size_t i = 0; i < kNumMessages; i++) { | 157 for (size_t i = 0; i < kNumMessages; i++) { |
155 std::string write_buffer(i, 'A' + (i % 26)); | 158 std::string write_buffer(i, 'A' + (i % 26)); |
156 EXPECT_EQ(MOJO_RESULT_OK, | 159 EXPECT_EQ(MOJO_RESULT_OK, |
157 mp->WriteMessage(0, | 160 mp->WriteMessage(0, |
158 UserPointer<const void>(write_buffer.data()), | 161 UserPointer<const void>(write_buffer.data()), |
159 static_cast<uint32_t>(write_buffer.size()), | 162 static_cast<uint32_t>(write_buffer.size()), |
160 NULL, | 163 NULL, |
161 MOJO_WRITE_MESSAGE_FLAG_NONE)); | 164 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 EXPECT_EQ(static_cast<int>(kNumMessages % 100), | 209 EXPECT_EQ(static_cast<int>(kNumMessages % 100), |
207 helper()->WaitForChildShutdown()); | 210 helper()->WaitForChildShutdown()); |
208 } | 211 } |
209 | 212 |
210 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(CheckSharedBuffer) { | 213 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(CheckSharedBuffer) { |
211 embedder::SimplePlatformSupport platform_support; | 214 embedder::SimplePlatformSupport platform_support; |
212 test::ChannelThread channel_thread(&platform_support); | 215 test::ChannelThread channel_thread(&platform_support); |
213 embedder::ScopedPlatformHandle client_platform_handle = | 216 embedder::ScopedPlatformHandle client_platform_handle = |
214 mojo::test::MultiprocessTestHelper::client_platform_handle.Pass(); | 217 mojo::test::MultiprocessTestHelper::client_platform_handle.Pass(); |
215 CHECK(client_platform_handle.is_valid()); | 218 CHECK(client_platform_handle.is_valid()); |
216 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalProxy()); | 219 scoped_refptr<ChannelEndpoint> ep; |
217 channel_thread.Start(client_platform_handle.Pass(), mp); | 220 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalProxy(&ep)); |
| 221 channel_thread.Start(client_platform_handle.Pass(), ep); |
218 | 222 |
219 // Wait for the first message from our parent. | 223 // Wait for the first message from our parent. |
220 HandleSignalsState hss; | 224 HandleSignalsState hss; |
221 CHECK_EQ(test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss), | 225 CHECK_EQ(test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss), |
222 MOJO_RESULT_OK); | 226 MOJO_RESULT_OK); |
223 // In this test, the parent definitely doesn't close its end of the message | 227 // In this test, the parent definitely doesn't close its end of the message |
224 // pipe before we do. | 228 // pipe before we do. |
225 CHECK_EQ(hss.satisfied_signals, | 229 CHECK_EQ(hss.satisfied_signals, |
226 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE); | 230 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE); |
227 CHECK_EQ(hss.satisfiable_signals, | 231 CHECK_EQ(hss.satisfiable_signals, |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 | 309 |
306 #if defined(OS_POSIX) | 310 #if defined(OS_POSIX) |
307 #define MAYBE_SharedBufferPassing SharedBufferPassing | 311 #define MAYBE_SharedBufferPassing SharedBufferPassing |
308 #else | 312 #else |
309 // Not yet implemented (on Windows). | 313 // Not yet implemented (on Windows). |
310 #define MAYBE_SharedBufferPassing DISABLED_SharedBufferPassing | 314 #define MAYBE_SharedBufferPassing DISABLED_SharedBufferPassing |
311 #endif | 315 #endif |
312 TEST_F(MultiprocessMessagePipeTest, MAYBE_SharedBufferPassing) { | 316 TEST_F(MultiprocessMessagePipeTest, MAYBE_SharedBufferPassing) { |
313 helper()->StartChild("CheckSharedBuffer"); | 317 helper()->StartChild("CheckSharedBuffer"); |
314 | 318 |
315 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalProxy()); | 319 scoped_refptr<ChannelEndpoint> ep; |
316 Init(mp); | 320 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalProxy(&ep)); |
| 321 Init(ep); |
317 | 322 |
318 // Make a shared buffer. | 323 // Make a shared buffer. |
319 scoped_refptr<SharedBufferDispatcher> dispatcher; | 324 scoped_refptr<SharedBufferDispatcher> dispatcher; |
320 EXPECT_EQ(MOJO_RESULT_OK, | 325 EXPECT_EQ(MOJO_RESULT_OK, |
321 SharedBufferDispatcher::Create( | 326 SharedBufferDispatcher::Create( |
322 platform_support(), | 327 platform_support(), |
323 SharedBufferDispatcher::kDefaultCreateOptions, | 328 SharedBufferDispatcher::kDefaultCreateOptions, |
324 100, | 329 100, |
325 &dispatcher)); | 330 &dispatcher)); |
326 ASSERT_TRUE(dispatcher.get()); | 331 ASSERT_TRUE(dispatcher.get()); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 | 405 |
401 EXPECT_EQ(0, helper()->WaitForChildShutdown()); | 406 EXPECT_EQ(0, helper()->WaitForChildShutdown()); |
402 } | 407 } |
403 | 408 |
404 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(CheckPlatformHandleFile) { | 409 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(CheckPlatformHandleFile) { |
405 embedder::SimplePlatformSupport platform_support; | 410 embedder::SimplePlatformSupport platform_support; |
406 test::ChannelThread channel_thread(&platform_support); | 411 test::ChannelThread channel_thread(&platform_support); |
407 embedder::ScopedPlatformHandle client_platform_handle = | 412 embedder::ScopedPlatformHandle client_platform_handle = |
408 mojo::test::MultiprocessTestHelper::client_platform_handle.Pass(); | 413 mojo::test::MultiprocessTestHelper::client_platform_handle.Pass(); |
409 CHECK(client_platform_handle.is_valid()); | 414 CHECK(client_platform_handle.is_valid()); |
410 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalProxy()); | 415 scoped_refptr<ChannelEndpoint> ep; |
411 channel_thread.Start(client_platform_handle.Pass(), mp); | 416 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalProxy(&ep)); |
| 417 channel_thread.Start(client_platform_handle.Pass(), ep); |
412 | 418 |
413 HandleSignalsState hss; | 419 HandleSignalsState hss; |
414 CHECK_EQ(test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss), | 420 CHECK_EQ(test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss), |
415 MOJO_RESULT_OK); | 421 MOJO_RESULT_OK); |
416 CHECK_EQ(hss.satisfied_signals, | 422 CHECK_EQ(hss.satisfied_signals, |
417 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE); | 423 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE); |
418 CHECK_EQ(hss.satisfiable_signals, | 424 CHECK_EQ(hss.satisfiable_signals, |
419 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE); | 425 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE); |
420 | 426 |
421 std::string read_buffer(100, '\0'); | 427 std::string read_buffer(100, '\0'); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 #else | 464 #else |
459 // Not yet implemented (on Windows). | 465 // Not yet implemented (on Windows). |
460 #define MAYBE_PlatformHandlePassing DISABLED_PlatformHandlePassing | 466 #define MAYBE_PlatformHandlePassing DISABLED_PlatformHandlePassing |
461 #endif | 467 #endif |
462 TEST_F(MultiprocessMessagePipeTest, MAYBE_PlatformHandlePassing) { | 468 TEST_F(MultiprocessMessagePipeTest, MAYBE_PlatformHandlePassing) { |
463 base::ScopedTempDir temp_dir; | 469 base::ScopedTempDir temp_dir; |
464 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 470 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
465 | 471 |
466 helper()->StartChild("CheckPlatformHandleFile"); | 472 helper()->StartChild("CheckPlatformHandleFile"); |
467 | 473 |
468 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalProxy()); | 474 scoped_refptr<ChannelEndpoint> ep; |
469 Init(mp); | 475 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalProxy(&ep)); |
| 476 Init(ep); |
470 | 477 |
471 base::FilePath unused; | 478 base::FilePath unused; |
472 base::ScopedFILE fp( | 479 base::ScopedFILE fp( |
473 CreateAndOpenTemporaryFileInDir(temp_dir.path(), &unused)); | 480 CreateAndOpenTemporaryFileInDir(temp_dir.path(), &unused)); |
474 const std::string world("world"); | 481 const std::string world("world"); |
475 ASSERT_EQ(fwrite(&world[0], 1, world.size(), fp.get()), world.size()); | 482 ASSERT_EQ(fwrite(&world[0], 1, world.size(), fp.get()), world.size()); |
476 fflush(fp.get()); | 483 fflush(fp.get()); |
477 rewind(fp.get()); | 484 rewind(fp.get()); |
478 | 485 |
479 embedder::ScopedPlatformHandle h( | 486 embedder::ScopedPlatformHandle h( |
(...skipping 27 matching lines...) Expand all Loading... |
507 EXPECT_EQ(0u, hss.satisfiable_signals); | 514 EXPECT_EQ(0u, hss.satisfiable_signals); |
508 | 515 |
509 mp->Close(0); | 516 mp->Close(0); |
510 | 517 |
511 EXPECT_EQ(0, helper()->WaitForChildShutdown()); | 518 EXPECT_EQ(0, helper()->WaitForChildShutdown()); |
512 } | 519 } |
513 | 520 |
514 } // namespace | 521 } // namespace |
515 } // namespace system | 522 } // namespace system |
516 } // namespace mojo | 523 } // namespace mojo |
OLD | NEW |