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

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

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