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

Unified Diff: Source/platform/scheduler/SchedulerTest.cpp

Issue 559973003: Adds the concept of Policies to the Blink Scheduler (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixed some names Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: Source/platform/scheduler/SchedulerTest.cpp
diff --git a/Source/platform/scheduler/SchedulerTest.cpp b/Source/platform/scheduler/SchedulerTest.cpp
index 40b8a7cc62a6bcea7114b4b316256d28975aca61..2731a83c5af706be03a36a31315f7523389afa05 100644
--- a/Source/platform/scheduler/SchedulerTest.cpp
+++ b/Source/platform/scheduler/SchedulerTest.cpp
@@ -19,6 +19,18 @@ using blink::Scheduler;
namespace {
+class SchedulerForTest : public blink::Scheduler {
+public:
+ static void initializeOnMainThread()
+ {
+ s_sharedScheduler = new SchedulerForTest();
+ }
+
+ using Scheduler::Normal;
Sami 2014/09/11 11:32:18 Neat!
alexclarke 2014/09/11 11:52:05 Acknowledged.
+ using Scheduler::CompositorPriority;
+ using Scheduler::enterSchedulerPolicy;
+};
+
class TestMainThread : public blink::WebThread {
public:
// blink::WebThread implementation.
@@ -76,6 +88,12 @@ public:
, m_sharedTimerRunning(false)
, m_sharedTimerFireInterval(0)
{
+ WTF::setMonotonicallyIncreasingTimeFunction(getMonotonicTimeForTest);
Sami 2014/09/11 11:32:19 Drop the "get", it's cleaner :) Do we actually ne
alexclarke 2014/09/11 11:52:05 Turns out we don't. Nice.
+ }
+
+ virtual ~SchedulerTestingPlatformSupport()
+ {
+ WTF::setMonotonicallyIncreasingTimeFunction(0);
}
// blink::Platform implementation.
@@ -89,6 +107,11 @@ public:
m_sharedTimerFunction = timerFunction;
}
+ virtual double monotonicallyIncreasingTime() OVERRIDE
+ {
+ return s_debugTime;
Sami 2014/09/11 11:32:18 nit: also call this s_monotonicallyIncreasingTime.
alexclarke 2014/09/11 11:52:05 Done.
+ }
+
virtual void setSharedTimerFireInterval(double)
{
m_sharedTimerFireInterval = 0;
@@ -125,21 +148,35 @@ public:
return m_mainThread.numPendingMainThreadTasks();
}
+ static void setDebugTime(double time)
Sami 2014/09/11 11:32:18 setMonotonicTimeForTest?
alexclarke 2014/09/11 11:52:05 Done.
+ {
+ s_debugTime = time;
+ }
+
private:
+ static double getMonotonicTimeForTest(void)
+ {
+ return s_debugTime;
+ }
+
TestMainThread m_mainThread;
SharedTimerFunction m_sharedTimerFunction;
bool m_sharedTimerRunning;
double m_sharedTimerFireInterval;
+
+ static double s_debugTime;
};
+double SchedulerTestingPlatformSupport::s_debugTime = 0;
+
class SchedulerTest : public testing::Test {
public:
SchedulerTest()
: m_reentrantCount(0)
, m_maxRecursion(4)
{
- Scheduler::initializeOnMainThread();
- m_scheduler = Scheduler::shared();
+ SchedulerForTest::initializeOnMainThread();
+ m_scheduler = static_cast<SchedulerForTest*>(Scheduler::shared());
}
~SchedulerTest()
@@ -186,7 +223,7 @@ public:
protected:
SchedulerTestingPlatformSupport m_platformSupport;
- Scheduler* m_scheduler;
+ SchedulerForTest* m_scheduler;
std::vector<std::string> m_order;
std::vector<int> m_reentrantOrder;
int m_reentrantCount;
@@ -266,8 +303,24 @@ TEST_F(SchedulerTest, TestIdleTask)
EXPECT_EQ(4, result);
}
-TEST_F(SchedulerTest, TestTaskPrioritization)
+TEST_F(SchedulerTest, TestTaskPrioritization_normalPolicy)
{
+ m_scheduler->enterSchedulerPolicy(SchedulerForTest::Normal);
Sami 2014/09/11 11:32:18 Instead of doing this in every test, let's add a s
alexclarke 2014/09/11 11:52:05 Done.
+ m_scheduler->postTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVector, this, std::string("L1")));
+ m_scheduler->postTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVector, this, std::string("L2")));
+ m_scheduler->postInputTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVector, this, std::string("I1")));
+ m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVector, this, std::string("C1")));
+ m_scheduler->postInputTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVector, this, std::string("I2")));
+ m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVector, this, std::string("C2")));
+
+ runPendingTasks();
+ EXPECT_THAT(m_order, testing::ElementsAre(
+ std::string("L1"), std::string("L2"), std::string("I1"), std::string("C1"), std::string("I2"), std::string("C2")));
+}
+
+TEST_F(SchedulerTest, TestTaskPrioritization_compositorPriorityPolicy)
+{
+ m_scheduler->enterSchedulerPolicy(SchedulerForTest::CompositorPriority);
m_scheduler->postTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVector, this, std::string("L1")));
m_scheduler->postTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVector, this, std::string("L2")));
m_scheduler->postInputTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVector, this, std::string("I1")));
@@ -383,9 +436,27 @@ void postDummyInputTask()
Scheduler::shared()->postInputTask(FROM_HERE, WTF::bind(&dummyTask));
}
-TEST_F(SchedulerTest, HighPriorityTasksOnlyRunOncePerSharedTimerFiring)
+TEST_F(SchedulerTest, HighPriorityTasksOnlyDontRunBecasueOfSharedTimerFiring_InNormalMode)
Sami 2014/09/11 11:32:18 s/Becasue/Because/
alexclarke 2014/09/11 11:52:05 Done.
{
s_dummyTaskCount = 0;
+ m_scheduler->enterSchedulerPolicy(SchedulerForTest::Normal);
+ m_scheduler->postInputTask(FROM_HERE, WTF::bind(&dummyTask));
+ // Trigger the posting of an input task during execution of the shared timer function.
+ m_scheduler->setSharedTimerFiredFunction(&postDummyInputTask);
+ m_scheduler->setSharedTimerFireInterval(0);
+ m_platformSupport.triggerSharedTimer();
+
+ EXPECT_EQ(0, s_dummyTaskCount);
+
+ // Clean up.
+ m_scheduler->stopSharedTimer();
+ m_scheduler->setSharedTimerFiredFunction(nullptr);
+}
+
+TEST_F(SchedulerTest, HighPriorityTasksOnlyRunOncePerSharedTimerFiring_InLowSchedulerPolicy)
+{
+ s_dummyTaskCount = 0;
+ m_scheduler->enterSchedulerPolicy(SchedulerForTest::CompositorPriority);
m_scheduler->postInputTask(FROM_HERE, WTF::bind(&dummyTask));
// Trigger the posting of an input task during execution of the shared timer function.
m_scheduler->setSharedTimerFiredFunction(&postDummyInputTask);
@@ -399,4 +470,51 @@ TEST_F(SchedulerTest, HighPriorityTasksOnlyRunOncePerSharedTimerFiring)
m_scheduler->setSharedTimerFiredFunction(nullptr);
}
+TEST_F(SchedulerTest, TestInputEventDoesNotTriggerShouldYield_InNormalMode)
+{
+ m_scheduler->enterSchedulerPolicy(SchedulerForTest::Normal);
+ m_scheduler->postInputTask(FROM_HERE, WTF::bind(&dummyTask));
+
+ EXPECT_FALSE(m_scheduler->shouldYieldForHighPriorityWork());
+}
+
+TEST_F(SchedulerTest, TestCompositorEventDoesNotTriggerShouldYield_InNormalMode)
+{
+ m_scheduler->enterSchedulerPolicy(SchedulerForTest::Normal);
+ m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&dummyTask));
+
+ EXPECT_FALSE(m_scheduler->shouldYieldForHighPriorityWork());
+}
+
+TEST_F(SchedulerTest, TestInputEventDoesTriggerShouldYield_InLowSchedulerPolicy)
+{
+ m_scheduler->enterSchedulerPolicy(SchedulerForTest::CompositorPriority);
+ m_scheduler->postInputTask(FROM_HERE, WTF::bind(&dummyTask));
+
+ EXPECT_TRUE(m_scheduler->shouldYieldForHighPriorityWork());
+}
+
+TEST_F(SchedulerTest, TestCompositorEventDoesTriggerShouldYield_InLowSchedulerPolicy)
+{
+ m_scheduler->enterSchedulerPolicy(SchedulerForTest::CompositorPriority);
+ m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&dummyTask));
+
+ EXPECT_TRUE(m_scheduler->shouldYieldForHighPriorityWork());
+}
+
+TEST_F(SchedulerTest, TestCompositorEvent_LowSchedulerPolicyDoesntLastLong)
+{
+ SchedulerTestingPlatformSupport::setDebugTime(1000.0);
+
+ m_scheduler->enterSchedulerPolicy(SchedulerForTest::CompositorPriority);
+ m_scheduler->postInputTask(FROM_HERE, WTF::bind(&dummyTask));
+ SchedulerTestingPlatformSupport::setDebugTime(1000.5);
+ runPendingTasks();
+
+ ASSERT_FALSE(m_scheduler->shouldYieldForHighPriorityWork());
+ m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&dummyTask));
+
+ EXPECT_FALSE(m_scheduler->shouldYieldForHighPriorityWork());
+}
+
} // namespace
« 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