OLD | NEW |
---|---|
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 "config.h" | 5 #include "config.h" |
6 #include "platform/scheduler/Scheduler.h" | 6 #include "platform/scheduler/Scheduler.h" |
7 | 7 |
8 #include "platform/TestingPlatformSupport.h" | 8 #include "platform/TestingPlatformSupport.h" |
9 #include "platform/TraceLocation.h" | 9 #include "platform/TraceLocation.h" |
10 #include "public/platform/Platform.h" | 10 #include "public/platform/Platform.h" |
11 #include "public/platform/WebThread.h" | 11 #include "public/platform/WebThread.h" |
12 | 12 |
13 #include <gmock/gmock.h> | |
13 #include <gtest/gtest.h> | 14 #include <gtest/gtest.h> |
15 #include <string> | |
16 #include <vector> | |
14 | 17 |
15 using blink::Scheduler; | 18 using blink::Scheduler; |
19 using namespace std; | |
16 | 20 |
17 namespace { | 21 namespace { |
18 | 22 |
19 class TestMainThread : public blink::WebThread { | 23 class TestMainThread : public blink::WebThread { |
20 public: | 24 public: |
21 // blink::WebThread implementation. | 25 // blink::WebThread implementation. |
22 virtual void postTask(Task* task) OVERRIDE | 26 virtual void postTask(Task* task) OVERRIDE |
23 { | 27 { |
24 m_pendingTasks.append(adoptPtr(task)); | 28 m_pendingTasks.append(adoptPtr(task)); |
25 } | 29 } |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
124 ~SchedulerTest() | 128 ~SchedulerTest() |
125 { | 129 { |
126 Scheduler::shutdown(); | 130 Scheduler::shutdown(); |
127 } | 131 } |
128 | 132 |
129 void runPendingTasks() | 133 void runPendingTasks() |
130 { | 134 { |
131 m_platformSupport.runPendingTasks(); | 135 m_platformSupport.runPendingTasks(); |
132 } | 136 } |
133 | 137 |
138 void appendToVector(string value) | |
139 { | |
140 m_order.push_back(value); | |
141 } | |
142 | |
143 void appendToVectorReentrant(int count) | |
144 { | |
145 m_reentrantOrder.push_back(count); | |
146 | |
147 if (count < 4) | |
148 m_scheduler->postTask(FROM_HERE, bind(&SchedulerTest::appendToVector Reentrant, this, count + 1)); | |
149 } | |
150 | |
134 protected: | 151 protected: |
135 SchedulerTestingPlatformSupport m_platformSupport; | 152 SchedulerTestingPlatformSupport m_platformSupport; |
136 Scheduler* m_scheduler; | 153 Scheduler* m_scheduler; |
154 std::vector<string> m_order; | |
155 std::vector<int> m_reentrantOrder; | |
137 }; | 156 }; |
138 | 157 |
139 void orderedTestTask(int value, int* result) | 158 void orderedTestTask(int value, int* result) |
140 { | 159 { |
141 *result = (*result << 4) | value; | 160 *result = (*result << 4) | value; |
142 } | 161 } |
143 | 162 |
144 void unorderedTestTask(int value, int* result) | 163 void unorderedTestTask(int value, int* result) |
145 { | 164 { |
146 *result += value; | 165 *result += value; |
(...skipping 19 matching lines...) Expand all Loading... | |
166 { | 185 { |
167 int result = 0; | 186 int result = 0; |
168 m_scheduler->postTask(FROM_HERE, bind(&unorderedTestTask, 1, &result)); | 187 m_scheduler->postTask(FROM_HERE, bind(&unorderedTestTask, 1, &result)); |
169 m_scheduler->postInputTask(FROM_HERE, bind(&unorderedTestTask, 2, &result)); | 188 m_scheduler->postInputTask(FROM_HERE, bind(&unorderedTestTask, 2, &result)); |
170 m_scheduler->postCompositorTask(FROM_HERE, bind(&unorderedTestTask, 4, &resu lt)); | 189 m_scheduler->postCompositorTask(FROM_HERE, bind(&unorderedTestTask, 4, &resu lt)); |
171 m_scheduler->postTask(FROM_HERE, bind(&unorderedTestTask, 8, &result)); | 190 m_scheduler->postTask(FROM_HERE, bind(&unorderedTestTask, 8, &result)); |
172 runPendingTasks(); | 191 runPendingTasks(); |
173 EXPECT_EQ(15, result); | 192 EXPECT_EQ(15, result); |
174 } | 193 } |
175 | 194 |
195 TEST_F(SchedulerTest, TestTasksExecutedOnShutdown) | |
196 { | |
197 int result = 0; | |
198 m_scheduler->postTask(FROM_HERE, bind(&unorderedTestTask, 1, &result)); | |
199 m_scheduler->postInputTask(FROM_HERE, bind(&unorderedTestTask, 2, &result)); | |
200 m_scheduler->postCompositorTask(FROM_HERE, bind(&unorderedTestTask, 4, &resu lt)); | |
201 m_scheduler->postTask(FROM_HERE, bind(&unorderedTestTask, 8, &result)); | |
202 Scheduler::shutdown(); | |
Sami
2014/08/07 15:51:27
Thanks for adding this test. Can you add a re-entr
alexclarke
2014/08/07 16:01:30
Done.
| |
203 EXPECT_EQ(15, result); | |
204 } | |
205 | |
176 int s_sharedTimerTickCount; | 206 int s_sharedTimerTickCount; |
177 void sharedTimerFunction() | 207 void sharedTimerFunction() |
178 { | 208 { |
179 s_sharedTimerTickCount++; | 209 s_sharedTimerTickCount++; |
180 } | 210 } |
181 | 211 |
182 TEST_F(SchedulerTest, TestSharedTimer) | 212 TEST_F(SchedulerTest, TestSharedTimer) |
183 { | 213 { |
184 s_sharedTimerTickCount = 0; | 214 s_sharedTimerTickCount = 0; |
185 m_scheduler->setSharedTimerFiredFunction(&sharedTimerFunction); | 215 m_scheduler->setSharedTimerFiredFunction(&sharedTimerFunction); |
(...skipping 16 matching lines...) Expand all Loading... | |
202 // TODO: Check task allottedTime when implemented in the scheduler. | 232 // TODO: Check task allottedTime when implemented in the scheduler. |
203 int result = 0; | 233 int result = 0; |
204 m_scheduler->postIdleTask(bind<double>(&idleTestTask, 1, &result)); | 234 m_scheduler->postIdleTask(bind<double>(&idleTestTask, 1, &result)); |
205 m_scheduler->postIdleTask(bind<double>(&idleTestTask, 1, &result)); | 235 m_scheduler->postIdleTask(bind<double>(&idleTestTask, 1, &result)); |
206 m_scheduler->postIdleTask(bind<double>(&idleTestTask, 1, &result)); | 236 m_scheduler->postIdleTask(bind<double>(&idleTestTask, 1, &result)); |
207 m_scheduler->postIdleTask(bind<double>(&idleTestTask, 1, &result)); | 237 m_scheduler->postIdleTask(bind<double>(&idleTestTask, 1, &result)); |
208 runPendingTasks(); | 238 runPendingTasks(); |
209 EXPECT_EQ(4, result); | 239 EXPECT_EQ(4, result); |
210 } | 240 } |
211 | 241 |
242 TEST_F(SchedulerTest, TestTaskPrioritization) | |
243 { | |
244 m_scheduler->postTask(FROM_HERE, bind(&SchedulerTest::appendToVector, this, string("L1"))); | |
245 m_scheduler->postTask(FROM_HERE, bind(&SchedulerTest::appendToVector, this, string("L2"))); | |
246 m_scheduler->postInputTask(FROM_HERE, bind(&SchedulerTest::appendToVector, t his, string("I1"))); | |
247 m_scheduler->postInputTask(FROM_HERE, bind(&SchedulerTest::appendToVector, t his, string("I2"))); | |
248 m_scheduler->postCompositorTask(FROM_HERE, bind(&SchedulerTest::appendToVect or, this, string("C1"))); | |
249 m_scheduler->postCompositorTask(FROM_HERE, bind(&SchedulerTest::appendToVect or, this, string("C2"))); | |
250 | |
251 runPendingTasks(); | |
252 EXPECT_THAT(m_order, testing::ElementsAre( | |
253 string("I1"), string("I2"), string("C1"), string("C2"), string("L1"), st ring("L2"))); | |
254 } | |
255 | |
256 TEST_F(SchedulerTest, TestRentrantTask) | |
257 { | |
258 m_scheduler->postTask(FROM_HERE, bind(&SchedulerTest::appendToVectorReentran t, this, 0)); | |
259 runPendingTasks(); | |
260 | |
261 EXPECT_THAT(m_reentrantOrder, testing::ElementsAre(0, 1, 2, 3, 4)); | |
262 } | |
263 | |
264 | |
212 } // namespace | 265 } // namespace |
OLD | NEW |