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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 // Now make sure that we bracketed our tracked time nicely. | 63 // Now make sure that we bracketed our tracked time nicely. |
64 Duration before = now - TrackedTime(ticks_before); | 64 Duration before = now - TrackedTime(ticks_before); |
65 EXPECT_LE(0, before.InMilliseconds()); | 65 EXPECT_LE(0, before.InMilliseconds()); |
66 Duration after = now - TrackedTime(ticks_after); | 66 Duration after = now - TrackedTime(ticks_after); |
67 EXPECT_GE(0, after.InMilliseconds()); | 67 EXPECT_GE(0, after.InMilliseconds()); |
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 ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED); |
74 return; | |
75 // Since we disabled tracking, we should get a null response. | 74 // Since we disabled tracking, we should get a null response. |
76 TrackedTime track_now = ThreadData::Now(); | 75 TrackedTime track_now = ThreadData::Now(); |
77 EXPECT_TRUE(track_now.is_null()); | 76 EXPECT_TRUE(track_now.is_null()); |
78 } | 77 } |
79 | 78 |
80 TEST(TrackedTimeTest, TrackedTimerEnabled) { | 79 TEST(TrackedTimeTest, TrackedTimerEnabled) { |
81 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::PROFILING_ACTIVE)) | 80 ThreadData::InitializeAndSetTrackingStatus(ThreadData::PROFILING_ACTIVE); |
82 return; | |
83 // Make sure that when we enable tracking, we get a real timer result. | 81 // Make sure that when we enable tracking, we get a real timer result. |
84 | 82 |
85 // First get a 64 bit timer (which should not be null). | 83 // First get a 64 bit timer (which should not be null). |
86 base::TimeTicks ticks_before = base::TimeTicks::Now(); | 84 base::TimeTicks ticks_before = base::TimeTicks::Now(); |
87 EXPECT_FALSE(ticks_before.is_null()); | 85 EXPECT_FALSE(ticks_before.is_null()); |
88 | 86 |
89 // Then get a 32 bit timer that can be null when it wraps. | 87 // Then get a 32 bit timer that can be null when it wraps. |
90 // Crtical difference from the TrackedTimerVsTimeTicks test, is that we use | 88 // Crtical difference from the TrackedTimerVsTimeTicks test, is that we use |
91 // ThreadData::Now(). It can sometimes return the null time. | 89 // ThreadData::Now(). It can sometimes return the null time. |
92 TrackedTime now = ThreadData::Now(); | 90 TrackedTime now = ThreadData::Now(); |
93 | 91 |
94 // Then get a bracketing time. | 92 // Then get a bracketing time. |
95 base::TimeTicks ticks_after = base::TimeTicks::Now(); | 93 base::TimeTicks ticks_after = base::TimeTicks::Now(); |
96 EXPECT_FALSE(ticks_after.is_null()); | 94 EXPECT_FALSE(ticks_after.is_null()); |
97 | 95 |
98 // Now make sure that we bracketed our tracked time nicely. | 96 // Now make sure that we bracketed our tracked time nicely. |
99 Duration before = now - TrackedTime(ticks_before); | 97 Duration before = now - TrackedTime(ticks_before); |
100 EXPECT_LE(0, before.InMilliseconds()); | 98 EXPECT_LE(0, before.InMilliseconds()); |
101 Duration after = now - TrackedTime(ticks_after); | 99 Duration after = now - TrackedTime(ticks_after); |
102 EXPECT_GE(0, after.InMilliseconds()); | 100 EXPECT_GE(0, after.InMilliseconds()); |
103 } | 101 } |
104 | 102 |
105 } // namespace tracked_objects | 103 } // namespace tracked_objects |
OLD | NEW |