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 // 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/time.h" | 8 #include "base/time/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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 } | 68 } |
69 | 69 |
70 TEST(TrackedTimeTest, TrackedTimerDisabled) { | 70 TEST(TrackedTimeTest, TrackedTimerDisabled) { |
71 // Check to be sure disabling the collection of data induces a null time | 71 // Check to be sure disabling the collection of data induces a null time |
72 // (which we know will return much faster). | 72 // (which we know will return much faster). |
73 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) | 73 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) |
74 return; | 74 return; |
75 // Since we disabled tracking, we should get a null response. | 75 // Since we disabled tracking, we should get a null response. |
76 TrackedTime track_now = ThreadData::Now(); | 76 TrackedTime track_now = ThreadData::Now(); |
77 EXPECT_TRUE(track_now.is_null()); | 77 EXPECT_TRUE(track_now.is_null()); |
78 track_now = ThreadData::NowForStartOfRun(NULL); | |
79 EXPECT_TRUE(track_now.is_null()); | |
80 track_now = ThreadData::NowForEndOfRun(); | |
81 EXPECT_TRUE(track_now.is_null()); | |
82 } | 78 } |
83 | 79 |
84 TEST(TrackedTimeTest, TrackedTimerEnabled) { | 80 TEST(TrackedTimeTest, TrackedTimerEnabled) { |
85 if (!ThreadData::InitializeAndSetTrackingStatus( | 81 if (!ThreadData::InitializeAndSetTrackingStatus( |
86 ThreadData::PROFILING_CHILDREN_ACTIVE)) | 82 ThreadData::PROFILING_CHILDREN_ACTIVE)) |
87 return; | 83 return; |
88 // Make sure that when we enable tracking, we get a real timer result. | 84 // Make sure that when we enable tracking, we get a real timer result. |
89 | 85 |
90 // First get a 64 bit timer (which should not be null). | 86 // First get a 64 bit timer (which should not be null). |
91 base::TimeTicks ticks_before = base::TimeTicks::Now(); | 87 base::TimeTicks ticks_before = base::TimeTicks::Now(); |
92 EXPECT_FALSE(ticks_before.is_null()); | 88 EXPECT_FALSE(ticks_before.is_null()); |
93 | 89 |
94 // Then get a 32 bit timer that can be null when it wraps. | 90 // Then get a 32 bit timer that can be null when it wraps. |
95 // Crtical difference from the TrackedTimerVsTimeTicks test, is that we use | 91 // Crtical difference from the TrackedTimerVsTimeTicks test, is that we use |
96 // ThreadData::Now(). It can sometimes return the null time. | 92 // ThreadData::Now(). It can sometimes return the null time. |
97 TrackedTime now = ThreadData::Now(); | 93 TrackedTime now = ThreadData::Now(); |
98 | 94 |
99 // Then get a bracketing time. | 95 // Then get a bracketing time. |
100 base::TimeTicks ticks_after = base::TimeTicks::Now(); | 96 base::TimeTicks ticks_after = base::TimeTicks::Now(); |
101 EXPECT_FALSE(ticks_after.is_null()); | 97 EXPECT_FALSE(ticks_after.is_null()); |
102 | 98 |
103 // Now make sure that we bracketed our tracked time nicely. | 99 // Now make sure that we bracketed our tracked time nicely. |
104 Duration before = now - TrackedTime(ticks_before); | 100 Duration before = now - TrackedTime(ticks_before); |
105 EXPECT_LE(0, before.InMilliseconds()); | 101 EXPECT_LE(0, before.InMilliseconds()); |
106 Duration after = now - TrackedTime(ticks_after); | 102 Duration after = now - TrackedTime(ticks_after); |
107 EXPECT_GE(0, after.InMilliseconds()); | 103 EXPECT_GE(0, after.InMilliseconds()); |
108 } | 104 } |
109 | 105 |
110 } // namespace tracked_objects | 106 } // namespace tracked_objects |
OLD | NEW |