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

Side by Side 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, 10 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
OLDNEW
« 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