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> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/threading/platform_thread.h" | 13 #include "base/threading/platform_thread.h" |
14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 | 16 |
17 using base::Time; | 17 using base::Time; |
18 using base::TimeDelta; | 18 using base::TimeDelta; |
19 using base::TimeTicks; | 19 using base::TimeTicks; |
| 20 using base::TraceTicks; |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 class MockTimeTicks : public TimeTicks { | 24 class MockTimeTicks : public TimeTicks { |
24 public: | 25 public: |
25 static DWORD Ticker() { | 26 static DWORD Ticker() { |
26 return static_cast<int>(InterlockedIncrement(&ticker_)); | 27 return static_cast<int>(InterlockedIncrement(&ticker_)); |
27 } | 28 } |
28 | 29 |
29 static void InstallTicker() { | 30 static void InstallTicker() { |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 typedef TimeTicks (*TestFunc)(); | 179 typedef TimeTicks (*TestFunc)(); |
179 struct TestCase { | 180 struct TestCase { |
180 TestFunc func; | 181 TestFunc func; |
181 const char *description; | 182 const char *description; |
182 }; | 183 }; |
183 // Cheating a bit here: assumes sizeof(TimeTicks) == sizeof(Time) | 184 // Cheating a bit here: assumes sizeof(TimeTicks) == sizeof(Time) |
184 // in order to create a single test case list. | 185 // in order to create a single test case list. |
185 COMPILE_ASSERT(sizeof(TimeTicks) == sizeof(Time), | 186 COMPILE_ASSERT(sizeof(TimeTicks) == sizeof(Time), |
186 test_only_works_with_same_sizes); | 187 test_only_works_with_same_sizes); |
187 TestCase cases[] = { | 188 TestCase cases[] = { |
188 { reinterpret_cast<TestFunc>(Time::Now), "Time::Now" }, | 189 { reinterpret_cast<TestFunc>(&Time::Now), "Time::Now" }, |
189 { TimeTicks::Now, "TimeTicks::Now" }, | 190 { &TimeTicks::Now, "TimeTicks::Now" }, |
190 { TimeTicks::NowFromSystemTraceTime, "TimeTicks::NowFromSystemTraceTime" }, | 191 { reinterpret_cast<TestFunc>(&TraceTicks::Now), "TraceTicks::Now" }, |
191 { NULL, "" } | 192 { NULL, "" } |
192 }; | 193 }; |
193 | 194 |
194 int test_case = 0; | 195 int test_case = 0; |
195 while (cases[test_case].func) { | 196 while (cases[test_case].func) { |
196 TimeTicks start = TimeTicks::Now(); | 197 TimeTicks start = TimeTicks::Now(); |
197 for (int index = 0; index < kLoops; index++) | 198 for (int index = 0; index < kLoops; index++) |
198 cases[test_case].func(); | 199 cases[test_case].func(); |
199 TimeTicks stop = TimeTicks::Now(); | 200 TimeTicks stop = TimeTicks::Now(); |
200 // Turning off the check for acceptible delays. Without this check, | 201 // Turning off the check for acceptible delays. Without this check, |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 const TimeTicks converted_value = TimeTicks::FromQPCValue(ticks); | 259 const TimeTicks converted_value = TimeTicks::FromQPCValue(ticks); |
259 const double converted_microseconds_since_origin = | 260 const double converted_microseconds_since_origin = |
260 static_cast<double>((converted_value - TimeTicks()).InMicroseconds()); | 261 static_cast<double>((converted_value - TimeTicks()).InMicroseconds()); |
261 EXPECT_NEAR(expected_microseconds_since_origin, | 262 EXPECT_NEAR(expected_microseconds_since_origin, |
262 converted_microseconds_since_origin, | 263 converted_microseconds_since_origin, |
263 1.0) | 264 1.0) |
264 << "ticks=" << ticks << ", to be converted via logic path: " | 265 << "ticks=" << ticks << ", to be converted via logic path: " |
265 << (ticks < Time::kQPCOverflowThreshold ? "FAST" : "SAFE"); | 266 << (ticks < Time::kQPCOverflowThreshold ? "FAST" : "SAFE"); |
266 } | 267 } |
267 } | 268 } |
OLD | NEW |