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

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

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