OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/embedder.h" | 5 #include "mojo/edk/embedder/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/bind.h" | 11 #include "base/bind.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "mojo/edk/embedder/platform_channel_pair.h" | 14 #include "mojo/edk/embedder/platform_channel_pair.h" |
15 #include "mojo/edk/embedder/test_embedder.h" | 15 #include "mojo/edk/embedder/test_embedder.h" |
16 #include "mojo/edk/system/test/test_command_line.h" | 16 #include "mojo/edk/system/test/test_command_line.h" |
17 #include "mojo/edk/system/test/test_io_thread.h" | 17 #include "mojo/edk/system/test/test_io_thread.h" |
18 #include "mojo/edk/system/test/timeouts.h" | 18 #include "mojo/edk/system/test/timeouts.h" |
| 19 #include "mojo/edk/system/waitable_event.h" |
19 #include "mojo/edk/test/multiprocess_test_helper.h" | 20 #include "mojo/edk/test/multiprocess_test_helper.h" |
20 #include "mojo/edk/test/scoped_ipc_support.h" | 21 #include "mojo/edk/test/scoped_ipc_support.h" |
21 #include "mojo/edk/util/command_line.h" | 22 #include "mojo/edk/util/command_line.h" |
22 #include "mojo/edk/util/mutex.h" | 23 #include "mojo/edk/util/mutex.h" |
23 #include "mojo/edk/util/thread_annotations.h" | 24 #include "mojo/edk/util/thread_annotations.h" |
24 #include "mojo/edk/util/waitable_event.h" | |
25 #include "mojo/public/c/system/core.h" | 25 #include "mojo/public/c/system/core.h" |
26 #include "mojo/public/cpp/system/handle.h" | 26 #include "mojo/public/cpp/system/handle.h" |
27 #include "mojo/public/cpp/system/macros.h" | 27 #include "mojo/public/cpp/system/macros.h" |
28 #include "mojo/public/cpp/system/message_pipe.h" | 28 #include "mojo/public/cpp/system/message_pipe.h" |
29 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
30 | 30 |
31 using mojo::system::test::TestIOThread; | 31 using mojo::system::test::TestIOThread; |
32 using mojo::util::ManualResetWaitableEvent; | |
33 using mojo::util::Mutex; | 32 using mojo::util::Mutex; |
34 using mojo::util::MutexLocker; | 33 using mojo::util::MutexLocker; |
35 | 34 |
36 namespace mojo { | 35 namespace mojo { |
37 namespace embedder { | 36 namespace embedder { |
38 namespace { | 37 namespace { |
39 | 38 |
40 const MojoHandleSignals kSignalReadadableWritable = | 39 const MojoHandleSignals kSignalReadadableWritable = |
41 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE; | 40 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE; |
42 | 41 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 | 111 |
113 // Valid from creation until whenever it gets closed (by the "owner" of this | 112 // Valid from creation until whenever it gets closed (by the "owner" of this |
114 // object). | 113 // object). |
115 // Note: We don't want use the C++ wrappers here, since we want to test the | 114 // Note: We don't want use the C++ wrappers here, since we want to test the |
116 // API at the lowest level. | 115 // API at the lowest level. |
117 MojoHandle bootstrap_message_pipe_; | 116 MojoHandle bootstrap_message_pipe_; |
118 | 117 |
119 // Set after channel creation has been completed (i.e., the callback to | 118 // Set after channel creation has been completed (i.e., the callback to |
120 // |CreateChannel()| has been called). Also used in the destructor to wait for | 119 // |CreateChannel()| has been called). Also used in the destructor to wait for |
121 // |DestroyChannel()| completion. | 120 // |DestroyChannel()| completion. |
122 ManualResetWaitableEvent event_; | 121 mojo::system::ManualResetWaitableEvent event_; |
123 | 122 |
124 // Valid after channel creation completion until destruction. | 123 // Valid after channel creation completion until destruction. |
125 ChannelInfo* channel_info_; | 124 ChannelInfo* channel_info_; |
126 | 125 |
127 // Whether the destructor should wait until the channel is destroyed. | 126 // Whether the destructor should wait until the channel is destroyed. |
128 bool wait_on_shutdown_; | 127 bool wait_on_shutdown_; |
129 | 128 |
130 MOJO_DISALLOW_COPY_AND_ASSIGN(ScopedTestChannel); | 129 MOJO_DISALLOW_COPY_AND_ASSIGN(ScopedTestChannel); |
131 }; | 130 }; |
132 | 131 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 bool TryWait() { | 208 bool TryWait() { |
210 return !event_.WaitWithTimeout(mojo::system::test::ActionTimeout()); | 209 return !event_.WaitWithTimeout(mojo::system::test::ActionTimeout()); |
211 } | 210 } |
212 | 211 |
213 MojoResult wait_result() const { | 212 MojoResult wait_result() const { |
214 MutexLocker l(&wait_result_mutex_); | 213 MutexLocker l(&wait_result_mutex_); |
215 return wait_result_; | 214 return wait_result_; |
216 } | 215 } |
217 | 216 |
218 private: | 217 private: |
219 ManualResetWaitableEvent event_; | 218 mojo::system::ManualResetWaitableEvent event_; |
220 | 219 |
221 mutable Mutex wait_result_mutex_; | 220 mutable Mutex wait_result_mutex_; |
222 MojoResult wait_result_ MOJO_GUARDED_BY(wait_result_mutex_); | 221 MojoResult wait_result_ MOJO_GUARDED_BY(wait_result_mutex_); |
223 | 222 |
224 MOJO_DISALLOW_COPY_AND_ASSIGN(TestAsyncWaiter); | 223 MOJO_DISALLOW_COPY_AND_ASSIGN(TestAsyncWaiter); |
225 }; | 224 }; |
226 | 225 |
227 void WriteHello(MessagePipeHandle pipe) { | 226 void WriteHello(MessagePipeHandle pipe) { |
228 static const char kHello[] = "hello"; | 227 static const char kHello[] = "hello"; |
229 CHECK_EQ(MOJO_RESULT_OK, | 228 CHECK_EQ(MOJO_RESULT_OK, |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 // TODO(vtl): I'm guessing this is true of this test too? | 402 // TODO(vtl): I'm guessing this is true of this test too? |
404 #define MAYBE_MultiprocessMasterSlave DISABLED_MultiprocessMasterSlave | 403 #define MAYBE_MultiprocessMasterSlave DISABLED_MultiprocessMasterSlave |
405 #else | 404 #else |
406 #define MAYBE_MultiprocessMasterSlave MultiprocessMasterSlave | 405 #define MAYBE_MultiprocessMasterSlave MultiprocessMasterSlave |
407 #endif // defined(OS_ANDROID) | 406 #endif // defined(OS_ANDROID) |
408 TEST_F(EmbedderTest, MAYBE_MultiprocessMasterSlave) { | 407 TEST_F(EmbedderTest, MAYBE_MultiprocessMasterSlave) { |
409 mojo::test::ScopedMasterIPCSupport ipc_support(test_io_task_runner()); | 408 mojo::test::ScopedMasterIPCSupport ipc_support(test_io_task_runner()); |
410 | 409 |
411 mojo::test::MultiprocessTestHelper multiprocess_test_helper; | 410 mojo::test::MultiprocessTestHelper multiprocess_test_helper; |
412 std::string connection_id; | 411 std::string connection_id; |
413 ManualResetWaitableEvent event; | 412 mojo::system::ManualResetWaitableEvent event; |
414 ChannelInfo* channel_info = nullptr; | 413 ChannelInfo* channel_info = nullptr; |
415 ScopedMessagePipeHandle mp = ConnectToSlave( | 414 ScopedMessagePipeHandle mp = ConnectToSlave( |
416 nullptr, multiprocess_test_helper.server_platform_handle.Pass(), | 415 nullptr, multiprocess_test_helper.server_platform_handle.Pass(), |
417 base::Bind(&ManualResetWaitableEvent::Signal, base::Unretained(&event)), | 416 base::Bind(&mojo::system::ManualResetWaitableEvent::Signal, |
| 417 base::Unretained(&event)), |
418 nullptr, &connection_id, &channel_info); | 418 nullptr, &connection_id, &channel_info); |
419 ASSERT_TRUE(mp.is_valid()); | 419 ASSERT_TRUE(mp.is_valid()); |
420 EXPECT_TRUE(channel_info); | 420 EXPECT_TRUE(channel_info); |
421 ASSERT_FALSE(connection_id.empty()); | 421 ASSERT_FALSE(connection_id.empty()); |
422 | 422 |
423 multiprocess_test_helper.StartChildWithExtraSwitch( | 423 multiprocess_test_helper.StartChildWithExtraSwitch( |
424 "MultiprocessMasterSlave", kConnectionIdFlag, connection_id); | 424 "MultiprocessMasterSlave", kConnectionIdFlag, connection_id); |
425 | 425 |
426 // Send a message saying "hello". | 426 // Send a message saying "hello". |
427 EXPECT_EQ(MOJO_RESULT_OK, WriteMessageRaw(mp.get(), "hello", 5, nullptr, 0, | 427 EXPECT_EQ(MOJO_RESULT_OK, WriteMessageRaw(mp.get(), "hello", 5, nullptr, 0, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 test::InitWithSimplePlatformSupport(); | 480 test::InitWithSimplePlatformSupport(); |
481 | 481 |
482 { | 482 { |
483 mojo::test::ScopedSlaveIPCSupport ipc_support( | 483 mojo::test::ScopedSlaveIPCSupport ipc_support( |
484 test_io_thread.task_runner(), client_platform_handle.Pass()); | 484 test_io_thread.task_runner(), client_platform_handle.Pass()); |
485 | 485 |
486 std::string connection_id; | 486 std::string connection_id; |
487 ASSERT_TRUE(mojo::system::test::GetTestCommandLine()->GetOptionValue( | 487 ASSERT_TRUE(mojo::system::test::GetTestCommandLine()->GetOptionValue( |
488 kConnectionIdFlag, &connection_id)); | 488 kConnectionIdFlag, &connection_id)); |
489 ASSERT_FALSE(connection_id.empty()); | 489 ASSERT_FALSE(connection_id.empty()); |
490 ManualResetWaitableEvent event; | 490 mojo::system::ManualResetWaitableEvent event; |
491 ChannelInfo* channel_info = nullptr; | 491 ChannelInfo* channel_info = nullptr; |
492 ScopedMessagePipeHandle mp = ConnectToMaster( | 492 ScopedMessagePipeHandle mp = ConnectToMaster( |
493 connection_id, | 493 connection_id, |
494 base::Bind(&ManualResetWaitableEvent::Signal, base::Unretained(&event)), | 494 base::Bind(&mojo::system::ManualResetWaitableEvent::Signal, |
| 495 base::Unretained(&event)), |
495 nullptr, &channel_info); | 496 nullptr, &channel_info); |
496 ASSERT_TRUE(mp.is_valid()); | 497 ASSERT_TRUE(mp.is_valid()); |
497 EXPECT_TRUE(channel_info); | 498 EXPECT_TRUE(channel_info); |
498 | 499 |
499 // Wait for the master to send us a message. | 500 // Wait for the master to send us a message. |
500 EXPECT_EQ(MOJO_RESULT_OK, | 501 EXPECT_EQ(MOJO_RESULT_OK, |
501 Wait(mp.get(), MOJO_HANDLE_SIGNAL_READABLE, | 502 Wait(mp.get(), MOJO_HANDLE_SIGNAL_READABLE, |
502 mojo::system::test::ActionTimeout(), nullptr)); | 503 mojo::system::test::ActionTimeout(), nullptr)); |
503 | 504 |
504 // It should say "hello". | 505 // It should say "hello". |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
781 | 782 |
782 EXPECT_TRUE(test::Shutdown()); | 783 EXPECT_TRUE(test::Shutdown()); |
783 } | 784 } |
784 | 785 |
785 // TODO(vtl): Test immediate write & close. | 786 // TODO(vtl): Test immediate write & close. |
786 // TODO(vtl): Test broken-connection cases. | 787 // TODO(vtl): Test broken-connection cases. |
787 | 788 |
788 } // namespace | 789 } // namespace |
789 } // namespace embedder | 790 } // namespace embedder |
790 } // namespace mojo | 791 } // namespace mojo |
OLD | NEW |