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/file_util.h" | 13 #include "base/file_util.h" |
14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.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 "base/threading/platform_thread.h" // For |Sleep()|. | |
21 #include "build/build_config.h" // TODO(vtl): Remove this. | 20 #include "build/build_config.h" // TODO(vtl): Remove this. |
22 #include "mojo/common/test/multiprocess_test_helper.h" | |
23 #include "mojo/common/test/test_utils.h" | 21 #include "mojo/common/test/test_utils.h" |
24 #include "mojo/embedder/platform_shared_buffer.h" | 22 #include "mojo/embedder/platform_shared_buffer.h" |
25 #include "mojo/embedder/scoped_platform_handle.h" | 23 #include "mojo/embedder/scoped_platform_handle.h" |
26 #include "mojo/embedder/simple_platform_support.h" | |
27 #include "mojo/system/channel.h" | 24 #include "mojo/system/channel.h" |
28 #include "mojo/system/dispatcher.h" | 25 #include "mojo/system/dispatcher.h" |
29 #include "mojo/system/local_message_pipe_endpoint.h" | 26 #include "mojo/system/local_message_pipe_endpoint.h" |
30 #include "mojo/system/message_pipe.h" | 27 #include "mojo/system/message_pipe.h" |
| 28 #include "mojo/system/message_pipe_test_utils.h" |
31 #include "mojo/system/platform_handle_dispatcher.h" | 29 #include "mojo/system/platform_handle_dispatcher.h" |
32 #include "mojo/system/proxy_message_pipe_endpoint.h" | 30 #include "mojo/system/proxy_message_pipe_endpoint.h" |
33 #include "mojo/system/raw_channel.h" | 31 #include "mojo/system/raw_channel.h" |
34 #include "mojo/system/shared_buffer_dispatcher.h" | 32 #include "mojo/system/shared_buffer_dispatcher.h" |
35 #include "mojo/system/test_utils.h" | 33 #include "mojo/system/test_utils.h" |
36 #include "mojo/system/waiter.h" | |
37 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
38 | 35 |
39 namespace mojo { | 36 namespace mojo { |
40 namespace system { | 37 namespace system { |
41 namespace { | 38 namespace { |
42 | 39 |
43 class ChannelThread { | 40 class MultiprocessMessagePipeTest |
44 public: | 41 : public test::MultiprocessMessagePipeTestBase {}; |
45 explicit ChannelThread(embedder::PlatformSupport* platform_support) | |
46 : platform_support_(platform_support), | |
47 test_io_thread_(test::TestIOThread::kManualStart) {} | |
48 ~ChannelThread() { Stop(); } | |
49 | |
50 void Start(embedder::ScopedPlatformHandle platform_handle, | |
51 scoped_refptr<MessagePipe> message_pipe) { | |
52 test_io_thread_.Start(); | |
53 test_io_thread_.PostTaskAndWait( | |
54 FROM_HERE, | |
55 base::Bind(&ChannelThread::InitChannelOnIOThread, | |
56 base::Unretained(this), | |
57 base::Passed(&platform_handle), | |
58 message_pipe)); | |
59 } | |
60 | |
61 void Stop() { | |
62 if (channel_) { | |
63 // Hack to flush write buffers before quitting. | |
64 // TODO(vtl): Remove this once |Channel| has a | |
65 // |FlushWriteBufferAndShutdown()| (or whatever). | |
66 while (!channel_->IsWriteBufferEmpty()) | |
67 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(20)); | |
68 | |
69 test_io_thread_.PostTaskAndWait( | |
70 FROM_HERE, | |
71 base::Bind(&ChannelThread::ShutdownChannelOnIOThread, | |
72 base::Unretained(this))); | |
73 } | |
74 test_io_thread_.Stop(); | |
75 } | |
76 | |
77 private: | |
78 void InitChannelOnIOThread(embedder::ScopedPlatformHandle platform_handle, | |
79 scoped_refptr<MessagePipe> message_pipe) { | |
80 CHECK_EQ(base::MessageLoop::current(), test_io_thread_.message_loop()); | |
81 CHECK(platform_handle.is_valid()); | |
82 | |
83 // Create and initialize |Channel|. | |
84 channel_ = new Channel(platform_support_); | |
85 CHECK(channel_->Init(RawChannel::Create(platform_handle.Pass()))); | |
86 | |
87 // Attach the message pipe endpoint. | |
88 // Note: On the "server" (parent process) side, we need not attach the | |
89 // message pipe endpoint immediately. However, on the "client" (child | |
90 // process) side, this *must* be done here -- otherwise, the |Channel| may | |
91 // receive/process messages (which it can do as soon as it's hooked up to | |
92 // the IO thread message loop, and that message loop runs) before the | |
93 // message pipe endpoint is attached. | |
94 CHECK_EQ(channel_->AttachMessagePipeEndpoint(message_pipe, 1), | |
95 Channel::kBootstrapEndpointId); | |
96 CHECK(channel_->RunMessagePipeEndpoint(Channel::kBootstrapEndpointId, | |
97 Channel::kBootstrapEndpointId)); | |
98 } | |
99 | |
100 void ShutdownChannelOnIOThread() { | |
101 CHECK(channel_); | |
102 channel_->Shutdown(); | |
103 channel_ = NULL; | |
104 } | |
105 | |
106 embedder::PlatformSupport* const platform_support_; | |
107 test::TestIOThread test_io_thread_; | |
108 scoped_refptr<Channel> channel_; | |
109 | |
110 DISALLOW_COPY_AND_ASSIGN(ChannelThread); | |
111 }; | |
112 | |
113 class MultiprocessMessagePipeTest : public testing::Test { | |
114 public: | |
115 MultiprocessMessagePipeTest() : channel_thread_(&platform_support_) {} | |
116 virtual ~MultiprocessMessagePipeTest() {} | |
117 | |
118 protected: | |
119 void Init(scoped_refptr<MessagePipe> mp) { | |
120 channel_thread_.Start(helper_.server_platform_handle.Pass(), mp); | |
121 } | |
122 | |
123 embedder::PlatformSupport* platform_support() { return &platform_support_; } | |
124 mojo::test::MultiprocessTestHelper* helper() { return &helper_; } | |
125 | |
126 private: | |
127 embedder::SimplePlatformSupport platform_support_; | |
128 ChannelThread channel_thread_; | |
129 mojo::test::MultiprocessTestHelper helper_; | |
130 | |
131 DISALLOW_COPY_AND_ASSIGN(MultiprocessMessagePipeTest); | |
132 }; | |
133 | |
134 MojoResult WaitIfNecessary(scoped_refptr<MessagePipe> mp, | |
135 MojoHandleSignals signals, | |
136 HandleSignalsState* signals_state) { | |
137 Waiter waiter; | |
138 waiter.Init(); | |
139 | |
140 MojoResult add_result = mp->AddWaiter(0, &waiter, signals, 0, signals_state); | |
141 if (add_result != MOJO_RESULT_OK) { | |
142 return (add_result == MOJO_RESULT_ALREADY_EXISTS) ? MOJO_RESULT_OK | |
143 : add_result; | |
144 } | |
145 | |
146 MojoResult wait_result = waiter.Wait(MOJO_DEADLINE_INDEFINITE, NULL); | |
147 mp->RemoveWaiter(0, &waiter, signals_state); | |
148 return wait_result; | |
149 } | |
150 | 42 |
151 // For each message received, sends a reply message with the same contents | 43 // For each message received, sends a reply message with the same contents |
152 // repeated twice, until the other end is closed or it receives "quitquitquit" | 44 // repeated twice, until the other end is closed or it receives "quitquitquit" |
153 // (which it doesn't reply to). It'll return the number of messages received, | 45 // (which it doesn't reply to). It'll return the number of messages received, |
154 // not including any "quitquitquit" message, modulo 100. | 46 // not including any "quitquitquit" message, modulo 100. |
155 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(EchoEcho) { | 47 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(EchoEcho) { |
156 embedder::SimplePlatformSupport platform_support; | 48 embedder::SimplePlatformSupport platform_support; |
157 ChannelThread channel_thread(&platform_support); | 49 test::ChannelThread channel_thread(&platform_support); |
158 embedder::ScopedPlatformHandle client_platform_handle = | 50 embedder::ScopedPlatformHandle client_platform_handle = |
159 mojo::test::MultiprocessTestHelper::client_platform_handle.Pass(); | 51 mojo::test::MultiprocessTestHelper::client_platform_handle.Pass(); |
160 CHECK(client_platform_handle.is_valid()); | 52 CHECK(client_platform_handle.is_valid()); |
161 scoped_refptr<MessagePipe> mp(new MessagePipe( | 53 scoped_refptr<MessagePipe> mp(new MessagePipe( |
162 scoped_ptr<MessagePipeEndpoint>(new LocalMessagePipeEndpoint()), | 54 scoped_ptr<MessagePipeEndpoint>(new LocalMessagePipeEndpoint()), |
163 scoped_ptr<MessagePipeEndpoint>(new ProxyMessagePipeEndpoint()))); | 55 scoped_ptr<MessagePipeEndpoint>(new ProxyMessagePipeEndpoint()))); |
164 channel_thread.Start(client_platform_handle.Pass(), mp); | 56 channel_thread.Start(client_platform_handle.Pass(), mp); |
165 | 57 |
166 const std::string quitquitquit("quitquitquit"); | 58 const std::string quitquitquit("quitquitquit"); |
167 int rv = 0; | 59 int rv = 0; |
168 for (;; rv = (rv + 1) % 100) { | 60 for (;; rv = (rv + 1) % 100) { |
169 // Wait for our end of the message pipe to be readable. | 61 // Wait for our end of the message pipe to be readable. |
170 HandleSignalsState hss; | 62 HandleSignalsState hss; |
171 MojoResult result = WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss); | 63 MojoResult result = |
| 64 test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss); |
172 if (result != MOJO_RESULT_OK) { | 65 if (result != MOJO_RESULT_OK) { |
173 // It was closed, probably. | 66 // It was closed, probably. |
174 CHECK_EQ(result, MOJO_RESULT_FAILED_PRECONDITION); | 67 CHECK_EQ(result, MOJO_RESULT_FAILED_PRECONDITION); |
175 CHECK_EQ(hss.satisfied_signals, 0u); | 68 CHECK_EQ(hss.satisfied_signals, 0u); |
176 CHECK_EQ(hss.satisfiable_signals, 0u); | 69 CHECK_EQ(hss.satisfiable_signals, 0u); |
177 break; | 70 break; |
178 } else { | 71 } else { |
179 CHECK((hss.satisfied_signals & MOJO_HANDLE_SIGNAL_READABLE)); | 72 CHECK((hss.satisfied_signals & MOJO_HANDLE_SIGNAL_READABLE)); |
180 CHECK((hss.satisfiable_signals & MOJO_HANDLE_SIGNAL_READABLE)); | 73 CHECK((hss.satisfiable_signals & MOJO_HANDLE_SIGNAL_READABLE)); |
181 } | 74 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 std::string hello("hello"); | 115 std::string hello("hello"); |
223 EXPECT_EQ(MOJO_RESULT_OK, | 116 EXPECT_EQ(MOJO_RESULT_OK, |
224 mp->WriteMessage(0, | 117 mp->WriteMessage(0, |
225 UserPointer<const void>(hello.data()), | 118 UserPointer<const void>(hello.data()), |
226 static_cast<uint32_t>(hello.size()), | 119 static_cast<uint32_t>(hello.size()), |
227 NULL, | 120 NULL, |
228 MOJO_WRITE_MESSAGE_FLAG_NONE)); | 121 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
229 | 122 |
230 HandleSignalsState hss; | 123 HandleSignalsState hss; |
231 EXPECT_EQ(MOJO_RESULT_OK, | 124 EXPECT_EQ(MOJO_RESULT_OK, |
232 WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss)); | 125 test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss)); |
233 // The child may or may not have closed its end of the message pipe and died | 126 // The child may or may not have closed its end of the message pipe and died |
234 // (and we may or may not know it yet), so our end may or may not appear as | 127 // (and we may or may not know it yet), so our end may or may not appear as |
235 // writable. | 128 // writable. |
236 EXPECT_TRUE((hss.satisfied_signals & MOJO_HANDLE_SIGNAL_READABLE)); | 129 EXPECT_TRUE((hss.satisfied_signals & MOJO_HANDLE_SIGNAL_READABLE)); |
237 EXPECT_TRUE((hss.satisfiable_signals & MOJO_HANDLE_SIGNAL_READABLE)); | 130 EXPECT_TRUE((hss.satisfiable_signals & MOJO_HANDLE_SIGNAL_READABLE)); |
238 | 131 |
239 std::string read_buffer(1000, '\0'); | 132 std::string read_buffer(1000, '\0'); |
240 uint32_t read_buffer_size = static_cast<uint32_t>(read_buffer.size()); | 133 uint32_t read_buffer_size = static_cast<uint32_t>(read_buffer.size()); |
241 CHECK_EQ(mp->ReadMessage(0, | 134 CHECK_EQ(mp->ReadMessage(0, |
242 UserPointer<void>(&read_buffer[0]), | 135 UserPointer<void>(&read_buffer[0]), |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 EXPECT_EQ(MOJO_RESULT_OK, | 173 EXPECT_EQ(MOJO_RESULT_OK, |
281 mp->WriteMessage(0, | 174 mp->WriteMessage(0, |
282 UserPointer<const void>(quitquitquit.data()), | 175 UserPointer<const void>(quitquitquit.data()), |
283 static_cast<uint32_t>(quitquitquit.size()), | 176 static_cast<uint32_t>(quitquitquit.size()), |
284 NULL, | 177 NULL, |
285 MOJO_WRITE_MESSAGE_FLAG_NONE)); | 178 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
286 | 179 |
287 for (size_t i = 0; i < kNumMessages; i++) { | 180 for (size_t i = 0; i < kNumMessages; i++) { |
288 HandleSignalsState hss; | 181 HandleSignalsState hss; |
289 EXPECT_EQ(MOJO_RESULT_OK, | 182 EXPECT_EQ(MOJO_RESULT_OK, |
290 WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss)); | 183 test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss)); |
291 // The child may or may not have closed its end of the message pipe and died | 184 // The child may or may not have closed its end of the message pipe and died |
292 // (and we may or may not know it yet), so our end may or may not appear as | 185 // (and we may or may not know it yet), so our end may or may not appear as |
293 // writable. | 186 // writable. |
294 EXPECT_TRUE((hss.satisfied_signals & MOJO_HANDLE_SIGNAL_READABLE)); | 187 EXPECT_TRUE((hss.satisfied_signals & MOJO_HANDLE_SIGNAL_READABLE)); |
295 EXPECT_TRUE((hss.satisfiable_signals & MOJO_HANDLE_SIGNAL_READABLE)); | 188 EXPECT_TRUE((hss.satisfiable_signals & MOJO_HANDLE_SIGNAL_READABLE)); |
296 | 189 |
297 std::string read_buffer(kNumMessages * 2, '\0'); | 190 std::string read_buffer(kNumMessages * 2, '\0'); |
298 uint32_t read_buffer_size = static_cast<uint32_t>(read_buffer.size()); | 191 uint32_t read_buffer_size = static_cast<uint32_t>(read_buffer.size()); |
299 CHECK_EQ(mp->ReadMessage(0, | 192 CHECK_EQ(mp->ReadMessage(0, |
300 UserPointer<void>(&read_buffer[0]), | 193 UserPointer<void>(&read_buffer[0]), |
301 MakeUserPointer(&read_buffer_size), | 194 MakeUserPointer(&read_buffer_size), |
302 NULL, | 195 NULL, |
303 NULL, | 196 NULL, |
304 MOJO_READ_MESSAGE_FLAG_NONE), | 197 MOJO_READ_MESSAGE_FLAG_NONE), |
305 MOJO_RESULT_OK); | 198 MOJO_RESULT_OK); |
306 read_buffer.resize(read_buffer_size); | 199 read_buffer.resize(read_buffer_size); |
307 | 200 |
308 EXPECT_EQ(std::string(i * 2, 'A' + (i % 26)), read_buffer); | 201 EXPECT_EQ(std::string(i * 2, 'A' + (i % 26)), read_buffer); |
309 } | 202 } |
310 | 203 |
311 // Wait for it to become readable, which should fail (since we sent | 204 // Wait for it to become readable, which should fail (since we sent |
312 // "quitquitquit"). | 205 // "quitquitquit"). |
313 HandleSignalsState hss; | 206 HandleSignalsState hss; |
314 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, | 207 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, |
315 WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss)); | 208 test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss)); |
316 EXPECT_EQ(0u, hss.satisfied_signals); | 209 EXPECT_EQ(0u, hss.satisfied_signals); |
317 EXPECT_EQ(0u, hss.satisfiable_signals); | 210 EXPECT_EQ(0u, hss.satisfiable_signals); |
318 | 211 |
319 mp->Close(0); | 212 mp->Close(0); |
320 | 213 |
321 EXPECT_EQ(static_cast<int>(kNumMessages % 100), | 214 EXPECT_EQ(static_cast<int>(kNumMessages % 100), |
322 helper()->WaitForChildShutdown()); | 215 helper()->WaitForChildShutdown()); |
323 } | 216 } |
324 | 217 |
325 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(CheckSharedBuffer) { | 218 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(CheckSharedBuffer) { |
326 embedder::SimplePlatformSupport platform_support; | 219 embedder::SimplePlatformSupport platform_support; |
327 ChannelThread channel_thread(&platform_support); | 220 test::ChannelThread channel_thread(&platform_support); |
328 embedder::ScopedPlatformHandle client_platform_handle = | 221 embedder::ScopedPlatformHandle client_platform_handle = |
329 mojo::test::MultiprocessTestHelper::client_platform_handle.Pass(); | 222 mojo::test::MultiprocessTestHelper::client_platform_handle.Pass(); |
330 CHECK(client_platform_handle.is_valid()); | 223 CHECK(client_platform_handle.is_valid()); |
331 scoped_refptr<MessagePipe> mp(new MessagePipe( | 224 scoped_refptr<MessagePipe> mp(new MessagePipe( |
332 scoped_ptr<MessagePipeEndpoint>(new LocalMessagePipeEndpoint()), | 225 scoped_ptr<MessagePipeEndpoint>(new LocalMessagePipeEndpoint()), |
333 scoped_ptr<MessagePipeEndpoint>(new ProxyMessagePipeEndpoint()))); | 226 scoped_ptr<MessagePipeEndpoint>(new ProxyMessagePipeEndpoint()))); |
334 channel_thread.Start(client_platform_handle.Pass(), mp); | 227 channel_thread.Start(client_platform_handle.Pass(), mp); |
335 | 228 |
336 // Wait for the first message from our parent. | 229 // Wait for the first message from our parent. |
337 HandleSignalsState hss; | 230 HandleSignalsState hss; |
338 CHECK_EQ(WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss), | 231 CHECK_EQ(test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss), |
339 MOJO_RESULT_OK); | 232 MOJO_RESULT_OK); |
340 // In this test, the parent definitely doesn't close its end of the message | 233 // In this test, the parent definitely doesn't close its end of the message |
341 // pipe before we do. | 234 // pipe before we do. |
342 CHECK_EQ(hss.satisfied_signals, | 235 CHECK_EQ(hss.satisfied_signals, |
343 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE); | 236 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE); |
344 CHECK_EQ(hss.satisfiable_signals, | 237 CHECK_EQ(hss.satisfiable_signals, |
345 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE); | 238 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE); |
346 | 239 |
347 // It should have a shared buffer. | 240 // It should have a shared buffer. |
348 std::string read_buffer(100, '\0'); | 241 std::string read_buffer(100, '\0'); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 const std::string go2("go 2"); | 277 const std::string go2("go 2"); |
385 CHECK_EQ(mp->WriteMessage(0, | 278 CHECK_EQ(mp->WriteMessage(0, |
386 UserPointer<const void>(&go2[0]), | 279 UserPointer<const void>(&go2[0]), |
387 static_cast<uint32_t>(go2.size()), | 280 static_cast<uint32_t>(go2.size()), |
388 NULL, | 281 NULL, |
389 MOJO_WRITE_MESSAGE_FLAG_NONE), | 282 MOJO_WRITE_MESSAGE_FLAG_NONE), |
390 MOJO_RESULT_OK); | 283 MOJO_RESULT_OK); |
391 | 284 |
392 // Now wait for our parent to send us a message. | 285 // Now wait for our parent to send us a message. |
393 hss = HandleSignalsState(); | 286 hss = HandleSignalsState(); |
394 CHECK_EQ(WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss), | 287 CHECK_EQ(test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss), |
395 MOJO_RESULT_OK); | 288 MOJO_RESULT_OK); |
396 CHECK_EQ(hss.satisfied_signals, | 289 CHECK_EQ(hss.satisfied_signals, |
397 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE); | 290 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE); |
398 CHECK_EQ(hss.satisfiable_signals, | 291 CHECK_EQ(hss.satisfiable_signals, |
399 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE); | 292 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE); |
400 | 293 |
401 read_buffer = std::string(100, '\0'); | 294 read_buffer = std::string(100, '\0'); |
402 num_bytes = static_cast<uint32_t>(read_buffer.size()); | 295 num_bytes = static_cast<uint32_t>(read_buffer.size()); |
403 CHECK_EQ(mp->ReadMessage(0, | 296 CHECK_EQ(mp->ReadMessage(0, |
404 UserPointer<void>(&read_buffer[0]), | 297 UserPointer<void>(&read_buffer[0]), |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 &transports, | 360 &transports, |
468 MOJO_WRITE_MESSAGE_FLAG_NONE)); | 361 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
469 transport.End(); | 362 transport.End(); |
470 | 363 |
471 EXPECT_TRUE(dispatcher->HasOneRef()); | 364 EXPECT_TRUE(dispatcher->HasOneRef()); |
472 dispatcher = NULL; | 365 dispatcher = NULL; |
473 | 366 |
474 // Wait for a message from the child. | 367 // Wait for a message from the child. |
475 HandleSignalsState hss; | 368 HandleSignalsState hss; |
476 EXPECT_EQ(MOJO_RESULT_OK, | 369 EXPECT_EQ(MOJO_RESULT_OK, |
477 WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss)); | 370 test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss)); |
478 EXPECT_TRUE((hss.satisfied_signals & MOJO_HANDLE_SIGNAL_READABLE)); | 371 EXPECT_TRUE((hss.satisfied_signals & MOJO_HANDLE_SIGNAL_READABLE)); |
479 EXPECT_TRUE((hss.satisfiable_signals & MOJO_HANDLE_SIGNAL_READABLE)); | 372 EXPECT_TRUE((hss.satisfiable_signals & MOJO_HANDLE_SIGNAL_READABLE)); |
480 | 373 |
481 std::string read_buffer(100, '\0'); | 374 std::string read_buffer(100, '\0'); |
482 uint32_t num_bytes = static_cast<uint32_t>(read_buffer.size()); | 375 uint32_t num_bytes = static_cast<uint32_t>(read_buffer.size()); |
483 EXPECT_EQ(MOJO_RESULT_OK, | 376 EXPECT_EQ(MOJO_RESULT_OK, |
484 mp->ReadMessage(0, | 377 mp->ReadMessage(0, |
485 UserPointer<void>(&read_buffer[0]), | 378 UserPointer<void>(&read_buffer[0]), |
486 MakeUserPointer(&num_bytes), | 379 MakeUserPointer(&num_bytes), |
487 NULL, | 380 NULL, |
(...skipping 16 matching lines...) Expand all Loading... |
504 EXPECT_EQ(MOJO_RESULT_OK, | 397 EXPECT_EQ(MOJO_RESULT_OK, |
505 mp->WriteMessage(0, | 398 mp->WriteMessage(0, |
506 UserPointer<const void>(&go3[0]), | 399 UserPointer<const void>(&go3[0]), |
507 static_cast<uint32_t>(go3.size()), | 400 static_cast<uint32_t>(go3.size()), |
508 NULL, | 401 NULL, |
509 MOJO_WRITE_MESSAGE_FLAG_NONE)); | 402 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
510 | 403 |
511 // Wait for |mp| to become readable, which should fail. | 404 // Wait for |mp| to become readable, which should fail. |
512 hss = HandleSignalsState(); | 405 hss = HandleSignalsState(); |
513 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, | 406 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, |
514 WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss)); | 407 test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss)); |
515 EXPECT_EQ(0u, hss.satisfied_signals); | 408 EXPECT_EQ(0u, hss.satisfied_signals); |
516 EXPECT_EQ(0u, hss.satisfiable_signals); | 409 EXPECT_EQ(0u, hss.satisfiable_signals); |
517 | 410 |
518 mp->Close(0); | 411 mp->Close(0); |
519 | 412 |
520 EXPECT_EQ(0, helper()->WaitForChildShutdown()); | 413 EXPECT_EQ(0, helper()->WaitForChildShutdown()); |
521 } | 414 } |
522 | 415 |
523 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(CheckPlatformHandleFile) { | 416 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(CheckPlatformHandleFile) { |
524 embedder::SimplePlatformSupport platform_support; | 417 embedder::SimplePlatformSupport platform_support; |
525 ChannelThread channel_thread(&platform_support); | 418 test::ChannelThread channel_thread(&platform_support); |
526 embedder::ScopedPlatformHandle client_platform_handle = | 419 embedder::ScopedPlatformHandle client_platform_handle = |
527 mojo::test::MultiprocessTestHelper::client_platform_handle.Pass(); | 420 mojo::test::MultiprocessTestHelper::client_platform_handle.Pass(); |
528 CHECK(client_platform_handle.is_valid()); | 421 CHECK(client_platform_handle.is_valid()); |
529 scoped_refptr<MessagePipe> mp(new MessagePipe( | 422 scoped_refptr<MessagePipe> mp(new MessagePipe( |
530 scoped_ptr<MessagePipeEndpoint>(new LocalMessagePipeEndpoint()), | 423 scoped_ptr<MessagePipeEndpoint>(new LocalMessagePipeEndpoint()), |
531 scoped_ptr<MessagePipeEndpoint>(new ProxyMessagePipeEndpoint()))); | 424 scoped_ptr<MessagePipeEndpoint>(new ProxyMessagePipeEndpoint()))); |
532 channel_thread.Start(client_platform_handle.Pass(), mp); | 425 channel_thread.Start(client_platform_handle.Pass(), mp); |
533 | 426 |
534 HandleSignalsState hss; | 427 HandleSignalsState hss; |
535 CHECK_EQ(WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss), | 428 CHECK_EQ(test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss), |
536 MOJO_RESULT_OK); | 429 MOJO_RESULT_OK); |
537 CHECK_EQ(hss.satisfied_signals, | 430 CHECK_EQ(hss.satisfied_signals, |
538 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE); | 431 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE); |
539 CHECK_EQ(hss.satisfiable_signals, | 432 CHECK_EQ(hss.satisfiable_signals, |
540 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE); | 433 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE); |
541 | 434 |
542 std::string read_buffer(100, '\0'); | 435 std::string read_buffer(100, '\0'); |
543 uint32_t num_bytes = static_cast<uint32_t>(read_buffer.size()); | 436 uint32_t num_bytes = static_cast<uint32_t>(read_buffer.size()); |
544 DispatcherVector dispatchers; | 437 DispatcherVector dispatchers; |
545 uint32_t num_dispatchers = 10; // Maximum number to receive. | 438 uint32_t num_dispatchers = 10; // Maximum number to receive. |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 &transports, | 511 &transports, |
619 MOJO_WRITE_MESSAGE_FLAG_NONE)); | 512 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
620 transport.End(); | 513 transport.End(); |
621 | 514 |
622 EXPECT_TRUE(dispatcher->HasOneRef()); | 515 EXPECT_TRUE(dispatcher->HasOneRef()); |
623 dispatcher = NULL; | 516 dispatcher = NULL; |
624 | 517 |
625 // Wait for it to become readable, which should fail. | 518 // Wait for it to become readable, which should fail. |
626 HandleSignalsState hss; | 519 HandleSignalsState hss; |
627 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, | 520 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, |
628 WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss)); | 521 test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss)); |
629 EXPECT_EQ(0u, hss.satisfied_signals); | 522 EXPECT_EQ(0u, hss.satisfied_signals); |
630 EXPECT_EQ(0u, hss.satisfiable_signals); | 523 EXPECT_EQ(0u, hss.satisfiable_signals); |
631 | 524 |
632 mp->Close(0); | 525 mp->Close(0); |
633 | 526 |
634 EXPECT_EQ(0, helper()->WaitForChildShutdown()); | 527 EXPECT_EQ(0, helper()->WaitForChildShutdown()); |
635 } | 528 } |
636 | 529 |
637 } // namespace | 530 } // namespace |
638 } // namespace system | 531 } // namespace system |
639 } // namespace mojo | 532 } // namespace mojo |
OLD | NEW |