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

Side by Side Diff: mojo/edk/embedder/embedder_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 "mojo/edk/embedder/embedder.h" 5 #include "mojo/edk/embedder/embedder.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
14 #include "base/synchronization/waitable_event.h" 14 #include "base/synchronization/waitable_event.h"
15 #include "base/test/test_io_thread.h" 15 #include "base/test/test_io_thread.h"
16 #include "mojo/edk/embedder/platform_channel_pair.h" 16 #include "mojo/edk/embedder/platform_channel_pair.h"
17 #include "mojo/edk/embedder/test_embedder.h" 17 #include "mojo/edk/embedder/test_embedder.h"
18 #include "mojo/edk/system/test_utils.h" 18 #include "mojo/edk/system/test_utils.h"
19 #include "mojo/edk/test/multiprocess_test_helper.h" 19 #include "mojo/edk/test/multiprocess_test_helper.h"
20 #include "mojo/public/c/system/core.h" 20 #include "mojo/public/c/system/core.h"
21 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
22 22
23 namespace mojo { 23 namespace mojo {
24 namespace embedder { 24 namespace embedder {
25 namespace { 25 namespace {
26 26
27 const MojoHandleSignals kSignalReadadableWritable =
28 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE;
29
30 const MojoHandleSignals kSignalAll = MOJO_HANDLE_SIGNAL_READABLE |
31 MOJO_HANDLE_SIGNAL_WRITABLE |
32 MOJO_HANDLE_SIGNAL_PEER_CLOSED;
33
27 class ScopedTestChannel { 34 class ScopedTestChannel {
28 public: 35 public:
29 // Creates a channel that lives on a given I/O thread (determined by the given 36 // Creates a channel that lives on a given I/O thread (determined by the given
30 // |TaskRunner|) attached to the given |platform_handle|. After construction, 37 // |TaskRunner|) attached to the given |platform_handle|. After construction,
31 // |bootstrap_message_pipe()| gives the Mojo handle for the bootstrap message 38 // |bootstrap_message_pipe()| gives the Mojo handle for the bootstrap message
32 // pipe on this channel; it is up to the caller to close this handle. 39 // pipe on this channel; it is up to the caller to close this handle.
33 // Note: The I/O thread must outlive this object (and its message loop must 40 // Note: The I/O thread must outlive this object (and its message loop must
34 // continue pumping messages while this object is alive). 41 // continue pumping messages while this object is alive).
35 ScopedTestChannel(scoped_refptr<base::TaskRunner> io_thread_task_runner, 42 ScopedTestChannel(scoped_refptr<base::TaskRunner> io_thread_task_runner,
36 ScopedPlatformHandle platform_handle) 43 ScopedPlatformHandle platform_handle)
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 EXPECT_NE(client_mp, MOJO_HANDLE_INVALID); 123 EXPECT_NE(client_mp, MOJO_HANDLE_INVALID);
117 124
118 // We can write to a message pipe handle immediately. 125 // We can write to a message pipe handle immediately.
119 const char kHello[] = "hello"; 126 const char kHello[] = "hello";
120 EXPECT_EQ(MOJO_RESULT_OK, 127 EXPECT_EQ(MOJO_RESULT_OK,
121 MojoWriteMessage(server_mp, kHello, 128 MojoWriteMessage(server_mp, kHello,
122 static_cast<uint32_t>(sizeof(kHello)), nullptr, 129 static_cast<uint32_t>(sizeof(kHello)), nullptr,
123 0, MOJO_WRITE_MESSAGE_FLAG_NONE)); 130 0, MOJO_WRITE_MESSAGE_FLAG_NONE));
124 131
125 // Now wait for the other side to become readable. 132 // Now wait for the other side to become readable.
126 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(client_mp, MOJO_HANDLE_SIGNAL_READABLE, 133 MojoHandleSignalsState state;
127 MOJO_DEADLINE_INDEFINITE)); 134 EXPECT_EQ(MOJO_RESULT_OK,
135 MojoNewWait(client_mp, MOJO_HANDLE_SIGNAL_READABLE,
136 MOJO_DEADLINE_INDEFINITE, &state));
137 EXPECT_EQ(kSignalReadadableWritable, state.satisfied_signals);
138 EXPECT_EQ(kSignalAll, state.satisfiable_signals);
128 139
129 char buffer[1000] = {}; 140 char buffer[1000] = {};
130 uint32_t num_bytes = static_cast<uint32_t>(sizeof(buffer)); 141 uint32_t num_bytes = static_cast<uint32_t>(sizeof(buffer));
131 EXPECT_EQ(MOJO_RESULT_OK, 142 EXPECT_EQ(MOJO_RESULT_OK,
132 MojoReadMessage(client_mp, buffer, &num_bytes, nullptr, nullptr, 143 MojoReadMessage(client_mp, buffer, &num_bytes, nullptr, nullptr,
133 MOJO_READ_MESSAGE_FLAG_NONE)); 144 MOJO_READ_MESSAGE_FLAG_NONE));
134 EXPECT_EQ(sizeof(kHello), num_bytes); 145 EXPECT_EQ(sizeof(kHello), num_bytes);
135 EXPECT_STREQ(kHello, buffer); 146 EXPECT_STREQ(kHello, buffer);
136 147
137 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(server_mp)); 148 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(server_mp));
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 MOJO_WRITE_MESSAGE_FLAG_NONE)); 192 MOJO_WRITE_MESSAGE_FLAG_NONE));
182 h1 = MOJO_HANDLE_INVALID; 193 h1 = MOJO_HANDLE_INVALID;
183 194
184 // Write another message to |h0|. 195 // Write another message to |h0|.
185 const char kFoo[] = "foo"; 196 const char kFoo[] = "foo";
186 EXPECT_EQ(MOJO_RESULT_OK, 197 EXPECT_EQ(MOJO_RESULT_OK,
187 MojoWriteMessage(h0, kFoo, static_cast<uint32_t>(sizeof(kFoo)), 198 MojoWriteMessage(h0, kFoo, static_cast<uint32_t>(sizeof(kFoo)),
188 nullptr, 0, MOJO_WRITE_MESSAGE_FLAG_NONE)); 199 nullptr, 0, MOJO_WRITE_MESSAGE_FLAG_NONE));
189 200
190 // Wait for |client_mp| to become readable. 201 // Wait for |client_mp| to become readable.
191 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(client_mp, MOJO_HANDLE_SIGNAL_READABLE, 202 MojoHandleSignalsState state;
192 MOJO_DEADLINE_INDEFINITE)); 203 EXPECT_EQ(MOJO_RESULT_OK,
204 MojoNewWait(client_mp, MOJO_HANDLE_SIGNAL_READABLE,
205 MOJO_DEADLINE_INDEFINITE, &state));
206 EXPECT_EQ(kSignalReadadableWritable, state.satisfied_signals);
207 EXPECT_EQ(kSignalAll, state.satisfiable_signals);
193 208
194 // Read a message from |client_mp|. 209 // Read a message from |client_mp|.
195 char buffer[1000] = {}; 210 char buffer[1000] = {};
196 uint32_t num_bytes = static_cast<uint32_t>(sizeof(buffer)); 211 uint32_t num_bytes = static_cast<uint32_t>(sizeof(buffer));
197 MojoHandle handles[10] = {}; 212 MojoHandle handles[10] = {};
198 uint32_t num_handles = arraysize(handles); 213 uint32_t num_handles = arraysize(handles);
199 EXPECT_EQ(MOJO_RESULT_OK, 214 EXPECT_EQ(MOJO_RESULT_OK,
200 MojoReadMessage(client_mp, buffer, &num_bytes, handles, 215 MojoReadMessage(client_mp, buffer, &num_bytes, handles,
201 &num_handles, MOJO_READ_MESSAGE_FLAG_NONE)); 216 &num_handles, MOJO_READ_MESSAGE_FLAG_NONE));
202 EXPECT_EQ(sizeof(kWorld), num_bytes); 217 EXPECT_EQ(sizeof(kWorld), num_bytes);
203 EXPECT_STREQ(kWorld, buffer); 218 EXPECT_STREQ(kWorld, buffer);
204 EXPECT_EQ(1u, num_handles); 219 EXPECT_EQ(1u, num_handles);
205 EXPECT_NE(handles[0], MOJO_HANDLE_INVALID); 220 EXPECT_NE(handles[0], MOJO_HANDLE_INVALID);
206 h1 = handles[0]; 221 h1 = handles[0];
207 222
208 // Wait for |h1| to become readable. 223 // Wait for |h1| to become readable.
209 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(h1, MOJO_HANDLE_SIGNAL_READABLE, 224 EXPECT_EQ(MOJO_RESULT_OK, MojoNewWait(h1, MOJO_HANDLE_SIGNAL_READABLE,
210 MOJO_DEADLINE_INDEFINITE)); 225 MOJO_DEADLINE_INDEFINITE, &state));
226 EXPECT_EQ(kSignalReadadableWritable, state.satisfied_signals);
227 EXPECT_EQ(kSignalAll, state.satisfiable_signals);
211 228
212 // Read a message from |h1|. 229 // Read a message from |h1|.
213 memset(buffer, 0, sizeof(buffer)); 230 memset(buffer, 0, sizeof(buffer));
214 num_bytes = static_cast<uint32_t>(sizeof(buffer)); 231 num_bytes = static_cast<uint32_t>(sizeof(buffer));
215 memset(handles, 0, sizeof(handles)); 232 memset(handles, 0, sizeof(handles));
216 num_handles = arraysize(handles); 233 num_handles = arraysize(handles);
217 EXPECT_EQ(MOJO_RESULT_OK, 234 EXPECT_EQ(MOJO_RESULT_OK,
218 MojoReadMessage(h1, buffer, &num_bytes, handles, &num_handles, 235 MojoReadMessage(h1, buffer, &num_bytes, handles, &num_handles,
219 MOJO_READ_MESSAGE_FLAG_NONE)); 236 MOJO_READ_MESSAGE_FLAG_NONE));
220 EXPECT_EQ(sizeof(kHello), num_bytes); 237 EXPECT_EQ(sizeof(kHello), num_bytes);
221 EXPECT_STREQ(kHello, buffer); 238 EXPECT_STREQ(kHello, buffer);
222 EXPECT_EQ(0u, num_handles); 239 EXPECT_EQ(0u, num_handles);
223 240
224 // Wait for |h1| to become readable (again). 241 // Wait for |h1| to become readable (again).
225 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(h1, MOJO_HANDLE_SIGNAL_READABLE, 242 EXPECT_EQ(MOJO_RESULT_OK, MojoNewWait(h1, MOJO_HANDLE_SIGNAL_READABLE,
226 MOJO_DEADLINE_INDEFINITE)); 243 MOJO_DEADLINE_INDEFINITE, &state));
244 EXPECT_EQ(kSignalReadadableWritable, state.satisfied_signals);
245 EXPECT_EQ(kSignalAll, state.satisfiable_signals);
227 246
228 // Read the second message from |h1|. 247 // Read the second message from |h1|.
229 memset(buffer, 0, sizeof(buffer)); 248 memset(buffer, 0, sizeof(buffer));
230 num_bytes = static_cast<uint32_t>(sizeof(buffer)); 249 num_bytes = static_cast<uint32_t>(sizeof(buffer));
231 EXPECT_EQ(MOJO_RESULT_OK, 250 EXPECT_EQ(MOJO_RESULT_OK,
232 MojoReadMessage(h1, buffer, &num_bytes, nullptr, nullptr, 251 MojoReadMessage(h1, buffer, &num_bytes, nullptr, nullptr,
233 MOJO_READ_MESSAGE_FLAG_NONE)); 252 MOJO_READ_MESSAGE_FLAG_NONE));
234 EXPECT_EQ(sizeof(kFoo), num_bytes); 253 EXPECT_EQ(sizeof(kFoo), num_bytes);
235 EXPECT_STREQ(kFoo, buffer); 254 EXPECT_STREQ(kFoo, buffer);
236 255
237 // Write a message to |h1|. 256 // Write a message to |h1|.
238 const char kBarBaz[] = "barbaz"; 257 const char kBarBaz[] = "barbaz";
239 EXPECT_EQ( 258 EXPECT_EQ(
240 MOJO_RESULT_OK, 259 MOJO_RESULT_OK,
241 MojoWriteMessage(h1, kBarBaz, static_cast<uint32_t>(sizeof(kBarBaz)), 260 MojoWriteMessage(h1, kBarBaz, static_cast<uint32_t>(sizeof(kBarBaz)),
242 nullptr, 0, MOJO_WRITE_MESSAGE_FLAG_NONE)); 261 nullptr, 0, MOJO_WRITE_MESSAGE_FLAG_NONE));
243 262
244 // Wait for |h0| to become readable. 263 // Wait for |h0| to become readable.
245 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(h0, MOJO_HANDLE_SIGNAL_READABLE, 264 EXPECT_EQ(MOJO_RESULT_OK, MojoNewWait(h0, MOJO_HANDLE_SIGNAL_READABLE,
246 MOJO_DEADLINE_INDEFINITE)); 265 MOJO_DEADLINE_INDEFINITE, &state));
266 EXPECT_EQ(kSignalReadadableWritable, state.satisfied_signals);
267 EXPECT_EQ(kSignalAll, state.satisfiable_signals);
247 268
248 // Read a message from |h0|. 269 // Read a message from |h0|.
249 memset(buffer, 0, sizeof(buffer)); 270 memset(buffer, 0, sizeof(buffer));
250 num_bytes = static_cast<uint32_t>(sizeof(buffer)); 271 num_bytes = static_cast<uint32_t>(sizeof(buffer));
251 EXPECT_EQ(MOJO_RESULT_OK, 272 EXPECT_EQ(MOJO_RESULT_OK,
252 MojoReadMessage(h0, buffer, &num_bytes, nullptr, nullptr, 273 MojoReadMessage(h0, buffer, &num_bytes, nullptr, nullptr,
253 MOJO_READ_MESSAGE_FLAG_NONE)); 274 MOJO_READ_MESSAGE_FLAG_NONE));
254 EXPECT_EQ(sizeof(kBarBaz), num_bytes); 275 EXPECT_EQ(sizeof(kBarBaz), num_bytes);
255 EXPECT_STREQ(kBarBaz, buffer); 276 EXPECT_STREQ(kBarBaz, buffer);
256 277
(...skipping 18 matching lines...) Expand all
275 // 3. "FOO" 296 // 3. "FOO"
276 // 4. "Bar"+mp1 297 // 4. "Bar"+mp1
277 // 5. (close) 298 // 5. (close)
278 // 6. (close) 299 // 6. (close)
279 // 7. "baz" 300 // 7. "baz"
280 // 8. (closed) 301 // 8. (closed)
281 // 9. "quux"+mp2 302 // 9. "quux"+mp2
282 // 10. (close) 303 // 10. (close)
283 // 11. (wait/cl.) 304 // 11. (wait/cl.)
284 // 12. (wait/cl.) 305 // 12. (wait/cl.)
306
285 #if defined(OS_ANDROID) 307 #if defined(OS_ANDROID)
286 // Android multi-process tests are not executing the new process. This is flaky. 308 // Android multi-process tests are not executing the new process. This is flaky.
287 #define MAYBE_MultiprocessChannels DISABLED_MultiprocessChannels 309 #define MAYBE_MultiprocessChannels DISABLED_MultiprocessChannels
288 #else 310 #else
289 #define MAYBE_MultiprocessChannels MultiprocessChannels 311 #define MAYBE_MultiprocessChannels MultiprocessChannels
290 #endif // defined(OS_ANDROID) 312 #endif // defined(OS_ANDROID)
291 TEST_F(EmbedderTest, MAYBE_MultiprocessChannels) { 313 TEST_F(EmbedderTest, MAYBE_MultiprocessChannels) {
292 mojo::embedder::test::InitWithSimplePlatformSupport(); 314 mojo::embedder::test::InitWithSimplePlatformSupport();
293 mojo::test::MultiprocessTestHelper multiprocess_test_helper; 315 mojo::test::MultiprocessTestHelper multiprocess_test_helper;
294 multiprocess_test_helper.StartChild("MultiprocessChannelsClient"); 316 multiprocess_test_helper.StartChild("MultiprocessChannelsClient");
(...skipping 11 matching lines...) Expand all
306 const char kHello[] = "hello"; 328 const char kHello[] = "hello";
307 EXPECT_EQ(MOJO_RESULT_OK, 329 EXPECT_EQ(MOJO_RESULT_OK,
308 MojoWriteMessage(server_mp, kHello, 330 MojoWriteMessage(server_mp, kHello,
309 static_cast<uint32_t>(sizeof(kHello)), nullptr, 331 static_cast<uint32_t>(sizeof(kHello)), nullptr,
310 0, MOJO_WRITE_MESSAGE_FLAG_NONE)); 332 0, MOJO_WRITE_MESSAGE_FLAG_NONE));
311 333
312 // TODO(vtl): If the scope were ended immediately here (maybe after closing 334 // TODO(vtl): If the scope were ended immediately here (maybe after closing
313 // |server_mp|), we die with a fatal error in |Channel::HandleLocalError()|. 335 // |server_mp|), we die with a fatal error in |Channel::HandleLocalError()|.
314 336
315 // 2. Read a message from |server_mp|. 337 // 2. Read a message from |server_mp|.
316 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(server_mp, MOJO_HANDLE_SIGNAL_READABLE, 338 MojoHandleSignalsState state;
317 MOJO_DEADLINE_INDEFINITE)); 339 EXPECT_EQ(MOJO_RESULT_OK,
340 MojoNewWait(server_mp, MOJO_HANDLE_SIGNAL_READABLE,
341 MOJO_DEADLINE_INDEFINITE, &state));
342 EXPECT_EQ(kSignalReadadableWritable, state.satisfied_signals);
343 EXPECT_EQ(kSignalAll, state.satisfiable_signals);
344
318 char buffer[1000] = {}; 345 char buffer[1000] = {};
319 uint32_t num_bytes = static_cast<uint32_t>(sizeof(buffer)); 346 uint32_t num_bytes = static_cast<uint32_t>(sizeof(buffer));
320 EXPECT_EQ(MOJO_RESULT_OK, 347 EXPECT_EQ(MOJO_RESULT_OK,
321 MojoReadMessage(server_mp, buffer, &num_bytes, nullptr, nullptr, 348 MojoReadMessage(server_mp, buffer, &num_bytes, nullptr, nullptr,
322 MOJO_READ_MESSAGE_FLAG_NONE)); 349 MOJO_READ_MESSAGE_FLAG_NONE));
323 const char kWorld[] = "world!"; 350 const char kWorld[] = "world!";
324 EXPECT_EQ(sizeof(kWorld), num_bytes); 351 EXPECT_EQ(sizeof(kWorld), num_bytes);
325 EXPECT_STREQ(kWorld, buffer); 352 EXPECT_STREQ(kWorld, buffer);
326 353
327 // Create a new message pipe (endpoints |mp0| and |mp1|). 354 // Create a new message pipe (endpoints |mp0| and |mp1|).
(...skipping 11 matching lines...) Expand all
339 EXPECT_EQ( 366 EXPECT_EQ(
340 MOJO_RESULT_OK, 367 MOJO_RESULT_OK,
341 MojoWriteMessage(server_mp, kBar, static_cast<uint32_t>(sizeof(kBar)), 368 MojoWriteMessage(server_mp, kBar, static_cast<uint32_t>(sizeof(kBar)),
342 &mp1, 1, MOJO_WRITE_MESSAGE_FLAG_NONE)); 369 &mp1, 1, MOJO_WRITE_MESSAGE_FLAG_NONE));
343 mp1 = MOJO_HANDLE_INVALID; 370 mp1 = MOJO_HANDLE_INVALID;
344 371
345 // 5. Close |server_mp|. 372 // 5. Close |server_mp|.
346 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(server_mp)); 373 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(server_mp));
347 374
348 // 9. Read a message from |mp0|, which should have |mp2| attached. 375 // 9. Read a message from |mp0|, which should have |mp2| attached.
349 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(mp0, MOJO_HANDLE_SIGNAL_READABLE, 376 EXPECT_EQ(MOJO_RESULT_OK, MojoNewWait(mp0, MOJO_HANDLE_SIGNAL_READABLE,
350 MOJO_DEADLINE_INDEFINITE)); 377 MOJO_DEADLINE_INDEFINITE, &state));
378 EXPECT_EQ(kSignalReadadableWritable, state.satisfied_signals);
379 EXPECT_EQ(kSignalAll, state.satisfiable_signals);
380
351 memset(buffer, 0, sizeof(buffer)); 381 memset(buffer, 0, sizeof(buffer));
352 num_bytes = static_cast<uint32_t>(sizeof(buffer)); 382 num_bytes = static_cast<uint32_t>(sizeof(buffer));
353 MojoHandle mp2 = MOJO_HANDLE_INVALID; 383 MojoHandle mp2 = MOJO_HANDLE_INVALID;
354 uint32_t num_handles = 1; 384 uint32_t num_handles = 1;
355 EXPECT_EQ(MOJO_RESULT_OK, 385 EXPECT_EQ(MOJO_RESULT_OK,
356 MojoReadMessage(mp0, buffer, &num_bytes, &mp2, &num_handles, 386 MojoReadMessage(mp0, buffer, &num_bytes, &mp2, &num_handles,
357 MOJO_READ_MESSAGE_FLAG_NONE)); 387 MOJO_READ_MESSAGE_FLAG_NONE));
358 const char kQuux[] = "quux"; 388 const char kQuux[] = "quux";
359 EXPECT_EQ(sizeof(kQuux), num_bytes); 389 EXPECT_EQ(sizeof(kQuux), num_bytes);
360 EXPECT_STREQ(kQuux, buffer); 390 EXPECT_STREQ(kQuux, buffer);
361 EXPECT_EQ(1u, num_handles); 391 EXPECT_EQ(1u, num_handles);
362 EXPECT_NE(mp2, MOJO_HANDLE_INVALID); 392 EXPECT_NE(mp2, MOJO_HANDLE_INVALID);
363 393
364 // 7. Read a message from |mp2|. 394 // 7. Read a message from |mp2|.
365 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(mp2, MOJO_HANDLE_SIGNAL_READABLE, 395 EXPECT_EQ(MOJO_RESULT_OK, MojoNewWait(mp2, MOJO_HANDLE_SIGNAL_READABLE,
366 MOJO_DEADLINE_INDEFINITE)); 396 MOJO_DEADLINE_INDEFINITE, &state));
397 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED,
398 state.satisfied_signals);
399 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED,
400 state.satisfiable_signals);
401
367 memset(buffer, 0, sizeof(buffer)); 402 memset(buffer, 0, sizeof(buffer));
368 num_bytes = static_cast<uint32_t>(sizeof(buffer)); 403 num_bytes = static_cast<uint32_t>(sizeof(buffer));
369 EXPECT_EQ(MOJO_RESULT_OK, 404 EXPECT_EQ(MOJO_RESULT_OK,
370 MojoReadMessage(mp2, buffer, &num_bytes, nullptr, nullptr, 405 MojoReadMessage(mp2, buffer, &num_bytes, nullptr, nullptr,
371 MOJO_READ_MESSAGE_FLAG_NONE)); 406 MOJO_READ_MESSAGE_FLAG_NONE));
372 const char kBaz[] = "baz"; 407 const char kBaz[] = "baz";
373 EXPECT_EQ(sizeof(kBaz), num_bytes); 408 EXPECT_EQ(sizeof(kBaz), num_bytes);
374 EXPECT_STREQ(kBaz, buffer); 409 EXPECT_STREQ(kBaz, buffer);
375 410
376 // 10. Close |mp0|. 411 // 10. Close |mp0|.
377 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(mp0)); 412 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(mp0));
378 413
379 // 12. Wait on |mp2| (which should eventually fail) and then close it. 414 // 12. Wait on |mp2| (which should eventually fail) and then close it.
380 // TODO(vtl): crbug.com/351768 415 // TODO(vtl): crbug.com/351768
381 #if 0 416 #if 0
382 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, 417 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
383 MojoWait(mp2, MOJO_HANDLE_SIGNAL_READABLE, 418 MojoNewWait(mp2, MOJO_HANDLE_SIGNAL_READABLE,
384 MOJO_DEADLINE_INDEFINITE)); 419 MOJO_DEADLINE_INDEFINITE,
420 &state));
421 EXPECT_EQ(MOJO_HANDLE_SIGNAL_NONE, state.satisfied_signals);
422 EXPECT_EQ(MOJO_HANDLE_SIGNAL_NONE, state.satisfiable_signals);
385 #endif 423 #endif
386 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(mp2)); 424 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(mp2));
387 } 425 }
388 426
389 EXPECT_TRUE(multiprocess_test_helper.WaitForChildTestShutdown()); 427 EXPECT_TRUE(multiprocess_test_helper.WaitForChildTestShutdown());
390 EXPECT_TRUE(test::Shutdown()); 428 EXPECT_TRUE(test::Shutdown());
391 } 429 }
392 430
393 MOJO_MULTIPROCESS_TEST_CHILD_TEST(MultiprocessChannelsClient) { 431 MOJO_MULTIPROCESS_TEST_CHILD_TEST(MultiprocessChannelsClient) {
394 ScopedPlatformHandle client_platform_handle = 432 ScopedPlatformHandle client_platform_handle =
395 mojo::test::MultiprocessTestHelper::client_platform_handle.Pass(); 433 mojo::test::MultiprocessTestHelper::client_platform_handle.Pass();
396 EXPECT_TRUE(client_platform_handle.is_valid()); 434 EXPECT_TRUE(client_platform_handle.is_valid());
397 435
398 base::TestIOThread test_io_thread(base::TestIOThread::kAutoStart); 436 base::TestIOThread test_io_thread(base::TestIOThread::kAutoStart);
399 mojo::embedder::test::InitWithSimplePlatformSupport(); 437 mojo::embedder::test::InitWithSimplePlatformSupport();
400 438
401 { 439 {
402 ScopedTestChannel client_channel(test_io_thread.task_runner(), 440 ScopedTestChannel client_channel(test_io_thread.task_runner(),
403 client_platform_handle.Pass()); 441 client_platform_handle.Pass());
404 MojoHandle client_mp = client_channel.bootstrap_message_pipe(); 442 MojoHandle client_mp = client_channel.bootstrap_message_pipe();
405 EXPECT_NE(client_mp, MOJO_HANDLE_INVALID); 443 EXPECT_NE(client_mp, MOJO_HANDLE_INVALID);
406 client_channel.WaitForChannelCreationCompletion(); 444 client_channel.WaitForChannelCreationCompletion();
407 CHECK(client_channel.channel_info() != nullptr); 445 CHECK(client_channel.channel_info() != nullptr);
408 446
409 // 1. Read the first message from |client_mp|. 447 // 1. Read the first message from |client_mp|.
410 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(client_mp, MOJO_HANDLE_SIGNAL_READABLE, 448 MojoHandleSignalsState state;
411 MOJO_DEADLINE_INDEFINITE)); 449 EXPECT_EQ(MOJO_RESULT_OK,
450 MojoNewWait(client_mp, MOJO_HANDLE_SIGNAL_READABLE,
451 MOJO_DEADLINE_INDEFINITE, &state));
452 EXPECT_EQ(kSignalReadadableWritable, state.satisfied_signals);
453 EXPECT_EQ(kSignalAll, state.satisfiable_signals);
454
412 char buffer[1000] = {}; 455 char buffer[1000] = {};
413 uint32_t num_bytes = static_cast<uint32_t>(sizeof(buffer)); 456 uint32_t num_bytes = static_cast<uint32_t>(sizeof(buffer));
414 EXPECT_EQ(MOJO_RESULT_OK, 457 EXPECT_EQ(MOJO_RESULT_OK,
415 MojoReadMessage(client_mp, buffer, &num_bytes, nullptr, nullptr, 458 MojoReadMessage(client_mp, buffer, &num_bytes, nullptr, nullptr,
416 MOJO_READ_MESSAGE_FLAG_NONE)); 459 MOJO_READ_MESSAGE_FLAG_NONE));
417 const char kHello[] = "hello"; 460 const char kHello[] = "hello";
418 EXPECT_EQ(sizeof(kHello), num_bytes); 461 EXPECT_EQ(sizeof(kHello), num_bytes);
419 EXPECT_STREQ(kHello, buffer); 462 EXPECT_STREQ(kHello, buffer);
420 463
421 // 2. Write a message to |client_mp| (attaching nothing). 464 // 2. Write a message to |client_mp| (attaching nothing).
422 const char kWorld[] = "world!"; 465 const char kWorld[] = "world!";
423 EXPECT_EQ(MOJO_RESULT_OK, 466 EXPECT_EQ(MOJO_RESULT_OK,
424 MojoWriteMessage(client_mp, kWorld, 467 MojoWriteMessage(client_mp, kWorld,
425 static_cast<uint32_t>(sizeof(kWorld)), nullptr, 468 static_cast<uint32_t>(sizeof(kWorld)), nullptr,
426 0, MOJO_WRITE_MESSAGE_FLAG_NONE)); 469 0, MOJO_WRITE_MESSAGE_FLAG_NONE));
427 470
428 // 4. Read a message from |client_mp|, which should have |mp1| attached. 471 // 4. Read a message from |client_mp|, which should have |mp1| attached.
429 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(client_mp, MOJO_HANDLE_SIGNAL_READABLE, 472 EXPECT_EQ(MOJO_RESULT_OK,
430 MOJO_DEADLINE_INDEFINITE)); 473 MojoNewWait(client_mp, MOJO_HANDLE_SIGNAL_READABLE,
474 MOJO_DEADLINE_INDEFINITE, &state));
475 // The other end of the handle may or may not be closed at this point, so we
476 // can't test MOJO_HANDLE_SIGNAL_WRITABLE or MOJO_HANDLE_SIGNAL_PEER_CLOSED.
477 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE,
478 state.satisfied_signals & MOJO_HANDLE_SIGNAL_READABLE);
479 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE,
480 state.satisfiable_signals & MOJO_HANDLE_SIGNAL_READABLE);
431 // TODO(vtl): If the scope were to end here (and |client_mp| closed), we'd 481 // TODO(vtl): If the scope were to end here (and |client_mp| closed), we'd
432 // die (again due to |Channel::HandleLocalError()|). 482 // die (again due to |Channel::HandleLocalError()|).
433 memset(buffer, 0, sizeof(buffer)); 483 memset(buffer, 0, sizeof(buffer));
434 num_bytes = static_cast<uint32_t>(sizeof(buffer)); 484 num_bytes = static_cast<uint32_t>(sizeof(buffer));
435 MojoHandle mp1 = MOJO_HANDLE_INVALID; 485 MojoHandle mp1 = MOJO_HANDLE_INVALID;
436 uint32_t num_handles = 1; 486 uint32_t num_handles = 1;
437 EXPECT_EQ(MOJO_RESULT_OK, 487 EXPECT_EQ(MOJO_RESULT_OK,
438 MojoReadMessage(client_mp, buffer, &num_bytes, &mp1, &num_handles, 488 MojoReadMessage(client_mp, buffer, &num_bytes, &mp1, &num_handles,
439 MOJO_READ_MESSAGE_FLAG_NONE)); 489 MOJO_READ_MESSAGE_FLAG_NONE));
440 const char kBar[] = "Bar"; 490 const char kBar[] = "Bar";
(...skipping 22 matching lines...) Expand all
463 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(mp3)); 513 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(mp3));
464 514
465 // 9. Write a message to |mp1|, attaching |mp2|. 515 // 9. Write a message to |mp1|, attaching |mp2|.
466 const char kQuux[] = "quux"; 516 const char kQuux[] = "quux";
467 EXPECT_EQ(MOJO_RESULT_OK, 517 EXPECT_EQ(MOJO_RESULT_OK,
468 MojoWriteMessage(mp1, kQuux, static_cast<uint32_t>(sizeof(kQuux)), 518 MojoWriteMessage(mp1, kQuux, static_cast<uint32_t>(sizeof(kQuux)),
469 &mp2, 1, MOJO_WRITE_MESSAGE_FLAG_NONE)); 519 &mp2, 1, MOJO_WRITE_MESSAGE_FLAG_NONE));
470 mp2 = MOJO_HANDLE_INVALID; 520 mp2 = MOJO_HANDLE_INVALID;
471 521
472 // 3. Read a message from |mp1|. 522 // 3. Read a message from |mp1|.
473 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(mp1, MOJO_HANDLE_SIGNAL_READABLE, 523 EXPECT_EQ(MOJO_RESULT_OK, MojoNewWait(mp1, MOJO_HANDLE_SIGNAL_READABLE,
474 MOJO_DEADLINE_INDEFINITE)); 524 MOJO_DEADLINE_INDEFINITE, &state));
525 EXPECT_EQ(kSignalReadadableWritable, state.satisfied_signals);
526 EXPECT_EQ(kSignalAll, state.satisfiable_signals);
527
475 memset(buffer, 0, sizeof(buffer)); 528 memset(buffer, 0, sizeof(buffer));
476 num_bytes = static_cast<uint32_t>(sizeof(buffer)); 529 num_bytes = static_cast<uint32_t>(sizeof(buffer));
477 EXPECT_EQ(MOJO_RESULT_OK, 530 EXPECT_EQ(MOJO_RESULT_OK,
478 MojoReadMessage(mp1, buffer, &num_bytes, nullptr, nullptr, 531 MojoReadMessage(mp1, buffer, &num_bytes, nullptr, nullptr,
479 MOJO_READ_MESSAGE_FLAG_NONE)); 532 MOJO_READ_MESSAGE_FLAG_NONE));
480 const char kFoo[] = "FOO"; 533 const char kFoo[] = "FOO";
481 EXPECT_EQ(sizeof(kFoo), num_bytes); 534 EXPECT_EQ(sizeof(kFoo), num_bytes);
482 EXPECT_STREQ(kFoo, buffer); 535 EXPECT_STREQ(kFoo, buffer);
483 536
484 // 11. Wait on |mp1| (which should eventually fail) and then close it. 537 // 11. Wait on |mp1| (which should eventually fail) and then close it.
485 EXPECT_EQ( 538 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
486 MOJO_RESULT_FAILED_PRECONDITION, 539 MojoNewWait(mp1, MOJO_HANDLE_SIGNAL_READABLE,
487 MojoWait(mp1, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE)); 540 MOJO_DEADLINE_INDEFINITE, &state));
541 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, state.satisfied_signals);
542 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, state.satisfiable_signals);
488 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(mp1)); 543 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(mp1));
489 } 544 }
490 545
491 EXPECT_TRUE(test::Shutdown()); 546 EXPECT_TRUE(test::Shutdown());
492 } 547 }
493 548
494 // TODO(vtl): Test immediate write & close. 549 // TODO(vtl): Test immediate write & close.
495 // TODO(vtl): Test broken-connection cases. 550 // TODO(vtl): Test broken-connection cases.
496 551
497 } // namespace 552 } // namespace
498 } // namespace embedder 553 } // namespace embedder
499 } // namespace mojo 554 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698