Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(250)

Side by Side Diff: mojo/edk/system/remote_message_pipe_unittest.cc

Issue 782693004: Update mojo sdk to rev f6c8ec07c01deebc13178d516225fd12695c3dc2 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: hack mojo_system_impl gypi for android :| Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); 103 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop());
104 104
105 embedder::PlatformChannelPair channel_pair; 105 embedder::PlatformChannelPair channel_pair;
106 platform_handles_[0] = channel_pair.PassServerHandle(); 106 platform_handles_[0] = channel_pair.PassServerHandle();
107 platform_handles_[1] = channel_pair.PassClientHandle(); 107 platform_handles_[1] = channel_pair.PassClientHandle();
108 } 108 }
109 109
110 void TearDownOnIOThread() { 110 void TearDownOnIOThread() {
111 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); 111 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop());
112 112
113 if (channels_[0].get()) { 113 if (channels_[0]) {
114 channels_[0]->Shutdown(); 114 channels_[0]->Shutdown();
115 channels_[0] = nullptr; 115 channels_[0] = nullptr;
116 } 116 }
117 if (channels_[1].get()) { 117 if (channels_[1]) {
118 channels_[1]->Shutdown(); 118 channels_[1]->Shutdown();
119 channels_[1] = nullptr; 119 channels_[1] = nullptr;
120 } 120 }
121 } 121 }
122 122
123 void CreateAndInitChannel(unsigned channel_index) { 123 void CreateAndInitChannel(unsigned channel_index) {
124 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); 124 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop());
125 CHECK(channel_index == 0 || channel_index == 1); 125 CHECK(channel_index == 0 || channel_index == 1);
126 CHECK(!channels_[channel_index].get()); 126 CHECK(!channels_[channel_index]);
127 127
128 channels_[channel_index] = new Channel(&platform_support_); 128 channels_[channel_index] = new Channel(&platform_support_);
129 CHECK(channels_[channel_index]->Init( 129 CHECK(channels_[channel_index]->Init(
130 RawChannel::Create(platform_handles_[channel_index].Pass()))); 130 RawChannel::Create(platform_handles_[channel_index].Pass())));
131 } 131 }
132 132
133 void BootstrapChannelEndpointsOnIOThread(scoped_refptr<ChannelEndpoint> ep0, 133 void BootstrapChannelEndpointsOnIOThread(scoped_refptr<ChannelEndpoint> ep0,
134 scoped_refptr<ChannelEndpoint> ep1) { 134 scoped_refptr<ChannelEndpoint> ep1) {
135 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); 135 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop());
136 136
137 if (!channels_[0].get()) 137 if (!channels_[0])
138 CreateAndInitChannel(0); 138 CreateAndInitChannel(0);
139 if (!channels_[1].get()) 139 if (!channels_[1])
140 CreateAndInitChannel(1); 140 CreateAndInitChannel(1);
141 141
142 channels_[0]->AttachAndRunEndpoint(ep0, true); 142 channels_[0]->AttachAndRunEndpoint(ep0, true);
143 channels_[1]->AttachAndRunEndpoint(ep1, true); 143 channels_[1]->AttachAndRunEndpoint(ep1, true);
144 } 144 }
145 145
146 void BootstrapChannelEndpointOnIOThread(unsigned channel_index, 146 void BootstrapChannelEndpointOnIOThread(unsigned channel_index,
147 scoped_refptr<ChannelEndpoint> ep) { 147 scoped_refptr<ChannelEndpoint> ep) {
148 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); 148 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop());
149 CHECK(channel_index == 0 || channel_index == 1); 149 CHECK(channel_index == 0 || channel_index == 1);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1)); 186 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1));
187 BootstrapChannelEndpoints(ep0, ep1); 187 BootstrapChannelEndpoints(ep0, ep1);
188 188
189 // Write in one direction: MP 0, port 0 -> ... -> MP 1, port 1. 189 // Write in one direction: MP 0, port 0 -> ... -> MP 1, port 1.
190 190
191 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do 191 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do
192 // it later, it might already be readable.) 192 // it later, it might already be readable.)
193 waiter.Init(); 193 waiter.Init();
194 ASSERT_EQ( 194 ASSERT_EQ(
195 MOJO_RESULT_OK, 195 MOJO_RESULT_OK,
196 mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); 196 mp1->AddAwakable(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr));
197 197
198 // Write to MP 0, port 0. 198 // Write to MP 0, port 0.
199 EXPECT_EQ( 199 EXPECT_EQ(
200 MOJO_RESULT_OK, 200 MOJO_RESULT_OK,
201 mp0->WriteMessage(0, UserPointer<const void>(kHello), sizeof(kHello), 201 mp0->WriteMessage(0, UserPointer<const void>(kHello), sizeof(kHello),
202 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); 202 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
203 203
204 // Wait. 204 // Wait.
205 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); 205 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context));
206 EXPECT_EQ(123u, context); 206 EXPECT_EQ(123u, context);
207 hss = HandleSignalsState(); 207 hss = HandleSignalsState();
208 mp1->RemoveWaiter(1, &waiter, &hss); 208 mp1->RemoveAwakable(1, &waiter, &hss);
209 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 209 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
210 hss.satisfied_signals); 210 hss.satisfied_signals);
211 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); 211 EXPECT_EQ(kAllSignals, hss.satisfiable_signals);
212 212
213 // Read from MP 1, port 1. 213 // Read from MP 1, port 1.
214 EXPECT_EQ(MOJO_RESULT_OK, 214 EXPECT_EQ(MOJO_RESULT_OK,
215 mp1->ReadMessage(1, UserPointer<void>(buffer), 215 mp1->ReadMessage(1, UserPointer<void>(buffer),
216 MakeUserPointer(&buffer_size), nullptr, nullptr, 216 MakeUserPointer(&buffer_size), nullptr, nullptr,
217 MOJO_READ_MESSAGE_FLAG_NONE)); 217 MOJO_READ_MESSAGE_FLAG_NONE));
218 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(buffer_size)); 218 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(buffer_size));
219 EXPECT_STREQ(kHello, buffer); 219 EXPECT_STREQ(kHello, buffer);
220 220
221 // Write in the other direction: MP 1, port 1 -> ... -> MP 0, port 0. 221 // Write in the other direction: MP 1, port 1 -> ... -> MP 0, port 0.
222 222
223 waiter.Init(); 223 waiter.Init();
224 ASSERT_EQ( 224 ASSERT_EQ(
225 MOJO_RESULT_OK, 225 MOJO_RESULT_OK,
226 mp0->AddWaiter(0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 456, nullptr)); 226 mp0->AddAwakable(0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 456, nullptr));
227 227
228 EXPECT_EQ( 228 EXPECT_EQ(
229 MOJO_RESULT_OK, 229 MOJO_RESULT_OK,
230 mp1->WriteMessage(1, UserPointer<const void>(kWorld), sizeof(kWorld), 230 mp1->WriteMessage(1, UserPointer<const void>(kWorld), sizeof(kWorld),
231 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); 231 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
232 232
233 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); 233 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context));
234 EXPECT_EQ(456u, context); 234 EXPECT_EQ(456u, context);
235 hss = HandleSignalsState(); 235 hss = HandleSignalsState();
236 mp0->RemoveWaiter(0, &waiter, &hss); 236 mp0->RemoveAwakable(0, &waiter, &hss);
237 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 237 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
238 hss.satisfied_signals); 238 hss.satisfied_signals);
239 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); 239 EXPECT_EQ(kAllSignals, hss.satisfiable_signals);
240 240
241 buffer_size = static_cast<uint32_t>(sizeof(buffer)); 241 buffer_size = static_cast<uint32_t>(sizeof(buffer));
242 EXPECT_EQ(MOJO_RESULT_OK, 242 EXPECT_EQ(MOJO_RESULT_OK,
243 mp0->ReadMessage(0, UserPointer<void>(buffer), 243 mp0->ReadMessage(0, UserPointer<void>(buffer),
244 MakeUserPointer(&buffer_size), nullptr, nullptr, 244 MakeUserPointer(&buffer_size), nullptr, nullptr,
245 MOJO_READ_MESSAGE_FLAG_NONE)); 245 MOJO_READ_MESSAGE_FLAG_NONE));
246 EXPECT_EQ(sizeof(kWorld), static_cast<size_t>(buffer_size)); 246 EXPECT_EQ(sizeof(kWorld), static_cast<size_t>(buffer_size));
247 EXPECT_STREQ(kWorld, buffer); 247 EXPECT_STREQ(kWorld, buffer);
248 248
249 // Close MP 0, port 0. 249 // Close MP 0, port 0.
250 mp0->Close(0); 250 mp0->Close(0);
251 251
252 // Try to wait for MP 1, port 1 to become readable. This will eventually fail 252 // Try to wait for MP 1, port 1 to become readable. This will eventually fail
253 // when it realizes that MP 0, port 0 has been closed. (It may also fail 253 // when it realizes that MP 0, port 0 has been closed. (It may also fail
254 // immediately.) 254 // immediately.)
255 waiter.Init(); 255 waiter.Init();
256 hss = HandleSignalsState(); 256 hss = HandleSignalsState();
257 MojoResult result = 257 MojoResult result =
258 mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 789, &hss); 258 mp1->AddAwakable(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 789, &hss);
259 if (result == MOJO_RESULT_OK) { 259 if (result == MOJO_RESULT_OK) {
260 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, 260 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
261 waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); 261 waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context));
262 EXPECT_EQ(789u, context); 262 EXPECT_EQ(789u, context);
263 hss = HandleSignalsState(); 263 hss = HandleSignalsState();
264 mp1->RemoveWaiter(1, &waiter, &hss); 264 mp1->RemoveAwakable(1, &waiter, &hss);
265 } 265 }
266 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfied_signals); 266 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfied_signals);
267 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfiable_signals); 267 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfiable_signals);
268 268
269 // And MP 1, port 1. 269 // And MP 1, port 1.
270 mp1->Close(1); 270 mp1->Close(1);
271 } 271 }
272 272
273 TEST_F(RemoteMessagePipeTest, PeerClosed) { 273 TEST_F(RemoteMessagePipeTest, PeerClosed) {
274 Waiter waiter; 274 Waiter waiter;
(...skipping 10 matching lines...) Expand all
285 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1)); 285 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1));
286 BootstrapChannelEndpoints(ep0, ep1); 286 BootstrapChannelEndpoints(ep0, ep1);
287 287
288 // Close MP 0, port 0. 288 // Close MP 0, port 0.
289 mp0->Close(0); 289 mp0->Close(0);
290 290
291 // Try to wait for MP 1, port 1 to be signaled with peer closed. 291 // Try to wait for MP 1, port 1 to be signaled with peer closed.
292 waiter.Init(); 292 waiter.Init();
293 hss = HandleSignalsState(); 293 hss = HandleSignalsState();
294 MojoResult result = 294 MojoResult result =
295 mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_PEER_CLOSED, 101, &hss); 295 mp1->AddAwakable(1, &waiter, MOJO_HANDLE_SIGNAL_PEER_CLOSED, 101, &hss);
296 if (result == MOJO_RESULT_OK) { 296 if (result == MOJO_RESULT_OK) {
297 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); 297 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context));
298 EXPECT_EQ(101u, context); 298 EXPECT_EQ(101u, context);
299 hss = HandleSignalsState(); 299 hss = HandleSignalsState();
300 mp1->RemoveWaiter(1, &waiter, &hss); 300 mp1->RemoveAwakable(1, &waiter, &hss);
301 } 301 }
302 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfied_signals); 302 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfied_signals);
303 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfiable_signals); 303 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfiable_signals);
304 304
305 // And MP 1, port 1. 305 // And MP 1, port 1.
306 mp1->Close(1); 306 mp1->Close(1);
307 } 307 }
308 308
309 TEST_F(RemoteMessagePipeTest, Multiplex) { 309 TEST_F(RemoteMessagePipeTest, Multiplex) {
310 static const char kHello[] = "hello"; 310 static const char kHello[] = "hello";
(...skipping 21 matching lines...) Expand all
332 // message pipe on the other side. 332 // message pipe on the other side.
333 scoped_refptr<ChannelEndpoint> ep2; 333 scoped_refptr<ChannelEndpoint> ep2;
334 scoped_refptr<MessagePipe> mp2(MessagePipe::CreateLocalProxy(&ep2)); 334 scoped_refptr<MessagePipe> mp2(MessagePipe::CreateLocalProxy(&ep2));
335 ASSERT_TRUE(channels(0)); 335 ASSERT_TRUE(channels(0));
336 ChannelEndpointId remote_id = channels(0)->AttachAndRunEndpoint(ep2, false); 336 ChannelEndpointId remote_id = channels(0)->AttachAndRunEndpoint(ep2, false);
337 EXPECT_TRUE(remote_id.is_remote()); 337 EXPECT_TRUE(remote_id.is_remote());
338 338
339 waiter.Init(); 339 waiter.Init();
340 ASSERT_EQ( 340 ASSERT_EQ(
341 MOJO_RESULT_OK, 341 MOJO_RESULT_OK,
342 mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); 342 mp1->AddAwakable(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr));
343 343
344 EXPECT_EQ(MOJO_RESULT_OK, 344 EXPECT_EQ(MOJO_RESULT_OK,
345 mp0->WriteMessage(0, UserPointer<const void>(&remote_id), 345 mp0->WriteMessage(0, UserPointer<const void>(&remote_id),
346 sizeof(remote_id), nullptr, 346 sizeof(remote_id), nullptr,
347 MOJO_WRITE_MESSAGE_FLAG_NONE)); 347 MOJO_WRITE_MESSAGE_FLAG_NONE));
348 348
349 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); 349 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context));
350 EXPECT_EQ(123u, context); 350 EXPECT_EQ(123u, context);
351 hss = HandleSignalsState(); 351 hss = HandleSignalsState();
352 mp1->RemoveWaiter(1, &waiter, &hss); 352 mp1->RemoveAwakable(1, &waiter, &hss);
353 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 353 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
354 hss.satisfied_signals); 354 hss.satisfied_signals);
355 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); 355 EXPECT_EQ(kAllSignals, hss.satisfiable_signals);
356 356
357 ChannelEndpointId received_id; 357 ChannelEndpointId received_id;
358 buffer_size = static_cast<uint32_t>(sizeof(received_id)); 358 buffer_size = static_cast<uint32_t>(sizeof(received_id));
359 EXPECT_EQ(MOJO_RESULT_OK, 359 EXPECT_EQ(MOJO_RESULT_OK,
360 mp1->ReadMessage(1, UserPointer<void>(&received_id), 360 mp1->ReadMessage(1, UserPointer<void>(&received_id),
361 MakeUserPointer(&buffer_size), nullptr, nullptr, 361 MakeUserPointer(&buffer_size), nullptr, nullptr,
362 MOJO_READ_MESSAGE_FLAG_NONE)); 362 MOJO_READ_MESSAGE_FLAG_NONE));
363 EXPECT_EQ(sizeof(received_id), static_cast<size_t>(buffer_size)); 363 EXPECT_EQ(sizeof(received_id), static_cast<size_t>(buffer_size));
364 EXPECT_EQ(remote_id, received_id); 364 EXPECT_EQ(remote_id, received_id);
365 365
366 // Warning: The local side of mp3 is port 0, not port 1. 366 // Warning: The local side of mp3 is port 0, not port 1.
367 scoped_refptr<MessagePipe> mp3 = 367 scoped_refptr<MessagePipe> mp3 =
368 channels(1)->PassIncomingMessagePipe(received_id); 368 channels(1)->PassIncomingMessagePipe(received_id);
369 ASSERT_TRUE(mp3.get()); 369 ASSERT_TRUE(mp3);
370 370
371 // Write: MP 2, port 0 -> MP 3, port 1. 371 // Write: MP 2, port 0 -> MP 3, port 1.
372 372
373 waiter.Init(); 373 waiter.Init();
374 ASSERT_EQ( 374 ASSERT_EQ(
375 MOJO_RESULT_OK, 375 MOJO_RESULT_OK,
376 mp3->AddWaiter(0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 789, nullptr)); 376 mp3->AddAwakable(0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 789, nullptr));
377 377
378 EXPECT_EQ( 378 EXPECT_EQ(
379 MOJO_RESULT_OK, 379 MOJO_RESULT_OK,
380 mp2->WriteMessage(0, UserPointer<const void>(kHello), sizeof(kHello), 380 mp2->WriteMessage(0, UserPointer<const void>(kHello), sizeof(kHello),
381 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); 381 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
382 382
383 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); 383 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context));
384 EXPECT_EQ(789u, context); 384 EXPECT_EQ(789u, context);
385 hss = HandleSignalsState(); 385 hss = HandleSignalsState();
386 mp3->RemoveWaiter(0, &waiter, &hss); 386 mp3->RemoveAwakable(0, &waiter, &hss);
387 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 387 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
388 hss.satisfied_signals); 388 hss.satisfied_signals);
389 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); 389 EXPECT_EQ(kAllSignals, hss.satisfiable_signals);
390 390
391 // Make sure there's nothing on MP 0, port 0 or MP 1, port 1 or MP 2, port 0. 391 // Make sure there's nothing on MP 0, port 0 or MP 1, port 1 or MP 2, port 0.
392 buffer_size = static_cast<uint32_t>(sizeof(buffer)); 392 buffer_size = static_cast<uint32_t>(sizeof(buffer));
393 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT, 393 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT,
394 mp0->ReadMessage(0, UserPointer<void>(buffer), 394 mp0->ReadMessage(0, UserPointer<void>(buffer),
395 MakeUserPointer(&buffer_size), nullptr, nullptr, 395 MakeUserPointer(&buffer_size), nullptr, nullptr,
396 MOJO_READ_MESSAGE_FLAG_NONE)); 396 MOJO_READ_MESSAGE_FLAG_NONE));
(...skipping 15 matching lines...) Expand all
412 MakeUserPointer(&buffer_size), nullptr, nullptr, 412 MakeUserPointer(&buffer_size), nullptr, nullptr,
413 MOJO_READ_MESSAGE_FLAG_NONE)); 413 MOJO_READ_MESSAGE_FLAG_NONE));
414 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(buffer_size)); 414 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(buffer_size));
415 EXPECT_STREQ(kHello, buffer); 415 EXPECT_STREQ(kHello, buffer);
416 416
417 // Write: MP 0, port 0 -> MP 1, port 1 again. 417 // Write: MP 0, port 0 -> MP 1, port 1 again.
418 418
419 waiter.Init(); 419 waiter.Init();
420 ASSERT_EQ( 420 ASSERT_EQ(
421 MOJO_RESULT_OK, 421 MOJO_RESULT_OK,
422 mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); 422 mp1->AddAwakable(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr));
423 423
424 EXPECT_EQ( 424 EXPECT_EQ(
425 MOJO_RESULT_OK, 425 MOJO_RESULT_OK,
426 mp0->WriteMessage(0, UserPointer<const void>(kWorld), sizeof(kWorld), 426 mp0->WriteMessage(0, UserPointer<const void>(kWorld), sizeof(kWorld),
427 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); 427 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
428 428
429 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); 429 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context));
430 EXPECT_EQ(123u, context); 430 EXPECT_EQ(123u, context);
431 hss = HandleSignalsState(); 431 hss = HandleSignalsState();
432 mp1->RemoveWaiter(1, &waiter, &hss); 432 mp1->RemoveAwakable(1, &waiter, &hss);
433 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 433 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
434 hss.satisfied_signals); 434 hss.satisfied_signals);
435 EXPECT_EQ(kAllSignals | MOJO_HANDLE_SIGNAL_PEER_CLOSED, 435 EXPECT_EQ(kAllSignals | MOJO_HANDLE_SIGNAL_PEER_CLOSED,
436 hss.satisfiable_signals); 436 hss.satisfiable_signals);
437 437
438 // Make sure there's nothing on the other ports. 438 // Make sure there's nothing on the other ports.
439 buffer_size = static_cast<uint32_t>(sizeof(buffer)); 439 buffer_size = static_cast<uint32_t>(sizeof(buffer));
440 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT, 440 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT,
441 mp0->ReadMessage(0, UserPointer<void>(buffer), 441 mp0->ReadMessage(0, UserPointer<void>(buffer),
442 MakeUserPointer(&buffer_size), nullptr, nullptr, 442 MakeUserPointer(&buffer_size), nullptr, nullptr,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 BootstrapChannelEndpointNoWait(0, ep0); 493 BootstrapChannelEndpointNoWait(0, ep0);
494 494
495 scoped_refptr<ChannelEndpoint> ep1; 495 scoped_refptr<ChannelEndpoint> ep1;
496 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1)); 496 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1));
497 497
498 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do 498 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do
499 // it later, it might already be readable.) 499 // it later, it might already be readable.)
500 waiter.Init(); 500 waiter.Init();
501 ASSERT_EQ( 501 ASSERT_EQ(
502 MOJO_RESULT_OK, 502 MOJO_RESULT_OK,
503 mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); 503 mp1->AddAwakable(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr));
504 504
505 BootstrapChannelEndpointNoWait(1, ep1); 505 BootstrapChannelEndpointNoWait(1, ep1);
506 506
507 // Wait. 507 // Wait.
508 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); 508 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context));
509 EXPECT_EQ(123u, context); 509 EXPECT_EQ(123u, context);
510 hss = HandleSignalsState(); 510 hss = HandleSignalsState();
511 // Note: MP 1, port 1 should definitely should be readable, but it may or may 511 // Note: MP 1, port 1 should definitely should be readable, but it may or may
512 // not appear as writable (there's a race, and it may not have noticed that 512 // not appear as writable (there's a race, and it may not have noticed that
513 // the other side was closed yet -- e.g., inserting a sleep here would make it 513 // the other side was closed yet -- e.g., inserting a sleep here would make it
514 // much more likely to notice that it's no longer writable). 514 // much more likely to notice that it's no longer writable).
515 mp1->RemoveWaiter(1, &waiter, &hss); 515 mp1->RemoveAwakable(1, &waiter, &hss);
516 EXPECT_TRUE((hss.satisfied_signals & MOJO_HANDLE_SIGNAL_READABLE)); 516 EXPECT_TRUE((hss.satisfied_signals & MOJO_HANDLE_SIGNAL_READABLE));
517 EXPECT_TRUE((hss.satisfiable_signals & MOJO_HANDLE_SIGNAL_READABLE)); 517 EXPECT_TRUE((hss.satisfiable_signals & MOJO_HANDLE_SIGNAL_READABLE));
518 518
519 // Read from MP 1, port 1. 519 // Read from MP 1, port 1.
520 EXPECT_EQ(MOJO_RESULT_OK, 520 EXPECT_EQ(MOJO_RESULT_OK,
521 mp1->ReadMessage(1, UserPointer<void>(buffer), 521 mp1->ReadMessage(1, UserPointer<void>(buffer),
522 MakeUserPointer(&buffer_size), nullptr, nullptr, 522 MakeUserPointer(&buffer_size), nullptr, nullptr,
523 MOJO_READ_MESSAGE_FLAG_NONE)); 523 MOJO_READ_MESSAGE_FLAG_NONE));
524 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(buffer_size)); 524 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(buffer_size));
525 EXPECT_STREQ(kHello, buffer); 525 EXPECT_STREQ(kHello, buffer);
(...skipping 29 matching lines...) Expand all
555 mp0->Close(0); 555 mp0->Close(0);
556 556
557 scoped_refptr<ChannelEndpoint> ep1; 557 scoped_refptr<ChannelEndpoint> ep1;
558 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1)); 558 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1));
559 559
560 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do 560 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do
561 // it later, it might already be readable.) 561 // it later, it might already be readable.)
562 waiter.Init(); 562 waiter.Init();
563 ASSERT_EQ( 563 ASSERT_EQ(
564 MOJO_RESULT_OK, 564 MOJO_RESULT_OK,
565 mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); 565 mp1->AddAwakable(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr));
566 566
567 BootstrapChannelEndpointNoWait(1, ep1); 567 BootstrapChannelEndpointNoWait(1, ep1);
568 568
569 // Wait. 569 // Wait.
570 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); 570 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context));
571 EXPECT_EQ(123u, context); 571 EXPECT_EQ(123u, context);
572 hss = HandleSignalsState(); 572 hss = HandleSignalsState();
573 // Note: MP 1, port 1 should definitely should be readable, but it may or may 573 // Note: MP 1, port 1 should definitely should be readable, but it may or may
574 // not appear as writable (there's a race, and it may not have noticed that 574 // not appear as writable (there's a race, and it may not have noticed that
575 // the other side was closed yet -- e.g., inserting a sleep here would make it 575 // the other side was closed yet -- e.g., inserting a sleep here would make it
576 // much more likely to notice that it's no longer writable). 576 // much more likely to notice that it's no longer writable).
577 mp1->RemoveWaiter(1, &waiter, &hss); 577 mp1->RemoveAwakable(1, &waiter, &hss);
578 EXPECT_TRUE((hss.satisfied_signals & MOJO_HANDLE_SIGNAL_READABLE)); 578 EXPECT_TRUE((hss.satisfied_signals & MOJO_HANDLE_SIGNAL_READABLE));
579 EXPECT_TRUE((hss.satisfiable_signals & MOJO_HANDLE_SIGNAL_READABLE)); 579 EXPECT_TRUE((hss.satisfiable_signals & MOJO_HANDLE_SIGNAL_READABLE));
580 580
581 // Read from MP 1, port 1. 581 // Read from MP 1, port 1.
582 EXPECT_EQ(MOJO_RESULT_OK, 582 EXPECT_EQ(MOJO_RESULT_OK,
583 mp1->ReadMessage(1, UserPointer<void>(buffer), 583 mp1->ReadMessage(1, UserPointer<void>(buffer),
584 MakeUserPointer(&buffer_size), nullptr, nullptr, 584 MakeUserPointer(&buffer_size), nullptr, nullptr,
585 MOJO_READ_MESSAGE_FLAG_NONE)); 585 MOJO_READ_MESSAGE_FLAG_NONE));
586 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(buffer_size)); 586 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(buffer_size));
587 EXPECT_STREQ(kHello, buffer); 587 EXPECT_STREQ(kHello, buffer);
(...skipping 18 matching lines...) Expand all
606 scoped_refptr<MessagePipeDispatcher> dispatcher( 606 scoped_refptr<MessagePipeDispatcher> dispatcher(
607 new MessagePipeDispatcher(MessagePipeDispatcher::kDefaultCreateOptions)); 607 new MessagePipeDispatcher(MessagePipeDispatcher::kDefaultCreateOptions));
608 scoped_refptr<MessagePipe> local_mp(MessagePipe::CreateLocalLocal()); 608 scoped_refptr<MessagePipe> local_mp(MessagePipe::CreateLocalLocal());
609 dispatcher->Init(local_mp, 0); 609 dispatcher->Init(local_mp, 0);
610 610
611 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do 611 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do
612 // it later, it might already be readable.) 612 // it later, it might already be readable.)
613 waiter.Init(); 613 waiter.Init();
614 ASSERT_EQ( 614 ASSERT_EQ(
615 MOJO_RESULT_OK, 615 MOJO_RESULT_OK,
616 mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); 616 mp1->AddAwakable(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr));
617 617
618 // Write to MP 0, port 0. 618 // Write to MP 0, port 0.
619 { 619 {
620 DispatcherTransport transport( 620 DispatcherTransport transport(
621 test::DispatcherTryStartTransport(dispatcher.get())); 621 test::DispatcherTryStartTransport(dispatcher.get()));
622 EXPECT_TRUE(transport.is_valid()); 622 EXPECT_TRUE(transport.is_valid());
623 623
624 std::vector<DispatcherTransport> transports; 624 std::vector<DispatcherTransport> transports;
625 transports.push_back(transport); 625 transports.push_back(transport);
626 EXPECT_EQ( 626 EXPECT_EQ(
627 MOJO_RESULT_OK, 627 MOJO_RESULT_OK,
628 mp0->WriteMessage(0, UserPointer<const void>(kHello), sizeof(kHello), 628 mp0->WriteMessage(0, UserPointer<const void>(kHello), sizeof(kHello),
629 &transports, MOJO_WRITE_MESSAGE_FLAG_NONE)); 629 &transports, MOJO_WRITE_MESSAGE_FLAG_NONE));
630 transport.End(); 630 transport.End();
631 631
632 // |dispatcher| should have been closed. This is |DCHECK()|ed when the 632 // |dispatcher| should have been closed. This is |DCHECK()|ed when the
633 // |dispatcher| is destroyed. 633 // |dispatcher| is destroyed.
634 EXPECT_TRUE(dispatcher->HasOneRef()); 634 EXPECT_TRUE(dispatcher->HasOneRef());
635 dispatcher = nullptr; 635 dispatcher = nullptr;
636 } 636 }
637 637
638 // Wait. 638 // Wait.
639 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); 639 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context));
640 EXPECT_EQ(123u, context); 640 EXPECT_EQ(123u, context);
641 hss = HandleSignalsState(); 641 hss = HandleSignalsState();
642 mp1->RemoveWaiter(1, &waiter, &hss); 642 mp1->RemoveAwakable(1, &waiter, &hss);
643 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 643 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
644 hss.satisfied_signals); 644 hss.satisfied_signals);
645 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); 645 EXPECT_EQ(kAllSignals, hss.satisfiable_signals);
646 646
647 // Read from MP 1, port 1. 647 // Read from MP 1, port 1.
648 char read_buffer[100] = {0}; 648 char read_buffer[100] = {0};
649 uint32_t read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer)); 649 uint32_t read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer));
650 DispatcherVector read_dispatchers; 650 DispatcherVector read_dispatchers;
651 uint32_t read_num_dispatchers = 10; // Maximum to get. 651 uint32_t read_num_dispatchers = 10; // Maximum to get.
652 EXPECT_EQ( 652 EXPECT_EQ(
653 MOJO_RESULT_OK, 653 MOJO_RESULT_OK,
654 mp1->ReadMessage(1, UserPointer<void>(read_buffer), 654 mp1->ReadMessage(1, UserPointer<void>(read_buffer),
655 MakeUserPointer(&read_buffer_size), &read_dispatchers, 655 MakeUserPointer(&read_buffer_size), &read_dispatchers,
656 &read_num_dispatchers, MOJO_READ_MESSAGE_FLAG_NONE)); 656 &read_num_dispatchers, MOJO_READ_MESSAGE_FLAG_NONE));
657 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size)); 657 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size));
658 EXPECT_STREQ(kHello, read_buffer); 658 EXPECT_STREQ(kHello, read_buffer);
659 EXPECT_EQ(1u, read_dispatchers.size()); 659 EXPECT_EQ(1u, read_dispatchers.size());
660 EXPECT_EQ(1u, read_num_dispatchers); 660 EXPECT_EQ(1u, read_num_dispatchers);
661 ASSERT_TRUE(read_dispatchers[0].get()); 661 ASSERT_TRUE(read_dispatchers[0]);
662 EXPECT_TRUE(read_dispatchers[0]->HasOneRef()); 662 EXPECT_TRUE(read_dispatchers[0]->HasOneRef());
663 663
664 EXPECT_EQ(Dispatcher::kTypeMessagePipe, read_dispatchers[0]->GetType()); 664 EXPECT_EQ(Dispatcher::kTypeMessagePipe, read_dispatchers[0]->GetType());
665 dispatcher = static_cast<MessagePipeDispatcher*>(read_dispatchers[0].get()); 665 dispatcher = static_cast<MessagePipeDispatcher*>(read_dispatchers[0].get());
666 666
667 // Add the waiter now, before it becomes readable to avoid a race. 667 // Add the waiter now, before it becomes readable to avoid a race.
668 waiter.Init(); 668 waiter.Init();
669 ASSERT_EQ(MOJO_RESULT_OK, 669 ASSERT_EQ(MOJO_RESULT_OK,
670 dispatcher->AddWaiter(&waiter, MOJO_HANDLE_SIGNAL_READABLE, 456, 670 dispatcher->AddAwakable(&waiter, MOJO_HANDLE_SIGNAL_READABLE, 456,
671 nullptr)); 671 nullptr));
672 672
673 // Write to "local_mp", port 1. 673 // Write to "local_mp", port 1.
674 EXPECT_EQ( 674 EXPECT_EQ(
675 MOJO_RESULT_OK, 675 MOJO_RESULT_OK,
676 local_mp->WriteMessage(1, UserPointer<const void>(kHello), sizeof(kHello), 676 local_mp->WriteMessage(1, UserPointer<const void>(kHello), sizeof(kHello),
677 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); 677 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
678 678
679 // TODO(vtl): FIXME -- We (racily) crash if I close |dispatcher| immediately 679 // TODO(vtl): FIXME -- We (racily) crash if I close |dispatcher| immediately
680 // here. (We don't crash if I sleep and then close.) 680 // here. (We don't crash if I sleep and then close.)
681 681
682 // Wait for the dispatcher to become readable. 682 // Wait for the dispatcher to become readable.
683 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); 683 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context));
684 EXPECT_EQ(456u, context); 684 EXPECT_EQ(456u, context);
685 hss = HandleSignalsState(); 685 hss = HandleSignalsState();
686 dispatcher->RemoveWaiter(&waiter, &hss); 686 dispatcher->RemoveAwakable(&waiter, &hss);
687 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 687 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
688 hss.satisfied_signals); 688 hss.satisfied_signals);
689 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); 689 EXPECT_EQ(kAllSignals, hss.satisfiable_signals);
690 690
691 // Read from the dispatcher. 691 // Read from the dispatcher.
692 memset(read_buffer, 0, sizeof(read_buffer)); 692 memset(read_buffer, 0, sizeof(read_buffer));
693 read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer)); 693 read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer));
694 EXPECT_EQ(MOJO_RESULT_OK, 694 EXPECT_EQ(MOJO_RESULT_OK,
695 dispatcher->ReadMessage(UserPointer<void>(read_buffer), 695 dispatcher->ReadMessage(UserPointer<void>(read_buffer),
696 MakeUserPointer(&read_buffer_size), 0, 696 MakeUserPointer(&read_buffer_size), 0,
697 nullptr, MOJO_READ_MESSAGE_FLAG_NONE)); 697 nullptr, MOJO_READ_MESSAGE_FLAG_NONE));
698 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size)); 698 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size));
699 EXPECT_STREQ(kHello, read_buffer); 699 EXPECT_STREQ(kHello, read_buffer);
700 700
701 // Prepare to wait on "local_mp", port 1. 701 // Prepare to wait on "local_mp", port 1.
702 waiter.Init(); 702 waiter.Init();
703 ASSERT_EQ(MOJO_RESULT_OK, 703 ASSERT_EQ(MOJO_RESULT_OK,
704 local_mp->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 789, 704 local_mp->AddAwakable(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 789,
705 nullptr)); 705 nullptr));
706 706
707 // Write to the dispatcher. 707 // Write to the dispatcher.
708 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->WriteMessage( 708 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->WriteMessage(
709 UserPointer<const void>(kHello), sizeof(kHello), 709 UserPointer<const void>(kHello), sizeof(kHello),
710 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); 710 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
711 711
712 // Wait. 712 // Wait.
713 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); 713 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context));
714 EXPECT_EQ(789u, context); 714 EXPECT_EQ(789u, context);
715 hss = HandleSignalsState(); 715 hss = HandleSignalsState();
716 local_mp->RemoveWaiter(1, &waiter, &hss); 716 local_mp->RemoveAwakable(1, &waiter, &hss);
717 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 717 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
718 hss.satisfied_signals); 718 hss.satisfied_signals);
719 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); 719 EXPECT_EQ(kAllSignals, hss.satisfiable_signals);
720 720
721 // Read from "local_mp", port 1. 721 // Read from "local_mp", port 1.
722 memset(read_buffer, 0, sizeof(read_buffer)); 722 memset(read_buffer, 0, sizeof(read_buffer));
723 read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer)); 723 read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer));
724 EXPECT_EQ(MOJO_RESULT_OK, 724 EXPECT_EQ(MOJO_RESULT_OK,
725 local_mp->ReadMessage(1, UserPointer<void>(read_buffer), 725 local_mp->ReadMessage(1, UserPointer<void>(read_buffer),
726 MakeUserPointer(&read_buffer_size), nullptr, 726 MakeUserPointer(&read_buffer_size), nullptr,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy(&ep0)); 780 scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy(&ep0));
781 scoped_refptr<ChannelEndpoint> ep1; 781 scoped_refptr<ChannelEndpoint> ep1;
782 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1)); 782 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1));
783 BootstrapChannelEndpoints(ep0, ep1); 783 BootstrapChannelEndpoints(ep0, ep1);
784 784
785 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do 785 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do
786 // it later, it might already be readable.) 786 // it later, it might already be readable.)
787 waiter.Init(); 787 waiter.Init();
788 ASSERT_EQ( 788 ASSERT_EQ(
789 MOJO_RESULT_OK, 789 MOJO_RESULT_OK,
790 mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); 790 mp1->AddAwakable(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr));
791 791
792 // Write to MP 0, port 0. 792 // Write to MP 0, port 0.
793 { 793 {
794 DispatcherTransport transport( 794 DispatcherTransport transport(
795 test::DispatcherTryStartTransport(dispatcher.get())); 795 test::DispatcherTryStartTransport(dispatcher.get()));
796 EXPECT_TRUE(transport.is_valid()); 796 EXPECT_TRUE(transport.is_valid());
797 797
798 std::vector<DispatcherTransport> transports; 798 std::vector<DispatcherTransport> transports;
799 transports.push_back(transport); 799 transports.push_back(transport);
800 EXPECT_EQ( 800 EXPECT_EQ(
801 MOJO_RESULT_OK, 801 MOJO_RESULT_OK,
802 mp0->WriteMessage(0, UserPointer<const void>(kHello), sizeof(kHello), 802 mp0->WriteMessage(0, UserPointer<const void>(kHello), sizeof(kHello),
803 &transports, MOJO_WRITE_MESSAGE_FLAG_NONE)); 803 &transports, MOJO_WRITE_MESSAGE_FLAG_NONE));
804 transport.End(); 804 transport.End();
805 805
806 // |dispatcher| should have been closed. This is |DCHECK()|ed when the 806 // |dispatcher| should have been closed. This is |DCHECK()|ed when the
807 // |dispatcher| is destroyed. 807 // |dispatcher| is destroyed.
808 EXPECT_TRUE(dispatcher->HasOneRef()); 808 EXPECT_TRUE(dispatcher->HasOneRef());
809 dispatcher = nullptr; 809 dispatcher = nullptr;
810 } 810 }
811 811
812 // Wait. 812 // Wait.
813 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); 813 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context));
814 EXPECT_EQ(123u, context); 814 EXPECT_EQ(123u, context);
815 hss = HandleSignalsState(); 815 hss = HandleSignalsState();
816 mp1->RemoveWaiter(1, &waiter, &hss); 816 mp1->RemoveAwakable(1, &waiter, &hss);
817 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 817 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
818 hss.satisfied_signals); 818 hss.satisfied_signals);
819 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); 819 EXPECT_EQ(kAllSignals, hss.satisfiable_signals);
820 820
821 // Read from MP 1, port 1. 821 // Read from MP 1, port 1.
822 char read_buffer[100] = {0}; 822 char read_buffer[100] = {0};
823 uint32_t read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer)); 823 uint32_t read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer));
824 DispatcherVector read_dispatchers; 824 DispatcherVector read_dispatchers;
825 uint32_t read_num_dispatchers = 10; // Maximum to get. 825 uint32_t read_num_dispatchers = 10; // Maximum to get.
826 EXPECT_EQ( 826 EXPECT_EQ(
827 MOJO_RESULT_OK, 827 MOJO_RESULT_OK,
828 mp1->ReadMessage(1, UserPointer<void>(read_buffer), 828 mp1->ReadMessage(1, UserPointer<void>(read_buffer),
829 MakeUserPointer(&read_buffer_size), &read_dispatchers, 829 MakeUserPointer(&read_buffer_size), &read_dispatchers,
830 &read_num_dispatchers, MOJO_READ_MESSAGE_FLAG_NONE)); 830 &read_num_dispatchers, MOJO_READ_MESSAGE_FLAG_NONE));
831 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size)); 831 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size));
832 EXPECT_STREQ(kHello, read_buffer); 832 EXPECT_STREQ(kHello, read_buffer);
833 EXPECT_EQ(1u, read_dispatchers.size()); 833 EXPECT_EQ(1u, read_dispatchers.size());
834 EXPECT_EQ(1u, read_num_dispatchers); 834 EXPECT_EQ(1u, read_num_dispatchers);
835 ASSERT_TRUE(read_dispatchers[0].get()); 835 ASSERT_TRUE(read_dispatchers[0]);
836 EXPECT_TRUE(read_dispatchers[0]->HasOneRef()); 836 EXPECT_TRUE(read_dispatchers[0]->HasOneRef());
837 837
838 EXPECT_EQ(Dispatcher::kTypeMessagePipe, read_dispatchers[0]->GetType()); 838 EXPECT_EQ(Dispatcher::kTypeMessagePipe, read_dispatchers[0]->GetType());
839 dispatcher = static_cast<MessagePipeDispatcher*>(read_dispatchers[0].get()); 839 dispatcher = static_cast<MessagePipeDispatcher*>(read_dispatchers[0].get());
840 840
841 // |dispatcher| should already be readable and not writable. 841 // |dispatcher| should already be readable and not writable.
842 hss = dispatcher->GetHandleSignalsState(); 842 hss = dispatcher->GetHandleSignalsState();
843 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, 843 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED,
844 hss.satisfied_signals); 844 hss.satisfied_signals);
845 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, 845 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 scoped_refptr<ChannelEndpoint> ep1; 896 scoped_refptr<ChannelEndpoint> ep1;
897 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1)); 897 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1));
898 BootstrapChannelEndpoints(ep0, ep1); 898 BootstrapChannelEndpoints(ep0, ep1);
899 899
900 // We'll try to pass this dispatcher. 900 // We'll try to pass this dispatcher.
901 scoped_refptr<SharedBufferDispatcher> dispatcher; 901 scoped_refptr<SharedBufferDispatcher> dispatcher;
902 EXPECT_EQ(MOJO_RESULT_OK, SharedBufferDispatcher::Create( 902 EXPECT_EQ(MOJO_RESULT_OK, SharedBufferDispatcher::Create(
903 platform_support(), 903 platform_support(),
904 SharedBufferDispatcher::kDefaultCreateOptions, 904 SharedBufferDispatcher::kDefaultCreateOptions,
905 100, &dispatcher)); 905 100, &dispatcher));
906 ASSERT_TRUE(dispatcher.get()); 906 ASSERT_TRUE(dispatcher);
907 907
908 // Make a mapping. 908 // Make a mapping.
909 scoped_ptr<embedder::PlatformSharedBufferMapping> mapping0; 909 scoped_ptr<embedder::PlatformSharedBufferMapping> mapping0;
910 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->MapBuffer( 910 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->MapBuffer(
911 0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping0)); 911 0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping0));
912 ASSERT_TRUE(mapping0); 912 ASSERT_TRUE(mapping0);
913 ASSERT_TRUE(mapping0->GetBase()); 913 ASSERT_TRUE(mapping0->GetBase());
914 ASSERT_EQ(100u, mapping0->GetLength()); 914 ASSERT_EQ(100u, mapping0->GetLength());
915 static_cast<char*>(mapping0->GetBase())[0] = 'A'; 915 static_cast<char*>(mapping0->GetBase())[0] = 'A';
916 static_cast<char*>(mapping0->GetBase())[50] = 'B'; 916 static_cast<char*>(mapping0->GetBase())[50] = 'B';
917 static_cast<char*>(mapping0->GetBase())[99] = 'C'; 917 static_cast<char*>(mapping0->GetBase())[99] = 'C';
918 918
919 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do 919 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do
920 // it later, it might already be readable.) 920 // it later, it might already be readable.)
921 waiter.Init(); 921 waiter.Init();
922 ASSERT_EQ( 922 ASSERT_EQ(
923 MOJO_RESULT_OK, 923 MOJO_RESULT_OK,
924 mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); 924 mp1->AddAwakable(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr));
925 925
926 // Write to MP 0, port 0. 926 // Write to MP 0, port 0.
927 { 927 {
928 DispatcherTransport transport( 928 DispatcherTransport transport(
929 test::DispatcherTryStartTransport(dispatcher.get())); 929 test::DispatcherTryStartTransport(dispatcher.get()));
930 EXPECT_TRUE(transport.is_valid()); 930 EXPECT_TRUE(transport.is_valid());
931 931
932 std::vector<DispatcherTransport> transports; 932 std::vector<DispatcherTransport> transports;
933 transports.push_back(transport); 933 transports.push_back(transport);
934 EXPECT_EQ( 934 EXPECT_EQ(
935 MOJO_RESULT_OK, 935 MOJO_RESULT_OK,
936 mp0->WriteMessage(0, UserPointer<const void>(kHello), sizeof(kHello), 936 mp0->WriteMessage(0, UserPointer<const void>(kHello), sizeof(kHello),
937 &transports, MOJO_WRITE_MESSAGE_FLAG_NONE)); 937 &transports, MOJO_WRITE_MESSAGE_FLAG_NONE));
938 transport.End(); 938 transport.End();
939 939
940 // |dispatcher| should have been closed. This is |DCHECK()|ed when the 940 // |dispatcher| should have been closed. This is |DCHECK()|ed when the
941 // |dispatcher| is destroyed. 941 // |dispatcher| is destroyed.
942 EXPECT_TRUE(dispatcher->HasOneRef()); 942 EXPECT_TRUE(dispatcher->HasOneRef());
943 dispatcher = nullptr; 943 dispatcher = nullptr;
944 } 944 }
945 945
946 // Wait. 946 // Wait.
947 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); 947 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context));
948 EXPECT_EQ(123u, context); 948 EXPECT_EQ(123u, context);
949 hss = HandleSignalsState(); 949 hss = HandleSignalsState();
950 mp1->RemoveWaiter(1, &waiter, &hss); 950 mp1->RemoveAwakable(1, &waiter, &hss);
951 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 951 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
952 hss.satisfied_signals); 952 hss.satisfied_signals);
953 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); 953 EXPECT_EQ(kAllSignals, hss.satisfiable_signals);
954 954
955 // Read from MP 1, port 1. 955 // Read from MP 1, port 1.
956 char read_buffer[100] = {0}; 956 char read_buffer[100] = {0};
957 uint32_t read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer)); 957 uint32_t read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer));
958 DispatcherVector read_dispatchers; 958 DispatcherVector read_dispatchers;
959 uint32_t read_num_dispatchers = 10; // Maximum to get. 959 uint32_t read_num_dispatchers = 10; // Maximum to get.
960 EXPECT_EQ( 960 EXPECT_EQ(
961 MOJO_RESULT_OK, 961 MOJO_RESULT_OK,
962 mp1->ReadMessage(1, UserPointer<void>(read_buffer), 962 mp1->ReadMessage(1, UserPointer<void>(read_buffer),
963 MakeUserPointer(&read_buffer_size), &read_dispatchers, 963 MakeUserPointer(&read_buffer_size), &read_dispatchers,
964 &read_num_dispatchers, MOJO_READ_MESSAGE_FLAG_NONE)); 964 &read_num_dispatchers, MOJO_READ_MESSAGE_FLAG_NONE));
965 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size)); 965 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size));
966 EXPECT_STREQ(kHello, read_buffer); 966 EXPECT_STREQ(kHello, read_buffer);
967 EXPECT_EQ(1u, read_dispatchers.size()); 967 EXPECT_EQ(1u, read_dispatchers.size());
968 EXPECT_EQ(1u, read_num_dispatchers); 968 EXPECT_EQ(1u, read_num_dispatchers);
969 ASSERT_TRUE(read_dispatchers[0].get()); 969 ASSERT_TRUE(read_dispatchers[0]);
970 EXPECT_TRUE(read_dispatchers[0]->HasOneRef()); 970 EXPECT_TRUE(read_dispatchers[0]->HasOneRef());
971 971
972 EXPECT_EQ(Dispatcher::kTypeSharedBuffer, read_dispatchers[0]->GetType()); 972 EXPECT_EQ(Dispatcher::kTypeSharedBuffer, read_dispatchers[0]->GetType());
973 dispatcher = static_cast<SharedBufferDispatcher*>(read_dispatchers[0].get()); 973 dispatcher = static_cast<SharedBufferDispatcher*>(read_dispatchers[0].get());
974 974
975 // Make another mapping. 975 // Make another mapping.
976 scoped_ptr<embedder::PlatformSharedBufferMapping> mapping1; 976 scoped_ptr<embedder::PlatformSharedBufferMapping> mapping1;
977 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->MapBuffer( 977 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->MapBuffer(
978 0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping1)); 978 0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping1));
979 ASSERT_TRUE(mapping1); 979 ASSERT_TRUE(mapping1);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1033 // be passed. 1033 // be passed.
1034 scoped_refptr<PlatformHandleDispatcher> dispatcher( 1034 scoped_refptr<PlatformHandleDispatcher> dispatcher(
1035 new PlatformHandleDispatcher( 1035 new PlatformHandleDispatcher(
1036 mojo::test::PlatformHandleFromFILE(fp.Pass()))); 1036 mojo::test::PlatformHandleFromFILE(fp.Pass())));
1037 1037
1038 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do 1038 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do
1039 // it later, it might already be readable.) 1039 // it later, it might already be readable.)
1040 waiter.Init(); 1040 waiter.Init();
1041 ASSERT_EQ( 1041 ASSERT_EQ(
1042 MOJO_RESULT_OK, 1042 MOJO_RESULT_OK,
1043 mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); 1043 mp1->AddAwakable(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr));
1044 1044
1045 // Write to MP 0, port 0. 1045 // Write to MP 0, port 0.
1046 { 1046 {
1047 DispatcherTransport transport( 1047 DispatcherTransport transport(
1048 test::DispatcherTryStartTransport(dispatcher.get())); 1048 test::DispatcherTryStartTransport(dispatcher.get()));
1049 EXPECT_TRUE(transport.is_valid()); 1049 EXPECT_TRUE(transport.is_valid());
1050 1050
1051 std::vector<DispatcherTransport> transports; 1051 std::vector<DispatcherTransport> transports;
1052 transports.push_back(transport); 1052 transports.push_back(transport);
1053 EXPECT_EQ( 1053 EXPECT_EQ(
1054 MOJO_RESULT_OK, 1054 MOJO_RESULT_OK,
1055 mp0->WriteMessage(0, UserPointer<const void>(kWorld), sizeof(kWorld), 1055 mp0->WriteMessage(0, UserPointer<const void>(kWorld), sizeof(kWorld),
1056 &transports, MOJO_WRITE_MESSAGE_FLAG_NONE)); 1056 &transports, MOJO_WRITE_MESSAGE_FLAG_NONE));
1057 transport.End(); 1057 transport.End();
1058 1058
1059 // |dispatcher| should have been closed. This is |DCHECK()|ed when the 1059 // |dispatcher| should have been closed. This is |DCHECK()|ed when the
1060 // |dispatcher| is destroyed. 1060 // |dispatcher| is destroyed.
1061 EXPECT_TRUE(dispatcher->HasOneRef()); 1061 EXPECT_TRUE(dispatcher->HasOneRef());
1062 dispatcher = nullptr; 1062 dispatcher = nullptr;
1063 } 1063 }
1064 1064
1065 // Wait. 1065 // Wait.
1066 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); 1066 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context));
1067 EXPECT_EQ(123u, context); 1067 EXPECT_EQ(123u, context);
1068 hss = HandleSignalsState(); 1068 hss = HandleSignalsState();
1069 mp1->RemoveWaiter(1, &waiter, &hss); 1069 mp1->RemoveAwakable(1, &waiter, &hss);
1070 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 1070 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
1071 hss.satisfied_signals); 1071 hss.satisfied_signals);
1072 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); 1072 EXPECT_EQ(kAllSignals, hss.satisfiable_signals);
1073 1073
1074 // Read from MP 1, port 1. 1074 // Read from MP 1, port 1.
1075 char read_buffer[100] = {0}; 1075 char read_buffer[100] = {0};
1076 uint32_t read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer)); 1076 uint32_t read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer));
1077 DispatcherVector read_dispatchers; 1077 DispatcherVector read_dispatchers;
1078 uint32_t read_num_dispatchers = 10; // Maximum to get. 1078 uint32_t read_num_dispatchers = 10; // Maximum to get.
1079 EXPECT_EQ( 1079 EXPECT_EQ(
1080 MOJO_RESULT_OK, 1080 MOJO_RESULT_OK,
1081 mp1->ReadMessage(1, UserPointer<void>(read_buffer), 1081 mp1->ReadMessage(1, UserPointer<void>(read_buffer),
1082 MakeUserPointer(&read_buffer_size), &read_dispatchers, 1082 MakeUserPointer(&read_buffer_size), &read_dispatchers,
1083 &read_num_dispatchers, MOJO_READ_MESSAGE_FLAG_NONE)); 1083 &read_num_dispatchers, MOJO_READ_MESSAGE_FLAG_NONE));
1084 EXPECT_EQ(sizeof(kWorld), static_cast<size_t>(read_buffer_size)); 1084 EXPECT_EQ(sizeof(kWorld), static_cast<size_t>(read_buffer_size));
1085 EXPECT_STREQ(kWorld, read_buffer); 1085 EXPECT_STREQ(kWorld, read_buffer);
1086 EXPECT_EQ(1u, read_dispatchers.size()); 1086 EXPECT_EQ(1u, read_dispatchers.size());
1087 EXPECT_EQ(1u, read_num_dispatchers); 1087 EXPECT_EQ(1u, read_num_dispatchers);
1088 ASSERT_TRUE(read_dispatchers[0].get()); 1088 ASSERT_TRUE(read_dispatchers[0]);
1089 EXPECT_TRUE(read_dispatchers[0]->HasOneRef()); 1089 EXPECT_TRUE(read_dispatchers[0]->HasOneRef());
1090 1090
1091 EXPECT_EQ(Dispatcher::kTypePlatformHandle, read_dispatchers[0]->GetType()); 1091 EXPECT_EQ(Dispatcher::kTypePlatformHandle, read_dispatchers[0]->GetType());
1092 dispatcher = 1092 dispatcher =
1093 static_cast<PlatformHandleDispatcher*>(read_dispatchers[0].get()); 1093 static_cast<PlatformHandleDispatcher*>(read_dispatchers[0].get());
1094 1094
1095 embedder::ScopedPlatformHandle h = dispatcher->PassPlatformHandle().Pass(); 1095 embedder::ScopedPlatformHandle h = dispatcher->PassPlatformHandle().Pass();
1096 EXPECT_TRUE(h.is_valid()); 1096 EXPECT_TRUE(h.is_valid());
1097 1097
1098 fp = mojo::test::FILEFromPlatformHandle(h.Pass(), "rb").Pass(); 1098 fp = mojo::test::FILEFromPlatformHandle(h.Pass(), "rb").Pass();
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1170 scoped_refptr<MessagePipeDispatcher> dispatcher( 1170 scoped_refptr<MessagePipeDispatcher> dispatcher(
1171 new MessagePipeDispatcher(MessagePipeDispatcher::kDefaultCreateOptions)); 1171 new MessagePipeDispatcher(MessagePipeDispatcher::kDefaultCreateOptions));
1172 scoped_refptr<MessagePipe> local_mp(MessagePipe::CreateLocalLocal()); 1172 scoped_refptr<MessagePipe> local_mp(MessagePipe::CreateLocalLocal());
1173 dispatcher->Init(local_mp, 0); 1173 dispatcher->Init(local_mp, 0);
1174 1174
1175 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do 1175 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do
1176 // it later, it might already be readable.) 1176 // it later, it might already be readable.)
1177 waiter.Init(); 1177 waiter.Init();
1178 ASSERT_EQ( 1178 ASSERT_EQ(
1179 MOJO_RESULT_OK, 1179 MOJO_RESULT_OK,
1180 mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); 1180 mp1->AddAwakable(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr));
1181 1181
1182 // Write to MP 0, port 0. 1182 // Write to MP 0, port 0.
1183 { 1183 {
1184 DispatcherTransport transport( 1184 DispatcherTransport transport(
1185 test::DispatcherTryStartTransport(dispatcher.get())); 1185 test::DispatcherTryStartTransport(dispatcher.get()));
1186 EXPECT_TRUE(transport.is_valid()); 1186 EXPECT_TRUE(transport.is_valid());
1187 1187
1188 std::vector<DispatcherTransport> transports; 1188 std::vector<DispatcherTransport> transports;
1189 transports.push_back(transport); 1189 transports.push_back(transport);
1190 EXPECT_EQ( 1190 EXPECT_EQ(
1191 MOJO_RESULT_OK, 1191 MOJO_RESULT_OK,
1192 mp0->WriteMessage(0, UserPointer<const void>(kHello), sizeof(kHello), 1192 mp0->WriteMessage(0, UserPointer<const void>(kHello), sizeof(kHello),
1193 &transports, MOJO_WRITE_MESSAGE_FLAG_NONE)); 1193 &transports, MOJO_WRITE_MESSAGE_FLAG_NONE));
1194 transport.End(); 1194 transport.End();
1195 1195
1196 // |dispatcher| should have been closed. This is |DCHECK()|ed when the 1196 // |dispatcher| should have been closed. This is |DCHECK()|ed when the
1197 // |dispatcher| is destroyed. 1197 // |dispatcher| is destroyed.
1198 EXPECT_TRUE(dispatcher->HasOneRef()); 1198 EXPECT_TRUE(dispatcher->HasOneRef());
1199 dispatcher = nullptr; 1199 dispatcher = nullptr;
1200 } 1200 }
1201 1201
1202 // Wait. 1202 // Wait.
1203 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); 1203 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context));
1204 EXPECT_EQ(123u, context); 1204 EXPECT_EQ(123u, context);
1205 hss = HandleSignalsState(); 1205 hss = HandleSignalsState();
1206 mp1->RemoveWaiter(1, &waiter, &hss); 1206 mp1->RemoveAwakable(1, &waiter, &hss);
1207 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 1207 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
1208 hss.satisfied_signals); 1208 hss.satisfied_signals);
1209 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); 1209 EXPECT_EQ(kAllSignals, hss.satisfiable_signals);
1210 1210
1211 // Read from MP 1, port 1. 1211 // Read from MP 1, port 1.
1212 char read_buffer[100] = {0}; 1212 char read_buffer[100] = {0};
1213 uint32_t read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer)); 1213 uint32_t read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer));
1214 DispatcherVector read_dispatchers; 1214 DispatcherVector read_dispatchers;
1215 uint32_t read_num_dispatchers = 10; // Maximum to get. 1215 uint32_t read_num_dispatchers = 10; // Maximum to get.
1216 EXPECT_EQ( 1216 EXPECT_EQ(
1217 MOJO_RESULT_OK, 1217 MOJO_RESULT_OK,
1218 mp1->ReadMessage(1, UserPointer<void>(read_buffer), 1218 mp1->ReadMessage(1, UserPointer<void>(read_buffer),
1219 MakeUserPointer(&read_buffer_size), &read_dispatchers, 1219 MakeUserPointer(&read_buffer_size), &read_dispatchers,
1220 &read_num_dispatchers, MOJO_READ_MESSAGE_FLAG_NONE)); 1220 &read_num_dispatchers, MOJO_READ_MESSAGE_FLAG_NONE));
1221 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size)); 1221 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size));
1222 EXPECT_STREQ(kHello, read_buffer); 1222 EXPECT_STREQ(kHello, read_buffer);
1223 EXPECT_EQ(1u, read_dispatchers.size()); 1223 EXPECT_EQ(1u, read_dispatchers.size());
1224 EXPECT_EQ(1u, read_num_dispatchers); 1224 EXPECT_EQ(1u, read_num_dispatchers);
1225 ASSERT_TRUE(read_dispatchers[0].get()); 1225 ASSERT_TRUE(read_dispatchers[0]);
1226 EXPECT_TRUE(read_dispatchers[0]->HasOneRef()); 1226 EXPECT_TRUE(read_dispatchers[0]->HasOneRef());
1227 1227
1228 EXPECT_EQ(Dispatcher::kTypeMessagePipe, read_dispatchers[0]->GetType()); 1228 EXPECT_EQ(Dispatcher::kTypeMessagePipe, read_dispatchers[0]->GetType());
1229 dispatcher = static_cast<MessagePipeDispatcher*>(read_dispatchers[0].get()); 1229 dispatcher = static_cast<MessagePipeDispatcher*>(read_dispatchers[0].get());
1230 read_dispatchers.clear(); 1230 read_dispatchers.clear();
1231 1231
1232 // Now pass it back. 1232 // Now pass it back.
1233 1233
1234 // Prepare to wait on MP 0, port 0. (Add the waiter now. Otherwise, if we do 1234 // Prepare to wait on MP 0, port 0. (Add the waiter now. Otherwise, if we do
1235 // it later, it might already be readable.) 1235 // it later, it might already be readable.)
1236 waiter.Init(); 1236 waiter.Init();
1237 ASSERT_EQ( 1237 ASSERT_EQ(
1238 MOJO_RESULT_OK, 1238 MOJO_RESULT_OK,
1239 mp0->AddWaiter(0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 456, nullptr)); 1239 mp0->AddAwakable(0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 456, nullptr));
1240 1240
1241 // Write to MP 1, port 1. 1241 // Write to MP 1, port 1.
1242 { 1242 {
1243 DispatcherTransport transport( 1243 DispatcherTransport transport(
1244 test::DispatcherTryStartTransport(dispatcher.get())); 1244 test::DispatcherTryStartTransport(dispatcher.get()));
1245 EXPECT_TRUE(transport.is_valid()); 1245 EXPECT_TRUE(transport.is_valid());
1246 1246
1247 std::vector<DispatcherTransport> transports; 1247 std::vector<DispatcherTransport> transports;
1248 transports.push_back(transport); 1248 transports.push_back(transport);
1249 EXPECT_EQ( 1249 EXPECT_EQ(
1250 MOJO_RESULT_OK, 1250 MOJO_RESULT_OK,
1251 mp1->WriteMessage(1, UserPointer<const void>(kWorld), sizeof(kWorld), 1251 mp1->WriteMessage(1, UserPointer<const void>(kWorld), sizeof(kWorld),
1252 &transports, MOJO_WRITE_MESSAGE_FLAG_NONE)); 1252 &transports, MOJO_WRITE_MESSAGE_FLAG_NONE));
1253 transport.End(); 1253 transport.End();
1254 1254
1255 // |dispatcher| should have been closed. This is |DCHECK()|ed when the 1255 // |dispatcher| should have been closed. This is |DCHECK()|ed when the
1256 // |dispatcher| is destroyed. 1256 // |dispatcher| is destroyed.
1257 EXPECT_TRUE(dispatcher->HasOneRef()); 1257 EXPECT_TRUE(dispatcher->HasOneRef());
1258 dispatcher = nullptr; 1258 dispatcher = nullptr;
1259 } 1259 }
1260 1260
1261 // Wait. 1261 // Wait.
1262 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); 1262 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context));
1263 EXPECT_EQ(456u, context); 1263 EXPECT_EQ(456u, context);
1264 hss = HandleSignalsState(); 1264 hss = HandleSignalsState();
1265 mp0->RemoveWaiter(0, &waiter, &hss); 1265 mp0->RemoveAwakable(0, &waiter, &hss);
1266 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 1266 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
1267 hss.satisfied_signals); 1267 hss.satisfied_signals);
1268 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); 1268 EXPECT_EQ(kAllSignals, hss.satisfiable_signals);
1269 1269
1270 // Read from MP 0, port 0. 1270 // Read from MP 0, port 0.
1271 read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer)); 1271 read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer));
1272 read_num_dispatchers = 10; // Maximum to get. 1272 read_num_dispatchers = 10; // Maximum to get.
1273 EXPECT_EQ( 1273 EXPECT_EQ(
1274 MOJO_RESULT_OK, 1274 MOJO_RESULT_OK,
1275 mp0->ReadMessage(0, UserPointer<void>(read_buffer), 1275 mp0->ReadMessage(0, UserPointer<void>(read_buffer),
1276 MakeUserPointer(&read_buffer_size), &read_dispatchers, 1276 MakeUserPointer(&read_buffer_size), &read_dispatchers,
1277 &read_num_dispatchers, MOJO_READ_MESSAGE_FLAG_NONE)); 1277 &read_num_dispatchers, MOJO_READ_MESSAGE_FLAG_NONE));
1278 EXPECT_EQ(sizeof(kWorld), static_cast<size_t>(read_buffer_size)); 1278 EXPECT_EQ(sizeof(kWorld), static_cast<size_t>(read_buffer_size));
1279 EXPECT_STREQ(kWorld, read_buffer); 1279 EXPECT_STREQ(kWorld, read_buffer);
1280 EXPECT_EQ(1u, read_dispatchers.size()); 1280 EXPECT_EQ(1u, read_dispatchers.size());
1281 EXPECT_EQ(1u, read_num_dispatchers); 1281 EXPECT_EQ(1u, read_num_dispatchers);
1282 ASSERT_TRUE(read_dispatchers[0].get()); 1282 ASSERT_TRUE(read_dispatchers[0]);
1283 EXPECT_TRUE(read_dispatchers[0]->HasOneRef()); 1283 EXPECT_TRUE(read_dispatchers[0]->HasOneRef());
1284 1284
1285 EXPECT_EQ(Dispatcher::kTypeMessagePipe, read_dispatchers[0]->GetType()); 1285 EXPECT_EQ(Dispatcher::kTypeMessagePipe, read_dispatchers[0]->GetType());
1286 dispatcher = static_cast<MessagePipeDispatcher*>(read_dispatchers[0].get()); 1286 dispatcher = static_cast<MessagePipeDispatcher*>(read_dispatchers[0].get());
1287 read_dispatchers.clear(); 1287 read_dispatchers.clear();
1288 1288
1289 // Add the waiter now, before it becomes readable to avoid a race. 1289 // Add the waiter now, before it becomes readable to avoid a race.
1290 waiter.Init(); 1290 waiter.Init();
1291 ASSERT_EQ(MOJO_RESULT_OK, 1291 ASSERT_EQ(MOJO_RESULT_OK,
1292 dispatcher->AddWaiter(&waiter, MOJO_HANDLE_SIGNAL_READABLE, 789, 1292 dispatcher->AddAwakable(&waiter, MOJO_HANDLE_SIGNAL_READABLE, 789,
1293 nullptr)); 1293 nullptr));
1294 1294
1295 // Write to "local_mp", port 1. 1295 // Write to "local_mp", port 1.
1296 EXPECT_EQ( 1296 EXPECT_EQ(
1297 MOJO_RESULT_OK, 1297 MOJO_RESULT_OK,
1298 local_mp->WriteMessage(1, UserPointer<const void>(kHello), sizeof(kHello), 1298 local_mp->WriteMessage(1, UserPointer<const void>(kHello), sizeof(kHello),
1299 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); 1299 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
1300 1300
1301 // Wait for the dispatcher to become readable. 1301 // Wait for the dispatcher to become readable.
1302 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); 1302 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context));
1303 EXPECT_EQ(789u, context); 1303 EXPECT_EQ(789u, context);
1304 hss = HandleSignalsState(); 1304 hss = HandleSignalsState();
1305 dispatcher->RemoveWaiter(&waiter, &hss); 1305 dispatcher->RemoveAwakable(&waiter, &hss);
1306 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 1306 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
1307 hss.satisfied_signals); 1307 hss.satisfied_signals);
1308 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); 1308 EXPECT_EQ(kAllSignals, hss.satisfiable_signals);
1309 1309
1310 // Read from the dispatcher. 1310 // Read from the dispatcher.
1311 memset(read_buffer, 0, sizeof(read_buffer)); 1311 memset(read_buffer, 0, sizeof(read_buffer));
1312 read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer)); 1312 read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer));
1313 EXPECT_EQ(MOJO_RESULT_OK, 1313 EXPECT_EQ(MOJO_RESULT_OK,
1314 dispatcher->ReadMessage(UserPointer<void>(read_buffer), 1314 dispatcher->ReadMessage(UserPointer<void>(read_buffer),
1315 MakeUserPointer(&read_buffer_size), 0, 1315 MakeUserPointer(&read_buffer_size), 0,
1316 nullptr, MOJO_READ_MESSAGE_FLAG_NONE)); 1316 nullptr, MOJO_READ_MESSAGE_FLAG_NONE));
1317 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size)); 1317 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size));
1318 EXPECT_STREQ(kHello, read_buffer); 1318 EXPECT_STREQ(kHello, read_buffer);
1319 1319
1320 // Prepare to wait on "local_mp", port 1. 1320 // Prepare to wait on "local_mp", port 1.
1321 waiter.Init(); 1321 waiter.Init();
1322 ASSERT_EQ(MOJO_RESULT_OK, 1322 ASSERT_EQ(MOJO_RESULT_OK,
1323 local_mp->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 789, 1323 local_mp->AddAwakable(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 789,
1324 nullptr)); 1324 nullptr));
1325 1325
1326 // Write to the dispatcher. 1326 // Write to the dispatcher.
1327 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->WriteMessage( 1327 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->WriteMessage(
1328 UserPointer<const void>(kHello), sizeof(kHello), 1328 UserPointer<const void>(kHello), sizeof(kHello),
1329 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); 1329 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
1330 1330
1331 // Wait. 1331 // Wait.
1332 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context)); 1332 EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context));
1333 EXPECT_EQ(789u, context); 1333 EXPECT_EQ(789u, context);
1334 hss = HandleSignalsState(); 1334 hss = HandleSignalsState();
1335 local_mp->RemoveWaiter(1, &waiter, &hss); 1335 local_mp->RemoveAwakable(1, &waiter, &hss);
1336 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 1336 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
1337 hss.satisfied_signals); 1337 hss.satisfied_signals);
1338 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); 1338 EXPECT_EQ(kAllSignals, hss.satisfiable_signals);
1339 1339
1340 // Read from "local_mp", port 1. 1340 // Read from "local_mp", port 1.
1341 memset(read_buffer, 0, sizeof(read_buffer)); 1341 memset(read_buffer, 0, sizeof(read_buffer));
1342 read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer)); 1342 read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer));
1343 EXPECT_EQ(MOJO_RESULT_OK, 1343 EXPECT_EQ(MOJO_RESULT_OK,
1344 local_mp->ReadMessage(1, UserPointer<void>(read_buffer), 1344 local_mp->ReadMessage(1, UserPointer<void>(read_buffer),
1345 MakeUserPointer(&read_buffer_size), nullptr, 1345 MakeUserPointer(&read_buffer_size), nullptr,
1346 nullptr, MOJO_READ_MESSAGE_FLAG_NONE)); 1346 nullptr, MOJO_READ_MESSAGE_FLAG_NONE));
1347 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size)); 1347 EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size));
1348 EXPECT_STREQ(kHello, read_buffer); 1348 EXPECT_STREQ(kHello, read_buffer);
1349 1349
1350 // TODO(vtl): Also test the cases where messages are written and read (at 1350 // TODO(vtl): Also test the cases where messages are written and read (at
1351 // various points) on the message pipe being passed around. 1351 // various points) on the message pipe being passed around.
1352 1352
1353 // Close everything that belongs to us. 1353 // Close everything that belongs to us.
1354 mp0->Close(0); 1354 mp0->Close(0);
1355 mp1->Close(1); 1355 mp1->Close(1);
1356 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); 1356 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close());
1357 // Note that |local_mp|'s port 0 belong to |dispatcher|, which was closed. 1357 // Note that |local_mp|'s port 0 belong to |dispatcher|, which was closed.
1358 local_mp->Close(1); 1358 local_mp->Close(1);
1359 } 1359 }
1360 1360
1361 } // namespace 1361 } // namespace
1362 } // namespace system 1362 } // namespace system
1363 } // namespace mojo 1363 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698