Index: Source/platform/scheduler/SchedulerTest.cpp |
diff --git a/Source/platform/scheduler/SchedulerTest.cpp b/Source/platform/scheduler/SchedulerTest.cpp |
index 0b35485e9232fb0518f3c5ef9e964dca34c5de72..cf36df12fd9d2fde59efc11bc697ba0dcb6d01f2 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,7 @@ private: |
class SchedulerTest : public testing::Test { |
public: |
SchedulerTest() |
+ : m_reentrantCount(0) |
{ |
Scheduler::initializeOnMainThread(); |
m_scheduler = Scheduler::shared(); |
@@ -131,9 +136,50 @@ public: |
m_platformSupport.runPendingTasks(); |
} |
+ void appendToVector(string value) |
+ { |
+ m_order.push_back(value); |
+ } |
+ |
+ void appendToVectorReentrantTask() |
+ { |
+ m_reentrantOrder.push_back(m_reentrantCount++); |
+ |
+ // Note TestRentrantTaskAfterShutdown exposes the case where a low priority task |
+ // is executed after the Scheduler has shut down. It's necessary to check here |
+ // that the Scheduler still exists befpre making the re-entrant call. |
Sami
2014/08/08 15:31:13
s/befpre/before/
alexclarke
2014/08/08 15:47:46
Done.
|
+ if (m_reentrantCount <= 4 && Scheduler::shared()) { |
+ Scheduler::shared()->postTask( |
+ FROM_HERE, WTF::bind(&SchedulerTest::appendToVectorReentrantTask, this)); |
+ } |
+ } |
+ |
+ void appendToVectorReentrantInputTask() |
+ { |
+ m_reentrantOrder.push_back(m_reentrantCount++); |
+ |
+ if (m_reentrantCount <= 4) { |
+ m_scheduler->postInputTask( |
+ FROM_HERE, WTF::bind(&SchedulerTest::appendToVectorReentrantInputTask, this)); |
+ } |
+ } |
+ |
+ void appendToVectorReentrantCompositorTask() |
+ { |
+ m_reentrantOrder.push_back(m_reentrantCount++); |
+ |
+ if (m_reentrantCount <= 4) { |
+ 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; |
}; |
void orderedTestTask(int value, int* result) |
@@ -154,10 +200,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 +211,22 @@ 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); |
+} |
+ |
+TEST_F(SchedulerTest, TestTasksExecutedOnShutdown) |
+{ |
+ int result = 0; |
+ 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)); |
+ Scheduler::shutdown(); |
runPendingTasks(); |
EXPECT_EQ(15, result); |
} |
@@ -201,12 +259,68 @@ 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(WTF::bind<double>(&idleTestTask, 1, &result)); |
+ m_scheduler->postIdleTask(WTF::bind<double>(&idleTestTask, 1, &result)); |
+ m_scheduler->postIdleTask(WTF::bind<double>(&idleTestTask, 1, &result)); |
+ m_scheduler->postIdleTask(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, TestRentrantTaskAfterShutdown) |
+{ |
+ m_scheduler->postTask( |
+ FROM_HERE, WTF::bind(&SchedulerTest::appendToVectorReentrantTask, this)); |
+ Scheduler::shutdown(); |
+ EXPECT_TRUE(m_reentrantOrder.empty()); |
+ |
+ // Regular tasks are delegated to the main run loop, and since the scheduler has shutdown it's |
+ // no longer possible to post any more tasks through it. Hence only 1 task gets executed. |
+ runPendingTasks(); |
+ EXPECT_THAT(m_reentrantOrder, testing::ElementsAre(0)); |
+} |
+ |
+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 |
+ |
Sami
2014/08/08 15:31:13
nit: Some extra whitespace here.
alexclarke
2014/08/08 15:47:46
Done.
|
+ |