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

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

Issue 2100553002: Add Core methods for wait set. (Closed) Base URL: https://github.com/domokit/mojo.git@work790_wait_set_5.4
Patch Set: Created 4 years, 5 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') | mojo/edk/system/dispatcher.h » ('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 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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 EXPECT_EQ(MOJO_RESULT_UNIMPLEMENTED, 146 EXPECT_EQ(MOJO_RESULT_UNIMPLEMENTED,
147 core()->GetBufferInformation(h, NullUserPointer(), 0)); 147 core()->GetBufferInformation(h, NullUserPointer(), 0));
148 EXPECT_EQ(1u, info.GetGetBufferInformationCallCount()); 148 EXPECT_EQ(1u, info.GetGetBufferInformationCallCount());
149 149
150 EXPECT_EQ(0u, info.GetMapBufferCallCount()); 150 EXPECT_EQ(0u, info.GetMapBufferCallCount());
151 EXPECT_EQ( 151 EXPECT_EQ(
152 MOJO_RESULT_UNIMPLEMENTED, 152 MOJO_RESULT_UNIMPLEMENTED,
153 core()->MapBuffer(h, 0, 0, NullUserPointer(), MOJO_MAP_BUFFER_FLAG_NONE)); 153 core()->MapBuffer(h, 0, 0, NullUserPointer(), MOJO_MAP_BUFFER_FLAG_NONE));
154 EXPECT_EQ(1u, info.GetMapBufferCallCount()); 154 EXPECT_EQ(1u, info.GetMapBufferCallCount());
155 155
156 EXPECT_EQ(0u, info.GetWaitSetAddCallCount());
157 EXPECT_EQ(
158 MOJO_RESULT_UNIMPLEMENTED,
159 core()->WaitSetAdd(h, h, MOJO_HANDLE_SIGNAL_NONE, 0, NullUserPointer()));
160 EXPECT_EQ(1u, info.GetWaitSetAddCallCount());
161
162 EXPECT_EQ(0u, info.GetWaitSetRemoveCallCount());
163 EXPECT_EQ(MOJO_RESULT_UNIMPLEMENTED, core()->WaitSetRemove(h, 0));
164 EXPECT_EQ(1u, info.GetWaitSetRemoveCallCount());
165
166 EXPECT_EQ(0u, info.GetWaitSetWaitCallCount());
167 EXPECT_EQ(MOJO_RESULT_UNIMPLEMENTED,
168 core()->WaitSetWait(h, MOJO_DEADLINE_INDEFINITE, NullUserPointer(),
169 NullUserPointer(), NullUserPointer()));
170 EXPECT_EQ(1u, info.GetWaitSetWaitCallCount());
171
156 EXPECT_EQ(0u, info.GetAddAwakableCallCount()); 172 EXPECT_EQ(0u, info.GetAddAwakableCallCount());
157 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, 173 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
158 core()->Wait(h, ~MOJO_HANDLE_SIGNAL_NONE, MOJO_DEADLINE_INDEFINITE, 174 core()->Wait(h, ~MOJO_HANDLE_SIGNAL_NONE, MOJO_DEADLINE_INDEFINITE,
159 NullUserPointer())); 175 NullUserPointer()));
160 EXPECT_EQ(1u, info.GetAddAwakableCallCount()); 176 EXPECT_EQ(1u, info.GetAddAwakableCallCount());
161 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, 177 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
162 core()->Wait(h, ~MOJO_HANDLE_SIGNAL_NONE, 0, NullUserPointer())); 178 core()->Wait(h, ~MOJO_HANDLE_SIGNAL_NONE, 0, NullUserPointer()));
163 EXPECT_EQ(2u, info.GetAddAwakableCallCount()); 179 EXPECT_EQ(2u, info.GetAddAwakableCallCount());
164 MojoHandleSignalsState hss = kFullMojoHandleSignalsState; 180 MojoHandleSignalsState hss = kFullMojoHandleSignalsState;
165 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, 181 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 core()->GetBufferInformation(MOJO_HANDLE_INVALID, NullUserPointer(), 0u)); 653 core()->GetBufferInformation(MOJO_HANDLE_INVALID, NullUserPointer(), 0u));
638 654
639 // |MapBuffer()|: 655 // |MapBuffer()|:
640 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 656 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
641 core()->MapBuffer(MOJO_HANDLE_INVALID, 0u, 0u, NullUserPointer(), 657 core()->MapBuffer(MOJO_HANDLE_INVALID, 0u, 0u, NullUserPointer(),
642 MOJO_MAP_BUFFER_FLAG_NONE)); 658 MOJO_MAP_BUFFER_FLAG_NONE));
643 659
644 // |UnmapBuffer()|: 660 // |UnmapBuffer()|:
645 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 661 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
646 core()->UnmapBuffer(NullUserPointer())); 662 core()->UnmapBuffer(NullUserPointer()));
663
664 // |WaitSetAdd()|:
665 {
666 MockHandleInfo info;
667 MojoHandle h = CreateMockHandle(&info);
668
669 EXPECT_EQ(
670 MOJO_RESULT_INVALID_ARGUMENT,
671 core()->WaitSetAdd(MOJO_HANDLE_INVALID, MOJO_HANDLE_INVALID,
672 MOJO_HANDLE_SIGNAL_NONE, 0, NullUserPointer()));
673 EXPECT_EQ(
674 MOJO_RESULT_INVALID_ARGUMENT,
675 core()->WaitSetAdd(MOJO_HANDLE_INVALID, h, MOJO_HANDLE_SIGNAL_NONE, 0,
676 NullUserPointer()));
677 EXPECT_EQ(
678 MOJO_RESULT_INVALID_ARGUMENT,
679 core()->WaitSetAdd(h, MOJO_HANDLE_INVALID, MOJO_HANDLE_SIGNAL_NONE, 0,
680 NullUserPointer()));
681
682 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h));
683 }
684
685 // |WaitSetRemove()|:
686 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
687 core()->WaitSetRemove(MOJO_HANDLE_INVALID, 0));
688
689 // |WaitSetWait()|:
690 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
691 core()->WaitSetWait(MOJO_HANDLE_INVALID, MOJO_DEADLINE_INDEFINITE,
692 NullUserPointer(), NullUserPointer(),
693 NullUserPointer()));
647 } 694 }
648 695
649 // These test invalid arguments that should cause death if we're being paranoid 696 // These test invalid arguments that should cause death if we're being paranoid
650 // about checking arguments (which we would want to do if, e.g., we were in a 697 // about checking arguments (which we would want to do if, e.g., we were in a
651 // true "kernel" situation, but we might not want to do otherwise for 698 // true "kernel" situation, but we might not want to do otherwise for
652 // performance reasons). Probably blatant errors like passing in null pointers 699 // performance reasons). Probably blatant errors like passing in null pointers
653 // (for required pointer arguments) will still cause death, but perhaps not 700 // (for required pointer arguments) will still cause death, but perhaps not
654 // predictably. 701 // predictably.
655 TEST_F(CoreTest, InvalidArgumentsDeath) { 702 TEST_F(CoreTest, InvalidArgumentsDeath) {
656 const char kMemoryCheckFailedRegex[] = "Check failed"; 703 const char kMemoryCheckFailedRegex[] = "Check failed";
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 EXPECT_DEATH_IF_SUPPORTED( 796 EXPECT_DEATH_IF_SUPPORTED(
750 core()->ReadMessage(h, NullUserPointer(), NullUserPointer(), 797 core()->ReadMessage(h, NullUserPointer(), NullUserPointer(),
751 NullUserPointer(), MakeUserPointer(&handle_count), 798 NullUserPointer(), MakeUserPointer(&handle_count),
752 MOJO_READ_MESSAGE_FLAG_NONE), 799 MOJO_READ_MESSAGE_FLAG_NONE),
753 kMemoryCheckFailedRegex); 800 kMemoryCheckFailedRegex);
754 801
755 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h)); 802 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h));
756 } 803 }
757 804
758 // TODO(vtl): Missing a bunch here. 805 // TODO(vtl): Missing a bunch here.
806
807 // |CreateWaitSet()|:
808 {
809 EXPECT_DEATH_IF_SUPPORTED(
810 core()->CreateWaitSet(NullUserPointer(), NullUserPointer()),
811 kMemoryCheckFailedRegex);
812 }
759 } 813 }
760 814
761 // TODO(vtl): test |Wait()| and |WaitMany()| properly 815 // TODO(vtl): test |Wait()| and |WaitMany()| properly
762 // - including |WaitMany()| with the same handle more than once (with 816 // - including |WaitMany()| with the same handle more than once (with
763 // same/different signals) 817 // same/different signals)
764 818
765 TEST_F(CoreTest, MessagePipe) { 819 TEST_F(CoreTest, MessagePipe) {
766 MojoHandle h[2] = {MOJO_HANDLE_INVALID, MOJO_HANDLE_INVALID}; 820 MojoHandle h[2] = {MOJO_HANDLE_INVALID, MOJO_HANDLE_INVALID};
767 MojoHandleSignalsState hss[2]; 821 MojoHandleSignalsState hss[2];
768 uint32_t result_index; 822 uint32_t result_index;
(...skipping 1187 matching lines...) Expand 10 before | Expand all | Expand 10 after
1956 info.GetAddedAwakableAt(0)->Awake(0, Awakable::AwakeReason::UNSATISFIABLE, 2010 info.GetAddedAwakableAt(0)->Awake(0, Awakable::AwakeReason::UNSATISFIABLE,
1957 HandleSignalsState()); 2011 HandleSignalsState());
1958 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, waiter.result); 2012 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, waiter.result);
1959 2013
1960 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h)); 2014 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h));
1961 } 2015 }
1962 2016
1963 // TODO(vtl): Test |CreateSharedBuffer()|, |DuplicateBufferHandle()|, and 2017 // TODO(vtl): Test |CreateSharedBuffer()|, |DuplicateBufferHandle()|, and
1964 // |MapBuffer()|. 2018 // |MapBuffer()|.
1965 2019
2020 TEST_F(CoreTest, WaitSet) {
2021 MojoHandle h = MOJO_HANDLE_INVALID;
2022 EXPECT_EQ(MOJO_RESULT_OK,
2023 core()->CreateWaitSet(NullUserPointer(), MakeUserPointer(&h)));
2024 EXPECT_NE(h, MOJO_HANDLE_INVALID);
2025
2026 MockHandleInfo info;
2027 info.AllowAddAwakable(true);
2028 MojoHandle h_member = CreateMockHandle(&info);
2029
2030 EXPECT_EQ(0u, info.GetAddAwakableCallCount());
2031 EXPECT_EQ(MOJO_RESULT_OK,
2032 core()->WaitSetAdd(h, h_member, MOJO_HANDLE_SIGNAL_READABLE, 123,
2033 NullUserPointer()));
2034 EXPECT_EQ(1u, info.GetAddAwakableCallCount());
2035
2036 EXPECT_EQ(0u, info.GetRemoveAwakableCallCount());
2037 EXPECT_EQ(MOJO_RESULT_OK, core()->WaitSetRemove(h, 123));
2038 EXPECT_EQ(1u, info.GetRemoveAwakableCallCount());
2039
2040 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h_member));
2041
2042 uint32_t num_results = 5;
2043 MojoWaitSetResult results[5] = {};
2044 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED,
2045 core()->WaitSetWait(h, static_cast<MojoDeadline>(0),
2046 MakeUserPointer(&num_results),
2047 MakeUserPointer(results), NullUserPointer()));
2048
2049 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h));
2050 }
2051
1966 } // namespace 2052 } // namespace
1967 } // namespace system 2053 } // namespace system
1968 } // namespace mojo 2054 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/core_test_base.cc ('k') | mojo/edk/system/dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698