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

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

Issue 1781513002: Implement MojoGetBufferInformation(), part 2. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 9 months 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/system/core_test_base.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "mojo/edk/system/core.h" 5 #include "mojo/edk/system/core.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <limits> 9 #include <limits>
10 10
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 EXPECT_EQ(0u, info.GetBeginReadDataCallCount()); 92 EXPECT_EQ(0u, info.GetBeginReadDataCallCount());
93 EXPECT_EQ(MOJO_RESULT_UNIMPLEMENTED, 93 EXPECT_EQ(MOJO_RESULT_UNIMPLEMENTED,
94 core()->BeginReadData(h, NullUserPointer(), NullUserPointer(), 94 core()->BeginReadData(h, NullUserPointer(), NullUserPointer(),
95 MOJO_READ_DATA_FLAG_NONE)); 95 MOJO_READ_DATA_FLAG_NONE));
96 EXPECT_EQ(1u, info.GetBeginReadDataCallCount()); 96 EXPECT_EQ(1u, info.GetBeginReadDataCallCount());
97 97
98 EXPECT_EQ(0u, info.GetEndReadDataCallCount()); 98 EXPECT_EQ(0u, info.GetEndReadDataCallCount());
99 EXPECT_EQ(MOJO_RESULT_UNIMPLEMENTED, core()->EndReadData(h, 0)); 99 EXPECT_EQ(MOJO_RESULT_UNIMPLEMENTED, core()->EndReadData(h, 0));
100 EXPECT_EQ(1u, info.GetEndReadDataCallCount()); 100 EXPECT_EQ(1u, info.GetEndReadDataCallCount());
101 101
102 EXPECT_EQ(0u, info.GetDuplicateBufferHandleCallCount());
103 EXPECT_EQ(
104 MOJO_RESULT_UNIMPLEMENTED,
105 core()->DuplicateBufferHandle(h, NullUserPointer(), NullUserPointer()));
106 EXPECT_EQ(1u, info.GetDuplicateBufferHandleCallCount());
107
108 EXPECT_EQ(0u, info.GetGetBufferInformationCallCount());
109 EXPECT_EQ(MOJO_RESULT_UNIMPLEMENTED,
110 core()->GetBufferInformation(h, NullUserPointer(), 0));
111 EXPECT_EQ(1u, info.GetGetBufferInformationCallCount());
112
113 EXPECT_EQ(0u, info.GetMapBufferCallCount());
114 EXPECT_EQ(
115 MOJO_RESULT_UNIMPLEMENTED,
116 core()->MapBuffer(h, 0, 0, NullUserPointer(), MOJO_MAP_BUFFER_FLAG_NONE));
117 EXPECT_EQ(1u, info.GetMapBufferCallCount());
118
102 EXPECT_EQ(0u, info.GetAddAwakableCallCount()); 119 EXPECT_EQ(0u, info.GetAddAwakableCallCount());
103 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, 120 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
104 core()->Wait(h, ~MOJO_HANDLE_SIGNAL_NONE, MOJO_DEADLINE_INDEFINITE, 121 core()->Wait(h, ~MOJO_HANDLE_SIGNAL_NONE, MOJO_DEADLINE_INDEFINITE,
105 NullUserPointer())); 122 NullUserPointer()));
106 EXPECT_EQ(1u, info.GetAddAwakableCallCount()); 123 EXPECT_EQ(1u, info.GetAddAwakableCallCount());
107 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, 124 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
108 core()->Wait(h, ~MOJO_HANDLE_SIGNAL_NONE, 0, NullUserPointer())); 125 core()->Wait(h, ~MOJO_HANDLE_SIGNAL_NONE, 0, NullUserPointer()));
109 EXPECT_EQ(2u, info.GetAddAwakableCallCount()); 126 EXPECT_EQ(2u, info.GetAddAwakableCallCount());
110 MojoHandleSignalsState hss = kFullMojoHandleSignalsState; 127 MojoHandleSignalsState hss = kFullMojoHandleSignalsState;
111 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, 128 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 MOJO_DEADLINE_INDEFINITE, NullUserPointer(), 330 MOJO_DEADLINE_INDEFINITE, NullUserPointer(),
314 NullUserPointer())); 331 NullUserPointer()));
315 332
316 // TODO(vtl): Test one where we get "failed precondition" only for the 333 // TODO(vtl): Test one where we get "failed precondition" only for the
317 // second handle (and the first one is valid to wait on). 334 // second handle (and the first one is valid to wait on).
318 335
319 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(handles[0])); 336 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(handles[0]));
320 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(handles[1])); 337 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(handles[1]));
321 } 338 }
322 339
323 // |CreateMessagePipe()|: Nothing to check (apart from things that cause 340 // |CreateMessagePipe()|:
324 // death). 341 {
342 // Invalid options: unknown flag.
343 const MojoCreateMessagePipeOptions kOptions = {
344 static_cast<uint32_t>(sizeof(MojoCreateMessagePipeOptions)),
345 ~MOJO_CREATE_MESSAGE_PIPE_OPTIONS_FLAG_NONE};
346 MojoHandle handles[2] = {MOJO_HANDLE_INVALID, MOJO_HANDLE_INVALID};
347 EXPECT_EQ(MOJO_RESULT_UNIMPLEMENTED,
348 core()->CreateMessagePipe(MakeUserPointer(&kOptions),
349 MakeUserPointer(&handles[0]),
350 MakeUserPointer(&handles[1])));
351 EXPECT_EQ(MOJO_HANDLE_INVALID, handles[0]);
352 EXPECT_EQ(MOJO_HANDLE_INVALID, handles[1]);
353 }
325 354
326 // |WriteMessage()|: 355 // |WriteMessage()|:
327 // Only check arguments checked by |Core|, namely |handle|, |handles|, and 356 // Only check arguments checked by |Core|, namely |handle|, |handles|, and
328 // |num_handles|. 357 // |num_handles|.
329 { 358 {
330 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 359 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
331 core()->WriteMessage(MOJO_HANDLE_INVALID, NullUserPointer(), 0, 360 core()->WriteMessage(MOJO_HANDLE_INVALID, NullUserPointer(), 0,
332 NullUserPointer(), 0, 361 NullUserPointer(), 0,
333 MOJO_WRITE_MESSAGE_FLAG_NONE)); 362 MOJO_WRITE_MESSAGE_FLAG_NONE));
334 363
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 uint32_t handle_count = 0; 465 uint32_t handle_count = 0;
437 EXPECT_EQ(MOJO_RESULT_OK, 466 EXPECT_EQ(MOJO_RESULT_OK,
438 core()->ReadMessage( 467 core()->ReadMessage(
439 h, NullUserPointer(), NullUserPointer(), NullUserPointer(), 468 h, NullUserPointer(), NullUserPointer(), NullUserPointer(),
440 MakeUserPointer(&handle_count), MOJO_READ_MESSAGE_FLAG_NONE)); 469 MakeUserPointer(&handle_count), MOJO_READ_MESSAGE_FLAG_NONE));
441 // Checked by |Core|, shouldn't go through to the dispatcher. 470 // Checked by |Core|, shouldn't go through to the dispatcher.
442 EXPECT_EQ(1u, info.GetReadMessageCallCount()); 471 EXPECT_EQ(1u, info.GetReadMessageCallCount());
443 472
444 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h)); 473 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h));
445 } 474 }
475
476 // |CreateDataPipe()|:
477 {
478 // Invalid options: unknown flag.
479 const MojoCreateDataPipeOptions kOptions = {
480 static_cast<uint32_t>(sizeof(MojoCreateDataPipeOptions)),
481 ~MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, 1u, 0u};
482 MojoHandle handles[2] = {MOJO_HANDLE_INVALID, MOJO_HANDLE_INVALID};
483 EXPECT_EQ(MOJO_RESULT_UNIMPLEMENTED,
484 core()->CreateDataPipe(MakeUserPointer(&kOptions),
485 MakeUserPointer(&handles[0]),
486 MakeUserPointer(&handles[1])));
487 EXPECT_EQ(MOJO_HANDLE_INVALID, handles[0]);
488 EXPECT_EQ(MOJO_HANDLE_INVALID, handles[1]);
489 }
490
491 // |WriteData()|:
492 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
493 core()->WriteData(MOJO_HANDLE_INVALID, NullUserPointer(),
494 NullUserPointer(), MOJO_WRITE_DATA_FLAG_NONE));
495
496 // |BeginWriteData()|:
497 EXPECT_EQ(
498 MOJO_RESULT_INVALID_ARGUMENT,
499 core()->BeginWriteData(MOJO_HANDLE_INVALID, NullUserPointer(),
500 NullUserPointer(), MOJO_WRITE_DATA_FLAG_NONE));
501
502 // |EndWriteData()|:
503 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
504 core()->EndWriteData(MOJO_HANDLE_INVALID, 0u));
505
506 // |ReadData()|:
507 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
508 core()->ReadData(MOJO_HANDLE_INVALID, NullUserPointer(),
509 NullUserPointer(), MOJO_READ_DATA_FLAG_NONE));
510
511 // |BeginReadData()|:
512 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
513 core()->BeginReadData(MOJO_HANDLE_INVALID, NullUserPointer(),
514 NullUserPointer(), MOJO_READ_DATA_FLAG_NONE));
515
516 // |EndReadData()|:
517 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
518 core()->EndReadData(MOJO_HANDLE_INVALID, 0u));
519
520 // |CreateSharedBuffer()|:
521 {
522 // Invalid options: unknown flag.
523 const MojoCreateSharedBufferOptions kOptions = {
524 static_cast<uint32_t>(sizeof(MojoCreateSharedBufferOptions)),
525 ~MOJO_CREATE_SHARED_BUFFER_OPTIONS_FLAG_NONE};
526 MojoHandle handle = MOJO_HANDLE_INVALID;
527 EXPECT_EQ(MOJO_RESULT_UNIMPLEMENTED,
528 core()->CreateSharedBuffer(MakeUserPointer(&kOptions), 4096u,
529 MakeUserPointer(&handle)));
530 EXPECT_EQ(MOJO_HANDLE_INVALID, handle);
531 }
532
533 // |DuplicateBufferHandle()|:
534 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
535 core()->DuplicateBufferHandle(
536 MOJO_HANDLE_INVALID, NullUserPointer(), NullUserPointer()));
537
538 // |GetBufferInformation()|:
539 EXPECT_EQ(
540 MOJO_RESULT_INVALID_ARGUMENT,
541 core()->GetBufferInformation(MOJO_HANDLE_INVALID, NullUserPointer(), 0u));
542
543 // |MapBuffer()|:
544 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
545 core()->MapBuffer(MOJO_HANDLE_INVALID, 0u, 0u, NullUserPointer(),
546 MOJO_MAP_BUFFER_FLAG_NONE));
547
548 // |UnmapBuffer()|:
549 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
550 core()->UnmapBuffer(NullUserPointer()));
446 } 551 }
447 552
448 // These test invalid arguments that should cause death if we're being paranoid 553 // These test invalid arguments that should cause death if we're being paranoid
449 // about checking arguments (which we would want to do if, e.g., we were in a 554 // about checking arguments (which we would want to do if, e.g., we were in a
450 // true "kernel" situation, but we might not want to do otherwise for 555 // true "kernel" situation, but we might not want to do otherwise for
451 // performance reasons). Probably blatant errors like passing in null pointers 556 // performance reasons). Probably blatant errors like passing in null pointers
452 // (for required pointer arguments) will still cause death, but perhaps not 557 // (for required pointer arguments) will still cause death, but perhaps not
453 // predictably. 558 // predictably.
454 TEST_F(CoreTest, InvalidArgumentsDeath) { 559 TEST_F(CoreTest, InvalidArgumentsDeath) {
455 const char kMemoryCheckFailedRegex[] = "Check failed"; 560 const char kMemoryCheckFailedRegex[] = "Check failed";
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 619
515 uint32_t handle_count = 1; 620 uint32_t handle_count = 1;
516 EXPECT_DEATH_IF_SUPPORTED( 621 EXPECT_DEATH_IF_SUPPORTED(
517 core()->ReadMessage(h, NullUserPointer(), NullUserPointer(), 622 core()->ReadMessage(h, NullUserPointer(), NullUserPointer(),
518 NullUserPointer(), MakeUserPointer(&handle_count), 623 NullUserPointer(), MakeUserPointer(&handle_count),
519 MOJO_READ_MESSAGE_FLAG_NONE), 624 MOJO_READ_MESSAGE_FLAG_NONE),
520 kMemoryCheckFailedRegex); 625 kMemoryCheckFailedRegex);
521 626
522 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h)); 627 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h));
523 } 628 }
629
630 // TODO(vtl): Missing a bunch here.
524 } 631 }
525 632
526 // TODO(vtl): test |Wait()| and |WaitMany()| properly 633 // TODO(vtl): test |Wait()| and |WaitMany()| properly
527 // - including |WaitMany()| with the same handle more than once (with 634 // - including |WaitMany()| with the same handle more than once (with
528 // same/different signals) 635 // same/different signals)
529 636
530 TEST_F(CoreTest, MessagePipe) { 637 TEST_F(CoreTest, MessagePipe) {
531 MojoHandle h[2]; 638 MojoHandle h[2];
532 MojoHandleSignalsState hss[2]; 639 MojoHandleSignalsState hss[2];
533 uint32_t result_index; 640 uint32_t result_index;
(...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after
1310 EXPECT_EQ(MOJO_RESULT_BUSY, waiter.result); 1417 EXPECT_EQ(MOJO_RESULT_BUSY, waiter.result);
1311 1418
1312 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h)); 1419 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h));
1313 } 1420 }
1314 1421
1315 // TODO(vtl): Test |DuplicateBufferHandle()| and |MapBuffer()|. 1422 // TODO(vtl): Test |DuplicateBufferHandle()| and |MapBuffer()|.
1316 1423
1317 } // namespace 1424 } // namespace
1318 } // namespace system 1425 } // namespace system
1319 } // namespace mojo 1426 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/core_test_base.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698