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" |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 void orderedTestTask(int value, int* result) | 232 void orderedTestTask(int value, int* result) |
233 { | 233 { |
234 *result = (*result << 4) | value; | 234 *result = (*result << 4) | value; |
235 } | 235 } |
236 | 236 |
237 void unorderedTestTask(int value, int* result) | 237 void unorderedTestTask(int value, int* result) |
238 { | 238 { |
239 *result += value; | 239 *result += value; |
240 } | 240 } |
241 | 241 |
242 void idleTestTask(int value, int* result, double allottedTime) | 242 void idleTestTask(bool* taskRun, double expectedDeadline, double deadlineSeconds
) |
243 { | 243 { |
244 *result += value; | 244 EXPECT_EQ(false, *taskRun); |
| 245 EXPECT_EQ(expectedDeadline, deadlineSeconds); |
| 246 *taskRun = true; |
245 } | 247 } |
246 | 248 |
247 TEST_F(SchedulerTest, TestPostTask) | 249 TEST_F(SchedulerTest, TestPostTask) |
248 { | 250 { |
249 int result = 0; | 251 int result = 0; |
250 m_scheduler->postTask(FROM_HERE, WTF::bind(&orderedTestTask, 1, &result)); | 252 m_scheduler->postTask(FROM_HERE, WTF::bind(&orderedTestTask, 1, &result)); |
251 m_scheduler->postTask(FROM_HERE, WTF::bind(&orderedTestTask, 2, &result)); | 253 m_scheduler->postTask(FROM_HERE, WTF::bind(&orderedTestTask, 2, &result)); |
252 m_scheduler->postTask(FROM_HERE, WTF::bind(&orderedTestTask, 3, &result)); | 254 m_scheduler->postTask(FROM_HERE, WTF::bind(&orderedTestTask, 3, &result)); |
253 m_scheduler->postTask(FROM_HERE, WTF::bind(&orderedTestTask, 4, &result)); | 255 m_scheduler->postTask(FROM_HERE, WTF::bind(&orderedTestTask, 4, &result)); |
254 runPendingTasks(); | 256 runPendingTasks(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 | 288 |
287 m_scheduler->stopSharedTimer(); | 289 m_scheduler->stopSharedTimer(); |
288 EXPECT_FALSE(m_platformSupport.sharedTimerRunning()); | 290 EXPECT_FALSE(m_platformSupport.sharedTimerRunning()); |
289 | 291 |
290 m_scheduler->setSharedTimerFiredFunction(nullptr); | 292 m_scheduler->setSharedTimerFiredFunction(nullptr); |
291 EXPECT_FALSE(m_platformSupport.sharedTimerRunning()); | 293 EXPECT_FALSE(m_platformSupport.sharedTimerRunning()); |
292 } | 294 } |
293 | 295 |
294 TEST_F(SchedulerTest, TestIdleTask) | 296 TEST_F(SchedulerTest, TestIdleTask) |
295 { | 297 { |
296 // TODO: Check task allottedTime when implemented in the scheduler. | 298 bool taskRun = false; |
297 int result = 0; | 299 double firstDeadline = 1.1; |
298 m_scheduler->postIdleTask(FROM_HERE, WTF::bind<double>(&idleTestTask, 1, &re
sult)); | 300 double secondDeadline = 2.3; |
299 m_scheduler->postIdleTask(FROM_HERE, WTF::bind<double>(&idleTestTask, 1, &re
sult)); | 301 m_platformSupport.setMonotonicTimeForTest(0.1); |
300 m_scheduler->postIdleTask(FROM_HERE, WTF::bind<double>(&idleTestTask, 1, &re
sult)); | 302 |
301 m_scheduler->postIdleTask(FROM_HERE, WTF::bind<double>(&idleTestTask, 1, &re
sult)); | 303 m_scheduler->postIdleTask(FROM_HERE, WTF::bind<double>(&idleTestTask, &taskR
un, secondDeadline)); |
| 304 |
302 runPendingTasks(); | 305 runPendingTasks(); |
303 EXPECT_EQ(4, result); | 306 EXPECT_FALSE(taskRun); // Shouldn't run yet as no willBeginFrame. |
| 307 |
| 308 m_scheduler->willBeginFrame(firstDeadline); |
| 309 runPendingTasks(); |
| 310 EXPECT_FALSE(taskRun); // Shouldn't run yet as no didCommitFrameToCompositor
. |
| 311 |
| 312 m_platformSupport.setMonotonicTimeForTest(firstDeadline + 0.1); |
| 313 m_scheduler->didCommitFrameToCompositor(); |
| 314 runPendingTasks(); |
| 315 EXPECT_FALSE(taskRun); // We missed the deadline. |
| 316 |
| 317 m_scheduler->willBeginFrame(secondDeadline); |
| 318 m_platformSupport.setMonotonicTimeForTest(secondDeadline - 0.1); |
| 319 m_scheduler->didCommitFrameToCompositor(); |
| 320 runPendingTasks(); |
| 321 EXPECT_TRUE(taskRun); |
304 } | 322 } |
305 | 323 |
306 TEST_F(SchedulerTest, TestTaskPrioritization_normalPolicy) | 324 TEST_F(SchedulerTest, TestTaskPrioritization_normalPolicy) |
307 { | 325 { |
308 m_scheduler->postTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVector, t
his, std::string("L1"))); | 326 m_scheduler->postTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVector, t
his, std::string("L1"))); |
309 m_scheduler->postTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVector, t
his, std::string("L2"))); | 327 m_scheduler->postTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVector, t
his, std::string("L2"))); |
310 m_scheduler->postInputTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVect
or, this, std::string("I1"))); | 328 m_scheduler->postInputTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVect
or, this, std::string("I1"))); |
311 m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&SchedulerTest::appendT
oVector, this, std::string("C1"))); | 329 m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&SchedulerTest::appendT
oVector, this, std::string("C1"))); |
312 m_scheduler->postInputTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVect
or, this, std::string("I2"))); | 330 m_scheduler->postInputTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVect
or, this, std::string("I2"))); |
313 m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&SchedulerTest::appendT
oVector, this, std::string("C2"))); | 331 m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&SchedulerTest::appendT
oVector, this, std::string("C2"))); |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 m_platformSupport.setMonotonicTimeForTest(1000.5); | 516 m_platformSupport.setMonotonicTimeForTest(1000.5); |
499 runPendingTasks(); | 517 runPendingTasks(); |
500 | 518 |
501 ASSERT_FALSE(m_scheduler->shouldYieldForHighPriorityWork()); | 519 ASSERT_FALSE(m_scheduler->shouldYieldForHighPriorityWork()); |
502 m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&dummyTask)); | 520 m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&dummyTask)); |
503 | 521 |
504 EXPECT_FALSE(m_scheduler->shouldYieldForHighPriorityWork()); | 522 EXPECT_FALSE(m_scheduler->shouldYieldForHighPriorityWork()); |
505 } | 523 } |
506 | 524 |
507 } // namespace | 525 } // namespace |
OLD | NEW |