| 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/waiter.h" | 10 #include "mojo/edk/system/waiter.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 public: | 30 public: |
| 31 explicit WaitingThread(MojoDeadline deadline) | 31 explicit WaitingThread(MojoDeadline deadline) |
| 32 : base::SimpleThread("waiting_thread"), | 32 : base::SimpleThread("waiting_thread"), |
| 33 deadline_(deadline), | 33 deadline_(deadline), |
| 34 done_(false), | 34 done_(false), |
| 35 result_(MOJO_RESULT_UNKNOWN), | 35 result_(MOJO_RESULT_UNKNOWN), |
| 36 context_(static_cast<uint32_t>(-1)) { | 36 context_(static_cast<uint32_t>(-1)) { |
| 37 waiter_.Init(); | 37 waiter_.Init(); |
| 38 } | 38 } |
| 39 | 39 |
| 40 virtual ~WaitingThread() { Join(); } | 40 ~WaitingThread() override { Join(); } |
| 41 | 41 |
| 42 void WaitUntilDone(MojoResult* result, | 42 void WaitUntilDone(MojoResult* result, |
| 43 uint32_t* context, | 43 uint32_t* context, |
| 44 base::TimeDelta* elapsed) { | 44 base::TimeDelta* elapsed) { |
| 45 for (;;) { | 45 for (;;) { |
| 46 { | 46 { |
| 47 base::AutoLock locker(lock_); | 47 base::AutoLock locker(lock_); |
| 48 if (done_) { | 48 if (done_) { |
| 49 *result = result_; | 49 *result = result_; |
| 50 *context = context_; | 50 *context = context_; |
| 51 *elapsed = elapsed_; | 51 *elapsed = elapsed_; |
| 52 break; | 52 break; |
| 53 } | 53 } |
| 54 } | 54 } |
| 55 | 55 |
| 56 base::PlatformThread::Sleep( | 56 base::PlatformThread::Sleep( |
| 57 base::TimeDelta::FromMicroseconds(kPollTimeMicros)); | 57 base::TimeDelta::FromMicroseconds(kPollTimeMicros)); |
| 58 } | 58 } |
| 59 } | 59 } |
| 60 | 60 |
| 61 Waiter* waiter() { return &waiter_; } | 61 Waiter* waiter() { return &waiter_; } |
| 62 | 62 |
| 63 private: | 63 private: |
| 64 virtual void Run() override { | 64 void Run() override { |
| 65 test::Stopwatch stopwatch; | 65 test::Stopwatch stopwatch; |
| 66 MojoResult result; | 66 MojoResult result; |
| 67 uint32_t context = static_cast<uint32_t>(-1); | 67 uint32_t context = static_cast<uint32_t>(-1); |
| 68 base::TimeDelta elapsed; | 68 base::TimeDelta elapsed; |
| 69 | 69 |
| 70 stopwatch.Start(); | 70 stopwatch.Start(); |
| 71 result = waiter_.Wait(deadline_, &context); | 71 result = waiter_.Wait(deadline_, &context); |
| 72 elapsed = stopwatch.Elapsed(); | 72 elapsed = stopwatch.Elapsed(); |
| 73 | 73 |
| 74 { | 74 { |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result); | 293 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result); |
| 294 EXPECT_EQ(7u, context); | 294 EXPECT_EQ(7u, context); |
| 295 EXPECT_GT(elapsed, (1 - 1) * test::EpsilonTimeout()); | 295 EXPECT_GT(elapsed, (1 - 1) * test::EpsilonTimeout()); |
| 296 EXPECT_LT(elapsed, (1 + 1) * test::EpsilonTimeout()); | 296 EXPECT_LT(elapsed, (1 + 1) * test::EpsilonTimeout()); |
| 297 } | 297 } |
| 298 } | 298 } |
| 299 | 299 |
| 300 } // namespace | 300 } // namespace |
| 301 } // namespace system | 301 } // namespace system |
| 302 } // namespace mojo | 302 } // namespace mojo |
| OLD | NEW |