diff options
author | mbelshe@chromium.org <mbelshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-23 15:54:48 +0000 |
---|---|---|
committer | mbelshe@chromium.org <mbelshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-23 15:54:48 +0000 |
commit | 8af6f3346e40353c78ed6b787aa128f934432689 (patch) | |
tree | 54fdeca3410be1e8f8c6317ebdb1693843d40a27 | |
parent | ef7511d1b5cfa9645970a16ff5636827121f15b8 (diff) | |
download | chromium_src-8af6f3346e40353c78ed6b787aa128f934432689.zip chromium_src-8af6f3346e40353c78ed6b787aa128f934432689.tar.gz chromium_src-8af6f3346e40353c78ed6b787aa128f934432689.tar.bz2 |
The submillisecond test was broken in at least two ways. First, the
high resolution clock is intentionally disabled on some systems (old AMDs).
If QueryPerformanceCounter doesn't work on this system, we shouldn't run the
test.
Second, however, if the time between two HighResNow() calls is *always* 0us,
then this test would fail. Due to speedstep technology with intentionally
underclocked QPC (at the windows level), this is quite possible.
BUG=42850
TEST=TimeTicks.SubMillisecondTimers
Review URL: http://codereview.chromium.org/3387011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@60293 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | base/time.h | 4 | ||||
-rw-r--r-- | base/time_win.cc | 5 | ||||
-rw-r--r-- | base/time_win_unittest.cc | 34 |
3 files changed, 27 insertions, 16 deletions
diff --git a/base/time.h b/base/time.h index 494aa57..79e30b4 100644 --- a/base/time.h +++ b/base/time.h @@ -468,6 +468,10 @@ class TimeTicks { #if defined(OS_WIN) // Get the absolute value of QPC time drift. For testing. static int64 GetQPCDriftMicroseconds(); + + // Returns true if the high resolution clock is working on this system. + // This is only for testing. + static bool IsHighResClockWorking(); #endif // Returns true if this object has not been initialized. diff --git a/base/time_win.cc b/base/time_win.cc index 00868f6..5d3ecd6 100644 --- a/base/time_win.cc +++ b/base/time_win.cc @@ -400,4 +400,9 @@ TimeTicks TimeTicks::HighResNow() { // static int64 TimeTicks::GetQPCDriftMicroseconds() { return Singleton<HighResNowSingleton>::get()->GetQPCDriftMicroseconds(); +} + +// static +bool TimeTicks::IsHighResClockWorking() { + return Singleton<HighResNowSingleton>::get()->IsUsingHighResClock(); }
\ No newline at end of file diff --git a/base/time_win_unittest.cc b/base/time_win_unittest.cc index 26a9784..4389e7a 100644 --- a/base/time_win_unittest.cc +++ b/base/time_win_unittest.cc @@ -108,27 +108,29 @@ TEST(TimeTicks, WinRollover) { } } -// Flaky, http://crbug.com/42850. -TEST(TimeTicks, FLAKY_SubMillisecondTimers) { - // Loop for a bit getting timers quickly. We want to - // see at least one case where we get a new sample in - // less than one millisecond. +TEST(TimeTicks, SubMillisecondTimers) { + // HighResNow doesn't work on some systems. Since the product still works + // even if it doesn't work, it makes this entire test questionable. + if (!TimeTicks::IsHighResClockWorking()) + return; + + const int kRetries = 1000; bool saw_submillisecond_timer = false; - int64 min_timer = 1000; - TimeTicks last_time = TimeTicks::HighResNow(); + + // Run kRetries attempts to see a sub-millisecond timer. for (int index = 0; index < 1000; index++) { - TimeTicks now = TimeTicks::HighResNow(); - TimeDelta delta = now - last_time; - if (delta.InMicroseconds() > 0 && - delta.InMicroseconds() < 1000) { - if (min_timer > delta.InMicroseconds()) - min_timer = delta.InMicroseconds(); + TimeTicks last_time = TimeTicks::HighResNow(); + TimeDelta delta; + // Spin until the clock has detected a change. + do { + delta = TimeTicks::HighResNow() - last_time; + } while (delta.InMicroseconds() == 0); + if (delta.InMicroseconds() < 1000) { saw_submillisecond_timer = true; + break; } - last_time = now; } EXPECT_TRUE(saw_submillisecond_timer); - printf("Min timer is: %ldus\n", static_cast<long>(min_timer)); } TEST(TimeTicks, TimeGetTimeCaps) { @@ -230,4 +232,4 @@ TEST(TimeTicks, Drift) { printf("average time drift in microseconds: %lld\n", total_drift / kIterations); -}
\ No newline at end of file +} |