| 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 <cmath> | 9 #include <cmath> |
| 10 #include <limits> | 10 #include <limits> |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 } | 109 } |
| 110 | 110 |
| 111 CloseHandle(g_rollover_test_start); | 111 CloseHandle(g_rollover_test_start); |
| 112 | 112 |
| 113 // Teardown | 113 // Teardown |
| 114 MockTimeTicks::UninstallTicker(); | 114 MockTimeTicks::UninstallTicker(); |
| 115 } | 115 } |
| 116 } | 116 } |
| 117 | 117 |
| 118 TEST(TimeTicks, SubMillisecondTimers) { | 118 TEST(TimeTicks, SubMillisecondTimers) { |
| 119 // HighResNow doesn't work on some systems. Since the product still works | 119 // IsHighResolution() is false on some systems. Since the product still works |
| 120 // even if it doesn't work, it makes this entire test questionable. | 120 // even if it's false, it makes this entire test questionable. |
| 121 if (!TimeTicks::IsHighResolution()) | 121 if (!TimeTicks::IsHighResolution()) |
| 122 return; | 122 return; |
| 123 | 123 |
| 124 const int kRetries = 1000; | 124 const int kRetries = 1000; |
| 125 bool saw_submillisecond_timer = false; | 125 bool saw_submillisecond_timer = false; |
| 126 | 126 |
| 127 // Run kRetries attempts to see a sub-millisecond timer. | 127 // Run kRetries attempts to see a sub-millisecond timer. |
| 128 for (int index = 0; index < kRetries; index++) { | 128 for (int index = 0; index < kRetries; index++) { |
| 129 TimeTicks last_time = TimeTicks::HighResNow(); | 129 TimeTicks last_time = TimeTicks::Now(); |
| 130 TimeDelta delta; | 130 TimeDelta delta; |
| 131 // Spin until the clock has detected a change. | 131 // Spin until the clock has detected a change. |
| 132 do { | 132 do { |
| 133 delta = TimeTicks::HighResNow() - last_time; | 133 delta = TimeTicks::Now() - last_time; |
| 134 } while (delta.InMicroseconds() == 0); | 134 } while (delta.InMicroseconds() == 0); |
| 135 if (delta.InMicroseconds() < 1000) { | 135 if (delta.InMicroseconds() < 1000) { |
| 136 saw_submillisecond_timer = true; | 136 saw_submillisecond_timer = true; |
| 137 break; | 137 break; |
| 138 } | 138 } |
| 139 } | 139 } |
| 140 EXPECT_TRUE(saw_submillisecond_timer); | 140 EXPECT_TRUE(saw_submillisecond_timer); |
| 141 } | 141 } |
| 142 | 142 |
| 143 TEST(TimeTicks, TimeGetTimeCaps) { | 143 TEST(TimeTicks, TimeGetTimeCaps) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 test_only_works_with_same_sizes); | 186 test_only_works_with_same_sizes); |
| 187 TestCase cases[] = { | 187 TestCase cases[] = { |
| 188 { reinterpret_cast<TestFunc>(Time::Now), "Time::Now" }, | 188 { reinterpret_cast<TestFunc>(Time::Now), "Time::Now" }, |
| 189 { TimeTicks::Now, "TimeTicks::Now" }, | 189 { TimeTicks::Now, "TimeTicks::Now" }, |
| 190 { TimeTicks::NowFromSystemTraceTime, "TimeTicks::NowFromSystemTraceTime" }, | 190 { TimeTicks::NowFromSystemTraceTime, "TimeTicks::NowFromSystemTraceTime" }, |
| 191 { NULL, "" } | 191 { NULL, "" } |
| 192 }; | 192 }; |
| 193 | 193 |
| 194 int test_case = 0; | 194 int test_case = 0; |
| 195 while (cases[test_case].func) { | 195 while (cases[test_case].func) { |
| 196 TimeTicks start = TimeTicks::HighResNow(); | 196 TimeTicks start = TimeTicks::Now(); |
| 197 for (int index = 0; index < kLoops; index++) | 197 for (int index = 0; index < kLoops; index++) |
| 198 cases[test_case].func(); | 198 cases[test_case].func(); |
| 199 TimeTicks stop = TimeTicks::HighResNow(); | 199 TimeTicks stop = TimeTicks::Now(); |
| 200 // Turning off the check for acceptible delays. Without this check, | 200 // Turning off the check for acceptible delays. Without this check, |
| 201 // the test really doesn't do much other than measure. But the | 201 // the test really doesn't do much other than measure. But the |
| 202 // measurements are still useful for testing timers on various platforms. | 202 // measurements are still useful for testing timers on various platforms. |
| 203 // The reason to remove the check is because the tests run on many | 203 // 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 | 204 // 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. | 205 // slow, and there is really no value for checking against a max timer. |
| 206 //const int kMaxTime = 35; // Maximum acceptible milliseconds for test. | 206 //const int kMaxTime = 35; // Maximum acceptible milliseconds for test. |
| 207 //EXPECT_LT((stop - start).InMilliseconds(), kMaxTime); | 207 //EXPECT_LT((stop - start).InMilliseconds(), kMaxTime); |
| 208 printf("%s: %1.2fus per call\n", cases[test_case].description, | 208 printf("%s: %1.2fus per call\n", cases[test_case].description, |
| 209 (stop - start).InMillisecondsF() * 1000 / kLoops); | 209 (stop - start).InMillisecondsF() * 1000 / kLoops); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 const TimeTicks converted_value = TimeTicks::FromQPCValue(ticks); | 258 const TimeTicks converted_value = TimeTicks::FromQPCValue(ticks); |
| 259 const double converted_microseconds_since_origin = | 259 const double converted_microseconds_since_origin = |
| 260 static_cast<double>((converted_value - TimeTicks()).InMicroseconds()); | 260 static_cast<double>((converted_value - TimeTicks()).InMicroseconds()); |
| 261 EXPECT_NEAR(expected_microseconds_since_origin, | 261 EXPECT_NEAR(expected_microseconds_since_origin, |
| 262 converted_microseconds_since_origin, | 262 converted_microseconds_since_origin, |
| 263 1.0) | 263 1.0) |
| 264 << "ticks=" << ticks << ", to be converted via logic path: " | 264 << "ticks=" << ticks << ", to be converted via logic path: " |
| 265 << (ticks < Time::kQPCOverflowThreshold ? "FAST" : "SAFE"); | 265 << (ticks < Time::kQPCOverflowThreshold ? "FAST" : "SAFE"); |
| 266 } | 266 } |
| 267 } | 267 } |
| OLD | NEW |