OLD | NEW |
---|---|
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #include <windows.h> | 5 #include <windows.h> |
6 #include <mmsystem.h> | 6 #include <mmsystem.h> |
7 #include <process.h> | 7 #include <process.h> |
8 | 8 |
9 #include "base/platform_thread.h" | 9 #include "base/platform_thread.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
101 EXPECT_EQ(rv, WAIT_OBJECT_0); | 101 EXPECT_EQ(rv, WAIT_OBJECT_0); |
102 } | 102 } |
103 | 103 |
104 CloseHandle(g_rollover_test_start); | 104 CloseHandle(g_rollover_test_start); |
105 | 105 |
106 // Teardown | 106 // Teardown |
107 MockTimeTicks::UninstallTicker(); | 107 MockTimeTicks::UninstallTicker(); |
108 } | 108 } |
109 } | 109 } |
110 | 110 |
111 // Flaky, http://crbug.com/42850. | 111 TEST(TimeTicks, SubMillisecondTimers) { |
112 TEST(TimeTicks, FLAKY_SubMillisecondTimers) { | 112 // HighResNow doesn't work on some systems. Since the product still works |
113 // Loop for a bit getting timers quickly. We want to | 113 // even if it doesn't work, it makes this entire test questionable. |
114 // see at least one case where we get a new sample in | 114 if (!TimeTicks::IsHighResClockWorking()) |
115 // less than one millisecond. | 115 return; |
116 | |
117 const int kRetries = 1000; | |
116 bool saw_submillisecond_timer = false; | 118 bool saw_submillisecond_timer = false; |
117 int64 min_timer = 1000; | 119 |
118 TimeTicks last_time = TimeTicks::HighResNow(); | 120 // Run kRetries attempts to see a sub-millisecond timer. |
Paweł Hajdan Jr.
2010/09/22 09:35:32
This test has still potential for flakiness. What
Mike Belshe
2010/09/22 21:58:48
Unfortunately, I don't think it helps. In this ca
| |
119 for (int index = 0; index < 1000; index++) { | 121 for (int index = 0; index < 1000; index++) { |
120 TimeTicks now = TimeTicks::HighResNow(); | 122 TimeTicks last_time = TimeTicks::HighResNow(); |
121 TimeDelta delta = now - last_time; | 123 TimeDelta delta; |
122 if (delta.InMicroseconds() > 0 && | 124 // Spin until the clock changes a little |
Paweł Hajdan Jr.
2010/09/22 09:35:32
nit: Dot at the end, and explain why.
Mike Belshe
2010/09/22 21:58:48
Done.
| |
123 delta.InMicroseconds() < 1000) { | 125 do { |
124 if (min_timer > delta.InMicroseconds()) | 126 delta = TimeTicks::HighResNow() - last_time; |
125 min_timer = delta.InMicroseconds(); | 127 } while (delta.InMicroseconds() == 0); |
128 if (delta.InMicroseconds() < 1000) { | |
126 saw_submillisecond_timer = true; | 129 saw_submillisecond_timer = true; |
130 break; | |
127 } | 131 } |
128 last_time = now; | |
129 } | 132 } |
130 EXPECT_TRUE(saw_submillisecond_timer); | 133 EXPECT_TRUE(saw_submillisecond_timer); |
131 printf("Min timer is: %ldus\n", static_cast<long>(min_timer)); | |
132 } | 134 } |
133 | 135 |
134 TEST(TimeTicks, TimeGetTimeCaps) { | 136 TEST(TimeTicks, TimeGetTimeCaps) { |
135 // Test some basic assumptions that we expect about how timeGetDevCaps works. | 137 // Test some basic assumptions that we expect about how timeGetDevCaps works. |
136 | 138 |
137 TIMECAPS caps; | 139 TIMECAPS caps; |
138 MMRESULT status = timeGetDevCaps(&caps, sizeof(caps)); | 140 MMRESULT status = timeGetDevCaps(&caps, sizeof(caps)); |
139 EXPECT_EQ(TIMERR_NOERROR, status); | 141 EXPECT_EQ(TIMERR_NOERROR, status); |
140 if (status != TIMERR_NOERROR) { | 142 if (status != TIMERR_NOERROR) { |
141 printf("Could not get timeGetDevCaps\n"); | 143 printf("Could not get timeGetDevCaps\n"); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
223 total_drift += drift_microseconds; | 225 total_drift += drift_microseconds; |
224 } | 226 } |
225 | 227 |
226 // Sanity check. We expect some time drift to occur, especially across | 228 // Sanity check. We expect some time drift to occur, especially across |
227 // the number of iterations we do. However, if the QPC is disabled, this | 229 // the number of iterations we do. However, if the QPC is disabled, this |
228 // is not measuring anything (drift is zero in that case). | 230 // is not measuring anything (drift is zero in that case). |
229 EXPECT_LT(0, total_drift); | 231 EXPECT_LT(0, total_drift); |
230 | 232 |
231 printf("average time drift in microseconds: %lld\n", | 233 printf("average time drift in microseconds: %lld\n", |
232 total_drift / kIterations); | 234 total_drift / kIterations); |
233 } | 235 } |
OLD | NEW |