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

Side by Side Diff: components/scheduler/renderer/idle_time_estimator_unittest.cc

Issue 2118903002: scheduler: Move the Blink scheduler into Blink (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 4 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
OLDNEW
(Empty)
1 // Copyright 2015 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 "components/scheduler/renderer/idle_time_estimator.h"
6
7 #include "base/memory/ptr_util.h"
8 #include "base/test/simple_test_tick_clock.h"
9 #include "cc/test/ordered_simple_task_runner.h"
10 #include "components/scheduler/base/task_queue_manager.h"
11 #include "components/scheduler/base/test_task_time_tracker.h"
12 #include "components/scheduler/base/test_time_source.h"
13 #include "components/scheduler/child/scheduler_tqm_delegate_for_test.h"
14 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 namespace scheduler {
18
19 class IdleTimeEstimatorForTest : public IdleTimeEstimator {
20 public:
21 IdleTimeEstimatorForTest(
22 const scoped_refptr<TaskQueue>& compositor_task_runner,
23 TestTimeSource* test_time_source,
24 int sample_count,
25 double estimation_percentile)
26 : IdleTimeEstimator(compositor_task_runner,
27 test_time_source,
28 sample_count,
29 estimation_percentile) {}
30 };
31
32 class IdleTimeEstimatorTest : public testing::Test {
33 public:
34 IdleTimeEstimatorTest()
35 : frame_length_(base::TimeDelta::FromMilliseconds(16)) {}
36
37 ~IdleTimeEstimatorTest() override {}
38
39 void SetUp() override {
40 clock_.reset(new base::SimpleTestTickClock());
41 clock_->Advance(base::TimeDelta::FromMicroseconds(5000));
42 test_time_source_.reset(new TestTimeSource(clock_.get()));
43 mock_task_runner_ = make_scoped_refptr(
44 new cc::OrderedSimpleTaskRunner(clock_.get(), false));
45 main_task_runner_ = SchedulerTqmDelegateForTest::Create(
46 mock_task_runner_, base::MakeUnique<TestTimeSource>(clock_.get()));
47 manager_ = base::MakeUnique<TaskQueueManager>(
48 main_task_runner_, "test.scheduler", "test.scheduler",
49 "test.scheduler.debug");
50 compositor_task_runner_ =
51 manager_->NewTaskQueue(TaskQueue::Spec("compositor_tq"));
52 estimator_.reset(new IdleTimeEstimatorForTest(
53 compositor_task_runner_, test_time_source_.get(), 10, 50));
54 }
55
56 void SimulateFrameWithOneCompositorTask(int compositor_time) {
57 base::TimeDelta non_idle_time =
58 base::TimeDelta::FromMilliseconds(compositor_time);
59 base::PendingTask task(FROM_HERE, base::Closure());
60 estimator_->WillProcessTask(task);
61 clock_->Advance(non_idle_time);
62 estimator_->DidCommitFrameToCompositor();
63 estimator_->DidProcessTask(task);
64 if (non_idle_time < frame_length_)
65 clock_->Advance(frame_length_ - non_idle_time);
66 }
67
68 void SimulateFrameWithTwoCompositorTasks(int compositor_time1,
69 int compositor_time2) {
70 base::TimeDelta non_idle_time1 =
71 base::TimeDelta::FromMilliseconds(compositor_time1);
72 base::TimeDelta non_idle_time2 =
73 base::TimeDelta::FromMilliseconds(compositor_time2);
74 base::PendingTask task(FROM_HERE, base::Closure());
75 estimator_->WillProcessTask(task);
76 clock_->Advance(non_idle_time1);
77 estimator_->DidProcessTask(task);
78
79 estimator_->WillProcessTask(task);
80 clock_->Advance(non_idle_time2);
81 estimator_->DidCommitFrameToCompositor();
82 estimator_->DidProcessTask(task);
83
84 base::TimeDelta idle_time = frame_length_ - non_idle_time1 - non_idle_time2;
85 clock_->Advance(idle_time);
86 }
87
88 std::unique_ptr<base::SimpleTestTickClock> clock_;
89 std::unique_ptr<TestTimeSource> test_time_source_;
90 scoped_refptr<cc::OrderedSimpleTaskRunner> mock_task_runner_;
91 scoped_refptr<SchedulerTqmDelegate> main_task_runner_;
92 std::unique_ptr<TaskQueueManager> manager_;
93 scoped_refptr<TaskQueue> compositor_task_runner_;
94 std::unique_ptr<IdleTimeEstimatorForTest> estimator_;
95 const base::TimeDelta frame_length_;
96 TestTaskTimeTracker test_task_time_tracker_;
97 };
98
99 TEST_F(IdleTimeEstimatorTest, InitialTimeEstimateWithNoData) {
100 EXPECT_EQ(frame_length_, estimator_->GetExpectedIdleDuration(frame_length_));
101 }
102
103 TEST_F(IdleTimeEstimatorTest, BasicEstimation_SteadyState) {
104 SimulateFrameWithOneCompositorTask(5);
105 SimulateFrameWithOneCompositorTask(5);
106
107 EXPECT_EQ(base::TimeDelta::FromMilliseconds(11),
108 estimator_->GetExpectedIdleDuration(frame_length_));
109 }
110
111 TEST_F(IdleTimeEstimatorTest, BasicEstimation_Variable) {
112 SimulateFrameWithOneCompositorTask(5);
113 SimulateFrameWithOneCompositorTask(6);
114 SimulateFrameWithOneCompositorTask(7);
115 SimulateFrameWithOneCompositorTask(7);
116 SimulateFrameWithOneCompositorTask(7);
117 SimulateFrameWithOneCompositorTask(8);
118
119 // We expect it to return the median.
120 EXPECT_EQ(base::TimeDelta::FromMilliseconds(9),
121 estimator_->GetExpectedIdleDuration(frame_length_));
122 }
123
124 TEST_F(IdleTimeEstimatorTest, NoIdleTime) {
125 SimulateFrameWithOneCompositorTask(100);
126 SimulateFrameWithOneCompositorTask(100);
127
128 EXPECT_EQ(base::TimeDelta::FromMilliseconds(0),
129 estimator_->GetExpectedIdleDuration(frame_length_));
130 }
131
132 TEST_F(IdleTimeEstimatorTest, Clear) {
133 SimulateFrameWithOneCompositorTask(5);
134 SimulateFrameWithOneCompositorTask(5);
135
136 EXPECT_EQ(base::TimeDelta::FromMilliseconds(11),
137 estimator_->GetExpectedIdleDuration(frame_length_));
138 estimator_->Clear();
139
140 EXPECT_EQ(frame_length_, estimator_->GetExpectedIdleDuration(frame_length_));
141 }
142
143 TEST_F(IdleTimeEstimatorTest, Estimation_MultipleTasks) {
144 SimulateFrameWithTwoCompositorTasks(1, 4);
145 SimulateFrameWithTwoCompositorTasks(1, 4);
146
147 EXPECT_EQ(base::TimeDelta::FromMilliseconds(11),
148 estimator_->GetExpectedIdleDuration(frame_length_));
149 }
150
151 TEST_F(IdleTimeEstimatorTest, IgnoresNestedTasks) {
152 SimulateFrameWithOneCompositorTask(5);
153 SimulateFrameWithOneCompositorTask(5);
154
155 base::PendingTask task(FROM_HERE, base::Closure());
156 estimator_->WillProcessTask(task);
157 SimulateFrameWithTwoCompositorTasks(4, 4);
158 SimulateFrameWithTwoCompositorTasks(4, 4);
159 SimulateFrameWithTwoCompositorTasks(4, 4);
160 SimulateFrameWithTwoCompositorTasks(4, 4);
161 estimator_->DidCommitFrameToCompositor();
162 estimator_->DidProcessTask(task);
163
164 EXPECT_EQ(base::TimeDelta::FromMilliseconds(11),
165 estimator_->GetExpectedIdleDuration(frame_length_));
166 }
167
168
169 } // namespace scheduler
OLDNEW
« no previous file with comments | « components/scheduler/renderer/idle_time_estimator.cc ('k') | components/scheduler/renderer/render_widget_scheduling_state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698