Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(484)

Side by Side Diff: base/debug/trace_event_synthetic_delay_unittest.cc

Issue 104613003: Use Begin/End semantics for synthetic delays (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/debug/trace_event_synthetic_delay.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "base/debug/trace_event_synthetic_delay.h" 5 #include "base/debug/trace_event_synthetic_delay.h"
6 6
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 8
9 namespace base { 9 namespace base {
10 namespace debug { 10 namespace debug {
(...skipping 26 matching lines...) Expand all
37 } 37 }
38 38
39 void AdvanceTime(base::TimeDelta delta) { now_ += delta; } 39 void AdvanceTime(base::TimeDelta delta) { now_ += delta; }
40 40
41 int TestFunction() { 41 int TestFunction() {
42 base::TimeTicks start = Now(); 42 base::TimeTicks start = Now();
43 { TRACE_EVENT_SYNTHETIC_DELAY("test.Delay"); } 43 { TRACE_EVENT_SYNTHETIC_DELAY("test.Delay"); }
44 return (Now() - start).InMilliseconds(); 44 return (Now() - start).InMilliseconds();
45 } 45 }
46 46
47 int AsyncTestFunctionActivate() { 47 int AsyncTestFunctionBegin() {
48 base::TimeTicks start = Now(); 48 base::TimeTicks start = Now();
49 { TRACE_EVENT_SYNTHETIC_DELAY_ACTIVATE("test.AsyncDelay"); } 49 { TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("test.AsyncDelay"); }
50 return (Now() - start).InMilliseconds(); 50 return (Now() - start).InMilliseconds();
51 } 51 }
52 52
53 int AsyncTestFunctionApply() { 53 int AsyncTestFunctionEnd() {
54 base::TimeTicks start = Now(); 54 base::TimeTicks start = Now();
55 { TRACE_EVENT_SYNTHETIC_DELAY_APPLY("test.AsyncDelay"); } 55 { TRACE_EVENT_SYNTHETIC_DELAY_END("test.AsyncDelay"); }
56 return (Now() - start).InMilliseconds(); 56 return (Now() - start).InMilliseconds();
57 } 57 }
58 58
59 private: 59 private:
60 base::TimeTicks now_; 60 base::TimeTicks now_;
61 61
62 DISALLOW_COPY_AND_ASSIGN(TraceEventSyntheticDelayTest); 62 DISALLOW_COPY_AND_ASSIGN(TraceEventSyntheticDelayTest);
63 }; 63 };
64 64
65 TEST_F(TraceEventSyntheticDelayTest, StaticDelay) { 65 TEST_F(TraceEventSyntheticDelayTest, StaticDelay) {
(...skipping 17 matching lines...) Expand all
83 TraceEventSyntheticDelay* delay = ConfigureDelay("test.Delay"); 83 TraceEventSyntheticDelay* delay = ConfigureDelay("test.Delay");
84 delay->SetMode(TraceEventSyntheticDelay::ALTERNATING); 84 delay->SetMode(TraceEventSyntheticDelay::ALTERNATING);
85 EXPECT_GE(TestFunction(), kTargetDurationMs); 85 EXPECT_GE(TestFunction(), kTargetDurationMs);
86 EXPECT_LT(TestFunction(), kShortDurationMs); 86 EXPECT_LT(TestFunction(), kShortDurationMs);
87 EXPECT_GE(TestFunction(), kTargetDurationMs); 87 EXPECT_GE(TestFunction(), kTargetDurationMs);
88 EXPECT_LT(TestFunction(), kShortDurationMs); 88 EXPECT_LT(TestFunction(), kShortDurationMs);
89 } 89 }
90 90
91 TEST_F(TraceEventSyntheticDelayTest, AsyncDelay) { 91 TEST_F(TraceEventSyntheticDelayTest, AsyncDelay) {
92 ConfigureDelay("test.AsyncDelay"); 92 ConfigureDelay("test.AsyncDelay");
93 EXPECT_LT(AsyncTestFunctionActivate(), kShortDurationMs); 93 EXPECT_LT(AsyncTestFunctionBegin(), kShortDurationMs);
94 EXPECT_GE(AsyncTestFunctionApply(), kTargetDurationMs / 2); 94 EXPECT_GE(AsyncTestFunctionEnd(), kTargetDurationMs / 2);
95 } 95 }
96 96
97 TEST_F(TraceEventSyntheticDelayTest, AsyncDelayExceeded) { 97 TEST_F(TraceEventSyntheticDelayTest, AsyncDelayExceeded) {
98 ConfigureDelay("test.AsyncDelay"); 98 ConfigureDelay("test.AsyncDelay");
99 EXPECT_LT(AsyncTestFunctionActivate(), kShortDurationMs); 99 EXPECT_LT(AsyncTestFunctionBegin(), kShortDurationMs);
100 AdvanceTime(base::TimeDelta::FromMilliseconds(kTargetDurationMs)); 100 AdvanceTime(base::TimeDelta::FromMilliseconds(kTargetDurationMs));
101 EXPECT_LT(AsyncTestFunctionApply(), kShortDurationMs); 101 EXPECT_LT(AsyncTestFunctionEnd(), kShortDurationMs);
102 } 102 }
103 103
104 TEST_F(TraceEventSyntheticDelayTest, AsyncDelayNoActivation) { 104 TEST_F(TraceEventSyntheticDelayTest, AsyncDelayNoActivation) {
105 ConfigureDelay("test.AsyncDelay"); 105 ConfigureDelay("test.AsyncDelay");
106 EXPECT_LT(AsyncTestFunctionApply(), kShortDurationMs); 106 EXPECT_LT(AsyncTestFunctionEnd(), kShortDurationMs);
107 } 107 }
108 108
109 TEST_F(TraceEventSyntheticDelayTest, AsyncDelayMultipleActivations) { 109 TEST_F(TraceEventSyntheticDelayTest, AsyncDelayNested) {
110 ConfigureDelay("test.AsyncDelay"); 110 ConfigureDelay("test.AsyncDelay");
111 EXPECT_LT(AsyncTestFunctionActivate(), kShortDurationMs); 111 EXPECT_LT(AsyncTestFunctionBegin(), kShortDurationMs);
112 AdvanceTime(base::TimeDelta::FromMilliseconds(kTargetDurationMs)); 112 EXPECT_LT(AsyncTestFunctionBegin(), kShortDurationMs);
113 EXPECT_LT(AsyncTestFunctionActivate(), kShortDurationMs); 113 EXPECT_LT(AsyncTestFunctionEnd(), kShortDurationMs);
114 EXPECT_LT(AsyncTestFunctionApply(), kShortDurationMs); 114 EXPECT_GE(AsyncTestFunctionEnd(), kTargetDurationMs / 2);
115 }
116
117 TEST_F(TraceEventSyntheticDelayTest, AsyncDelayUnbalanced) {
118 ConfigureDelay("test.AsyncDelay");
119 EXPECT_LT(AsyncTestFunctionBegin(), kShortDurationMs);
120 EXPECT_GE(AsyncTestFunctionEnd(), kTargetDurationMs / 2);
121 EXPECT_LT(AsyncTestFunctionEnd(), kShortDurationMs);
122
123 EXPECT_LT(AsyncTestFunctionBegin(), kShortDurationMs);
124 EXPECT_GE(AsyncTestFunctionEnd(), kTargetDurationMs / 2);
125 }
126
127 TEST_F(TraceEventSyntheticDelayTest, ResetDelays) {
128 ConfigureDelay("test.Delay");
129 ResetTraceEventSyntheticDelays();
130 EXPECT_LT(TestFunction(), kShortDurationMs);
131 }
132
133 TEST_F(TraceEventSyntheticDelayTest, BeginParallel) {
134 TraceEventSyntheticDelay* delay = ConfigureDelay("test.AsyncDelay");
135 base::TimeTicks end_times[2];
136 base::TimeTicks start_time = Now();
137
138 delay->BeginParallel(&end_times[0]);
139 EXPECT_FALSE(end_times[0].is_null());
140
141 delay->BeginParallel(&end_times[1]);
142 EXPECT_FALSE(end_times[1].is_null());
143
144 delay->EndParallel(end_times[0]);
145 EXPECT_GE((Now() - start_time).InMilliseconds(), kTargetDurationMs);
146
147 start_time = Now();
148 delay->EndParallel(end_times[1]);
149 EXPECT_LT((Now() - start_time).InMilliseconds(), kShortDurationMs);
115 } 150 }
116 151
117 } // namespace debug 152 } // namespace debug
118 } // namespace base 153 } // namespace base
OLDNEW
« no previous file with comments | « base/debug/trace_event_synthetic_delay.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698