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 <gmock/gmock.h> |
14 #include <gtest/gtest.h> | 14 #include <gtest/gtest.h> |
15 #include <string> | 15 #include <string> |
16 #include <vector> | 16 #include <vector> |
17 | 17 |
18 using blink::Scheduler; | 18 using blink::Scheduler; |
19 using namespace std; | |
20 | 19 |
21 namespace { | 20 namespace { |
22 | 21 |
23 class TestMainThread : public blink::WebThread { | 22 class TestMainThread : public blink::WebThread { |
24 public: | 23 public: |
25 // blink::WebThread implementation. | 24 // blink::WebThread implementation. |
26 virtual void postTask(Task* task) OVERRIDE | 25 virtual void postTask(Task* task) OVERRIDE |
27 { | 26 { |
28 m_pendingTasks.append(adoptPtr(task)); | 27 m_pendingTasks.append(adoptPtr(task)); |
29 } | 28 } |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 ~SchedulerTest() | 129 ~SchedulerTest() |
131 { | 130 { |
132 Scheduler::shutdown(); | 131 Scheduler::shutdown(); |
133 } | 132 } |
134 | 133 |
135 void runPendingTasks() | 134 void runPendingTasks() |
136 { | 135 { |
137 m_platformSupport.runPendingTasks(); | 136 m_platformSupport.runPendingTasks(); |
138 } | 137 } |
139 | 138 |
140 void appendToVector(string value) | 139 void appendToVector(std::string value) |
141 { | 140 { |
142 m_order.push_back(value); | 141 m_order.push_back(value); |
143 } | 142 } |
144 | 143 |
145 void appendToVectorReentrantTask() | 144 void appendToVectorReentrantTask() |
146 { | 145 { |
147 m_reentrantOrder.push_back(m_reentrantCount++); | 146 m_reentrantOrder.push_back(m_reentrantCount++); |
148 | 147 |
149 if (m_reentrantCount > m_maxRecursion) | 148 if (m_reentrantCount > m_maxRecursion) |
150 return; | 149 return; |
(...skipping 14 matching lines...) Expand all Loading... |
165 m_reentrantOrder.push_back(m_reentrantCount++); | 164 m_reentrantOrder.push_back(m_reentrantCount++); |
166 | 165 |
167 if (m_reentrantCount > m_maxRecursion) | 166 if (m_reentrantCount > m_maxRecursion) |
168 return; | 167 return; |
169 m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&SchedulerTest::app
endToVectorReentrantCompositorTask, this)); | 168 m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&SchedulerTest::app
endToVectorReentrantCompositorTask, this)); |
170 } | 169 } |
171 | 170 |
172 protected: | 171 protected: |
173 SchedulerTestingPlatformSupport m_platformSupport; | 172 SchedulerTestingPlatformSupport m_platformSupport; |
174 Scheduler* m_scheduler; | 173 Scheduler* m_scheduler; |
175 std::vector<string> m_order; | 174 std::vector<std::string> m_order; |
176 std::vector<int> m_reentrantOrder; | 175 std::vector<int> m_reentrantOrder; |
177 int m_reentrantCount; | 176 int m_reentrantCount; |
178 int m_maxRecursion; | 177 int m_maxRecursion; |
179 }; | 178 }; |
180 | 179 |
181 void orderedTestTask(int value, int* result) | 180 void orderedTestTask(int value, int* result) |
182 { | 181 { |
183 *result = (*result << 4) | value; | 182 *result = (*result << 4) | value; |
184 } | 183 } |
185 | 184 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 m_scheduler->postIdleTask(FROM_HERE, WTF::bind<double>(&idleTestTask, 1, &re
sult)); | 245 m_scheduler->postIdleTask(FROM_HERE, WTF::bind<double>(&idleTestTask, 1, &re
sult)); |
247 m_scheduler->postIdleTask(FROM_HERE, WTF::bind<double>(&idleTestTask, 1, &re
sult)); | 246 m_scheduler->postIdleTask(FROM_HERE, WTF::bind<double>(&idleTestTask, 1, &re
sult)); |
248 m_scheduler->postIdleTask(FROM_HERE, WTF::bind<double>(&idleTestTask, 1, &re
sult)); | 247 m_scheduler->postIdleTask(FROM_HERE, WTF::bind<double>(&idleTestTask, 1, &re
sult)); |
249 m_scheduler->postIdleTask(FROM_HERE, WTF::bind<double>(&idleTestTask, 1, &re
sult)); | 248 m_scheduler->postIdleTask(FROM_HERE, WTF::bind<double>(&idleTestTask, 1, &re
sult)); |
250 runPendingTasks(); | 249 runPendingTasks(); |
251 EXPECT_EQ(4, result); | 250 EXPECT_EQ(4, result); |
252 } | 251 } |
253 | 252 |
254 TEST_F(SchedulerTest, TestTaskPrioritization) | 253 TEST_F(SchedulerTest, TestTaskPrioritization) |
255 { | 254 { |
256 m_scheduler->postTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVector, t
his, string("L1"))); | 255 m_scheduler->postTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVector, t
his, std::string("L1"))); |
257 m_scheduler->postTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVector, t
his, string("L2"))); | 256 m_scheduler->postTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVector, t
his, std::string("L2"))); |
258 m_scheduler->postInputTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVect
or, this, string("I1"))); | 257 m_scheduler->postInputTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVect
or, this, std::string("I1"))); |
259 m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&SchedulerTest::appendT
oVector, this, string("C1"))); | 258 m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&SchedulerTest::appendT
oVector, this, std::string("C1"))); |
260 m_scheduler->postInputTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVect
or, this, string("I2"))); | 259 m_scheduler->postInputTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVect
or, this, std::string("I2"))); |
261 m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&SchedulerTest::appendT
oVector, this, string("C2"))); | 260 m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&SchedulerTest::appendT
oVector, this, std::string("C2"))); |
262 | 261 |
263 runPendingTasks(); | 262 runPendingTasks(); |
264 EXPECT_THAT(m_order, testing::ElementsAre( | 263 EXPECT_THAT(m_order, testing::ElementsAre( |
265 string("I1"), string("C1"), string("I2"), string("C2"), string("L1"), st
ring("L2"))); | 264 std::string("I1"), std::string("C1"), std::string("I2"), std::string("C2
"), std::string("L1"), std::string("L2"))); |
266 } | 265 } |
267 | 266 |
268 TEST_F(SchedulerTest, TestRentrantTask) | 267 TEST_F(SchedulerTest, TestRentrantTask) |
269 { | 268 { |
270 m_scheduler->postTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVectorRee
ntrantTask, this)); | 269 m_scheduler->postTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVectorRee
ntrantTask, this)); |
271 runPendingTasks(); | 270 runPendingTasks(); |
272 | 271 |
273 EXPECT_THAT(m_reentrantOrder, testing::ElementsAre(0, 1, 2, 3, 4)); | 272 EXPECT_THAT(m_reentrantOrder, testing::ElementsAre(0, 1, 2, 3, 4)); |
274 } | 273 } |
275 | 274 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 { | 321 { |
323 s_shouldContinue = true; | 322 s_shouldContinue = true; |
324 m_scheduler->postInputTask(FROM_HERE, WTF::bind(&reentrantCompositorTask, m_
scheduler)); | 323 m_scheduler->postInputTask(FROM_HERE, WTF::bind(&reentrantCompositorTask, m_
scheduler)); |
325 m_scheduler->postTask(FROM_HERE, WTF::bind(&stopReentrantTask)); | 324 m_scheduler->postTask(FROM_HERE, WTF::bind(&stopReentrantTask)); |
326 | 325 |
327 // If starvation occurs then this will never exit. | 326 // If starvation occurs then this will never exit. |
328 runPendingTasks(); | 327 runPendingTasks(); |
329 } | 328 } |
330 | 329 |
331 } // namespace | 330 } // namespace |
OLD | NEW |