| 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/edk/system/awakable_list.h" | 10 #include "mojo/edk/system/awakable_list.h" |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 EXPECT_EQ(MOJO_RESULT_OK, result1); | 278 EXPECT_EQ(MOJO_RESULT_OK, result1); |
| 279 EXPECT_EQ(7u, context1); | 279 EXPECT_EQ(7u, context1); |
| 280 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result2); | 280 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result2); |
| 281 EXPECT_EQ(8u, context2); | 281 EXPECT_EQ(8u, context2); |
| 282 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result3); | 282 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result3); |
| 283 EXPECT_EQ(9u, context3); | 283 EXPECT_EQ(9u, context3); |
| 284 EXPECT_EQ(MOJO_RESULT_CANCELLED, result4); | 284 EXPECT_EQ(MOJO_RESULT_CANCELLED, result4); |
| 285 EXPECT_EQ(10u, context4); | 285 EXPECT_EQ(10u, context4); |
| 286 } | 286 } |
| 287 | 287 |
| 288 TEST(AwakableListTest, RemoveWithContext) { |
| 289 MojoResult result; |
| 290 uint64_t context; |
| 291 |
| 292 { |
| 293 AwakableList awakable_list; |
| 294 test::SimpleWaiterThread thread(&result, &context); |
| 295 awakable_list.Add(thread.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 1); |
| 296 awakable_list.Add(thread.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 2); |
| 297 thread.Start(); |
| 298 awakable_list.RemoveWithContext(thread.waiter(), 2); |
| 299 awakable_list.AwakeForStateChange(HandleSignalsState( |
| 300 MOJO_HANDLE_SIGNAL_READABLE, |
| 301 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE)); |
| 302 awakable_list.RemoveWithContext(thread.waiter(), 1); |
| 303 // Double-remove okay: |
| 304 awakable_list.RemoveWithContext(thread.waiter(), 1); |
| 305 } // Join |thread|. |
| 306 EXPECT_EQ(MOJO_RESULT_OK, result); |
| 307 EXPECT_EQ(1u, context); |
| 308 |
| 309 // Try the same thing, but remove "1" before the awake instead. |
| 310 { |
| 311 AwakableList awakable_list; |
| 312 test::SimpleWaiterThread thread(&result, &context); |
| 313 awakable_list.Add(thread.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 1); |
| 314 awakable_list.Add(thread.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 2); |
| 315 thread.Start(); |
| 316 awakable_list.RemoveWithContext(thread.waiter(), 1); |
| 317 awakable_list.AwakeForStateChange(HandleSignalsState( |
| 318 MOJO_HANDLE_SIGNAL_READABLE, |
| 319 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE)); |
| 320 awakable_list.RemoveWithContext(thread.waiter(), 2); |
| 321 } // Join |thread|. |
| 322 EXPECT_EQ(MOJO_RESULT_OK, result); |
| 323 EXPECT_EQ(2u, context); |
| 324 } |
| 325 |
| 288 class KeepAwakable : public Awakable { | 326 class KeepAwakable : public Awakable { |
| 289 public: | 327 public: |
| 290 KeepAwakable() : awake_count(0) {} | 328 KeepAwakable() : awake_count(0) {} |
| 291 | 329 |
| 292 bool Awake(MojoResult result, uint64_t context) override { | 330 bool Awake(MojoResult result, uint64_t context) override { |
| 293 awake_count++; | 331 awake_count++; |
| 294 return true; | 332 return true; |
| 295 } | 333 } |
| 296 | 334 |
| 297 int awake_count; | 335 int awake_count; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 EXPECT_EQ(keep1.awake_count, 2); | 388 EXPECT_EQ(keep1.awake_count, 2); |
| 351 EXPECT_EQ(remove2.awake_count, 1); | 389 EXPECT_EQ(remove2.awake_count, 1); |
| 352 | 390 |
| 353 remove_first.Remove(&keep0); | 391 remove_first.Remove(&keep0); |
| 354 remove_first.Remove(&keep1); | 392 remove_first.Remove(&keep1); |
| 355 } | 393 } |
| 356 | 394 |
| 357 } // namespace | 395 } // namespace |
| 358 } // namespace system | 396 } // namespace system |
| 359 } // namespace mojo | 397 } // namespace mojo |
| OLD | NEW |