OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "mojo/edk/platform/thread_utils.h" |
| 6 |
| 7 #include "mojo/edk/system/test/stopwatch.h" |
| 8 #include "mojo/edk/system/test/timeouts.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 |
| 11 using mojo::system::test::EpsilonTimeout; |
| 12 using mojo::system::test::Stopwatch; |
| 13 |
| 14 namespace mojo { |
| 15 namespace platform { |
| 16 namespace { |
| 17 |
| 18 TEST(ThreadUtils, ThreadYield) { |
| 19 // It's pretty hard to test yield, other than maybe statistically (but tough |
| 20 // even then, since it'd be dependent on the number of cores). So just check |
| 21 // that it doesn't crash. |
| 22 ThreadYield(); |
| 23 } |
| 24 |
| 25 TEST(ThreadUtils, ThreadSleep) { |
| 26 Stopwatch stopwatch; |
| 27 |
| 28 stopwatch.Start(); |
| 29 ThreadSleep(0ULL); |
| 30 EXPECT_LT(stopwatch.Elapsed(), EpsilonTimeout()); |
| 31 |
| 32 stopwatch.Start(); |
| 33 ThreadSleep(2 * EpsilonTimeout()); |
| 34 MojoDeadline elapsed = stopwatch.Elapsed(); |
| 35 EXPECT_GT(elapsed, EpsilonTimeout()); |
| 36 EXPECT_LT(elapsed, 3 * EpsilonTimeout()); |
| 37 } |
| 38 |
| 39 } // namespace |
| 40 } // namespace platform |
| 41 } // namespace mojo |
OLD | NEW |