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

Side by Side Diff: mojo/edk/embedder/embedder_unittest.cc

Issue 728553002: Update mojo sdk to rev afb4440fd5a10cba980878c326180b7ad7960480 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « mojo/edk/embedder/embedder_internal.h ('k') | mojo/edk/embedder/entrypoints.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 21 matching lines...) Expand all
32 // pipe on this channel; it is up to the caller to close this handle. 32 // 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 33 // Note: The I/O thread must outlive this object (and its message loop must
34 // continue pumping messages while this object is alive). 34 // continue pumping messages while this object is alive).
35 ScopedTestChannel(scoped_refptr<base::TaskRunner> io_thread_task_runner, 35 ScopedTestChannel(scoped_refptr<base::TaskRunner> io_thread_task_runner,
36 ScopedPlatformHandle platform_handle) 36 ScopedPlatformHandle platform_handle)
37 : io_thread_task_runner_(io_thread_task_runner), 37 : io_thread_task_runner_(io_thread_task_runner),
38 bootstrap_message_pipe_(MOJO_HANDLE_INVALID), 38 bootstrap_message_pipe_(MOJO_HANDLE_INVALID),
39 did_create_channel_event_(true, false), 39 did_create_channel_event_(true, false),
40 channel_info_(nullptr) { 40 channel_info_(nullptr) {
41 bootstrap_message_pipe_ = 41 bootstrap_message_pipe_ =
42 CreateChannel(platform_handle.Pass(), 42 CreateChannel(platform_handle.Pass(), io_thread_task_runner_,
43 io_thread_task_runner_,
44 base::Bind(&ScopedTestChannel::DidCreateChannel, 43 base::Bind(&ScopedTestChannel::DidCreateChannel,
45 base::Unretained(this)), 44 base::Unretained(this)),
46 nullptr) 45 nullptr)
47 .release() 46 .release()
48 .value(); 47 .value();
49 CHECK_NE(bootstrap_message_pipe_, MOJO_HANDLE_INVALID); 48 CHECK_NE(bootstrap_message_pipe_, MOJO_HANDLE_INVALID);
50 } 49 }
51 50
52 // Destructor: Shuts down the channel. (As noted above, for this to happen, 51 // Destructor: Shuts down the channel. (As noted above, for this to happen,
53 // the I/O thread must be alive and pumping messages.) 52 // the I/O thread must be alive and pumping messages.)
54 ~ScopedTestChannel() { 53 ~ScopedTestChannel() {
55 system::test::PostTaskAndWait( 54 system::test::PostTaskAndWait(
56 io_thread_task_runner_, 55 io_thread_task_runner_, FROM_HERE,
57 FROM_HERE,
58 base::Bind(&ScopedTestChannel::DestroyChannel, base::Unretained(this))); 56 base::Bind(&ScopedTestChannel::DestroyChannel, base::Unretained(this)));
59 } 57 }
60 58
61 // Waits for channel creation to be completed. 59 // Waits for channel creation to be completed.
62 void WaitForChannelCreationCompletion() { did_create_channel_event_.Wait(); } 60 void WaitForChannelCreationCompletion() { did_create_channel_event_.Wait(); }
63 61
64 MojoHandle bootstrap_message_pipe() const { return bootstrap_message_pipe_; } 62 MojoHandle bootstrap_message_pipe() const { return bootstrap_message_pipe_; }
65 63
66 // Call only after |WaitForChannelCreationCompletion()|. Use only to check 64 // Call only after |WaitForChannelCreationCompletion()|. Use only to check
67 // that it's not null. 65 // that it's not null.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 MojoHandle server_mp = server_channel.bootstrap_message_pipe(); 121 MojoHandle server_mp = server_channel.bootstrap_message_pipe();
124 EXPECT_NE(server_mp, MOJO_HANDLE_INVALID); 122 EXPECT_NE(server_mp, MOJO_HANDLE_INVALID);
125 ScopedTestChannel client_channel(test_io_thread()->task_runner(), 123 ScopedTestChannel client_channel(test_io_thread()->task_runner(),
126 channel_pair.PassClientHandle()); 124 channel_pair.PassClientHandle());
127 MojoHandle client_mp = client_channel.bootstrap_message_pipe(); 125 MojoHandle client_mp = client_channel.bootstrap_message_pipe();
128 EXPECT_NE(client_mp, MOJO_HANDLE_INVALID); 126 EXPECT_NE(client_mp, MOJO_HANDLE_INVALID);
129 127
130 // We can write to a message pipe handle immediately. 128 // We can write to a message pipe handle immediately.
131 const char kHello[] = "hello"; 129 const char kHello[] = "hello";
132 EXPECT_EQ(MOJO_RESULT_OK, 130 EXPECT_EQ(MOJO_RESULT_OK,
133 MojoWriteMessage(server_mp, 131 MojoWriteMessage(server_mp, kHello,
134 kHello, 132 static_cast<uint32_t>(sizeof(kHello)), nullptr,
135 static_cast<uint32_t>(sizeof(kHello)), 133 0, MOJO_WRITE_MESSAGE_FLAG_NONE));
136 nullptr,
137 0,
138 MOJO_WRITE_MESSAGE_FLAG_NONE));
139 134
140 // Now wait for the other side to become readable. 135 // Now wait for the other side to become readable.
141 EXPECT_EQ( 136 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(client_mp, MOJO_HANDLE_SIGNAL_READABLE,
142 MOJO_RESULT_OK, 137 MOJO_DEADLINE_INDEFINITE));
143 MojoWait(
144 client_mp, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE));
145 138
146 char buffer[1000] = {}; 139 char buffer[1000] = {};
147 uint32_t num_bytes = static_cast<uint32_t>(sizeof(buffer)); 140 uint32_t num_bytes = static_cast<uint32_t>(sizeof(buffer));
148 EXPECT_EQ(MOJO_RESULT_OK, 141 EXPECT_EQ(MOJO_RESULT_OK,
149 MojoReadMessage(client_mp, 142 MojoReadMessage(client_mp, buffer, &num_bytes, nullptr, nullptr,
150 buffer,
151 &num_bytes,
152 nullptr,
153 nullptr,
154 MOJO_READ_MESSAGE_FLAG_NONE)); 143 MOJO_READ_MESSAGE_FLAG_NONE));
155 EXPECT_EQ(sizeof(kHello), num_bytes); 144 EXPECT_EQ(sizeof(kHello), num_bytes);
156 EXPECT_STREQ(kHello, buffer); 145 EXPECT_STREQ(kHello, buffer);
157 146
158 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(server_mp)); 147 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(server_mp));
159 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(client_mp)); 148 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(client_mp));
160 149
161 // By this point, these waits should basically be no-ops (since we've waited 150 // By this point, these waits should basically be no-ops (since we've waited
162 // for the client message pipe to become readable, which implies that both 151 // for the client message pipe to become readable, which implies that both
163 // the server and client channels were completely created). 152 // the server and client channels were completely created).
(...skipping 18 matching lines...) Expand all
182 ScopedTestChannel client_channel(test_io_thread()->task_runner(), 171 ScopedTestChannel client_channel(test_io_thread()->task_runner(),
183 channel_pair.PassClientHandle()); 172 channel_pair.PassClientHandle());
184 MojoHandle client_mp = client_channel.bootstrap_message_pipe(); 173 MojoHandle client_mp = client_channel.bootstrap_message_pipe();
185 EXPECT_NE(client_mp, MOJO_HANDLE_INVALID); 174 EXPECT_NE(client_mp, MOJO_HANDLE_INVALID);
186 175
187 MojoHandle h0, h1; 176 MojoHandle h0, h1;
188 EXPECT_EQ(MOJO_RESULT_OK, MojoCreateMessagePipe(nullptr, &h0, &h1)); 177 EXPECT_EQ(MOJO_RESULT_OK, MojoCreateMessagePipe(nullptr, &h0, &h1));
189 178
190 // Write a message to |h0| (attaching nothing). 179 // Write a message to |h0| (attaching nothing).
191 const char kHello[] = "hello"; 180 const char kHello[] = "hello";
192 EXPECT_EQ(MOJO_RESULT_OK, 181 EXPECT_EQ(
193 MojoWriteMessage(h0, 182 MOJO_RESULT_OK,
194 kHello, 183 MojoWriteMessage(h0, kHello, static_cast<uint32_t>(sizeof(kHello)),
195 static_cast<uint32_t>(sizeof(kHello)), 184 nullptr, 0, MOJO_WRITE_MESSAGE_FLAG_NONE));
196 nullptr,
197 0,
198 MOJO_WRITE_MESSAGE_FLAG_NONE));
199 185
200 // Write one message to |server_mp|, attaching |h1|. 186 // Write one message to |server_mp|, attaching |h1|.
201 const char kWorld[] = "world!!!"; 187 const char kWorld[] = "world!!!";
202 EXPECT_EQ(MOJO_RESULT_OK, 188 EXPECT_EQ(MOJO_RESULT_OK,
203 MojoWriteMessage(server_mp, 189 MojoWriteMessage(server_mp, kWorld,
204 kWorld, 190 static_cast<uint32_t>(sizeof(kWorld)), &h1, 1,
205 static_cast<uint32_t>(sizeof(kWorld)),
206 &h1,
207 1,
208 MOJO_WRITE_MESSAGE_FLAG_NONE)); 191 MOJO_WRITE_MESSAGE_FLAG_NONE));
209 h1 = MOJO_HANDLE_INVALID; 192 h1 = MOJO_HANDLE_INVALID;
210 193
211 // Write another message to |h0|. 194 // Write another message to |h0|.
212 const char kFoo[] = "foo"; 195 const char kFoo[] = "foo";
213 EXPECT_EQ(MOJO_RESULT_OK, 196 EXPECT_EQ(MOJO_RESULT_OK,
214 MojoWriteMessage(h0, 197 MojoWriteMessage(h0, kFoo, static_cast<uint32_t>(sizeof(kFoo)),
215 kFoo, 198 nullptr, 0, MOJO_WRITE_MESSAGE_FLAG_NONE));
216 static_cast<uint32_t>(sizeof(kFoo)),
217 nullptr,
218 0,
219 MOJO_WRITE_MESSAGE_FLAG_NONE));
220 199
221 // Wait for |client_mp| to become readable. 200 // Wait for |client_mp| to become readable.
222 EXPECT_EQ( 201 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(client_mp, MOJO_HANDLE_SIGNAL_READABLE,
223 MOJO_RESULT_OK, 202 MOJO_DEADLINE_INDEFINITE));
224 MojoWait(
225 client_mp, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE));
226 203
227 // Read a message from |client_mp|. 204 // Read a message from |client_mp|.
228 char buffer[1000] = {}; 205 char buffer[1000] = {};
229 uint32_t num_bytes = static_cast<uint32_t>(sizeof(buffer)); 206 uint32_t num_bytes = static_cast<uint32_t>(sizeof(buffer));
230 MojoHandle handles[10] = {}; 207 MojoHandle handles[10] = {};
231 uint32_t num_handles = arraysize(handles); 208 uint32_t num_handles = arraysize(handles);
232 EXPECT_EQ(MOJO_RESULT_OK, 209 EXPECT_EQ(MOJO_RESULT_OK,
233 MojoReadMessage(client_mp, 210 MojoReadMessage(client_mp, buffer, &num_bytes, handles,
234 buffer, 211 &num_handles, MOJO_READ_MESSAGE_FLAG_NONE));
235 &num_bytes,
236 handles,
237 &num_handles,
238 MOJO_READ_MESSAGE_FLAG_NONE));
239 EXPECT_EQ(sizeof(kWorld), num_bytes); 212 EXPECT_EQ(sizeof(kWorld), num_bytes);
240 EXPECT_STREQ(kWorld, buffer); 213 EXPECT_STREQ(kWorld, buffer);
241 EXPECT_EQ(1u, num_handles); 214 EXPECT_EQ(1u, num_handles);
242 EXPECT_NE(handles[0], MOJO_HANDLE_INVALID); 215 EXPECT_NE(handles[0], MOJO_HANDLE_INVALID);
243 h1 = handles[0]; 216 h1 = handles[0];
244 217
245 // Wait for |h1| to become readable. 218 // Wait for |h1| to become readable.
246 EXPECT_EQ( 219 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(h1, MOJO_HANDLE_SIGNAL_READABLE,
247 MOJO_RESULT_OK, 220 MOJO_DEADLINE_INDEFINITE));
248 MojoWait(h1, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE));
249 221
250 // Read a message from |h1|. 222 // Read a message from |h1|.
251 memset(buffer, 0, sizeof(buffer)); 223 memset(buffer, 0, sizeof(buffer));
252 num_bytes = static_cast<uint32_t>(sizeof(buffer)); 224 num_bytes = static_cast<uint32_t>(sizeof(buffer));
253 memset(handles, 0, sizeof(handles)); 225 memset(handles, 0, sizeof(handles));
254 num_handles = arraysize(handles); 226 num_handles = arraysize(handles);
255 EXPECT_EQ(MOJO_RESULT_OK, 227 EXPECT_EQ(MOJO_RESULT_OK,
256 MojoReadMessage(h1, 228 MojoReadMessage(h1, buffer, &num_bytes, handles, &num_handles,
257 buffer,
258 &num_bytes,
259 handles,
260 &num_handles,
261 MOJO_READ_MESSAGE_FLAG_NONE)); 229 MOJO_READ_MESSAGE_FLAG_NONE));
262 EXPECT_EQ(sizeof(kHello), num_bytes); 230 EXPECT_EQ(sizeof(kHello), num_bytes);
263 EXPECT_STREQ(kHello, buffer); 231 EXPECT_STREQ(kHello, buffer);
264 EXPECT_EQ(0u, num_handles); 232 EXPECT_EQ(0u, num_handles);
265 233
266 // Wait for |h1| to become readable (again). 234 // Wait for |h1| to become readable (again).
267 EXPECT_EQ( 235 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(h1, MOJO_HANDLE_SIGNAL_READABLE,
268 MOJO_RESULT_OK, 236 MOJO_DEADLINE_INDEFINITE));
269 MojoWait(h1, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE));
270 237
271 // Read the second message from |h1|. 238 // Read the second message from |h1|.
272 memset(buffer, 0, sizeof(buffer)); 239 memset(buffer, 0, sizeof(buffer));
273 num_bytes = static_cast<uint32_t>(sizeof(buffer)); 240 num_bytes = static_cast<uint32_t>(sizeof(buffer));
274 EXPECT_EQ(MOJO_RESULT_OK, 241 EXPECT_EQ(MOJO_RESULT_OK,
275 MojoReadMessage(h1, 242 MojoReadMessage(h1, buffer, &num_bytes, nullptr, nullptr,
276 buffer,
277 &num_bytes,
278 nullptr,
279 nullptr,
280 MOJO_READ_MESSAGE_FLAG_NONE)); 243 MOJO_READ_MESSAGE_FLAG_NONE));
281 EXPECT_EQ(sizeof(kFoo), num_bytes); 244 EXPECT_EQ(sizeof(kFoo), num_bytes);
282 EXPECT_STREQ(kFoo, buffer); 245 EXPECT_STREQ(kFoo, buffer);
283 246
284 // Write a message to |h1|. 247 // Write a message to |h1|.
285 const char kBarBaz[] = "barbaz"; 248 const char kBarBaz[] = "barbaz";
286 EXPECT_EQ(MOJO_RESULT_OK, 249 EXPECT_EQ(
287 MojoWriteMessage(h1, 250 MOJO_RESULT_OK,
288 kBarBaz, 251 MojoWriteMessage(h1, kBarBaz, static_cast<uint32_t>(sizeof(kBarBaz)),
289 static_cast<uint32_t>(sizeof(kBarBaz)), 252 nullptr, 0, MOJO_WRITE_MESSAGE_FLAG_NONE));
290 nullptr,
291 0,
292 MOJO_WRITE_MESSAGE_FLAG_NONE));
293 253
294 // Wait for |h0| to become readable. 254 // Wait for |h0| to become readable.
295 EXPECT_EQ( 255 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(h0, MOJO_HANDLE_SIGNAL_READABLE,
296 MOJO_RESULT_OK, 256 MOJO_DEADLINE_INDEFINITE));
297 MojoWait(h0, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE));
298 257
299 // Read a message from |h0|. 258 // Read a message from |h0|.
300 memset(buffer, 0, sizeof(buffer)); 259 memset(buffer, 0, sizeof(buffer));
301 num_bytes = static_cast<uint32_t>(sizeof(buffer)); 260 num_bytes = static_cast<uint32_t>(sizeof(buffer));
302 EXPECT_EQ(MOJO_RESULT_OK, 261 EXPECT_EQ(MOJO_RESULT_OK,
303 MojoReadMessage(h0, 262 MojoReadMessage(h0, buffer, &num_bytes, nullptr, nullptr,
304 buffer,
305 &num_bytes,
306 nullptr,
307 nullptr,
308 MOJO_READ_MESSAGE_FLAG_NONE)); 263 MOJO_READ_MESSAGE_FLAG_NONE));
309 EXPECT_EQ(sizeof(kBarBaz), num_bytes); 264 EXPECT_EQ(sizeof(kBarBaz), num_bytes);
310 EXPECT_STREQ(kBarBaz, buffer); 265 EXPECT_STREQ(kBarBaz, buffer);
311 266
312 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(server_mp)); 267 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(server_mp));
313 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(client_mp)); 268 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(client_mp));
314 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h0)); 269 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h0));
315 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h1)); 270 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h1));
316 271
317 server_channel.WaitForChannelCreationCompletion(); 272 server_channel.WaitForChannelCreationCompletion();
(...skipping 29 matching lines...) Expand all
347 test_io_thread()->task_runner(), 302 test_io_thread()->task_runner(),
348 multiprocess_test_helper.server_platform_handle.Pass()); 303 multiprocess_test_helper.server_platform_handle.Pass());
349 MojoHandle server_mp = server_channel.bootstrap_message_pipe(); 304 MojoHandle server_mp = server_channel.bootstrap_message_pipe();
350 EXPECT_NE(server_mp, MOJO_HANDLE_INVALID); 305 EXPECT_NE(server_mp, MOJO_HANDLE_INVALID);
351 server_channel.WaitForChannelCreationCompletion(); 306 server_channel.WaitForChannelCreationCompletion();
352 EXPECT_TRUE(server_channel.channel_info()); 307 EXPECT_TRUE(server_channel.channel_info());
353 308
354 // 1. Write a message to |server_mp| (attaching nothing). 309 // 1. Write a message to |server_mp| (attaching nothing).
355 const char kHello[] = "hello"; 310 const char kHello[] = "hello";
356 EXPECT_EQ(MOJO_RESULT_OK, 311 EXPECT_EQ(MOJO_RESULT_OK,
357 MojoWriteMessage(server_mp, 312 MojoWriteMessage(server_mp, kHello,
358 kHello, 313 static_cast<uint32_t>(sizeof(kHello)), nullptr,
359 static_cast<uint32_t>(sizeof(kHello)), 314 0, MOJO_WRITE_MESSAGE_FLAG_NONE));
360 nullptr,
361 0,
362 MOJO_WRITE_MESSAGE_FLAG_NONE));
363 315
364 // TODO(vtl): If the scope were ended immediately here (maybe after closing 316 // TODO(vtl): If the scope were ended immediately here (maybe after closing
365 // |server_mp|), we die with a fatal error in |Channel::HandleLocalError()|. 317 // |server_mp|), we die with a fatal error in |Channel::HandleLocalError()|.
366 318
367 // 2. Read a message from |server_mp|. 319 // 2. Read a message from |server_mp|.
368 EXPECT_EQ( 320 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(server_mp, MOJO_HANDLE_SIGNAL_READABLE,
369 MOJO_RESULT_OK, 321 MOJO_DEADLINE_INDEFINITE));
370 MojoWait(
371 server_mp, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE));
372 char buffer[1000] = {}; 322 char buffer[1000] = {};
373 uint32_t num_bytes = static_cast<uint32_t>(sizeof(buffer)); 323 uint32_t num_bytes = static_cast<uint32_t>(sizeof(buffer));
374 EXPECT_EQ(MOJO_RESULT_OK, 324 EXPECT_EQ(MOJO_RESULT_OK,
375 MojoReadMessage(server_mp, 325 MojoReadMessage(server_mp, buffer, &num_bytes, nullptr, nullptr,
376 buffer,
377 &num_bytes,
378 nullptr,
379 nullptr,
380 MOJO_READ_MESSAGE_FLAG_NONE)); 326 MOJO_READ_MESSAGE_FLAG_NONE));
381 const char kWorld[] = "world!"; 327 const char kWorld[] = "world!";
382 EXPECT_EQ(sizeof(kWorld), num_bytes); 328 EXPECT_EQ(sizeof(kWorld), num_bytes);
383 EXPECT_STREQ(kWorld, buffer); 329 EXPECT_STREQ(kWorld, buffer);
384 330
385 // Create a new message pipe (endpoints |mp0| and |mp1|). 331 // Create a new message pipe (endpoints |mp0| and |mp1|).
386 MojoHandle mp0, mp1; 332 MojoHandle mp0, mp1;
387 EXPECT_EQ(MOJO_RESULT_OK, MojoCreateMessagePipe(nullptr, &mp0, &mp1)); 333 EXPECT_EQ(MOJO_RESULT_OK, MojoCreateMessagePipe(nullptr, &mp0, &mp1));
388 334
389 // 3. Write something to |mp0|. 335 // 3. Write something to |mp0|.
390 const char kFoo[] = "FOO"; 336 const char kFoo[] = "FOO";
391 EXPECT_EQ(MOJO_RESULT_OK, 337 EXPECT_EQ(MOJO_RESULT_OK,
392 MojoWriteMessage(mp0, 338 MojoWriteMessage(mp0, kFoo, static_cast<uint32_t>(sizeof(kFoo)),
393 kFoo, 339 nullptr, 0, MOJO_WRITE_MESSAGE_FLAG_NONE));
394 static_cast<uint32_t>(sizeof(kFoo)),
395 nullptr,
396 0,
397 MOJO_WRITE_MESSAGE_FLAG_NONE));
398 340
399 // 4. Write a message to |server_mp|, attaching |mp1|. 341 // 4. Write a message to |server_mp|, attaching |mp1|.
400 const char kBar[] = "Bar"; 342 const char kBar[] = "Bar";
401 EXPECT_EQ(MOJO_RESULT_OK, 343 EXPECT_EQ(
402 MojoWriteMessage(server_mp, 344 MOJO_RESULT_OK,
403 kBar, 345 MojoWriteMessage(server_mp, kBar, static_cast<uint32_t>(sizeof(kBar)),
404 static_cast<uint32_t>(sizeof(kBar)), 346 &mp1, 1, MOJO_WRITE_MESSAGE_FLAG_NONE));
405 &mp1,
406 1,
407 MOJO_WRITE_MESSAGE_FLAG_NONE));
408 mp1 = MOJO_HANDLE_INVALID; 347 mp1 = MOJO_HANDLE_INVALID;
409 348
410 // 5. Close |server_mp|. 349 // 5. Close |server_mp|.
411 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(server_mp)); 350 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(server_mp));
412 351
413 // 9. Read a message from |mp0|, which should have |mp2| attached. 352 // 9. Read a message from |mp0|, which should have |mp2| attached.
414 EXPECT_EQ( 353 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(mp0, MOJO_HANDLE_SIGNAL_READABLE,
415 MOJO_RESULT_OK, 354 MOJO_DEADLINE_INDEFINITE));
416 MojoWait(mp0, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE));
417 memset(buffer, 0, sizeof(buffer)); 355 memset(buffer, 0, sizeof(buffer));
418 num_bytes = static_cast<uint32_t>(sizeof(buffer)); 356 num_bytes = static_cast<uint32_t>(sizeof(buffer));
419 MojoHandle mp2 = MOJO_HANDLE_INVALID; 357 MojoHandle mp2 = MOJO_HANDLE_INVALID;
420 uint32_t num_handles = 1; 358 uint32_t num_handles = 1;
421 EXPECT_EQ(MOJO_RESULT_OK, 359 EXPECT_EQ(MOJO_RESULT_OK,
422 MojoReadMessage(mp0, 360 MojoReadMessage(mp0, buffer, &num_bytes, &mp2, &num_handles,
423 buffer,
424 &num_bytes,
425 &mp2,
426 &num_handles,
427 MOJO_READ_MESSAGE_FLAG_NONE)); 361 MOJO_READ_MESSAGE_FLAG_NONE));
428 const char kQuux[] = "quux"; 362 const char kQuux[] = "quux";
429 EXPECT_EQ(sizeof(kQuux), num_bytes); 363 EXPECT_EQ(sizeof(kQuux), num_bytes);
430 EXPECT_STREQ(kQuux, buffer); 364 EXPECT_STREQ(kQuux, buffer);
431 EXPECT_EQ(1u, num_handles); 365 EXPECT_EQ(1u, num_handles);
432 EXPECT_NE(mp2, MOJO_HANDLE_INVALID); 366 EXPECT_NE(mp2, MOJO_HANDLE_INVALID);
433 367
434 // 7. Read a message from |mp2|. 368 // 7. Read a message from |mp2|.
435 EXPECT_EQ( 369 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(mp2, MOJO_HANDLE_SIGNAL_READABLE,
436 MOJO_RESULT_OK, 370 MOJO_DEADLINE_INDEFINITE));
437 MojoWait(mp2, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE));
438 memset(buffer, 0, sizeof(buffer)); 371 memset(buffer, 0, sizeof(buffer));
439 num_bytes = static_cast<uint32_t>(sizeof(buffer)); 372 num_bytes = static_cast<uint32_t>(sizeof(buffer));
440 EXPECT_EQ(MOJO_RESULT_OK, 373 EXPECT_EQ(MOJO_RESULT_OK,
441 MojoReadMessage(mp2, 374 MojoReadMessage(mp2, buffer, &num_bytes, nullptr, nullptr,
442 buffer,
443 &num_bytes,
444 nullptr,
445 nullptr,
446 MOJO_READ_MESSAGE_FLAG_NONE)); 375 MOJO_READ_MESSAGE_FLAG_NONE));
447 const char kBaz[] = "baz"; 376 const char kBaz[] = "baz";
448 EXPECT_EQ(sizeof(kBaz), num_bytes); 377 EXPECT_EQ(sizeof(kBaz), num_bytes);
449 EXPECT_STREQ(kBaz, buffer); 378 EXPECT_STREQ(kBaz, buffer);
450 379
451 // 10. Close |mp0|. 380 // 10. Close |mp0|.
452 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(mp0)); 381 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(mp0));
453 382
454 // 12. Wait on |mp2| (which should eventually fail) and then close it. 383 // 12. Wait on |mp2| (which should eventually fail) and then close it.
455 // TODO(vtl): crbug.com/351768 384 // TODO(vtl): crbug.com/351768
(...skipping 19 matching lines...) Expand all
475 404
476 { 405 {
477 ScopedTestChannel client_channel(test_io_thread.task_runner(), 406 ScopedTestChannel client_channel(test_io_thread.task_runner(),
478 client_platform_handle.Pass()); 407 client_platform_handle.Pass());
479 MojoHandle client_mp = client_channel.bootstrap_message_pipe(); 408 MojoHandle client_mp = client_channel.bootstrap_message_pipe();
480 EXPECT_NE(client_mp, MOJO_HANDLE_INVALID); 409 EXPECT_NE(client_mp, MOJO_HANDLE_INVALID);
481 client_channel.WaitForChannelCreationCompletion(); 410 client_channel.WaitForChannelCreationCompletion();
482 CHECK(client_channel.channel_info() != nullptr); 411 CHECK(client_channel.channel_info() != nullptr);
483 412
484 // 1. Read the first message from |client_mp|. 413 // 1. Read the first message from |client_mp|.
485 EXPECT_EQ( 414 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(client_mp, MOJO_HANDLE_SIGNAL_READABLE,
486 MOJO_RESULT_OK, 415 MOJO_DEADLINE_INDEFINITE));
487 MojoWait(
488 client_mp, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE));
489 char buffer[1000] = {}; 416 char buffer[1000] = {};
490 uint32_t num_bytes = static_cast<uint32_t>(sizeof(buffer)); 417 uint32_t num_bytes = static_cast<uint32_t>(sizeof(buffer));
491 EXPECT_EQ(MOJO_RESULT_OK, 418 EXPECT_EQ(MOJO_RESULT_OK,
492 MojoReadMessage(client_mp, 419 MojoReadMessage(client_mp, buffer, &num_bytes, nullptr, nullptr,
493 buffer,
494 &num_bytes,
495 nullptr,
496 nullptr,
497 MOJO_READ_MESSAGE_FLAG_NONE)); 420 MOJO_READ_MESSAGE_FLAG_NONE));
498 const char kHello[] = "hello"; 421 const char kHello[] = "hello";
499 EXPECT_EQ(sizeof(kHello), num_bytes); 422 EXPECT_EQ(sizeof(kHello), num_bytes);
500 EXPECT_STREQ(kHello, buffer); 423 EXPECT_STREQ(kHello, buffer);
501 424
502 // 2. Write a message to |client_mp| (attaching nothing). 425 // 2. Write a message to |client_mp| (attaching nothing).
503 const char kWorld[] = "world!"; 426 const char kWorld[] = "world!";
504 EXPECT_EQ(MOJO_RESULT_OK, 427 EXPECT_EQ(MOJO_RESULT_OK,
505 MojoWriteMessage(client_mp, 428 MojoWriteMessage(client_mp, kWorld,
506 kWorld, 429 static_cast<uint32_t>(sizeof(kWorld)), nullptr,
507 static_cast<uint32_t>(sizeof(kWorld)), 430 0, MOJO_WRITE_MESSAGE_FLAG_NONE));
508 nullptr,
509 0,
510 MOJO_WRITE_MESSAGE_FLAG_NONE));
511 431
512 // 4. Read a message from |client_mp|, which should have |mp1| attached. 432 // 4. Read a message from |client_mp|, which should have |mp1| attached.
513 EXPECT_EQ( 433 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(client_mp, MOJO_HANDLE_SIGNAL_READABLE,
514 MOJO_RESULT_OK, 434 MOJO_DEADLINE_INDEFINITE));
515 MojoWait(
516 client_mp, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE));
517 // TODO(vtl): If the scope were to end here (and |client_mp| closed), we'd 435 // TODO(vtl): If the scope were to end here (and |client_mp| closed), we'd
518 // die (again due to |Channel::HandleLocalError()|). 436 // die (again due to |Channel::HandleLocalError()|).
519 memset(buffer, 0, sizeof(buffer)); 437 memset(buffer, 0, sizeof(buffer));
520 num_bytes = static_cast<uint32_t>(sizeof(buffer)); 438 num_bytes = static_cast<uint32_t>(sizeof(buffer));
521 MojoHandle mp1 = MOJO_HANDLE_INVALID; 439 MojoHandle mp1 = MOJO_HANDLE_INVALID;
522 uint32_t num_handles = 1; 440 uint32_t num_handles = 1;
523 EXPECT_EQ(MOJO_RESULT_OK, 441 EXPECT_EQ(MOJO_RESULT_OK,
524 MojoReadMessage(client_mp, 442 MojoReadMessage(client_mp, buffer, &num_bytes, &mp1, &num_handles,
525 buffer,
526 &num_bytes,
527 &mp1,
528 &num_handles,
529 MOJO_READ_MESSAGE_FLAG_NONE)); 443 MOJO_READ_MESSAGE_FLAG_NONE));
530 const char kBar[] = "Bar"; 444 const char kBar[] = "Bar";
531 EXPECT_EQ(sizeof(kBar), num_bytes); 445 EXPECT_EQ(sizeof(kBar), num_bytes);
532 EXPECT_STREQ(kBar, buffer); 446 EXPECT_STREQ(kBar, buffer);
533 EXPECT_EQ(1u, num_handles); 447 EXPECT_EQ(1u, num_handles);
534 EXPECT_NE(mp1, MOJO_HANDLE_INVALID); 448 EXPECT_NE(mp1, MOJO_HANDLE_INVALID);
535 // TODO(vtl): If the scope were to end here (and the two handles closed), 449 // TODO(vtl): If the scope were to end here (and the two handles closed),
536 // we'd die due to |Channel::RunRemoteMessagePipeEndpoint()| not handling 450 // we'd die due to |Channel::RunRemoteMessagePipeEndpoint()| not handling
537 // write errors (assuming the parent had closed the pipe). 451 // write errors (assuming the parent had closed the pipe).
538 452
539 // 6. Close |client_mp|. 453 // 6. Close |client_mp|.
540 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(client_mp)); 454 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(client_mp));
541 455
542 // Create a new message pipe (endpoints |mp2| and |mp3|). 456 // Create a new message pipe (endpoints |mp2| and |mp3|).
543 MojoHandle mp2, mp3; 457 MojoHandle mp2, mp3;
544 EXPECT_EQ(MOJO_RESULT_OK, MojoCreateMessagePipe(nullptr, &mp2, &mp3)); 458 EXPECT_EQ(MOJO_RESULT_OK, MojoCreateMessagePipe(nullptr, &mp2, &mp3));
545 459
546 // 7. Write a message to |mp3|. 460 // 7. Write a message to |mp3|.
547 const char kBaz[] = "baz"; 461 const char kBaz[] = "baz";
548 EXPECT_EQ(MOJO_RESULT_OK, 462 EXPECT_EQ(MOJO_RESULT_OK,
549 MojoWriteMessage(mp3, 463 MojoWriteMessage(mp3, kBaz, static_cast<uint32_t>(sizeof(kBaz)),
550 kBaz, 464 nullptr, 0, MOJO_WRITE_MESSAGE_FLAG_NONE));
551 static_cast<uint32_t>(sizeof(kBaz)),
552 nullptr,
553 0,
554 MOJO_WRITE_MESSAGE_FLAG_NONE));
555 465
556 // 8. Close |mp3|. 466 // 8. Close |mp3|.
557 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(mp3)); 467 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(mp3));
558 468
559 // 9. Write a message to |mp1|, attaching |mp2|. 469 // 9. Write a message to |mp1|, attaching |mp2|.
560 const char kQuux[] = "quux"; 470 const char kQuux[] = "quux";
561 EXPECT_EQ(MOJO_RESULT_OK, 471 EXPECT_EQ(MOJO_RESULT_OK,
562 MojoWriteMessage(mp1, 472 MojoWriteMessage(mp1, kQuux, static_cast<uint32_t>(sizeof(kQuux)),
563 kQuux, 473 &mp2, 1, MOJO_WRITE_MESSAGE_FLAG_NONE));
564 static_cast<uint32_t>(sizeof(kQuux)),
565 &mp2,
566 1,
567 MOJO_WRITE_MESSAGE_FLAG_NONE));
568 mp2 = MOJO_HANDLE_INVALID; 474 mp2 = MOJO_HANDLE_INVALID;
569 475
570 // 3. Read a message from |mp1|. 476 // 3. Read a message from |mp1|.
571 EXPECT_EQ( 477 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(mp1, MOJO_HANDLE_SIGNAL_READABLE,
572 MOJO_RESULT_OK, 478 MOJO_DEADLINE_INDEFINITE));
573 MojoWait(mp1, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE));
574 memset(buffer, 0, sizeof(buffer)); 479 memset(buffer, 0, sizeof(buffer));
575 num_bytes = static_cast<uint32_t>(sizeof(buffer)); 480 num_bytes = static_cast<uint32_t>(sizeof(buffer));
576 EXPECT_EQ(MOJO_RESULT_OK, 481 EXPECT_EQ(MOJO_RESULT_OK,
577 MojoReadMessage(mp1, 482 MojoReadMessage(mp1, buffer, &num_bytes, nullptr, nullptr,
578 buffer,
579 &num_bytes,
580 nullptr,
581 nullptr,
582 MOJO_READ_MESSAGE_FLAG_NONE)); 483 MOJO_READ_MESSAGE_FLAG_NONE));
583 const char kFoo[] = "FOO"; 484 const char kFoo[] = "FOO";
584 EXPECT_EQ(sizeof(kFoo), num_bytes); 485 EXPECT_EQ(sizeof(kFoo), num_bytes);
585 EXPECT_STREQ(kFoo, buffer); 486 EXPECT_STREQ(kFoo, buffer);
586 487
587 // 11. Wait on |mp1| (which should eventually fail) and then close it. 488 // 11. Wait on |mp1| (which should eventually fail) and then close it.
588 EXPECT_EQ( 489 EXPECT_EQ(
589 MOJO_RESULT_FAILED_PRECONDITION, 490 MOJO_RESULT_FAILED_PRECONDITION,
590 MojoWait(mp1, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE)); 491 MojoWait(mp1, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE));
591 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(mp1)); 492 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(mp1));
592 } 493 }
593 494
594 EXPECT_TRUE(test::Shutdown()); 495 EXPECT_TRUE(test::Shutdown());
595 } 496 }
596 497
597 // TODO(vtl): Test immediate write & close. 498 // TODO(vtl): Test immediate write & close.
598 // TODO(vtl): Test broken-connection cases. 499 // TODO(vtl): Test broken-connection cases.
599 500
600 } // namespace 501 } // namespace
601 } // namespace embedder 502 } // namespace embedder
602 } // namespace mojo 503 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/embedder/embedder_internal.h ('k') | mojo/edk/embedder/entrypoints.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698