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

Unified Diff: mojo/edk/platform/thread_utils_unittest.cc

Issue 1639093002: Add //mojo/edk/platform/thread_utils.* containing "yield" and "sleep". (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 11 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/edk/platform/thread_utils.h ('k') | mojo/edk/system/awakable_list_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « mojo/edk/platform/thread_utils.h ('k') | mojo/edk/system/awakable_list_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698