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

Side by Side Diff: mojo/edk/system/message_pipe_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
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/message_pipe.h" 5 #include "mojo/edk/system/message_pipe.h"
6 6
7 #include "base/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 #include "base/threading/platform_thread.h" // For |Sleep()|. 8 #include "base/threading/platform_thread.h" // For |Sleep()|.
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 #include "mojo/edk/system/waiter.h" 10 #include "mojo/edk/system/waiter.h"
(...skipping 21 matching lines...) Expand all
32 32
33 int32_t buffer[2]; 33 int32_t buffer[2];
34 const uint32_t kBufferSize = static_cast<uint32_t>(sizeof(buffer)); 34 const uint32_t kBufferSize = static_cast<uint32_t>(sizeof(buffer));
35 uint32_t buffer_size; 35 uint32_t buffer_size;
36 36
37 // Nothing to read yet on port 0. 37 // Nothing to read yet on port 0.
38 buffer[0] = 123; 38 buffer[0] = 123;
39 buffer[1] = 456; 39 buffer[1] = 456;
40 buffer_size = kBufferSize; 40 buffer_size = kBufferSize;
41 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT, 41 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT,
42 mp->ReadMessage(0, 42 mp->ReadMessage(0, UserPointer<void>(buffer),
43 UserPointer<void>(buffer), 43 MakeUserPointer(&buffer_size), 0, nullptr,
44 MakeUserPointer(&buffer_size),
45 0,
46 nullptr,
47 MOJO_READ_MESSAGE_FLAG_NONE)); 44 MOJO_READ_MESSAGE_FLAG_NONE));
48 EXPECT_EQ(kBufferSize, buffer_size); 45 EXPECT_EQ(kBufferSize, buffer_size);
49 EXPECT_EQ(123, buffer[0]); 46 EXPECT_EQ(123, buffer[0]);
50 EXPECT_EQ(456, buffer[1]); 47 EXPECT_EQ(456, buffer[1]);
51 48
52 // Ditto for port 1. 49 // Ditto for port 1.
53 buffer[0] = 123; 50 buffer[0] = 123;
54 buffer[1] = 456; 51 buffer[1] = 456;
55 buffer_size = kBufferSize; 52 buffer_size = kBufferSize;
56 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT, 53 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT,
57 mp->ReadMessage(1, 54 mp->ReadMessage(1, UserPointer<void>(buffer),
58 UserPointer<void>(buffer), 55 MakeUserPointer(&buffer_size), 0, nullptr,
59 MakeUserPointer(&buffer_size),
60 0,
61 nullptr,
62 MOJO_READ_MESSAGE_FLAG_NONE)); 56 MOJO_READ_MESSAGE_FLAG_NONE));
63 57
64 // Write from port 1 (to port 0). 58 // Write from port 1 (to port 0).
65 buffer[0] = 789012345; 59 buffer[0] = 789012345;
66 buffer[1] = 0; 60 buffer[1] = 0;
67 EXPECT_EQ(MOJO_RESULT_OK, 61 EXPECT_EQ(MOJO_RESULT_OK,
68 mp->WriteMessage(1, 62 mp->WriteMessage(1, UserPointer<const void>(buffer),
69 UserPointer<const void>(buffer), 63 static_cast<uint32_t>(sizeof(buffer[0])), nullptr,
70 static_cast<uint32_t>(sizeof(buffer[0])),
71 nullptr,
72 MOJO_WRITE_MESSAGE_FLAG_NONE)); 64 MOJO_WRITE_MESSAGE_FLAG_NONE));
73 65
74 // Read from port 0. 66 // Read from port 0.
75 buffer[0] = 123; 67 buffer[0] = 123;
76 buffer[1] = 456; 68 buffer[1] = 456;
77 buffer_size = kBufferSize; 69 buffer_size = kBufferSize;
78 EXPECT_EQ(MOJO_RESULT_OK, 70 EXPECT_EQ(MOJO_RESULT_OK,
79 mp->ReadMessage(0, 71 mp->ReadMessage(0, UserPointer<void>(buffer),
80 UserPointer<void>(buffer), 72 MakeUserPointer(&buffer_size), 0, nullptr,
81 MakeUserPointer(&buffer_size),
82 0,
83 nullptr,
84 MOJO_READ_MESSAGE_FLAG_NONE)); 73 MOJO_READ_MESSAGE_FLAG_NONE));
85 EXPECT_EQ(static_cast<uint32_t>(sizeof(buffer[0])), buffer_size); 74 EXPECT_EQ(static_cast<uint32_t>(sizeof(buffer[0])), buffer_size);
86 EXPECT_EQ(789012345, buffer[0]); 75 EXPECT_EQ(789012345, buffer[0]);
87 EXPECT_EQ(456, buffer[1]); 76 EXPECT_EQ(456, buffer[1]);
88 77
89 // Read again from port 0 -- it should be empty. 78 // Read again from port 0 -- it should be empty.
90 buffer_size = kBufferSize; 79 buffer_size = kBufferSize;
91 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT, 80 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT,
92 mp->ReadMessage(0, 81 mp->ReadMessage(0, UserPointer<void>(buffer),
93 UserPointer<void>(buffer), 82 MakeUserPointer(&buffer_size), 0, nullptr,
94 MakeUserPointer(&buffer_size),
95 0,
96 nullptr,
97 MOJO_READ_MESSAGE_FLAG_NONE)); 83 MOJO_READ_MESSAGE_FLAG_NONE));
98 84
99 // Write two messages from port 0 (to port 1). 85 // Write two messages from port 0 (to port 1).
100 buffer[0] = 123456789; 86 buffer[0] = 123456789;
101 buffer[1] = 0; 87 buffer[1] = 0;
102 EXPECT_EQ(MOJO_RESULT_OK, 88 EXPECT_EQ(MOJO_RESULT_OK,
103 mp->WriteMessage(0, 89 mp->WriteMessage(0, UserPointer<const void>(buffer),
104 UserPointer<const void>(buffer), 90 static_cast<uint32_t>(sizeof(buffer[0])), nullptr,
105 static_cast<uint32_t>(sizeof(buffer[0])),
106 nullptr,
107 MOJO_WRITE_MESSAGE_FLAG_NONE)); 91 MOJO_WRITE_MESSAGE_FLAG_NONE));
108 buffer[0] = 234567890; 92 buffer[0] = 234567890;
109 buffer[1] = 0; 93 buffer[1] = 0;
110 EXPECT_EQ(MOJO_RESULT_OK, 94 EXPECT_EQ(MOJO_RESULT_OK,
111 mp->WriteMessage(0, 95 mp->WriteMessage(0, UserPointer<const void>(buffer),
112 UserPointer<const void>(buffer), 96 static_cast<uint32_t>(sizeof(buffer[0])), nullptr,
113 static_cast<uint32_t>(sizeof(buffer[0])),
114 nullptr,
115 MOJO_WRITE_MESSAGE_FLAG_NONE)); 97 MOJO_WRITE_MESSAGE_FLAG_NONE));
116 98
117 // Read from port 1 with buffer size 0 (should get the size of next message). 99 // Read from port 1 with buffer size 0 (should get the size of next message).
118 // Also test that giving a null buffer is okay when the buffer size is 0. 100 // Also test that giving a null buffer is okay when the buffer size is 0.
119 buffer_size = 0; 101 buffer_size = 0;
120 EXPECT_EQ(MOJO_RESULT_RESOURCE_EXHAUSTED, 102 EXPECT_EQ(MOJO_RESULT_RESOURCE_EXHAUSTED,
121 mp->ReadMessage(1, 103 mp->ReadMessage(1, NullUserPointer(), MakeUserPointer(&buffer_size),
122 NullUserPointer(), 104 0, nullptr, MOJO_READ_MESSAGE_FLAG_NONE));
123 MakeUserPointer(&buffer_size),
124 0,
125 nullptr,
126 MOJO_READ_MESSAGE_FLAG_NONE));
127 EXPECT_EQ(static_cast<uint32_t>(sizeof(buffer[0])), buffer_size); 105 EXPECT_EQ(static_cast<uint32_t>(sizeof(buffer[0])), buffer_size);
128 106
129 // Read from port 1 with buffer size 1 (too small; should get the size of next 107 // Read from port 1 with buffer size 1 (too small; should get the size of next
130 // message). 108 // message).
131 buffer[0] = 123; 109 buffer[0] = 123;
132 buffer[1] = 456; 110 buffer[1] = 456;
133 buffer_size = 1; 111 buffer_size = 1;
134 EXPECT_EQ(MOJO_RESULT_RESOURCE_EXHAUSTED, 112 EXPECT_EQ(MOJO_RESULT_RESOURCE_EXHAUSTED,
135 mp->ReadMessage(1, 113 mp->ReadMessage(1, UserPointer<void>(buffer),
136 UserPointer<void>(buffer), 114 MakeUserPointer(&buffer_size), 0, nullptr,
137 MakeUserPointer(&buffer_size),
138 0,
139 nullptr,
140 MOJO_READ_MESSAGE_FLAG_NONE)); 115 MOJO_READ_MESSAGE_FLAG_NONE));
141 EXPECT_EQ(static_cast<uint32_t>(sizeof(buffer[0])), buffer_size); 116 EXPECT_EQ(static_cast<uint32_t>(sizeof(buffer[0])), buffer_size);
142 EXPECT_EQ(123, buffer[0]); 117 EXPECT_EQ(123, buffer[0]);
143 EXPECT_EQ(456, buffer[1]); 118 EXPECT_EQ(456, buffer[1]);
144 119
145 // Read from port 1. 120 // Read from port 1.
146 buffer[0] = 123; 121 buffer[0] = 123;
147 buffer[1] = 456; 122 buffer[1] = 456;
148 buffer_size = kBufferSize; 123 buffer_size = kBufferSize;
149 EXPECT_EQ(MOJO_RESULT_OK, 124 EXPECT_EQ(MOJO_RESULT_OK,
150 mp->ReadMessage(1, 125 mp->ReadMessage(1, UserPointer<void>(buffer),
151 UserPointer<void>(buffer), 126 MakeUserPointer(&buffer_size), 0, nullptr,
152 MakeUserPointer(&buffer_size),
153 0,
154 nullptr,
155 MOJO_READ_MESSAGE_FLAG_NONE)); 127 MOJO_READ_MESSAGE_FLAG_NONE));
156 EXPECT_EQ(static_cast<uint32_t>(sizeof(buffer[0])), buffer_size); 128 EXPECT_EQ(static_cast<uint32_t>(sizeof(buffer[0])), buffer_size);
157 EXPECT_EQ(123456789, buffer[0]); 129 EXPECT_EQ(123456789, buffer[0]);
158 EXPECT_EQ(456, buffer[1]); 130 EXPECT_EQ(456, buffer[1]);
159 131
160 // Read again from port 1. 132 // Read again from port 1.
161 buffer[0] = 123; 133 buffer[0] = 123;
162 buffer[1] = 456; 134 buffer[1] = 456;
163 buffer_size = kBufferSize; 135 buffer_size = kBufferSize;
164 EXPECT_EQ(MOJO_RESULT_OK, 136 EXPECT_EQ(MOJO_RESULT_OK,
165 mp->ReadMessage(1, 137 mp->ReadMessage(1, UserPointer<void>(buffer),
166 UserPointer<void>(buffer), 138 MakeUserPointer(&buffer_size), 0, nullptr,
167 MakeUserPointer(&buffer_size),
168 0,
169 nullptr,
170 MOJO_READ_MESSAGE_FLAG_NONE)); 139 MOJO_READ_MESSAGE_FLAG_NONE));
171 EXPECT_EQ(static_cast<uint32_t>(sizeof(buffer[0])), buffer_size); 140 EXPECT_EQ(static_cast<uint32_t>(sizeof(buffer[0])), buffer_size);
172 EXPECT_EQ(234567890, buffer[0]); 141 EXPECT_EQ(234567890, buffer[0]);
173 EXPECT_EQ(456, buffer[1]); 142 EXPECT_EQ(456, buffer[1]);
174 143
175 // Read again from port 1 -- it should be empty. 144 // Read again from port 1 -- it should be empty.
176 buffer_size = kBufferSize; 145 buffer_size = kBufferSize;
177 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT, 146 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT,
178 mp->ReadMessage(1, 147 mp->ReadMessage(1, UserPointer<void>(buffer),
179 UserPointer<void>(buffer), 148 MakeUserPointer(&buffer_size), 0, nullptr,
180 MakeUserPointer(&buffer_size),
181 0,
182 nullptr,
183 MOJO_READ_MESSAGE_FLAG_NONE)); 149 MOJO_READ_MESSAGE_FLAG_NONE));
184 150
185 // Write from port 0 (to port 1). 151 // Write from port 0 (to port 1).
186 buffer[0] = 345678901; 152 buffer[0] = 345678901;
187 buffer[1] = 0; 153 buffer[1] = 0;
188 EXPECT_EQ(MOJO_RESULT_OK, 154 EXPECT_EQ(MOJO_RESULT_OK,
189 mp->WriteMessage(0, 155 mp->WriteMessage(0, UserPointer<const void>(buffer),
190 UserPointer<const void>(buffer), 156 static_cast<uint32_t>(sizeof(buffer[0])), nullptr,
191 static_cast<uint32_t>(sizeof(buffer[0])),
192 nullptr,
193 MOJO_WRITE_MESSAGE_FLAG_NONE)); 157 MOJO_WRITE_MESSAGE_FLAG_NONE));
194 158
195 // Close port 0. 159 // Close port 0.
196 mp->Close(0); 160 mp->Close(0);
197 161
198 // Try to write from port 1 (to port 0). 162 // Try to write from port 1 (to port 0).
199 buffer[0] = 456789012; 163 buffer[0] = 456789012;
200 buffer[1] = 0; 164 buffer[1] = 0;
201 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, 165 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
202 mp->WriteMessage(1, 166 mp->WriteMessage(1, UserPointer<const void>(buffer),
203 UserPointer<const void>(buffer), 167 static_cast<uint32_t>(sizeof(buffer[0])), nullptr,
204 static_cast<uint32_t>(sizeof(buffer[0])),
205 nullptr,
206 MOJO_WRITE_MESSAGE_FLAG_NONE)); 168 MOJO_WRITE_MESSAGE_FLAG_NONE));
207 169
208 // Read from port 1; should still get message (even though port 0 was closed). 170 // Read from port 1; should still get message (even though port 0 was closed).
209 buffer[0] = 123; 171 buffer[0] = 123;
210 buffer[1] = 456; 172 buffer[1] = 456;
211 buffer_size = kBufferSize; 173 buffer_size = kBufferSize;
212 EXPECT_EQ(MOJO_RESULT_OK, 174 EXPECT_EQ(MOJO_RESULT_OK,
213 mp->ReadMessage(1, 175 mp->ReadMessage(1, UserPointer<void>(buffer),
214 UserPointer<void>(buffer), 176 MakeUserPointer(&buffer_size), 0, nullptr,
215 MakeUserPointer(&buffer_size),
216 0,
217 nullptr,
218 MOJO_READ_MESSAGE_FLAG_NONE)); 177 MOJO_READ_MESSAGE_FLAG_NONE));
219 EXPECT_EQ(static_cast<uint32_t>(sizeof(buffer[0])), buffer_size); 178 EXPECT_EQ(static_cast<uint32_t>(sizeof(buffer[0])), buffer_size);
220 EXPECT_EQ(345678901, buffer[0]); 179 EXPECT_EQ(345678901, buffer[0]);
221 EXPECT_EQ(456, buffer[1]); 180 EXPECT_EQ(456, buffer[1]);
222 181
223 // Read again from port 1 -- it should be empty (and port 0 is closed). 182 // Read again from port 1 -- it should be empty (and port 0 is closed).
224 buffer_size = kBufferSize; 183 buffer_size = kBufferSize;
225 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, 184 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
226 mp->ReadMessage(1, 185 mp->ReadMessage(1, UserPointer<void>(buffer),
227 UserPointer<void>(buffer), 186 MakeUserPointer(&buffer_size), 0, nullptr,
228 MakeUserPointer(&buffer_size),
229 0,
230 nullptr,
231 MOJO_READ_MESSAGE_FLAG_NONE)); 187 MOJO_READ_MESSAGE_FLAG_NONE));
232 188
233 mp->Close(1); 189 mp->Close(1);
234 } 190 }
235 191
236 TEST(MessagePipeTest, CloseWithQueuedIncomingMessages) { 192 TEST(MessagePipeTest, CloseWithQueuedIncomingMessages) {
237 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalLocal()); 193 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalLocal());
238 194
239 int32_t buffer[1]; 195 int32_t buffer[1];
240 const uint32_t kBufferSize = static_cast<uint32_t>(sizeof(buffer)); 196 const uint32_t kBufferSize = static_cast<uint32_t>(sizeof(buffer));
241 uint32_t buffer_size; 197 uint32_t buffer_size;
242 198
243 // Write some messages from port 1 (to port 0). 199 // Write some messages from port 1 (to port 0).
244 for (int32_t i = 0; i < 5; i++) { 200 for (int32_t i = 0; i < 5; i++) {
245 buffer[0] = i; 201 buffer[0] = i;
246 EXPECT_EQ(MOJO_RESULT_OK, 202 EXPECT_EQ(MOJO_RESULT_OK,
247 mp->WriteMessage(1, 203 mp->WriteMessage(1, UserPointer<const void>(buffer), kBufferSize,
248 UserPointer<const void>(buffer), 204 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
249 kBufferSize,
250 nullptr,
251 MOJO_WRITE_MESSAGE_FLAG_NONE));
252 } 205 }
253 206
254 // Port 0 shouldn't be empty. 207 // Port 0 shouldn't be empty.
255 buffer_size = 0; 208 buffer_size = 0;
256 EXPECT_EQ(MOJO_RESULT_RESOURCE_EXHAUSTED, 209 EXPECT_EQ(MOJO_RESULT_RESOURCE_EXHAUSTED,
257 mp->ReadMessage(0, 210 mp->ReadMessage(0, NullUserPointer(), MakeUserPointer(&buffer_size),
258 NullUserPointer(), 211 0, nullptr, MOJO_READ_MESSAGE_FLAG_NONE));
259 MakeUserPointer(&buffer_size),
260 0,
261 nullptr,
262 MOJO_READ_MESSAGE_FLAG_NONE));
263 EXPECT_EQ(kBufferSize, buffer_size); 212 EXPECT_EQ(kBufferSize, buffer_size);
264 213
265 // Close port 0 first, which should have outstanding (incoming) messages. 214 // Close port 0 first, which should have outstanding (incoming) messages.
266 mp->Close(0); 215 mp->Close(0);
267 mp->Close(1); 216 mp->Close(1);
268 } 217 }
269 218
270 TEST(MessagePipeTest, DiscardMode) { 219 TEST(MessagePipeTest, DiscardMode) {
271 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalLocal()); 220 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalLocal());
272 221
273 int32_t buffer[2]; 222 int32_t buffer[2];
274 const uint32_t kBufferSize = static_cast<uint32_t>(sizeof(buffer)); 223 const uint32_t kBufferSize = static_cast<uint32_t>(sizeof(buffer));
275 uint32_t buffer_size; 224 uint32_t buffer_size;
276 225
277 // Write from port 1 (to port 0). 226 // Write from port 1 (to port 0).
278 buffer[0] = 789012345; 227 buffer[0] = 789012345;
279 buffer[1] = 0; 228 buffer[1] = 0;
280 EXPECT_EQ(MOJO_RESULT_OK, 229 EXPECT_EQ(MOJO_RESULT_OK,
281 mp->WriteMessage(1, 230 mp->WriteMessage(1, UserPointer<const void>(buffer),
282 UserPointer<const void>(buffer), 231 static_cast<uint32_t>(sizeof(buffer[0])), nullptr,
283 static_cast<uint32_t>(sizeof(buffer[0])),
284 nullptr,
285 MOJO_WRITE_MESSAGE_FLAG_NONE)); 232 MOJO_WRITE_MESSAGE_FLAG_NONE));
286 233
287 // Read/discard from port 0 (no buffer); get size. 234 // Read/discard from port 0 (no buffer); get size.
288 buffer_size = 0; 235 buffer_size = 0;
289 EXPECT_EQ(MOJO_RESULT_RESOURCE_EXHAUSTED, 236 EXPECT_EQ(MOJO_RESULT_RESOURCE_EXHAUSTED,
290 mp->ReadMessage(0, 237 mp->ReadMessage(0, NullUserPointer(), MakeUserPointer(&buffer_size),
291 NullUserPointer(), 238 0, nullptr, MOJO_READ_MESSAGE_FLAG_MAY_DISCARD));
292 MakeUserPointer(&buffer_size),
293 0,
294 nullptr,
295 MOJO_READ_MESSAGE_FLAG_MAY_DISCARD));
296 EXPECT_EQ(static_cast<uint32_t>(sizeof(buffer[0])), buffer_size); 239 EXPECT_EQ(static_cast<uint32_t>(sizeof(buffer[0])), buffer_size);
297 240
298 // Read again from port 0 -- it should be empty. 241 // Read again from port 0 -- it should be empty.
299 buffer_size = kBufferSize; 242 buffer_size = kBufferSize;
300 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT, 243 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT,
301 mp->ReadMessage(0, 244 mp->ReadMessage(0, UserPointer<void>(buffer),
302 UserPointer<void>(buffer), 245 MakeUserPointer(&buffer_size), 0, nullptr,
303 MakeUserPointer(&buffer_size),
304 0,
305 nullptr,
306 MOJO_READ_MESSAGE_FLAG_MAY_DISCARD)); 246 MOJO_READ_MESSAGE_FLAG_MAY_DISCARD));
307 247
308 // Write from port 1 (to port 0). 248 // Write from port 1 (to port 0).
309 buffer[0] = 890123456; 249 buffer[0] = 890123456;
310 buffer[1] = 0; 250 buffer[1] = 0;
311 EXPECT_EQ(MOJO_RESULT_OK, 251 EXPECT_EQ(MOJO_RESULT_OK,
312 mp->WriteMessage(1, 252 mp->WriteMessage(1, UserPointer<const void>(buffer),
313 UserPointer<const void>(buffer), 253 static_cast<uint32_t>(sizeof(buffer[0])), nullptr,
314 static_cast<uint32_t>(sizeof(buffer[0])),
315 nullptr,
316 MOJO_WRITE_MESSAGE_FLAG_NONE)); 254 MOJO_WRITE_MESSAGE_FLAG_NONE));
317 255
318 // Read from port 0 (buffer big enough). 256 // Read from port 0 (buffer big enough).
319 buffer[0] = 123; 257 buffer[0] = 123;
320 buffer[1] = 456; 258 buffer[1] = 456;
321 buffer_size = kBufferSize; 259 buffer_size = kBufferSize;
322 EXPECT_EQ(MOJO_RESULT_OK, 260 EXPECT_EQ(MOJO_RESULT_OK,
323 mp->ReadMessage(0, 261 mp->ReadMessage(0, UserPointer<void>(buffer),
324 UserPointer<void>(buffer), 262 MakeUserPointer(&buffer_size), 0, nullptr,
325 MakeUserPointer(&buffer_size),
326 0,
327 nullptr,
328 MOJO_READ_MESSAGE_FLAG_MAY_DISCARD)); 263 MOJO_READ_MESSAGE_FLAG_MAY_DISCARD));
329 EXPECT_EQ(static_cast<uint32_t>(sizeof(buffer[0])), buffer_size); 264 EXPECT_EQ(static_cast<uint32_t>(sizeof(buffer[0])), buffer_size);
330 EXPECT_EQ(890123456, buffer[0]); 265 EXPECT_EQ(890123456, buffer[0]);
331 EXPECT_EQ(456, buffer[1]); 266 EXPECT_EQ(456, buffer[1]);
332 267
333 // Read again from port 0 -- it should be empty. 268 // Read again from port 0 -- it should be empty.
334 buffer_size = kBufferSize; 269 buffer_size = kBufferSize;
335 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT, 270 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT,
336 mp->ReadMessage(0, 271 mp->ReadMessage(0, UserPointer<void>(buffer),
337 UserPointer<void>(buffer), 272 MakeUserPointer(&buffer_size), 0, nullptr,
338 MakeUserPointer(&buffer_size),
339 0,
340 nullptr,
341 MOJO_READ_MESSAGE_FLAG_MAY_DISCARD)); 273 MOJO_READ_MESSAGE_FLAG_MAY_DISCARD));
342 274
343 // Write from port 1 (to port 0). 275 // Write from port 1 (to port 0).
344 buffer[0] = 901234567; 276 buffer[0] = 901234567;
345 buffer[1] = 0; 277 buffer[1] = 0;
346 EXPECT_EQ(MOJO_RESULT_OK, 278 EXPECT_EQ(MOJO_RESULT_OK,
347 mp->WriteMessage(1, 279 mp->WriteMessage(1, UserPointer<const void>(buffer),
348 UserPointer<const void>(buffer), 280 static_cast<uint32_t>(sizeof(buffer[0])), nullptr,
349 static_cast<uint32_t>(sizeof(buffer[0])),
350 nullptr,
351 MOJO_WRITE_MESSAGE_FLAG_NONE)); 281 MOJO_WRITE_MESSAGE_FLAG_NONE));
352 282
353 // Read/discard from port 0 (buffer too small); get size. 283 // Read/discard from port 0 (buffer too small); get size.
354 buffer_size = 1; 284 buffer_size = 1;
355 EXPECT_EQ(MOJO_RESULT_RESOURCE_EXHAUSTED, 285 EXPECT_EQ(MOJO_RESULT_RESOURCE_EXHAUSTED,
356 mp->ReadMessage(0, 286 mp->ReadMessage(0, UserPointer<void>(buffer),
357 UserPointer<void>(buffer), 287 MakeUserPointer(&buffer_size), 0, nullptr,
358 MakeUserPointer(&buffer_size),
359 0,
360 nullptr,
361 MOJO_READ_MESSAGE_FLAG_MAY_DISCARD)); 288 MOJO_READ_MESSAGE_FLAG_MAY_DISCARD));
362 EXPECT_EQ(static_cast<uint32_t>(sizeof(buffer[0])), buffer_size); 289 EXPECT_EQ(static_cast<uint32_t>(sizeof(buffer[0])), buffer_size);
363 290
364 // Read again from port 0 -- it should be empty. 291 // Read again from port 0 -- it should be empty.
365 buffer_size = kBufferSize; 292 buffer_size = kBufferSize;
366 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT, 293 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT,
367 mp->ReadMessage(0, 294 mp->ReadMessage(0, UserPointer<void>(buffer),
368 UserPointer<void>(buffer), 295 MakeUserPointer(&buffer_size), 0, nullptr,
369 MakeUserPointer(&buffer_size),
370 0,
371 nullptr,
372 MOJO_READ_MESSAGE_FLAG_MAY_DISCARD)); 296 MOJO_READ_MESSAGE_FLAG_MAY_DISCARD));
373 297
374 // Write from port 1 (to port 0). 298 // Write from port 1 (to port 0).
375 buffer[0] = 123456789; 299 buffer[0] = 123456789;
376 buffer[1] = 0; 300 buffer[1] = 0;
377 EXPECT_EQ(MOJO_RESULT_OK, 301 EXPECT_EQ(MOJO_RESULT_OK,
378 mp->WriteMessage(1, 302 mp->WriteMessage(1, UserPointer<const void>(buffer),
379 UserPointer<const void>(buffer), 303 static_cast<uint32_t>(sizeof(buffer[0])), nullptr,
380 static_cast<uint32_t>(sizeof(buffer[0])),
381 nullptr,
382 MOJO_WRITE_MESSAGE_FLAG_NONE)); 304 MOJO_WRITE_MESSAGE_FLAG_NONE));
383 305
384 // Discard from port 0. 306 // Discard from port 0.
385 buffer_size = 1; 307 buffer_size = 1;
386 EXPECT_EQ(MOJO_RESULT_RESOURCE_EXHAUSTED, 308 EXPECT_EQ(MOJO_RESULT_RESOURCE_EXHAUSTED,
387 mp->ReadMessage(0, 309 mp->ReadMessage(0, NullUserPointer(), NullUserPointer(), 0, nullptr,
388 NullUserPointer(),
389 NullUserPointer(),
390 0,
391 nullptr,
392 MOJO_READ_MESSAGE_FLAG_MAY_DISCARD)); 310 MOJO_READ_MESSAGE_FLAG_MAY_DISCARD));
393 311
394 // Read again from port 0 -- it should be empty. 312 // Read again from port 0 -- it should be empty.
395 buffer_size = kBufferSize; 313 buffer_size = kBufferSize;
396 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT, 314 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT,
397 mp->ReadMessage(0, 315 mp->ReadMessage(0, UserPointer<void>(buffer),
398 UserPointer<void>(buffer), 316 MakeUserPointer(&buffer_size), 0, nullptr,
399 MakeUserPointer(&buffer_size),
400 0,
401 nullptr,
402 MOJO_READ_MESSAGE_FLAG_MAY_DISCARD)); 317 MOJO_READ_MESSAGE_FLAG_MAY_DISCARD));
403 318
404 mp->Close(0); 319 mp->Close(0);
405 mp->Close(1); 320 mp->Close(1);
406 } 321 }
407 322
408 TEST(MessagePipeTest, BasicWaiting) { 323 TEST(MessagePipeTest, BasicWaiting) {
409 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalLocal()); 324 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalLocal());
410 Waiter waiter; 325 Waiter waiter;
411 HandleSignalsState hss; 326 HandleSignalsState hss;
412 327
413 int32_t buffer[1]; 328 int32_t buffer[1];
414 const uint32_t kBufferSize = static_cast<uint32_t>(sizeof(buffer)); 329 const uint32_t kBufferSize = static_cast<uint32_t>(sizeof(buffer));
415 uint32_t buffer_size; 330 uint32_t buffer_size;
416 331
417 // Always writable (until the other port is closed). 332 // Always writable (until the other port is closed).
418 waiter.Init(); 333 waiter.Init();
419 hss = HandleSignalsState(); 334 hss = HandleSignalsState();
420 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, 335 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS,
421 mp->AddWaiter(0, &waiter, MOJO_HANDLE_SIGNAL_WRITABLE, 0, &hss)); 336 mp->AddWaiter(0, &waiter, MOJO_HANDLE_SIGNAL_WRITABLE, 0, &hss));
422 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals); 337 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals);
423 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 338 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
424 hss.satisfiable_signals); 339 hss.satisfiable_signals);
425 waiter.Init(); 340 waiter.Init();
426 hss = HandleSignalsState(); 341 hss = HandleSignalsState();
427 EXPECT_EQ( 342 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS,
428 MOJO_RESULT_ALREADY_EXISTS, 343 mp->AddWaiter(0, &waiter, MOJO_HANDLE_SIGNAL_READABLE |
429 mp->AddWaiter(0, 344 MOJO_HANDLE_SIGNAL_WRITABLE,
430 &waiter, 345 0, &hss));
431 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
432 0,
433 &hss));
434 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals); 346 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals);
435 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 347 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
436 hss.satisfiable_signals); 348 hss.satisfiable_signals);
437 349
438 // Not yet readable. 350 // Not yet readable.
439 waiter.Init(); 351 waiter.Init();
440 ASSERT_EQ(MOJO_RESULT_OK, 352 ASSERT_EQ(MOJO_RESULT_OK,
441 mp->AddWaiter(0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 1, nullptr)); 353 mp->AddWaiter(0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 1, nullptr));
442 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, waiter.Wait(0, nullptr)); 354 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, waiter.Wait(0, nullptr));
443 hss = HandleSignalsState(); 355 hss = HandleSignalsState();
444 mp->RemoveWaiter(0, &waiter, &hss); 356 mp->RemoveWaiter(0, &waiter, &hss);
445 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals); 357 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals);
446 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 358 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
447 hss.satisfiable_signals); 359 hss.satisfiable_signals);
448 360
449 // Write from port 0 (to port 1), to make port 1 readable. 361 // Write from port 0 (to port 1), to make port 1 readable.
450 buffer[0] = 123456789; 362 buffer[0] = 123456789;
451 EXPECT_EQ(MOJO_RESULT_OK, 363 EXPECT_EQ(MOJO_RESULT_OK,
452 mp->WriteMessage(0, 364 mp->WriteMessage(0, UserPointer<const void>(buffer), kBufferSize,
453 UserPointer<const void>(buffer), 365 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
454 kBufferSize,
455 nullptr,
456 MOJO_WRITE_MESSAGE_FLAG_NONE));
457 366
458 // Port 1 should already be readable now. 367 // Port 1 should already be readable now.
459 waiter.Init(); 368 waiter.Init();
460 hss = HandleSignalsState(); 369 hss = HandleSignalsState();
461 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, 370 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS,
462 mp->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 2, &hss)); 371 mp->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 2, &hss));
463 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 372 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
464 hss.satisfied_signals); 373 hss.satisfied_signals);
465 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 374 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
466 hss.satisfiable_signals); 375 hss.satisfiable_signals);
467 waiter.Init(); 376 waiter.Init();
468 hss = HandleSignalsState(); 377 hss = HandleSignalsState();
469 EXPECT_EQ( 378 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS,
470 MOJO_RESULT_ALREADY_EXISTS, 379 mp->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE |
471 mp->AddWaiter(1, 380 MOJO_HANDLE_SIGNAL_WRITABLE,
472 &waiter, 381 0, &hss));
473 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
474 0,
475 &hss));
476 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 382 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
477 hss.satisfied_signals); 383 hss.satisfied_signals);
478 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 384 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
479 hss.satisfiable_signals); 385 hss.satisfiable_signals);
480 // ... and still writable. 386 // ... and still writable.
481 waiter.Init(); 387 waiter.Init();
482 hss = HandleSignalsState(); 388 hss = HandleSignalsState();
483 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, 389 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS,
484 mp->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_WRITABLE, 3, &hss)); 390 mp->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_WRITABLE, 3, &hss));
485 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 391 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
(...skipping 17 matching lines...) Expand all
503 hss = HandleSignalsState(); 409 hss = HandleSignalsState();
504 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, 410 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS,
505 mp->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 5, &hss)); 411 mp->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 5, &hss));
506 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals); 412 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals);
507 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfiable_signals); 413 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfiable_signals);
508 414
509 // Read from port 1. 415 // Read from port 1.
510 buffer[0] = 0; 416 buffer[0] = 0;
511 buffer_size = kBufferSize; 417 buffer_size = kBufferSize;
512 EXPECT_EQ(MOJO_RESULT_OK, 418 EXPECT_EQ(MOJO_RESULT_OK,
513 mp->ReadMessage(1, 419 mp->ReadMessage(1, UserPointer<void>(buffer),
514 UserPointer<void>(buffer), 420 MakeUserPointer(&buffer_size), 0, nullptr,
515 MakeUserPointer(&buffer_size),
516 0,
517 nullptr,
518 MOJO_READ_MESSAGE_FLAG_NONE)); 421 MOJO_READ_MESSAGE_FLAG_NONE));
519 EXPECT_EQ(123456789, buffer[0]); 422 EXPECT_EQ(123456789, buffer[0]);
520 423
521 // Now port 1 should no longer be readable. 424 // Now port 1 should no longer be readable.
522 waiter.Init(); 425 waiter.Init();
523 hss = HandleSignalsState(); 426 hss = HandleSignalsState();
524 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, 427 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
525 mp->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 6, nullptr)); 428 mp->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 6, nullptr));
526 EXPECT_EQ(0u, hss.satisfied_signals); 429 EXPECT_EQ(0u, hss.satisfied_signals);
527 EXPECT_EQ(0u, hss.satisfiable_signals); 430 EXPECT_EQ(0u, hss.satisfiable_signals);
528 431
529 mp->Close(1); 432 mp->Close(1);
530 } 433 }
531 434
532 TEST(MessagePipeTest, ThreadedWaiting) { 435 TEST(MessagePipeTest, ThreadedWaiting) {
533 int32_t buffer[1]; 436 int32_t buffer[1];
534 const uint32_t kBufferSize = static_cast<uint32_t>(sizeof(buffer)); 437 const uint32_t kBufferSize = static_cast<uint32_t>(sizeof(buffer));
535 438
536 MojoResult result; 439 MojoResult result;
537 uint32_t context; 440 uint32_t context;
538 441
539 // Write to wake up waiter waiting for read. 442 // Write to wake up waiter waiting for read.
540 { 443 {
541 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalLocal()); 444 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalLocal());
542 test::SimpleWaiterThread thread(&result, &context); 445 test::SimpleWaiterThread thread(&result, &context);
543 446
544 thread.waiter()->Init(); 447 thread.waiter()->Init();
545 ASSERT_EQ(MOJO_RESULT_OK, 448 ASSERT_EQ(MOJO_RESULT_OK,
546 mp->AddWaiter( 449 mp->AddWaiter(1, thread.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 1,
547 1, thread.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 1, nullptr)); 450 nullptr));
548 thread.Start(); 451 thread.Start();
549 452
550 buffer[0] = 123456789; 453 buffer[0] = 123456789;
551 // Write from port 0 (to port 1), which should wake up the waiter. 454 // Write from port 0 (to port 1), which should wake up the waiter.
552 EXPECT_EQ(MOJO_RESULT_OK, 455 EXPECT_EQ(MOJO_RESULT_OK,
553 mp->WriteMessage(0, 456 mp->WriteMessage(0, UserPointer<const void>(buffer), kBufferSize,
554 UserPointer<const void>(buffer), 457 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
555 kBufferSize,
556 nullptr,
557 MOJO_WRITE_MESSAGE_FLAG_NONE));
558 458
559 HandleSignalsState hss; 459 HandleSignalsState hss;
560 mp->RemoveWaiter(1, thread.waiter(), &hss); 460 mp->RemoveWaiter(1, thread.waiter(), &hss);
561 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 461 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
562 hss.satisfied_signals); 462 hss.satisfied_signals);
563 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 463 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
564 hss.satisfiable_signals); 464 hss.satisfiable_signals);
565 465
566 mp->Close(0); 466 mp->Close(0);
567 mp->Close(1); 467 mp->Close(1);
568 } // Joins |thread|. 468 } // Joins |thread|.
569 // The waiter should have woken up successfully. 469 // The waiter should have woken up successfully.
570 EXPECT_EQ(MOJO_RESULT_OK, result); 470 EXPECT_EQ(MOJO_RESULT_OK, result);
571 EXPECT_EQ(1u, context); 471 EXPECT_EQ(1u, context);
572 472
573 // Close to cancel waiter. 473 // Close to cancel waiter.
574 { 474 {
575 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalLocal()); 475 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalLocal());
576 test::SimpleWaiterThread thread(&result, &context); 476 test::SimpleWaiterThread thread(&result, &context);
577 477
578 thread.waiter()->Init(); 478 thread.waiter()->Init();
579 ASSERT_EQ(MOJO_RESULT_OK, 479 ASSERT_EQ(MOJO_RESULT_OK,
580 mp->AddWaiter( 480 mp->AddWaiter(1, thread.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 2,
581 1, thread.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 2, nullptr)); 481 nullptr));
582 thread.Start(); 482 thread.Start();
583 483
584 // Close port 1 first -- this should result in the waiter being cancelled. 484 // Close port 1 first -- this should result in the waiter being cancelled.
585 mp->CancelAllWaiters(1); 485 mp->CancelAllWaiters(1);
586 mp->Close(1); 486 mp->Close(1);
587 487
588 // Port 1 is closed, so |Dispatcher::RemoveWaiter()| wouldn't call into the 488 // Port 1 is closed, so |Dispatcher::RemoveWaiter()| wouldn't call into the
589 // |MessagePipe| to remove any waiter. 489 // |MessagePipe| to remove any waiter.
590 490
591 mp->Close(0); 491 mp->Close(0);
592 } // Joins |thread|. 492 } // Joins |thread|.
593 EXPECT_EQ(MOJO_RESULT_CANCELLED, result); 493 EXPECT_EQ(MOJO_RESULT_CANCELLED, result);
594 EXPECT_EQ(2u, context); 494 EXPECT_EQ(2u, context);
595 495
596 // Close to make waiter un-wake-up-able. 496 // Close to make waiter un-wake-up-able.
597 { 497 {
598 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalLocal()); 498 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalLocal());
599 test::SimpleWaiterThread thread(&result, &context); 499 test::SimpleWaiterThread thread(&result, &context);
600 500
601 thread.waiter()->Init(); 501 thread.waiter()->Init();
602 ASSERT_EQ(MOJO_RESULT_OK, 502 ASSERT_EQ(MOJO_RESULT_OK,
603 mp->AddWaiter( 503 mp->AddWaiter(1, thread.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 3,
604 1, thread.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 3, nullptr)); 504 nullptr));
605 thread.Start(); 505 thread.Start();
606 506
607 // Close port 0 first -- this should wake the waiter up, since port 1 will 507 // Close port 0 first -- this should wake the waiter up, since port 1 will
608 // never be readable. 508 // never be readable.
609 mp->CancelAllWaiters(0); 509 mp->CancelAllWaiters(0);
610 mp->Close(0); 510 mp->Close(0);
611 511
612 HandleSignalsState hss; 512 HandleSignalsState hss;
613 mp->RemoveWaiter(1, thread.waiter(), &hss); 513 mp->RemoveWaiter(1, thread.waiter(), &hss);
614 EXPECT_EQ(0u, hss.satisfied_signals); 514 EXPECT_EQ(0u, hss.satisfied_signals);
615 EXPECT_EQ(0u, hss.satisfiable_signals); 515 EXPECT_EQ(0u, hss.satisfiable_signals);
616 516
617 mp->CancelAllWaiters(1); 517 mp->CancelAllWaiters(1);
618 mp->Close(1); 518 mp->Close(1);
619 } // Joins |thread|. 519 } // Joins |thread|.
620 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result); 520 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result);
621 EXPECT_EQ(3u, context); 521 EXPECT_EQ(3u, context);
622 } 522 }
623 523
624 } // namespace 524 } // namespace
625 } // namespace system 525 } // namespace system
626 } // namespace mojo 526 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/message_pipe_test_utils.cc ('k') | mojo/edk/system/multiprocess_message_pipe_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698