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

Side by Side 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: Adds a comment to a test 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 unified diff | Download patch
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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 }; 69 };
70 70
71 class SchedulerTestingPlatformSupport : blink::TestingPlatformSupport { 71 class SchedulerTestingPlatformSupport : blink::TestingPlatformSupport {
72 public: 72 public:
73 SchedulerTestingPlatformSupport() 73 SchedulerTestingPlatformSupport()
74 : TestingPlatformSupport(TestingPlatformSupport::Config()) 74 : TestingPlatformSupport(TestingPlatformSupport::Config())
75 , m_sharedTimerFunction(nullptr) 75 , m_sharedTimerFunction(nullptr)
76 , m_sharedTimerRunning(false) 76 , m_sharedTimerRunning(false)
77 , m_sharedTimerFireInterval(0) 77 , m_sharedTimerFireInterval(0)
78 { 78 {
79 WTF::setMonotonicallyIncreasingTimeFunction(getDebugTime);
Sami 2014/09/10 16:00:39 Maybe getMonotonicTimeForTest?
alexclarke 2014/09/10 17:35:37 Done.
80 }
81
82 virtual ~SchedulerTestingPlatformSupport()
83 {
84 WTF::setMonotonicallyIncreasingTimeFunction(0);
Sami 2014/09/10 16:00:39 I hope we're not stomping over some other test by
alexclarke 2014/09/10 17:35:37 Likewise. If it turns out we are, then we can jus
79 } 85 }
80 86
81 // blink::Platform implementation. 87 // blink::Platform implementation.
82 virtual blink::WebThread* currentThread() OVERRIDE 88 virtual blink::WebThread* currentThread() OVERRIDE
83 { 89 {
84 return &m_mainThread; 90 return &m_mainThread;
85 } 91 }
86 92
87 virtual void setSharedTimerFiredFunction(SharedTimerFunction timerFunction) OVERRIDE 93 virtual void setSharedTimerFiredFunction(SharedTimerFunction timerFunction) OVERRIDE
88 { 94 {
89 m_sharedTimerFunction = timerFunction; 95 m_sharedTimerFunction = timerFunction;
90 } 96 }
91 97
98 virtual double monotonicallyIncreasingTime() OVERRIDE
99 {
100 return s_debugTime;
101 }
102
92 virtual void setSharedTimerFireInterval(double) 103 virtual void setSharedTimerFireInterval(double)
93 { 104 {
94 m_sharedTimerFireInterval = 0; 105 m_sharedTimerFireInterval = 0;
95 m_sharedTimerRunning = true; 106 m_sharedTimerRunning = true;
96 } 107 }
97 108
98 virtual void stopSharedTimer() 109 virtual void stopSharedTimer()
99 { 110 {
100 m_sharedTimerRunning = false; 111 m_sharedTimerRunning = false;
101 } 112 }
(...skipping 16 matching lines...) Expand all
118 void triggerSharedTimer() 129 void triggerSharedTimer()
119 { 130 {
120 m_sharedTimerFunction(); 131 m_sharedTimerFunction();
121 } 132 }
122 133
123 size_t numPendingMainThreadTasks() const 134 size_t numPendingMainThreadTasks() const
124 { 135 {
125 return m_mainThread.numPendingMainThreadTasks(); 136 return m_mainThread.numPendingMainThreadTasks();
126 } 137 }
127 138
139 static void setDebugTime(double time)
140 {
141 s_debugTime = time;
142 }
143
128 private: 144 private:
145 static double getDebugTime(void)
146 {
147 return s_debugTime;
148 }
149
129 TestMainThread m_mainThread; 150 TestMainThread m_mainThread;
130 SharedTimerFunction m_sharedTimerFunction; 151 SharedTimerFunction m_sharedTimerFunction;
131 bool m_sharedTimerRunning; 152 bool m_sharedTimerRunning;
132 double m_sharedTimerFireInterval; 153 double m_sharedTimerFireInterval;
154
155 static double s_debugTime;
133 }; 156 };
134 157
158 double SchedulerTestingPlatformSupport::s_debugTime = 0;
159
135 class SchedulerTest : public testing::Test { 160 class SchedulerTest : public testing::Test {
136 public: 161 public:
137 SchedulerTest() 162 SchedulerTest()
138 : m_reentrantCount(0) 163 : m_reentrantCount(0)
139 , m_maxRecursion(4) 164 , m_maxRecursion(4)
140 { 165 {
141 Scheduler::initializeOnMainThread(); 166 Scheduler::initializeOnMainThread();
142 m_scheduler = Scheduler::shared(); 167 m_scheduler = Scheduler::shared();
143 } 168 }
144 169
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 m_scheduler->setSharedTimerFireInterval(0); 417 m_scheduler->setSharedTimerFireInterval(0);
393 m_platformSupport.triggerSharedTimer(); 418 m_platformSupport.triggerSharedTimer();
394 419
395 EXPECT_EQ(1, s_dummyTaskCount); 420 EXPECT_EQ(1, s_dummyTaskCount);
396 421
397 // Clean up. 422 // Clean up.
398 m_scheduler->stopSharedTimer(); 423 m_scheduler->stopSharedTimer();
399 m_scheduler->setSharedTimerFiredFunction(nullptr); 424 m_scheduler->setSharedTimerFiredFunction(nullptr);
400 } 425 }
401 426
427 TEST_F(SchedulerTest, TestInputEventTriggersShouldYield)
428 {
429 ASSERT_FALSE(m_scheduler->shouldYieldForHighPriorityWork());
430 m_scheduler->postInputTask(FROM_HERE, WTF::bind(&dummyTask));
431
432 EXPECT_TRUE(m_scheduler->shouldYieldForHighPriorityWork());
433 }
434
435 TEST_F(SchedulerTest, TestCompositorEventDoesNotTriggerShouldYield_InNormalMode)
436 {
437 ASSERT_FALSE(m_scheduler->shouldYieldForHighPriorityWork());
438 m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&dummyTask));
439
440 EXPECT_FALSE(m_scheduler->shouldYieldForHighPriorityWork());
441 }
442
443 TEST_F(SchedulerTest, TestInputEventTriggersLowLatencyMode)
444 {
445 // Fire off an input task to put us in low latency mode.
446 m_scheduler->postInputTask(FROM_HERE, WTF::bind(&dummyTask));
447 runPendingTasks();
448
449 ASSERT_FALSE(m_scheduler->shouldYieldForHighPriorityWork());
450 m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&dummyTask));
451
452 EXPECT_TRUE(m_scheduler->shouldYieldForHighPriorityWork());
453 }
454
455 TEST_F(SchedulerTest, TestCompositorEvent_LowLatencyModeDoesntLastLongWithoutInp utEvents)
456 {
457 SchedulerTestingPlatformSupport::setDebugTime(1000.0);
458
459 // Fire off an input task to put us in low latency mode.
460 m_scheduler->postInputTask(FROM_HERE, WTF::bind(&dummyTask));
461 SchedulerTestingPlatformSupport::setDebugTime(1000.5);
462 runPendingTasks();
463
464 ASSERT_FALSE(m_scheduler->shouldYieldForHighPriorityWork());
465 m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&dummyTask));
466
467 EXPECT_FALSE(m_scheduler->shouldYieldForHighPriorityWork());
468 }
469
402 } // namespace 470 } // 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