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 <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 <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "mojo/edk/embedder/platform_channel_pair.h" | 14 #include "mojo/edk/embedder/platform_channel_pair.h" |
15 #include "mojo/edk/embedder/platform_shared_buffer.h" | 15 #include "mojo/edk/embedder/platform_shared_buffer.h" |
16 #include "mojo/edk/embedder/simple_platform_support.h" | 16 #include "mojo/edk/embedder/simple_platform_support.h" |
17 #include "mojo/edk/platform/scoped_platform_handle.h" | 17 #include "mojo/edk/platform/scoped_platform_handle.h" |
| 18 #include "mojo/edk/platform/thread_utils.h" |
18 #include "mojo/edk/system/channel.h" | 19 #include "mojo/edk/system/channel.h" |
19 #include "mojo/edk/system/channel_endpoint.h" | 20 #include "mojo/edk/system/channel_endpoint.h" |
20 #include "mojo/edk/system/channel_endpoint_id.h" | 21 #include "mojo/edk/system/channel_endpoint_id.h" |
21 #include "mojo/edk/system/incoming_endpoint.h" | 22 #include "mojo/edk/system/incoming_endpoint.h" |
22 #include "mojo/edk/system/message_pipe.h" | 23 #include "mojo/edk/system/message_pipe.h" |
23 #include "mojo/edk/system/message_pipe_dispatcher.h" | 24 #include "mojo/edk/system/message_pipe_dispatcher.h" |
24 #include "mojo/edk/system/platform_handle_dispatcher.h" | 25 #include "mojo/edk/system/platform_handle_dispatcher.h" |
25 #include "mojo/edk/system/raw_channel.h" | 26 #include "mojo/edk/system/raw_channel.h" |
26 #include "mojo/edk/system/shared_buffer_dispatcher.h" | 27 #include "mojo/edk/system/shared_buffer_dispatcher.h" |
27 #include "mojo/edk/system/test/scoped_test_dir.h" | 28 #include "mojo/edk/system/test/scoped_test_dir.h" |
28 #include "mojo/edk/system/test/sleep.h" | |
29 #include "mojo/edk/system/test/test_io_thread.h" | 29 #include "mojo/edk/system/test/test_io_thread.h" |
30 #include "mojo/edk/system/test/timeouts.h" | 30 #include "mojo/edk/system/test/timeouts.h" |
31 #include "mojo/edk/system/waiter.h" | 31 #include "mojo/edk/system/waiter.h" |
32 #include "mojo/edk/test/test_utils.h" | 32 #include "mojo/edk/test/test_utils.h" |
33 #include "mojo/edk/util/ref_ptr.h" | 33 #include "mojo/edk/util/ref_ptr.h" |
34 #include "mojo/edk/util/scoped_file.h" | 34 #include "mojo/edk/util/scoped_file.h" |
35 #include "mojo/public/cpp/system/macros.h" | 35 #include "mojo/public/cpp/system/macros.h" |
36 #include "testing/gtest/include/gtest/gtest.h" | 36 #include "testing/gtest/include/gtest/gtest.h" |
37 | 37 |
38 using mojo::platform::ScopedPlatformHandle; | 38 using mojo::platform::ScopedPlatformHandle; |
| 39 using mojo::platform::ThreadSleep; |
39 using mojo::util::MakeRefCounted; | 40 using mojo::util::MakeRefCounted; |
40 using mojo::util::RefPtr; | 41 using mojo::util::RefPtr; |
41 | 42 |
42 namespace mojo { | 43 namespace mojo { |
43 namespace system { | 44 namespace system { |
44 namespace { | 45 namespace { |
45 | 46 |
46 const MojoHandleSignals kAllSignals = MOJO_HANDLE_SIGNAL_READABLE | | 47 const MojoHandleSignals kAllSignals = MOJO_HANDLE_SIGNAL_READABLE | |
47 MOJO_HANDLE_SIGNAL_WRITABLE | | 48 MOJO_HANDLE_SIGNAL_WRITABLE | |
48 MOJO_HANDLE_SIGNAL_PEER_CLOSED; | 49 MOJO_HANDLE_SIGNAL_PEER_CLOSED; |
(...skipping 1069 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1118 DVLOG(2) << "---------------------------------------- " << i; | 1119 DVLOG(2) << "---------------------------------------- " << i; |
1119 RefPtr<ChannelEndpoint> ep0; | 1120 RefPtr<ChannelEndpoint> ep0; |
1120 auto mp0 = MessagePipe::CreateLocalProxy(&ep0); | 1121 auto mp0 = MessagePipe::CreateLocalProxy(&ep0); |
1121 BootstrapChannelEndpointNoWait(0, std::move(ep0)); | 1122 BootstrapChannelEndpointNoWait(0, std::move(ep0)); |
1122 | 1123 |
1123 RefPtr<ChannelEndpoint> ep1; | 1124 RefPtr<ChannelEndpoint> ep1; |
1124 auto mp1 = MessagePipe::CreateProxyLocal(&ep1); | 1125 auto mp1 = MessagePipe::CreateProxyLocal(&ep1); |
1125 BootstrapChannelEndpointNoWait(1, std::move(ep1)); | 1126 BootstrapChannelEndpointNoWait(1, std::move(ep1)); |
1126 | 1127 |
1127 if (i & 1u) { | 1128 if (i & 1u) { |
1128 io_thread()->PostTask([delay]() { test::Sleep(delay); }); | 1129 io_thread()->PostTask([delay]() { ThreadSleep(delay); }); |
1129 } | 1130 } |
1130 if (i & 2u) | 1131 if (i & 2u) |
1131 test::Sleep(delay); | 1132 ThreadSleep(delay); |
1132 | 1133 |
1133 mp0->Close(0); | 1134 mp0->Close(0); |
1134 | 1135 |
1135 if (i & 4u) { | 1136 if (i & 4u) { |
1136 io_thread()->PostTask([delay]() { test::Sleep(delay); }); | 1137 io_thread()->PostTask([delay]() { ThreadSleep(delay); }); |
1137 } | 1138 } |
1138 if (i & 8u) | 1139 if (i & 8u) |
1139 test::Sleep(delay); | 1140 ThreadSleep(delay); |
1140 | 1141 |
1141 mp1->Close(1); | 1142 mp1->Close(1); |
1142 | 1143 |
1143 RestoreInitialState(); | 1144 RestoreInitialState(); |
1144 } | 1145 } |
1145 } | 1146 } |
1146 | 1147 |
1147 // Tests passing an end of a message pipe over a remote message pipe, and then | 1148 // Tests passing an end of a message pipe over a remote message pipe, and then |
1148 // passing that end back. | 1149 // passing that end back. |
1149 // TODO(vtl): Also test passing a message pipe across two remote message pipes. | 1150 // TODO(vtl): Also test passing a message pipe across two remote message pipes. |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1350 mp0->Close(0); | 1351 mp0->Close(0); |
1351 mp1->Close(1); | 1352 mp1->Close(1); |
1352 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); | 1353 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); |
1353 // Note that |local_mp|'s port 0 belong to |dispatcher|, which was closed. | 1354 // Note that |local_mp|'s port 0 belong to |dispatcher|, which was closed. |
1354 local_mp->Close(1); | 1355 local_mp->Close(1); |
1355 } | 1356 } |
1356 | 1357 |
1357 } // namespace | 1358 } // namespace |
1358 } // namespace system | 1359 } // namespace system |
1359 } // namespace mojo | 1360 } // namespace mojo |
OLD | NEW |