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 <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 30 matching lines...) Expand all Loading... |
41 namespace system { | 41 namespace system { |
42 namespace { | 42 namespace { |
43 | 43 |
44 class RemoteMessagePipeTest : public testing::Test { | 44 class RemoteMessagePipeTest : public testing::Test { |
45 public: | 45 public: |
46 RemoteMessagePipeTest() : io_thread_(base::TestIOThread::kAutoStart) {} | 46 RemoteMessagePipeTest() : io_thread_(base::TestIOThread::kAutoStart) {} |
47 ~RemoteMessagePipeTest() override {} | 47 ~RemoteMessagePipeTest() override {} |
48 | 48 |
49 void SetUp() override { | 49 void SetUp() override { |
50 io_thread_.PostTaskAndWait( | 50 io_thread_.PostTaskAndWait( |
51 FROM_HERE, base::Bind(&RemoteMessagePipeTest::SetUpOnIOThread, | 51 FROM_HERE, |
52 base::Unretained(this))); | 52 base::Bind(&RemoteMessagePipeTest::SetUpOnIOThread, |
| 53 base::Unretained(this))); |
53 } | 54 } |
54 | 55 |
55 void TearDown() override { | 56 void TearDown() override { |
56 io_thread_.PostTaskAndWait( | 57 io_thread_.PostTaskAndWait( |
57 FROM_HERE, base::Bind(&RemoteMessagePipeTest::TearDownOnIOThread, | 58 FROM_HERE, |
58 base::Unretained(this))); | 59 base::Bind(&RemoteMessagePipeTest::TearDownOnIOThread, |
| 60 base::Unretained(this))); |
59 } | 61 } |
60 | 62 |
61 protected: | 63 protected: |
62 // This connects the two given |ChannelEndpoint|s. It assumes/requires that | 64 // This connects the two given |ChannelEndpoint|s. It assumes/requires that |
63 // this is the bootstrap case (i.e., no other message pipes have ever been | 65 // this is the bootstrap case (i.e., no other message pipes have ever been |
64 // hosted on the channel). | 66 // hosted on the channel). |
65 void BootstrapChannelEndpoints(scoped_refptr<ChannelEndpoint> ep0, | 67 void BootstrapChannelEndpoints(scoped_refptr<ChannelEndpoint> ep0, |
66 scoped_refptr<ChannelEndpoint> ep1) { | 68 scoped_refptr<ChannelEndpoint> ep1) { |
67 io_thread_.PostTaskAndWait( | 69 io_thread_.PostTaskAndWait( |
68 FROM_HERE, | 70 FROM_HERE, |
69 base::Bind(&RemoteMessagePipeTest::BootstrapChannelEndpointsOnIOThread, | 71 base::Bind(&RemoteMessagePipeTest::BootstrapChannelEndpointsOnIOThread, |
70 base::Unretained(this), ep0, ep1)); | 72 base::Unretained(this), |
| 73 ep0, |
| 74 ep1)); |
71 } | 75 } |
72 | 76 |
73 // This bootstraps |ep| on |channels_[channel_index]|. It assumes/requires | 77 // This bootstraps |ep| on |channels_[channel_index]|. It assumes/requires |
74 // that this is the bootstrap case (i.e., no message pipes have ever been | 78 // that this is the bootstrap case (i.e., no message pipes have ever been |
75 // hosted on the channel). This returns *without* waiting. | 79 // hosted on the channel). This returns *without* waiting. |
76 void BootstrapChannelEndpointNoWait(unsigned channel_index, | 80 void BootstrapChannelEndpointNoWait(unsigned channel_index, |
77 scoped_refptr<ChannelEndpoint> ep) { | 81 scoped_refptr<ChannelEndpoint> ep) { |
78 io_thread_.PostTask( | 82 io_thread_.PostTask( |
79 FROM_HERE, | 83 FROM_HERE, |
80 base::Bind(&RemoteMessagePipeTest::BootstrapChannelEndpointOnIOThread, | 84 base::Bind(&RemoteMessagePipeTest::BootstrapChannelEndpointOnIOThread, |
81 base::Unretained(this), channel_index, ep)); | 85 base::Unretained(this), |
| 86 channel_index, |
| 87 ep)); |
82 } | 88 } |
83 | 89 |
84 void RestoreInitialState() { | 90 void RestoreInitialState() { |
85 io_thread_.PostTaskAndWait( | 91 io_thread_.PostTaskAndWait( |
86 FROM_HERE, | 92 FROM_HERE, |
87 base::Bind(&RemoteMessagePipeTest::RestoreInitialStateOnIOThread, | 93 base::Bind(&RemoteMessagePipeTest::RestoreInitialStateOnIOThread, |
88 base::Unretained(this))); | 94 base::Unretained(this))); |
89 } | 95 } |
90 | 96 |
91 embedder::PlatformSupport* platform_support() { return &platform_support_; } | 97 embedder::PlatformSupport* platform_support() { return &platform_support_; } |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 // Write in one direction: MP 0, port 0 -> ... -> MP 1, port 1. | 191 // Write in one direction: MP 0, port 0 -> ... -> MP 1, port 1. |
186 | 192 |
187 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do | 193 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do |
188 // it later, it might already be readable.) | 194 // it later, it might already be readable.) |
189 waiter.Init(); | 195 waiter.Init(); |
190 ASSERT_EQ( | 196 ASSERT_EQ( |
191 MOJO_RESULT_OK, | 197 MOJO_RESULT_OK, |
192 mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); | 198 mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); |
193 | 199 |
194 // Write to MP 0, port 0. | 200 // Write to MP 0, port 0. |
195 EXPECT_EQ( | 201 EXPECT_EQ(MOJO_RESULT_OK, |
196 MOJO_RESULT_OK, | 202 mp0->WriteMessage(0, |
197 mp0->WriteMessage(0, UserPointer<const void>(kHello), sizeof(kHello), | 203 UserPointer<const void>(kHello), |
198 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); | 204 sizeof(kHello), |
| 205 nullptr, |
| 206 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
199 | 207 |
200 // Wait. | 208 // Wait. |
201 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); | 209 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); |
202 EXPECT_EQ(123u, context); | 210 EXPECT_EQ(123u, context); |
203 hss = HandleSignalsState(); | 211 hss = HandleSignalsState(); |
204 mp1->RemoveWaiter(1, &waiter, &hss); | 212 mp1->RemoveWaiter(1, &waiter, &hss); |
205 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 213 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
206 hss.satisfied_signals); | 214 hss.satisfied_signals); |
207 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 215 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
208 hss.satisfiable_signals); | 216 hss.satisfiable_signals); |
209 | 217 |
210 // Read from MP 1, port 1. | 218 // Read from MP 1, port 1. |
211 EXPECT_EQ(MOJO_RESULT_OK, | 219 EXPECT_EQ(MOJO_RESULT_OK, |
212 mp1->ReadMessage(1, UserPointer<void>(buffer), | 220 mp1->ReadMessage(1, |
213 MakeUserPointer(&buffer_size), nullptr, nullptr, | 221 UserPointer<void>(buffer), |
| 222 MakeUserPointer(&buffer_size), |
| 223 nullptr, |
| 224 nullptr, |
214 MOJO_READ_MESSAGE_FLAG_NONE)); | 225 MOJO_READ_MESSAGE_FLAG_NONE)); |
215 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(buffer_size)); | 226 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(buffer_size)); |
216 EXPECT_STREQ(kHello, buffer); | 227 EXPECT_STREQ(kHello, buffer); |
217 | 228 |
218 // Write in the other direction: MP 1, port 1 -> ... -> MP 0, port 0. | 229 // Write in the other direction: MP 1, port 1 -> ... -> MP 0, port 0. |
219 | 230 |
220 waiter.Init(); | 231 waiter.Init(); |
221 ASSERT_EQ( | 232 ASSERT_EQ( |
222 MOJO_RESULT_OK, | 233 MOJO_RESULT_OK, |
223 mp0->AddWaiter(0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 456, nullptr)); | 234 mp0->AddWaiter(0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 456, nullptr)); |
224 | 235 |
225 EXPECT_EQ( | 236 EXPECT_EQ(MOJO_RESULT_OK, |
226 MOJO_RESULT_OK, | 237 mp1->WriteMessage(1, |
227 mp1->WriteMessage(1, UserPointer<const void>(kWorld), sizeof(kWorld), | 238 UserPointer<const void>(kWorld), |
228 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); | 239 sizeof(kWorld), |
| 240 nullptr, |
| 241 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
229 | 242 |
230 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); | 243 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); |
231 EXPECT_EQ(456u, context); | 244 EXPECT_EQ(456u, context); |
232 hss = HandleSignalsState(); | 245 hss = HandleSignalsState(); |
233 mp0->RemoveWaiter(0, &waiter, &hss); | 246 mp0->RemoveWaiter(0, &waiter, &hss); |
234 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 247 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
235 hss.satisfied_signals); | 248 hss.satisfied_signals); |
236 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 249 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
237 hss.satisfiable_signals); | 250 hss.satisfiable_signals); |
238 | 251 |
239 buffer_size = static_cast<uint32_t>(sizeof(buffer)); | 252 buffer_size = static_cast<uint32_t>(sizeof(buffer)); |
240 EXPECT_EQ(MOJO_RESULT_OK, | 253 EXPECT_EQ(MOJO_RESULT_OK, |
241 mp0->ReadMessage(0, UserPointer<void>(buffer), | 254 mp0->ReadMessage(0, |
242 MakeUserPointer(&buffer_size), nullptr, nullptr, | 255 UserPointer<void>(buffer), |
| 256 MakeUserPointer(&buffer_size), |
| 257 nullptr, |
| 258 nullptr, |
243 MOJO_READ_MESSAGE_FLAG_NONE)); | 259 MOJO_READ_MESSAGE_FLAG_NONE)); |
244 EXPECT_EQ(sizeof(kWorld), static_cast<size_t>(buffer_size)); | 260 EXPECT_EQ(sizeof(kWorld), static_cast<size_t>(buffer_size)); |
245 EXPECT_STREQ(kWorld, buffer); | 261 EXPECT_STREQ(kWorld, buffer); |
246 | 262 |
247 // Close MP 0, port 0. | 263 // Close MP 0, port 0. |
248 mp0->Close(0); | 264 mp0->Close(0); |
249 | 265 |
250 // Try to wait for MP 1, port 1 to become readable. This will eventually fail | 266 // Try to wait for MP 1, port 1 to become readable. This will eventually fail |
251 // when it realizes that MP 0, port 0 has been closed. (It may also fail | 267 // when it realizes that MP 0, port 0 has been closed. (It may also fail |
252 // immediately.) | 268 // immediately.) |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 ASSERT_TRUE(channels(0)); | 313 ASSERT_TRUE(channels(0)); |
298 ChannelEndpointId remote_id = channels(0)->AttachAndRunEndpoint(ep2, false); | 314 ChannelEndpointId remote_id = channels(0)->AttachAndRunEndpoint(ep2, false); |
299 EXPECT_TRUE(remote_id.is_remote()); | 315 EXPECT_TRUE(remote_id.is_remote()); |
300 | 316 |
301 waiter.Init(); | 317 waiter.Init(); |
302 ASSERT_EQ( | 318 ASSERT_EQ( |
303 MOJO_RESULT_OK, | 319 MOJO_RESULT_OK, |
304 mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); | 320 mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); |
305 | 321 |
306 EXPECT_EQ(MOJO_RESULT_OK, | 322 EXPECT_EQ(MOJO_RESULT_OK, |
307 mp0->WriteMessage(0, UserPointer<const void>(&remote_id), | 323 mp0->WriteMessage(0, |
308 sizeof(remote_id), nullptr, | 324 UserPointer<const void>(&remote_id), |
| 325 sizeof(remote_id), |
| 326 nullptr, |
309 MOJO_WRITE_MESSAGE_FLAG_NONE)); | 327 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
310 | 328 |
311 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); | 329 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); |
312 EXPECT_EQ(123u, context); | 330 EXPECT_EQ(123u, context); |
313 hss = HandleSignalsState(); | 331 hss = HandleSignalsState(); |
314 mp1->RemoveWaiter(1, &waiter, &hss); | 332 mp1->RemoveWaiter(1, &waiter, &hss); |
315 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 333 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
316 hss.satisfied_signals); | 334 hss.satisfied_signals); |
317 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 335 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
318 hss.satisfiable_signals); | 336 hss.satisfiable_signals); |
319 | 337 |
320 ChannelEndpointId received_id; | 338 ChannelEndpointId received_id; |
321 buffer_size = static_cast<uint32_t>(sizeof(received_id)); | 339 buffer_size = static_cast<uint32_t>(sizeof(received_id)); |
322 EXPECT_EQ(MOJO_RESULT_OK, | 340 EXPECT_EQ(MOJO_RESULT_OK, |
323 mp1->ReadMessage(1, UserPointer<void>(&received_id), | 341 mp1->ReadMessage(1, |
324 MakeUserPointer(&buffer_size), nullptr, nullptr, | 342 UserPointer<void>(&received_id), |
| 343 MakeUserPointer(&buffer_size), |
| 344 nullptr, |
| 345 nullptr, |
325 MOJO_READ_MESSAGE_FLAG_NONE)); | 346 MOJO_READ_MESSAGE_FLAG_NONE)); |
326 EXPECT_EQ(sizeof(received_id), static_cast<size_t>(buffer_size)); | 347 EXPECT_EQ(sizeof(received_id), static_cast<size_t>(buffer_size)); |
327 EXPECT_EQ(remote_id, received_id); | 348 EXPECT_EQ(remote_id, received_id); |
328 | 349 |
329 // Warning: The local side of mp3 is port 0, not port 1. | 350 // Warning: The local side of mp3 is port 0, not port 1. |
330 scoped_refptr<MessagePipe> mp3 = | 351 scoped_refptr<MessagePipe> mp3 = |
331 channels(1)->PassIncomingMessagePipe(received_id); | 352 channels(1)->PassIncomingMessagePipe(received_id); |
332 ASSERT_TRUE(mp3.get()); | 353 ASSERT_TRUE(mp3.get()); |
333 | 354 |
334 // Write: MP 2, port 0 -> MP 3, port 1. | 355 // Write: MP 2, port 0 -> MP 3, port 1. |
335 | 356 |
336 waiter.Init(); | 357 waiter.Init(); |
337 ASSERT_EQ( | 358 ASSERT_EQ( |
338 MOJO_RESULT_OK, | 359 MOJO_RESULT_OK, |
339 mp3->AddWaiter(0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 789, nullptr)); | 360 mp3->AddWaiter(0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 789, nullptr)); |
340 | 361 |
341 EXPECT_EQ( | 362 EXPECT_EQ(MOJO_RESULT_OK, |
342 MOJO_RESULT_OK, | 363 mp2->WriteMessage(0, |
343 mp2->WriteMessage(0, UserPointer<const void>(kHello), sizeof(kHello), | 364 UserPointer<const void>(kHello), |
344 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); | 365 sizeof(kHello), |
| 366 nullptr, |
| 367 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
345 | 368 |
346 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); | 369 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); |
347 EXPECT_EQ(789u, context); | 370 EXPECT_EQ(789u, context); |
348 hss = HandleSignalsState(); | 371 hss = HandleSignalsState(); |
349 mp3->RemoveWaiter(0, &waiter, &hss); | 372 mp3->RemoveWaiter(0, &waiter, &hss); |
350 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 373 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
351 hss.satisfied_signals); | 374 hss.satisfied_signals); |
352 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 375 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
353 hss.satisfiable_signals); | 376 hss.satisfiable_signals); |
354 | 377 |
355 // Make sure there's nothing on MP 0, port 0 or MP 1, port 1 or MP 2, port 0. | 378 // Make sure there's nothing on MP 0, port 0 or MP 1, port 1 or MP 2, port 0. |
356 buffer_size = static_cast<uint32_t>(sizeof(buffer)); | 379 buffer_size = static_cast<uint32_t>(sizeof(buffer)); |
357 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT, | 380 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT, |
358 mp0->ReadMessage(0, UserPointer<void>(buffer), | 381 mp0->ReadMessage(0, |
359 MakeUserPointer(&buffer_size), nullptr, nullptr, | 382 UserPointer<void>(buffer), |
| 383 MakeUserPointer(&buffer_size), |
| 384 nullptr, |
| 385 nullptr, |
360 MOJO_READ_MESSAGE_FLAG_NONE)); | 386 MOJO_READ_MESSAGE_FLAG_NONE)); |
361 buffer_size = static_cast<uint32_t>(sizeof(buffer)); | 387 buffer_size = static_cast<uint32_t>(sizeof(buffer)); |
362 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT, | 388 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT, |
363 mp1->ReadMessage(1, UserPointer<void>(buffer), | 389 mp1->ReadMessage(1, |
364 MakeUserPointer(&buffer_size), nullptr, nullptr, | 390 UserPointer<void>(buffer), |
| 391 MakeUserPointer(&buffer_size), |
| 392 nullptr, |
| 393 nullptr, |
365 MOJO_READ_MESSAGE_FLAG_NONE)); | 394 MOJO_READ_MESSAGE_FLAG_NONE)); |
366 buffer_size = static_cast<uint32_t>(sizeof(buffer)); | 395 buffer_size = static_cast<uint32_t>(sizeof(buffer)); |
367 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT, | 396 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT, |
368 mp2->ReadMessage(0, UserPointer<void>(buffer), | 397 mp2->ReadMessage(0, |
369 MakeUserPointer(&buffer_size), nullptr, nullptr, | 398 UserPointer<void>(buffer), |
| 399 MakeUserPointer(&buffer_size), |
| 400 nullptr, |
| 401 nullptr, |
370 MOJO_READ_MESSAGE_FLAG_NONE)); | 402 MOJO_READ_MESSAGE_FLAG_NONE)); |
371 | 403 |
372 // Read from MP 3, port 1. | 404 // Read from MP 3, port 1. |
373 buffer_size = static_cast<uint32_t>(sizeof(buffer)); | 405 buffer_size = static_cast<uint32_t>(sizeof(buffer)); |
374 EXPECT_EQ(MOJO_RESULT_OK, | 406 EXPECT_EQ(MOJO_RESULT_OK, |
375 mp3->ReadMessage(0, UserPointer<void>(buffer), | 407 mp3->ReadMessage(0, |
376 MakeUserPointer(&buffer_size), nullptr, nullptr, | 408 UserPointer<void>(buffer), |
| 409 MakeUserPointer(&buffer_size), |
| 410 nullptr, |
| 411 nullptr, |
377 MOJO_READ_MESSAGE_FLAG_NONE)); | 412 MOJO_READ_MESSAGE_FLAG_NONE)); |
378 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(buffer_size)); | 413 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(buffer_size)); |
379 EXPECT_STREQ(kHello, buffer); | 414 EXPECT_STREQ(kHello, buffer); |
380 | 415 |
381 // Write: MP 0, port 0 -> MP 1, port 1 again. | 416 // Write: MP 0, port 0 -> MP 1, port 1 again. |
382 | 417 |
383 waiter.Init(); | 418 waiter.Init(); |
384 ASSERT_EQ( | 419 ASSERT_EQ( |
385 MOJO_RESULT_OK, | 420 MOJO_RESULT_OK, |
386 mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); | 421 mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); |
387 | 422 |
388 EXPECT_EQ( | 423 EXPECT_EQ(MOJO_RESULT_OK, |
389 MOJO_RESULT_OK, | 424 mp0->WriteMessage(0, |
390 mp0->WriteMessage(0, UserPointer<const void>(kWorld), sizeof(kWorld), | 425 UserPointer<const void>(kWorld), |
391 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); | 426 sizeof(kWorld), |
| 427 nullptr, |
| 428 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
392 | 429 |
393 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); | 430 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); |
394 EXPECT_EQ(123u, context); | 431 EXPECT_EQ(123u, context); |
395 hss = HandleSignalsState(); | 432 hss = HandleSignalsState(); |
396 mp1->RemoveWaiter(1, &waiter, &hss); | 433 mp1->RemoveWaiter(1, &waiter, &hss); |
397 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 434 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
398 hss.satisfied_signals); | 435 hss.satisfied_signals); |
399 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 436 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
400 hss.satisfiable_signals); | 437 hss.satisfiable_signals); |
401 | 438 |
402 // Make sure there's nothing on the other ports. | 439 // Make sure there's nothing on the other ports. |
403 buffer_size = static_cast<uint32_t>(sizeof(buffer)); | 440 buffer_size = static_cast<uint32_t>(sizeof(buffer)); |
404 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT, | 441 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT, |
405 mp0->ReadMessage(0, UserPointer<void>(buffer), | 442 mp0->ReadMessage(0, |
406 MakeUserPointer(&buffer_size), nullptr, nullptr, | 443 UserPointer<void>(buffer), |
| 444 MakeUserPointer(&buffer_size), |
| 445 nullptr, |
| 446 nullptr, |
407 MOJO_READ_MESSAGE_FLAG_NONE)); | 447 MOJO_READ_MESSAGE_FLAG_NONE)); |
408 buffer_size = static_cast<uint32_t>(sizeof(buffer)); | 448 buffer_size = static_cast<uint32_t>(sizeof(buffer)); |
409 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT, | 449 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT, |
410 mp2->ReadMessage(0, UserPointer<void>(buffer), | 450 mp2->ReadMessage(0, |
411 MakeUserPointer(&buffer_size), nullptr, nullptr, | 451 UserPointer<void>(buffer), |
| 452 MakeUserPointer(&buffer_size), |
| 453 nullptr, |
| 454 nullptr, |
412 MOJO_READ_MESSAGE_FLAG_NONE)); | 455 MOJO_READ_MESSAGE_FLAG_NONE)); |
413 buffer_size = static_cast<uint32_t>(sizeof(buffer)); | 456 buffer_size = static_cast<uint32_t>(sizeof(buffer)); |
414 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT, | 457 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT, |
415 mp3->ReadMessage(0, UserPointer<void>(buffer), | 458 mp3->ReadMessage(0, |
416 MakeUserPointer(&buffer_size), nullptr, nullptr, | 459 UserPointer<void>(buffer), |
| 460 MakeUserPointer(&buffer_size), |
| 461 nullptr, |
| 462 nullptr, |
417 MOJO_READ_MESSAGE_FLAG_NONE)); | 463 MOJO_READ_MESSAGE_FLAG_NONE)); |
418 | 464 |
419 buffer_size = static_cast<uint32_t>(sizeof(buffer)); | 465 buffer_size = static_cast<uint32_t>(sizeof(buffer)); |
420 EXPECT_EQ(MOJO_RESULT_OK, | 466 EXPECT_EQ(MOJO_RESULT_OK, |
421 mp1->ReadMessage(1, UserPointer<void>(buffer), | 467 mp1->ReadMessage(1, |
422 MakeUserPointer(&buffer_size), nullptr, nullptr, | 468 UserPointer<void>(buffer), |
| 469 MakeUserPointer(&buffer_size), |
| 470 nullptr, |
| 471 nullptr, |
423 MOJO_READ_MESSAGE_FLAG_NONE)); | 472 MOJO_READ_MESSAGE_FLAG_NONE)); |
424 EXPECT_EQ(sizeof(kWorld), static_cast<size_t>(buffer_size)); | 473 EXPECT_EQ(sizeof(kWorld), static_cast<size_t>(buffer_size)); |
425 EXPECT_STREQ(kWorld, buffer); | 474 EXPECT_STREQ(kWorld, buffer); |
426 | 475 |
427 mp0->Close(0); | 476 mp0->Close(0); |
428 mp1->Close(1); | 477 mp1->Close(1); |
429 mp2->Close(0); | 478 mp2->Close(0); |
430 mp3->Close(0); | 479 mp3->Close(0); |
431 } | 480 } |
432 | 481 |
433 TEST_F(RemoteMessagePipeTest, CloseBeforeAttachAndRun) { | 482 TEST_F(RemoteMessagePipeTest, CloseBeforeAttachAndRun) { |
434 static const char kHello[] = "hello"; | 483 static const char kHello[] = "hello"; |
435 char buffer[100] = {0}; | 484 char buffer[100] = {0}; |
436 uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer)); | 485 uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer)); |
437 Waiter waiter; | 486 Waiter waiter; |
438 HandleSignalsState hss; | 487 HandleSignalsState hss; |
439 uint32_t context = 0; | 488 uint32_t context = 0; |
440 | 489 |
441 // Connect message pipes. MP 0, port 1 will be attached to channel 0 and | 490 // Connect message pipes. MP 0, port 1 will be attached to channel 0 and |
442 // connected to MP 1, port 0, which will be attached to channel 1. This leaves | 491 // connected to MP 1, port 0, which will be attached to channel 1. This leaves |
443 // MP 0, port 0 and MP 1, port 1 as the "user-facing" endpoints. | 492 // MP 0, port 0 and MP 1, port 1 as the "user-facing" endpoints. |
444 | 493 |
445 scoped_refptr<ChannelEndpoint> ep0; | 494 scoped_refptr<ChannelEndpoint> ep0; |
446 scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy(&ep0)); | 495 scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy(&ep0)); |
447 | 496 |
448 // Write to MP 0, port 0. | 497 // Write to MP 0, port 0. |
449 EXPECT_EQ( | 498 EXPECT_EQ(MOJO_RESULT_OK, |
450 MOJO_RESULT_OK, | 499 mp0->WriteMessage(0, |
451 mp0->WriteMessage(0, UserPointer<const void>(kHello), sizeof(kHello), | 500 UserPointer<const void>(kHello), |
452 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); | 501 sizeof(kHello), |
| 502 nullptr, |
| 503 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
453 | 504 |
454 // Close MP 0, port 0 before it's even been attached to the channel and run. | 505 // Close MP 0, port 0 before it's even been attached to the channel and run. |
455 mp0->Close(0); | 506 mp0->Close(0); |
456 | 507 |
457 BootstrapChannelEndpointNoWait(0, ep0); | 508 BootstrapChannelEndpointNoWait(0, ep0); |
458 | 509 |
459 scoped_refptr<ChannelEndpoint> ep1; | 510 scoped_refptr<ChannelEndpoint> ep1; |
460 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1)); | 511 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1)); |
461 | 512 |
462 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do | 513 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do |
(...skipping 12 matching lines...) Expand all Loading... |
475 // Note: MP 1, port 1 should definitely should be readable, but it may or may | 526 // Note: MP 1, port 1 should definitely should be readable, but it may or may |
476 // not appear as writable (there's a race, and it may not have noticed that | 527 // not appear as writable (there's a race, and it may not have noticed that |
477 // the other side was closed yet -- e.g., inserting a sleep here would make it | 528 // the other side was closed yet -- e.g., inserting a sleep here would make it |
478 // much more likely to notice that it's no longer writable). | 529 // much more likely to notice that it's no longer writable). |
479 mp1->RemoveWaiter(1, &waiter, &hss); | 530 mp1->RemoveWaiter(1, &waiter, &hss); |
480 EXPECT_TRUE((hss.satisfied_signals & MOJO_HANDLE_SIGNAL_READABLE)); | 531 EXPECT_TRUE((hss.satisfied_signals & MOJO_HANDLE_SIGNAL_READABLE)); |
481 EXPECT_TRUE((hss.satisfiable_signals & MOJO_HANDLE_SIGNAL_READABLE)); | 532 EXPECT_TRUE((hss.satisfiable_signals & MOJO_HANDLE_SIGNAL_READABLE)); |
482 | 533 |
483 // Read from MP 1, port 1. | 534 // Read from MP 1, port 1. |
484 EXPECT_EQ(MOJO_RESULT_OK, | 535 EXPECT_EQ(MOJO_RESULT_OK, |
485 mp1->ReadMessage(1, UserPointer<void>(buffer), | 536 mp1->ReadMessage(1, |
486 MakeUserPointer(&buffer_size), nullptr, nullptr, | 537 UserPointer<void>(buffer), |
| 538 MakeUserPointer(&buffer_size), |
| 539 nullptr, |
| 540 nullptr, |
487 MOJO_READ_MESSAGE_FLAG_NONE)); | 541 MOJO_READ_MESSAGE_FLAG_NONE)); |
488 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(buffer_size)); | 542 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(buffer_size)); |
489 EXPECT_STREQ(kHello, buffer); | 543 EXPECT_STREQ(kHello, buffer); |
490 | 544 |
491 // And MP 1, port 1. | 545 // And MP 1, port 1. |
492 mp1->Close(1); | 546 mp1->Close(1); |
493 } | 547 } |
494 | 548 |
495 TEST_F(RemoteMessagePipeTest, CloseBeforeConnect) { | 549 TEST_F(RemoteMessagePipeTest, CloseBeforeConnect) { |
496 static const char kHello[] = "hello"; | 550 static const char kHello[] = "hello"; |
497 char buffer[100] = {0}; | 551 char buffer[100] = {0}; |
498 uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer)); | 552 uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer)); |
499 Waiter waiter; | 553 Waiter waiter; |
500 HandleSignalsState hss; | 554 HandleSignalsState hss; |
501 uint32_t context = 0; | 555 uint32_t context = 0; |
502 | 556 |
503 // Connect message pipes. MP 0, port 1 will be attached to channel 0 and | 557 // Connect message pipes. MP 0, port 1 will be attached to channel 0 and |
504 // connected to MP 1, port 0, which will be attached to channel 1. This leaves | 558 // connected to MP 1, port 0, which will be attached to channel 1. This leaves |
505 // MP 0, port 0 and MP 1, port 1 as the "user-facing" endpoints. | 559 // MP 0, port 0 and MP 1, port 1 as the "user-facing" endpoints. |
506 | 560 |
507 scoped_refptr<ChannelEndpoint> ep0; | 561 scoped_refptr<ChannelEndpoint> ep0; |
508 scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy(&ep0)); | 562 scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy(&ep0)); |
509 | 563 |
510 // Write to MP 0, port 0. | 564 // Write to MP 0, port 0. |
511 EXPECT_EQ( | 565 EXPECT_EQ(MOJO_RESULT_OK, |
512 MOJO_RESULT_OK, | 566 mp0->WriteMessage(0, |
513 mp0->WriteMessage(0, UserPointer<const void>(kHello), sizeof(kHello), | 567 UserPointer<const void>(kHello), |
514 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); | 568 sizeof(kHello), |
| 569 nullptr, |
| 570 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
515 | 571 |
516 BootstrapChannelEndpointNoWait(0, ep0); | 572 BootstrapChannelEndpointNoWait(0, ep0); |
517 | 573 |
518 // Close MP 0, port 0 before channel 1 is even connected. | 574 // Close MP 0, port 0 before channel 1 is even connected. |
519 mp0->Close(0); | 575 mp0->Close(0); |
520 | 576 |
521 scoped_refptr<ChannelEndpoint> ep1; | 577 scoped_refptr<ChannelEndpoint> ep1; |
522 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1)); | 578 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1)); |
523 | 579 |
524 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do | 580 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do |
(...skipping 12 matching lines...) Expand all Loading... |
537 // Note: MP 1, port 1 should definitely should be readable, but it may or may | 593 // Note: MP 1, port 1 should definitely should be readable, but it may or may |
538 // not appear as writable (there's a race, and it may not have noticed that | 594 // not appear as writable (there's a race, and it may not have noticed that |
539 // the other side was closed yet -- e.g., inserting a sleep here would make it | 595 // the other side was closed yet -- e.g., inserting a sleep here would make it |
540 // much more likely to notice that it's no longer writable). | 596 // much more likely to notice that it's no longer writable). |
541 mp1->RemoveWaiter(1, &waiter, &hss); | 597 mp1->RemoveWaiter(1, &waiter, &hss); |
542 EXPECT_TRUE((hss.satisfied_signals & MOJO_HANDLE_SIGNAL_READABLE)); | 598 EXPECT_TRUE((hss.satisfied_signals & MOJO_HANDLE_SIGNAL_READABLE)); |
543 EXPECT_TRUE((hss.satisfiable_signals & MOJO_HANDLE_SIGNAL_READABLE)); | 599 EXPECT_TRUE((hss.satisfiable_signals & MOJO_HANDLE_SIGNAL_READABLE)); |
544 | 600 |
545 // Read from MP 1, port 1. | 601 // Read from MP 1, port 1. |
546 EXPECT_EQ(MOJO_RESULT_OK, | 602 EXPECT_EQ(MOJO_RESULT_OK, |
547 mp1->ReadMessage(1, UserPointer<void>(buffer), | 603 mp1->ReadMessage(1, |
548 MakeUserPointer(&buffer_size), nullptr, nullptr, | 604 UserPointer<void>(buffer), |
| 605 MakeUserPointer(&buffer_size), |
| 606 nullptr, |
| 607 nullptr, |
549 MOJO_READ_MESSAGE_FLAG_NONE)); | 608 MOJO_READ_MESSAGE_FLAG_NONE)); |
550 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(buffer_size)); | 609 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(buffer_size)); |
551 EXPECT_STREQ(kHello, buffer); | 610 EXPECT_STREQ(kHello, buffer); |
552 | 611 |
553 // And MP 1, port 1. | 612 // And MP 1, port 1. |
554 mp1->Close(1); | 613 mp1->Close(1); |
555 } | 614 } |
556 | 615 |
557 TEST_F(RemoteMessagePipeTest, HandlePassing) { | 616 TEST_F(RemoteMessagePipeTest, HandlePassing) { |
558 static const char kHello[] = "hello"; | 617 static const char kHello[] = "hello"; |
(...skipping 21 matching lines...) Expand all Loading... |
580 mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); | 639 mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); |
581 | 640 |
582 // Write to MP 0, port 0. | 641 // Write to MP 0, port 0. |
583 { | 642 { |
584 DispatcherTransport transport( | 643 DispatcherTransport transport( |
585 test::DispatcherTryStartTransport(dispatcher.get())); | 644 test::DispatcherTryStartTransport(dispatcher.get())); |
586 EXPECT_TRUE(transport.is_valid()); | 645 EXPECT_TRUE(transport.is_valid()); |
587 | 646 |
588 std::vector<DispatcherTransport> transports; | 647 std::vector<DispatcherTransport> transports; |
589 transports.push_back(transport); | 648 transports.push_back(transport); |
590 EXPECT_EQ( | 649 EXPECT_EQ(MOJO_RESULT_OK, |
591 MOJO_RESULT_OK, | 650 mp0->WriteMessage(0, |
592 mp0->WriteMessage(0, UserPointer<const void>(kHello), sizeof(kHello), | 651 UserPointer<const void>(kHello), |
593 &transports, MOJO_WRITE_MESSAGE_FLAG_NONE)); | 652 sizeof(kHello), |
| 653 &transports, |
| 654 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
594 transport.End(); | 655 transport.End(); |
595 | 656 |
596 // |dispatcher| should have been closed. This is |DCHECK()|ed when the | 657 // |dispatcher| should have been closed. This is |DCHECK()|ed when the |
597 // |dispatcher| is destroyed. | 658 // |dispatcher| is destroyed. |
598 EXPECT_TRUE(dispatcher->HasOneRef()); | 659 EXPECT_TRUE(dispatcher->HasOneRef()); |
599 dispatcher = nullptr; | 660 dispatcher = nullptr; |
600 } | 661 } |
601 | 662 |
602 // Wait. | 663 // Wait. |
603 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); | 664 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); |
604 EXPECT_EQ(123u, context); | 665 EXPECT_EQ(123u, context); |
605 hss = HandleSignalsState(); | 666 hss = HandleSignalsState(); |
606 mp1->RemoveWaiter(1, &waiter, &hss); | 667 mp1->RemoveWaiter(1, &waiter, &hss); |
607 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 668 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
608 hss.satisfied_signals); | 669 hss.satisfied_signals); |
609 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 670 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
610 hss.satisfiable_signals); | 671 hss.satisfiable_signals); |
611 | 672 |
612 // Read from MP 1, port 1. | 673 // Read from MP 1, port 1. |
613 char read_buffer[100] = {0}; | 674 char read_buffer[100] = {0}; |
614 uint32_t read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer)); | 675 uint32_t read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer)); |
615 DispatcherVector read_dispatchers; | 676 DispatcherVector read_dispatchers; |
616 uint32_t read_num_dispatchers = 10; // Maximum to get. | 677 uint32_t read_num_dispatchers = 10; // Maximum to get. |
617 EXPECT_EQ( | 678 EXPECT_EQ(MOJO_RESULT_OK, |
618 MOJO_RESULT_OK, | 679 mp1->ReadMessage(1, |
619 mp1->ReadMessage(1, UserPointer<void>(read_buffer), | 680 UserPointer<void>(read_buffer), |
620 MakeUserPointer(&read_buffer_size), &read_dispatchers, | 681 MakeUserPointer(&read_buffer_size), |
621 &read_num_dispatchers, MOJO_READ_MESSAGE_FLAG_NONE)); | 682 &read_dispatchers, |
| 683 &read_num_dispatchers, |
| 684 MOJO_READ_MESSAGE_FLAG_NONE)); |
622 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size)); | 685 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size)); |
623 EXPECT_STREQ(kHello, read_buffer); | 686 EXPECT_STREQ(kHello, read_buffer); |
624 EXPECT_EQ(1u, read_dispatchers.size()); | 687 EXPECT_EQ(1u, read_dispatchers.size()); |
625 EXPECT_EQ(1u, read_num_dispatchers); | 688 EXPECT_EQ(1u, read_num_dispatchers); |
626 ASSERT_TRUE(read_dispatchers[0].get()); | 689 ASSERT_TRUE(read_dispatchers[0].get()); |
627 EXPECT_TRUE(read_dispatchers[0]->HasOneRef()); | 690 EXPECT_TRUE(read_dispatchers[0]->HasOneRef()); |
628 | 691 |
629 EXPECT_EQ(Dispatcher::kTypeMessagePipe, read_dispatchers[0]->GetType()); | 692 EXPECT_EQ(Dispatcher::kTypeMessagePipe, read_dispatchers[0]->GetType()); |
630 dispatcher = static_cast<MessagePipeDispatcher*>(read_dispatchers[0].get()); | 693 dispatcher = static_cast<MessagePipeDispatcher*>(read_dispatchers[0].get()); |
631 | 694 |
632 // Add the waiter now, before it becomes readable to avoid a race. | 695 // Add the waiter now, before it becomes readable to avoid a race. |
633 waiter.Init(); | 696 waiter.Init(); |
634 ASSERT_EQ(MOJO_RESULT_OK, | 697 ASSERT_EQ(MOJO_RESULT_OK, |
635 dispatcher->AddWaiter(&waiter, MOJO_HANDLE_SIGNAL_READABLE, 456, | 698 dispatcher->AddWaiter( |
636 nullptr)); | 699 &waiter, MOJO_HANDLE_SIGNAL_READABLE, 456, nullptr)); |
637 | 700 |
638 // Write to "local_mp", port 1. | 701 // Write to "local_mp", port 1. |
639 EXPECT_EQ( | 702 EXPECT_EQ(MOJO_RESULT_OK, |
640 MOJO_RESULT_OK, | 703 local_mp->WriteMessage(1, |
641 local_mp->WriteMessage(1, UserPointer<const void>(kHello), sizeof(kHello), | 704 UserPointer<const void>(kHello), |
642 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); | 705 sizeof(kHello), |
| 706 nullptr, |
| 707 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
643 | 708 |
644 // TODO(vtl): FIXME -- We (racily) crash if I close |dispatcher| immediately | 709 // TODO(vtl): FIXME -- We (racily) crash if I close |dispatcher| immediately |
645 // here. (We don't crash if I sleep and then close.) | 710 // here. (We don't crash if I sleep and then close.) |
646 | 711 |
647 // Wait for the dispatcher to become readable. | 712 // Wait for the dispatcher to become readable. |
648 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); | 713 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); |
649 EXPECT_EQ(456u, context); | 714 EXPECT_EQ(456u, context); |
650 hss = HandleSignalsState(); | 715 hss = HandleSignalsState(); |
651 dispatcher->RemoveWaiter(&waiter, &hss); | 716 dispatcher->RemoveWaiter(&waiter, &hss); |
652 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 717 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
653 hss.satisfied_signals); | 718 hss.satisfied_signals); |
654 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 719 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
655 hss.satisfiable_signals); | 720 hss.satisfiable_signals); |
656 | 721 |
657 // Read from the dispatcher. | 722 // Read from the dispatcher. |
658 memset(read_buffer, 0, sizeof(read_buffer)); | 723 memset(read_buffer, 0, sizeof(read_buffer)); |
659 read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer)); | 724 read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer)); |
660 EXPECT_EQ(MOJO_RESULT_OK, | 725 EXPECT_EQ(MOJO_RESULT_OK, |
661 dispatcher->ReadMessage(UserPointer<void>(read_buffer), | 726 dispatcher->ReadMessage(UserPointer<void>(read_buffer), |
662 MakeUserPointer(&read_buffer_size), 0, | 727 MakeUserPointer(&read_buffer_size), |
663 nullptr, MOJO_READ_MESSAGE_FLAG_NONE)); | 728 0, |
| 729 nullptr, |
| 730 MOJO_READ_MESSAGE_FLAG_NONE)); |
664 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size)); | 731 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size)); |
665 EXPECT_STREQ(kHello, read_buffer); | 732 EXPECT_STREQ(kHello, read_buffer); |
666 | 733 |
667 // Prepare to wait on "local_mp", port 1. | 734 // Prepare to wait on "local_mp", port 1. |
668 waiter.Init(); | 735 waiter.Init(); |
669 ASSERT_EQ(MOJO_RESULT_OK, | 736 ASSERT_EQ(MOJO_RESULT_OK, |
670 local_mp->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 789, | 737 local_mp->AddWaiter( |
671 nullptr)); | 738 1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 789, nullptr)); |
672 | 739 |
673 // Write to the dispatcher. | 740 // Write to the dispatcher. |
674 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->WriteMessage( | 741 EXPECT_EQ(MOJO_RESULT_OK, |
675 UserPointer<const void>(kHello), sizeof(kHello), | 742 dispatcher->WriteMessage(UserPointer<const void>(kHello), |
676 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); | 743 sizeof(kHello), |
| 744 nullptr, |
| 745 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
677 | 746 |
678 // Wait. | 747 // Wait. |
679 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); | 748 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); |
680 EXPECT_EQ(789u, context); | 749 EXPECT_EQ(789u, context); |
681 hss = HandleSignalsState(); | 750 hss = HandleSignalsState(); |
682 local_mp->RemoveWaiter(1, &waiter, &hss); | 751 local_mp->RemoveWaiter(1, &waiter, &hss); |
683 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 752 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
684 hss.satisfied_signals); | 753 hss.satisfied_signals); |
685 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 754 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
686 hss.satisfiable_signals); | 755 hss.satisfiable_signals); |
687 | 756 |
688 // Read from "local_mp", port 1. | 757 // Read from "local_mp", port 1. |
689 memset(read_buffer, 0, sizeof(read_buffer)); | 758 memset(read_buffer, 0, sizeof(read_buffer)); |
690 read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer)); | 759 read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer)); |
691 EXPECT_EQ(MOJO_RESULT_OK, | 760 EXPECT_EQ(MOJO_RESULT_OK, |
692 local_mp->ReadMessage(1, UserPointer<void>(read_buffer), | 761 local_mp->ReadMessage(1, |
693 MakeUserPointer(&read_buffer_size), nullptr, | 762 UserPointer<void>(read_buffer), |
694 nullptr, MOJO_READ_MESSAGE_FLAG_NONE)); | 763 MakeUserPointer(&read_buffer_size), |
| 764 nullptr, |
| 765 nullptr, |
| 766 MOJO_READ_MESSAGE_FLAG_NONE)); |
695 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size)); | 767 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size)); |
696 EXPECT_STREQ(kHello, read_buffer); | 768 EXPECT_STREQ(kHello, read_buffer); |
697 | 769 |
698 // TODO(vtl): Also test that messages queued up before the handle was sent are | 770 // TODO(vtl): Also test that messages queued up before the handle was sent are |
699 // delivered properly. | 771 // delivered properly. |
700 | 772 |
701 // Close everything that belongs to us. | 773 // Close everything that belongs to us. |
702 mp0->Close(0); | 774 mp0->Close(0); |
703 mp1->Close(1); | 775 mp1->Close(1); |
704 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); | 776 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); |
(...skipping 12 matching lines...) Expand all Loading... |
717 scoped_refptr<MessagePipeDispatcher> dispatcher( | 789 scoped_refptr<MessagePipeDispatcher> dispatcher( |
718 new MessagePipeDispatcher(MessagePipeDispatcher::kDefaultCreateOptions)); | 790 new MessagePipeDispatcher(MessagePipeDispatcher::kDefaultCreateOptions)); |
719 scoped_refptr<MessagePipe> local_mp(MessagePipe::CreateLocalLocal()); | 791 scoped_refptr<MessagePipe> local_mp(MessagePipe::CreateLocalLocal()); |
720 dispatcher->Init(local_mp, 0); | 792 dispatcher->Init(local_mp, 0); |
721 | 793 |
722 hss = local_mp->GetHandleSignalsState(0); | 794 hss = local_mp->GetHandleSignalsState(0); |
723 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals); | 795 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals); |
724 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 796 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
725 hss.satisfiable_signals); | 797 hss.satisfiable_signals); |
726 // Write to the other end (|local_mp|, port 1), and then close it. | 798 // Write to the other end (|local_mp|, port 1), and then close it. |
727 EXPECT_EQ( | 799 EXPECT_EQ(MOJO_RESULT_OK, |
728 MOJO_RESULT_OK, | 800 local_mp->WriteMessage(1, |
729 local_mp->WriteMessage(1, UserPointer<const void>(kHello), sizeof(kHello), | 801 UserPointer<const void>(kHello), |
730 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); | 802 sizeof(kHello), |
| 803 nullptr, |
| 804 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
731 hss = local_mp->GetHandleSignalsState(0); | 805 hss = local_mp->GetHandleSignalsState(0); |
732 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 806 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
733 hss.satisfied_signals); | 807 hss.satisfied_signals); |
734 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 808 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
735 hss.satisfiable_signals); | 809 hss.satisfiable_signals); |
736 // Then the second message.... | 810 // Then the second message.... |
737 EXPECT_EQ( | 811 EXPECT_EQ(MOJO_RESULT_OK, |
738 MOJO_RESULT_OK, | 812 local_mp->WriteMessage(1, |
739 local_mp->WriteMessage(1, UserPointer<const void>(kWorld), sizeof(kWorld), | 813 UserPointer<const void>(kWorld), |
740 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); | 814 sizeof(kWorld), |
| 815 nullptr, |
| 816 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
741 hss = local_mp->GetHandleSignalsState(0); | 817 hss = local_mp->GetHandleSignalsState(0); |
742 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 818 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
743 hss.satisfied_signals); | 819 hss.satisfied_signals); |
744 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 820 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
745 hss.satisfiable_signals); | 821 hss.satisfiable_signals); |
746 // Then close it. | 822 // Then close it. |
747 local_mp->Close(1); | 823 local_mp->Close(1); |
748 | 824 |
749 scoped_refptr<ChannelEndpoint> ep0; | 825 scoped_refptr<ChannelEndpoint> ep0; |
750 scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy(&ep0)); | 826 scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy(&ep0)); |
751 scoped_refptr<ChannelEndpoint> ep1; | 827 scoped_refptr<ChannelEndpoint> ep1; |
752 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1)); | 828 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1)); |
753 BootstrapChannelEndpoints(ep0, ep1); | 829 BootstrapChannelEndpoints(ep0, ep1); |
754 | 830 |
755 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do | 831 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do |
756 // it later, it might already be readable.) | 832 // it later, it might already be readable.) |
757 waiter.Init(); | 833 waiter.Init(); |
758 ASSERT_EQ( | 834 ASSERT_EQ( |
759 MOJO_RESULT_OK, | 835 MOJO_RESULT_OK, |
760 mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); | 836 mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); |
761 | 837 |
762 // Write to MP 0, port 0. | 838 // Write to MP 0, port 0. |
763 { | 839 { |
764 DispatcherTransport transport( | 840 DispatcherTransport transport( |
765 test::DispatcherTryStartTransport(dispatcher.get())); | 841 test::DispatcherTryStartTransport(dispatcher.get())); |
766 EXPECT_TRUE(transport.is_valid()); | 842 EXPECT_TRUE(transport.is_valid()); |
767 | 843 |
768 std::vector<DispatcherTransport> transports; | 844 std::vector<DispatcherTransport> transports; |
769 transports.push_back(transport); | 845 transports.push_back(transport); |
770 EXPECT_EQ( | 846 EXPECT_EQ(MOJO_RESULT_OK, |
771 MOJO_RESULT_OK, | 847 mp0->WriteMessage(0, |
772 mp0->WriteMessage(0, UserPointer<const void>(kHello), sizeof(kHello), | 848 UserPointer<const void>(kHello), |
773 &transports, MOJO_WRITE_MESSAGE_FLAG_NONE)); | 849 sizeof(kHello), |
| 850 &transports, |
| 851 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
774 transport.End(); | 852 transport.End(); |
775 | 853 |
776 // |dispatcher| should have been closed. This is |DCHECK()|ed when the | 854 // |dispatcher| should have been closed. This is |DCHECK()|ed when the |
777 // |dispatcher| is destroyed. | 855 // |dispatcher| is destroyed. |
778 EXPECT_TRUE(dispatcher->HasOneRef()); | 856 EXPECT_TRUE(dispatcher->HasOneRef()); |
779 dispatcher = nullptr; | 857 dispatcher = nullptr; |
780 } | 858 } |
781 | 859 |
782 // Wait. | 860 // Wait. |
783 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); | 861 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); |
784 EXPECT_EQ(123u, context); | 862 EXPECT_EQ(123u, context); |
785 hss = HandleSignalsState(); | 863 hss = HandleSignalsState(); |
786 mp1->RemoveWaiter(1, &waiter, &hss); | 864 mp1->RemoveWaiter(1, &waiter, &hss); |
787 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 865 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
788 hss.satisfied_signals); | 866 hss.satisfied_signals); |
789 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 867 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
790 hss.satisfiable_signals); | 868 hss.satisfiable_signals); |
791 | 869 |
792 // Read from MP 1, port 1. | 870 // Read from MP 1, port 1. |
793 char read_buffer[100] = {0}; | 871 char read_buffer[100] = {0}; |
794 uint32_t read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer)); | 872 uint32_t read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer)); |
795 DispatcherVector read_dispatchers; | 873 DispatcherVector read_dispatchers; |
796 uint32_t read_num_dispatchers = 10; // Maximum to get. | 874 uint32_t read_num_dispatchers = 10; // Maximum to get. |
797 EXPECT_EQ( | 875 EXPECT_EQ(MOJO_RESULT_OK, |
798 MOJO_RESULT_OK, | 876 mp1->ReadMessage(1, |
799 mp1->ReadMessage(1, UserPointer<void>(read_buffer), | 877 UserPointer<void>(read_buffer), |
800 MakeUserPointer(&read_buffer_size), &read_dispatchers, | 878 MakeUserPointer(&read_buffer_size), |
801 &read_num_dispatchers, MOJO_READ_MESSAGE_FLAG_NONE)); | 879 &read_dispatchers, |
| 880 &read_num_dispatchers, |
| 881 MOJO_READ_MESSAGE_FLAG_NONE)); |
802 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size)); | 882 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size)); |
803 EXPECT_STREQ(kHello, read_buffer); | 883 EXPECT_STREQ(kHello, read_buffer); |
804 EXPECT_EQ(1u, read_dispatchers.size()); | 884 EXPECT_EQ(1u, read_dispatchers.size()); |
805 EXPECT_EQ(1u, read_num_dispatchers); | 885 EXPECT_EQ(1u, read_num_dispatchers); |
806 ASSERT_TRUE(read_dispatchers[0].get()); | 886 ASSERT_TRUE(read_dispatchers[0].get()); |
807 EXPECT_TRUE(read_dispatchers[0]->HasOneRef()); | 887 EXPECT_TRUE(read_dispatchers[0]->HasOneRef()); |
808 | 888 |
809 EXPECT_EQ(Dispatcher::kTypeMessagePipe, read_dispatchers[0]->GetType()); | 889 EXPECT_EQ(Dispatcher::kTypeMessagePipe, read_dispatchers[0]->GetType()); |
810 dispatcher = static_cast<MessagePipeDispatcher*>(read_dispatchers[0].get()); | 890 dispatcher = static_cast<MessagePipeDispatcher*>(read_dispatchers[0].get()); |
811 | 891 |
812 // |dispatcher| should already be readable and not writable. | 892 // |dispatcher| should already be readable and not writable. |
813 hss = dispatcher->GetHandleSignalsState(); | 893 hss = dispatcher->GetHandleSignalsState(); |
814 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals); | 894 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals); |
815 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfiable_signals); | 895 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfiable_signals); |
816 // So read from it. | 896 // So read from it. |
817 memset(read_buffer, 0, sizeof(read_buffer)); | 897 memset(read_buffer, 0, sizeof(read_buffer)); |
818 read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer)); | 898 read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer)); |
819 EXPECT_EQ(MOJO_RESULT_OK, | 899 EXPECT_EQ(MOJO_RESULT_OK, |
820 dispatcher->ReadMessage(UserPointer<void>(read_buffer), | 900 dispatcher->ReadMessage(UserPointer<void>(read_buffer), |
821 MakeUserPointer(&read_buffer_size), 0, | 901 MakeUserPointer(&read_buffer_size), |
822 nullptr, MOJO_READ_MESSAGE_FLAG_NONE)); | 902 0, |
| 903 nullptr, |
| 904 MOJO_READ_MESSAGE_FLAG_NONE)); |
823 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size)); | 905 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size)); |
824 EXPECT_STREQ(kHello, read_buffer); | 906 EXPECT_STREQ(kHello, read_buffer); |
825 // It should still be readable. | 907 // It should still be readable. |
826 hss = dispatcher->GetHandleSignalsState(); | 908 hss = dispatcher->GetHandleSignalsState(); |
827 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals); | 909 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals); |
828 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfiable_signals); | 910 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfiable_signals); |
829 // So read from it. | 911 // So read from it. |
830 memset(read_buffer, 0, sizeof(read_buffer)); | 912 memset(read_buffer, 0, sizeof(read_buffer)); |
831 read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer)); | 913 read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer)); |
832 EXPECT_EQ(MOJO_RESULT_OK, | 914 EXPECT_EQ(MOJO_RESULT_OK, |
833 dispatcher->ReadMessage(UserPointer<void>(read_buffer), | 915 dispatcher->ReadMessage(UserPointer<void>(read_buffer), |
834 MakeUserPointer(&read_buffer_size), 0, | 916 MakeUserPointer(&read_buffer_size), |
835 nullptr, MOJO_READ_MESSAGE_FLAG_NONE)); | 917 0, |
| 918 nullptr, |
| 919 MOJO_READ_MESSAGE_FLAG_NONE)); |
836 EXPECT_EQ(sizeof(kWorld), static_cast<size_t>(read_buffer_size)); | 920 EXPECT_EQ(sizeof(kWorld), static_cast<size_t>(read_buffer_size)); |
837 EXPECT_STREQ(kWorld, read_buffer); | 921 EXPECT_STREQ(kWorld, read_buffer); |
838 // Now it should no longer be readable. | 922 // Now it should no longer be readable. |
839 hss = dispatcher->GetHandleSignalsState(); | 923 hss = dispatcher->GetHandleSignalsState(); |
840 EXPECT_EQ(MOJO_HANDLE_SIGNAL_NONE, hss.satisfied_signals); | 924 EXPECT_EQ(MOJO_HANDLE_SIGNAL_NONE, hss.satisfied_signals); |
841 EXPECT_EQ(MOJO_HANDLE_SIGNAL_NONE, hss.satisfiable_signals); | 925 EXPECT_EQ(MOJO_HANDLE_SIGNAL_NONE, hss.satisfiable_signals); |
842 | 926 |
843 // Close everything that belongs to us. | 927 // Close everything that belongs to us. |
844 mp0->Close(0); | 928 mp0->Close(0); |
845 mp1->Close(1); | 929 mp1->Close(1); |
(...skipping 13 matching lines...) Expand all Loading... |
859 uint32_t context = 0; | 943 uint32_t context = 0; |
860 | 944 |
861 scoped_refptr<ChannelEndpoint> ep0; | 945 scoped_refptr<ChannelEndpoint> ep0; |
862 scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy(&ep0)); | 946 scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy(&ep0)); |
863 scoped_refptr<ChannelEndpoint> ep1; | 947 scoped_refptr<ChannelEndpoint> ep1; |
864 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1)); | 948 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1)); |
865 BootstrapChannelEndpoints(ep0, ep1); | 949 BootstrapChannelEndpoints(ep0, ep1); |
866 | 950 |
867 // We'll try to pass this dispatcher. | 951 // We'll try to pass this dispatcher. |
868 scoped_refptr<SharedBufferDispatcher> dispatcher; | 952 scoped_refptr<SharedBufferDispatcher> dispatcher; |
869 EXPECT_EQ(MOJO_RESULT_OK, SharedBufferDispatcher::Create( | 953 EXPECT_EQ(MOJO_RESULT_OK, |
870 platform_support(), | 954 SharedBufferDispatcher::Create( |
871 SharedBufferDispatcher::kDefaultCreateOptions, | 955 platform_support(), |
872 100, &dispatcher)); | 956 SharedBufferDispatcher::kDefaultCreateOptions, |
| 957 100, |
| 958 &dispatcher)); |
873 ASSERT_TRUE(dispatcher.get()); | 959 ASSERT_TRUE(dispatcher.get()); |
874 | 960 |
875 // Make a mapping. | 961 // Make a mapping. |
876 scoped_ptr<embedder::PlatformSharedBufferMapping> mapping0; | 962 scoped_ptr<embedder::PlatformSharedBufferMapping> mapping0; |
877 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->MapBuffer( | 963 EXPECT_EQ( |
878 0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping0)); | 964 MOJO_RESULT_OK, |
| 965 dispatcher->MapBuffer(0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping0)); |
879 ASSERT_TRUE(mapping0); | 966 ASSERT_TRUE(mapping0); |
880 ASSERT_TRUE(mapping0->GetBase()); | 967 ASSERT_TRUE(mapping0->GetBase()); |
881 ASSERT_EQ(100u, mapping0->GetLength()); | 968 ASSERT_EQ(100u, mapping0->GetLength()); |
882 static_cast<char*>(mapping0->GetBase())[0] = 'A'; | 969 static_cast<char*>(mapping0->GetBase())[0] = 'A'; |
883 static_cast<char*>(mapping0->GetBase())[50] = 'B'; | 970 static_cast<char*>(mapping0->GetBase())[50] = 'B'; |
884 static_cast<char*>(mapping0->GetBase())[99] = 'C'; | 971 static_cast<char*>(mapping0->GetBase())[99] = 'C'; |
885 | 972 |
886 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do | 973 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do |
887 // it later, it might already be readable.) | 974 // it later, it might already be readable.) |
888 waiter.Init(); | 975 waiter.Init(); |
889 ASSERT_EQ( | 976 ASSERT_EQ( |
890 MOJO_RESULT_OK, | 977 MOJO_RESULT_OK, |
891 mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); | 978 mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); |
892 | 979 |
893 // Write to MP 0, port 0. | 980 // Write to MP 0, port 0. |
894 { | 981 { |
895 DispatcherTransport transport( | 982 DispatcherTransport transport( |
896 test::DispatcherTryStartTransport(dispatcher.get())); | 983 test::DispatcherTryStartTransport(dispatcher.get())); |
897 EXPECT_TRUE(transport.is_valid()); | 984 EXPECT_TRUE(transport.is_valid()); |
898 | 985 |
899 std::vector<DispatcherTransport> transports; | 986 std::vector<DispatcherTransport> transports; |
900 transports.push_back(transport); | 987 transports.push_back(transport); |
901 EXPECT_EQ( | 988 EXPECT_EQ(MOJO_RESULT_OK, |
902 MOJO_RESULT_OK, | 989 mp0->WriteMessage(0, |
903 mp0->WriteMessage(0, UserPointer<const void>(kHello), sizeof(kHello), | 990 UserPointer<const void>(kHello), |
904 &transports, MOJO_WRITE_MESSAGE_FLAG_NONE)); | 991 sizeof(kHello), |
| 992 &transports, |
| 993 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
905 transport.End(); | 994 transport.End(); |
906 | 995 |
907 // |dispatcher| should have been closed. This is |DCHECK()|ed when the | 996 // |dispatcher| should have been closed. This is |DCHECK()|ed when the |
908 // |dispatcher| is destroyed. | 997 // |dispatcher| is destroyed. |
909 EXPECT_TRUE(dispatcher->HasOneRef()); | 998 EXPECT_TRUE(dispatcher->HasOneRef()); |
910 dispatcher = nullptr; | 999 dispatcher = nullptr; |
911 } | 1000 } |
912 | 1001 |
913 // Wait. | 1002 // Wait. |
914 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); | 1003 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); |
915 EXPECT_EQ(123u, context); | 1004 EXPECT_EQ(123u, context); |
916 hss = HandleSignalsState(); | 1005 hss = HandleSignalsState(); |
917 mp1->RemoveWaiter(1, &waiter, &hss); | 1006 mp1->RemoveWaiter(1, &waiter, &hss); |
918 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 1007 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
919 hss.satisfied_signals); | 1008 hss.satisfied_signals); |
920 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 1009 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
921 hss.satisfiable_signals); | 1010 hss.satisfiable_signals); |
922 | 1011 |
923 // Read from MP 1, port 1. | 1012 // Read from MP 1, port 1. |
924 char read_buffer[100] = {0}; | 1013 char read_buffer[100] = {0}; |
925 uint32_t read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer)); | 1014 uint32_t read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer)); |
926 DispatcherVector read_dispatchers; | 1015 DispatcherVector read_dispatchers; |
927 uint32_t read_num_dispatchers = 10; // Maximum to get. | 1016 uint32_t read_num_dispatchers = 10; // Maximum to get. |
928 EXPECT_EQ( | 1017 EXPECT_EQ(MOJO_RESULT_OK, |
929 MOJO_RESULT_OK, | 1018 mp1->ReadMessage(1, |
930 mp1->ReadMessage(1, UserPointer<void>(read_buffer), | 1019 UserPointer<void>(read_buffer), |
931 MakeUserPointer(&read_buffer_size), &read_dispatchers, | 1020 MakeUserPointer(&read_buffer_size), |
932 &read_num_dispatchers, MOJO_READ_MESSAGE_FLAG_NONE)); | 1021 &read_dispatchers, |
| 1022 &read_num_dispatchers, |
| 1023 MOJO_READ_MESSAGE_FLAG_NONE)); |
933 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size)); | 1024 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size)); |
934 EXPECT_STREQ(kHello, read_buffer); | 1025 EXPECT_STREQ(kHello, read_buffer); |
935 EXPECT_EQ(1u, read_dispatchers.size()); | 1026 EXPECT_EQ(1u, read_dispatchers.size()); |
936 EXPECT_EQ(1u, read_num_dispatchers); | 1027 EXPECT_EQ(1u, read_num_dispatchers); |
937 ASSERT_TRUE(read_dispatchers[0].get()); | 1028 ASSERT_TRUE(read_dispatchers[0].get()); |
938 EXPECT_TRUE(read_dispatchers[0]->HasOneRef()); | 1029 EXPECT_TRUE(read_dispatchers[0]->HasOneRef()); |
939 | 1030 |
940 EXPECT_EQ(Dispatcher::kTypeSharedBuffer, read_dispatchers[0]->GetType()); | 1031 EXPECT_EQ(Dispatcher::kTypeSharedBuffer, read_dispatchers[0]->GetType()); |
941 dispatcher = static_cast<SharedBufferDispatcher*>(read_dispatchers[0].get()); | 1032 dispatcher = static_cast<SharedBufferDispatcher*>(read_dispatchers[0].get()); |
942 | 1033 |
943 // Make another mapping. | 1034 // Make another mapping. |
944 scoped_ptr<embedder::PlatformSharedBufferMapping> mapping1; | 1035 scoped_ptr<embedder::PlatformSharedBufferMapping> mapping1; |
945 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->MapBuffer( | 1036 EXPECT_EQ( |
946 0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping1)); | 1037 MOJO_RESULT_OK, |
| 1038 dispatcher->MapBuffer(0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping1)); |
947 ASSERT_TRUE(mapping1); | 1039 ASSERT_TRUE(mapping1); |
948 ASSERT_TRUE(mapping1->GetBase()); | 1040 ASSERT_TRUE(mapping1->GetBase()); |
949 ASSERT_EQ(100u, mapping1->GetLength()); | 1041 ASSERT_EQ(100u, mapping1->GetLength()); |
950 EXPECT_NE(mapping1->GetBase(), mapping0->GetBase()); | 1042 EXPECT_NE(mapping1->GetBase(), mapping0->GetBase()); |
951 EXPECT_EQ('A', static_cast<char*>(mapping1->GetBase())[0]); | 1043 EXPECT_EQ('A', static_cast<char*>(mapping1->GetBase())[0]); |
952 EXPECT_EQ('B', static_cast<char*>(mapping1->GetBase())[50]); | 1044 EXPECT_EQ('B', static_cast<char*>(mapping1->GetBase())[50]); |
953 EXPECT_EQ('C', static_cast<char*>(mapping1->GetBase())[99]); | 1045 EXPECT_EQ('C', static_cast<char*>(mapping1->GetBase())[99]); |
954 | 1046 |
955 // Write stuff either way. | 1047 // Write stuff either way. |
956 static_cast<char*>(mapping1->GetBase())[1] = 'x'; | 1048 static_cast<char*>(mapping1->GetBase())[1] = 'x'; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1011 mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); | 1103 mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); |
1012 | 1104 |
1013 // Write to MP 0, port 0. | 1105 // Write to MP 0, port 0. |
1014 { | 1106 { |
1015 DispatcherTransport transport( | 1107 DispatcherTransport transport( |
1016 test::DispatcherTryStartTransport(dispatcher.get())); | 1108 test::DispatcherTryStartTransport(dispatcher.get())); |
1017 EXPECT_TRUE(transport.is_valid()); | 1109 EXPECT_TRUE(transport.is_valid()); |
1018 | 1110 |
1019 std::vector<DispatcherTransport> transports; | 1111 std::vector<DispatcherTransport> transports; |
1020 transports.push_back(transport); | 1112 transports.push_back(transport); |
1021 EXPECT_EQ( | 1113 EXPECT_EQ(MOJO_RESULT_OK, |
1022 MOJO_RESULT_OK, | 1114 mp0->WriteMessage(0, |
1023 mp0->WriteMessage(0, UserPointer<const void>(kWorld), sizeof(kWorld), | 1115 UserPointer<const void>(kWorld), |
1024 &transports, MOJO_WRITE_MESSAGE_FLAG_NONE)); | 1116 sizeof(kWorld), |
| 1117 &transports, |
| 1118 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
1025 transport.End(); | 1119 transport.End(); |
1026 | 1120 |
1027 // |dispatcher| should have been closed. This is |DCHECK()|ed when the | 1121 // |dispatcher| should have been closed. This is |DCHECK()|ed when the |
1028 // |dispatcher| is destroyed. | 1122 // |dispatcher| is destroyed. |
1029 EXPECT_TRUE(dispatcher->HasOneRef()); | 1123 EXPECT_TRUE(dispatcher->HasOneRef()); |
1030 dispatcher = nullptr; | 1124 dispatcher = nullptr; |
1031 } | 1125 } |
1032 | 1126 |
1033 // Wait. | 1127 // Wait. |
1034 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); | 1128 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); |
1035 EXPECT_EQ(123u, context); | 1129 EXPECT_EQ(123u, context); |
1036 hss = HandleSignalsState(); | 1130 hss = HandleSignalsState(); |
1037 mp1->RemoveWaiter(1, &waiter, &hss); | 1131 mp1->RemoveWaiter(1, &waiter, &hss); |
1038 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 1132 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
1039 hss.satisfied_signals); | 1133 hss.satisfied_signals); |
1040 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 1134 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
1041 hss.satisfiable_signals); | 1135 hss.satisfiable_signals); |
1042 | 1136 |
1043 // Read from MP 1, port 1. | 1137 // Read from MP 1, port 1. |
1044 char read_buffer[100] = {0}; | 1138 char read_buffer[100] = {0}; |
1045 uint32_t read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer)); | 1139 uint32_t read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer)); |
1046 DispatcherVector read_dispatchers; | 1140 DispatcherVector read_dispatchers; |
1047 uint32_t read_num_dispatchers = 10; // Maximum to get. | 1141 uint32_t read_num_dispatchers = 10; // Maximum to get. |
1048 EXPECT_EQ( | 1142 EXPECT_EQ(MOJO_RESULT_OK, |
1049 MOJO_RESULT_OK, | 1143 mp1->ReadMessage(1, |
1050 mp1->ReadMessage(1, UserPointer<void>(read_buffer), | 1144 UserPointer<void>(read_buffer), |
1051 MakeUserPointer(&read_buffer_size), &read_dispatchers, | 1145 MakeUserPointer(&read_buffer_size), |
1052 &read_num_dispatchers, MOJO_READ_MESSAGE_FLAG_NONE)); | 1146 &read_dispatchers, |
| 1147 &read_num_dispatchers, |
| 1148 MOJO_READ_MESSAGE_FLAG_NONE)); |
1053 EXPECT_EQ(sizeof(kWorld), static_cast<size_t>(read_buffer_size)); | 1149 EXPECT_EQ(sizeof(kWorld), static_cast<size_t>(read_buffer_size)); |
1054 EXPECT_STREQ(kWorld, read_buffer); | 1150 EXPECT_STREQ(kWorld, read_buffer); |
1055 EXPECT_EQ(1u, read_dispatchers.size()); | 1151 EXPECT_EQ(1u, read_dispatchers.size()); |
1056 EXPECT_EQ(1u, read_num_dispatchers); | 1152 EXPECT_EQ(1u, read_num_dispatchers); |
1057 ASSERT_TRUE(read_dispatchers[0].get()); | 1153 ASSERT_TRUE(read_dispatchers[0].get()); |
1058 EXPECT_TRUE(read_dispatchers[0]->HasOneRef()); | 1154 EXPECT_TRUE(read_dispatchers[0]->HasOneRef()); |
1059 | 1155 |
1060 EXPECT_EQ(Dispatcher::kTypePlatformHandle, read_dispatchers[0]->GetType()); | 1156 EXPECT_EQ(Dispatcher::kTypePlatformHandle, read_dispatchers[0]->GetType()); |
1061 dispatcher = | 1157 dispatcher = |
1062 static_cast<PlatformHandleDispatcher*>(read_dispatchers[0].get()); | 1158 static_cast<PlatformHandleDispatcher*>(read_dispatchers[0].get()); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1149 mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); | 1245 mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); |
1150 | 1246 |
1151 // Write to MP 0, port 0. | 1247 // Write to MP 0, port 0. |
1152 { | 1248 { |
1153 DispatcherTransport transport( | 1249 DispatcherTransport transport( |
1154 test::DispatcherTryStartTransport(dispatcher.get())); | 1250 test::DispatcherTryStartTransport(dispatcher.get())); |
1155 EXPECT_TRUE(transport.is_valid()); | 1251 EXPECT_TRUE(transport.is_valid()); |
1156 | 1252 |
1157 std::vector<DispatcherTransport> transports; | 1253 std::vector<DispatcherTransport> transports; |
1158 transports.push_back(transport); | 1254 transports.push_back(transport); |
1159 EXPECT_EQ( | 1255 EXPECT_EQ(MOJO_RESULT_OK, |
1160 MOJO_RESULT_OK, | 1256 mp0->WriteMessage(0, |
1161 mp0->WriteMessage(0, UserPointer<const void>(kHello), sizeof(kHello), | 1257 UserPointer<const void>(kHello), |
1162 &transports, MOJO_WRITE_MESSAGE_FLAG_NONE)); | 1258 sizeof(kHello), |
| 1259 &transports, |
| 1260 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
1163 transport.End(); | 1261 transport.End(); |
1164 | 1262 |
1165 // |dispatcher| should have been closed. This is |DCHECK()|ed when the | 1263 // |dispatcher| should have been closed. This is |DCHECK()|ed when the |
1166 // |dispatcher| is destroyed. | 1264 // |dispatcher| is destroyed. |
1167 EXPECT_TRUE(dispatcher->HasOneRef()); | 1265 EXPECT_TRUE(dispatcher->HasOneRef()); |
1168 dispatcher = nullptr; | 1266 dispatcher = nullptr; |
1169 } | 1267 } |
1170 | 1268 |
1171 // Wait. | 1269 // Wait. |
1172 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); | 1270 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); |
1173 EXPECT_EQ(123u, context); | 1271 EXPECT_EQ(123u, context); |
1174 hss = HandleSignalsState(); | 1272 hss = HandleSignalsState(); |
1175 mp1->RemoveWaiter(1, &waiter, &hss); | 1273 mp1->RemoveWaiter(1, &waiter, &hss); |
1176 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 1274 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
1177 hss.satisfied_signals); | 1275 hss.satisfied_signals); |
1178 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 1276 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
1179 hss.satisfiable_signals); | 1277 hss.satisfiable_signals); |
1180 | 1278 |
1181 // Read from MP 1, port 1. | 1279 // Read from MP 1, port 1. |
1182 char read_buffer[100] = {0}; | 1280 char read_buffer[100] = {0}; |
1183 uint32_t read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer)); | 1281 uint32_t read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer)); |
1184 DispatcherVector read_dispatchers; | 1282 DispatcherVector read_dispatchers; |
1185 uint32_t read_num_dispatchers = 10; // Maximum to get. | 1283 uint32_t read_num_dispatchers = 10; // Maximum to get. |
1186 EXPECT_EQ( | 1284 EXPECT_EQ(MOJO_RESULT_OK, |
1187 MOJO_RESULT_OK, | 1285 mp1->ReadMessage(1, |
1188 mp1->ReadMessage(1, UserPointer<void>(read_buffer), | 1286 UserPointer<void>(read_buffer), |
1189 MakeUserPointer(&read_buffer_size), &read_dispatchers, | 1287 MakeUserPointer(&read_buffer_size), |
1190 &read_num_dispatchers, MOJO_READ_MESSAGE_FLAG_NONE)); | 1288 &read_dispatchers, |
| 1289 &read_num_dispatchers, |
| 1290 MOJO_READ_MESSAGE_FLAG_NONE)); |
1191 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size)); | 1291 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size)); |
1192 EXPECT_STREQ(kHello, read_buffer); | 1292 EXPECT_STREQ(kHello, read_buffer); |
1193 EXPECT_EQ(1u, read_dispatchers.size()); | 1293 EXPECT_EQ(1u, read_dispatchers.size()); |
1194 EXPECT_EQ(1u, read_num_dispatchers); | 1294 EXPECT_EQ(1u, read_num_dispatchers); |
1195 ASSERT_TRUE(read_dispatchers[0].get()); | 1295 ASSERT_TRUE(read_dispatchers[0].get()); |
1196 EXPECT_TRUE(read_dispatchers[0]->HasOneRef()); | 1296 EXPECT_TRUE(read_dispatchers[0]->HasOneRef()); |
1197 | 1297 |
1198 EXPECT_EQ(Dispatcher::kTypeMessagePipe, read_dispatchers[0]->GetType()); | 1298 EXPECT_EQ(Dispatcher::kTypeMessagePipe, read_dispatchers[0]->GetType()); |
1199 dispatcher = static_cast<MessagePipeDispatcher*>(read_dispatchers[0].get()); | 1299 dispatcher = static_cast<MessagePipeDispatcher*>(read_dispatchers[0].get()); |
1200 read_dispatchers.clear(); | 1300 read_dispatchers.clear(); |
1201 | 1301 |
1202 // Now pass it back. | 1302 // Now pass it back. |
1203 | 1303 |
1204 // Prepare to wait on MP 0, port 0. (Add the waiter now. Otherwise, if we do | 1304 // Prepare to wait on MP 0, port 0. (Add the waiter now. Otherwise, if we do |
1205 // it later, it might already be readable.) | 1305 // it later, it might already be readable.) |
1206 waiter.Init(); | 1306 waiter.Init(); |
1207 ASSERT_EQ( | 1307 ASSERT_EQ( |
1208 MOJO_RESULT_OK, | 1308 MOJO_RESULT_OK, |
1209 mp0->AddWaiter(0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 456, nullptr)); | 1309 mp0->AddWaiter(0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 456, nullptr)); |
1210 | 1310 |
1211 // Write to MP 1, port 1. | 1311 // Write to MP 1, port 1. |
1212 { | 1312 { |
1213 DispatcherTransport transport( | 1313 DispatcherTransport transport( |
1214 test::DispatcherTryStartTransport(dispatcher.get())); | 1314 test::DispatcherTryStartTransport(dispatcher.get())); |
1215 EXPECT_TRUE(transport.is_valid()); | 1315 EXPECT_TRUE(transport.is_valid()); |
1216 | 1316 |
1217 std::vector<DispatcherTransport> transports; | 1317 std::vector<DispatcherTransport> transports; |
1218 transports.push_back(transport); | 1318 transports.push_back(transport); |
1219 EXPECT_EQ( | 1319 EXPECT_EQ(MOJO_RESULT_OK, |
1220 MOJO_RESULT_OK, | 1320 mp1->WriteMessage(1, |
1221 mp1->WriteMessage(1, UserPointer<const void>(kWorld), sizeof(kWorld), | 1321 UserPointer<const void>(kWorld), |
1222 &transports, MOJO_WRITE_MESSAGE_FLAG_NONE)); | 1322 sizeof(kWorld), |
| 1323 &transports, |
| 1324 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
1223 transport.End(); | 1325 transport.End(); |
1224 | 1326 |
1225 // |dispatcher| should have been closed. This is |DCHECK()|ed when the | 1327 // |dispatcher| should have been closed. This is |DCHECK()|ed when the |
1226 // |dispatcher| is destroyed. | 1328 // |dispatcher| is destroyed. |
1227 EXPECT_TRUE(dispatcher->HasOneRef()); | 1329 EXPECT_TRUE(dispatcher->HasOneRef()); |
1228 dispatcher = nullptr; | 1330 dispatcher = nullptr; |
1229 } | 1331 } |
1230 | 1332 |
1231 // Wait. | 1333 // Wait. |
1232 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); | 1334 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); |
1233 EXPECT_EQ(456u, context); | 1335 EXPECT_EQ(456u, context); |
1234 hss = HandleSignalsState(); | 1336 hss = HandleSignalsState(); |
1235 mp0->RemoveWaiter(0, &waiter, &hss); | 1337 mp0->RemoveWaiter(0, &waiter, &hss); |
1236 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 1338 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
1237 hss.satisfied_signals); | 1339 hss.satisfied_signals); |
1238 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 1340 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
1239 hss.satisfiable_signals); | 1341 hss.satisfiable_signals); |
1240 | 1342 |
1241 // Read from MP 0, port 0. | 1343 // Read from MP 0, port 0. |
1242 read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer)); | 1344 read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer)); |
1243 read_num_dispatchers = 10; // Maximum to get. | 1345 read_num_dispatchers = 10; // Maximum to get. |
1244 EXPECT_EQ( | 1346 EXPECT_EQ(MOJO_RESULT_OK, |
1245 MOJO_RESULT_OK, | 1347 mp0->ReadMessage(0, |
1246 mp0->ReadMessage(0, UserPointer<void>(read_buffer), | 1348 UserPointer<void>(read_buffer), |
1247 MakeUserPointer(&read_buffer_size), &read_dispatchers, | 1349 MakeUserPointer(&read_buffer_size), |
1248 &read_num_dispatchers, MOJO_READ_MESSAGE_FLAG_NONE)); | 1350 &read_dispatchers, |
| 1351 &read_num_dispatchers, |
| 1352 MOJO_READ_MESSAGE_FLAG_NONE)); |
1249 EXPECT_EQ(sizeof(kWorld), static_cast<size_t>(read_buffer_size)); | 1353 EXPECT_EQ(sizeof(kWorld), static_cast<size_t>(read_buffer_size)); |
1250 EXPECT_STREQ(kWorld, read_buffer); | 1354 EXPECT_STREQ(kWorld, read_buffer); |
1251 EXPECT_EQ(1u, read_dispatchers.size()); | 1355 EXPECT_EQ(1u, read_dispatchers.size()); |
1252 EXPECT_EQ(1u, read_num_dispatchers); | 1356 EXPECT_EQ(1u, read_num_dispatchers); |
1253 ASSERT_TRUE(read_dispatchers[0].get()); | 1357 ASSERT_TRUE(read_dispatchers[0].get()); |
1254 EXPECT_TRUE(read_dispatchers[0]->HasOneRef()); | 1358 EXPECT_TRUE(read_dispatchers[0]->HasOneRef()); |
1255 | 1359 |
1256 EXPECT_EQ(Dispatcher::kTypeMessagePipe, read_dispatchers[0]->GetType()); | 1360 EXPECT_EQ(Dispatcher::kTypeMessagePipe, read_dispatchers[0]->GetType()); |
1257 dispatcher = static_cast<MessagePipeDispatcher*>(read_dispatchers[0].get()); | 1361 dispatcher = static_cast<MessagePipeDispatcher*>(read_dispatchers[0].get()); |
1258 read_dispatchers.clear(); | 1362 read_dispatchers.clear(); |
1259 | 1363 |
1260 // Add the waiter now, before it becomes readable to avoid a race. | 1364 // Add the waiter now, before it becomes readable to avoid a race. |
1261 waiter.Init(); | 1365 waiter.Init(); |
1262 ASSERT_EQ(MOJO_RESULT_OK, | 1366 ASSERT_EQ(MOJO_RESULT_OK, |
1263 dispatcher->AddWaiter(&waiter, MOJO_HANDLE_SIGNAL_READABLE, 789, | 1367 dispatcher->AddWaiter( |
1264 nullptr)); | 1368 &waiter, MOJO_HANDLE_SIGNAL_READABLE, 789, nullptr)); |
1265 | 1369 |
1266 // Write to "local_mp", port 1. | 1370 // Write to "local_mp", port 1. |
1267 EXPECT_EQ( | 1371 EXPECT_EQ(MOJO_RESULT_OK, |
1268 MOJO_RESULT_OK, | 1372 local_mp->WriteMessage(1, |
1269 local_mp->WriteMessage(1, UserPointer<const void>(kHello), sizeof(kHello), | 1373 UserPointer<const void>(kHello), |
1270 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); | 1374 sizeof(kHello), |
| 1375 nullptr, |
| 1376 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
1271 | 1377 |
1272 // Wait for the dispatcher to become readable. | 1378 // Wait for the dispatcher to become readable. |
1273 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); | 1379 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); |
1274 EXPECT_EQ(789u, context); | 1380 EXPECT_EQ(789u, context); |
1275 hss = HandleSignalsState(); | 1381 hss = HandleSignalsState(); |
1276 dispatcher->RemoveWaiter(&waiter, &hss); | 1382 dispatcher->RemoveWaiter(&waiter, &hss); |
1277 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 1383 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
1278 hss.satisfied_signals); | 1384 hss.satisfied_signals); |
1279 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 1385 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
1280 hss.satisfiable_signals); | 1386 hss.satisfiable_signals); |
1281 | 1387 |
1282 // Read from the dispatcher. | 1388 // Read from the dispatcher. |
1283 memset(read_buffer, 0, sizeof(read_buffer)); | 1389 memset(read_buffer, 0, sizeof(read_buffer)); |
1284 read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer)); | 1390 read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer)); |
1285 EXPECT_EQ(MOJO_RESULT_OK, | 1391 EXPECT_EQ(MOJO_RESULT_OK, |
1286 dispatcher->ReadMessage(UserPointer<void>(read_buffer), | 1392 dispatcher->ReadMessage(UserPointer<void>(read_buffer), |
1287 MakeUserPointer(&read_buffer_size), 0, | 1393 MakeUserPointer(&read_buffer_size), |
1288 nullptr, MOJO_READ_MESSAGE_FLAG_NONE)); | 1394 0, |
| 1395 nullptr, |
| 1396 MOJO_READ_MESSAGE_FLAG_NONE)); |
1289 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size)); | 1397 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size)); |
1290 EXPECT_STREQ(kHello, read_buffer); | 1398 EXPECT_STREQ(kHello, read_buffer); |
1291 | 1399 |
1292 // Prepare to wait on "local_mp", port 1. | 1400 // Prepare to wait on "local_mp", port 1. |
1293 waiter.Init(); | 1401 waiter.Init(); |
1294 ASSERT_EQ(MOJO_RESULT_OK, | 1402 ASSERT_EQ(MOJO_RESULT_OK, |
1295 local_mp->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 789, | 1403 local_mp->AddWaiter( |
1296 nullptr)); | 1404 1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 789, nullptr)); |
1297 | 1405 |
1298 // Write to the dispatcher. | 1406 // Write to the dispatcher. |
1299 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->WriteMessage( | 1407 EXPECT_EQ(MOJO_RESULT_OK, |
1300 UserPointer<const void>(kHello), sizeof(kHello), | 1408 dispatcher->WriteMessage(UserPointer<const void>(kHello), |
1301 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); | 1409 sizeof(kHello), |
| 1410 nullptr, |
| 1411 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
1302 | 1412 |
1303 // Wait. | 1413 // Wait. |
1304 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); | 1414 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); |
1305 EXPECT_EQ(789u, context); | 1415 EXPECT_EQ(789u, context); |
1306 hss = HandleSignalsState(); | 1416 hss = HandleSignalsState(); |
1307 local_mp->RemoveWaiter(1, &waiter, &hss); | 1417 local_mp->RemoveWaiter(1, &waiter, &hss); |
1308 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 1418 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
1309 hss.satisfied_signals); | 1419 hss.satisfied_signals); |
1310 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 1420 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
1311 hss.satisfiable_signals); | 1421 hss.satisfiable_signals); |
1312 | 1422 |
1313 // Read from "local_mp", port 1. | 1423 // Read from "local_mp", port 1. |
1314 memset(read_buffer, 0, sizeof(read_buffer)); | 1424 memset(read_buffer, 0, sizeof(read_buffer)); |
1315 read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer)); | 1425 read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer)); |
1316 EXPECT_EQ(MOJO_RESULT_OK, | 1426 EXPECT_EQ(MOJO_RESULT_OK, |
1317 local_mp->ReadMessage(1, UserPointer<void>(read_buffer), | 1427 local_mp->ReadMessage(1, |
1318 MakeUserPointer(&read_buffer_size), nullptr, | 1428 UserPointer<void>(read_buffer), |
1319 nullptr, MOJO_READ_MESSAGE_FLAG_NONE)); | 1429 MakeUserPointer(&read_buffer_size), |
| 1430 nullptr, |
| 1431 nullptr, |
| 1432 MOJO_READ_MESSAGE_FLAG_NONE)); |
1320 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size)); | 1433 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size)); |
1321 EXPECT_STREQ(kHello, read_buffer); | 1434 EXPECT_STREQ(kHello, read_buffer); |
1322 | 1435 |
1323 // TODO(vtl): Also test the cases where messages are written and read (at | 1436 // TODO(vtl): Also test the cases where messages are written and read (at |
1324 // various points) on the message pipe being passed around. | 1437 // various points) on the message pipe being passed around. |
1325 | 1438 |
1326 // Close everything that belongs to us. | 1439 // Close everything that belongs to us. |
1327 mp0->Close(0); | 1440 mp0->Close(0); |
1328 mp1->Close(1); | 1441 mp1->Close(1); |
1329 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); | 1442 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); |
1330 // Note that |local_mp|'s port 0 belong to |dispatcher|, which was closed. | 1443 // Note that |local_mp|'s port 0 belong to |dispatcher|, which was closed. |
1331 local_mp->Close(1); | 1444 local_mp->Close(1); |
1332 } | 1445 } |
1333 | 1446 |
1334 } // namespace | 1447 } // namespace |
1335 } // namespace system | 1448 } // namespace system |
1336 } // namespace mojo | 1449 } // namespace mojo |
OLD | NEW |