| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/threading/platform_thread.h" | 9 #include "base/threading/platform_thread.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 TEST(TimeTicks, SubMillisecondTimers) { | 114 TEST(TimeTicks, SubMillisecondTimers) { |
| 115 // HighResNow doesn't work on some systems. Since the product still works | 115 // HighResNow doesn't work on some systems. Since the product still works |
| 116 // even if it doesn't work, it makes this entire test questionable. | 116 // even if it doesn't work, it makes this entire test questionable. |
| 117 if (!TimeTicks::IsHighResClockWorking()) | 117 if (!TimeTicks::IsHighResClockWorking()) |
| 118 return; | 118 return; |
| 119 | 119 |
| 120 const int kRetries = 1000; | 120 const int kRetries = 1000; |
| 121 bool saw_submillisecond_timer = false; | 121 bool saw_submillisecond_timer = false; |
| 122 | 122 |
| 123 // Run kRetries attempts to see a sub-millisecond timer. | 123 // Run kRetries attempts to see a sub-millisecond timer. |
| 124 for (int index = 0; index < 1000; index++) { | 124 for (int index = 0; index < kRetries; index++) { |
| 125 TimeTicks last_time = TimeTicks::HighResNow(); | 125 TimeTicks last_time = TimeTicks::HighResNow(); |
| 126 TimeDelta delta; | 126 TimeDelta delta; |
| 127 // Spin until the clock has detected a change. | 127 // Spin until the clock has detected a change. |
| 128 do { | 128 do { |
| 129 delta = TimeTicks::HighResNow() - last_time; | 129 delta = TimeTicks::HighResNow() - last_time; |
| 130 } while (delta.InMicroseconds() == 0); | 130 } while (delta.InMicroseconds() == 0); |
| 131 if (delta.InMicroseconds() < 1000) { | 131 if (delta.InMicroseconds() < 1000) { |
| 132 saw_submillisecond_timer = true; | 132 saw_submillisecond_timer = true; |
| 133 break; | 133 break; |
| 134 } | 134 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 163 EXPECT_EQ(TRUE, rv); | 163 EXPECT_EQ(TRUE, rv); |
| 164 EXPECT_GT(frequency.QuadPart, 1000000); // Expect at least 1MHz | 164 EXPECT_GT(frequency.QuadPart, 1000000); // Expect at least 1MHz |
| 165 printf("QueryPerformanceFrequency is %5.2fMHz\n", | 165 printf("QueryPerformanceFrequency is %5.2fMHz\n", |
| 166 frequency.QuadPart / 1000000.0); | 166 frequency.QuadPart / 1000000.0); |
| 167 } | 167 } |
| 168 | 168 |
| 169 TEST(TimeTicks, TimerPerformance) { | 169 TEST(TimeTicks, TimerPerformance) { |
| 170 // Verify that various timer mechanisms can always complete quickly. | 170 // Verify that various timer mechanisms can always complete quickly. |
| 171 // Note: This is a somewhat arbitrary test. | 171 // Note: This is a somewhat arbitrary test. |
| 172 const int kLoops = 10000; | 172 const int kLoops = 10000; |
| 173 // Due to the fact that these run on bbots, which are horribly slow, | |
| 174 // we can't really make any guarantees about minimum runtime. | |
| 175 // Really, we want these to finish in ~10ms, and that is generous. | |
| 176 const int kMaxTime = 35; // Maximum acceptible milliseconds for test. | |
| 177 | 173 |
| 178 typedef TimeTicks (*TestFunc)(); | 174 typedef TimeTicks (*TestFunc)(); |
| 179 struct TestCase { | 175 struct TestCase { |
| 180 TestFunc func; | 176 TestFunc func; |
| 181 const char *description; | 177 const char *description; |
| 182 }; | 178 }; |
| 183 // Cheating a bit here: assumes sizeof(TimeTicks) == sizeof(Time) | 179 // Cheating a bit here: assumes sizeof(TimeTicks) == sizeof(Time) |
| 184 // in order to create a single test case list. | 180 // in order to create a single test case list. |
| 185 COMPILE_ASSERT(sizeof(TimeTicks) == sizeof(Time), | 181 COMPILE_ASSERT(sizeof(TimeTicks) == sizeof(Time), |
| 186 test_only_works_with_same_sizes); | 182 test_only_works_with_same_sizes); |
| 187 TestCase cases[] = { | 183 TestCase cases[] = { |
| 188 { reinterpret_cast<TestFunc>(Time::Now), "Time::Now" }, | 184 { reinterpret_cast<TestFunc>(Time::Now), "Time::Now" }, |
| 189 { TimeTicks::Now, "TimeTicks::Now" }, | 185 { TimeTicks::Now, "TimeTicks::Now" }, |
| 190 { TimeTicks::HighResNow, "TimeTicks::HighResNow" }, | 186 { TimeTicks::HighResNow, "TimeTicks::HighResNow" }, |
| 191 { NULL, "" } | 187 { NULL, "" } |
| 192 }; | 188 }; |
| 193 | 189 |
| 194 int test_case = 0; | 190 int test_case = 0; |
| 195 while (cases[test_case].func) { | 191 while (cases[test_case].func) { |
| 196 TimeTicks start = TimeTicks::HighResNow(); | 192 TimeTicks start = TimeTicks::HighResNow(); |
| 197 for (int index = 0; index < kLoops; index++) | 193 for (int index = 0; index < kLoops; index++) |
| 198 cases[test_case].func(); | 194 cases[test_case].func(); |
| 199 TimeTicks stop = TimeTicks::HighResNow(); | 195 TimeTicks stop = TimeTicks::HighResNow(); |
| 200 // Turning off the check for acceptible delays. Without this check, | 196 // Turning off the check for acceptible delays. Without this check, |
| 201 // the test really doesn't do much other than measure. But the | 197 // the test really doesn't do much other than measure. But the |
| 202 // measurements are still useful for testing timers on various platforms. | 198 // measurements are still useful for testing timers on various platforms. |
| 203 // The reason to remove the check is because the tests run on many | 199 // The reason to remove the check is because the tests run on many |
| 204 // buildbots, some of which are VMs. These machines can run horribly | 200 // buildbots, some of which are VMs. These machines can run horribly |
| 205 // slow, and there is really no value for checking against a max timer. | 201 // slow, and there is really no value for checking against a max timer. |
| 202 //const int kMaxTime = 35; // Maximum acceptible milliseconds for test. |
| 206 //EXPECT_LT((stop - start).InMilliseconds(), kMaxTime); | 203 //EXPECT_LT((stop - start).InMilliseconds(), kMaxTime); |
| 207 printf("%s: %1.2fus per call\n", cases[test_case].description, | 204 printf("%s: %1.2fus per call\n", cases[test_case].description, |
| 208 (stop - start).InMillisecondsF() * 1000 / kLoops); | 205 (stop - start).InMillisecondsF() * 1000 / kLoops); |
| 209 test_case++; | 206 test_case++; |
| 210 } | 207 } |
| 211 } | 208 } |
| 212 | 209 |
| 213 // http://crbug.com/396384 | 210 // http://crbug.com/396384 |
| 214 TEST(TimeTicks, DISABLED_Drift) { | 211 TEST(TimeTicks, DISABLED_Drift) { |
| 215 // If QPC is disabled, this isn't measuring anything. | 212 // If QPC is disabled, this isn't measuring anything. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 EXPECT_EQ(expected_value, | 261 EXPECT_EQ(expected_value, |
| 265 TimeTicks::FromQPCValue(qpc_value + 1)); | 262 TimeTicks::FromQPCValue(qpc_value + 1)); |
| 266 expected_value = TimeTicks::FromInternalValue( | 263 expected_value = TimeTicks::FromInternalValue( |
| 267 QPCValueToMicrosecondsSafely(qpc_value, ticks_per_second)); | 264 QPCValueToMicrosecondsSafely(qpc_value, ticks_per_second)); |
| 268 EXPECT_EQ(expected_value, | 265 EXPECT_EQ(expected_value, |
| 269 TimeTicks::FromQPCValue(qpc_value)); | 266 TimeTicks::FromQPCValue(qpc_value)); |
| 270 expected_value = TimeTicks::FromInternalValue( | 267 expected_value = TimeTicks::FromInternalValue( |
| 271 QPCValueToMicrosecondsSafely(qpc_value - 1, ticks_per_second)); | 268 QPCValueToMicrosecondsSafely(qpc_value - 1, ticks_per_second)); |
| 272 EXPECT_EQ(expected_value, | 269 EXPECT_EQ(expected_value, |
| 273 TimeTicks::FromQPCValue(qpc_value - 1)); | 270 TimeTicks::FromQPCValue(qpc_value - 1)); |
| 274 } | 271 } |
| OLD | NEW |