Index: mojo/edk/platform/thread_utils_unittest.cc |
diff --git a/mojo/edk/platform/thread_utils_unittest.cc b/mojo/edk/platform/thread_utils_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8d65a4fd3a5e44fe26d8e00268eb5c5441b562c5 |
--- /dev/null |
+++ b/mojo/edk/platform/thread_utils_unittest.cc |
@@ -0,0 +1,41 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "mojo/edk/platform/thread_utils.h" |
+ |
+#include "mojo/edk/system/test/stopwatch.h" |
+#include "mojo/edk/system/test/timeouts.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+using mojo::system::test::EpsilonTimeout; |
+using mojo::system::test::Stopwatch; |
+ |
+namespace mojo { |
+namespace platform { |
+namespace { |
+ |
+TEST(ThreadUtils, ThreadYield) { |
+ // It's pretty hard to test yield, other than maybe statistically (but tough |
+ // even then, since it'd be dependent on the number of cores). So just check |
+ // that it doesn't crash. |
+ ThreadYield(); |
+} |
+ |
+TEST(ThreadUtils, ThreadSleep) { |
+ Stopwatch stopwatch; |
+ |
+ stopwatch.Start(); |
+ ThreadSleep(0ULL); |
+ EXPECT_LT(stopwatch.Elapsed(), EpsilonTimeout()); |
+ |
+ stopwatch.Start(); |
+ ThreadSleep(2 * EpsilonTimeout()); |
+ MojoDeadline elapsed = stopwatch.Elapsed(); |
+ EXPECT_GT(elapsed, EpsilonTimeout()); |
+ EXPECT_LT(elapsed, 3 * EpsilonTimeout()); |
+} |
+ |
+} // namespace |
+} // namespace platform |
+} // namespace mojo |