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

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

Issue 439923006: Prioritizing input and compositor tasks in the blink scheduler. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Adding a missing #include Created 6 years, 4 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
« no previous file with comments | « Source/platform/scheduler/Scheduler.cpp ('k') | Source/wtf/DoubleBufferedDeque.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/scheduler/SchedulerTest.cpp
diff --git a/Source/platform/scheduler/SchedulerTest.cpp b/Source/platform/scheduler/SchedulerTest.cpp
index 0b35485e9232fb0518f3c5ef9e964dca34c5de72..7b03e9498e2fa6259d0043dc06707857e1072d30 100644
--- a/Source/platform/scheduler/SchedulerTest.cpp
+++ b/Source/platform/scheduler/SchedulerTest.cpp
@@ -10,9 +10,13 @@
#include "public/platform/Platform.h"
#include "public/platform/WebThread.h"
+#include <gmock/gmock.h>
#include <gtest/gtest.h>
+#include <string>
+#include <vector>
using blink::Scheduler;
+using namespace std;
namespace {
@@ -116,6 +120,8 @@ private:
class SchedulerTest : public testing::Test {
public:
SchedulerTest()
+ : m_reentrantCount(0)
+ , m_maxRecursion(4)
{
Scheduler::initializeOnMainThread();
m_scheduler = Scheduler::shared();
@@ -131,9 +137,45 @@ public:
m_platformSupport.runPendingTasks();
}
+ void appendToVector(string value)
+ {
+ m_order.push_back(value);
+ }
+
+ void appendToVectorReentrantTask()
+ {
+ m_reentrantOrder.push_back(m_reentrantCount++);
+
+ if (m_reentrantCount > m_maxRecursion)
+ return;
+ Scheduler::shared()->postTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVectorReentrantTask, this));
+ }
+
+ void appendToVectorReentrantInputTask()
+ {
+ m_reentrantOrder.push_back(m_reentrantCount++);
+
+ if (m_reentrantCount > m_maxRecursion)
+ return;
+ m_scheduler->postInputTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVectorReentrantInputTask, this));
+ }
+
+ void appendToVectorReentrantCompositorTask()
+ {
+ m_reentrantOrder.push_back(m_reentrantCount++);
+
+ if (m_reentrantCount > m_maxRecursion)
+ return;
+ m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVectorReentrantCompositorTask, this));
+ }
+
protected:
SchedulerTestingPlatformSupport m_platformSupport;
Scheduler* m_scheduler;
+ std::vector<string> m_order;
+ std::vector<int> m_reentrantOrder;
+ int m_reentrantCount;
+ int m_maxRecursion;
};
void orderedTestTask(int value, int* result)
@@ -154,10 +196,10 @@ void idleTestTask(int value, int* result, double allottedTime)
TEST_F(SchedulerTest, TestPostTask)
{
int result = 0;
- m_scheduler->postTask(FROM_HERE, bind(&orderedTestTask, 1, &result));
- m_scheduler->postTask(FROM_HERE, bind(&orderedTestTask, 2, &result));
- m_scheduler->postTask(FROM_HERE, bind(&orderedTestTask, 3, &result));
- m_scheduler->postTask(FROM_HERE, bind(&orderedTestTask, 4, &result));
+ m_scheduler->postTask(FROM_HERE, WTF::bind(&orderedTestTask, 1, &result));
+ m_scheduler->postTask(FROM_HERE, WTF::bind(&orderedTestTask, 2, &result));
+ m_scheduler->postTask(FROM_HERE, WTF::bind(&orderedTestTask, 3, &result));
+ m_scheduler->postTask(FROM_HERE, WTF::bind(&orderedTestTask, 4, &result));
runPendingTasks();
EXPECT_EQ(0x1234, result);
}
@@ -165,10 +207,10 @@ TEST_F(SchedulerTest, TestPostTask)
TEST_F(SchedulerTest, TestPostMixedTaskTypes)
{
int result = 0;
- m_scheduler->postTask(FROM_HERE, bind(&unorderedTestTask, 1, &result));
- m_scheduler->postInputTask(FROM_HERE, bind(&unorderedTestTask, 2, &result));
- m_scheduler->postCompositorTask(FROM_HERE, bind(&unorderedTestTask, 4, &result));
- m_scheduler->postTask(FROM_HERE, bind(&unorderedTestTask, 8, &result));
+ m_scheduler->postTask(FROM_HERE, WTF::bind(&unorderedTestTask, 1, &result));
+ m_scheduler->postInputTask(FROM_HERE, WTF::bind(&unorderedTestTask, 2, &result));
+ m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&unorderedTestTask, 4, &result));
+ m_scheduler->postTask(FROM_HERE, WTF::bind(&unorderedTestTask, 8, &result));
runPendingTasks();
EXPECT_EQ(15, result);
}
@@ -201,12 +243,51 @@ TEST_F(SchedulerTest, TestIdleTask)
{
// TODO: Check task allottedTime when implemented in the scheduler.
int result = 0;
- m_scheduler->postIdleTask(bind<double>(&idleTestTask, 1, &result));
- m_scheduler->postIdleTask(bind<double>(&idleTestTask, 1, &result));
- m_scheduler->postIdleTask(bind<double>(&idleTestTask, 1, &result));
- m_scheduler->postIdleTask(bind<double>(&idleTestTask, 1, &result));
+ m_scheduler->postIdleTask(FROM_HERE, WTF::bind<double>(&idleTestTask, 1, &result));
+ m_scheduler->postIdleTask(FROM_HERE, WTF::bind<double>(&idleTestTask, 1, &result));
+ m_scheduler->postIdleTask(FROM_HERE, WTF::bind<double>(&idleTestTask, 1, &result));
+ m_scheduler->postIdleTask(FROM_HERE, WTF::bind<double>(&idleTestTask, 1, &result));
runPendingTasks();
EXPECT_EQ(4, result);
}
+TEST_F(SchedulerTest, TestTaskPrioritization)
+{
+ m_scheduler->postTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVector, this, string("L1")));
+ m_scheduler->postTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVector, this, string("L2")));
+ m_scheduler->postInputTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVector, this, string("I1")));
+ m_scheduler->postInputTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVector, this, string("I2")));
+ m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVector, this, string("C1")));
+ m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVector, this, string("C2")));
+
+ runPendingTasks();
+ EXPECT_THAT(m_order, testing::ElementsAre(
+ string("I1"), string("I2"), string("C1"), string("C2"), string("L1"), string("L2")));
+}
+
+TEST_F(SchedulerTest, TestRentrantTask)
+{
+ m_scheduler->postTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVectorReentrantTask, this));
+ runPendingTasks();
+
+ EXPECT_THAT(m_reentrantOrder, testing::ElementsAre(0, 1, 2, 3, 4));
+}
+
+
+TEST_F(SchedulerTest, TestRentrantInputTaskDuringShutdown)
+{
+ m_scheduler->postInputTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVectorReentrantInputTask, this));
+ Scheduler::shutdown();
+
+ EXPECT_THAT(m_reentrantOrder, testing::ElementsAre(0, 1, 2, 3, 4));
+}
+
+TEST_F(SchedulerTest, TestRentrantCompositorTaskDuringShutdown)
+{
+ m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVectorReentrantCompositorTask, this));
+ Scheduler::shutdown();
+
+ EXPECT_THAT(m_reentrantOrder, testing::ElementsAre(0, 1, 2, 3, 4));
+}
+
} // namespace
« no previous file with comments | « Source/platform/scheduler/Scheduler.cpp ('k') | Source/wtf/DoubleBufferedDeque.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698