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

Side by Side Diff: chrome/browser/sync/util/highres_timer_unittest.cc

Issue 193103: Build sync engine as part of the browser build (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // High resolution timer unit tests. 5 // High resolution timer unit tests.
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "build/build_config.h"
8 #include "chrome/browser/sync/util/highres_timer.h" 9 #include "chrome/browser/sync/util/highres_timer.h"
9 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
10 11
11 // These unittests have proven to be flaky on buildbot. While we don't want 12 // 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 // them breaking the build, we still build them to guard against bitrot.
13 // On dev machines during local builds we can enable them. 14 // On dev machines during local builds we can enable them.
14 TEST(HighresTimer, DISABLED_MillisecondClock) { 15 TEST(HighresTimer, DISABLED_MillisecondClock) {
15 HighresTimer timer; 16 HighresTimer timer;
16 17
17 // Note: this could fail if we context switch between initializing the timer 18 // Note: this could fail if we context switch between initializing the timer
18 // and here. Very unlikely however. 19 // and here. Very unlikely however.
19 EXPECT_EQ(0, timer.GetElapsedMs()); 20 EXPECT_EQ(0, timer.GetElapsedMs());
20 timer.Start(); 21 timer.Start();
21 uint64 half_ms = HighresTimer::GetTimerFrequency() / 2000; 22 uint64 half_ms = HighresTimer::GetTimerFrequency() / 2000;
22 // Busy wait for half a millisecond. 23 // Busy wait for half a millisecond.
23 while (timer.start_ticks() + half_ms > HighresTimer::GetCurrentTicks()) { 24 while (timer.start_ticks() + half_ms > HighresTimer::GetCurrentTicks()) {
24 // Nothing 25 // Nothing
25 } 26 }
26 EXPECT_EQ(1, timer.GetElapsedMs()); 27 EXPECT_EQ(1, timer.GetElapsedMs());
27 } 28 }
28 29
29 TEST(HighresTimer, DISABLED_SecondClock) { 30 TEST(HighresTimer, DISABLED_SecondClock) {
30 HighresTimer timer; 31 HighresTimer timer;
31 32
32 EXPECT_EQ(0, timer.GetElapsedSec()); 33 EXPECT_EQ(0, timer.GetElapsedSec());
33 #ifdef OS_WINDOWS 34 #ifdef OS_WIN
34 ::Sleep(250); 35 ::Sleep(250);
35 #else 36 #else
36 struct timespec ts1 = {0, 250000000}; 37 struct timespec ts1 = {0, 250000000};
37 nanosleep(&ts1, 0); 38 nanosleep(&ts1, 0);
38 #endif 39 #endif
39 EXPECT_EQ(0, timer.GetElapsedSec()); 40 EXPECT_EQ(0, timer.GetElapsedSec());
40 EXPECT_LE(230, timer.GetElapsedMs()); 41 EXPECT_LE(230, timer.GetElapsedMs());
41 EXPECT_GE(270, timer.GetElapsedMs()); 42 EXPECT_GE(270, timer.GetElapsedMs());
42 #ifdef OS_WINDOWS 43 #ifdef OS_WIN
43 ::Sleep(251); 44 ::Sleep(251);
44 #else 45 #else
45 struct timespec ts2 = {0, 251000000}; 46 struct timespec ts2 = {0, 251000000};
46 nanosleep(&ts2, 0); 47 nanosleep(&ts2, 0);
47 #endif 48 #endif
48 EXPECT_EQ(1, timer.GetElapsedSec()); 49 EXPECT_EQ(1, timer.GetElapsedSec());
49 } 50 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/util/highres_timer-win32.cc ('k') | chrome/browser/sync/util/highres_timer_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698