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

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

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