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

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

Issue 1993983002: EDK: Add Core::GetRights(). (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 7 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 26 matching lines...) Expand all
37 } 37 }
38 38
39 TEST_F(CoreTest, Basic) { 39 TEST_F(CoreTest, Basic) {
40 MockHandleInfo info; 40 MockHandleInfo info;
41 41
42 EXPECT_EQ(0u, info.GetCtorCallCount()); 42 EXPECT_EQ(0u, info.GetCtorCallCount());
43 MojoHandle h = CreateMockHandle(&info); 43 MojoHandle h = CreateMockHandle(&info);
44 EXPECT_EQ(1u, info.GetCtorCallCount()); 44 EXPECT_EQ(1u, info.GetCtorCallCount());
45 EXPECT_NE(h, MOJO_HANDLE_INVALID); 45 EXPECT_NE(h, MOJO_HANDLE_INVALID);
46 46
47 MojoHandleRights rights = 0;
48 EXPECT_EQ(MOJO_RESULT_OK, core()->GetRights(h, MakeUserPointer(&rights)));
49 EXPECT_EQ(kDefaultMockHandleRights, rights);
50
47 EXPECT_EQ(0u, info.GetWriteMessageCallCount()); 51 EXPECT_EQ(0u, info.GetWriteMessageCallCount());
48 EXPECT_EQ(MOJO_RESULT_OK, 52 EXPECT_EQ(MOJO_RESULT_OK,
49 core()->WriteMessage(h, NullUserPointer(), 0, NullUserPointer(), 0, 53 core()->WriteMessage(h, NullUserPointer(), 0, NullUserPointer(), 0,
50 MOJO_WRITE_MESSAGE_FLAG_NONE)); 54 MOJO_WRITE_MESSAGE_FLAG_NONE));
51 EXPECT_EQ(1u, info.GetWriteMessageCallCount()); 55 EXPECT_EQ(1u, info.GetWriteMessageCallCount());
52 56
53 EXPECT_EQ(0u, info.GetReadMessageCallCount()); 57 EXPECT_EQ(0u, info.GetReadMessageCallCount());
54 uint32_t num_bytes = 0; 58 uint32_t num_bytes = 0;
55 EXPECT_EQ( 59 EXPECT_EQ(
56 MOJO_RESULT_OK, 60 MOJO_RESULT_OK,
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 201
198 // Test a double-close. 202 // Test a double-close.
199 MockHandleInfo info; 203 MockHandleInfo info;
200 MojoHandle h = CreateMockHandle(&info); 204 MojoHandle h = CreateMockHandle(&info);
201 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h)); 205 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h));
202 EXPECT_EQ(1u, info.GetCloseCallCount()); 206 EXPECT_EQ(1u, info.GetCloseCallCount());
203 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, core()->Close(h)); 207 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, core()->Close(h));
204 EXPECT_EQ(1u, info.GetCloseCallCount()); 208 EXPECT_EQ(1u, info.GetCloseCallCount());
205 } 209 }
206 210
211 // |GetRights()|:
212 {
213 MojoHandleRights rights = 0;
214 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
215 core()->GetRights(MOJO_HANDLE_INVALID, MakeUserPointer(&rights)));
216 EXPECT_EQ(0u, rights);
217 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
218 core()->GetRights(10, MakeUserPointer(&rights)));
219 EXPECT_EQ(0u, rights);
220 }
221
207 // |Wait()|: 222 // |Wait()|:
208 { 223 {
209 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 224 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
210 core()->Wait(MOJO_HANDLE_INVALID, ~MOJO_HANDLE_SIGNAL_NONE, 225 core()->Wait(MOJO_HANDLE_INVALID, ~MOJO_HANDLE_SIGNAL_NONE,
211 MOJO_DEADLINE_INDEFINITE, NullUserPointer())); 226 MOJO_DEADLINE_INDEFINITE, NullUserPointer()));
212 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 227 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
213 core()->Wait(10, ~MOJO_HANDLE_SIGNAL_NONE, 228 core()->Wait(10, ~MOJO_HANDLE_SIGNAL_NONE,
214 MOJO_DEADLINE_INDEFINITE, NullUserPointer())); 229 MOJO_DEADLINE_INDEFINITE, NullUserPointer()));
215 230
216 MojoHandleSignalsState hss = kFullMojoHandleSignalsState; 231 MojoHandleSignalsState hss = kFullMojoHandleSignalsState;
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 564
550 // These test invalid arguments that should cause death if we're being paranoid 565 // These test invalid arguments that should cause death if we're being paranoid
551 // about checking arguments (which we would want to do if, e.g., we were in a 566 // about checking arguments (which we would want to do if, e.g., we were in a
552 // true "kernel" situation, but we might not want to do otherwise for 567 // true "kernel" situation, but we might not want to do otherwise for
553 // performance reasons). Probably blatant errors like passing in null pointers 568 // performance reasons). Probably blatant errors like passing in null pointers
554 // (for required pointer arguments) will still cause death, but perhaps not 569 // (for required pointer arguments) will still cause death, but perhaps not
555 // predictably. 570 // predictably.
556 TEST_F(CoreTest, InvalidArgumentsDeath) { 571 TEST_F(CoreTest, InvalidArgumentsDeath) {
557 const char kMemoryCheckFailedRegex[] = "Check failed"; 572 const char kMemoryCheckFailedRegex[] = "Check failed";
558 573
574 // |GetRights()|:
575 {
576 MockHandleInfo info;
577 MojoHandle h = CreateMockHandle(&info);
578 EXPECT_DEATH_IF_SUPPORTED(core()->GetRights(h, NullUserPointer()),
579 kMemoryCheckFailedRegex);
580
581 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h));
582 }
583
559 // |WaitMany()|: 584 // |WaitMany()|:
560 { 585 {
561 MojoHandle handle = MOJO_HANDLE_INVALID; 586 MojoHandle handle = MOJO_HANDLE_INVALID;
562 MojoHandleSignals signals = ~MOJO_HANDLE_SIGNAL_NONE; 587 MojoHandleSignals signals = ~MOJO_HANDLE_SIGNAL_NONE;
563 EXPECT_DEATH_IF_SUPPORTED( 588 EXPECT_DEATH_IF_SUPPORTED(
564 core()->WaitMany(NullUserPointer(), MakeUserPointer(&signals), 1, 589 core()->WaitMany(NullUserPointer(), MakeUserPointer(&signals), 1,
565 MOJO_DEADLINE_INDEFINITE, NullUserPointer(), 590 MOJO_DEADLINE_INDEFINITE, NullUserPointer(),
566 NullUserPointer()), 591 NullUserPointer()),
567 kMemoryCheckFailedRegex); 592 kMemoryCheckFailedRegex);
568 EXPECT_DEATH_IF_SUPPORTED( 593 EXPECT_DEATH_IF_SUPPORTED(
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 } 650 }
626 651
627 // TODO(vtl): Missing a bunch here. 652 // TODO(vtl): Missing a bunch here.
628 } 653 }
629 654
630 // TODO(vtl): test |Wait()| and |WaitMany()| properly 655 // TODO(vtl): test |Wait()| and |WaitMany()| properly
631 // - including |WaitMany()| with the same handle more than once (with 656 // - including |WaitMany()| with the same handle more than once (with
632 // same/different signals) 657 // same/different signals)
633 658
634 TEST_F(CoreTest, MessagePipe) { 659 TEST_F(CoreTest, MessagePipe) {
635 MojoHandle h[2]; 660 MojoHandle h[2] = {MOJO_HANDLE_INVALID, MOJO_HANDLE_INVALID};
636 MojoHandleSignalsState hss[2]; 661 MojoHandleSignalsState hss[2];
637 uint32_t result_index; 662 uint32_t result_index;
638 663
639 EXPECT_EQ(MOJO_RESULT_OK, 664 EXPECT_EQ(MOJO_RESULT_OK,
640 core()->CreateMessagePipe(NullUserPointer(), MakeUserPointer(&h[0]), 665 core()->CreateMessagePipe(NullUserPointer(), MakeUserPointer(&h[0]),
641 MakeUserPointer(&h[1]))); 666 MakeUserPointer(&h[1])));
642 // Should get two distinct, valid handles. 667 // Should get two distinct, valid handles.
643 EXPECT_NE(h[0], MOJO_HANDLE_INVALID); 668 EXPECT_NE(h[0], MOJO_HANDLE_INVALID);
644 EXPECT_NE(h[1], MOJO_HANDLE_INVALID); 669 EXPECT_NE(h[1], MOJO_HANDLE_INVALID);
645 EXPECT_NE(h[0], h[1]); 670 EXPECT_NE(h[0], h[1]);
646 671
672 // Both should have the correct rights.
673 static const MojoHandleRights kMessagePipeHandleRights =
674 MOJO_HANDLE_RIGHT_TRANSFER | MOJO_HANDLE_RIGHT_READ |
675 MOJO_HANDLE_RIGHT_WRITE | MOJO_HANDLE_RIGHT_GET_OPTIONS |
676 MOJO_HANDLE_RIGHT_SET_OPTIONS;
677 MojoHandleRights rights = MOJO_HANDLE_RIGHT_NONE;
678 EXPECT_EQ(MOJO_RESULT_OK, core()->GetRights(h[0], MakeUserPointer(&rights)));
679 EXPECT_EQ(kMessagePipeHandleRights, rights);
680 rights = MOJO_HANDLE_RIGHT_NONE;
681 EXPECT_EQ(MOJO_RESULT_OK, core()->GetRights(h[1], MakeUserPointer(&rights)));
682 EXPECT_EQ(kMessagePipeHandleRights, rights);
683
647 // Neither should be readable. 684 // Neither should be readable.
648 MojoHandleSignals signals[2] = {MOJO_HANDLE_SIGNAL_READABLE, 685 MojoHandleSignals signals[2] = {MOJO_HANDLE_SIGNAL_READABLE,
649 MOJO_HANDLE_SIGNAL_READABLE}; 686 MOJO_HANDLE_SIGNAL_READABLE};
650 result_index = static_cast<uint32_t>(-1); 687 result_index = static_cast<uint32_t>(-1);
651 hss[0] = kEmptyMojoHandleSignalsState; 688 hss[0] = kEmptyMojoHandleSignalsState;
652 hss[1] = kEmptyMojoHandleSignalsState; 689 hss[1] = kEmptyMojoHandleSignalsState;
653 EXPECT_EQ( 690 EXPECT_EQ(
654 MOJO_RESULT_DEADLINE_EXCEEDED, 691 MOJO_RESULT_DEADLINE_EXCEEDED,
655 core()->WaitMany(MakeUserPointer(h), MakeUserPointer(signals), 2, 0, 692 core()->WaitMany(MakeUserPointer(h), MakeUserPointer(signals), 2, 0,
656 MakeUserPointer(&result_index), MakeUserPointer(hss))); 693 MakeUserPointer(&result_index), MakeUserPointer(hss)));
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
969 EXPECT_STREQ(kHello, buffer); 1006 EXPECT_STREQ(kHello, buffer);
970 EXPECT_EQ(0u, num_handles); 1007 EXPECT_EQ(0u, num_handles);
971 1008
972 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h_passing[0])); 1009 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h_passing[0]));
973 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h_passing[1])); 1010 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h_passing[1]));
974 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h_passed[0])); 1011 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h_passed[0]));
975 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h_received)); 1012 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h_received));
976 } 1013 }
977 1014
978 TEST_F(CoreTest, DataPipe) { 1015 TEST_F(CoreTest, DataPipe) {
979 MojoHandle ph, ch; // p is for producer and c is for consumer. 1016 // p is for producer and c is for consumer.
1017 MojoHandle ph = MOJO_HANDLE_INVALID;
1018 MojoHandle ch = MOJO_HANDLE_INVALID;
980 MojoHandleSignalsState hss; 1019 MojoHandleSignalsState hss;
981 1020
982 EXPECT_EQ(MOJO_RESULT_OK, 1021 EXPECT_EQ(MOJO_RESULT_OK,
983 core()->CreateDataPipe(NullUserPointer(), MakeUserPointer(&ph), 1022 core()->CreateDataPipe(NullUserPointer(), MakeUserPointer(&ph),
984 MakeUserPointer(&ch))); 1023 MakeUserPointer(&ch)));
985 // Should get two distinct, valid handles. 1024 // Should get two distinct, valid handles.
986 EXPECT_NE(ph, MOJO_HANDLE_INVALID); 1025 EXPECT_NE(ph, MOJO_HANDLE_INVALID);
987 EXPECT_NE(ch, MOJO_HANDLE_INVALID); 1026 EXPECT_NE(ch, MOJO_HANDLE_INVALID);
988 EXPECT_NE(ph, ch); 1027 EXPECT_NE(ph, ch);
989 1028
1029 // Both should have the correct rights.
1030 static const MojoHandleRights kDataPipeProducerHandleRights =
1031 MOJO_HANDLE_RIGHT_TRANSFER | MOJO_HANDLE_RIGHT_WRITE |
1032 MOJO_HANDLE_RIGHT_GET_OPTIONS | MOJO_HANDLE_RIGHT_SET_OPTIONS;
1033 static const MojoHandleRights kDataPipeConsumerHandleRights =
1034 MOJO_HANDLE_RIGHT_TRANSFER | MOJO_HANDLE_RIGHT_READ |
1035 MOJO_HANDLE_RIGHT_GET_OPTIONS | MOJO_HANDLE_RIGHT_SET_OPTIONS;
1036 MojoHandleRights rights = MOJO_HANDLE_RIGHT_NONE;
1037 EXPECT_EQ(MOJO_RESULT_OK, core()->GetRights(ph, MakeUserPointer(&rights)));
1038 EXPECT_EQ(kDataPipeProducerHandleRights, rights);
1039 rights = MOJO_HANDLE_RIGHT_NONE;
1040 EXPECT_EQ(MOJO_RESULT_OK, core()->GetRights(ch, MakeUserPointer(&rights)));
1041 EXPECT_EQ(kDataPipeConsumerHandleRights, rights);
1042
990 // Producer should be never-readable, but already writable. 1043 // Producer should be never-readable, but already writable.
991 hss = kEmptyMojoHandleSignalsState; 1044 hss = kEmptyMojoHandleSignalsState;
992 EXPECT_EQ( 1045 EXPECT_EQ(
993 MOJO_RESULT_FAILED_PRECONDITION, 1046 MOJO_RESULT_FAILED_PRECONDITION,
994 core()->Wait(ph, MOJO_HANDLE_SIGNAL_READABLE, 0, MakeUserPointer(&hss))); 1047 core()->Wait(ph, MOJO_HANDLE_SIGNAL_READABLE, 0, MakeUserPointer(&hss)));
995 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE | MOJO_HANDLE_SIGNAL_WRITE_THRESHOLD, 1048 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE | MOJO_HANDLE_SIGNAL_WRITE_THRESHOLD,
996 hss.satisfied_signals); 1049 hss.satisfied_signals);
997 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED | 1050 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED |
998 MOJO_HANDLE_SIGNAL_WRITE_THRESHOLD, 1051 MOJO_HANDLE_SIGNAL_WRITE_THRESHOLD,
999 hss.satisfiable_signals); 1052 hss.satisfiable_signals);
(...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after
1674 waiter.Awake(result); 1727 waiter.Awake(result);
1675 })); 1728 }));
1676 EXPECT_EQ(1u, info.GetAddedAwakableSize()); 1729 EXPECT_EQ(1u, info.GetAddedAwakableSize());
1677 1730
1678 EXPECT_FALSE(info.GetAddedAwakableAt(0)->Awake(MOJO_RESULT_BUSY, 0)); 1731 EXPECT_FALSE(info.GetAddedAwakableAt(0)->Awake(MOJO_RESULT_BUSY, 0));
1679 EXPECT_EQ(MOJO_RESULT_BUSY, waiter.result); 1732 EXPECT_EQ(MOJO_RESULT_BUSY, waiter.result);
1680 1733
1681 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h)); 1734 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h));
1682 } 1735 }
1683 1736
1684 // TODO(vtl): Test |DuplicateBufferHandle()| and |MapBuffer()|. 1737 // TODO(vtl): Test |CreateSharedBuffer()|, |DuplicateBufferHandle()|, and
1738 // |MapBuffer()|.
1685 1739
1686 } // namespace 1740 } // namespace
1687 } // namespace system 1741 } // namespace system
1688 } // namespace mojo 1742 } // 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