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 // NOTE(vtl): Some of these tests are inherently flaky (e.g., if run on a | 5 // NOTE(vtl): Some of these tests are inherently flaky (e.g., if run on a |
6 // heavily-loaded system). Sorry. |test::EpsilonTimeout()| may be increased to | 6 // heavily-loaded system). Sorry. |test::EpsilonTimeout()| may be increased to |
7 // increase tolerance and reduce observed flakiness (though doing so reduces the | 7 // increase tolerance and reduce observed flakiness (though doing so reduces the |
8 // meaningfulness of the test). | 8 // meaningfulness of the test). |
9 | 9 |
10 #include "mojo/edk/system/message_pipe_dispatcher.h" | 10 #include "mojo/edk/system/message_pipe_dispatcher.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 d1->Init(mp, i ^ 1); // 1, 0. | 52 d1->Init(mp, i ^ 1); // 1, 0. |
53 } | 53 } |
54 Waiter w; | 54 Waiter w; |
55 uint32_t context = 0; | 55 uint32_t context = 0; |
56 HandleSignalsState hss; | 56 HandleSignalsState hss; |
57 | 57 |
58 // Try adding a writable waiter when already writable. | 58 // Try adding a writable waiter when already writable. |
59 w.Init(); | 59 w.Init(); |
60 hss = HandleSignalsState(); | 60 hss = HandleSignalsState(); |
61 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, | 61 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, |
62 d0->AddWaiter(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 0, &hss)); | 62 d0->AddAwakable(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 0, &hss)); |
63 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals); | 63 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals); |
64 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); | 64 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); |
65 // Shouldn't need to remove the waiter (it was not added). | 65 // Shouldn't need to remove the waiter (it was not added). |
66 | 66 |
67 // Add a readable waiter to |d0|, then make it readable (by writing to | 67 // Add a readable waiter to |d0|, then make it readable (by writing to |
68 // |d1|), then wait. | 68 // |d1|), then wait. |
69 w.Init(); | 69 w.Init(); |
70 ASSERT_EQ(MOJO_RESULT_OK, | 70 ASSERT_EQ(MOJO_RESULT_OK, |
71 d0->AddWaiter(&w, MOJO_HANDLE_SIGNAL_READABLE, 1, nullptr)); | 71 d0->AddAwakable(&w, MOJO_HANDLE_SIGNAL_READABLE, 1, nullptr)); |
72 buffer[0] = 123456789; | 72 buffer[0] = 123456789; |
73 EXPECT_EQ(MOJO_RESULT_OK, | 73 EXPECT_EQ(MOJO_RESULT_OK, |
74 d1->WriteMessage(UserPointer<const void>(buffer), kBufferSize, | 74 d1->WriteMessage(UserPointer<const void>(buffer), kBufferSize, |
75 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); | 75 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); |
76 stopwatch.Start(); | 76 stopwatch.Start(); |
77 EXPECT_EQ(MOJO_RESULT_OK, w.Wait(MOJO_DEADLINE_INDEFINITE, &context)); | 77 EXPECT_EQ(MOJO_RESULT_OK, w.Wait(MOJO_DEADLINE_INDEFINITE, &context)); |
78 EXPECT_EQ(1u, context); | 78 EXPECT_EQ(1u, context); |
79 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); | 79 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); |
80 hss = HandleSignalsState(); | 80 hss = HandleSignalsState(); |
81 d0->RemoveWaiter(&w, &hss); | 81 d0->RemoveAwakable(&w, &hss); |
82 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 82 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
83 hss.satisfied_signals); | 83 hss.satisfied_signals); |
84 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); | 84 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); |
85 | 85 |
86 // Try adding a readable waiter when already readable (from above). | 86 // Try adding a readable waiter when already readable (from above). |
87 w.Init(); | 87 w.Init(); |
88 hss = HandleSignalsState(); | 88 hss = HandleSignalsState(); |
89 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, | 89 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, |
90 d0->AddWaiter(&w, MOJO_HANDLE_SIGNAL_READABLE, 2, &hss)); | 90 d0->AddAwakable(&w, MOJO_HANDLE_SIGNAL_READABLE, 2, &hss)); |
91 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 91 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
92 hss.satisfied_signals); | 92 hss.satisfied_signals); |
93 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); | 93 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); |
94 // Shouldn't need to remove the waiter (it was not added). | 94 // Shouldn't need to remove the waiter (it was not added). |
95 | 95 |
96 // Make |d0| no longer readable (by reading from it). | 96 // Make |d0| no longer readable (by reading from it). |
97 buffer[0] = 0; | 97 buffer[0] = 0; |
98 buffer_size = kBufferSize; | 98 buffer_size = kBufferSize; |
99 EXPECT_EQ(MOJO_RESULT_OK, | 99 EXPECT_EQ(MOJO_RESULT_OK, |
100 d0->ReadMessage(UserPointer<void>(buffer), | 100 d0->ReadMessage(UserPointer<void>(buffer), |
101 MakeUserPointer(&buffer_size), 0, nullptr, | 101 MakeUserPointer(&buffer_size), 0, nullptr, |
102 MOJO_READ_MESSAGE_FLAG_NONE)); | 102 MOJO_READ_MESSAGE_FLAG_NONE)); |
103 EXPECT_EQ(kBufferSize, buffer_size); | 103 EXPECT_EQ(kBufferSize, buffer_size); |
104 EXPECT_EQ(123456789, buffer[0]); | 104 EXPECT_EQ(123456789, buffer[0]); |
105 | 105 |
106 // Wait for zero time for readability on |d0| (will time out). | 106 // Wait for zero time for readability on |d0| (will time out). |
107 w.Init(); | 107 w.Init(); |
108 ASSERT_EQ(MOJO_RESULT_OK, | 108 ASSERT_EQ(MOJO_RESULT_OK, |
109 d0->AddWaiter(&w, MOJO_HANDLE_SIGNAL_READABLE, 3, nullptr)); | 109 d0->AddAwakable(&w, MOJO_HANDLE_SIGNAL_READABLE, 3, nullptr)); |
110 stopwatch.Start(); | 110 stopwatch.Start(); |
111 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, w.Wait(0, nullptr)); | 111 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, w.Wait(0, nullptr)); |
112 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); | 112 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); |
113 hss = HandleSignalsState(); | 113 hss = HandleSignalsState(); |
114 d0->RemoveWaiter(&w, &hss); | 114 d0->RemoveAwakable(&w, &hss); |
115 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals); | 115 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals); |
116 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); | 116 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); |
117 | 117 |
118 // Wait for non-zero, finite time for readability on |d0| (will time out). | 118 // Wait for non-zero, finite time for readability on |d0| (will time out). |
119 w.Init(); | 119 w.Init(); |
120 ASSERT_EQ(MOJO_RESULT_OK, | 120 ASSERT_EQ(MOJO_RESULT_OK, |
121 d0->AddWaiter(&w, MOJO_HANDLE_SIGNAL_READABLE, 3, nullptr)); | 121 d0->AddAwakable(&w, MOJO_HANDLE_SIGNAL_READABLE, 3, nullptr)); |
122 stopwatch.Start(); | 122 stopwatch.Start(); |
123 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, | 123 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, |
124 w.Wait(2 * test::EpsilonTimeout().InMicroseconds(), nullptr)); | 124 w.Wait(2 * test::EpsilonTimeout().InMicroseconds(), nullptr)); |
125 base::TimeDelta elapsed = stopwatch.Elapsed(); | 125 base::TimeDelta elapsed = stopwatch.Elapsed(); |
126 EXPECT_GT(elapsed, (2 - 1) * test::EpsilonTimeout()); | 126 EXPECT_GT(elapsed, (2 - 1) * test::EpsilonTimeout()); |
127 EXPECT_LT(elapsed, (2 + 1) * test::EpsilonTimeout()); | 127 EXPECT_LT(elapsed, (2 + 1) * test::EpsilonTimeout()); |
128 hss = HandleSignalsState(); | 128 hss = HandleSignalsState(); |
129 d0->RemoveWaiter(&w, &hss); | 129 d0->RemoveAwakable(&w, &hss); |
130 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals); | 130 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals); |
131 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); | 131 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); |
132 | 132 |
133 // Check the peer closed signal. | 133 // Check the peer closed signal. |
134 w.Init(); | 134 w.Init(); |
135 ASSERT_EQ(MOJO_RESULT_OK, | 135 ASSERT_EQ(MOJO_RESULT_OK, |
136 d0->AddWaiter(&w, MOJO_HANDLE_SIGNAL_PEER_CLOSED, 12, nullptr)); | 136 d0->AddAwakable(&w, MOJO_HANDLE_SIGNAL_PEER_CLOSED, 12, nullptr)); |
137 | 137 |
138 // Close the peer. | 138 // Close the peer. |
139 EXPECT_EQ(MOJO_RESULT_OK, d1->Close()); | 139 EXPECT_EQ(MOJO_RESULT_OK, d1->Close()); |
140 | 140 |
141 // It should be signaled. | 141 // It should be signaled. |
142 EXPECT_EQ(MOJO_RESULT_OK, w.Wait(1000, &context)); | 142 EXPECT_EQ(MOJO_RESULT_OK, w.Wait(1000, &context)); |
143 EXPECT_EQ(12u, context); | 143 EXPECT_EQ(12u, context); |
144 hss = HandleSignalsState(); | 144 hss = HandleSignalsState(); |
145 d0->RemoveWaiter(&w, &hss); | 145 d0->RemoveAwakable(&w, &hss); |
146 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfied_signals); | 146 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfied_signals); |
147 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfiable_signals); | 147 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfiable_signals); |
148 | 148 |
149 EXPECT_EQ(MOJO_RESULT_OK, d0->Close()); | 149 EXPECT_EQ(MOJO_RESULT_OK, d0->Close()); |
150 } | 150 } |
151 } | 151 } |
152 | 152 |
153 TEST(MessagePipeDispatcherTest, InvalidParams) { | 153 TEST(MessagePipeDispatcherTest, InvalidParams) { |
154 char buffer[1]; | 154 char buffer[1]; |
155 | 155 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); | 242 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); |
243 buffer[0] = 234567890; | 243 buffer[0] = 234567890; |
244 EXPECT_EQ(MOJO_RESULT_OK, | 244 EXPECT_EQ(MOJO_RESULT_OK, |
245 d1->WriteMessage(UserPointer<const void>(buffer), kBufferSize, | 245 d1->WriteMessage(UserPointer<const void>(buffer), kBufferSize, |
246 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); | 246 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); |
247 | 247 |
248 // Try waiting for readable on |d0|; should fail (already satisfied). | 248 // Try waiting for readable on |d0|; should fail (already satisfied). |
249 w.Init(); | 249 w.Init(); |
250 hss = HandleSignalsState(); | 250 hss = HandleSignalsState(); |
251 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, | 251 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, |
252 d0->AddWaiter(&w, MOJO_HANDLE_SIGNAL_READABLE, 0, &hss)); | 252 d0->AddAwakable(&w, MOJO_HANDLE_SIGNAL_READABLE, 0, &hss)); |
253 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 253 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
254 hss.satisfied_signals); | 254 hss.satisfied_signals); |
255 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); | 255 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); |
256 | 256 |
257 // Try reading from |d1|; should fail (nothing to read). | 257 // Try reading from |d1|; should fail (nothing to read). |
258 buffer[0] = 0; | 258 buffer[0] = 0; |
259 buffer_size = kBufferSize; | 259 buffer_size = kBufferSize; |
260 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT, | 260 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT, |
261 d1->ReadMessage(UserPointer<void>(buffer), | 261 d1->ReadMessage(UserPointer<void>(buffer), |
262 MakeUserPointer(&buffer_size), 0, nullptr, | 262 MakeUserPointer(&buffer_size), 0, nullptr, |
263 MOJO_READ_MESSAGE_FLAG_NONE)); | 263 MOJO_READ_MESSAGE_FLAG_NONE)); |
264 | 264 |
265 // Close |d1|. | 265 // Close |d1|. |
266 EXPECT_EQ(MOJO_RESULT_OK, d1->Close()); | 266 EXPECT_EQ(MOJO_RESULT_OK, d1->Close()); |
267 | 267 |
268 // Try waiting for readable on |d0|; should fail (already satisfied). | 268 // Try waiting for readable on |d0|; should fail (already satisfied). |
269 w.Init(); | 269 w.Init(); |
270 hss = HandleSignalsState(); | 270 hss = HandleSignalsState(); |
271 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, | 271 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, |
272 d0->AddWaiter(&w, MOJO_HANDLE_SIGNAL_READABLE, 1, &hss)); | 272 d0->AddAwakable(&w, MOJO_HANDLE_SIGNAL_READABLE, 1, &hss)); |
273 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, | 273 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, |
274 hss.satisfied_signals); | 274 hss.satisfied_signals); |
275 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, | 275 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, |
276 hss.satisfiable_signals); | 276 hss.satisfiable_signals); |
277 | 277 |
278 // Read from |d0|. | 278 // Read from |d0|. |
279 buffer[0] = 0; | 279 buffer[0] = 0; |
280 buffer_size = kBufferSize; | 280 buffer_size = kBufferSize; |
281 EXPECT_EQ(MOJO_RESULT_OK, | 281 EXPECT_EQ(MOJO_RESULT_OK, |
282 d0->ReadMessage(UserPointer<void>(buffer), | 282 d0->ReadMessage(UserPointer<void>(buffer), |
283 MakeUserPointer(&buffer_size), 0, nullptr, | 283 MakeUserPointer(&buffer_size), 0, nullptr, |
284 MOJO_READ_MESSAGE_FLAG_NONE)); | 284 MOJO_READ_MESSAGE_FLAG_NONE)); |
285 EXPECT_EQ(kBufferSize, buffer_size); | 285 EXPECT_EQ(kBufferSize, buffer_size); |
286 EXPECT_EQ(123456789, buffer[0]); | 286 EXPECT_EQ(123456789, buffer[0]); |
287 | 287 |
288 // Try waiting for readable on |d0|; should fail (already satisfied). | 288 // Try waiting for readable on |d0|; should fail (already satisfied). |
289 w.Init(); | 289 w.Init(); |
290 hss = HandleSignalsState(); | 290 hss = HandleSignalsState(); |
291 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, | 291 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, |
292 d0->AddWaiter(&w, MOJO_HANDLE_SIGNAL_READABLE, 2, &hss)); | 292 d0->AddAwakable(&w, MOJO_HANDLE_SIGNAL_READABLE, 2, &hss)); |
293 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, | 293 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, |
294 hss.satisfied_signals); | 294 hss.satisfied_signals); |
295 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, | 295 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, |
296 hss.satisfiable_signals); | 296 hss.satisfiable_signals); |
297 | 297 |
298 // Read again from |d0|. | 298 // Read again from |d0|. |
299 buffer[0] = 0; | 299 buffer[0] = 0; |
300 buffer_size = kBufferSize; | 300 buffer_size = kBufferSize; |
301 EXPECT_EQ(MOJO_RESULT_OK, | 301 EXPECT_EQ(MOJO_RESULT_OK, |
302 d0->ReadMessage(UserPointer<void>(buffer), | 302 d0->ReadMessage(UserPointer<void>(buffer), |
303 MakeUserPointer(&buffer_size), 0, nullptr, | 303 MakeUserPointer(&buffer_size), 0, nullptr, |
304 MOJO_READ_MESSAGE_FLAG_NONE)); | 304 MOJO_READ_MESSAGE_FLAG_NONE)); |
305 EXPECT_EQ(kBufferSize, buffer_size); | 305 EXPECT_EQ(kBufferSize, buffer_size); |
306 EXPECT_EQ(234567890, buffer[0]); | 306 EXPECT_EQ(234567890, buffer[0]); |
307 | 307 |
308 // Try waiting for readable on |d0|; should fail (unsatisfiable). | 308 // Try waiting for readable on |d0|; should fail (unsatisfiable). |
309 w.Init(); | 309 w.Init(); |
310 hss = HandleSignalsState(); | 310 hss = HandleSignalsState(); |
311 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, | 311 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, |
312 d0->AddWaiter(&w, MOJO_HANDLE_SIGNAL_READABLE, 3, &hss)); | 312 d0->AddAwakable(&w, MOJO_HANDLE_SIGNAL_READABLE, 3, &hss)); |
313 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfied_signals); | 313 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfied_signals); |
314 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfiable_signals); | 314 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfiable_signals); |
315 | 315 |
316 // Try waiting for writable on |d0|; should fail (unsatisfiable). | 316 // Try waiting for writable on |d0|; should fail (unsatisfiable). |
317 w.Init(); | 317 w.Init(); |
318 hss = HandleSignalsState(); | 318 hss = HandleSignalsState(); |
319 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, | 319 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, |
320 d0->AddWaiter(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 4, &hss)); | 320 d0->AddAwakable(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 4, &hss)); |
321 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfied_signals); | 321 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfied_signals); |
322 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfiable_signals); | 322 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfiable_signals); |
323 | 323 |
324 // Try reading from |d0|; should fail (nothing to read and other end | 324 // Try reading from |d0|; should fail (nothing to read and other end |
325 // closed). | 325 // closed). |
326 buffer[0] = 0; | 326 buffer[0] = 0; |
327 buffer_size = kBufferSize; | 327 buffer_size = kBufferSize; |
328 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, | 328 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, |
329 d0->ReadMessage(UserPointer<void>(buffer), | 329 d0->ReadMessage(UserPointer<void>(buffer), |
330 MakeUserPointer(&buffer_size), 0, nullptr, | 330 MakeUserPointer(&buffer_size), 0, nullptr, |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 unsigned char buffer[kMaxMessageSize]; | 552 unsigned char buffer[kMaxMessageSize]; |
553 Waiter w; | 553 Waiter w; |
554 HandleSignalsState hss; | 554 HandleSignalsState hss; |
555 MojoResult result; | 555 MojoResult result; |
556 | 556 |
557 // Read messages. | 557 // Read messages. |
558 for (;;) { | 558 for (;;) { |
559 // Wait for it to be readable. | 559 // Wait for it to be readable. |
560 w.Init(); | 560 w.Init(); |
561 hss = HandleSignalsState(); | 561 hss = HandleSignalsState(); |
562 result = | 562 result = read_dispatcher_->AddAwakable(&w, MOJO_HANDLE_SIGNAL_READABLE, 0, |
563 read_dispatcher_->AddWaiter(&w, MOJO_HANDLE_SIGNAL_READABLE, 0, &hss); | 563 &hss); |
564 EXPECT_TRUE(result == MOJO_RESULT_OK || | 564 EXPECT_TRUE(result == MOJO_RESULT_OK || |
565 result == MOJO_RESULT_ALREADY_EXISTS) | 565 result == MOJO_RESULT_ALREADY_EXISTS) |
566 << "result: " << result; | 566 << "result: " << result; |
567 if (result == MOJO_RESULT_OK) { | 567 if (result == MOJO_RESULT_OK) { |
568 // Actually need to wait. | 568 // Actually need to wait. |
569 EXPECT_EQ(MOJO_RESULT_OK, w.Wait(MOJO_DEADLINE_INDEFINITE, nullptr)); | 569 EXPECT_EQ(MOJO_RESULT_OK, w.Wait(MOJO_DEADLINE_INDEFINITE, nullptr)); |
570 read_dispatcher_->RemoveWaiter(&w, &hss); | 570 read_dispatcher_->RemoveAwakable(&w, &hss); |
571 } | 571 } |
572 // We may not actually be readable, since we're racing with other threads. | 572 // We may not actually be readable, since we're racing with other threads. |
573 EXPECT_TRUE((hss.satisfiable_signals & MOJO_HANDLE_SIGNAL_READABLE)); | 573 EXPECT_TRUE((hss.satisfiable_signals & MOJO_HANDLE_SIGNAL_READABLE)); |
574 | 574 |
575 // Now, try to do the read. | 575 // Now, try to do the read. |
576 // Clear the buffer so that we can check the result. | 576 // Clear the buffer so that we can check the result. |
577 memset(buffer, 0, sizeof(buffer)); | 577 memset(buffer, 0, sizeof(buffer)); |
578 uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer)); | 578 uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer)); |
579 result = read_dispatcher_->ReadMessage( | 579 result = read_dispatcher_->ReadMessage( |
580 UserPointer<void>(buffer), MakeUserPointer(&buffer_size), 0, nullptr, | 580 UserPointer<void>(buffer), MakeUserPointer(&buffer_size), 0, nullptr, |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
682 EXPECT_EQ(total_messages_written, total_messages_read); | 682 EXPECT_EQ(total_messages_written, total_messages_read); |
683 EXPECT_EQ(total_bytes_written, total_bytes_read); | 683 EXPECT_EQ(total_bytes_written, total_bytes_read); |
684 | 684 |
685 EXPECT_EQ(MOJO_RESULT_OK, d_write->Close()); | 685 EXPECT_EQ(MOJO_RESULT_OK, d_write->Close()); |
686 EXPECT_EQ(MOJO_RESULT_OK, d_read->Close()); | 686 EXPECT_EQ(MOJO_RESULT_OK, d_read->Close()); |
687 } | 687 } |
688 | 688 |
689 } // namespace | 689 } // namespace |
690 } // namespace system | 690 } // namespace system |
691 } // namespace mojo | 691 } // namespace mojo |
OLD | NEW |