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

Side by Side Diff: cc/scheduler/scheduler_unittest.cc

Issue 554973002: Disable scheduler deadline task on battery power in Windows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added better tests for mithro 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
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 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 #include "cc/scheduler/scheduler.h" 4 #include "cc/scheduler/scheduler.h"
5 5
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/debug/trace_event.h" 9 #include "base/debug/trace_event.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/scoped_vector.h" 11 #include "base/memory/scoped_vector.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/power_monitor/power_monitor.h"
14 #include "base/power_monitor/power_monitor_source.h"
13 #include "base/run_loop.h" 15 #include "base/run_loop.h"
14 #include "base/time/time.h" 16 #include "base/time/time.h"
15 #include "cc/test/begin_frame_args_test.h" 17 #include "cc/test/begin_frame_args_test.h"
16 #include "cc/test/ordered_simple_task_runner.h" 18 #include "cc/test/ordered_simple_task_runner.h"
17 #include "cc/test/scheduler_test_common.h" 19 #include "cc/test/scheduler_test_common.h"
18 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
19 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
20 22
21 #define EXPECT_ACTION(action, client, action_index, expected_num_actions) \ 23 #define EXPECT_ACTION(action, client, action_index, expected_num_actions) \
22 do { \ 24 do { \
(...skipping 1939 matching lines...) Expand 10 before | Expand all | Expand 10 after
1962 scheduler->NotifyReadyToCommit(); 1964 scheduler->NotifyReadyToCommit();
1963 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); 1965 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client);
1964 1966
1965 client.Reset(); 1967 client.Reset();
1966 scheduler->SetVisible(false); 1968 scheduler->SetVisible(false);
1967 // Sync tree should be forced to activate. 1969 // Sync tree should be forced to activate.
1968 EXPECT_ACTION("SetNeedsBeginFrames(false)", client, 0, 2); 1970 EXPECT_ACTION("SetNeedsBeginFrames(false)", client, 0, 2);
1969 EXPECT_ACTION("ScheduledActionActivateSyncTree", client, 1, 2); 1971 EXPECT_ACTION("ScheduledActionActivateSyncTree", client, 1, 2);
1970 } 1972 }
1971 1973
1974 class FakePowerMonitorSource : public base::PowerMonitorSource {
1975 public:
1976 FakePowerMonitorSource() {}
1977 virtual ~FakePowerMonitorSource() {}
1978 void GeneratePowerStateEvent(bool on_battery_power) {
1979 on_battery_power_impl_ = on_battery_power;
1980 ProcessPowerEvent(POWER_STATE_EVENT);
1981 base::MessageLoop::current()->RunUntilIdle();
1982 }
1983 virtual bool IsOnBatteryPowerImpl() override {
1984 return on_battery_power_impl_;
1985 }
1986
1987 private:
1988 bool on_battery_power_impl_;
1989 };
1990
1991 TEST(SchedulerTest, SchedulerPowerMonitoring) {
1992 FakePowerMonitorSource* power_monitor_source = new FakePowerMonitorSource;
1993 base::PowerMonitor power_monitor(
1994 (scoped_ptr<base::PowerMonitorSource>(power_monitor_source)));
1995
1996 FakeSchedulerClient client;
1997 SchedulerSettings settings;
1998 settings.prioritize_impl_latency_on_battery = true;
1999 TestScheduler* scheduler = client.CreateScheduler(settings);
2000
2001 base::TimeTicks before_deadline, after_deadline;
2002
2003 scheduler->SetCanStart();
2004 scheduler->SetVisible(true);
2005 scheduler->SetCanDraw(true);
2006
2007 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
2008
2009 scheduler->SetNeedsCommit();
2010 client.Reset();
2011
2012 // On non-battery power
2013 EXPECT_FALSE(power_monitor.IsOnBatteryPower());
2014
2015 client.AdvanceFrame();
2016 client.Reset();
2017
2018 before_deadline = client.now_src()->Now();
2019 EXPECT_TRUE(client.task_runner().RunTasksWhile(
2020 client.ImplFrameDeadlinePending(true)));
2021 after_deadline = client.now_src()->Now();
2022
2023 // We post a non-zero deadline task when not on battery
2024 EXPECT_LT(before_deadline, after_deadline);
2025
2026 // Switch to battery power
2027 power_monitor_source->GeneratePowerStateEvent(true);
2028 EXPECT_TRUE(power_monitor.IsOnBatteryPower());
2029
2030 client.AdvanceFrame();
2031 client.Reset();
2032
2033 before_deadline = client.now_src()->Now();
2034 EXPECT_TRUE(client.task_runner().RunTasksWhile(
2035 client.ImplFrameDeadlinePending(true)));
2036 after_deadline = client.now_src()->Now();
2037
2038 // We post a zero deadline task when on battery
2039 EXPECT_EQ(before_deadline, after_deadline);
2040
2041 // Switch to non-battery power
2042 power_monitor_source->GeneratePowerStateEvent(false);
2043 EXPECT_FALSE(power_monitor.IsOnBatteryPower());
2044
2045 client.AdvanceFrame();
2046 client.Reset();
2047
2048 // Same as before
2049 before_deadline = client.now_src()->Now();
2050 EXPECT_TRUE(client.task_runner().RunTasksWhile(
2051 client.ImplFrameDeadlinePending(true)));
2052 after_deadline = client.now_src()->Now();
2053 }
2054
2055 TEST(SchedulerTest,
2056 SimulateWindowsLowResolutionTimerOnBattery_PrioritizeImplLatencyOff) {
2057 FakePowerMonitorSource* power_monitor_source = new FakePowerMonitorSource;
2058 base::PowerMonitor power_monitor(
2059 (scoped_ptr<base::PowerMonitorSource>(power_monitor_source)));
2060
2061 FakeSchedulerClient client;
2062 SchedulerSettings settings;
2063 TestScheduler* scheduler = client.CreateScheduler(settings);
2064
2065 scheduler->SetCanStart();
2066 scheduler->SetVisible(true);
2067 scheduler->SetCanDraw(true);
2068
2069 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
2070
2071 // Set needs commit so that the scheduler tries to wait for the main thread
2072 scheduler->SetNeedsCommit();
2073 // Set needs redraw so that the scheduler doesn't wait too long
2074 scheduler->SetNeedsRedraw();
2075 client.Reset();
2076
2077 // Switch to battery power
2078 power_monitor_source->GeneratePowerStateEvent(true);
2079 EXPECT_TRUE(power_monitor.IsOnBatteryPower());
2080
2081 client.AdvanceFrame();
2082 client.Reset();
2083
2084 // Disable auto-advancing of now_src
2085 client.task_runner().SetAutoAdvanceNowToPendingTasks(false);
2086
2087 // Deadline task is pending
2088 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
2089 client.task_runner().RunPendingTasks();
2090 // Deadline task is still pending
2091 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
2092
2093 // Advance now by 15 ms - same as windows low res timer
2094 client.now_src()->AdvanceNowMicroseconds(15000);
2095 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
2096 client.task_runner().RunUntilTime(client.now_src()->Now());
2097 // Deadline task finally completes
2098 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
2099 }
2100
2101 TEST(SchedulerTest,
2102 SimulateWindowsLowResolutionTimerOnBattery_PrioritizeImplLatencyOn) {
2103 FakePowerMonitorSource* power_monitor_source = new FakePowerMonitorSource;
2104 base::PowerMonitor power_monitor(
2105 (scoped_ptr<base::PowerMonitorSource>(power_monitor_source)));
2106
2107 FakeSchedulerClient client;
2108 SchedulerSettings settings;
2109 settings.prioritize_impl_latency_on_battery = true;
2110 TestScheduler* scheduler = client.CreateScheduler(settings);
2111
2112 scheduler->SetCanStart();
2113 scheduler->SetVisible(true);
2114 scheduler->SetCanDraw(true);
2115
2116 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
2117
2118 // Set needs commit so that the scheduler tries to wait for the main thread
2119 scheduler->SetNeedsCommit();
2120 // Set needs redraw so that the scheduler doesn't wait too long
2121 scheduler->SetNeedsRedraw();
2122 client.Reset();
2123
2124 // Switch to battery power
2125 power_monitor_source->GeneratePowerStateEvent(true);
2126 EXPECT_TRUE(power_monitor.IsOnBatteryPower());
2127
2128 client.AdvanceFrame();
2129 client.Reset();
2130
2131 // Disable auto-advancing of now_src
2132 client.task_runner().SetAutoAdvanceNowToPendingTasks(false);
2133
2134 // Deadline task is pending
2135 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
2136 client.task_runner().RunPendingTasks();
2137 // Deadline task runs immediately
2138 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
2139 }
2140
1972 } // namespace 2141 } // namespace
1973 } // namespace cc 2142 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698