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

Side by Side Diff: Source/platform/scheduler/SchedulerTest.cpp

Issue 621363002: scheduler: Post high priority tasks directly to the message loop (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Tests. Created 6 years, 2 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 | Annotate | Revision Log
OLDNEW
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 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 m_scheduler->postInputTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVect or, this, std::string("I2"))); 312 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"))); 313 m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&SchedulerTest::appendT oVector, this, std::string("C2")));
314 m_scheduler->postIpcTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVector , this, std::string("IPC"))); 314 m_scheduler->postIpcTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVector , this, std::string("IPC")));
315 315
316 runPendingTasks(); 316 runPendingTasks();
317 EXPECT_THAT(m_order, testing::ElementsAre( 317 EXPECT_THAT(m_order, testing::ElementsAre(
318 std::string("L1"), std::string("L2"), std::string("I1"), std::string("C1 "), std::string("I2"), std::string("C2"), 318 std::string("L1"), std::string("L2"), std::string("I1"), std::string("C1 "), std::string("I2"), std::string("C2"),
319 std::string("IPC"))); 319 std::string("IPC")));
320 } 320 }
321 321
322 TEST_F(SchedulerTest, TestTaskPrioritization_compositorPriorityPolicy)
323 {
324 m_scheduler->enterSchedulerPolicy(SchedulerForTest::CompositorPriority);
325 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("L2")));
327 m_scheduler->postInputTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVect or, this, std::string("I1")));
328 m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&SchedulerTest::appendT oVector, this, std::string("C1")));
329 m_scheduler->postInputTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVect or, this, std::string("I2")));
330 m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&SchedulerTest::appendT oVector, this, std::string("C2")));
331 m_scheduler->postIpcTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVector , this, std::string("IPC")));
332
333 runPendingTasks();
334 EXPECT_THAT(m_order, testing::ElementsAre(
335 std::string("I1"), std::string("C1"), std::string("I2"), std::string("C2 "), std::string("L1"), std::string("L2"),
336 std::string("IPC")));
337 }
338
339 TEST_F(SchedulerTest, TestRentrantTask) 322 TEST_F(SchedulerTest, TestRentrantTask)
340 { 323 {
341 m_scheduler->postTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVectorRee ntrantTask, this)); 324 m_scheduler->postTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVectorRee ntrantTask, this));
342 runPendingTasks(); 325 runPendingTasks();
343 326
344 EXPECT_THAT(m_reentrantOrder, testing::ElementsAre(0, 1, 2, 3, 4)); 327 EXPECT_THAT(m_reentrantOrder, testing::ElementsAre(0, 1, 2, 3, 4));
345 } 328 }
346 329
330 TEST_F(SchedulerTest, TestTasksRunAfterShutdown)
331 {
332 m_scheduler->postTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVector, t his, std::string("1")));
333 m_scheduler->postInputTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVect or, this, std::string("2")));
334 m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&SchedulerTest::appendT oVector, this, std::string("3")));
335 m_scheduler->postIpcTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVector , this, std::string("4")));
347 336
348 TEST_F(SchedulerTest, TestRentrantInputTaskDuringShutdown)
349 {
350 m_scheduler->postInputTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVect orReentrantInputTask, this));
351 Scheduler::shutdown(); 337 Scheduler::shutdown();
alexclarke 2014/10/06 14:11:03 Might be worth adding something between shutdown a
Sami 2014/10/06 14:59:18 Done.
352 338 runPendingTasks();
353 EXPECT_THAT(m_reentrantOrder, testing::ElementsAre(0, 1, 2, 3, 4)); 339 EXPECT_THAT(m_order, testing::ElementsAre(
354 } 340 std::string("1"), std::string("2"), std::string("3"), std::string("4"))) ;
355
356 TEST_F(SchedulerTest, TestRentrantCompositorTaskDuringShutdown)
357 {
358 m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&SchedulerTest::appendT oVectorReentrantCompositorTask, this));
359 Scheduler::shutdown();
360
361 EXPECT_THAT(m_reentrantOrder, testing::ElementsAre(0, 1, 2, 3, 4));
362 } 341 }
363 342
364 bool s_shouldContinue; 343 bool s_shouldContinue;
365 void reentrantInputTask(Scheduler* scheduler) 344 void reentrantInputTask(Scheduler* scheduler)
366 { 345 {
367 if (s_shouldContinue) 346 if (s_shouldContinue)
368 scheduler->postInputTask(FROM_HERE, WTF::bind(&reentrantInputTask, sched uler)); 347 scheduler->postInputTask(FROM_HERE, WTF::bind(&reentrantInputTask, sched uler));
369 } 348 }
370 349
371 void reentrantCompositorTask(Scheduler* scheduler) 350 void reentrantCompositorTask(Scheduler* scheduler)
(...skipping 26 matching lines...) Expand all
398 // If starvation occurs then this will never exit. 377 // If starvation occurs then this will never exit.
399 runPendingTasks(); 378 runPendingTasks();
400 } 379 }
401 380
402 int s_dummyTaskCount; 381 int s_dummyTaskCount;
403 void dummyTask() 382 void dummyTask()
404 { 383 {
405 s_dummyTaskCount++; 384 s_dummyTaskCount++;
406 } 385 }
407 386
408 TEST_F(SchedulerTest, TestMultipleCallsToPostInputOrCompositorTaskResultsInOnlyO neMainThreadTask)
409 {
410 EXPECT_EQ(0U, m_platformSupport.numPendingMainThreadTasks());
411
412 for (int i = 0; i < 10; i++) {
413 m_scheduler->postInputTask(FROM_HERE, WTF::bind(&dummyTask));
414 m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&dummyTask));
415 }
416
417 EXPECT_EQ(1U, m_platformSupport.numPendingMainThreadTasks());
418 }
419
420 TEST_F(SchedulerTest, TestMainThreadTaskLifeCycle) 387 TEST_F(SchedulerTest, TestMainThreadTaskLifeCycle)
421 { 388 {
422 EXPECT_EQ(0U, m_platformSupport.numPendingMainThreadTasks()); 389 EXPECT_EQ(0U, m_platformSupport.numPendingMainThreadTasks());
423 390
424 m_scheduler->postInputTask(FROM_HERE, WTF::bind(&dummyTask)); 391 m_scheduler->postInputTask(FROM_HERE, WTF::bind(&dummyTask));
425 EXPECT_EQ(1U, m_platformSupport.numPendingMainThreadTasks()); 392 EXPECT_EQ(1U, m_platformSupport.numPendingMainThreadTasks());
426 393
427 runPendingTasks(); 394 runPendingTasks();
428 EXPECT_EQ(0U, m_platformSupport.numPendingMainThreadTasks()); 395 EXPECT_EQ(0U, m_platformSupport.numPendingMainThreadTasks());
429 396
(...skipping 18 matching lines...) Expand all
448 m_scheduler->setSharedTimerFireInterval(0); 415 m_scheduler->setSharedTimerFireInterval(0);
449 m_platformSupport.triggerSharedTimer(); 416 m_platformSupport.triggerSharedTimer();
450 417
451 EXPECT_EQ(0, s_dummyTaskCount); 418 EXPECT_EQ(0, s_dummyTaskCount);
452 419
453 // Clean up. 420 // Clean up.
454 m_scheduler->stopSharedTimer(); 421 m_scheduler->stopSharedTimer();
455 m_scheduler->setSharedTimerFiredFunction(nullptr); 422 m_scheduler->setSharedTimerFiredFunction(nullptr);
456 } 423 }
457 424
458 TEST_F(SchedulerTest, HighPriorityTasksOnlyRunOncePerSharedTimerFiring_InLowSche dulerPolicy)
459 {
460 s_dummyTaskCount = 0;
461 m_scheduler->enterSchedulerPolicy(SchedulerForTest::CompositorPriority);
462 m_scheduler->postInputTask(FROM_HERE, WTF::bind(&dummyTask));
463 // Trigger the posting of an input task during execution of the shared timer function.
464 m_scheduler->setSharedTimerFiredFunction(&postDummyInputTask);
465 m_scheduler->setSharedTimerFireInterval(0);
466 m_platformSupport.triggerSharedTimer();
467
468 EXPECT_EQ(1, s_dummyTaskCount);
469
470 // Clean up.
471 m_scheduler->stopSharedTimer();
472 m_scheduler->setSharedTimerFiredFunction(nullptr);
473 }
474
475 TEST_F(SchedulerTest, TestInputEventDoesNotTriggerShouldYield_InNormalMode) 425 TEST_F(SchedulerTest, TestInputEventDoesNotTriggerShouldYield_InNormalMode)
476 { 426 {
477 m_scheduler->postInputTask(FROM_HERE, WTF::bind(&dummyTask)); 427 m_scheduler->postInputTask(FROM_HERE, WTF::bind(&dummyTask));
478 428
479 EXPECT_FALSE(m_scheduler->shouldYieldForHighPriorityWork()); 429 EXPECT_FALSE(m_scheduler->shouldYieldForHighPriorityWork());
480 } 430 }
481 431
482 TEST_F(SchedulerTest, TestDidReceiveInputEventDoesNotTriggerShouldYield) 432 TEST_F(SchedulerTest, TestDidReceiveInputEventDoesNotTriggerShouldYield)
483 { 433 {
484 m_scheduler->didReceiveInputEvent(); 434 m_scheduler->didReceiveInputEvent();
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 m_platformSupport.setMonotonicTimeForTest(1000.5); 496 m_platformSupport.setMonotonicTimeForTest(1000.5);
547 runPendingTasks(); 497 runPendingTasks();
548 498
549 ASSERT_FALSE(m_scheduler->shouldYieldForHighPriorityWork()); 499 ASSERT_FALSE(m_scheduler->shouldYieldForHighPriorityWork());
550 m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&dummyTask)); 500 m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&dummyTask));
551 501
552 EXPECT_FALSE(m_scheduler->shouldYieldForHighPriorityWork()); 502 EXPECT_FALSE(m_scheduler->shouldYieldForHighPriorityWork());
553 } 503 }
554 504
555 } // namespace 505 } // namespace
OLDNEW
« Source/platform/scheduler/Scheduler.cpp ('K') | « Source/platform/scheduler/Scheduler.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698