OLD | NEW |
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/system/simple_dispatcher.h" | 10 #include "mojo/system/simple_dispatcher.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 namespace mojo { | 24 namespace mojo { |
25 namespace system { | 25 namespace system { |
26 namespace { | 26 namespace { |
27 | 27 |
28 class MockSimpleDispatcher : public SimpleDispatcher { | 28 class MockSimpleDispatcher : public SimpleDispatcher { |
29 public: | 29 public: |
30 MockSimpleDispatcher() | 30 MockSimpleDispatcher() |
31 : state_(MOJO_WAIT_FLAG_NONE, | 31 : state_(MOJO_WAIT_FLAG_NONE, |
32 MOJO_WAIT_FLAG_READABLE | MOJO_WAIT_FLAG_WRITABLE) {} | 32 MOJO_WAIT_FLAG_READABLE | MOJO_WAIT_FLAG_WRITABLE) {} |
33 | 33 |
34 void SetSatisfiedFlags(MojoWaitFlags new_satisfied_flags) { | 34 void SetSatisfiedSignals(MojoHandleSignals new_satisfied_signals) { |
35 base::AutoLock locker(lock()); | 35 base::AutoLock locker(lock()); |
36 | 36 |
37 // Any new flags that are set should be satisfiable. | 37 // Any new signals that are set should be satisfiable. |
38 CHECK_EQ(new_satisfied_flags & ~state_.satisfied_flags, | 38 CHECK_EQ(new_satisfied_signals & ~state_.satisfied_signals, |
39 new_satisfied_flags & ~state_.satisfied_flags & | 39 new_satisfied_signals & ~state_.satisfied_signals & |
40 state_.satisfiable_flags); | 40 state_.satisfiable_signals); |
41 | 41 |
42 if (new_satisfied_flags == state_.satisfied_flags) | 42 if (new_satisfied_signals == state_.satisfied_signals) |
43 return; | 43 return; |
44 | 44 |
45 state_.satisfied_flags = new_satisfied_flags; | 45 state_.satisfied_signals = new_satisfied_signals; |
46 WaitFlagsStateChangedNoLock(); | 46 WaitFlagsStateChangedNoLock(); |
47 } | 47 } |
48 | 48 |
49 void SetSatisfiableFlags(MojoWaitFlags new_satisfiable_flags) { | 49 void SetSatisfiableSignals(MojoHandleSignals new_satisfiable_signals) { |
50 base::AutoLock locker(lock()); | 50 base::AutoLock locker(lock()); |
51 | 51 |
52 // Satisfied implies satisfiable. | 52 // Satisfied implies satisfiable. |
53 CHECK_EQ(new_satisfiable_flags & state_.satisfied_flags, | 53 CHECK_EQ(new_satisfiable_signals & state_.satisfied_signals, |
54 state_.satisfied_flags); | 54 state_.satisfied_signals); |
55 | 55 |
56 if (new_satisfiable_flags == state_.satisfiable_flags) | 56 if (new_satisfiable_signals == state_.satisfiable_signals) |
57 return; | 57 return; |
58 | 58 |
59 state_.satisfiable_flags = new_satisfiable_flags; | 59 state_.satisfiable_signals = new_satisfiable_signals; |
60 WaitFlagsStateChangedNoLock(); | 60 WaitFlagsStateChangedNoLock(); |
61 } | 61 } |
62 | 62 |
63 virtual Type GetType() const OVERRIDE { | 63 virtual Type GetType() const OVERRIDE { |
64 return kTypeUnknown; | 64 return kTypeUnknown; |
65 } | 65 } |
66 | 66 |
67 private: | 67 private: |
68 friend class base::RefCountedThreadSafe<MockSimpleDispatcher>; | 68 friend class base::RefCountedThreadSafe<MockSimpleDispatcher>; |
69 virtual ~MockSimpleDispatcher() {} | 69 virtual ~MockSimpleDispatcher() {} |
(...skipping 19 matching lines...) Expand all Loading... |
89 | 89 |
90 TEST(SimpleDispatcherTest, Basic) { | 90 TEST(SimpleDispatcherTest, Basic) { |
91 test::Stopwatch stopwatch; | 91 test::Stopwatch stopwatch; |
92 | 92 |
93 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher()); | 93 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher()); |
94 Waiter w; | 94 Waiter w; |
95 uint32_t context = 0; | 95 uint32_t context = 0; |
96 | 96 |
97 // Try adding a readable waiter when already readable. | 97 // Try adding a readable waiter when already readable. |
98 w.Init(); | 98 w.Init(); |
99 d->SetSatisfiedFlags(MOJO_WAIT_FLAG_READABLE); | 99 d->SetSatisfiedSignals(MOJO_WAIT_FLAG_READABLE); |
100 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, | 100 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, |
101 d->AddWaiter(&w, MOJO_WAIT_FLAG_READABLE, 0)); | 101 d->AddWaiter(&w, MOJO_WAIT_FLAG_READABLE, 0)); |
102 // Shouldn't need to remove the waiter (it was not added). | 102 // Shouldn't need to remove the waiter (it was not added). |
103 | 103 |
104 // Wait (forever) for writable when already writable. | 104 // Wait (forever) for writable when already writable. |
105 w.Init(); | 105 w.Init(); |
106 d->SetSatisfiedFlags(MOJO_WAIT_FLAG_READABLE); | 106 d->SetSatisfiedSignals(MOJO_WAIT_FLAG_READABLE); |
107 EXPECT_EQ(MOJO_RESULT_OK, d->AddWaiter(&w, MOJO_WAIT_FLAG_WRITABLE, 1)); | 107 EXPECT_EQ(MOJO_RESULT_OK, d->AddWaiter(&w, MOJO_WAIT_FLAG_WRITABLE, 1)); |
108 d->SetSatisfiedFlags(MOJO_WAIT_FLAG_WRITABLE); | 108 d->SetSatisfiedSignals(MOJO_WAIT_FLAG_WRITABLE); |
109 stopwatch.Start(); | 109 stopwatch.Start(); |
110 EXPECT_EQ(MOJO_RESULT_OK, w.Wait(MOJO_DEADLINE_INDEFINITE, &context)); | 110 EXPECT_EQ(MOJO_RESULT_OK, w.Wait(MOJO_DEADLINE_INDEFINITE, &context)); |
111 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); | 111 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); |
112 EXPECT_EQ(1u, context); | 112 EXPECT_EQ(1u, context); |
113 d->RemoveWaiter(&w); | 113 d->RemoveWaiter(&w); |
114 | 114 |
115 // Wait for zero time for writable when already writable. | 115 // Wait for zero time for writable when already writable. |
116 w.Init(); | 116 w.Init(); |
117 d->SetSatisfiedFlags(MOJO_WAIT_FLAG_READABLE); | 117 d->SetSatisfiedSignals(MOJO_WAIT_FLAG_READABLE); |
118 EXPECT_EQ(MOJO_RESULT_OK, d->AddWaiter(&w, MOJO_WAIT_FLAG_WRITABLE, 2)); | 118 EXPECT_EQ(MOJO_RESULT_OK, d->AddWaiter(&w, MOJO_WAIT_FLAG_WRITABLE, 2)); |
119 d->SetSatisfiedFlags(MOJO_WAIT_FLAG_WRITABLE); | 119 d->SetSatisfiedSignals(MOJO_WAIT_FLAG_WRITABLE); |
120 stopwatch.Start(); | 120 stopwatch.Start(); |
121 EXPECT_EQ(MOJO_RESULT_OK, w.Wait(0, &context)); | 121 EXPECT_EQ(MOJO_RESULT_OK, w.Wait(0, &context)); |
122 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); | 122 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); |
123 EXPECT_EQ(2u, context); | 123 EXPECT_EQ(2u, context); |
124 d->RemoveWaiter(&w); | 124 d->RemoveWaiter(&w); |
125 | 125 |
126 // Wait for non-zero, finite time for writable when already writable. | 126 // Wait for non-zero, finite time for writable when already writable. |
127 w.Init(); | 127 w.Init(); |
128 d->SetSatisfiedFlags(MOJO_WAIT_FLAG_READABLE); | 128 d->SetSatisfiedSignals(MOJO_WAIT_FLAG_READABLE); |
129 EXPECT_EQ(MOJO_RESULT_OK, d->AddWaiter(&w, MOJO_WAIT_FLAG_WRITABLE, 3)); | 129 EXPECT_EQ(MOJO_RESULT_OK, d->AddWaiter(&w, MOJO_WAIT_FLAG_WRITABLE, 3)); |
130 d->SetSatisfiedFlags(MOJO_WAIT_FLAG_WRITABLE); | 130 d->SetSatisfiedSignals(MOJO_WAIT_FLAG_WRITABLE); |
131 stopwatch.Start(); | 131 stopwatch.Start(); |
132 EXPECT_EQ(MOJO_RESULT_OK, | 132 EXPECT_EQ(MOJO_RESULT_OK, |
133 w.Wait(2 * test::EpsilonTimeout().InMicroseconds(), &context)); | 133 w.Wait(2 * test::EpsilonTimeout().InMicroseconds(), &context)); |
134 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); | 134 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); |
135 EXPECT_EQ(3u, context); | 135 EXPECT_EQ(3u, context); |
136 d->RemoveWaiter(&w); | 136 d->RemoveWaiter(&w); |
137 | 137 |
138 // Wait for zero time for writable when not writable (will time out). | 138 // Wait for zero time for writable when not writable (will time out). |
139 w.Init(); | 139 w.Init(); |
140 d->SetSatisfiedFlags(MOJO_WAIT_FLAG_READABLE); | 140 d->SetSatisfiedSignals(MOJO_WAIT_FLAG_READABLE); |
141 EXPECT_EQ(MOJO_RESULT_OK, d->AddWaiter(&w, MOJO_WAIT_FLAG_WRITABLE, 4)); | 141 EXPECT_EQ(MOJO_RESULT_OK, d->AddWaiter(&w, MOJO_WAIT_FLAG_WRITABLE, 4)); |
142 stopwatch.Start(); | 142 stopwatch.Start(); |
143 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, w.Wait(0, NULL)); | 143 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, w.Wait(0, NULL)); |
144 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); | 144 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); |
145 d->RemoveWaiter(&w); | 145 d->RemoveWaiter(&w); |
146 | 146 |
147 // Wait for non-zero, finite time for writable when not writable (will time | 147 // Wait for non-zero, finite time for writable when not writable (will time |
148 // out). | 148 // out). |
149 w.Init(); | 149 w.Init(); |
150 d->SetSatisfiedFlags(MOJO_WAIT_FLAG_READABLE); | 150 d->SetSatisfiedSignals(MOJO_WAIT_FLAG_READABLE); |
151 EXPECT_EQ(MOJO_RESULT_OK, d->AddWaiter(&w, MOJO_WAIT_FLAG_WRITABLE, 5)); | 151 EXPECT_EQ(MOJO_RESULT_OK, d->AddWaiter(&w, MOJO_WAIT_FLAG_WRITABLE, 5)); |
152 stopwatch.Start(); | 152 stopwatch.Start(); |
153 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, | 153 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, |
154 w.Wait(2 * test::EpsilonTimeout().InMicroseconds(), NULL)); | 154 w.Wait(2 * test::EpsilonTimeout().InMicroseconds(), NULL)); |
155 base::TimeDelta elapsed = stopwatch.Elapsed(); | 155 base::TimeDelta elapsed = stopwatch.Elapsed(); |
156 EXPECT_GT(elapsed, (2-1) * test::EpsilonTimeout()); | 156 EXPECT_GT(elapsed, (2-1) * test::EpsilonTimeout()); |
157 EXPECT_LT(elapsed, (2+1) * test::EpsilonTimeout()); | 157 EXPECT_LT(elapsed, (2+1) * test::EpsilonTimeout()); |
158 d->RemoveWaiter(&w); | 158 d->RemoveWaiter(&w); |
159 | 159 |
160 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); | 160 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); |
161 } | 161 } |
162 | 162 |
163 TEST(SimpleDispatcherTest, BasicUnsatisfiable) { | 163 TEST(SimpleDispatcherTest, BasicUnsatisfiable) { |
164 test::Stopwatch stopwatch; | 164 test::Stopwatch stopwatch; |
165 | 165 |
166 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher()); | 166 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher()); |
167 Waiter w; | 167 Waiter w; |
168 uint32_t context = 0; | 168 uint32_t context = 0; |
169 | 169 |
170 // Try adding a writable waiter when it can never be writable. | 170 // Try adding a writable waiter when it can never be writable. |
171 w.Init(); | 171 w.Init(); |
172 d->SetSatisfiableFlags(MOJO_WAIT_FLAG_READABLE); | 172 d->SetSatisfiableSignals(MOJO_WAIT_FLAG_READABLE); |
173 d->SetSatisfiedFlags(0); | 173 d->SetSatisfiedSignals(0); |
174 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, | 174 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, |
175 d->AddWaiter(&w, MOJO_WAIT_FLAG_WRITABLE, 1)); | 175 d->AddWaiter(&w, MOJO_WAIT_FLAG_WRITABLE, 1)); |
176 // Shouldn't need to remove the waiter (it was not added). | 176 // Shouldn't need to remove the waiter (it was not added). |
177 | 177 |
178 // Wait (forever) for writable and then it becomes never writable. | 178 // Wait (forever) for writable and then it becomes never writable. |
179 w.Init(); | 179 w.Init(); |
180 d->SetSatisfiableFlags(MOJO_WAIT_FLAG_READABLE | MOJO_WAIT_FLAG_WRITABLE); | 180 d->SetSatisfiableSignals(MOJO_WAIT_FLAG_READABLE | MOJO_WAIT_FLAG_WRITABLE); |
181 EXPECT_EQ(MOJO_RESULT_OK, d->AddWaiter(&w, MOJO_WAIT_FLAG_WRITABLE, 2)); | 181 EXPECT_EQ(MOJO_RESULT_OK, d->AddWaiter(&w, MOJO_WAIT_FLAG_WRITABLE, 2)); |
182 d->SetSatisfiableFlags(MOJO_WAIT_FLAG_READABLE); | 182 d->SetSatisfiableSignals(MOJO_WAIT_FLAG_READABLE); |
183 stopwatch.Start(); | 183 stopwatch.Start(); |
184 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, | 184 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, |
185 w.Wait(MOJO_DEADLINE_INDEFINITE, &context)); | 185 w.Wait(MOJO_DEADLINE_INDEFINITE, &context)); |
186 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); | 186 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); |
187 EXPECT_EQ(2u, context); | 187 EXPECT_EQ(2u, context); |
188 d->RemoveWaiter(&w); | 188 d->RemoveWaiter(&w); |
189 | 189 |
190 // Wait for zero time for writable and then it becomes never writable. | 190 // Wait for zero time for writable and then it becomes never writable. |
191 w.Init(); | 191 w.Init(); |
192 d->SetSatisfiableFlags(MOJO_WAIT_FLAG_READABLE | MOJO_WAIT_FLAG_WRITABLE); | 192 d->SetSatisfiableSignals(MOJO_WAIT_FLAG_READABLE | MOJO_WAIT_FLAG_WRITABLE); |
193 EXPECT_EQ(MOJO_RESULT_OK, d->AddWaiter(&w, MOJO_WAIT_FLAG_WRITABLE, 3)); | 193 EXPECT_EQ(MOJO_RESULT_OK, d->AddWaiter(&w, MOJO_WAIT_FLAG_WRITABLE, 3)); |
194 d->SetSatisfiableFlags(MOJO_WAIT_FLAG_READABLE); | 194 d->SetSatisfiableSignals(MOJO_WAIT_FLAG_READABLE); |
195 stopwatch.Start(); | 195 stopwatch.Start(); |
196 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, w.Wait(0, &context)); | 196 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, w.Wait(0, &context)); |
197 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); | 197 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); |
198 EXPECT_EQ(3u, context); | 198 EXPECT_EQ(3u, context); |
199 d->RemoveWaiter(&w); | 199 d->RemoveWaiter(&w); |
200 | 200 |
201 // Wait for non-zero, finite time for writable and then it becomes never | 201 // Wait for non-zero, finite time for writable and then it becomes never |
202 // writable. | 202 // writable. |
203 w.Init(); | 203 w.Init(); |
204 d->SetSatisfiableFlags(MOJO_WAIT_FLAG_READABLE | MOJO_WAIT_FLAG_WRITABLE); | 204 d->SetSatisfiableSignals(MOJO_WAIT_FLAG_READABLE | MOJO_WAIT_FLAG_WRITABLE); |
205 EXPECT_EQ(MOJO_RESULT_OK, d->AddWaiter(&w, MOJO_WAIT_FLAG_WRITABLE, 4)); | 205 EXPECT_EQ(MOJO_RESULT_OK, d->AddWaiter(&w, MOJO_WAIT_FLAG_WRITABLE, 4)); |
206 d->SetSatisfiableFlags(MOJO_WAIT_FLAG_READABLE); | 206 d->SetSatisfiableSignals(MOJO_WAIT_FLAG_READABLE); |
207 stopwatch.Start(); | 207 stopwatch.Start(); |
208 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, | 208 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, |
209 w.Wait(2 * test::EpsilonTimeout().InMicroseconds(), &context)); | 209 w.Wait(2 * test::EpsilonTimeout().InMicroseconds(), &context)); |
210 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); | 210 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); |
211 EXPECT_EQ(4u, context); | 211 EXPECT_EQ(4u, context); |
212 d->RemoveWaiter(&w); | 212 d->RemoveWaiter(&w); |
213 | 213 |
214 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); | 214 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); |
215 } | 215 } |
216 | 216 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 TEST(SimpleDispatcherTest, BasicThreaded) { | 268 TEST(SimpleDispatcherTest, BasicThreaded) { |
269 test::Stopwatch stopwatch; | 269 test::Stopwatch stopwatch; |
270 bool did_wait; | 270 bool did_wait; |
271 MojoResult result; | 271 MojoResult result; |
272 uint32_t context; | 272 uint32_t context; |
273 | 273 |
274 // Wait for readable (already readable). | 274 // Wait for readable (already readable). |
275 { | 275 { |
276 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher()); | 276 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher()); |
277 { | 277 { |
278 d->SetSatisfiedFlags(MOJO_WAIT_FLAG_READABLE); | 278 d->SetSatisfiedSignals(MOJO_WAIT_FLAG_READABLE); |
279 test::WaiterThread thread(d, | 279 test::WaiterThread thread(d, |
280 MOJO_WAIT_FLAG_READABLE, | 280 MOJO_WAIT_FLAG_READABLE, |
281 MOJO_DEADLINE_INDEFINITE, | 281 MOJO_DEADLINE_INDEFINITE, |
282 1, | 282 1, |
283 &did_wait, &result, &context); | 283 &did_wait, &result, &context); |
284 stopwatch.Start(); | 284 stopwatch.Start(); |
285 thread.Start(); | 285 thread.Start(); |
286 } // Joins the thread. | 286 } // Joins the thread. |
287 // If we closed earlier, then probably we'd get a |MOJO_RESULT_CANCELLED|. | 287 // If we closed earlier, then probably we'd get a |MOJO_RESULT_CANCELLED|. |
288 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); | 288 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); |
289 } | 289 } |
290 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); | 290 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); |
291 EXPECT_FALSE(did_wait); | 291 EXPECT_FALSE(did_wait); |
292 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, result); | 292 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, result); |
293 | 293 |
294 // Wait for readable and becomes readable after some time. | 294 // Wait for readable and becomes readable after some time. |
295 { | 295 { |
296 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher()); | 296 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher()); |
297 test::WaiterThread thread(d, | 297 test::WaiterThread thread(d, |
298 MOJO_WAIT_FLAG_READABLE, | 298 MOJO_WAIT_FLAG_READABLE, |
299 MOJO_DEADLINE_INDEFINITE, | 299 MOJO_DEADLINE_INDEFINITE, |
300 2, | 300 2, |
301 &did_wait, &result, &context); | 301 &did_wait, &result, &context); |
302 stopwatch.Start(); | 302 stopwatch.Start(); |
303 thread.Start(); | 303 thread.Start(); |
304 base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); | 304 base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); |
305 d->SetSatisfiedFlags(MOJO_WAIT_FLAG_READABLE); | 305 d->SetSatisfiedSignals(MOJO_WAIT_FLAG_READABLE); |
306 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); | 306 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); |
307 } // Joins the thread. | 307 } // Joins the thread. |
308 base::TimeDelta elapsed = stopwatch.Elapsed(); | 308 base::TimeDelta elapsed = stopwatch.Elapsed(); |
309 EXPECT_GT(elapsed, (2-1) * test::EpsilonTimeout()); | 309 EXPECT_GT(elapsed, (2-1) * test::EpsilonTimeout()); |
310 EXPECT_LT(elapsed, (2+1) * test::EpsilonTimeout()); | 310 EXPECT_LT(elapsed, (2+1) * test::EpsilonTimeout()); |
311 EXPECT_TRUE(did_wait); | 311 EXPECT_TRUE(did_wait); |
312 EXPECT_EQ(MOJO_RESULT_OK, result); | 312 EXPECT_EQ(MOJO_RESULT_OK, result); |
313 EXPECT_EQ(2u, context); | 313 EXPECT_EQ(2u, context); |
314 | 314 |
315 // Wait for readable and becomes never-readable after some time. | 315 // Wait for readable and becomes never-readable after some time. |
316 { | 316 { |
317 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher()); | 317 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher()); |
318 test::WaiterThread thread(d, | 318 test::WaiterThread thread(d, |
319 MOJO_WAIT_FLAG_READABLE, | 319 MOJO_WAIT_FLAG_READABLE, |
320 MOJO_DEADLINE_INDEFINITE, | 320 MOJO_DEADLINE_INDEFINITE, |
321 3, | 321 3, |
322 &did_wait, &result, &context); | 322 &did_wait, &result, &context); |
323 stopwatch.Start(); | 323 stopwatch.Start(); |
324 thread.Start(); | 324 thread.Start(); |
325 base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); | 325 base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); |
326 d->SetSatisfiableFlags(MOJO_WAIT_FLAG_NONE); | 326 d->SetSatisfiableSignals(MOJO_WAIT_FLAG_NONE); |
327 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); | 327 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); |
328 } // Joins the thread. | 328 } // Joins the thread. |
329 elapsed = stopwatch.Elapsed(); | 329 elapsed = stopwatch.Elapsed(); |
330 EXPECT_GT(elapsed, (2-1) * test::EpsilonTimeout()); | 330 EXPECT_GT(elapsed, (2-1) * test::EpsilonTimeout()); |
331 EXPECT_LT(elapsed, (2+1) * test::EpsilonTimeout()); | 331 EXPECT_LT(elapsed, (2+1) * test::EpsilonTimeout()); |
332 EXPECT_TRUE(did_wait); | 332 EXPECT_TRUE(did_wait); |
333 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result); | 333 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result); |
334 EXPECT_EQ(3u, context); | 334 EXPECT_EQ(3u, context); |
335 | 335 |
336 // Wait for readable and dispatcher gets closed. | 336 // Wait for readable and dispatcher gets closed. |
(...skipping 22 matching lines...) Expand all Loading... |
359 { | 359 { |
360 test::WaiterThread thread(d, | 360 test::WaiterThread thread(d, |
361 MOJO_WAIT_FLAG_READABLE, | 361 MOJO_WAIT_FLAG_READABLE, |
362 2 * test::EpsilonTimeout().InMicroseconds(), | 362 2 * test::EpsilonTimeout().InMicroseconds(), |
363 5, | 363 5, |
364 &did_wait, &result, &context); | 364 &did_wait, &result, &context); |
365 stopwatch.Start(); | 365 stopwatch.Start(); |
366 thread.Start(); | 366 thread.Start(); |
367 base::PlatformThread::Sleep(1 * test::EpsilonTimeout()); | 367 base::PlatformThread::Sleep(1 * test::EpsilonTimeout()); |
368 // Not what we're waiting for. | 368 // Not what we're waiting for. |
369 d->SetSatisfiedFlags(MOJO_WAIT_FLAG_WRITABLE); | 369 d->SetSatisfiedSignals(MOJO_WAIT_FLAG_WRITABLE); |
370 } // Joins the thread (after its wait times out). | 370 } // Joins the thread (after its wait times out). |
371 // If we closed earlier, then probably we'd get a |MOJO_RESULT_CANCELLED|. | 371 // If we closed earlier, then probably we'd get a |MOJO_RESULT_CANCELLED|. |
372 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); | 372 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); |
373 } | 373 } |
374 elapsed = stopwatch.Elapsed(); | 374 elapsed = stopwatch.Elapsed(); |
375 EXPECT_GT(elapsed, (2-1) * test::EpsilonTimeout()); | 375 EXPECT_GT(elapsed, (2-1) * test::EpsilonTimeout()); |
376 EXPECT_LT(elapsed, (2+1) * test::EpsilonTimeout()); | 376 EXPECT_LT(elapsed, (2+1) * test::EpsilonTimeout()); |
377 EXPECT_TRUE(did_wait); | 377 EXPECT_TRUE(did_wait); |
378 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, result); | 378 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, result); |
379 } | 379 } |
(...skipping 13 matching lines...) Expand all Loading... |
393 threads.push_back(new test::WaiterThread(d, | 393 threads.push_back(new test::WaiterThread(d, |
394 MOJO_WAIT_FLAG_READABLE, | 394 MOJO_WAIT_FLAG_READABLE, |
395 MOJO_DEADLINE_INDEFINITE, | 395 MOJO_DEADLINE_INDEFINITE, |
396 i, | 396 i, |
397 &did_wait[i], | 397 &did_wait[i], |
398 &result[i], | 398 &result[i], |
399 &context[i])); | 399 &context[i])); |
400 threads.back()->Start(); | 400 threads.back()->Start(); |
401 } | 401 } |
402 base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); | 402 base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); |
403 d->SetSatisfiedFlags(MOJO_WAIT_FLAG_READABLE); | 403 d->SetSatisfiedSignals(MOJO_WAIT_FLAG_READABLE); |
404 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); | 404 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); |
405 } // Joins the threads. | 405 } // Joins the threads. |
406 for (uint32_t i = 0; i < kNumWaiters; i++) { | 406 for (uint32_t i = 0; i < kNumWaiters; i++) { |
407 EXPECT_TRUE(did_wait[i]); | 407 EXPECT_TRUE(did_wait[i]); |
408 EXPECT_EQ(MOJO_RESULT_OK, result[i]); | 408 EXPECT_EQ(MOJO_RESULT_OK, result[i]); |
409 EXPECT_EQ(i, context[i]); | 409 EXPECT_EQ(i, context[i]); |
410 } | 410 } |
411 | 411 |
412 // Some wait for readable, some for writable, and becomes readable after some | 412 // Some wait for readable, some for writable, and becomes readable after some |
413 // time. | 413 // time. |
(...skipping 14 matching lines...) Expand all Loading... |
428 threads.push_back(new test::WaiterThread(d, | 428 threads.push_back(new test::WaiterThread(d, |
429 MOJO_WAIT_FLAG_WRITABLE, | 429 MOJO_WAIT_FLAG_WRITABLE, |
430 MOJO_DEADLINE_INDEFINITE, | 430 MOJO_DEADLINE_INDEFINITE, |
431 i, | 431 i, |
432 &did_wait[i], | 432 &did_wait[i], |
433 &result[i], | 433 &result[i], |
434 &context[i])); | 434 &context[i])); |
435 threads.back()->Start(); | 435 threads.back()->Start(); |
436 } | 436 } |
437 base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); | 437 base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); |
438 d->SetSatisfiedFlags(MOJO_WAIT_FLAG_READABLE); | 438 d->SetSatisfiedSignals(MOJO_WAIT_FLAG_READABLE); |
439 // This will wake up the ones waiting to write. | 439 // This will wake up the ones waiting to write. |
440 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); | 440 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); |
441 } // Joins the threads. | 441 } // Joins the threads. |
442 for (uint32_t i = 0; i < kNumWaiters / 2; i++) { | 442 for (uint32_t i = 0; i < kNumWaiters / 2; i++) { |
443 EXPECT_TRUE(did_wait[i]); | 443 EXPECT_TRUE(did_wait[i]); |
444 EXPECT_EQ(MOJO_RESULT_OK, result[i]); | 444 EXPECT_EQ(MOJO_RESULT_OK, result[i]); |
445 EXPECT_EQ(i, context[i]); | 445 EXPECT_EQ(i, context[i]); |
446 } | 446 } |
447 for (uint32_t i = kNumWaiters / 2; i < kNumWaiters; i++) { | 447 for (uint32_t i = kNumWaiters / 2; i < kNumWaiters; i++) { |
448 EXPECT_TRUE(did_wait[i]); | 448 EXPECT_TRUE(did_wait[i]); |
(...skipping 20 matching lines...) Expand all Loading... |
469 threads.push_back(new test::WaiterThread(d, | 469 threads.push_back(new test::WaiterThread(d, |
470 MOJO_WAIT_FLAG_WRITABLE, | 470 MOJO_WAIT_FLAG_WRITABLE, |
471 MOJO_DEADLINE_INDEFINITE, | 471 MOJO_DEADLINE_INDEFINITE, |
472 i, | 472 i, |
473 &did_wait[i], | 473 &did_wait[i], |
474 &result[i], | 474 &result[i], |
475 &context[i])); | 475 &context[i])); |
476 threads.back()->Start(); | 476 threads.back()->Start(); |
477 } | 477 } |
478 base::PlatformThread::Sleep(1 * test::EpsilonTimeout()); | 478 base::PlatformThread::Sleep(1 * test::EpsilonTimeout()); |
479 d->SetSatisfiableFlags(MOJO_WAIT_FLAG_READABLE); | 479 d->SetSatisfiableSignals(MOJO_WAIT_FLAG_READABLE); |
480 base::PlatformThread::Sleep(1 * test::EpsilonTimeout()); | 480 base::PlatformThread::Sleep(1 * test::EpsilonTimeout()); |
481 d->SetSatisfiedFlags(MOJO_WAIT_FLAG_READABLE); | 481 d->SetSatisfiedSignals(MOJO_WAIT_FLAG_READABLE); |
482 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); | 482 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); |
483 } // Joins the threads. | 483 } // Joins the threads. |
484 for (uint32_t i = 0; i < kNumWaiters / 2; i++) { | 484 for (uint32_t i = 0; i < kNumWaiters / 2; i++) { |
485 EXPECT_TRUE(did_wait[i]); | 485 EXPECT_TRUE(did_wait[i]); |
486 EXPECT_EQ(MOJO_RESULT_OK, result[i]); | 486 EXPECT_EQ(MOJO_RESULT_OK, result[i]); |
487 EXPECT_EQ(i, context[i]); | 487 EXPECT_EQ(i, context[i]); |
488 } | 488 } |
489 for (uint32_t i = kNumWaiters / 2; i < kNumWaiters; i++) { | 489 for (uint32_t i = kNumWaiters / 2; i < kNumWaiters; i++) { |
490 EXPECT_TRUE(did_wait[i]); | 490 EXPECT_TRUE(did_wait[i]); |
491 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result[i]); | 491 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result[i]); |
(...skipping 17 matching lines...) Expand all Loading... |
509 for (uint32_t i = kNumWaiters / 2; i < kNumWaiters; i++) { | 509 for (uint32_t i = kNumWaiters / 2; i < kNumWaiters; i++) { |
510 threads.push_back( | 510 threads.push_back( |
511 new test::WaiterThread(d, | 511 new test::WaiterThread(d, |
512 MOJO_WAIT_FLAG_WRITABLE, | 512 MOJO_WAIT_FLAG_WRITABLE, |
513 1 * test::EpsilonTimeout().InMicroseconds(), | 513 1 * test::EpsilonTimeout().InMicroseconds(), |
514 i, | 514 i, |
515 &did_wait[i], &result[i], &context[i])); | 515 &did_wait[i], &result[i], &context[i])); |
516 threads.back()->Start(); | 516 threads.back()->Start(); |
517 } | 517 } |
518 base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); | 518 base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); |
519 d->SetSatisfiedFlags(MOJO_WAIT_FLAG_READABLE); | 519 d->SetSatisfiedSignals(MOJO_WAIT_FLAG_READABLE); |
520 // All those waiting for writable should have timed out. | 520 // All those waiting for writable should have timed out. |
521 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); | 521 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); |
522 } // Joins the threads. | 522 } // Joins the threads. |
523 for (uint32_t i = 0; i < kNumWaiters / 2; i++) { | 523 for (uint32_t i = 0; i < kNumWaiters / 2; i++) { |
524 EXPECT_TRUE(did_wait[i]); | 524 EXPECT_TRUE(did_wait[i]); |
525 EXPECT_EQ(MOJO_RESULT_OK, result[i]); | 525 EXPECT_EQ(MOJO_RESULT_OK, result[i]); |
526 EXPECT_EQ(i, context[i]); | 526 EXPECT_EQ(i, context[i]); |
527 } | 527 } |
528 for (uint32_t i = kNumWaiters / 2; i < kNumWaiters; i++) { | 528 for (uint32_t i = kNumWaiters / 2; i < kNumWaiters; i++) { |
529 EXPECT_TRUE(did_wait[i]); | 529 EXPECT_TRUE(did_wait[i]); |
530 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, result[i]); | 530 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, result[i]); |
531 } | 531 } |
532 } | 532 } |
533 | 533 |
534 // TODO(vtl): Stress test? | 534 // TODO(vtl): Stress test? |
535 | 535 |
536 } // namespace | 536 } // namespace |
537 } // namespace system | 537 } // namespace system |
538 } // namespace mojo | 538 } // namespace mojo |
OLD | NEW |