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

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: Test tweak. 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
« no previous file with comments | « Source/platform/scheduler/Scheduler.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
338 EXPECT_TRUE(m_order.empty());
352 339
353 EXPECT_THAT(m_reentrantOrder, testing::ElementsAre(0, 1, 2, 3, 4)); 340 runPendingTasks();
354 } 341 EXPECT_THAT(m_order, testing::ElementsAre(
355 342 std::string("1"), std::string("2"), std::string("3"), std::string("4"))) ;
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 } 343 }
363 344
364 bool s_shouldContinue; 345 bool s_shouldContinue;
365 void reentrantInputTask(Scheduler* scheduler) 346 void reentrantInputTask(Scheduler* scheduler)
366 { 347 {
367 if (s_shouldContinue) 348 if (s_shouldContinue)
368 scheduler->postInputTask(FROM_HERE, WTF::bind(&reentrantInputTask, sched uler)); 349 scheduler->postInputTask(FROM_HERE, WTF::bind(&reentrantInputTask, sched uler));
369 } 350 }
370 351
371 void reentrantCompositorTask(Scheduler* scheduler) 352 void reentrantCompositorTask(Scheduler* scheduler)
(...skipping 26 matching lines...) Expand all
398 // If starvation occurs then this will never exit. 379 // If starvation occurs then this will never exit.
399 runPendingTasks(); 380 runPendingTasks();
400 } 381 }
401 382
402 int s_dummyTaskCount; 383 int s_dummyTaskCount;
403 void dummyTask() 384 void dummyTask()
404 { 385 {
405 s_dummyTaskCount++; 386 s_dummyTaskCount++;
406 } 387 }
407 388
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) 389 TEST_F(SchedulerTest, TestMainThreadTaskLifeCycle)
421 { 390 {
422 EXPECT_EQ(0U, m_platformSupport.numPendingMainThreadTasks()); 391 EXPECT_EQ(0U, m_platformSupport.numPendingMainThreadTasks());
423 392
424 m_scheduler->postInputTask(FROM_HERE, WTF::bind(&dummyTask)); 393 m_scheduler->postInputTask(FROM_HERE, WTF::bind(&dummyTask));
425 EXPECT_EQ(1U, m_platformSupport.numPendingMainThreadTasks()); 394 EXPECT_EQ(1U, m_platformSupport.numPendingMainThreadTasks());
426 395
427 runPendingTasks(); 396 runPendingTasks();
428 EXPECT_EQ(0U, m_platformSupport.numPendingMainThreadTasks()); 397 EXPECT_EQ(0U, m_platformSupport.numPendingMainThreadTasks());
429 398
(...skipping 18 matching lines...) Expand all
448 m_scheduler->setSharedTimerFireInterval(0); 417 m_scheduler->setSharedTimerFireInterval(0);
449 m_platformSupport.triggerSharedTimer(); 418 m_platformSupport.triggerSharedTimer();
450 419
451 EXPECT_EQ(0, s_dummyTaskCount); 420 EXPECT_EQ(0, s_dummyTaskCount);
452 421
453 // Clean up. 422 // Clean up.
454 m_scheduler->stopSharedTimer(); 423 m_scheduler->stopSharedTimer();
455 m_scheduler->setSharedTimerFiredFunction(nullptr); 424 m_scheduler->setSharedTimerFiredFunction(nullptr);
456 } 425 }
457 426
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) 427 TEST_F(SchedulerTest, TestInputEventDoesNotTriggerShouldYield_InNormalMode)
476 { 428 {
477 m_scheduler->postInputTask(FROM_HERE, WTF::bind(&dummyTask)); 429 m_scheduler->postInputTask(FROM_HERE, WTF::bind(&dummyTask));
478 430
479 EXPECT_FALSE(m_scheduler->shouldYieldForHighPriorityWork()); 431 EXPECT_FALSE(m_scheduler->shouldYieldForHighPriorityWork());
480 } 432 }
481 433
482 TEST_F(SchedulerTest, TestDidReceiveInputEventDoesNotTriggerShouldYield) 434 TEST_F(SchedulerTest, TestDidReceiveInputEventDoesNotTriggerShouldYield)
483 { 435 {
484 m_scheduler->didReceiveInputEvent(); 436 m_scheduler->didReceiveInputEvent();
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 m_platformSupport.setMonotonicTimeForTest(1000.5); 498 m_platformSupport.setMonotonicTimeForTest(1000.5);
547 runPendingTasks(); 499 runPendingTasks();
548 500
549 ASSERT_FALSE(m_scheduler->shouldYieldForHighPriorityWork()); 501 ASSERT_FALSE(m_scheduler->shouldYieldForHighPriorityWork());
550 m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&dummyTask)); 502 m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&dummyTask));
551 503
552 EXPECT_FALSE(m_scheduler->shouldYieldForHighPriorityWork()); 504 EXPECT_FALSE(m_scheduler->shouldYieldForHighPriorityWork());
553 } 505 }
554 506
555 } // namespace 507 } // namespace
OLDNEW
« no previous file with comments | « Source/platform/scheduler/Scheduler.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698