OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // Test of classes in tracked_time.cc | 5 // Test of classes in tracked_time.cc |
6 | 6 |
7 #include "base/profiler/tracked_time.h" | 7 #include "base/profiler/tracked_time.h" |
8 #include "base/time.h" | 8 #include "base/time.h" |
9 #include "base/tracked_objects.h" | 9 #include "base/tracked_objects.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 } | 74 } |
75 | 75 |
76 TEST(TrackedTimeTest, TrackedTimerDisabled) { | 76 TEST(TrackedTimeTest, TrackedTimerDisabled) { |
77 // Check to be sure disabling the collection of data induces a null time | 77 // Check to be sure disabling the collection of data induces a null time |
78 // (which we know will return much faster). | 78 // (which we know will return much faster). |
79 if (!ThreadData::InitializeAndSetTrackingStatus(false)) | 79 if (!ThreadData::InitializeAndSetTrackingStatus(false)) |
80 return; | 80 return; |
81 // Since we disabled tracking, we should get a null response. | 81 // Since we disabled tracking, we should get a null response. |
82 TrackedTime track_now = ThreadData::Now(); | 82 TrackedTime track_now = ThreadData::Now(); |
83 EXPECT_TRUE(track_now.is_null()); | 83 EXPECT_TRUE(track_now.is_null()); |
| 84 track_now = ThreadData::NowForStartOfRun(); |
| 85 EXPECT_TRUE(track_now.is_null()); |
| 86 track_now = ThreadData::NowForEndOfRun(); |
| 87 EXPECT_TRUE(track_now.is_null()); |
84 } | 88 } |
85 | 89 |
86 TEST(TrackedTimeTest, TrackedTimerEnabled) { | 90 TEST(TrackedTimeTest, TrackedTimerEnabled) { |
87 if (!ThreadData::InitializeAndSetTrackingStatus(true)) | 91 if (!ThreadData::InitializeAndSetTrackingStatus(true)) |
88 return; | 92 return; |
89 // Make sure that when we enable tracking, we get a real timer result. | 93 // Make sure that when we enable tracking, we get a real timer result. |
90 | 94 |
91 // First get a 64 bit timer (which should not be null). | 95 // First get a 64 bit timer (which should not be null). |
92 base::TimeTicks ticks_before = base::TimeTicks::Now(); | 96 base::TimeTicks ticks_before = base::TimeTicks::Now(); |
93 EXPECT_FALSE(ticks_before.is_null()); | 97 EXPECT_FALSE(ticks_before.is_null()); |
94 | 98 |
95 // Then get a 32 bit timer that can be null when it wraps. | 99 // Then get a 32 bit timer that can be null when it wraps. |
96 // Crtical difference from the TrackedTimerVsTimeTicks test, is that we use | 100 // Crtical difference from the TrackedTimerVsTimeTicks test, is that we use |
97 // ThreadData::Now(). It can sometimes return the null time. | 101 // ThreadData::Now(). It can sometimes return the null time. |
98 TrackedTime now = ThreadData::Now(); | 102 TrackedTime now = ThreadData::Now(); |
99 | 103 |
100 // Then get a bracketing time. | 104 // Then get a bracketing time. |
101 base::TimeTicks ticks_after = base::TimeTicks::Now(); | 105 base::TimeTicks ticks_after = base::TimeTicks::Now(); |
102 EXPECT_FALSE(ticks_after.is_null()); | 106 EXPECT_FALSE(ticks_after.is_null()); |
103 | 107 |
104 // Now make sure that we bracketed our tracked time nicely. | 108 // Now make sure that we bracketed our tracked time nicely. |
105 Duration before = now - TrackedTime(ticks_before); | 109 Duration before = now - TrackedTime(ticks_before); |
106 EXPECT_LE(0, before.InMilliseconds()); | 110 EXPECT_LE(0, before.InMilliseconds()); |
107 Duration after = now - TrackedTime(ticks_after); | 111 Duration after = now - TrackedTime(ticks_after); |
108 EXPECT_GE(0, after.InMilliseconds()); | 112 EXPECT_GE(0, after.InMilliseconds()); |
109 } | 113 } |
110 | 114 |
111 } // namespace tracked_objects | 115 } // namespace tracked_objects |
OLD | NEW |