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

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

Issue 728043002: Revert of 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/system/core_test_base.cc ('k') | mojo/edk/system/data_pipe.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 24 matching lines...) Expand all
35 TEST_F(CoreTest, Basic) { 35 TEST_F(CoreTest, Basic) {
36 MockHandleInfo info; 36 MockHandleInfo info;
37 37
38 EXPECT_EQ(0u, info.GetCtorCallCount()); 38 EXPECT_EQ(0u, info.GetCtorCallCount());
39 MojoHandle h = CreateMockHandle(&info); 39 MojoHandle h = CreateMockHandle(&info);
40 EXPECT_EQ(1u, info.GetCtorCallCount()); 40 EXPECT_EQ(1u, info.GetCtorCallCount());
41 EXPECT_NE(h, MOJO_HANDLE_INVALID); 41 EXPECT_NE(h, MOJO_HANDLE_INVALID);
42 42
43 EXPECT_EQ(0u, info.GetWriteMessageCallCount()); 43 EXPECT_EQ(0u, info.GetWriteMessageCallCount());
44 EXPECT_EQ(MOJO_RESULT_OK, 44 EXPECT_EQ(MOJO_RESULT_OK,
45 core()->WriteMessage(h, NullUserPointer(), 0, NullUserPointer(), 0, 45 core()->WriteMessage(h,
46 NullUserPointer(),
47 0,
48 NullUserPointer(),
49 0,
46 MOJO_WRITE_MESSAGE_FLAG_NONE)); 50 MOJO_WRITE_MESSAGE_FLAG_NONE));
47 EXPECT_EQ(1u, info.GetWriteMessageCallCount()); 51 EXPECT_EQ(1u, info.GetWriteMessageCallCount());
48 52
49 EXPECT_EQ(0u, info.GetReadMessageCallCount()); 53 EXPECT_EQ(0u, info.GetReadMessageCallCount());
50 uint32_t num_bytes = 0; 54 uint32_t num_bytes = 0;
51 EXPECT_EQ( 55 EXPECT_EQ(MOJO_RESULT_OK,
52 MOJO_RESULT_OK, 56 core()->ReadMessage(h,
53 core()->ReadMessage(h, NullUserPointer(), MakeUserPointer(&num_bytes), 57 NullUserPointer(),
54 NullUserPointer(), NullUserPointer(), 58 MakeUserPointer(&num_bytes),
55 MOJO_READ_MESSAGE_FLAG_NONE)); 59 NullUserPointer(),
60 NullUserPointer(),
61 MOJO_READ_MESSAGE_FLAG_NONE));
56 EXPECT_EQ(1u, info.GetReadMessageCallCount()); 62 EXPECT_EQ(1u, info.GetReadMessageCallCount());
57 EXPECT_EQ(MOJO_RESULT_OK, 63 EXPECT_EQ(MOJO_RESULT_OK,
58 core()->ReadMessage(h, NullUserPointer(), NullUserPointer(), 64 core()->ReadMessage(h,
59 NullUserPointer(), NullUserPointer(), 65 NullUserPointer(),
66 NullUserPointer(),
67 NullUserPointer(),
68 NullUserPointer(),
60 MOJO_READ_MESSAGE_FLAG_NONE)); 69 MOJO_READ_MESSAGE_FLAG_NONE));
61 EXPECT_EQ(2u, info.GetReadMessageCallCount()); 70 EXPECT_EQ(2u, info.GetReadMessageCallCount());
62 71
63 EXPECT_EQ(0u, info.GetWriteDataCallCount()); 72 EXPECT_EQ(0u, info.GetWriteDataCallCount());
64 EXPECT_EQ(MOJO_RESULT_UNIMPLEMENTED, 73 EXPECT_EQ(
65 core()->WriteData(h, NullUserPointer(), NullUserPointer(), 74 MOJO_RESULT_UNIMPLEMENTED,
66 MOJO_WRITE_DATA_FLAG_NONE)); 75 core()->WriteData(
76 h, NullUserPointer(), NullUserPointer(), MOJO_WRITE_DATA_FLAG_NONE));
67 EXPECT_EQ(1u, info.GetWriteDataCallCount()); 77 EXPECT_EQ(1u, info.GetWriteDataCallCount());
68 78
69 EXPECT_EQ(0u, info.GetBeginWriteDataCallCount()); 79 EXPECT_EQ(0u, info.GetBeginWriteDataCallCount());
70 EXPECT_EQ(MOJO_RESULT_UNIMPLEMENTED, 80 EXPECT_EQ(
71 core()->BeginWriteData(h, NullUserPointer(), NullUserPointer(), 81 MOJO_RESULT_UNIMPLEMENTED,
72 MOJO_WRITE_DATA_FLAG_NONE)); 82 core()->BeginWriteData(
83 h, NullUserPointer(), NullUserPointer(), MOJO_WRITE_DATA_FLAG_NONE));
73 EXPECT_EQ(1u, info.GetBeginWriteDataCallCount()); 84 EXPECT_EQ(1u, info.GetBeginWriteDataCallCount());
74 85
75 EXPECT_EQ(0u, info.GetEndWriteDataCallCount()); 86 EXPECT_EQ(0u, info.GetEndWriteDataCallCount());
76 EXPECT_EQ(MOJO_RESULT_UNIMPLEMENTED, core()->EndWriteData(h, 0)); 87 EXPECT_EQ(MOJO_RESULT_UNIMPLEMENTED, core()->EndWriteData(h, 0));
77 EXPECT_EQ(1u, info.GetEndWriteDataCallCount()); 88 EXPECT_EQ(1u, info.GetEndWriteDataCallCount());
78 89
79 EXPECT_EQ(0u, info.GetReadDataCallCount()); 90 EXPECT_EQ(0u, info.GetReadDataCallCount());
80 EXPECT_EQ(MOJO_RESULT_UNIMPLEMENTED, 91 EXPECT_EQ(
81 core()->ReadData(h, NullUserPointer(), NullUserPointer(), 92 MOJO_RESULT_UNIMPLEMENTED,
82 MOJO_READ_DATA_FLAG_NONE)); 93 core()->ReadData(
94 h, NullUserPointer(), NullUserPointer(), MOJO_READ_DATA_FLAG_NONE));
83 EXPECT_EQ(1u, info.GetReadDataCallCount()); 95 EXPECT_EQ(1u, info.GetReadDataCallCount());
84 96
85 EXPECT_EQ(0u, info.GetBeginReadDataCallCount()); 97 EXPECT_EQ(0u, info.GetBeginReadDataCallCount());
86 EXPECT_EQ(MOJO_RESULT_UNIMPLEMENTED, 98 EXPECT_EQ(
87 core()->BeginReadData(h, NullUserPointer(), NullUserPointer(), 99 MOJO_RESULT_UNIMPLEMENTED,
88 MOJO_READ_DATA_FLAG_NONE)); 100 core()->BeginReadData(
101 h, NullUserPointer(), NullUserPointer(), MOJO_READ_DATA_FLAG_NONE));
89 EXPECT_EQ(1u, info.GetBeginReadDataCallCount()); 102 EXPECT_EQ(1u, info.GetBeginReadDataCallCount());
90 103
91 EXPECT_EQ(0u, info.GetEndReadDataCallCount()); 104 EXPECT_EQ(0u, info.GetEndReadDataCallCount());
92 EXPECT_EQ(MOJO_RESULT_UNIMPLEMENTED, core()->EndReadData(h, 0)); 105 EXPECT_EQ(MOJO_RESULT_UNIMPLEMENTED, core()->EndReadData(h, 0));
93 EXPECT_EQ(1u, info.GetEndReadDataCallCount()); 106 EXPECT_EQ(1u, info.GetEndReadDataCallCount());
94 107
95 EXPECT_EQ(0u, info.GetAddWaiterCallCount()); 108 EXPECT_EQ(0u, info.GetAddWaiterCallCount());
96 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, 109 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
97 core()->Wait(h, ~MOJO_HANDLE_SIGNAL_NONE, MOJO_DEADLINE_INDEFINITE, 110 core()->Wait(h,
111 ~MOJO_HANDLE_SIGNAL_NONE,
112 MOJO_DEADLINE_INDEFINITE,
98 NullUserPointer())); 113 NullUserPointer()));
99 EXPECT_EQ(1u, info.GetAddWaiterCallCount()); 114 EXPECT_EQ(1u, info.GetAddWaiterCallCount());
100 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, 115 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
101 core()->Wait(h, ~MOJO_HANDLE_SIGNAL_NONE, 0, NullUserPointer())); 116 core()->Wait(h, ~MOJO_HANDLE_SIGNAL_NONE, 0, NullUserPointer()));
102 EXPECT_EQ(2u, info.GetAddWaiterCallCount()); 117 EXPECT_EQ(2u, info.GetAddWaiterCallCount());
103 MojoHandleSignalsState hss = kFullMojoHandleSignalsState; 118 MojoHandleSignalsState hss = kFullMojoHandleSignalsState;
104 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, 119 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
105 core()->Wait(h, ~MOJO_HANDLE_SIGNAL_NONE, MOJO_DEADLINE_INDEFINITE, 120 core()->Wait(h,
121 ~MOJO_HANDLE_SIGNAL_NONE,
122 MOJO_DEADLINE_INDEFINITE,
106 MakeUserPointer(&hss))); 123 MakeUserPointer(&hss)));
107 EXPECT_EQ(3u, info.GetAddWaiterCallCount()); 124 EXPECT_EQ(3u, info.GetAddWaiterCallCount());
108 EXPECT_EQ(0u, hss.satisfied_signals); 125 EXPECT_EQ(0u, hss.satisfied_signals);
109 EXPECT_EQ(0u, hss.satisfiable_signals); 126 EXPECT_EQ(0u, hss.satisfiable_signals);
110 EXPECT_EQ( 127 EXPECT_EQ(
111 MOJO_RESULT_FAILED_PRECONDITION, 128 MOJO_RESULT_FAILED_PRECONDITION,
112 core()->Wait(h, ~MOJO_HANDLE_SIGNAL_NONE, 10 * 1000, NullUserPointer())); 129 core()->Wait(h, ~MOJO_HANDLE_SIGNAL_NONE, 10 * 1000, NullUserPointer()));
113 EXPECT_EQ(4u, info.GetAddWaiterCallCount()); 130 EXPECT_EQ(4u, info.GetAddWaiterCallCount());
114 hss = kFullMojoHandleSignalsState; 131 hss = kFullMojoHandleSignalsState;
115 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, 132 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
116 core()->Wait(h, ~MOJO_HANDLE_SIGNAL_NONE, 10 * 1000, 133 core()->Wait(
117 MakeUserPointer(&hss))); 134 h, ~MOJO_HANDLE_SIGNAL_NONE, 10 * 1000, MakeUserPointer(&hss)));
118 EXPECT_EQ(5u, info.GetAddWaiterCallCount()); 135 EXPECT_EQ(5u, info.GetAddWaiterCallCount());
119 EXPECT_EQ(0u, hss.satisfied_signals); 136 EXPECT_EQ(0u, hss.satisfied_signals);
120 EXPECT_EQ(0u, hss.satisfiable_signals); 137 EXPECT_EQ(0u, hss.satisfiable_signals);
121 138
122 MojoHandleSignals handle_signals = ~MOJO_HANDLE_SIGNAL_NONE; 139 MojoHandleSignals handle_signals = ~MOJO_HANDLE_SIGNAL_NONE;
123 EXPECT_EQ( 140 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
124 MOJO_RESULT_FAILED_PRECONDITION, 141 core()->WaitMany(MakeUserPointer(&h),
125 core()->WaitMany(MakeUserPointer(&h), MakeUserPointer(&handle_signals), 1, 142 MakeUserPointer(&handle_signals),
126 MOJO_DEADLINE_INDEFINITE, NullUserPointer(), 143 1,
127 NullUserPointer())); 144 MOJO_DEADLINE_INDEFINITE,
145 NullUserPointer(),
146 NullUserPointer()));
128 EXPECT_EQ(6u, info.GetAddWaiterCallCount()); 147 EXPECT_EQ(6u, info.GetAddWaiterCallCount());
129 uint32_t result_index = static_cast<uint32_t>(-1); 148 uint32_t result_index = static_cast<uint32_t>(-1);
130 EXPECT_EQ( 149 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
131 MOJO_RESULT_FAILED_PRECONDITION, 150 core()->WaitMany(MakeUserPointer(&h),
132 core()->WaitMany(MakeUserPointer(&h), MakeUserPointer(&handle_signals), 1, 151 MakeUserPointer(&handle_signals),
133 MOJO_DEADLINE_INDEFINITE, MakeUserPointer(&result_index), 152 1,
134 NullUserPointer())); 153 MOJO_DEADLINE_INDEFINITE,
154 MakeUserPointer(&result_index),
155 NullUserPointer()));
135 EXPECT_EQ(7u, info.GetAddWaiterCallCount()); 156 EXPECT_EQ(7u, info.GetAddWaiterCallCount());
136 EXPECT_EQ(0u, result_index); 157 EXPECT_EQ(0u, result_index);
137 hss = kFullMojoHandleSignalsState; 158 hss = kFullMojoHandleSignalsState;
138 EXPECT_EQ( 159 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
139 MOJO_RESULT_FAILED_PRECONDITION, 160 core()->WaitMany(MakeUserPointer(&h),
140 core()->WaitMany(MakeUserPointer(&h), MakeUserPointer(&handle_signals), 1, 161 MakeUserPointer(&handle_signals),
141 MOJO_DEADLINE_INDEFINITE, NullUserPointer(), 162 1,
142 MakeUserPointer(&hss))); 163 MOJO_DEADLINE_INDEFINITE,
164 NullUserPointer(),
165 MakeUserPointer(&hss)));
143 EXPECT_EQ(8u, info.GetAddWaiterCallCount()); 166 EXPECT_EQ(8u, info.GetAddWaiterCallCount());
144 EXPECT_EQ(0u, hss.satisfied_signals); 167 EXPECT_EQ(0u, hss.satisfied_signals);
145 EXPECT_EQ(0u, hss.satisfiable_signals); 168 EXPECT_EQ(0u, hss.satisfiable_signals);
146 result_index = static_cast<uint32_t>(-1); 169 result_index = static_cast<uint32_t>(-1);
147 hss = kFullMojoHandleSignalsState; 170 hss = kFullMojoHandleSignalsState;
148 EXPECT_EQ( 171 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
149 MOJO_RESULT_FAILED_PRECONDITION, 172 core()->WaitMany(MakeUserPointer(&h),
150 core()->WaitMany(MakeUserPointer(&h), MakeUserPointer(&handle_signals), 1, 173 MakeUserPointer(&handle_signals),
151 MOJO_DEADLINE_INDEFINITE, MakeUserPointer(&result_index), 174 1,
152 MakeUserPointer(&hss))); 175 MOJO_DEADLINE_INDEFINITE,
176 MakeUserPointer(&result_index),
177 MakeUserPointer(&hss)));
153 EXPECT_EQ(9u, info.GetAddWaiterCallCount()); 178 EXPECT_EQ(9u, info.GetAddWaiterCallCount());
154 EXPECT_EQ(0u, result_index); 179 EXPECT_EQ(0u, result_index);
155 EXPECT_EQ(0u, hss.satisfied_signals); 180 EXPECT_EQ(0u, hss.satisfied_signals);
156 EXPECT_EQ(0u, hss.satisfiable_signals); 181 EXPECT_EQ(0u, hss.satisfiable_signals);
157 182
158 EXPECT_EQ(0u, info.GetDtorCallCount()); 183 EXPECT_EQ(0u, info.GetDtorCallCount());
159 EXPECT_EQ(0u, info.GetCloseCallCount()); 184 EXPECT_EQ(0u, info.GetCloseCallCount());
160 EXPECT_EQ(0u, info.GetCancelAllWaitersCallCount()); 185 EXPECT_EQ(0u, info.GetCancelAllWaitersCallCount());
161 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h)); 186 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h));
162 EXPECT_EQ(1u, info.GetCancelAllWaitersCallCount()); 187 EXPECT_EQ(1u, info.GetCancelAllWaitersCallCount());
(...skipping 16 matching lines...) Expand all
179 MojoHandle h = CreateMockHandle(&info); 204 MojoHandle h = CreateMockHandle(&info);
180 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h)); 205 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h));
181 EXPECT_EQ(1u, info.GetCloseCallCount()); 206 EXPECT_EQ(1u, info.GetCloseCallCount());
182 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, core()->Close(h)); 207 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, core()->Close(h));
183 EXPECT_EQ(1u, info.GetCloseCallCount()); 208 EXPECT_EQ(1u, info.GetCloseCallCount());
184 } 209 }
185 210
186 // |Wait()|: 211 // |Wait()|:
187 { 212 {
188 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 213 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
189 core()->Wait(MOJO_HANDLE_INVALID, ~MOJO_HANDLE_SIGNAL_NONE, 214 core()->Wait(MOJO_HANDLE_INVALID,
190 MOJO_DEADLINE_INDEFINITE, NullUserPointer())); 215 ~MOJO_HANDLE_SIGNAL_NONE,
216 MOJO_DEADLINE_INDEFINITE,
217 NullUserPointer()));
191 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 218 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
192 core()->Wait(10, ~MOJO_HANDLE_SIGNAL_NONE, 219 core()->Wait(10,
193 MOJO_DEADLINE_INDEFINITE, NullUserPointer())); 220 ~MOJO_HANDLE_SIGNAL_NONE,
221 MOJO_DEADLINE_INDEFINITE,
222 NullUserPointer()));
194 223
195 MojoHandleSignalsState hss = kFullMojoHandleSignalsState; 224 MojoHandleSignalsState hss = kFullMojoHandleSignalsState;
196 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 225 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
197 core()->Wait(MOJO_HANDLE_INVALID, ~MOJO_HANDLE_SIGNAL_NONE, 226 core()->Wait(MOJO_HANDLE_INVALID,
198 MOJO_DEADLINE_INDEFINITE, MakeUserPointer(&hss))); 227 ~MOJO_HANDLE_SIGNAL_NONE,
228 MOJO_DEADLINE_INDEFINITE,
229 MakeUserPointer(&hss)));
199 // On invalid argument, it shouldn't modify the handle signals state. 230 // On invalid argument, it shouldn't modify the handle signals state.
200 EXPECT_EQ(kFullMojoHandleSignalsState.satisfied_signals, 231 EXPECT_EQ(kFullMojoHandleSignalsState.satisfied_signals,
201 hss.satisfied_signals); 232 hss.satisfied_signals);
202 EXPECT_EQ(kFullMojoHandleSignalsState.satisfiable_signals, 233 EXPECT_EQ(kFullMojoHandleSignalsState.satisfiable_signals,
203 hss.satisfiable_signals); 234 hss.satisfiable_signals);
204 hss = kFullMojoHandleSignalsState; 235 hss = kFullMojoHandleSignalsState;
205 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 236 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
206 core()->Wait(10, ~MOJO_HANDLE_SIGNAL_NONE, 237 core()->Wait(10,
207 MOJO_DEADLINE_INDEFINITE, MakeUserPointer(&hss))); 238 ~MOJO_HANDLE_SIGNAL_NONE,
239 MOJO_DEADLINE_INDEFINITE,
240 MakeUserPointer(&hss)));
208 // On invalid argument, it shouldn't modify the handle signals state. 241 // On invalid argument, it shouldn't modify the handle signals state.
209 EXPECT_EQ(kFullMojoHandleSignalsState.satisfied_signals, 242 EXPECT_EQ(kFullMojoHandleSignalsState.satisfied_signals,
210 hss.satisfied_signals); 243 hss.satisfied_signals);
211 EXPECT_EQ(kFullMojoHandleSignalsState.satisfiable_signals, 244 EXPECT_EQ(kFullMojoHandleSignalsState.satisfiable_signals,
212 hss.satisfiable_signals); 245 hss.satisfiable_signals);
213 } 246 }
214 247
215 // |WaitMany()|: 248 // |WaitMany()|:
216 { 249 {
217 MojoHandle handles[2] = {MOJO_HANDLE_INVALID, MOJO_HANDLE_INVALID}; 250 MojoHandle handles[2] = {MOJO_HANDLE_INVALID, MOJO_HANDLE_INVALID};
218 MojoHandleSignals signals[2] = {~MOJO_HANDLE_SIGNAL_NONE, 251 MojoHandleSignals signals[2] = {~MOJO_HANDLE_SIGNAL_NONE,
219 ~MOJO_HANDLE_SIGNAL_NONE}; 252 ~MOJO_HANDLE_SIGNAL_NONE};
220 EXPECT_EQ(
221 MOJO_RESULT_INVALID_ARGUMENT,
222 core()->WaitMany(MakeUserPointer(handles), MakeUserPointer(signals), 0,
223 MOJO_DEADLINE_INDEFINITE, NullUserPointer(),
224 NullUserPointer()));
225 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 253 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
226 core()->WaitMany(NullUserPointer(), MakeUserPointer(signals), 0, 254 core()->WaitMany(MakeUserPointer(handles),
227 MOJO_DEADLINE_INDEFINITE, NullUserPointer(), 255 MakeUserPointer(signals),
256 0,
257 MOJO_DEADLINE_INDEFINITE,
258 NullUserPointer(),
259 NullUserPointer()));
260 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
261 core()->WaitMany(NullUserPointer(),
262 MakeUserPointer(signals),
263 0,
264 MOJO_DEADLINE_INDEFINITE,
265 NullUserPointer(),
228 NullUserPointer())); 266 NullUserPointer()));
229 // If |num_handles| is invalid, it should leave |result_index| and 267 // If |num_handles| is invalid, it should leave |result_index| and
230 // |signals_states| alone. 268 // |signals_states| alone.
231 // (We use -1 internally; make sure that doesn't leak.) 269 // (We use -1 internally; make sure that doesn't leak.)
232 uint32_t result_index = 123; 270 uint32_t result_index = 123;
233 MojoHandleSignalsState hss = kFullMojoHandleSignalsState; 271 MojoHandleSignalsState hss = kFullMojoHandleSignalsState;
234 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 272 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
235 core()->WaitMany(NullUserPointer(), MakeUserPointer(signals), 0, 273 core()->WaitMany(NullUserPointer(),
274 MakeUserPointer(signals),
275 0,
236 MOJO_DEADLINE_INDEFINITE, 276 MOJO_DEADLINE_INDEFINITE,
237 MakeUserPointer(&result_index), 277 MakeUserPointer(&result_index),
238 MakeUserPointer(&hss))); 278 MakeUserPointer(&hss)));
239 EXPECT_EQ(123u, result_index); 279 EXPECT_EQ(123u, result_index);
240 EXPECT_EQ(kFullMojoHandleSignalsState.satisfied_signals, 280 EXPECT_EQ(kFullMojoHandleSignalsState.satisfied_signals,
241 hss.satisfied_signals); 281 hss.satisfied_signals);
242 EXPECT_EQ(kFullMojoHandleSignalsState.satisfiable_signals, 282 EXPECT_EQ(kFullMojoHandleSignalsState.satisfiable_signals,
243 hss.satisfiable_signals); 283 hss.satisfiable_signals);
244 284
245 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 285 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
246 core()->WaitMany(MakeUserPointer(handles), NullUserPointer(), 0, 286 core()->WaitMany(MakeUserPointer(handles),
247 MOJO_DEADLINE_INDEFINITE, NullUserPointer(), 287 NullUserPointer(),
288 0,
289 MOJO_DEADLINE_INDEFINITE,
290 NullUserPointer(),
248 NullUserPointer())); 291 NullUserPointer()));
249 EXPECT_EQ( 292 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
250 MOJO_RESULT_INVALID_ARGUMENT, 293 core()->WaitMany(MakeUserPointer(handles),
251 core()->WaitMany(MakeUserPointer(handles), MakeUserPointer(signals), 1, 294 MakeUserPointer(signals),
252 MOJO_DEADLINE_INDEFINITE, NullUserPointer(), 295 1,
253 NullUserPointer())); 296 MOJO_DEADLINE_INDEFINITE,
297 NullUserPointer(),
298 NullUserPointer()));
254 // But if a handle is bad, then it should set |result_index| but still leave 299 // But if a handle is bad, then it should set |result_index| but still leave
255 // |signals_states| alone. 300 // |signals_states| alone.
256 result_index = static_cast<uint32_t>(-1); 301 result_index = static_cast<uint32_t>(-1);
257 hss = kFullMojoHandleSignalsState; 302 hss = kFullMojoHandleSignalsState;
258 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 303 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
259 core()->WaitMany( 304 core()->WaitMany(MakeUserPointer(handles),
260 MakeUserPointer(handles), MakeUserPointer(signals), 1, 305 MakeUserPointer(signals),
261 MOJO_DEADLINE_INDEFINITE, MakeUserPointer(&result_index), 306 1,
262 MakeUserPointer(&hss))); 307 MOJO_DEADLINE_INDEFINITE,
308 MakeUserPointer(&result_index),
309 MakeUserPointer(&hss)));
263 EXPECT_EQ(0u, result_index); 310 EXPECT_EQ(0u, result_index);
264 EXPECT_EQ(kFullMojoHandleSignalsState.satisfied_signals, 311 EXPECT_EQ(kFullMojoHandleSignalsState.satisfied_signals,
265 hss.satisfied_signals); 312 hss.satisfied_signals);
266 EXPECT_EQ(kFullMojoHandleSignalsState.satisfiable_signals, 313 EXPECT_EQ(kFullMojoHandleSignalsState.satisfiable_signals,
267 hss.satisfiable_signals); 314 hss.satisfiable_signals);
268 315
269 MockHandleInfo info[2]; 316 MockHandleInfo info[2];
270 handles[0] = CreateMockHandle(&info[0]); 317 handles[0] = CreateMockHandle(&info[0]);
271 318
272 result_index = static_cast<uint32_t>(-1); 319 result_index = static_cast<uint32_t>(-1);
273 hss = kFullMojoHandleSignalsState; 320 hss = kFullMojoHandleSignalsState;
274 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, 321 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
275 core()->WaitMany( 322 core()->WaitMany(MakeUserPointer(handles),
276 MakeUserPointer(handles), MakeUserPointer(signals), 1, 323 MakeUserPointer(signals),
277 MOJO_DEADLINE_INDEFINITE, MakeUserPointer(&result_index), 324 1,
278 MakeUserPointer(&hss))); 325 MOJO_DEADLINE_INDEFINITE,
326 MakeUserPointer(&result_index),
327 MakeUserPointer(&hss)));
279 EXPECT_EQ(0u, result_index); 328 EXPECT_EQ(0u, result_index);
280 EXPECT_EQ(0u, hss.satisfied_signals); 329 EXPECT_EQ(0u, hss.satisfied_signals);
281 EXPECT_EQ(0u, hss.satisfiable_signals); 330 EXPECT_EQ(0u, hss.satisfiable_signals);
282 331
283 // On invalid argument, it'll leave |signals_states| alone. 332 // On invalid argument, it'll leave |signals_states| alone.
284 result_index = static_cast<uint32_t>(-1); 333 result_index = static_cast<uint32_t>(-1);
285 hss = kFullMojoHandleSignalsState; 334 hss = kFullMojoHandleSignalsState;
286 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 335 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
287 core()->WaitMany( 336 core()->WaitMany(MakeUserPointer(handles),
288 MakeUserPointer(handles), MakeUserPointer(signals), 2, 337 MakeUserPointer(signals),
289 MOJO_DEADLINE_INDEFINITE, MakeUserPointer(&result_index), 338 2,
290 MakeUserPointer(&hss))); 339 MOJO_DEADLINE_INDEFINITE,
340 MakeUserPointer(&result_index),
341 MakeUserPointer(&hss)));
291 EXPECT_EQ(1u, result_index); 342 EXPECT_EQ(1u, result_index);
292 EXPECT_EQ(kFullMojoHandleSignalsState.satisfied_signals, 343 EXPECT_EQ(kFullMojoHandleSignalsState.satisfied_signals,
293 hss.satisfied_signals); 344 hss.satisfied_signals);
294 EXPECT_EQ(kFullMojoHandleSignalsState.satisfiable_signals, 345 EXPECT_EQ(kFullMojoHandleSignalsState.satisfiable_signals,
295 hss.satisfiable_signals); 346 hss.satisfiable_signals);
296 handles[1] = handles[0] + 1; // Invalid handle. 347 handles[1] = handles[0] + 1; // Invalid handle.
297 EXPECT_EQ( 348 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
298 MOJO_RESULT_INVALID_ARGUMENT, 349 core()->WaitMany(MakeUserPointer(handles),
299 core()->WaitMany(MakeUserPointer(handles), MakeUserPointer(signals), 2, 350 MakeUserPointer(signals),
300 MOJO_DEADLINE_INDEFINITE, NullUserPointer(), 351 2,
301 NullUserPointer())); 352 MOJO_DEADLINE_INDEFINITE,
353 NullUserPointer(),
354 NullUserPointer()));
302 handles[1] = CreateMockHandle(&info[1]); 355 handles[1] = CreateMockHandle(&info[1]);
303 EXPECT_EQ( 356 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
304 MOJO_RESULT_FAILED_PRECONDITION, 357 core()->WaitMany(MakeUserPointer(handles),
305 core()->WaitMany(MakeUserPointer(handles), MakeUserPointer(signals), 2, 358 MakeUserPointer(signals),
306 MOJO_DEADLINE_INDEFINITE, NullUserPointer(), 359 2,
307 NullUserPointer())); 360 MOJO_DEADLINE_INDEFINITE,
361 NullUserPointer(),
362 NullUserPointer()));
308 363
309 // TODO(vtl): Test one where we get "failed precondition" only for the 364 // TODO(vtl): Test one where we get "failed precondition" only for the
310 // second handle (and the first one is valid to wait on). 365 // second handle (and the first one is valid to wait on).
311 366
312 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(handles[0])); 367 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(handles[0]));
313 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(handles[1])); 368 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(handles[1]));
314 } 369 }
315 370
316 // |CreateMessagePipe()|: Nothing to check (apart from things that cause 371 // |CreateMessagePipe()|: Nothing to check (apart from things that cause
317 // death). 372 // death).
318 373
319 // |WriteMessage()|: 374 // |WriteMessage()|:
320 // Only check arguments checked by |Core|, namely |handle|, |handles|, and 375 // Only check arguments checked by |Core|, namely |handle|, |handles|, and
321 // |num_handles|. 376 // |num_handles|.
322 { 377 {
323 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 378 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
324 core()->WriteMessage(MOJO_HANDLE_INVALID, NullUserPointer(), 0, 379 core()->WriteMessage(MOJO_HANDLE_INVALID,
325 NullUserPointer(), 0, 380 NullUserPointer(),
381 0,
382 NullUserPointer(),
383 0,
326 MOJO_WRITE_MESSAGE_FLAG_NONE)); 384 MOJO_WRITE_MESSAGE_FLAG_NONE));
327 385
328 MockHandleInfo info; 386 MockHandleInfo info;
329 MojoHandle h = CreateMockHandle(&info); 387 MojoHandle h = CreateMockHandle(&info);
330 MojoHandle handles[2] = {MOJO_HANDLE_INVALID, MOJO_HANDLE_INVALID}; 388 MojoHandle handles[2] = {MOJO_HANDLE_INVALID, MOJO_HANDLE_INVALID};
331 389
332 // Huge handle count (implausibly big on some systems -- more than can be 390 // Huge handle count (implausibly big on some systems -- more than can be
333 // stored in a 32-bit address space). 391 // stored in a 32-bit address space).
334 // Note: This may return either |MOJO_RESULT_INVALID_ARGUMENT| or 392 // Note: This may return either |MOJO_RESULT_INVALID_ARGUMENT| or
335 // |MOJO_RESULT_RESOURCE_EXHAUSTED|, depending on whether it's plausible or 393 // |MOJO_RESULT_RESOURCE_EXHAUSTED|, depending on whether it's plausible or
336 // not. 394 // not.
337 EXPECT_NE( 395 EXPECT_NE(MOJO_RESULT_OK,
338 MOJO_RESULT_OK, 396 core()->WriteMessage(h,
339 core()->WriteMessage(h, NullUserPointer(), 0, MakeUserPointer(handles), 397 NullUserPointer(),
340 std::numeric_limits<uint32_t>::max(), 398 0,
341 MOJO_WRITE_MESSAGE_FLAG_NONE)); 399 MakeUserPointer(handles),
400 std::numeric_limits<uint32_t>::max(),
401 MOJO_WRITE_MESSAGE_FLAG_NONE));
342 EXPECT_EQ(0u, info.GetWriteMessageCallCount()); 402 EXPECT_EQ(0u, info.GetWriteMessageCallCount());
343 403
344 // Huge handle count (plausibly big). 404 // Huge handle count (plausibly big).
345 EXPECT_EQ(MOJO_RESULT_RESOURCE_EXHAUSTED, 405 EXPECT_EQ(MOJO_RESULT_RESOURCE_EXHAUSTED,
346 core()->WriteMessage( 406 core()->WriteMessage(
347 h, NullUserPointer(), 0, MakeUserPointer(handles), 407 h,
408 NullUserPointer(),
409 0,
410 MakeUserPointer(handles),
348 std::numeric_limits<uint32_t>::max() / sizeof(handles[0]), 411 std::numeric_limits<uint32_t>::max() / sizeof(handles[0]),
349 MOJO_WRITE_MESSAGE_FLAG_NONE)); 412 MOJO_WRITE_MESSAGE_FLAG_NONE));
350 EXPECT_EQ(0u, info.GetWriteMessageCallCount()); 413 EXPECT_EQ(0u, info.GetWriteMessageCallCount());
351 414
352 // Invalid handle in |handles|. 415 // Invalid handle in |handles|.
353 EXPECT_EQ( 416 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
354 MOJO_RESULT_INVALID_ARGUMENT, 417 core()->WriteMessage(h,
355 core()->WriteMessage(h, NullUserPointer(), 0, MakeUserPointer(handles), 418 NullUserPointer(),
356 1, MOJO_WRITE_MESSAGE_FLAG_NONE)); 419 0,
420 MakeUserPointer(handles),
421 1,
422 MOJO_WRITE_MESSAGE_FLAG_NONE));
357 EXPECT_EQ(0u, info.GetWriteMessageCallCount()); 423 EXPECT_EQ(0u, info.GetWriteMessageCallCount());
358 424
359 // Two invalid handles in |handles|. 425 // Two invalid handles in |handles|.
360 EXPECT_EQ( 426 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
361 MOJO_RESULT_INVALID_ARGUMENT, 427 core()->WriteMessage(h,
362 core()->WriteMessage(h, NullUserPointer(), 0, MakeUserPointer(handles), 428 NullUserPointer(),
363 2, MOJO_WRITE_MESSAGE_FLAG_NONE)); 429 0,
430 MakeUserPointer(handles),
431 2,
432 MOJO_WRITE_MESSAGE_FLAG_NONE));
364 EXPECT_EQ(0u, info.GetWriteMessageCallCount()); 433 EXPECT_EQ(0u, info.GetWriteMessageCallCount());
365 434
366 // Can't send a handle over itself. 435 // Can't send a handle over itself.
367 handles[0] = h; 436 handles[0] = h;
368 EXPECT_EQ( 437 EXPECT_EQ(MOJO_RESULT_BUSY,
369 MOJO_RESULT_BUSY, 438 core()->WriteMessage(h,
370 core()->WriteMessage(h, NullUserPointer(), 0, MakeUserPointer(handles), 439 NullUserPointer(),
371 1, MOJO_WRITE_MESSAGE_FLAG_NONE)); 440 0,
441 MakeUserPointer(handles),
442 1,
443 MOJO_WRITE_MESSAGE_FLAG_NONE));
372 EXPECT_EQ(0u, info.GetWriteMessageCallCount()); 444 EXPECT_EQ(0u, info.GetWriteMessageCallCount());
373 445
374 MockHandleInfo info2; 446 MockHandleInfo info2;
375 MojoHandle h2 = CreateMockHandle(&info2); 447 MojoHandle h2 = CreateMockHandle(&info2);
376 448
377 // This is "okay", but |MockDispatcher| doesn't implement it. 449 // This is "okay", but |MockDispatcher| doesn't implement it.
378 handles[0] = h2; 450 handles[0] = h2;
379 EXPECT_EQ( 451 EXPECT_EQ(MOJO_RESULT_UNIMPLEMENTED,
380 MOJO_RESULT_UNIMPLEMENTED, 452 core()->WriteMessage(h,
381 core()->WriteMessage(h, NullUserPointer(), 0, MakeUserPointer(handles), 453 NullUserPointer(),
382 1, MOJO_WRITE_MESSAGE_FLAG_NONE)); 454 0,
455 MakeUserPointer(handles),
456 1,
457 MOJO_WRITE_MESSAGE_FLAG_NONE));
383 EXPECT_EQ(1u, info.GetWriteMessageCallCount()); 458 EXPECT_EQ(1u, info.GetWriteMessageCallCount());
384 459
385 // One of the |handles| is still invalid. 460 // One of the |handles| is still invalid.
386 EXPECT_EQ( 461 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
387 MOJO_RESULT_INVALID_ARGUMENT, 462 core()->WriteMessage(h,
388 core()->WriteMessage(h, NullUserPointer(), 0, MakeUserPointer(handles), 463 NullUserPointer(),
389 2, MOJO_WRITE_MESSAGE_FLAG_NONE)); 464 0,
465 MakeUserPointer(handles),
466 2,
467 MOJO_WRITE_MESSAGE_FLAG_NONE));
390 EXPECT_EQ(1u, info.GetWriteMessageCallCount()); 468 EXPECT_EQ(1u, info.GetWriteMessageCallCount());
391 469
392 // One of the |handles| is the same as |handle|. 470 // One of the |handles| is the same as |handle|.
393 handles[1] = h; 471 handles[1] = h;
394 EXPECT_EQ( 472 EXPECT_EQ(MOJO_RESULT_BUSY,
395 MOJO_RESULT_BUSY, 473 core()->WriteMessage(h,
396 core()->WriteMessage(h, NullUserPointer(), 0, MakeUserPointer(handles), 474 NullUserPointer(),
397 2, MOJO_WRITE_MESSAGE_FLAG_NONE)); 475 0,
476 MakeUserPointer(handles),
477 2,
478 MOJO_WRITE_MESSAGE_FLAG_NONE));
398 EXPECT_EQ(1u, info.GetWriteMessageCallCount()); 479 EXPECT_EQ(1u, info.GetWriteMessageCallCount());
399 480
400 // Can't send a handle twice in the same message. 481 // Can't send a handle twice in the same message.
401 handles[1] = h2; 482 handles[1] = h2;
402 EXPECT_EQ( 483 EXPECT_EQ(MOJO_RESULT_BUSY,
403 MOJO_RESULT_BUSY, 484 core()->WriteMessage(h,
404 core()->WriteMessage(h, NullUserPointer(), 0, MakeUserPointer(handles), 485 NullUserPointer(),
405 2, MOJO_WRITE_MESSAGE_FLAG_NONE)); 486 0,
487 MakeUserPointer(handles),
488 2,
489 MOJO_WRITE_MESSAGE_FLAG_NONE));
406 EXPECT_EQ(1u, info.GetWriteMessageCallCount()); 490 EXPECT_EQ(1u, info.GetWriteMessageCallCount());
407 491
408 // Note: Since we never successfully sent anything with it, |h2| should 492 // Note: Since we never successfully sent anything with it, |h2| should
409 // still be valid. 493 // still be valid.
410 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h2)); 494 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h2));
411 495
412 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h)); 496 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h));
413 } 497 }
414 498
415 // |ReadMessage()|: 499 // |ReadMessage()|:
416 // Only check arguments checked by |Core|, namely |handle|, |handles|, and 500 // Only check arguments checked by |Core|, namely |handle|, |handles|, and
417 // |num_handles|. 501 // |num_handles|.
418 { 502 {
419 EXPECT_EQ( 503 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
420 MOJO_RESULT_INVALID_ARGUMENT, 504 core()->ReadMessage(MOJO_HANDLE_INVALID,
421 core()->ReadMessage(MOJO_HANDLE_INVALID, NullUserPointer(), 505 NullUserPointer(),
422 NullUserPointer(), NullUserPointer(), 506 NullUserPointer(),
423 NullUserPointer(), MOJO_READ_MESSAGE_FLAG_NONE)); 507 NullUserPointer(),
508 NullUserPointer(),
509 MOJO_READ_MESSAGE_FLAG_NONE));
424 510
425 MockHandleInfo info; 511 MockHandleInfo info;
426 MojoHandle h = CreateMockHandle(&info); 512 MojoHandle h = CreateMockHandle(&info);
427 513
428 // Okay. 514 // Okay.
429 uint32_t handle_count = 0; 515 uint32_t handle_count = 0;
430 EXPECT_EQ(MOJO_RESULT_OK, 516 EXPECT_EQ(MOJO_RESULT_OK,
431 core()->ReadMessage( 517 core()->ReadMessage(h,
432 h, NullUserPointer(), NullUserPointer(), NullUserPointer(), 518 NullUserPointer(),
433 MakeUserPointer(&handle_count), MOJO_READ_MESSAGE_FLAG_NONE)); 519 NullUserPointer(),
520 NullUserPointer(),
521 MakeUserPointer(&handle_count),
522 MOJO_READ_MESSAGE_FLAG_NONE));
434 // Checked by |Core|, shouldn't go through to the dispatcher. 523 // Checked by |Core|, shouldn't go through to the dispatcher.
435 EXPECT_EQ(1u, info.GetReadMessageCallCount()); 524 EXPECT_EQ(1u, info.GetReadMessageCallCount());
436 525
437 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h)); 526 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h));
438 } 527 }
439 } 528 }
440 529
441 // These test invalid arguments that should cause death if we're being paranoid 530 // These test invalid arguments that should cause death if we're being paranoid
442 // about checking arguments (which we would want to do if, e.g., we were in a 531 // about checking arguments (which we would want to do if, e.g., we were in a
443 // true "kernel" situation, but we might not want to do otherwise for 532 // true "kernel" situation, but we might not want to do otherwise for
444 // performance reasons). Probably blatant errors like passing in null pointers 533 // performance reasons). Probably blatant errors like passing in null pointers
445 // (for required pointer arguments) will still cause death, but perhaps not 534 // (for required pointer arguments) will still cause death, but perhaps not
446 // predictably. 535 // predictably.
447 TEST_F(CoreTest, InvalidArgumentsDeath) { 536 TEST_F(CoreTest, InvalidArgumentsDeath) {
448 const char kMemoryCheckFailedRegex[] = "Check failed"; 537 const char kMemoryCheckFailedRegex[] = "Check failed";
449 538
450 // |WaitMany()|: 539 // |WaitMany()|:
451 { 540 {
452 MojoHandle handle = MOJO_HANDLE_INVALID; 541 MojoHandle handle = MOJO_HANDLE_INVALID;
453 MojoHandleSignals signals = ~MOJO_HANDLE_SIGNAL_NONE; 542 MojoHandleSignals signals = ~MOJO_HANDLE_SIGNAL_NONE;
454 EXPECT_DEATH_IF_SUPPORTED( 543 EXPECT_DEATH_IF_SUPPORTED(core()->WaitMany(NullUserPointer(),
455 core()->WaitMany(NullUserPointer(), MakeUserPointer(&signals), 1, 544 MakeUserPointer(&signals),
456 MOJO_DEADLINE_INDEFINITE, NullUserPointer(), 545 1,
457 NullUserPointer()), 546 MOJO_DEADLINE_INDEFINITE,
458 kMemoryCheckFailedRegex); 547 NullUserPointer(),
459 EXPECT_DEATH_IF_SUPPORTED( 548 NullUserPointer()),
460 core()->WaitMany(MakeUserPointer(&handle), NullUserPointer(), 1, 549 kMemoryCheckFailedRegex);
461 MOJO_DEADLINE_INDEFINITE, NullUserPointer(), 550 EXPECT_DEATH_IF_SUPPORTED(core()->WaitMany(MakeUserPointer(&handle),
462 NullUserPointer()), 551 NullUserPointer(),
463 kMemoryCheckFailedRegex); 552 1,
553 MOJO_DEADLINE_INDEFINITE,
554 NullUserPointer(),
555 NullUserPointer()),
556 kMemoryCheckFailedRegex);
464 // TODO(vtl): |result_index| and |signals_states| are optional. Test them 557 // TODO(vtl): |result_index| and |signals_states| are optional. Test them
465 // with non-null invalid pointers? 558 // with non-null invalid pointers?
466 } 559 }
467 560
468 // |CreateMessagePipe()|: 561 // |CreateMessagePipe()|:
469 { 562 {
470 MojoHandle h; 563 MojoHandle h;
471 EXPECT_DEATH_IF_SUPPORTED( 564 EXPECT_DEATH_IF_SUPPORTED(
472 core()->CreateMessagePipe(NullUserPointer(), NullUserPointer(), 565 core()->CreateMessagePipe(
473 NullUserPointer()), 566 NullUserPointer(), NullUserPointer(), NullUserPointer()),
474 kMemoryCheckFailedRegex); 567 kMemoryCheckFailedRegex);
475 EXPECT_DEATH_IF_SUPPORTED( 568 EXPECT_DEATH_IF_SUPPORTED(
476 core()->CreateMessagePipe(NullUserPointer(), MakeUserPointer(&h), 569 core()->CreateMessagePipe(
477 NullUserPointer()), 570 NullUserPointer(), MakeUserPointer(&h), NullUserPointer()),
478 kMemoryCheckFailedRegex); 571 kMemoryCheckFailedRegex);
479 EXPECT_DEATH_IF_SUPPORTED( 572 EXPECT_DEATH_IF_SUPPORTED(
480 core()->CreateMessagePipe(NullUserPointer(), NullUserPointer(), 573 core()->CreateMessagePipe(
481 MakeUserPointer(&h)), 574 NullUserPointer(), NullUserPointer(), MakeUserPointer(&h)),
482 kMemoryCheckFailedRegex); 575 kMemoryCheckFailedRegex);
483 } 576 }
484 577
485 // |WriteMessage()|: 578 // |WriteMessage()|:
486 // Only check arguments checked by |Core|, namely |handle|, |handles|, and 579 // Only check arguments checked by |Core|, namely |handle|, |handles|, and
487 // |num_handles|. 580 // |num_handles|.
488 { 581 {
489 MockHandleInfo info; 582 MockHandleInfo info;
490 MojoHandle h = CreateMockHandle(&info); 583 MojoHandle h = CreateMockHandle(&info);
491 584
492 // Null |handles| with nonzero |num_handles|. 585 // Null |handles| with nonzero |num_handles|.
493 EXPECT_DEATH_IF_SUPPORTED( 586 EXPECT_DEATH_IF_SUPPORTED(
494 core()->WriteMessage(h, NullUserPointer(), 0, NullUserPointer(), 1, 587 core()->WriteMessage(h,
588 NullUserPointer(),
589 0,
590 NullUserPointer(),
591 1,
495 MOJO_WRITE_MESSAGE_FLAG_NONE), 592 MOJO_WRITE_MESSAGE_FLAG_NONE),
496 kMemoryCheckFailedRegex); 593 kMemoryCheckFailedRegex);
497 594
498 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h)); 595 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h));
499 } 596 }
500 597
501 // |ReadMessage()|: 598 // |ReadMessage()|:
502 // Only check arguments checked by |Core|, namely |handle|, |handles|, and 599 // Only check arguments checked by |Core|, namely |handle|, |handles|, and
503 // |num_handles|. 600 // |num_handles|.
504 { 601 {
505 MockHandleInfo info; 602 MockHandleInfo info;
506 MojoHandle h = CreateMockHandle(&info); 603 MojoHandle h = CreateMockHandle(&info);
507 604
508 uint32_t handle_count = 1; 605 uint32_t handle_count = 1;
509 EXPECT_DEATH_IF_SUPPORTED( 606 EXPECT_DEATH_IF_SUPPORTED(
510 core()->ReadMessage(h, NullUserPointer(), NullUserPointer(), 607 core()->ReadMessage(h,
511 NullUserPointer(), MakeUserPointer(&handle_count), 608 NullUserPointer(),
609 NullUserPointer(),
610 NullUserPointer(),
611 MakeUserPointer(&handle_count),
512 MOJO_READ_MESSAGE_FLAG_NONE), 612 MOJO_READ_MESSAGE_FLAG_NONE),
513 kMemoryCheckFailedRegex); 613 kMemoryCheckFailedRegex);
514 614
515 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h)); 615 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h));
516 } 616 }
517 } 617 }
518 618
519 // TODO(vtl): test |Wait()| and |WaitMany()| properly 619 // TODO(vtl): test |Wait()| and |WaitMany()| properly
520 // - including |WaitMany()| with the same handle more than once (with 620 // - including |WaitMany()| with the same handle more than once (with
521 // same/different signals) 621 // same/different signals)
522 622
523 TEST_F(CoreTest, MessagePipe) { 623 TEST_F(CoreTest, MessagePipe) {
524 MojoHandle h[2]; 624 MojoHandle h[2];
525 MojoHandleSignalsState hss[2]; 625 MojoHandleSignalsState hss[2];
526 uint32_t result_index; 626 uint32_t result_index;
527 627
528 EXPECT_EQ(MOJO_RESULT_OK, 628 EXPECT_EQ(
529 core()->CreateMessagePipe(NullUserPointer(), MakeUserPointer(&h[0]), 629 MOJO_RESULT_OK,
530 MakeUserPointer(&h[1]))); 630 core()->CreateMessagePipe(
631 NullUserPointer(), MakeUserPointer(&h[0]), MakeUserPointer(&h[1])));
531 // Should get two distinct, valid handles. 632 // Should get two distinct, valid handles.
532 EXPECT_NE(h[0], MOJO_HANDLE_INVALID); 633 EXPECT_NE(h[0], MOJO_HANDLE_INVALID);
533 EXPECT_NE(h[1], MOJO_HANDLE_INVALID); 634 EXPECT_NE(h[1], MOJO_HANDLE_INVALID);
534 EXPECT_NE(h[0], h[1]); 635 EXPECT_NE(h[0], h[1]);
535 636
536 // Neither should be readable. 637 // Neither should be readable.
537 MojoHandleSignals signals[2] = {MOJO_HANDLE_SIGNAL_READABLE, 638 MojoHandleSignals signals[2] = {MOJO_HANDLE_SIGNAL_READABLE,
538 MOJO_HANDLE_SIGNAL_READABLE}; 639 MOJO_HANDLE_SIGNAL_READABLE};
539 result_index = static_cast<uint32_t>(-1); 640 result_index = static_cast<uint32_t>(-1);
540 hss[0] = kEmptyMojoHandleSignalsState; 641 hss[0] = kEmptyMojoHandleSignalsState;
541 hss[1] = kEmptyMojoHandleSignalsState; 642 hss[1] = kEmptyMojoHandleSignalsState;
542 EXPECT_EQ( 643 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED,
543 MOJO_RESULT_DEADLINE_EXCEEDED, 644 core()->WaitMany(MakeUserPointer(h),
544 core()->WaitMany(MakeUserPointer(h), MakeUserPointer(signals), 2, 0, 645 MakeUserPointer(signals),
545 MakeUserPointer(&result_index), MakeUserPointer(hss))); 646 2,
647 0,
648 MakeUserPointer(&result_index),
649 MakeUserPointer(hss)));
546 EXPECT_EQ(static_cast<uint32_t>(-1), result_index); 650 EXPECT_EQ(static_cast<uint32_t>(-1), result_index);
547 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss[0].satisfied_signals); 651 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss[0].satisfied_signals);
548 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 652 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
549 hss[0].satisfiable_signals); 653 hss[0].satisfiable_signals);
550 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss[1].satisfied_signals); 654 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss[1].satisfied_signals);
551 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 655 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
552 hss[1].satisfiable_signals); 656 hss[1].satisfiable_signals);
553 657
554 // Try to read anyway. 658 // Try to read anyway.
555 char buffer[1] = {'a'}; 659 char buffer[1] = {'a'};
556 uint32_t buffer_size = 1; 660 uint32_t buffer_size = 1;
557 EXPECT_EQ( 661 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT,
558 MOJO_RESULT_SHOULD_WAIT, 662 core()->ReadMessage(h[0],
559 core()->ReadMessage(h[0], UserPointer<void>(buffer), 663 UserPointer<void>(buffer),
560 MakeUserPointer(&buffer_size), NullUserPointer(), 664 MakeUserPointer(&buffer_size),
561 NullUserPointer(), MOJO_READ_MESSAGE_FLAG_NONE)); 665 NullUserPointer(),
666 NullUserPointer(),
667 MOJO_READ_MESSAGE_FLAG_NONE));
562 // Check that it left its inputs alone. 668 // Check that it left its inputs alone.
563 EXPECT_EQ('a', buffer[0]); 669 EXPECT_EQ('a', buffer[0]);
564 EXPECT_EQ(1u, buffer_size); 670 EXPECT_EQ(1u, buffer_size);
565 671
566 // Both should be writable. 672 // Both should be writable.
567 hss[0] = kEmptyMojoHandleSignalsState; 673 hss[0] = kEmptyMojoHandleSignalsState;
568 EXPECT_EQ(MOJO_RESULT_OK, core()->Wait(h[0], MOJO_HANDLE_SIGNAL_WRITABLE, 674 EXPECT_EQ(MOJO_RESULT_OK,
569 1000000000, MakeUserPointer(&hss[0]))); 675 core()->Wait(h[0],
676 MOJO_HANDLE_SIGNAL_WRITABLE,
677 1000000000,
678 MakeUserPointer(&hss[0])));
570 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss[0].satisfied_signals); 679 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss[0].satisfied_signals);
571 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 680 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
572 hss[0].satisfiable_signals); 681 hss[0].satisfiable_signals);
573 hss[0] = kEmptyMojoHandleSignalsState; 682 hss[0] = kEmptyMojoHandleSignalsState;
574 EXPECT_EQ(MOJO_RESULT_OK, core()->Wait(h[1], MOJO_HANDLE_SIGNAL_WRITABLE, 683 EXPECT_EQ(MOJO_RESULT_OK,
575 1000000000, MakeUserPointer(&hss[0]))); 684 core()->Wait(h[1],
685 MOJO_HANDLE_SIGNAL_WRITABLE,
686 1000000000,
687 MakeUserPointer(&hss[0])));
576 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss[0].satisfied_signals); 688 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss[0].satisfied_signals);
577 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 689 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
578 hss[0].satisfiable_signals); 690 hss[0].satisfiable_signals);
579 691
580 // Also check that |h[1]| is writable using |WaitMany()|. 692 // Also check that |h[1]| is writable using |WaitMany()|.
581 signals[0] = MOJO_HANDLE_SIGNAL_READABLE; 693 signals[0] = MOJO_HANDLE_SIGNAL_READABLE;
582 signals[1] = MOJO_HANDLE_SIGNAL_WRITABLE; 694 signals[1] = MOJO_HANDLE_SIGNAL_WRITABLE;
583 result_index = static_cast<uint32_t>(-1); 695 result_index = static_cast<uint32_t>(-1);
584 hss[0] = kEmptyMojoHandleSignalsState; 696 hss[0] = kEmptyMojoHandleSignalsState;
585 hss[1] = kEmptyMojoHandleSignalsState; 697 hss[1] = kEmptyMojoHandleSignalsState;
586 EXPECT_EQ( 698 EXPECT_EQ(MOJO_RESULT_OK,
587 MOJO_RESULT_OK, 699 core()->WaitMany(MakeUserPointer(h),
588 core()->WaitMany(MakeUserPointer(h), MakeUserPointer(signals), 2, 700 MakeUserPointer(signals),
589 MOJO_DEADLINE_INDEFINITE, MakeUserPointer(&result_index), 701 2,
590 MakeUserPointer(hss))); 702 MOJO_DEADLINE_INDEFINITE,
703 MakeUserPointer(&result_index),
704 MakeUserPointer(hss)));
591 EXPECT_EQ(1u, result_index); 705 EXPECT_EQ(1u, result_index);
592 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss[0].satisfied_signals); 706 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss[0].satisfied_signals);
593 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 707 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
594 hss[0].satisfiable_signals); 708 hss[0].satisfiable_signals);
595 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss[1].satisfied_signals); 709 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss[1].satisfied_signals);
596 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 710 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
597 hss[1].satisfiable_signals); 711 hss[1].satisfiable_signals);
598 712
599 // Write to |h[1]|. 713 // Write to |h[1]|.
600 buffer[0] = 'b'; 714 buffer[0] = 'b';
601 EXPECT_EQ( 715 EXPECT_EQ(MOJO_RESULT_OK,
602 MOJO_RESULT_OK, 716 core()->WriteMessage(h[1],
603 core()->WriteMessage(h[1], UserPointer<const void>(buffer), 1, 717 UserPointer<const void>(buffer),
604 NullUserPointer(), 0, MOJO_WRITE_MESSAGE_FLAG_NONE)); 718 1,
719 NullUserPointer(),
720 0,
721 MOJO_WRITE_MESSAGE_FLAG_NONE));
605 722
606 // Check that |h[0]| is now readable. 723 // Check that |h[0]| is now readable.
607 signals[0] = MOJO_HANDLE_SIGNAL_READABLE; 724 signals[0] = MOJO_HANDLE_SIGNAL_READABLE;
608 signals[1] = MOJO_HANDLE_SIGNAL_READABLE; 725 signals[1] = MOJO_HANDLE_SIGNAL_READABLE;
609 result_index = static_cast<uint32_t>(-1); 726 result_index = static_cast<uint32_t>(-1);
610 hss[0] = kEmptyMojoHandleSignalsState; 727 hss[0] = kEmptyMojoHandleSignalsState;
611 hss[1] = kEmptyMojoHandleSignalsState; 728 hss[1] = kEmptyMojoHandleSignalsState;
612 EXPECT_EQ( 729 EXPECT_EQ(MOJO_RESULT_OK,
613 MOJO_RESULT_OK, 730 core()->WaitMany(MakeUserPointer(h),
614 core()->WaitMany(MakeUserPointer(h), MakeUserPointer(signals), 2, 731 MakeUserPointer(signals),
615 MOJO_DEADLINE_INDEFINITE, MakeUserPointer(&result_index), 732 2,
616 MakeUserPointer(hss))); 733 MOJO_DEADLINE_INDEFINITE,
734 MakeUserPointer(&result_index),
735 MakeUserPointer(hss)));
617 EXPECT_EQ(0u, result_index); 736 EXPECT_EQ(0u, result_index);
618 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 737 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
619 hss[0].satisfied_signals); 738 hss[0].satisfied_signals);
620 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 739 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
621 hss[0].satisfiable_signals); 740 hss[0].satisfiable_signals);
622 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss[1].satisfied_signals); 741 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss[1].satisfied_signals);
623 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 742 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
624 hss[1].satisfiable_signals); 743 hss[1].satisfiable_signals);
625 744
626 // Read from |h[0]|. 745 // Read from |h[0]|.
627 // First, get only the size. 746 // First, get only the size.
628 buffer_size = 0; 747 buffer_size = 0;
629 EXPECT_EQ( 748 EXPECT_EQ(MOJO_RESULT_RESOURCE_EXHAUSTED,
630 MOJO_RESULT_RESOURCE_EXHAUSTED, 749 core()->ReadMessage(h[0],
631 core()->ReadMessage(h[0], NullUserPointer(), 750 NullUserPointer(),
632 MakeUserPointer(&buffer_size), NullUserPointer(), 751 MakeUserPointer(&buffer_size),
633 NullUserPointer(), MOJO_READ_MESSAGE_FLAG_NONE)); 752 NullUserPointer(),
753 NullUserPointer(),
754 MOJO_READ_MESSAGE_FLAG_NONE));
634 EXPECT_EQ(1u, buffer_size); 755 EXPECT_EQ(1u, buffer_size);
635 // Then actually read it. 756 // Then actually read it.
636 buffer[0] = 'c'; 757 buffer[0] = 'c';
637 buffer_size = 1; 758 buffer_size = 1;
638 EXPECT_EQ( 759 EXPECT_EQ(MOJO_RESULT_OK,
639 MOJO_RESULT_OK, 760 core()->ReadMessage(h[0],
640 core()->ReadMessage(h[0], UserPointer<void>(buffer), 761 UserPointer<void>(buffer),
641 MakeUserPointer(&buffer_size), NullUserPointer(), 762 MakeUserPointer(&buffer_size),
642 NullUserPointer(), MOJO_READ_MESSAGE_FLAG_NONE)); 763 NullUserPointer(),
764 NullUserPointer(),
765 MOJO_READ_MESSAGE_FLAG_NONE));
643 EXPECT_EQ('b', buffer[0]); 766 EXPECT_EQ('b', buffer[0]);
644 EXPECT_EQ(1u, buffer_size); 767 EXPECT_EQ(1u, buffer_size);
645 768
646 // |h[0]| should no longer be readable. 769 // |h[0]| should no longer be readable.
647 hss[0] = kEmptyMojoHandleSignalsState; 770 hss[0] = kEmptyMojoHandleSignalsState;
648 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, 771 EXPECT_EQ(
649 core()->Wait(h[0], MOJO_HANDLE_SIGNAL_READABLE, 0, 772 MOJO_RESULT_DEADLINE_EXCEEDED,
650 MakeUserPointer(&hss[0]))); 773 core()->Wait(
774 h[0], MOJO_HANDLE_SIGNAL_READABLE, 0, MakeUserPointer(&hss[0])));
651 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss[0].satisfied_signals); 775 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss[0].satisfied_signals);
652 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 776 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
653 hss[0].satisfiable_signals); 777 hss[0].satisfiable_signals);
654 778
655 // Write to |h[0]|. 779 // Write to |h[0]|.
656 buffer[0] = 'd'; 780 buffer[0] = 'd';
657 EXPECT_EQ( 781 EXPECT_EQ(MOJO_RESULT_OK,
658 MOJO_RESULT_OK, 782 core()->WriteMessage(h[0],
659 core()->WriteMessage(h[0], UserPointer<const void>(buffer), 1, 783 UserPointer<const void>(buffer),
660 NullUserPointer(), 0, MOJO_WRITE_MESSAGE_FLAG_NONE)); 784 1,
785 NullUserPointer(),
786 0,
787 MOJO_WRITE_MESSAGE_FLAG_NONE));
661 788
662 // Close |h[0]|. 789 // Close |h[0]|.
663 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h[0])); 790 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h[0]));
664 791
665 // Check that |h[1]| is no longer writable (and will never be). 792 // Check that |h[1]| is no longer writable (and will never be).
666 hss[0] = kEmptyMojoHandleSignalsState; 793 hss[0] = kEmptyMojoHandleSignalsState;
667 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, 794 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
668 core()->Wait(h[1], MOJO_HANDLE_SIGNAL_WRITABLE, 1000000000, 795 core()->Wait(h[1],
796 MOJO_HANDLE_SIGNAL_WRITABLE,
797 1000000000,
669 MakeUserPointer(&hss[0]))); 798 MakeUserPointer(&hss[0])));
670 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss[0].satisfied_signals); 799 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss[0].satisfied_signals);
671 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss[0].satisfiable_signals); 800 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss[0].satisfiable_signals);
672 801
673 // Check that |h[1]| is still readable (for the moment). 802 // Check that |h[1]| is still readable (for the moment).
674 hss[0] = kEmptyMojoHandleSignalsState; 803 hss[0] = kEmptyMojoHandleSignalsState;
675 EXPECT_EQ(MOJO_RESULT_OK, core()->Wait(h[1], MOJO_HANDLE_SIGNAL_READABLE, 804 EXPECT_EQ(MOJO_RESULT_OK,
676 1000000000, MakeUserPointer(&hss[0]))); 805 core()->Wait(h[1],
806 MOJO_HANDLE_SIGNAL_READABLE,
807 1000000000,
808 MakeUserPointer(&hss[0])));
677 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss[0].satisfied_signals); 809 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss[0].satisfied_signals);
678 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss[0].satisfiable_signals); 810 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss[0].satisfiable_signals);
679 811
680 // Discard a message from |h[1]|. 812 // Discard a message from |h[1]|.
681 EXPECT_EQ(MOJO_RESULT_RESOURCE_EXHAUSTED, 813 EXPECT_EQ(MOJO_RESULT_RESOURCE_EXHAUSTED,
682 core()->ReadMessage(h[1], NullUserPointer(), NullUserPointer(), 814 core()->ReadMessage(h[1],
683 NullUserPointer(), NullUserPointer(), 815 NullUserPointer(),
816 NullUserPointer(),
817 NullUserPointer(),
818 NullUserPointer(),
684 MOJO_READ_MESSAGE_FLAG_MAY_DISCARD)); 819 MOJO_READ_MESSAGE_FLAG_MAY_DISCARD));
685 820
686 // |h[1]| is no longer readable (and will never be). 821 // |h[1]| is no longer readable (and will never be).
687 hss[0] = kFullMojoHandleSignalsState; 822 hss[0] = kFullMojoHandleSignalsState;
688 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, 823 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
689 core()->Wait(h[1], MOJO_HANDLE_SIGNAL_READABLE, 1000000000, 824 core()->Wait(h[1],
825 MOJO_HANDLE_SIGNAL_READABLE,
826 1000000000,
690 MakeUserPointer(&hss[0]))); 827 MakeUserPointer(&hss[0])));
691 EXPECT_EQ(0u, hss[0].satisfied_signals); 828 EXPECT_EQ(0u, hss[0].satisfied_signals);
692 EXPECT_EQ(0u, hss[0].satisfiable_signals); 829 EXPECT_EQ(0u, hss[0].satisfiable_signals);
693 830
694 // Try writing to |h[1]|. 831 // Try writing to |h[1]|.
695 buffer[0] = 'e'; 832 buffer[0] = 'e';
696 EXPECT_EQ( 833 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
697 MOJO_RESULT_FAILED_PRECONDITION, 834 core()->WriteMessage(h[1],
698 core()->WriteMessage(h[1], UserPointer<const void>(buffer), 1, 835 UserPointer<const void>(buffer),
699 NullUserPointer(), 0, MOJO_WRITE_MESSAGE_FLAG_NONE)); 836 1,
837 NullUserPointer(),
838 0,
839 MOJO_WRITE_MESSAGE_FLAG_NONE));
700 840
701 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h[1])); 841 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h[1]));
702 } 842 }
703 843
704 // Tests passing a message pipe handle. 844 // Tests passing a message pipe handle.
705 TEST_F(CoreTest, MessagePipeBasicLocalHandlePassing1) { 845 TEST_F(CoreTest, MessagePipeBasicLocalHandlePassing1) {
706 const char kHello[] = "hello"; 846 const char kHello[] = "hello";
707 const uint32_t kHelloSize = static_cast<uint32_t>(sizeof(kHello)); 847 const uint32_t kHelloSize = static_cast<uint32_t>(sizeof(kHello));
708 const char kWorld[] = "world!!!"; 848 const char kWorld[] = "world!!!";
709 const uint32_t kWorldSize = static_cast<uint32_t>(sizeof(kWorld)); 849 const uint32_t kWorldSize = static_cast<uint32_t>(sizeof(kWorld));
710 char buffer[100]; 850 char buffer[100];
711 const uint32_t kBufferSize = static_cast<uint32_t>(sizeof(buffer)); 851 const uint32_t kBufferSize = static_cast<uint32_t>(sizeof(buffer));
712 uint32_t num_bytes; 852 uint32_t num_bytes;
713 MojoHandle handles[10]; 853 MojoHandle handles[10];
714 uint32_t num_handles; 854 uint32_t num_handles;
715 MojoHandleSignalsState hss; 855 MojoHandleSignalsState hss;
716 MojoHandle h_received; 856 MojoHandle h_received;
717 857
718 MojoHandle h_passing[2]; 858 MojoHandle h_passing[2];
719 EXPECT_EQ(MOJO_RESULT_OK, 859 EXPECT_EQ(MOJO_RESULT_OK,
720 core()->CreateMessagePipe(NullUserPointer(), 860 core()->CreateMessagePipe(NullUserPointer(),
721 MakeUserPointer(&h_passing[0]), 861 MakeUserPointer(&h_passing[0]),
722 MakeUserPointer(&h_passing[1]))); 862 MakeUserPointer(&h_passing[1])));
723 863
724 // Make sure that |h_passing[]| work properly. 864 // Make sure that |h_passing[]| work properly.
725 EXPECT_EQ(MOJO_RESULT_OK, 865 EXPECT_EQ(MOJO_RESULT_OK,
726 core()->WriteMessage(h_passing[0], UserPointer<const void>(kHello), 866 core()->WriteMessage(h_passing[0],
727 kHelloSize, NullUserPointer(), 0, 867 UserPointer<const void>(kHello),
868 kHelloSize,
869 NullUserPointer(),
870 0,
728 MOJO_WRITE_MESSAGE_FLAG_NONE)); 871 MOJO_WRITE_MESSAGE_FLAG_NONE));
729 hss = kEmptyMojoHandleSignalsState; 872 hss = kEmptyMojoHandleSignalsState;
730 EXPECT_EQ(MOJO_RESULT_OK, 873 EXPECT_EQ(MOJO_RESULT_OK,
731 core()->Wait(h_passing[1], MOJO_HANDLE_SIGNAL_READABLE, 1000000000, 874 core()->Wait(h_passing[1],
875 MOJO_HANDLE_SIGNAL_READABLE,
876 1000000000,
732 MakeUserPointer(&hss))); 877 MakeUserPointer(&hss)));
733 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 878 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
734 hss.satisfied_signals); 879 hss.satisfied_signals);
735 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 880 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
736 hss.satisfiable_signals); 881 hss.satisfiable_signals);
737 num_bytes = kBufferSize; 882 num_bytes = kBufferSize;
738 num_handles = arraysize(handles); 883 num_handles = arraysize(handles);
739 EXPECT_EQ(MOJO_RESULT_OK, 884 EXPECT_EQ(MOJO_RESULT_OK,
740 core()->ReadMessage( 885 core()->ReadMessage(h_passing[1],
741 h_passing[1], UserPointer<void>(buffer), 886 UserPointer<void>(buffer),
742 MakeUserPointer(&num_bytes), MakeUserPointer(handles), 887 MakeUserPointer(&num_bytes),
743 MakeUserPointer(&num_handles), MOJO_READ_MESSAGE_FLAG_NONE)); 888 MakeUserPointer(handles),
889 MakeUserPointer(&num_handles),
890 MOJO_READ_MESSAGE_FLAG_NONE));
744 EXPECT_EQ(kHelloSize, num_bytes); 891 EXPECT_EQ(kHelloSize, num_bytes);
745 EXPECT_STREQ(kHello, buffer); 892 EXPECT_STREQ(kHello, buffer);
746 EXPECT_EQ(0u, num_handles); 893 EXPECT_EQ(0u, num_handles);
747 894
748 // Make sure that you can't pass either of the message pipe's handles over 895 // Make sure that you can't pass either of the message pipe's handles over
749 // itself. 896 // itself.
750 EXPECT_EQ(MOJO_RESULT_BUSY, 897 EXPECT_EQ(MOJO_RESULT_BUSY,
751 core()->WriteMessage(h_passing[0], UserPointer<const void>(kHello), 898 core()->WriteMessage(h_passing[0],
752 kHelloSize, MakeUserPointer(&h_passing[0]), 1, 899 UserPointer<const void>(kHello),
900 kHelloSize,
901 MakeUserPointer(&h_passing[0]),
902 1,
753 MOJO_WRITE_MESSAGE_FLAG_NONE)); 903 MOJO_WRITE_MESSAGE_FLAG_NONE));
754 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 904 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
755 core()->WriteMessage(h_passing[0], UserPointer<const void>(kHello), 905 core()->WriteMessage(h_passing[0],
756 kHelloSize, MakeUserPointer(&h_passing[1]), 1, 906 UserPointer<const void>(kHello),
907 kHelloSize,
908 MakeUserPointer(&h_passing[1]),
909 1,
757 MOJO_WRITE_MESSAGE_FLAG_NONE)); 910 MOJO_WRITE_MESSAGE_FLAG_NONE));
758 911
759 MojoHandle h_passed[2]; 912 MojoHandle h_passed[2];
760 EXPECT_EQ(MOJO_RESULT_OK, 913 EXPECT_EQ(MOJO_RESULT_OK,
761 core()->CreateMessagePipe(NullUserPointer(), 914 core()->CreateMessagePipe(NullUserPointer(),
762 MakeUserPointer(&h_passed[0]), 915 MakeUserPointer(&h_passed[0]),
763 MakeUserPointer(&h_passed[1]))); 916 MakeUserPointer(&h_passed[1])));
764 917
765 // Make sure that |h_passed[]| work properly. 918 // Make sure that |h_passed[]| work properly.
766 EXPECT_EQ(MOJO_RESULT_OK, 919 EXPECT_EQ(MOJO_RESULT_OK,
767 core()->WriteMessage(h_passed[0], UserPointer<const void>(kHello), 920 core()->WriteMessage(h_passed[0],
768 kHelloSize, NullUserPointer(), 0, 921 UserPointer<const void>(kHello),
922 kHelloSize,
923 NullUserPointer(),
924 0,
769 MOJO_WRITE_MESSAGE_FLAG_NONE)); 925 MOJO_WRITE_MESSAGE_FLAG_NONE));
770 hss = kEmptyMojoHandleSignalsState; 926 hss = kEmptyMojoHandleSignalsState;
771 EXPECT_EQ(MOJO_RESULT_OK, 927 EXPECT_EQ(MOJO_RESULT_OK,
772 core()->Wait(h_passed[1], MOJO_HANDLE_SIGNAL_READABLE, 1000000000, 928 core()->Wait(h_passed[1],
929 MOJO_HANDLE_SIGNAL_READABLE,
930 1000000000,
773 MakeUserPointer(&hss))); 931 MakeUserPointer(&hss)));
774 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 932 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
775 hss.satisfied_signals); 933 hss.satisfied_signals);
776 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 934 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
777 hss.satisfiable_signals); 935 hss.satisfiable_signals);
778 num_bytes = kBufferSize; 936 num_bytes = kBufferSize;
779 num_handles = arraysize(handles); 937 num_handles = arraysize(handles);
780 EXPECT_EQ(MOJO_RESULT_OK, 938 EXPECT_EQ(MOJO_RESULT_OK,
781 core()->ReadMessage( 939 core()->ReadMessage(h_passed[1],
782 h_passed[1], UserPointer<void>(buffer), 940 UserPointer<void>(buffer),
783 MakeUserPointer(&num_bytes), MakeUserPointer(handles), 941 MakeUserPointer(&num_bytes),
784 MakeUserPointer(&num_handles), MOJO_READ_MESSAGE_FLAG_NONE)); 942 MakeUserPointer(handles),
943 MakeUserPointer(&num_handles),
944 MOJO_READ_MESSAGE_FLAG_NONE));
785 EXPECT_EQ(kHelloSize, num_bytes); 945 EXPECT_EQ(kHelloSize, num_bytes);
786 EXPECT_STREQ(kHello, buffer); 946 EXPECT_STREQ(kHello, buffer);
787 EXPECT_EQ(0u, num_handles); 947 EXPECT_EQ(0u, num_handles);
788 948
789 // Send |h_passed[1]| from |h_passing[0]| to |h_passing[1]|. 949 // Send |h_passed[1]| from |h_passing[0]| to |h_passing[1]|.
790 EXPECT_EQ(MOJO_RESULT_OK, 950 EXPECT_EQ(MOJO_RESULT_OK,
791 core()->WriteMessage(h_passing[0], UserPointer<const void>(kWorld), 951 core()->WriteMessage(h_passing[0],
792 kWorldSize, MakeUserPointer(&h_passed[1]), 1, 952 UserPointer<const void>(kWorld),
953 kWorldSize,
954 MakeUserPointer(&h_passed[1]),
955 1,
793 MOJO_WRITE_MESSAGE_FLAG_NONE)); 956 MOJO_WRITE_MESSAGE_FLAG_NONE));
794 hss = kEmptyMojoHandleSignalsState; 957 hss = kEmptyMojoHandleSignalsState;
795 EXPECT_EQ(MOJO_RESULT_OK, 958 EXPECT_EQ(MOJO_RESULT_OK,
796 core()->Wait(h_passing[1], MOJO_HANDLE_SIGNAL_READABLE, 1000000000, 959 core()->Wait(h_passing[1],
960 MOJO_HANDLE_SIGNAL_READABLE,
961 1000000000,
797 MakeUserPointer(&hss))); 962 MakeUserPointer(&hss)));
798 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 963 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
799 hss.satisfied_signals); 964 hss.satisfied_signals);
800 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 965 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
801 hss.satisfiable_signals); 966 hss.satisfiable_signals);
802 num_bytes = kBufferSize; 967 num_bytes = kBufferSize;
803 num_handles = arraysize(handles); 968 num_handles = arraysize(handles);
804 EXPECT_EQ(MOJO_RESULT_OK, 969 EXPECT_EQ(MOJO_RESULT_OK,
805 core()->ReadMessage( 970 core()->ReadMessage(h_passing[1],
806 h_passing[1], UserPointer<void>(buffer), 971 UserPointer<void>(buffer),
807 MakeUserPointer(&num_bytes), MakeUserPointer(handles), 972 MakeUserPointer(&num_bytes),
808 MakeUserPointer(&num_handles), MOJO_READ_MESSAGE_FLAG_NONE)); 973 MakeUserPointer(handles),
974 MakeUserPointer(&num_handles),
975 MOJO_READ_MESSAGE_FLAG_NONE));
809 EXPECT_EQ(kWorldSize, num_bytes); 976 EXPECT_EQ(kWorldSize, num_bytes);
810 EXPECT_STREQ(kWorld, buffer); 977 EXPECT_STREQ(kWorld, buffer);
811 EXPECT_EQ(1u, num_handles); 978 EXPECT_EQ(1u, num_handles);
812 h_received = handles[0]; 979 h_received = handles[0];
813 EXPECT_NE(h_received, MOJO_HANDLE_INVALID); 980 EXPECT_NE(h_received, MOJO_HANDLE_INVALID);
814 EXPECT_NE(h_received, h_passing[0]); 981 EXPECT_NE(h_received, h_passing[0]);
815 EXPECT_NE(h_received, h_passing[1]); 982 EXPECT_NE(h_received, h_passing[1]);
816 EXPECT_NE(h_received, h_passed[0]); 983 EXPECT_NE(h_received, h_passed[0]);
817 984
818 // Note: We rely on the Mojo system not re-using handle values very often. 985 // Note: We rely on the Mojo system not re-using handle values very often.
819 EXPECT_NE(h_received, h_passed[1]); 986 EXPECT_NE(h_received, h_passed[1]);
820 987
821 // |h_passed[1]| should no longer be valid; check that trying to close it 988 // |h_passed[1]| should no longer be valid; check that trying to close it
822 // fails. See above note. 989 // fails. See above note.
823 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, core()->Close(h_passed[1])); 990 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, core()->Close(h_passed[1]));
824 991
825 // Write to |h_passed[0]|. Should receive on |h_received|. 992 // Write to |h_passed[0]|. Should receive on |h_received|.
826 EXPECT_EQ(MOJO_RESULT_OK, 993 EXPECT_EQ(MOJO_RESULT_OK,
827 core()->WriteMessage(h_passed[0], UserPointer<const void>(kHello), 994 core()->WriteMessage(h_passed[0],
828 kHelloSize, NullUserPointer(), 0, 995 UserPointer<const void>(kHello),
996 kHelloSize,
997 NullUserPointer(),
998 0,
829 MOJO_WRITE_MESSAGE_FLAG_NONE)); 999 MOJO_WRITE_MESSAGE_FLAG_NONE));
830 hss = kEmptyMojoHandleSignalsState; 1000 hss = kEmptyMojoHandleSignalsState;
831 EXPECT_EQ(MOJO_RESULT_OK, 1001 EXPECT_EQ(MOJO_RESULT_OK,
832 core()->Wait(h_received, MOJO_HANDLE_SIGNAL_READABLE, 1000000000, 1002 core()->Wait(h_received,
1003 MOJO_HANDLE_SIGNAL_READABLE,
1004 1000000000,
833 MakeUserPointer(&hss))); 1005 MakeUserPointer(&hss)));
834 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 1006 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
835 hss.satisfied_signals); 1007 hss.satisfied_signals);
836 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 1008 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
837 hss.satisfiable_signals); 1009 hss.satisfiable_signals);
838 num_bytes = kBufferSize; 1010 num_bytes = kBufferSize;
839 num_handles = arraysize(handles); 1011 num_handles = arraysize(handles);
840 EXPECT_EQ(MOJO_RESULT_OK, 1012 EXPECT_EQ(MOJO_RESULT_OK,
841 core()->ReadMessage( 1013 core()->ReadMessage(h_received,
842 h_received, UserPointer<void>(buffer), 1014 UserPointer<void>(buffer),
843 MakeUserPointer(&num_bytes), MakeUserPointer(handles), 1015 MakeUserPointer(&num_bytes),
844 MakeUserPointer(&num_handles), MOJO_READ_MESSAGE_FLAG_NONE)); 1016 MakeUserPointer(handles),
1017 MakeUserPointer(&num_handles),
1018 MOJO_READ_MESSAGE_FLAG_NONE));
845 EXPECT_EQ(kHelloSize, num_bytes); 1019 EXPECT_EQ(kHelloSize, num_bytes);
846 EXPECT_STREQ(kHello, buffer); 1020 EXPECT_STREQ(kHello, buffer);
847 EXPECT_EQ(0u, num_handles); 1021 EXPECT_EQ(0u, num_handles);
848 1022
849 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h_passing[0])); 1023 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h_passing[0]));
850 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h_passing[1])); 1024 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h_passing[1]));
851 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h_passed[0])); 1025 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h_passed[0]));
852 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h_received)); 1026 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h_received));
853 } 1027 }
854 1028
855 TEST_F(CoreTest, DataPipe) { 1029 TEST_F(CoreTest, DataPipe) {
856 MojoHandle ph, ch; // p is for producer and c is for consumer. 1030 MojoHandle ph, ch; // p is for producer and c is for consumer.
857 MojoHandleSignalsState hss; 1031 MojoHandleSignalsState hss;
858 1032
859 EXPECT_EQ(MOJO_RESULT_OK, 1033 EXPECT_EQ(MOJO_RESULT_OK,
860 core()->CreateDataPipe(NullUserPointer(), MakeUserPointer(&ph), 1034 core()->CreateDataPipe(
861 MakeUserPointer(&ch))); 1035 NullUserPointer(), MakeUserPointer(&ph), MakeUserPointer(&ch)));
862 // Should get two distinct, valid handles. 1036 // Should get two distinct, valid handles.
863 EXPECT_NE(ph, MOJO_HANDLE_INVALID); 1037 EXPECT_NE(ph, MOJO_HANDLE_INVALID);
864 EXPECT_NE(ch, MOJO_HANDLE_INVALID); 1038 EXPECT_NE(ch, MOJO_HANDLE_INVALID);
865 EXPECT_NE(ph, ch); 1039 EXPECT_NE(ph, ch);
866 1040
867 // Producer should be never-readable, but already writable. 1041 // Producer should be never-readable, but already writable.
868 hss = kEmptyMojoHandleSignalsState; 1042 hss = kEmptyMojoHandleSignalsState;
869 EXPECT_EQ( 1043 EXPECT_EQ(
870 MOJO_RESULT_FAILED_PRECONDITION, 1044 MOJO_RESULT_FAILED_PRECONDITION,
871 core()->Wait(ph, MOJO_HANDLE_SIGNAL_READABLE, 0, MakeUserPointer(&hss))); 1045 core()->Wait(ph, MOJO_HANDLE_SIGNAL_READABLE, 0, MakeUserPointer(&hss)));
872 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals); 1046 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals);
873 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfiable_signals); 1047 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfiable_signals);
874 hss = kEmptyMojoHandleSignalsState; 1048 hss = kEmptyMojoHandleSignalsState;
875 EXPECT_EQ(MOJO_RESULT_OK, core()->Wait(ph, MOJO_HANDLE_SIGNAL_WRITABLE, 0, 1049 EXPECT_EQ(
876 MakeUserPointer(&hss))); 1050 MOJO_RESULT_OK,
1051 core()->Wait(ph, MOJO_HANDLE_SIGNAL_WRITABLE, 0, MakeUserPointer(&hss)));
877 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals); 1052 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals);
878 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfiable_signals); 1053 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfiable_signals);
879 1054
880 // Consumer should be never-writable, and not yet readable. 1055 // Consumer should be never-writable, and not yet readable.
881 hss = kFullMojoHandleSignalsState; 1056 hss = kFullMojoHandleSignalsState;
882 EXPECT_EQ( 1057 EXPECT_EQ(
883 MOJO_RESULT_FAILED_PRECONDITION, 1058 MOJO_RESULT_FAILED_PRECONDITION,
884 core()->Wait(ch, MOJO_HANDLE_SIGNAL_WRITABLE, 0, MakeUserPointer(&hss))); 1059 core()->Wait(ch, MOJO_HANDLE_SIGNAL_WRITABLE, 0, MakeUserPointer(&hss)));
885 EXPECT_EQ(0u, hss.satisfied_signals); 1060 EXPECT_EQ(0u, hss.satisfied_signals);
886 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfiable_signals); 1061 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfiable_signals);
887 hss = kFullMojoHandleSignalsState; 1062 hss = kFullMojoHandleSignalsState;
888 EXPECT_EQ( 1063 EXPECT_EQ(
889 MOJO_RESULT_DEADLINE_EXCEEDED, 1064 MOJO_RESULT_DEADLINE_EXCEEDED,
890 core()->Wait(ch, MOJO_HANDLE_SIGNAL_READABLE, 0, MakeUserPointer(&hss))); 1065 core()->Wait(ch, MOJO_HANDLE_SIGNAL_READABLE, 0, MakeUserPointer(&hss)));
891 EXPECT_EQ(0u, hss.satisfied_signals); 1066 EXPECT_EQ(0u, hss.satisfied_signals);
892 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfiable_signals); 1067 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfiable_signals);
893 1068
894 // Write. 1069 // Write.
895 char elements[2] = {'A', 'B'}; 1070 char elements[2] = {'A', 'B'};
896 uint32_t num_bytes = 2u; 1071 uint32_t num_bytes = 2u;
897 EXPECT_EQ(MOJO_RESULT_OK, 1072 EXPECT_EQ(MOJO_RESULT_OK,
898 core()->WriteData(ph, UserPointer<const void>(elements), 1073 core()->WriteData(ph,
1074 UserPointer<const void>(elements),
899 MakeUserPointer(&num_bytes), 1075 MakeUserPointer(&num_bytes),
900 MOJO_WRITE_DATA_FLAG_NONE)); 1076 MOJO_WRITE_DATA_FLAG_NONE));
901 EXPECT_EQ(2u, num_bytes); 1077 EXPECT_EQ(2u, num_bytes);
902 1078
903 // Consumer should now be readable. 1079 // Consumer should now be readable.
904 hss = kEmptyMojoHandleSignalsState; 1080 hss = kEmptyMojoHandleSignalsState;
905 EXPECT_EQ(MOJO_RESULT_OK, core()->Wait(ch, MOJO_HANDLE_SIGNAL_READABLE, 0, 1081 EXPECT_EQ(
906 MakeUserPointer(&hss))); 1082 MOJO_RESULT_OK,
1083 core()->Wait(ch, MOJO_HANDLE_SIGNAL_READABLE, 0, MakeUserPointer(&hss)));
907 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals); 1084 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals);
908 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfiable_signals); 1085 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfiable_signals);
909 1086
910 // Peek one character. 1087 // Peek one character.
911 elements[0] = -1; 1088 elements[0] = -1;
912 elements[1] = -1; 1089 elements[1] = -1;
913 num_bytes = 1u; 1090 num_bytes = 1u;
914 EXPECT_EQ(MOJO_RESULT_OK, 1091 EXPECT_EQ(MOJO_RESULT_OK,
915 core()->ReadData( 1092 core()->ReadData(
916 ch, UserPointer<void>(elements), MakeUserPointer(&num_bytes), 1093 ch,
1094 UserPointer<void>(elements),
1095 MakeUserPointer(&num_bytes),
917 MOJO_READ_DATA_FLAG_NONE | MOJO_READ_DATA_FLAG_PEEK)); 1096 MOJO_READ_DATA_FLAG_NONE | MOJO_READ_DATA_FLAG_PEEK));
918 EXPECT_EQ('A', elements[0]); 1097 EXPECT_EQ('A', elements[0]);
919 EXPECT_EQ(-1, elements[1]); 1098 EXPECT_EQ(-1, elements[1]);
920 1099
921 // Read one character. 1100 // Read one character.
922 elements[0] = -1; 1101 elements[0] = -1;
923 elements[1] = -1; 1102 elements[1] = -1;
924 num_bytes = 1u; 1103 num_bytes = 1u;
925 EXPECT_EQ(MOJO_RESULT_OK, core()->ReadData(ch, UserPointer<void>(elements), 1104 EXPECT_EQ(MOJO_RESULT_OK,
926 MakeUserPointer(&num_bytes), 1105 core()->ReadData(ch,
927 MOJO_READ_DATA_FLAG_NONE)); 1106 UserPointer<void>(elements),
1107 MakeUserPointer(&num_bytes),
1108 MOJO_READ_DATA_FLAG_NONE));
928 EXPECT_EQ('A', elements[0]); 1109 EXPECT_EQ('A', elements[0]);
929 EXPECT_EQ(-1, elements[1]); 1110 EXPECT_EQ(-1, elements[1]);
930 1111
931 // Two-phase write. 1112 // Two-phase write.
932 void* write_ptr = nullptr; 1113 void* write_ptr = nullptr;
933 num_bytes = 0u; 1114 num_bytes = 0u;
934 ASSERT_EQ(MOJO_RESULT_OK, 1115 ASSERT_EQ(MOJO_RESULT_OK,
935 core()->BeginWriteData(ph, MakeUserPointer(&write_ptr), 1116 core()->BeginWriteData(ph,
1117 MakeUserPointer(&write_ptr),
936 MakeUserPointer(&num_bytes), 1118 MakeUserPointer(&num_bytes),
937 MOJO_WRITE_DATA_FLAG_NONE)); 1119 MOJO_WRITE_DATA_FLAG_NONE));
938 // We count on the default options providing a decent buffer size. 1120 // We count on the default options providing a decent buffer size.
939 ASSERT_GE(num_bytes, 3u); 1121 ASSERT_GE(num_bytes, 3u);
940 1122
941 // Trying to do a normal write during a two-phase write should fail. 1123 // Trying to do a normal write during a two-phase write should fail.
942 elements[0] = 'X'; 1124 elements[0] = 'X';
943 num_bytes = 1u; 1125 num_bytes = 1u;
944 EXPECT_EQ(MOJO_RESULT_BUSY, 1126 EXPECT_EQ(MOJO_RESULT_BUSY,
945 core()->WriteData(ph, UserPointer<const void>(elements), 1127 core()->WriteData(ph,
1128 UserPointer<const void>(elements),
946 MakeUserPointer(&num_bytes), 1129 MakeUserPointer(&num_bytes),
947 MOJO_WRITE_DATA_FLAG_NONE)); 1130 MOJO_WRITE_DATA_FLAG_NONE));
948 1131
949 // Actually write the data, and complete it now. 1132 // Actually write the data, and complete it now.
950 static_cast<char*>(write_ptr)[0] = 'C'; 1133 static_cast<char*>(write_ptr)[0] = 'C';
951 static_cast<char*>(write_ptr)[1] = 'D'; 1134 static_cast<char*>(write_ptr)[1] = 'D';
952 static_cast<char*>(write_ptr)[2] = 'E'; 1135 static_cast<char*>(write_ptr)[2] = 'E';
953 EXPECT_EQ(MOJO_RESULT_OK, core()->EndWriteData(ph, 3u)); 1136 EXPECT_EQ(MOJO_RESULT_OK, core()->EndWriteData(ph, 3u));
954 1137
955 // Query how much data we have. 1138 // Query how much data we have.
956 num_bytes = 0; 1139 num_bytes = 0;
957 EXPECT_EQ(MOJO_RESULT_OK, 1140 EXPECT_EQ(MOJO_RESULT_OK,
958 core()->ReadData(ch, NullUserPointer(), MakeUserPointer(&num_bytes), 1141 core()->ReadData(ch,
1142 NullUserPointer(),
1143 MakeUserPointer(&num_bytes),
959 MOJO_READ_DATA_FLAG_QUERY)); 1144 MOJO_READ_DATA_FLAG_QUERY));
960 EXPECT_EQ(4u, num_bytes); 1145 EXPECT_EQ(4u, num_bytes);
961 1146
962 // Try to query with peek. Should fail. 1147 // Try to query with peek. Should fail.
963 num_bytes = 0; 1148 num_bytes = 0;
964 EXPECT_EQ( 1149 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
965 MOJO_RESULT_INVALID_ARGUMENT, 1150 core()->ReadData(
966 core()->ReadData(ch, NullUserPointer(), MakeUserPointer(&num_bytes), 1151 ch,
967 MOJO_READ_DATA_FLAG_QUERY | MOJO_READ_DATA_FLAG_PEEK)); 1152 NullUserPointer(),
1153 MakeUserPointer(&num_bytes),
1154 MOJO_READ_DATA_FLAG_QUERY | MOJO_READ_DATA_FLAG_PEEK));
968 EXPECT_EQ(0u, num_bytes); 1155 EXPECT_EQ(0u, num_bytes);
969 1156
970 // Try to discard ten characters, in all-or-none mode. Should fail. 1157 // Try to discard ten characters, in all-or-none mode. Should fail.
971 num_bytes = 10; 1158 num_bytes = 10;
972 EXPECT_EQ(MOJO_RESULT_OUT_OF_RANGE, 1159 EXPECT_EQ(MOJO_RESULT_OUT_OF_RANGE,
973 core()->ReadData( 1160 core()->ReadData(
974 ch, NullUserPointer(), MakeUserPointer(&num_bytes), 1161 ch,
1162 NullUserPointer(),
1163 MakeUserPointer(&num_bytes),
975 MOJO_READ_DATA_FLAG_DISCARD | MOJO_READ_DATA_FLAG_ALL_OR_NONE)); 1164 MOJO_READ_DATA_FLAG_DISCARD | MOJO_READ_DATA_FLAG_ALL_OR_NONE));
976 1165
977 // Try to discard two characters, in peek mode. Should fail. 1166 // Try to discard two characters, in peek mode. Should fail.
978 num_bytes = 2; 1167 num_bytes = 2;
979 EXPECT_EQ( 1168 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
980 MOJO_RESULT_INVALID_ARGUMENT, 1169 core()->ReadData(
981 core()->ReadData(ch, NullUserPointer(), MakeUserPointer(&num_bytes), 1170 ch,
982 MOJO_READ_DATA_FLAG_DISCARD | MOJO_READ_DATA_FLAG_PEEK)); 1171 NullUserPointer(),
1172 MakeUserPointer(&num_bytes),
1173 MOJO_READ_DATA_FLAG_DISCARD | MOJO_READ_DATA_FLAG_PEEK));
983 1174
984 // Discard two characters. 1175 // Discard two characters.
985 num_bytes = 2; 1176 num_bytes = 2;
986 EXPECT_EQ(MOJO_RESULT_OK, 1177 EXPECT_EQ(MOJO_RESULT_OK,
987 core()->ReadData( 1178 core()->ReadData(
988 ch, NullUserPointer(), MakeUserPointer(&num_bytes), 1179 ch,
1180 NullUserPointer(),
1181 MakeUserPointer(&num_bytes),
989 MOJO_READ_DATA_FLAG_DISCARD | MOJO_READ_DATA_FLAG_ALL_OR_NONE)); 1182 MOJO_READ_DATA_FLAG_DISCARD | MOJO_READ_DATA_FLAG_ALL_OR_NONE));
990 1183
991 // Try a two-phase read of the remaining two bytes with peek. Should fail. 1184 // Try a two-phase read of the remaining two bytes with peek. Should fail.
992 const void* read_ptr = nullptr; 1185 const void* read_ptr = nullptr;
993 num_bytes = 2; 1186 num_bytes = 2;
994 ASSERT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 1187 ASSERT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
995 core()->BeginReadData(ch, MakeUserPointer(&read_ptr), 1188 core()->BeginReadData(ch,
1189 MakeUserPointer(&read_ptr),
996 MakeUserPointer(&num_bytes), 1190 MakeUserPointer(&num_bytes),
997 MOJO_READ_DATA_FLAG_PEEK)); 1191 MOJO_READ_DATA_FLAG_PEEK));
998 1192
999 // Read the remaining two characters, in two-phase mode (all-or-none). 1193 // Read the remaining two characters, in two-phase mode (all-or-none).
1000 num_bytes = 2; 1194 num_bytes = 2;
1001 ASSERT_EQ(MOJO_RESULT_OK, 1195 ASSERT_EQ(MOJO_RESULT_OK,
1002 core()->BeginReadData(ch, MakeUserPointer(&read_ptr), 1196 core()->BeginReadData(ch,
1197 MakeUserPointer(&read_ptr),
1003 MakeUserPointer(&num_bytes), 1198 MakeUserPointer(&num_bytes),
1004 MOJO_READ_DATA_FLAG_ALL_OR_NONE)); 1199 MOJO_READ_DATA_FLAG_ALL_OR_NONE));
1005 // Note: Count on still being able to do the contiguous read here. 1200 // Note: Count on still being able to do the contiguous read here.
1006 ASSERT_EQ(2u, num_bytes); 1201 ASSERT_EQ(2u, num_bytes);
1007 1202
1008 // Discarding right now should fail. 1203 // Discarding right now should fail.
1009 num_bytes = 1; 1204 num_bytes = 1;
1010 EXPECT_EQ(MOJO_RESULT_BUSY, 1205 EXPECT_EQ(MOJO_RESULT_BUSY,
1011 core()->ReadData(ch, NullUserPointer(), MakeUserPointer(&num_bytes), 1206 core()->ReadData(ch,
1207 NullUserPointer(),
1208 MakeUserPointer(&num_bytes),
1012 MOJO_READ_DATA_FLAG_DISCARD)); 1209 MOJO_READ_DATA_FLAG_DISCARD));
1013 1210
1014 // Actually check our data and end the two-phase read. 1211 // Actually check our data and end the two-phase read.
1015 EXPECT_EQ('D', static_cast<const char*>(read_ptr)[0]); 1212 EXPECT_EQ('D', static_cast<const char*>(read_ptr)[0]);
1016 EXPECT_EQ('E', static_cast<const char*>(read_ptr)[1]); 1213 EXPECT_EQ('E', static_cast<const char*>(read_ptr)[1]);
1017 EXPECT_EQ(MOJO_RESULT_OK, core()->EndReadData(ch, 2u)); 1214 EXPECT_EQ(MOJO_RESULT_OK, core()->EndReadData(ch, 2u));
1018 1215
1019 // Consumer should now be no longer readable. 1216 // Consumer should now be no longer readable.
1020 hss = kFullMojoHandleSignalsState; 1217 hss = kFullMojoHandleSignalsState;
1021 EXPECT_EQ( 1218 EXPECT_EQ(
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1054 MojoHandleSignalsState hss; 1251 MojoHandleSignalsState hss;
1055 1252
1056 MojoHandle h_passing[2]; 1253 MojoHandle h_passing[2];
1057 EXPECT_EQ(MOJO_RESULT_OK, 1254 EXPECT_EQ(MOJO_RESULT_OK,
1058 core()->CreateMessagePipe(NullUserPointer(), 1255 core()->CreateMessagePipe(NullUserPointer(),
1059 MakeUserPointer(&h_passing[0]), 1256 MakeUserPointer(&h_passing[0]),
1060 MakeUserPointer(&h_passing[1]))); 1257 MakeUserPointer(&h_passing[1])));
1061 1258
1062 MojoHandle ph, ch; 1259 MojoHandle ph, ch;
1063 EXPECT_EQ(MOJO_RESULT_OK, 1260 EXPECT_EQ(MOJO_RESULT_OK,
1064 core()->CreateDataPipe(NullUserPointer(), MakeUserPointer(&ph), 1261 core()->CreateDataPipe(
1065 MakeUserPointer(&ch))); 1262 NullUserPointer(), MakeUserPointer(&ph), MakeUserPointer(&ch)));
1066 1263
1067 // Send |ch| from |h_passing[0]| to |h_passing[1]|. 1264 // Send |ch| from |h_passing[0]| to |h_passing[1]|.
1068 EXPECT_EQ(MOJO_RESULT_OK, 1265 EXPECT_EQ(MOJO_RESULT_OK,
1069 core()->WriteMessage(h_passing[0], UserPointer<const void>(kHello), 1266 core()->WriteMessage(h_passing[0],
1070 kHelloSize, MakeUserPointer(&ch), 1, 1267 UserPointer<const void>(kHello),
1268 kHelloSize,
1269 MakeUserPointer(&ch),
1270 1,
1071 MOJO_WRITE_MESSAGE_FLAG_NONE)); 1271 MOJO_WRITE_MESSAGE_FLAG_NONE));
1072 hss = kEmptyMojoHandleSignalsState; 1272 hss = kEmptyMojoHandleSignalsState;
1073 EXPECT_EQ(MOJO_RESULT_OK, 1273 EXPECT_EQ(MOJO_RESULT_OK,
1074 core()->Wait(h_passing[1], MOJO_HANDLE_SIGNAL_READABLE, 1000000000, 1274 core()->Wait(h_passing[1],
1275 MOJO_HANDLE_SIGNAL_READABLE,
1276 1000000000,
1075 MakeUserPointer(&hss))); 1277 MakeUserPointer(&hss)));
1076 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 1278 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
1077 hss.satisfied_signals); 1279 hss.satisfied_signals);
1078 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 1280 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
1079 hss.satisfiable_signals); 1281 hss.satisfiable_signals);
1080 num_bytes = kBufferSize; 1282 num_bytes = kBufferSize;
1081 num_handles = arraysize(handles); 1283 num_handles = arraysize(handles);
1082 EXPECT_EQ(MOJO_RESULT_OK, 1284 EXPECT_EQ(MOJO_RESULT_OK,
1083 core()->ReadMessage( 1285 core()->ReadMessage(h_passing[1],
1084 h_passing[1], UserPointer<void>(buffer), 1286 UserPointer<void>(buffer),
1085 MakeUserPointer(&num_bytes), MakeUserPointer(handles), 1287 MakeUserPointer(&num_bytes),
1086 MakeUserPointer(&num_handles), MOJO_READ_MESSAGE_FLAG_NONE)); 1288 MakeUserPointer(handles),
1289 MakeUserPointer(&num_handles),
1290 MOJO_READ_MESSAGE_FLAG_NONE));
1087 EXPECT_EQ(kHelloSize, num_bytes); 1291 EXPECT_EQ(kHelloSize, num_bytes);
1088 EXPECT_STREQ(kHello, buffer); 1292 EXPECT_STREQ(kHello, buffer);
1089 EXPECT_EQ(1u, num_handles); 1293 EXPECT_EQ(1u, num_handles);
1090 MojoHandle ch_received = handles[0]; 1294 MojoHandle ch_received = handles[0];
1091 EXPECT_NE(ch_received, MOJO_HANDLE_INVALID); 1295 EXPECT_NE(ch_received, MOJO_HANDLE_INVALID);
1092 EXPECT_NE(ch_received, h_passing[0]); 1296 EXPECT_NE(ch_received, h_passing[0]);
1093 EXPECT_NE(ch_received, h_passing[1]); 1297 EXPECT_NE(ch_received, h_passing[1]);
1094 EXPECT_NE(ch_received, ph); 1298 EXPECT_NE(ch_received, ph);
1095 1299
1096 // Note: We rely on the Mojo system not re-using handle values very often. 1300 // Note: We rely on the Mojo system not re-using handle values very often.
1097 EXPECT_NE(ch_received, ch); 1301 EXPECT_NE(ch_received, ch);
1098 1302
1099 // |ch| should no longer be valid; check that trying to close it fails. See 1303 // |ch| should no longer be valid; check that trying to close it fails. See
1100 // above note. 1304 // above note.
1101 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, core()->Close(ch)); 1305 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, core()->Close(ch));
1102 1306
1103 // Write to |ph|. Should receive on |ch_received|. 1307 // Write to |ph|. Should receive on |ch_received|.
1104 num_bytes = kWorldSize; 1308 num_bytes = kWorldSize;
1105 EXPECT_EQ(MOJO_RESULT_OK, 1309 EXPECT_EQ(MOJO_RESULT_OK,
1106 core()->WriteData(ph, UserPointer<const void>(kWorld), 1310 core()->WriteData(ph,
1311 UserPointer<const void>(kWorld),
1107 MakeUserPointer(&num_bytes), 1312 MakeUserPointer(&num_bytes),
1108 MOJO_WRITE_DATA_FLAG_ALL_OR_NONE)); 1313 MOJO_WRITE_DATA_FLAG_ALL_OR_NONE));
1109 hss = kEmptyMojoHandleSignalsState; 1314 hss = kEmptyMojoHandleSignalsState;
1110 EXPECT_EQ(MOJO_RESULT_OK, 1315 EXPECT_EQ(MOJO_RESULT_OK,
1111 core()->Wait(ch_received, MOJO_HANDLE_SIGNAL_READABLE, 1000000000, 1316 core()->Wait(ch_received,
1317 MOJO_HANDLE_SIGNAL_READABLE,
1318 1000000000,
1112 MakeUserPointer(&hss))); 1319 MakeUserPointer(&hss)));
1113 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals); 1320 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals);
1114 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfiable_signals); 1321 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfiable_signals);
1115 num_bytes = kBufferSize; 1322 num_bytes = kBufferSize;
1116 EXPECT_EQ(MOJO_RESULT_OK, 1323 EXPECT_EQ(MOJO_RESULT_OK,
1117 core()->ReadData(ch_received, UserPointer<void>(buffer), 1324 core()->ReadData(ch_received,
1325 UserPointer<void>(buffer),
1118 MakeUserPointer(&num_bytes), 1326 MakeUserPointer(&num_bytes),
1119 MOJO_READ_MESSAGE_FLAG_NONE)); 1327 MOJO_READ_MESSAGE_FLAG_NONE));
1120 EXPECT_EQ(kWorldSize, num_bytes); 1328 EXPECT_EQ(kWorldSize, num_bytes);
1121 EXPECT_STREQ(kWorld, buffer); 1329 EXPECT_STREQ(kWorld, buffer);
1122 1330
1123 // Now pass |ph| in the same direction. 1331 // Now pass |ph| in the same direction.
1124 EXPECT_EQ(MOJO_RESULT_OK, 1332 EXPECT_EQ(MOJO_RESULT_OK,
1125 core()->WriteMessage(h_passing[0], UserPointer<const void>(kWorld), 1333 core()->WriteMessage(h_passing[0],
1126 kWorldSize, MakeUserPointer(&ph), 1, 1334 UserPointer<const void>(kWorld),
1335 kWorldSize,
1336 MakeUserPointer(&ph),
1337 1,
1127 MOJO_WRITE_MESSAGE_FLAG_NONE)); 1338 MOJO_WRITE_MESSAGE_FLAG_NONE));
1128 hss = kEmptyMojoHandleSignalsState; 1339 hss = kEmptyMojoHandleSignalsState;
1129 EXPECT_EQ(MOJO_RESULT_OK, 1340 EXPECT_EQ(MOJO_RESULT_OK,
1130 core()->Wait(h_passing[1], MOJO_HANDLE_SIGNAL_READABLE, 1000000000, 1341 core()->Wait(h_passing[1],
1342 MOJO_HANDLE_SIGNAL_READABLE,
1343 1000000000,
1131 MakeUserPointer(&hss))); 1344 MakeUserPointer(&hss)));
1132 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 1345 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
1133 hss.satisfied_signals); 1346 hss.satisfied_signals);
1134 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 1347 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
1135 hss.satisfiable_signals); 1348 hss.satisfiable_signals);
1136 num_bytes = kBufferSize; 1349 num_bytes = kBufferSize;
1137 num_handles = arraysize(handles); 1350 num_handles = arraysize(handles);
1138 EXPECT_EQ(MOJO_RESULT_OK, 1351 EXPECT_EQ(MOJO_RESULT_OK,
1139 core()->ReadMessage( 1352 core()->ReadMessage(h_passing[1],
1140 h_passing[1], UserPointer<void>(buffer), 1353 UserPointer<void>(buffer),
1141 MakeUserPointer(&num_bytes), MakeUserPointer(handles), 1354 MakeUserPointer(&num_bytes),
1142 MakeUserPointer(&num_handles), MOJO_READ_MESSAGE_FLAG_NONE)); 1355 MakeUserPointer(handles),
1356 MakeUserPointer(&num_handles),
1357 MOJO_READ_MESSAGE_FLAG_NONE));
1143 EXPECT_EQ(kWorldSize, num_bytes); 1358 EXPECT_EQ(kWorldSize, num_bytes);
1144 EXPECT_STREQ(kWorld, buffer); 1359 EXPECT_STREQ(kWorld, buffer);
1145 EXPECT_EQ(1u, num_handles); 1360 EXPECT_EQ(1u, num_handles);
1146 MojoHandle ph_received = handles[0]; 1361 MojoHandle ph_received = handles[0];
1147 EXPECT_NE(ph_received, MOJO_HANDLE_INVALID); 1362 EXPECT_NE(ph_received, MOJO_HANDLE_INVALID);
1148 EXPECT_NE(ph_received, h_passing[0]); 1363 EXPECT_NE(ph_received, h_passing[0]);
1149 EXPECT_NE(ph_received, h_passing[1]); 1364 EXPECT_NE(ph_received, h_passing[1]);
1150 EXPECT_NE(ph_received, ch_received); 1365 EXPECT_NE(ph_received, ch_received);
1151 1366
1152 // Again, rely on the Mojo system not re-using handle values very often. 1367 // Again, rely on the Mojo system not re-using handle values very often.
1153 EXPECT_NE(ph_received, ph); 1368 EXPECT_NE(ph_received, ph);
1154 1369
1155 // |ph| should no longer be valid; check that trying to close it fails. See 1370 // |ph| should no longer be valid; check that trying to close it fails. See
1156 // above note. 1371 // above note.
1157 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, core()->Close(ph)); 1372 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, core()->Close(ph));
1158 1373
1159 // Write to |ph_received|. Should receive on |ch_received|. 1374 // Write to |ph_received|. Should receive on |ch_received|.
1160 num_bytes = kHelloSize; 1375 num_bytes = kHelloSize;
1161 EXPECT_EQ(MOJO_RESULT_OK, 1376 EXPECT_EQ(MOJO_RESULT_OK,
1162 core()->WriteData(ph_received, UserPointer<const void>(kHello), 1377 core()->WriteData(ph_received,
1378 UserPointer<const void>(kHello),
1163 MakeUserPointer(&num_bytes), 1379 MakeUserPointer(&num_bytes),
1164 MOJO_WRITE_DATA_FLAG_ALL_OR_NONE)); 1380 MOJO_WRITE_DATA_FLAG_ALL_OR_NONE));
1165 hss = kEmptyMojoHandleSignalsState; 1381 hss = kEmptyMojoHandleSignalsState;
1166 EXPECT_EQ(MOJO_RESULT_OK, 1382 EXPECT_EQ(MOJO_RESULT_OK,
1167 core()->Wait(ch_received, MOJO_HANDLE_SIGNAL_READABLE, 1000000000, 1383 core()->Wait(ch_received,
1384 MOJO_HANDLE_SIGNAL_READABLE,
1385 1000000000,
1168 MakeUserPointer(&hss))); 1386 MakeUserPointer(&hss)));
1169 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals); 1387 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals);
1170 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfiable_signals); 1388 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfiable_signals);
1171 num_bytes = kBufferSize; 1389 num_bytes = kBufferSize;
1172 EXPECT_EQ(MOJO_RESULT_OK, 1390 EXPECT_EQ(MOJO_RESULT_OK,
1173 core()->ReadData(ch_received, UserPointer<void>(buffer), 1391 core()->ReadData(ch_received,
1392 UserPointer<void>(buffer),
1174 MakeUserPointer(&num_bytes), 1393 MakeUserPointer(&num_bytes),
1175 MOJO_READ_MESSAGE_FLAG_NONE)); 1394 MOJO_READ_MESSAGE_FLAG_NONE));
1176 EXPECT_EQ(kHelloSize, num_bytes); 1395 EXPECT_EQ(kHelloSize, num_bytes);
1177 EXPECT_STREQ(kHello, buffer); 1396 EXPECT_STREQ(kHello, buffer);
1178 1397
1179 ph = ph_received; 1398 ph = ph_received;
1180 ph_received = MOJO_HANDLE_INVALID; 1399 ph_received = MOJO_HANDLE_INVALID;
1181 ch = ch_received; 1400 ch = ch_received;
1182 ch_received = MOJO_HANDLE_INVALID; 1401 ch_received = MOJO_HANDLE_INVALID;
1183 1402
1184 // Make sure that |ph| can't be sent if it's in a two-phase write. 1403 // Make sure that |ph| can't be sent if it's in a two-phase write.
1185 void* write_ptr = nullptr; 1404 void* write_ptr = nullptr;
1186 num_bytes = 0; 1405 num_bytes = 0;
1187 ASSERT_EQ(MOJO_RESULT_OK, 1406 ASSERT_EQ(MOJO_RESULT_OK,
1188 core()->BeginWriteData(ph, MakeUserPointer(&write_ptr), 1407 core()->BeginWriteData(ph,
1408 MakeUserPointer(&write_ptr),
1189 MakeUserPointer(&num_bytes), 1409 MakeUserPointer(&num_bytes),
1190 MOJO_WRITE_DATA_FLAG_NONE)); 1410 MOJO_WRITE_DATA_FLAG_NONE));
1191 ASSERT_GE(num_bytes, 1u); 1411 ASSERT_GE(num_bytes, 1u);
1192 EXPECT_EQ(MOJO_RESULT_BUSY, 1412 EXPECT_EQ(MOJO_RESULT_BUSY,
1193 core()->WriteMessage(h_passing[0], UserPointer<const void>(kHello), 1413 core()->WriteMessage(h_passing[0],
1194 kHelloSize, MakeUserPointer(&ph), 1, 1414 UserPointer<const void>(kHello),
1415 kHelloSize,
1416 MakeUserPointer(&ph),
1417 1,
1195 MOJO_WRITE_MESSAGE_FLAG_NONE)); 1418 MOJO_WRITE_MESSAGE_FLAG_NONE));
1196 1419
1197 // But |ch| can, even if |ph| is in a two-phase write. 1420 // But |ch| can, even if |ph| is in a two-phase write.
1198 EXPECT_EQ(MOJO_RESULT_OK, 1421 EXPECT_EQ(MOJO_RESULT_OK,
1199 core()->WriteMessage(h_passing[0], UserPointer<const void>(kHello), 1422 core()->WriteMessage(h_passing[0],
1200 kHelloSize, MakeUserPointer(&ch), 1, 1423 UserPointer<const void>(kHello),
1424 kHelloSize,
1425 MakeUserPointer(&ch),
1426 1,
1201 MOJO_WRITE_MESSAGE_FLAG_NONE)); 1427 MOJO_WRITE_MESSAGE_FLAG_NONE));
1202 ch = MOJO_HANDLE_INVALID; 1428 ch = MOJO_HANDLE_INVALID;
1203 EXPECT_EQ(MOJO_RESULT_OK, 1429 EXPECT_EQ(MOJO_RESULT_OK,
1204 core()->Wait(h_passing[1], MOJO_HANDLE_SIGNAL_READABLE, 1000000000, 1430 core()->Wait(h_passing[1],
1431 MOJO_HANDLE_SIGNAL_READABLE,
1432 1000000000,
1205 NullUserPointer())); 1433 NullUserPointer()));
1206 num_bytes = kBufferSize; 1434 num_bytes = kBufferSize;
1207 num_handles = arraysize(handles); 1435 num_handles = arraysize(handles);
1208 EXPECT_EQ(MOJO_RESULT_OK, 1436 EXPECT_EQ(MOJO_RESULT_OK,
1209 core()->ReadMessage( 1437 core()->ReadMessage(h_passing[1],
1210 h_passing[1], UserPointer<void>(buffer), 1438 UserPointer<void>(buffer),
1211 MakeUserPointer(&num_bytes), MakeUserPointer(handles), 1439 MakeUserPointer(&num_bytes),
1212 MakeUserPointer(&num_handles), MOJO_READ_MESSAGE_FLAG_NONE)); 1440 MakeUserPointer(handles),
1441 MakeUserPointer(&num_handles),
1442 MOJO_READ_MESSAGE_FLAG_NONE));
1213 EXPECT_EQ(kHelloSize, num_bytes); 1443 EXPECT_EQ(kHelloSize, num_bytes);
1214 EXPECT_STREQ(kHello, buffer); 1444 EXPECT_STREQ(kHello, buffer);
1215 EXPECT_EQ(1u, num_handles); 1445 EXPECT_EQ(1u, num_handles);
1216 ch = handles[0]; 1446 ch = handles[0];
1217 EXPECT_NE(ch, MOJO_HANDLE_INVALID); 1447 EXPECT_NE(ch, MOJO_HANDLE_INVALID);
1218 1448
1219 // Complete the two-phase write. 1449 // Complete the two-phase write.
1220 static_cast<char*>(write_ptr)[0] = 'x'; 1450 static_cast<char*>(write_ptr)[0] = 'x';
1221 EXPECT_EQ(MOJO_RESULT_OK, core()->EndWriteData(ph, 1)); 1451 EXPECT_EQ(MOJO_RESULT_OK, core()->EndWriteData(ph, 1));
1222 1452
1223 // Wait for |ch| to be readable. 1453 // Wait for |ch| to be readable.
1224 hss = kEmptyMojoHandleSignalsState; 1454 hss = kEmptyMojoHandleSignalsState;
1225 EXPECT_EQ(MOJO_RESULT_OK, core()->Wait(ch, MOJO_HANDLE_SIGNAL_READABLE, 1455 EXPECT_EQ(
1226 1000000000, MakeUserPointer(&hss))); 1456 MOJO_RESULT_OK,
1457 core()->Wait(
1458 ch, MOJO_HANDLE_SIGNAL_READABLE, 1000000000, MakeUserPointer(&hss)));
1227 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals); 1459 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals);
1228 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfiable_signals); 1460 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfiable_signals);
1229 1461
1230 // Make sure that |ch| can't be sent if it's in a two-phase read. 1462 // Make sure that |ch| can't be sent if it's in a two-phase read.
1231 const void* read_ptr = nullptr; 1463 const void* read_ptr = nullptr;
1232 num_bytes = 1; 1464 num_bytes = 1;
1233 ASSERT_EQ(MOJO_RESULT_OK, 1465 ASSERT_EQ(MOJO_RESULT_OK,
1234 core()->BeginReadData(ch, MakeUserPointer(&read_ptr), 1466 core()->BeginReadData(ch,
1467 MakeUserPointer(&read_ptr),
1235 MakeUserPointer(&num_bytes), 1468 MakeUserPointer(&num_bytes),
1236 MOJO_READ_DATA_FLAG_ALL_OR_NONE)); 1469 MOJO_READ_DATA_FLAG_ALL_OR_NONE));
1237 EXPECT_EQ(MOJO_RESULT_BUSY, 1470 EXPECT_EQ(MOJO_RESULT_BUSY,
1238 core()->WriteMessage(h_passing[0], UserPointer<const void>(kHello), 1471 core()->WriteMessage(h_passing[0],
1239 kHelloSize, MakeUserPointer(&ch), 1, 1472 UserPointer<const void>(kHello),
1473 kHelloSize,
1474 MakeUserPointer(&ch),
1475 1,
1240 MOJO_WRITE_MESSAGE_FLAG_NONE)); 1476 MOJO_WRITE_MESSAGE_FLAG_NONE));
1241 1477
1242 // But |ph| can, even if |ch| is in a two-phase read. 1478 // But |ph| can, even if |ch| is in a two-phase read.
1243 EXPECT_EQ(MOJO_RESULT_OK, 1479 EXPECT_EQ(MOJO_RESULT_OK,
1244 core()->WriteMessage(h_passing[0], UserPointer<const void>(kWorld), 1480 core()->WriteMessage(h_passing[0],
1245 kWorldSize, MakeUserPointer(&ph), 1, 1481 UserPointer<const void>(kWorld),
1482 kWorldSize,
1483 MakeUserPointer(&ph),
1484 1,
1246 MOJO_WRITE_MESSAGE_FLAG_NONE)); 1485 MOJO_WRITE_MESSAGE_FLAG_NONE));
1247 ph = MOJO_HANDLE_INVALID; 1486 ph = MOJO_HANDLE_INVALID;
1248 hss = kEmptyMojoHandleSignalsState; 1487 hss = kEmptyMojoHandleSignalsState;
1249 EXPECT_EQ(MOJO_RESULT_OK, 1488 EXPECT_EQ(MOJO_RESULT_OK,
1250 core()->Wait(h_passing[1], MOJO_HANDLE_SIGNAL_READABLE, 1000000000, 1489 core()->Wait(h_passing[1],
1490 MOJO_HANDLE_SIGNAL_READABLE,
1491 1000000000,
1251 MakeUserPointer(&hss))); 1492 MakeUserPointer(&hss)));
1252 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 1493 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
1253 hss.satisfied_signals); 1494 hss.satisfied_signals);
1254 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 1495 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
1255 hss.satisfiable_signals); 1496 hss.satisfiable_signals);
1256 num_bytes = kBufferSize; 1497 num_bytes = kBufferSize;
1257 num_handles = arraysize(handles); 1498 num_handles = arraysize(handles);
1258 EXPECT_EQ(MOJO_RESULT_OK, 1499 EXPECT_EQ(MOJO_RESULT_OK,
1259 core()->ReadMessage( 1500 core()->ReadMessage(h_passing[1],
1260 h_passing[1], UserPointer<void>(buffer), 1501 UserPointer<void>(buffer),
1261 MakeUserPointer(&num_bytes), MakeUserPointer(handles), 1502 MakeUserPointer(&num_bytes),
1262 MakeUserPointer(&num_handles), MOJO_READ_MESSAGE_FLAG_NONE)); 1503 MakeUserPointer(handles),
1504 MakeUserPointer(&num_handles),
1505 MOJO_READ_MESSAGE_FLAG_NONE));
1263 EXPECT_EQ(kWorldSize, num_bytes); 1506 EXPECT_EQ(kWorldSize, num_bytes);
1264 EXPECT_STREQ(kWorld, buffer); 1507 EXPECT_STREQ(kWorld, buffer);
1265 EXPECT_EQ(1u, num_handles); 1508 EXPECT_EQ(1u, num_handles);
1266 ph = handles[0]; 1509 ph = handles[0];
1267 EXPECT_NE(ph, MOJO_HANDLE_INVALID); 1510 EXPECT_NE(ph, MOJO_HANDLE_INVALID);
1268 1511
1269 // Complete the two-phase read. 1512 // Complete the two-phase read.
1270 EXPECT_EQ('x', static_cast<const char*>(read_ptr)[0]); 1513 EXPECT_EQ('x', static_cast<const char*>(read_ptr)[0]);
1271 EXPECT_EQ(MOJO_RESULT_OK, core()->EndReadData(ch, 1)); 1514 EXPECT_EQ(MOJO_RESULT_OK, core()->EndReadData(ch, 1));
1272 1515
1273 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h_passing[0])); 1516 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h_passing[0]));
1274 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h_passing[1])); 1517 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h_passing[1]));
1275 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(ph)); 1518 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(ph));
1276 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(ch)); 1519 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(ch));
1277 } 1520 }
1278 1521
1279 // TODO(vtl): Test |DuplicateBufferHandle()| and |MapBuffer()|. 1522 // TODO(vtl): Test |DuplicateBufferHandle()| and |MapBuffer()|.
1280 1523
1281 } // namespace 1524 } // namespace
1282 } // namespace system 1525 } // namespace system
1283 } // namespace mojo 1526 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/core_test_base.cc ('k') | mojo/edk/system/data_pipe.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698