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

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

Issue 53923005: Add synthetic delay testing framework (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Renaming and cleanup. Created 7 years, 1 month 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
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/debug/trace_event_synthetic_delay.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 namespace base {
10 namespace debug {
11 namespace {
12
13 const int kTargetDurationMs = 100;
14
15 } // namespace
16
17 class TraceEventSyntheticDelayTest : public testing::Test,
18 public TraceEventSyntheticDelayClock {
19 public:
20 TraceEventSyntheticDelayTest() {}
21
22 // TraceEventSyntheticDelayClock implementation.
23 virtual base::TimeTicks Now() OVERRIDE {
24 AdvanceTime(base::TimeDelta::FromMilliseconds(kTargetDurationMs / 5));
25 return now_;
26 }
27
28 TraceEventSyntheticDelay* ConfigureDelay(const char* name) {
29 TraceEventSyntheticDelay* delay = TraceEventSyntheticDelay::Lookup(name);
30 delay->SetClock(this);
31 delay->SetTargetDuration(
32 base::TimeDelta::FromMilliseconds(kTargetDurationMs));
33 return delay;
34 }
35
36 void AdvanceTime(base::TimeDelta delta) { now_ += delta; }
37
38 int TestFunction() {
39 base::TimeTicks start = Now();
40 { TRACE_EVENT_SYNTHETIC_DELAY("test.Delay"); }
41 return (Now() - start).InMilliseconds();
42 }
43
44 int AsyncTestFunctionActivate() {
45 base::TimeTicks start = Now();
46 { TRACE_EVENT_SYNTHETIC_DELAY_ACTIVATE("test.AsyncDelay"); }
47 return (Now() - start).InMilliseconds();
48 }
49
50 int AsyncTestFunctionApply() {
51 base::TimeTicks start = Now();
52 { TRACE_EVENT_SYNTHETIC_DELAY_APPLY("test.AsyncDelay"); }
53 return (Now() - start).InMilliseconds();
54 }
55
56 private:
57 base::TimeTicks now_;
58
59 DISALLOW_COPY_AND_ASSIGN(TraceEventSyntheticDelayTest);
60 };
61
62 TEST_F(TraceEventSyntheticDelayTest, StaticDelay) {
63 TraceEventSyntheticDelay* delay = ConfigureDelay("test.Delay");
64 delay->SetMode(TraceEventSyntheticDelay::STATIC);
65 EXPECT_GE(TestFunction(), kTargetDurationMs);
66 }
67
68 TEST_F(TraceEventSyntheticDelayTest, OneShotDelay) {
69 TraceEventSyntheticDelay* delay = ConfigureDelay("test.Delay");
70 delay->SetMode(TraceEventSyntheticDelay::ONE_SHOT);
71 EXPECT_GE(TestFunction(), kTargetDurationMs);
72 EXPECT_LT(TestFunction(), kTargetDurationMs);
73
74 delay->SetTargetDuration(
75 base::TimeDelta::FromMilliseconds(kTargetDurationMs));
76 EXPECT_GE(TestFunction(), kTargetDurationMs);
77 }
78
79 TEST_F(TraceEventSyntheticDelayTest, AlternatingDelay) {
80 TraceEventSyntheticDelay* delay = ConfigureDelay("test.Delay");
81 delay->SetMode(TraceEventSyntheticDelay::ALTERNATING);
82 EXPECT_GE(TestFunction(), kTargetDurationMs);
83 EXPECT_LT(TestFunction(), kTargetDurationMs);
brianderson 2013/11/26 02:48:34 EXPECT_EQ(TestFunction(), 0)?
84 EXPECT_GE(TestFunction(), kTargetDurationMs);
85 EXPECT_LT(TestFunction(), kTargetDurationMs);
86 }
87
88 TEST_F(TraceEventSyntheticDelayTest, AsyncDelay) {
89 ConfigureDelay("test.AsyncDelay");
90 EXPECT_LT(AsyncTestFunctionActivate(), kTargetDurationMs);
91 EXPECT_GE(AsyncTestFunctionApply(), kTargetDurationMs / 2);
92 }
93
94 TEST_F(TraceEventSyntheticDelayTest, AsyncDelayExceeded) {
95 ConfigureDelay("test.AsyncDelay");
96 EXPECT_LT(AsyncTestFunctionActivate(), kTargetDurationMs);
97 AdvanceTime(base::TimeDelta::FromMilliseconds(kTargetDurationMs));
98 EXPECT_LT(AsyncTestFunctionApply(), kTargetDurationMs);
99 }
100
101 TEST_F(TraceEventSyntheticDelayTest, AsyncDelayNoActivation) {
102 ConfigureDelay("test.AsyncDelay");
103 EXPECT_LT(AsyncTestFunctionApply(), kTargetDurationMs);
104 }
105
106 TEST_F(TraceEventSyntheticDelayTest, AsyncDelayMultipleActivations) {
107 ConfigureDelay("test.AsyncDelay");
108 EXPECT_LT(AsyncTestFunctionActivate(), kTargetDurationMs);
109 AdvanceTime(base::TimeDelta::FromMilliseconds(kTargetDurationMs));
110 EXPECT_LT(AsyncTestFunctionActivate(), kTargetDurationMs);
111 EXPECT_LT(AsyncTestFunctionApply(), kTargetDurationMs);
112 }
113
114 } // namespace debug
115 } // namespace base
OLDNEW
« base/debug/trace_event_synthetic_delay.h ('K') | « 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