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

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

Issue 782693004: Update mojo sdk to rev f6c8ec07c01deebc13178d516225fd12695c3dc2 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: hack mojo_system_impl gypi for android :| Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // 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/simple_dispatcher.h" 10 #include "mojo/edk/system/simple_dispatcher.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher()); 97 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher());
98 Waiter w; 98 Waiter w;
99 uint32_t context = 0; 99 uint32_t context = 0;
100 HandleSignalsState hss; 100 HandleSignalsState hss;
101 101
102 // Try adding a readable waiter when already readable. 102 // Try adding a readable waiter when already readable.
103 w.Init(); 103 w.Init();
104 d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_READABLE); 104 d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_READABLE);
105 hss = HandleSignalsState(); 105 hss = HandleSignalsState();
106 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, 106 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS,
107 d->AddWaiter(&w, MOJO_HANDLE_SIGNAL_READABLE, 0, &hss)); 107 d->AddAwakable(&w, MOJO_HANDLE_SIGNAL_READABLE, 0, &hss));
108 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals); 108 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals);
109 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 109 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
110 hss.satisfiable_signals); 110 hss.satisfiable_signals);
111 // Shouldn't need to remove the waiter (it was not added). 111 // Shouldn't need to remove the waiter (it was not added).
112 112
113 // Wait (forever) for writable when already writable. 113 // Wait (forever) for writable when already writable.
114 w.Init(); 114 w.Init();
115 d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_READABLE); 115 d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_READABLE);
116 ASSERT_EQ(MOJO_RESULT_OK, 116 ASSERT_EQ(MOJO_RESULT_OK,
117 d->AddWaiter(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 1, nullptr)); 117 d->AddAwakable(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 1, nullptr));
118 d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_WRITABLE); 118 d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_WRITABLE);
119 stopwatch.Start(); 119 stopwatch.Start();
120 EXPECT_EQ(MOJO_RESULT_OK, w.Wait(MOJO_DEADLINE_INDEFINITE, &context)); 120 EXPECT_EQ(MOJO_RESULT_OK, w.Wait(MOJO_DEADLINE_INDEFINITE, &context));
121 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); 121 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout());
122 EXPECT_EQ(1u, context); 122 EXPECT_EQ(1u, context);
123 hss = HandleSignalsState(); 123 hss = HandleSignalsState();
124 d->RemoveWaiter(&w, &hss); 124 d->RemoveAwakable(&w, &hss);
125 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals); 125 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals);
126 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 126 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
127 hss.satisfiable_signals); 127 hss.satisfiable_signals);
128 128
129 // Wait for zero time for writable when already writable. 129 // Wait for zero time for writable when already writable.
130 w.Init(); 130 w.Init();
131 d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_READABLE); 131 d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_READABLE);
132 ASSERT_EQ(MOJO_RESULT_OK, 132 ASSERT_EQ(MOJO_RESULT_OK,
133 d->AddWaiter(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 2, nullptr)); 133 d->AddAwakable(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 2, nullptr));
134 d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_WRITABLE); 134 d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_WRITABLE);
135 stopwatch.Start(); 135 stopwatch.Start();
136 EXPECT_EQ(MOJO_RESULT_OK, w.Wait(0, &context)); 136 EXPECT_EQ(MOJO_RESULT_OK, w.Wait(0, &context));
137 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); 137 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout());
138 EXPECT_EQ(2u, context); 138 EXPECT_EQ(2u, context);
139 hss = HandleSignalsState(); 139 hss = HandleSignalsState();
140 d->RemoveWaiter(&w, &hss); 140 d->RemoveAwakable(&w, &hss);
141 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals); 141 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals);
142 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 142 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
143 hss.satisfiable_signals); 143 hss.satisfiable_signals);
144 144
145 // Wait for non-zero, finite time for writable when already writable. 145 // Wait for non-zero, finite time for writable when already writable.
146 w.Init(); 146 w.Init();
147 d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_READABLE); 147 d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_READABLE);
148 ASSERT_EQ(MOJO_RESULT_OK, 148 ASSERT_EQ(MOJO_RESULT_OK,
149 d->AddWaiter(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 3, nullptr)); 149 d->AddAwakable(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 3, nullptr));
150 d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_WRITABLE); 150 d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_WRITABLE);
151 stopwatch.Start(); 151 stopwatch.Start();
152 EXPECT_EQ(MOJO_RESULT_OK, 152 EXPECT_EQ(MOJO_RESULT_OK,
153 w.Wait(2 * test::EpsilonTimeout().InMicroseconds(), &context)); 153 w.Wait(2 * test::EpsilonTimeout().InMicroseconds(), &context));
154 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); 154 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout());
155 EXPECT_EQ(3u, context); 155 EXPECT_EQ(3u, context);
156 hss = HandleSignalsState(); 156 hss = HandleSignalsState();
157 d->RemoveWaiter(&w, &hss); 157 d->RemoveAwakable(&w, &hss);
158 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals); 158 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals);
159 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 159 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
160 hss.satisfiable_signals); 160 hss.satisfiable_signals);
161 161
162 // Wait for zero time for writable when not writable (will time out). 162 // Wait for zero time for writable when not writable (will time out).
163 w.Init(); 163 w.Init();
164 d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_READABLE); 164 d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_READABLE);
165 ASSERT_EQ(MOJO_RESULT_OK, 165 ASSERT_EQ(MOJO_RESULT_OK,
166 d->AddWaiter(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 4, nullptr)); 166 d->AddAwakable(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 4, nullptr));
167 stopwatch.Start(); 167 stopwatch.Start();
168 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, w.Wait(0, nullptr)); 168 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, w.Wait(0, nullptr));
169 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); 169 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout());
170 hss = HandleSignalsState(); 170 hss = HandleSignalsState();
171 d->RemoveWaiter(&w, &hss); 171 d->RemoveAwakable(&w, &hss);
172 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals); 172 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals);
173 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 173 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
174 hss.satisfiable_signals); 174 hss.satisfiable_signals);
175 175
176 // Wait for non-zero, finite time for writable when not writable (will time 176 // Wait for non-zero, finite time for writable when not writable (will time
177 // out). 177 // out).
178 w.Init(); 178 w.Init();
179 d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_READABLE); 179 d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_READABLE);
180 ASSERT_EQ(MOJO_RESULT_OK, 180 ASSERT_EQ(MOJO_RESULT_OK,
181 d->AddWaiter(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 5, nullptr)); 181 d->AddAwakable(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 5, nullptr));
182 stopwatch.Start(); 182 stopwatch.Start();
183 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, 183 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED,
184 w.Wait(2 * test::EpsilonTimeout().InMicroseconds(), nullptr)); 184 w.Wait(2 * test::EpsilonTimeout().InMicroseconds(), nullptr));
185 base::TimeDelta elapsed = stopwatch.Elapsed(); 185 base::TimeDelta elapsed = stopwatch.Elapsed();
186 EXPECT_GT(elapsed, (2 - 1) * test::EpsilonTimeout()); 186 EXPECT_GT(elapsed, (2 - 1) * test::EpsilonTimeout());
187 EXPECT_LT(elapsed, (2 + 1) * test::EpsilonTimeout()); 187 EXPECT_LT(elapsed, (2 + 1) * test::EpsilonTimeout());
188 hss = HandleSignalsState(); 188 hss = HandleSignalsState();
189 d->RemoveWaiter(&w, &hss); 189 d->RemoveAwakable(&w, &hss);
190 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals); 190 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals);
191 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 191 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
192 hss.satisfiable_signals); 192 hss.satisfiable_signals);
193 193
194 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); 194 EXPECT_EQ(MOJO_RESULT_OK, d->Close());
195 } 195 }
196 196
197 TEST(SimpleDispatcherTest, BasicUnsatisfiable) { 197 TEST(SimpleDispatcherTest, BasicUnsatisfiable) {
198 test::Stopwatch stopwatch; 198 test::Stopwatch stopwatch;
199 199
200 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher()); 200 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher());
201 Waiter w; 201 Waiter w;
202 uint32_t context = 0; 202 uint32_t context = 0;
203 HandleSignalsState hss; 203 HandleSignalsState hss;
204 204
205 // Try adding a writable waiter when it can never be writable. 205 // Try adding a writable waiter when it can never be writable.
206 w.Init(); 206 w.Init();
207 d->SetSatisfiableSignals(MOJO_HANDLE_SIGNAL_READABLE); 207 d->SetSatisfiableSignals(MOJO_HANDLE_SIGNAL_READABLE);
208 d->SetSatisfiedSignals(0); 208 d->SetSatisfiedSignals(0);
209 hss = HandleSignalsState(); 209 hss = HandleSignalsState();
210 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, 210 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
211 d->AddWaiter(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 1, &hss)); 211 d->AddAwakable(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 1, &hss));
212 EXPECT_EQ(0u, hss.satisfied_signals); 212 EXPECT_EQ(0u, hss.satisfied_signals);
213 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfiable_signals); 213 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfiable_signals);
214 // Shouldn't need to remove the waiter (it was not added). 214 // Shouldn't need to remove the waiter (it was not added).
215 215
216 // Wait (forever) for writable and then it becomes never writable. 216 // Wait (forever) for writable and then it becomes never writable.
217 w.Init(); 217 w.Init();
218 d->SetSatisfiableSignals(MOJO_HANDLE_SIGNAL_READABLE | 218 d->SetSatisfiableSignals(MOJO_HANDLE_SIGNAL_READABLE |
219 MOJO_HANDLE_SIGNAL_WRITABLE); 219 MOJO_HANDLE_SIGNAL_WRITABLE);
220 ASSERT_EQ(MOJO_RESULT_OK, 220 ASSERT_EQ(MOJO_RESULT_OK,
221 d->AddWaiter(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 2, nullptr)); 221 d->AddAwakable(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 2, nullptr));
222 d->SetSatisfiableSignals(MOJO_HANDLE_SIGNAL_READABLE); 222 d->SetSatisfiableSignals(MOJO_HANDLE_SIGNAL_READABLE);
223 stopwatch.Start(); 223 stopwatch.Start();
224 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, 224 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
225 w.Wait(MOJO_DEADLINE_INDEFINITE, &context)); 225 w.Wait(MOJO_DEADLINE_INDEFINITE, &context));
226 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); 226 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout());
227 EXPECT_EQ(2u, context); 227 EXPECT_EQ(2u, context);
228 hss = HandleSignalsState(); 228 hss = HandleSignalsState();
229 d->RemoveWaiter(&w, &hss); 229 d->RemoveAwakable(&w, &hss);
230 EXPECT_EQ(0u, hss.satisfied_signals); 230 EXPECT_EQ(0u, hss.satisfied_signals);
231 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfiable_signals); 231 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfiable_signals);
232 232
233 // Wait for zero time for writable and then it becomes never writable. 233 // Wait for zero time for writable and then it becomes never writable.
234 w.Init(); 234 w.Init();
235 d->SetSatisfiableSignals(MOJO_HANDLE_SIGNAL_READABLE | 235 d->SetSatisfiableSignals(MOJO_HANDLE_SIGNAL_READABLE |
236 MOJO_HANDLE_SIGNAL_WRITABLE); 236 MOJO_HANDLE_SIGNAL_WRITABLE);
237 ASSERT_EQ(MOJO_RESULT_OK, 237 ASSERT_EQ(MOJO_RESULT_OK,
238 d->AddWaiter(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 3, nullptr)); 238 d->AddAwakable(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 3, nullptr));
239 d->SetSatisfiableSignals(MOJO_HANDLE_SIGNAL_READABLE); 239 d->SetSatisfiableSignals(MOJO_HANDLE_SIGNAL_READABLE);
240 stopwatch.Start(); 240 stopwatch.Start();
241 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, w.Wait(0, &context)); 241 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, w.Wait(0, &context));
242 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); 242 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout());
243 EXPECT_EQ(3u, context); 243 EXPECT_EQ(3u, context);
244 hss = HandleSignalsState(); 244 hss = HandleSignalsState();
245 d->RemoveWaiter(&w, &hss); 245 d->RemoveAwakable(&w, &hss);
246 EXPECT_EQ(0u, hss.satisfied_signals); 246 EXPECT_EQ(0u, hss.satisfied_signals);
247 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfiable_signals); 247 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfiable_signals);
248 248
249 // Wait for non-zero, finite time for writable and then it becomes never 249 // Wait for non-zero, finite time for writable and then it becomes never
250 // writable. 250 // writable.
251 w.Init(); 251 w.Init();
252 d->SetSatisfiableSignals(MOJO_HANDLE_SIGNAL_READABLE | 252 d->SetSatisfiableSignals(MOJO_HANDLE_SIGNAL_READABLE |
253 MOJO_HANDLE_SIGNAL_WRITABLE); 253 MOJO_HANDLE_SIGNAL_WRITABLE);
254 ASSERT_EQ(MOJO_RESULT_OK, 254 ASSERT_EQ(MOJO_RESULT_OK,
255 d->AddWaiter(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 4, nullptr)); 255 d->AddAwakable(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 4, nullptr));
256 d->SetSatisfiableSignals(MOJO_HANDLE_SIGNAL_READABLE); 256 d->SetSatisfiableSignals(MOJO_HANDLE_SIGNAL_READABLE);
257 stopwatch.Start(); 257 stopwatch.Start();
258 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, 258 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
259 w.Wait(2 * test::EpsilonTimeout().InMicroseconds(), &context)); 259 w.Wait(2 * test::EpsilonTimeout().InMicroseconds(), &context));
260 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); 260 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout());
261 EXPECT_EQ(4u, context); 261 EXPECT_EQ(4u, context);
262 hss = HandleSignalsState(); 262 hss = HandleSignalsState();
263 d->RemoveWaiter(&w, &hss); 263 d->RemoveAwakable(&w, &hss);
264 EXPECT_EQ(0u, hss.satisfied_signals); 264 EXPECT_EQ(0u, hss.satisfied_signals);
265 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfiable_signals); 265 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfiable_signals);
266 266
267 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); 267 EXPECT_EQ(MOJO_RESULT_OK, d->Close());
268 } 268 }
269 269
270 TEST(SimpleDispatcherTest, BasicClosed) { 270 TEST(SimpleDispatcherTest, BasicClosed) {
271 test::Stopwatch stopwatch; 271 test::Stopwatch stopwatch;
272 272
273 scoped_refptr<MockSimpleDispatcher> d; 273 scoped_refptr<MockSimpleDispatcher> d;
274 Waiter w; 274 Waiter w;
275 uint32_t context = 0; 275 uint32_t context = 0;
276 HandleSignalsState hss; 276 HandleSignalsState hss;
277 277
278 // Try adding a writable waiter when the dispatcher has been closed. 278 // Try adding a writable waiter when the dispatcher has been closed.
279 d = new MockSimpleDispatcher(); 279 d = new MockSimpleDispatcher();
280 w.Init(); 280 w.Init();
281 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); 281 EXPECT_EQ(MOJO_RESULT_OK, d->Close());
282 hss = HandleSignalsState(); 282 hss = HandleSignalsState();
283 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 283 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
284 d->AddWaiter(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 1, &hss)); 284 d->AddAwakable(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 1, &hss));
285 EXPECT_EQ(0u, hss.satisfied_signals); 285 EXPECT_EQ(0u, hss.satisfied_signals);
286 EXPECT_EQ(0u, hss.satisfiable_signals); 286 EXPECT_EQ(0u, hss.satisfiable_signals);
287 // Shouldn't need to remove the waiter (it was not added). 287 // Shouldn't need to remove the waiter (it was not added).
288 288
289 // Wait (forever) for writable and then the dispatcher is closed. 289 // Wait (forever) for writable and then the dispatcher is closed.
290 d = new MockSimpleDispatcher(); 290 d = new MockSimpleDispatcher();
291 w.Init(); 291 w.Init();
292 ASSERT_EQ(MOJO_RESULT_OK, 292 ASSERT_EQ(MOJO_RESULT_OK,
293 d->AddWaiter(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 2, nullptr)); 293 d->AddAwakable(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 2, nullptr));
294 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); 294 EXPECT_EQ(MOJO_RESULT_OK, d->Close());
295 stopwatch.Start(); 295 stopwatch.Start();
296 EXPECT_EQ(MOJO_RESULT_CANCELLED, w.Wait(MOJO_DEADLINE_INDEFINITE, &context)); 296 EXPECT_EQ(MOJO_RESULT_CANCELLED, w.Wait(MOJO_DEADLINE_INDEFINITE, &context));
297 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); 297 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout());
298 EXPECT_EQ(2u, context); 298 EXPECT_EQ(2u, context);
299 // Don't need to remove waiters from closed dispatchers. 299 // Don't need to remove waiters from closed dispatchers.
300 300
301 // Wait for zero time for writable and then the dispatcher is closed. 301 // Wait for zero time for writable and then the dispatcher is closed.
302 d = new MockSimpleDispatcher(); 302 d = new MockSimpleDispatcher();
303 w.Init(); 303 w.Init();
304 ASSERT_EQ(MOJO_RESULT_OK, 304 ASSERT_EQ(MOJO_RESULT_OK,
305 d->AddWaiter(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 3, nullptr)); 305 d->AddAwakable(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 3, nullptr));
306 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); 306 EXPECT_EQ(MOJO_RESULT_OK, d->Close());
307 stopwatch.Start(); 307 stopwatch.Start();
308 EXPECT_EQ(MOJO_RESULT_CANCELLED, w.Wait(0, &context)); 308 EXPECT_EQ(MOJO_RESULT_CANCELLED, w.Wait(0, &context));
309 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); 309 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout());
310 EXPECT_EQ(3u, context); 310 EXPECT_EQ(3u, context);
311 // Don't need to remove waiters from closed dispatchers. 311 // Don't need to remove waiters from closed dispatchers.
312 312
313 // Wait for non-zero, finite time for writable and then the dispatcher is 313 // Wait for non-zero, finite time for writable and then the dispatcher is
314 // closed. 314 // closed.
315 d = new MockSimpleDispatcher(); 315 d = new MockSimpleDispatcher();
316 w.Init(); 316 w.Init();
317 ASSERT_EQ(MOJO_RESULT_OK, 317 ASSERT_EQ(MOJO_RESULT_OK,
318 d->AddWaiter(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 4, nullptr)); 318 d->AddAwakable(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 4, nullptr));
319 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); 319 EXPECT_EQ(MOJO_RESULT_OK, d->Close());
320 stopwatch.Start(); 320 stopwatch.Start();
321 EXPECT_EQ(MOJO_RESULT_CANCELLED, 321 EXPECT_EQ(MOJO_RESULT_CANCELLED,
322 w.Wait(2 * test::EpsilonTimeout().InMicroseconds(), &context)); 322 w.Wait(2 * test::EpsilonTimeout().InMicroseconds(), &context));
323 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); 323 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout());
324 EXPECT_EQ(4u, context); 324 EXPECT_EQ(4u, context);
325 // Don't need to remove waiters from closed dispatchers. 325 // Don't need to remove waiters from closed dispatchers.
326 } 326 }
327 327
328 #if defined(OS_WIN) 328 #if defined(OS_WIN)
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 // Since we closed before joining, we can't say much about what each thread 600 // Since we closed before joining, we can't say much about what each thread
601 // saw as the state. 601 // saw as the state.
602 } 602 }
603 } 603 }
604 604
605 // TODO(vtl): Stress test? 605 // TODO(vtl): Stress test?
606 606
607 } // namespace 607 } // namespace
608 } // namespace system 608 } // namespace system
609 } // namespace mojo 609 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698