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

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

Issue 728043002: Revert of Update mojo sdk to rev afb4440fd5a10cba980878c326180b7ad7960480 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/edk/system/message_pipe_dispatcher.cc ('k') | mojo/edk/system/message_pipe_perftest.cc » ('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 // NOTE(vtl): Some of these tests are inherently flaky (e.g., if run on a 5 // NOTE(vtl): Some of these tests are inherently flaky (e.g., if run on a
6 // heavily-loaded system). Sorry. |test::EpsilonTimeout()| may be increased to 6 // heavily-loaded system). Sorry. |test::EpsilonTimeout()| may be increased to
7 // increase tolerance and reduce observed flakiness (though doing so reduces the 7 // increase tolerance and reduce observed flakiness (though doing so reduces the
8 // meaningfulness of the test). 8 // meaningfulness of the test).
9 9
10 #include "mojo/edk/system/message_pipe_dispatcher.h" 10 #include "mojo/edk/system/message_pipe_dispatcher.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 hss.satisfiable_signals); 61 hss.satisfiable_signals);
62 // Shouldn't need to remove the waiter (it was not added). 62 // Shouldn't need to remove the waiter (it was not added).
63 63
64 // Add a readable waiter to |d0|, then make it readable (by writing to 64 // Add a readable waiter to |d0|, then make it readable (by writing to
65 // |d1|), then wait. 65 // |d1|), then wait.
66 w.Init(); 66 w.Init();
67 ASSERT_EQ(MOJO_RESULT_OK, 67 ASSERT_EQ(MOJO_RESULT_OK,
68 d0->AddWaiter(&w, MOJO_HANDLE_SIGNAL_READABLE, 1, nullptr)); 68 d0->AddWaiter(&w, MOJO_HANDLE_SIGNAL_READABLE, 1, nullptr));
69 buffer[0] = 123456789; 69 buffer[0] = 123456789;
70 EXPECT_EQ(MOJO_RESULT_OK, 70 EXPECT_EQ(MOJO_RESULT_OK,
71 d1->WriteMessage(UserPointer<const void>(buffer), kBufferSize, 71 d1->WriteMessage(UserPointer<const void>(buffer),
72 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); 72 kBufferSize,
73 nullptr,
74 MOJO_WRITE_MESSAGE_FLAG_NONE));
73 stopwatch.Start(); 75 stopwatch.Start();
74 EXPECT_EQ(MOJO_RESULT_OK, w.Wait(MOJO_DEADLINE_INDEFINITE, &context)); 76 EXPECT_EQ(MOJO_RESULT_OK, w.Wait(MOJO_DEADLINE_INDEFINITE, &context));
75 EXPECT_EQ(1u, context); 77 EXPECT_EQ(1u, context);
76 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); 78 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout());
77 hss = HandleSignalsState(); 79 hss = HandleSignalsState();
78 d0->RemoveWaiter(&w, &hss); 80 d0->RemoveWaiter(&w, &hss);
79 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 81 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
80 hss.satisfied_signals); 82 hss.satisfied_signals);
81 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 83 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
82 hss.satisfiable_signals); 84 hss.satisfiable_signals);
83 85
84 // Try adding a readable waiter when already readable (from above). 86 // Try adding a readable waiter when already readable (from above).
85 w.Init(); 87 w.Init();
86 hss = HandleSignalsState(); 88 hss = HandleSignalsState();
87 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, 89 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS,
88 d0->AddWaiter(&w, MOJO_HANDLE_SIGNAL_READABLE, 2, &hss)); 90 d0->AddWaiter(&w, MOJO_HANDLE_SIGNAL_READABLE, 2, &hss));
89 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 91 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
90 hss.satisfied_signals); 92 hss.satisfied_signals);
91 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 93 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
92 hss.satisfiable_signals); 94 hss.satisfiable_signals);
93 // Shouldn't need to remove the waiter (it was not added). 95 // Shouldn't need to remove the waiter (it was not added).
94 96
95 // Make |d0| no longer readable (by reading from it). 97 // Make |d0| no longer readable (by reading from it).
96 buffer[0] = 0; 98 buffer[0] = 0;
97 buffer_size = kBufferSize; 99 buffer_size = kBufferSize;
98 EXPECT_EQ(MOJO_RESULT_OK, 100 EXPECT_EQ(MOJO_RESULT_OK,
99 d0->ReadMessage(UserPointer<void>(buffer), 101 d0->ReadMessage(UserPointer<void>(buffer),
100 MakeUserPointer(&buffer_size), 0, nullptr, 102 MakeUserPointer(&buffer_size),
103 0,
104 nullptr,
101 MOJO_READ_MESSAGE_FLAG_NONE)); 105 MOJO_READ_MESSAGE_FLAG_NONE));
102 EXPECT_EQ(kBufferSize, buffer_size); 106 EXPECT_EQ(kBufferSize, buffer_size);
103 EXPECT_EQ(123456789, buffer[0]); 107 EXPECT_EQ(123456789, buffer[0]);
104 108
105 // Wait for zero time for readability on |d0| (will time out). 109 // Wait for zero time for readability on |d0| (will time out).
106 w.Init(); 110 w.Init();
107 ASSERT_EQ(MOJO_RESULT_OK, 111 ASSERT_EQ(MOJO_RESULT_OK,
108 d0->AddWaiter(&w, MOJO_HANDLE_SIGNAL_READABLE, 3, nullptr)); 112 d0->AddWaiter(&w, MOJO_HANDLE_SIGNAL_READABLE, 3, nullptr));
109 stopwatch.Start(); 113 stopwatch.Start();
110 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, w.Wait(0, nullptr)); 114 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, w.Wait(0, nullptr));
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 { 150 {
147 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalLocal()); 151 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalLocal());
148 d0->Init(mp, 0); 152 d0->Init(mp, 0);
149 d1->Init(mp, 1); 153 d1->Init(mp, 1);
150 } 154 }
151 155
152 // |WriteMessage|: 156 // |WriteMessage|:
153 // Huge buffer size. 157 // Huge buffer size.
154 EXPECT_EQ(MOJO_RESULT_RESOURCE_EXHAUSTED, 158 EXPECT_EQ(MOJO_RESULT_RESOURCE_EXHAUSTED,
155 d0->WriteMessage(UserPointer<const void>(buffer), 159 d0->WriteMessage(UserPointer<const void>(buffer),
156 std::numeric_limits<uint32_t>::max(), nullptr, 160 std::numeric_limits<uint32_t>::max(),
161 nullptr,
157 MOJO_WRITE_MESSAGE_FLAG_NONE)); 162 MOJO_WRITE_MESSAGE_FLAG_NONE));
158 163
159 EXPECT_EQ(MOJO_RESULT_OK, d0->Close()); 164 EXPECT_EQ(MOJO_RESULT_OK, d0->Close());
160 EXPECT_EQ(MOJO_RESULT_OK, d1->Close()); 165 EXPECT_EQ(MOJO_RESULT_OK, d1->Close());
161 } 166 }
162 167
163 // These test invalid arguments that should cause death if we're being paranoid 168 // These test invalid arguments that should cause death if we're being paranoid
164 // about checking arguments (which we would want to do if, e.g., we were in a 169 // about checking arguments (which we would want to do if, e.g., we were in a
165 // true "kernel" situation, but we might not want to do otherwise for 170 // true "kernel" situation, but we might not want to do otherwise for
166 // performance reasons). Probably blatant errors like passing in null pointers 171 // performance reasons). Probably blatant errors like passing in null pointers
167 // (for required pointer arguments) will still cause death, but perhaps not 172 // (for required pointer arguments) will still cause death, but perhaps not
168 // predictably. 173 // predictably.
169 TEST(MessagePipeDispatcherTest, InvalidParamsDeath) { 174 TEST(MessagePipeDispatcherTest, InvalidParamsDeath) {
170 const char kMemoryCheckFailedRegex[] = "Check failed"; 175 const char kMemoryCheckFailedRegex[] = "Check failed";
171 176
172 scoped_refptr<MessagePipeDispatcher> d0( 177 scoped_refptr<MessagePipeDispatcher> d0(
173 new MessagePipeDispatcher(MessagePipeDispatcher::kDefaultCreateOptions)); 178 new MessagePipeDispatcher(MessagePipeDispatcher::kDefaultCreateOptions));
174 scoped_refptr<MessagePipeDispatcher> d1( 179 scoped_refptr<MessagePipeDispatcher> d1(
175 new MessagePipeDispatcher(MessagePipeDispatcher::kDefaultCreateOptions)); 180 new MessagePipeDispatcher(MessagePipeDispatcher::kDefaultCreateOptions));
176 { 181 {
177 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalLocal()); 182 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalLocal());
178 d0->Init(mp, 0); 183 d0->Init(mp, 0);
179 d1->Init(mp, 1); 184 d1->Init(mp, 1);
180 } 185 }
181 186
182 // |WriteMessage|: 187 // |WriteMessage|:
183 // Null buffer with nonzero buffer size. 188 // Null buffer with nonzero buffer size.
184 EXPECT_DEATH_IF_SUPPORTED(d0->WriteMessage(NullUserPointer(), 1, nullptr, 189 EXPECT_DEATH_IF_SUPPORTED(
185 MOJO_WRITE_MESSAGE_FLAG_NONE), 190 d0->WriteMessage(
186 kMemoryCheckFailedRegex); 191 NullUserPointer(), 1, nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE),
192 kMemoryCheckFailedRegex);
187 193
188 // |ReadMessage|: 194 // |ReadMessage|:
189 // Null buffer with nonzero buffer size. 195 // Null buffer with nonzero buffer size.
190 // First write something so that we actually have something to read. 196 // First write something so that we actually have something to read.
191 EXPECT_EQ(MOJO_RESULT_OK, 197 EXPECT_EQ(MOJO_RESULT_OK,
192 d1->WriteMessage(UserPointer<const void>("x"), 1, nullptr, 198 d1->WriteMessage(UserPointer<const void>("x"),
199 1,
200 nullptr,
193 MOJO_WRITE_MESSAGE_FLAG_NONE)); 201 MOJO_WRITE_MESSAGE_FLAG_NONE));
194 uint32_t buffer_size = 1; 202 uint32_t buffer_size = 1;
195 EXPECT_DEATH_IF_SUPPORTED( 203 EXPECT_DEATH_IF_SUPPORTED(d0->ReadMessage(NullUserPointer(),
196 d0->ReadMessage(NullUserPointer(), MakeUserPointer(&buffer_size), 0, 204 MakeUserPointer(&buffer_size),
197 nullptr, MOJO_READ_MESSAGE_FLAG_NONE), 205 0,
198 kMemoryCheckFailedRegex); 206 nullptr,
207 MOJO_READ_MESSAGE_FLAG_NONE),
208 kMemoryCheckFailedRegex);
199 209
200 EXPECT_EQ(MOJO_RESULT_OK, d0->Close()); 210 EXPECT_EQ(MOJO_RESULT_OK, d0->Close());
201 EXPECT_EQ(MOJO_RESULT_OK, d1->Close()); 211 EXPECT_EQ(MOJO_RESULT_OK, d1->Close());
202 } 212 }
203 213
204 // Test what happens when one end is closed (single-threaded test). 214 // Test what happens when one end is closed (single-threaded test).
205 TEST(MessagePipeDispatcherTest, BasicClosed) { 215 TEST(MessagePipeDispatcherTest, BasicClosed) {
206 int32_t buffer[1]; 216 int32_t buffer[1];
207 const uint32_t kBufferSize = static_cast<uint32_t>(sizeof(buffer)); 217 const uint32_t kBufferSize = static_cast<uint32_t>(sizeof(buffer));
208 uint32_t buffer_size; 218 uint32_t buffer_size;
209 219
210 // Run this test both with |d0| as port 0, |d1| as port 1 and vice versa. 220 // Run this test both with |d0| as port 0, |d1| as port 1 and vice versa.
211 for (unsigned i = 0; i < 2; i++) { 221 for (unsigned i = 0; i < 2; i++) {
212 scoped_refptr<MessagePipeDispatcher> d0(new MessagePipeDispatcher( 222 scoped_refptr<MessagePipeDispatcher> d0(new MessagePipeDispatcher(
213 MessagePipeDispatcher::kDefaultCreateOptions)); 223 MessagePipeDispatcher::kDefaultCreateOptions));
214 scoped_refptr<MessagePipeDispatcher> d1(new MessagePipeDispatcher( 224 scoped_refptr<MessagePipeDispatcher> d1(new MessagePipeDispatcher(
215 MessagePipeDispatcher::kDefaultCreateOptions)); 225 MessagePipeDispatcher::kDefaultCreateOptions));
216 { 226 {
217 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalLocal()); 227 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalLocal());
218 d0->Init(mp, i); // 0, 1. 228 d0->Init(mp, i); // 0, 1.
219 d1->Init(mp, i ^ 1); // 1, 0. 229 d1->Init(mp, i ^ 1); // 1, 0.
220 } 230 }
221 Waiter w; 231 Waiter w;
222 HandleSignalsState hss; 232 HandleSignalsState hss;
223 233
224 // Write (twice) to |d1|. 234 // Write (twice) to |d1|.
225 buffer[0] = 123456789; 235 buffer[0] = 123456789;
226 EXPECT_EQ(MOJO_RESULT_OK, 236 EXPECT_EQ(MOJO_RESULT_OK,
227 d1->WriteMessage(UserPointer<const void>(buffer), kBufferSize, 237 d1->WriteMessage(UserPointer<const void>(buffer),
228 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); 238 kBufferSize,
239 nullptr,
240 MOJO_WRITE_MESSAGE_FLAG_NONE));
229 buffer[0] = 234567890; 241 buffer[0] = 234567890;
230 EXPECT_EQ(MOJO_RESULT_OK, 242 EXPECT_EQ(MOJO_RESULT_OK,
231 d1->WriteMessage(UserPointer<const void>(buffer), kBufferSize, 243 d1->WriteMessage(UserPointer<const void>(buffer),
232 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); 244 kBufferSize,
245 nullptr,
246 MOJO_WRITE_MESSAGE_FLAG_NONE));
233 247
234 // Try waiting for readable on |d0|; should fail (already satisfied). 248 // Try waiting for readable on |d0|; should fail (already satisfied).
235 w.Init(); 249 w.Init();
236 hss = HandleSignalsState(); 250 hss = HandleSignalsState();
237 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, 251 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS,
238 d0->AddWaiter(&w, MOJO_HANDLE_SIGNAL_READABLE, 0, &hss)); 252 d0->AddWaiter(&w, MOJO_HANDLE_SIGNAL_READABLE, 0, &hss));
239 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 253 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
240 hss.satisfied_signals); 254 hss.satisfied_signals);
241 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 255 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
242 hss.satisfiable_signals); 256 hss.satisfiable_signals);
243 257
244 // Try reading from |d1|; should fail (nothing to read). 258 // Try reading from |d1|; should fail (nothing to read).
245 buffer[0] = 0; 259 buffer[0] = 0;
246 buffer_size = kBufferSize; 260 buffer_size = kBufferSize;
247 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT, 261 EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT,
248 d1->ReadMessage(UserPointer<void>(buffer), 262 d1->ReadMessage(UserPointer<void>(buffer),
249 MakeUserPointer(&buffer_size), 0, nullptr, 263 MakeUserPointer(&buffer_size),
264 0,
265 nullptr,
250 MOJO_READ_MESSAGE_FLAG_NONE)); 266 MOJO_READ_MESSAGE_FLAG_NONE));
251 267
252 // Close |d1|. 268 // Close |d1|.
253 EXPECT_EQ(MOJO_RESULT_OK, d1->Close()); 269 EXPECT_EQ(MOJO_RESULT_OK, d1->Close());
254 270
255 // Try waiting for readable on |d0|; should fail (already satisfied). 271 // Try waiting for readable on |d0|; should fail (already satisfied).
256 w.Init(); 272 w.Init();
257 hss = HandleSignalsState(); 273 hss = HandleSignalsState();
258 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, 274 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS,
259 d0->AddWaiter(&w, MOJO_HANDLE_SIGNAL_READABLE, 1, &hss)); 275 d0->AddWaiter(&w, MOJO_HANDLE_SIGNAL_READABLE, 1, &hss));
260 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals); 276 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals);
261 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfiable_signals); 277 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfiable_signals);
262 278
263 // Read from |d0|. 279 // Read from |d0|.
264 buffer[0] = 0; 280 buffer[0] = 0;
265 buffer_size = kBufferSize; 281 buffer_size = kBufferSize;
266 EXPECT_EQ(MOJO_RESULT_OK, 282 EXPECT_EQ(MOJO_RESULT_OK,
267 d0->ReadMessage(UserPointer<void>(buffer), 283 d0->ReadMessage(UserPointer<void>(buffer),
268 MakeUserPointer(&buffer_size), 0, nullptr, 284 MakeUserPointer(&buffer_size),
285 0,
286 nullptr,
269 MOJO_READ_MESSAGE_FLAG_NONE)); 287 MOJO_READ_MESSAGE_FLAG_NONE));
270 EXPECT_EQ(kBufferSize, buffer_size); 288 EXPECT_EQ(kBufferSize, buffer_size);
271 EXPECT_EQ(123456789, buffer[0]); 289 EXPECT_EQ(123456789, buffer[0]);
272 290
273 // Try waiting for readable on |d0|; should fail (already satisfied). 291 // Try waiting for readable on |d0|; should fail (already satisfied).
274 w.Init(); 292 w.Init();
275 hss = HandleSignalsState(); 293 hss = HandleSignalsState();
276 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, 294 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS,
277 d0->AddWaiter(&w, MOJO_HANDLE_SIGNAL_READABLE, 2, &hss)); 295 d0->AddWaiter(&w, MOJO_HANDLE_SIGNAL_READABLE, 2, &hss));
278 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals); 296 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals);
279 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfiable_signals); 297 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfiable_signals);
280 298
281 // Read again from |d0|. 299 // Read again from |d0|.
282 buffer[0] = 0; 300 buffer[0] = 0;
283 buffer_size = kBufferSize; 301 buffer_size = kBufferSize;
284 EXPECT_EQ(MOJO_RESULT_OK, 302 EXPECT_EQ(MOJO_RESULT_OK,
285 d0->ReadMessage(UserPointer<void>(buffer), 303 d0->ReadMessage(UserPointer<void>(buffer),
286 MakeUserPointer(&buffer_size), 0, nullptr, 304 MakeUserPointer(&buffer_size),
305 0,
306 nullptr,
287 MOJO_READ_MESSAGE_FLAG_NONE)); 307 MOJO_READ_MESSAGE_FLAG_NONE));
288 EXPECT_EQ(kBufferSize, buffer_size); 308 EXPECT_EQ(kBufferSize, buffer_size);
289 EXPECT_EQ(234567890, buffer[0]); 309 EXPECT_EQ(234567890, buffer[0]);
290 310
291 // Try waiting for readable on |d0|; should fail (unsatisfiable). 311 // Try waiting for readable on |d0|; should fail (unsatisfiable).
292 w.Init(); 312 w.Init();
293 hss = HandleSignalsState(); 313 hss = HandleSignalsState();
294 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, 314 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
295 d0->AddWaiter(&w, MOJO_HANDLE_SIGNAL_READABLE, 3, &hss)); 315 d0->AddWaiter(&w, MOJO_HANDLE_SIGNAL_READABLE, 3, &hss));
296 EXPECT_EQ(0u, hss.satisfied_signals); 316 EXPECT_EQ(0u, hss.satisfied_signals);
297 EXPECT_EQ(0u, hss.satisfiable_signals); 317 EXPECT_EQ(0u, hss.satisfiable_signals);
298 318
299 // Try waiting for writable on |d0|; should fail (unsatisfiable). 319 // Try waiting for writable on |d0|; should fail (unsatisfiable).
300 w.Init(); 320 w.Init();
301 hss = HandleSignalsState(); 321 hss = HandleSignalsState();
302 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, 322 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
303 d0->AddWaiter(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 4, &hss)); 323 d0->AddWaiter(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 4, &hss));
304 EXPECT_EQ(0u, hss.satisfied_signals); 324 EXPECT_EQ(0u, hss.satisfied_signals);
305 EXPECT_EQ(0u, hss.satisfiable_signals); 325 EXPECT_EQ(0u, hss.satisfiable_signals);
306 326
307 // Try reading from |d0|; should fail (nothing to read and other end 327 // Try reading from |d0|; should fail (nothing to read and other end
308 // closed). 328 // closed).
309 buffer[0] = 0; 329 buffer[0] = 0;
310 buffer_size = kBufferSize; 330 buffer_size = kBufferSize;
311 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, 331 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
312 d0->ReadMessage(UserPointer<void>(buffer), 332 d0->ReadMessage(UserPointer<void>(buffer),
313 MakeUserPointer(&buffer_size), 0, nullptr, 333 MakeUserPointer(&buffer_size),
334 0,
335 nullptr,
314 MOJO_READ_MESSAGE_FLAG_NONE)); 336 MOJO_READ_MESSAGE_FLAG_NONE));
315 337
316 // Try writing to |d0|; should fail (other end closed). 338 // Try writing to |d0|; should fail (other end closed).
317 buffer[0] = 345678901; 339 buffer[0] = 345678901;
318 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, 340 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
319 d0->WriteMessage(UserPointer<const void>(buffer), kBufferSize, 341 d0->WriteMessage(UserPointer<const void>(buffer),
320 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); 342 kBufferSize,
343 nullptr,
344 MOJO_WRITE_MESSAGE_FLAG_NONE));
321 345
322 EXPECT_EQ(MOJO_RESULT_OK, d0->Close()); 346 EXPECT_EQ(MOJO_RESULT_OK, d0->Close());
323 } 347 }
324 } 348 }
325 349
326 #if defined(OS_WIN) 350 #if defined(OS_WIN)
327 // http://crbug.com/396386 351 // http://crbug.com/396386
328 #define MAYBE_BasicThreaded DISABLED_BasicThreaded 352 #define MAYBE_BasicThreaded DISABLED_BasicThreaded
329 #else 353 #else
330 #define MAYBE_BasicThreaded BasicThreaded 354 #define MAYBE_BasicThreaded BasicThreaded
(...skipping 16 matching lines...) Expand all
347 scoped_refptr<MessagePipeDispatcher> d1(new MessagePipeDispatcher( 371 scoped_refptr<MessagePipeDispatcher> d1(new MessagePipeDispatcher(
348 MessagePipeDispatcher::kDefaultCreateOptions)); 372 MessagePipeDispatcher::kDefaultCreateOptions));
349 { 373 {
350 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalLocal()); 374 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalLocal());
351 d0->Init(mp, i); // 0, 1. 375 d0->Init(mp, i); // 0, 1.
352 d1->Init(mp, i ^ 1); // 1, 0. 376 d1->Init(mp, i ^ 1); // 1, 0.
353 } 377 }
354 378
355 // Wait for readable on |d1|, which will become readable after some time. 379 // Wait for readable on |d1|, which will become readable after some time.
356 { 380 {
357 test::WaiterThread thread(d1, MOJO_HANDLE_SIGNAL_READABLE, 381 test::WaiterThread thread(d1,
358 MOJO_DEADLINE_INDEFINITE, 1, &did_wait, &result, 382 MOJO_HANDLE_SIGNAL_READABLE,
359 &context, &hss); 383 MOJO_DEADLINE_INDEFINITE,
384 1,
385 &did_wait,
386 &result,
387 &context,
388 &hss);
360 stopwatch.Start(); 389 stopwatch.Start();
361 thread.Start(); 390 thread.Start();
362 base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); 391 base::PlatformThread::Sleep(2 * test::EpsilonTimeout());
363 // Wake it up by writing to |d0|. 392 // Wake it up by writing to |d0|.
364 buffer[0] = 123456789; 393 buffer[0] = 123456789;
365 EXPECT_EQ(MOJO_RESULT_OK, 394 EXPECT_EQ(MOJO_RESULT_OK,
366 d0->WriteMessage(UserPointer<const void>(buffer), kBufferSize, 395 d0->WriteMessage(UserPointer<const void>(buffer),
367 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); 396 kBufferSize,
397 nullptr,
398 MOJO_WRITE_MESSAGE_FLAG_NONE));
368 } // Joins the thread. 399 } // Joins the thread.
369 elapsed = stopwatch.Elapsed(); 400 elapsed = stopwatch.Elapsed();
370 EXPECT_GT(elapsed, (2 - 1) * test::EpsilonTimeout()); 401 EXPECT_GT(elapsed, (2 - 1) * test::EpsilonTimeout());
371 EXPECT_LT(elapsed, (2 + 1) * test::EpsilonTimeout()); 402 EXPECT_LT(elapsed, (2 + 1) * test::EpsilonTimeout());
372 EXPECT_TRUE(did_wait); 403 EXPECT_TRUE(did_wait);
373 EXPECT_EQ(MOJO_RESULT_OK, result); 404 EXPECT_EQ(MOJO_RESULT_OK, result);
374 EXPECT_EQ(1u, context); 405 EXPECT_EQ(1u, context);
375 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 406 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
376 hss.satisfied_signals); 407 hss.satisfied_signals);
377 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 408 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
378 hss.satisfiable_signals); 409 hss.satisfiable_signals);
379 410
380 // Now |d1| is already readable. Try waiting for it again. 411 // Now |d1| is already readable. Try waiting for it again.
381 { 412 {
382 test::WaiterThread thread(d1, MOJO_HANDLE_SIGNAL_READABLE, 413 test::WaiterThread thread(d1,
383 MOJO_DEADLINE_INDEFINITE, 2, &did_wait, &result, 414 MOJO_HANDLE_SIGNAL_READABLE,
384 &context, &hss); 415 MOJO_DEADLINE_INDEFINITE,
416 2,
417 &did_wait,
418 &result,
419 &context,
420 &hss);
385 stopwatch.Start(); 421 stopwatch.Start();
386 thread.Start(); 422 thread.Start();
387 } // Joins the thread. 423 } // Joins the thread.
388 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); 424 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout());
389 EXPECT_FALSE(did_wait); 425 EXPECT_FALSE(did_wait);
390 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, result); 426 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, result);
391 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 427 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
392 hss.satisfied_signals); 428 hss.satisfied_signals);
393 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 429 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
394 hss.satisfiable_signals); 430 hss.satisfiable_signals);
395 431
396 // Consume what we wrote to |d0|. 432 // Consume what we wrote to |d0|.
397 buffer[0] = 0; 433 buffer[0] = 0;
398 buffer_size = kBufferSize; 434 buffer_size = kBufferSize;
399 EXPECT_EQ(MOJO_RESULT_OK, 435 EXPECT_EQ(MOJO_RESULT_OK,
400 d1->ReadMessage(UserPointer<void>(buffer), 436 d1->ReadMessage(UserPointer<void>(buffer),
401 MakeUserPointer(&buffer_size), 0, nullptr, 437 MakeUserPointer(&buffer_size),
438 0,
439 nullptr,
402 MOJO_READ_MESSAGE_FLAG_NONE)); 440 MOJO_READ_MESSAGE_FLAG_NONE));
403 EXPECT_EQ(kBufferSize, buffer_size); 441 EXPECT_EQ(kBufferSize, buffer_size);
404 EXPECT_EQ(123456789, buffer[0]); 442 EXPECT_EQ(123456789, buffer[0]);
405 443
406 // Wait for readable on |d1| and close |d0| after some time, which should 444 // Wait for readable on |d1| and close |d0| after some time, which should
407 // cancel that wait. 445 // cancel that wait.
408 { 446 {
409 test::WaiterThread thread(d1, MOJO_HANDLE_SIGNAL_READABLE, 447 test::WaiterThread thread(d1,
410 MOJO_DEADLINE_INDEFINITE, 3, &did_wait, &result, 448 MOJO_HANDLE_SIGNAL_READABLE,
411 &context, &hss); 449 MOJO_DEADLINE_INDEFINITE,
450 3,
451 &did_wait,
452 &result,
453 &context,
454 &hss);
412 stopwatch.Start(); 455 stopwatch.Start();
413 thread.Start(); 456 thread.Start();
414 base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); 457 base::PlatformThread::Sleep(2 * test::EpsilonTimeout());
415 EXPECT_EQ(MOJO_RESULT_OK, d0->Close()); 458 EXPECT_EQ(MOJO_RESULT_OK, d0->Close());
416 } // Joins the thread. 459 } // Joins the thread.
417 elapsed = stopwatch.Elapsed(); 460 elapsed = stopwatch.Elapsed();
418 EXPECT_GT(elapsed, (2 - 1) * test::EpsilonTimeout()); 461 EXPECT_GT(elapsed, (2 - 1) * test::EpsilonTimeout());
419 EXPECT_LT(elapsed, (2 + 1) * test::EpsilonTimeout()); 462 EXPECT_LT(elapsed, (2 + 1) * test::EpsilonTimeout());
420 EXPECT_TRUE(did_wait); 463 EXPECT_TRUE(did_wait);
421 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result); 464 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result);
(...skipping 11 matching lines...) Expand all
433 MessagePipeDispatcher::kDefaultCreateOptions)); 476 MessagePipeDispatcher::kDefaultCreateOptions));
434 { 477 {
435 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalLocal()); 478 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalLocal());
436 d0->Init(mp, i); // 0, 1. 479 d0->Init(mp, i); // 0, 1.
437 d1->Init(mp, i ^ 1); // 1, 0. 480 d1->Init(mp, i ^ 1); // 1, 0.
438 } 481 }
439 482
440 // Wait for readable on |d1| and close |d1| after some time, which should 483 // Wait for readable on |d1| and close |d1| after some time, which should
441 // cancel that wait. 484 // cancel that wait.
442 { 485 {
443 test::WaiterThread thread(d1, MOJO_HANDLE_SIGNAL_READABLE, 486 test::WaiterThread thread(d1,
444 MOJO_DEADLINE_INDEFINITE, 4, &did_wait, &result, 487 MOJO_HANDLE_SIGNAL_READABLE,
445 &context, &hss); 488 MOJO_DEADLINE_INDEFINITE,
489 4,
490 &did_wait,
491 &result,
492 &context,
493 &hss);
446 stopwatch.Start(); 494 stopwatch.Start();
447 thread.Start(); 495 thread.Start();
448 base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); 496 base::PlatformThread::Sleep(2 * test::EpsilonTimeout());
449 EXPECT_EQ(MOJO_RESULT_OK, d1->Close()); 497 EXPECT_EQ(MOJO_RESULT_OK, d1->Close());
450 } // Joins the thread. 498 } // Joins the thread.
451 elapsed = stopwatch.Elapsed(); 499 elapsed = stopwatch.Elapsed();
452 EXPECT_GT(elapsed, (2 - 1) * test::EpsilonTimeout()); 500 EXPECT_GT(elapsed, (2 - 1) * test::EpsilonTimeout());
453 EXPECT_LT(elapsed, (2 + 1) * test::EpsilonTimeout()); 501 EXPECT_LT(elapsed, (2 + 1) * test::EpsilonTimeout());
454 EXPECT_TRUE(did_wait); 502 EXPECT_TRUE(did_wait);
455 EXPECT_EQ(MOJO_RESULT_CANCELLED, result); 503 EXPECT_EQ(MOJO_RESULT_CANCELLED, result);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 539
492 // Number of messages to write. 540 // Number of messages to write.
493 *messages_written_ = static_cast<size_t>(base::RandInt(1000, 6000)); 541 *messages_written_ = static_cast<size_t>(base::RandInt(1000, 6000));
494 542
495 // Write messages. 543 // Write messages.
496 for (size_t i = 0; i < *messages_written_; i++) { 544 for (size_t i = 0; i < *messages_written_; i++) {
497 uint32_t bytes_to_write = static_cast<uint32_t>( 545 uint32_t bytes_to_write = static_cast<uint32_t>(
498 base::RandInt(1, static_cast<int>(kMaxMessageSize))); 546 base::RandInt(1, static_cast<int>(kMaxMessageSize)));
499 EXPECT_EQ(MOJO_RESULT_OK, 547 EXPECT_EQ(MOJO_RESULT_OK,
500 write_dispatcher_->WriteMessage(UserPointer<const void>(buffer), 548 write_dispatcher_->WriteMessage(UserPointer<const void>(buffer),
501 bytes_to_write, nullptr, 549 bytes_to_write,
550 nullptr,
502 MOJO_WRITE_MESSAGE_FLAG_NONE)); 551 MOJO_WRITE_MESSAGE_FLAG_NONE));
503 *bytes_written_ += bytes_to_write; 552 *bytes_written_ += bytes_to_write;
504 } 553 }
505 554
506 // Write one last "quit" message. 555 // Write one last "quit" message.
507 EXPECT_EQ(MOJO_RESULT_OK, write_dispatcher_->WriteMessage( 556 EXPECT_EQ(MOJO_RESULT_OK,
508 UserPointer<const void>("quit"), 4, nullptr, 557 write_dispatcher_->WriteMessage(UserPointer<const void>("quit"),
509 MOJO_WRITE_MESSAGE_FLAG_NONE)); 558 4,
559 nullptr,
560 MOJO_WRITE_MESSAGE_FLAG_NONE));
510 } 561 }
511 562
512 const scoped_refptr<Dispatcher> write_dispatcher_; 563 const scoped_refptr<Dispatcher> write_dispatcher_;
513 size_t* const messages_written_; 564 size_t* const messages_written_;
514 size_t* const bytes_written_; 565 size_t* const bytes_written_;
515 566
516 DISALLOW_COPY_AND_ASSIGN(WriterThread); 567 DISALLOW_COPY_AND_ASSIGN(WriterThread);
517 }; 568 };
518 569
519 class ReaderThread : public base::SimpleThread { 570 class ReaderThread : public base::SimpleThread {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 EXPECT_EQ(MOJO_RESULT_OK, w.Wait(MOJO_DEADLINE_INDEFINITE, nullptr)); 605 EXPECT_EQ(MOJO_RESULT_OK, w.Wait(MOJO_DEADLINE_INDEFINITE, nullptr));
555 read_dispatcher_->RemoveWaiter(&w, &hss); 606 read_dispatcher_->RemoveWaiter(&w, &hss);
556 } 607 }
557 // We may not actually be readable, since we're racing with other threads. 608 // We may not actually be readable, since we're racing with other threads.
558 EXPECT_TRUE((hss.satisfiable_signals & MOJO_HANDLE_SIGNAL_READABLE)); 609 EXPECT_TRUE((hss.satisfiable_signals & MOJO_HANDLE_SIGNAL_READABLE));
559 610
560 // Now, try to do the read. 611 // Now, try to do the read.
561 // Clear the buffer so that we can check the result. 612 // Clear the buffer so that we can check the result.
562 memset(buffer, 0, sizeof(buffer)); 613 memset(buffer, 0, sizeof(buffer));
563 uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer)); 614 uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer));
564 result = read_dispatcher_->ReadMessage( 615 result = read_dispatcher_->ReadMessage(UserPointer<void>(buffer),
565 UserPointer<void>(buffer), MakeUserPointer(&buffer_size), 0, nullptr, 616 MakeUserPointer(&buffer_size),
566 MOJO_READ_MESSAGE_FLAG_NONE); 617 0,
618 nullptr,
619 MOJO_READ_MESSAGE_FLAG_NONE);
567 EXPECT_TRUE(result == MOJO_RESULT_OK || result == MOJO_RESULT_SHOULD_WAIT) 620 EXPECT_TRUE(result == MOJO_RESULT_OK || result == MOJO_RESULT_SHOULD_WAIT)
568 << "result: " << result; 621 << "result: " << result;
569 // We're racing with others to read, so maybe we failed. 622 // We're racing with others to read, so maybe we failed.
570 if (result == MOJO_RESULT_SHOULD_WAIT) 623 if (result == MOJO_RESULT_SHOULD_WAIT)
571 continue; // In which case, try again. 624 continue; // In which case, try again.
572 // Check for quit. 625 // Check for quit.
573 if (buffer_size == 4 && memcmp("quit", buffer, 4) == 0) 626 if (buffer_size == 4 && memcmp("quit", buffer, 4) == 0)
574 return; 627 return;
575 EXPECT_GE(buffer_size, 1u); 628 EXPECT_GE(buffer_size, 1u);
576 EXPECT_LE(buffer_size, kMaxMessageSize); 629 EXPECT_LE(buffer_size, kMaxMessageSize);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 EXPECT_EQ(total_messages_written, total_messages_read); 720 EXPECT_EQ(total_messages_written, total_messages_read);
668 EXPECT_EQ(total_bytes_written, total_bytes_read); 721 EXPECT_EQ(total_bytes_written, total_bytes_read);
669 722
670 EXPECT_EQ(MOJO_RESULT_OK, d_write->Close()); 723 EXPECT_EQ(MOJO_RESULT_OK, d_write->Close());
671 EXPECT_EQ(MOJO_RESULT_OK, d_read->Close()); 724 EXPECT_EQ(MOJO_RESULT_OK, d_read->Close());
672 } 725 }
673 726
674 } // namespace 727 } // namespace
675 } // namespace system 728 } // namespace system
676 } // namespace mojo 729 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/message_pipe_dispatcher.cc ('k') | mojo/edk/system/message_pipe_perftest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698