OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 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 // High resolution timer unit tests. |
| 6 |
| 7 #include "base/basictypes.h" |
| 8 #include "chrome/browser/sync/util/highres_timer.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 |
| 11 // These unittests have proven to be flaky on buildbot. While we don't want |
| 12 // them breaking the build, we still build them to guard against bitrot. |
| 13 // On dev machines during local builds we can enable them. |
| 14 TEST(HighresTimer, DISABLED_MillisecondClock) { |
| 15 HighresTimer timer; |
| 16 |
| 17 // note: this could fail if we context switch between initializing the timer |
| 18 // and here. Very unlikely however. |
| 19 EXPECT_EQ(0, timer.GetElapsedMs()); |
| 20 timer.Start(); |
| 21 uint64 half_ms = HighresTimer::GetTimerFrequency() / 2000; |
| 22 // busy wait for half a millisecond |
| 23 while (timer.start_ticks() + half_ms > HighresTimer::GetCurrentTicks()) { |
| 24 // Nothing |
| 25 } |
| 26 EXPECT_EQ(1, timer.GetElapsedMs()); |
| 27 } |
| 28 |
| 29 TEST(HighresTimer, DISABLED_SecondClock) { |
| 30 HighresTimer timer; |
| 31 |
| 32 EXPECT_EQ(0, timer.GetElapsedSec()); |
| 33 #ifdef OS_WINDOWS |
| 34 ::Sleep(250); |
| 35 #else |
| 36 struct timespec ts1 = {0, 250000000}; |
| 37 nanosleep(&ts1, 0); |
| 38 #endif |
| 39 EXPECT_EQ(0, timer.GetElapsedSec()); |
| 40 EXPECT_LE(230, timer.GetElapsedMs()); |
| 41 EXPECT_GE(270, timer.GetElapsedMs()); |
| 42 #ifdef OS_WINDOWS |
| 43 ::Sleep(251); |
| 44 #else |
| 45 struct timespec ts2 = {0, 251000000}; |
| 46 nanosleep(&ts2, 0); |
| 47 #endif |
| 48 EXPECT_EQ(1, timer.GetElapsedSec()); |
| 49 } |
OLD | NEW |