Alec Mouri | 0a1cc96 | 2019-03-14 12:33:02 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #undef LOG_TAG |
| 18 | #define LOG_TAG "SchedulerUnittests" |
| 19 | |
| 20 | #include <gmock/gmock.h> |
| 21 | #include <log/log.h> |
| 22 | #include <thread> |
| 23 | |
| 24 | #include "DisplayHardware/HWC2.h" |
| 25 | #include "Scheduler/RefreshRateConfigs.h" |
Alec Mouri | 0a1cc96 | 2019-03-14 12:33:02 -0700 | [diff] [blame] | 26 | |
| 27 | using namespace std::chrono_literals; |
| 28 | using testing::_; |
| 29 | |
| 30 | namespace android { |
| 31 | namespace scheduler { |
| 32 | |
Alec Mouri | 0a1cc96 | 2019-03-14 12:33:02 -0700 | [diff] [blame] | 33 | using RefreshRate = RefreshRateConfigs::RefreshRate; |
| 34 | |
| 35 | class RefreshRateConfigsTest : public testing::Test { |
| 36 | protected: |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 37 | static inline const HwcConfigIndexType HWC_CONFIG_ID_60 = HwcConfigIndexType(0); |
| 38 | static inline const HwcConfigIndexType HWC_CONFIG_ID_90 = HwcConfigIndexType(1); |
| 39 | static inline const HwcConfigGroupType HWC_GROUP_ID_0 = HwcConfigGroupType(0); |
| 40 | static inline const HwcConfigGroupType HWC_GROUP_ID_1 = HwcConfigGroupType(1); |
Alec Mouri | 0a1cc96 | 2019-03-14 12:33:02 -0700 | [diff] [blame] | 41 | static constexpr int64_t VSYNC_60 = 16666667; |
Ana Krulec | 72f0d6e | 2020-01-06 15:24:47 -0800 | [diff] [blame^] | 42 | static constexpr int64_t VSYNC_60_POINT_4 = 16666665; |
Alec Mouri | 0a1cc96 | 2019-03-14 12:33:02 -0700 | [diff] [blame] | 43 | static constexpr int64_t VSYNC_90 = 11111111; |
| 44 | |
| 45 | RefreshRateConfigsTest(); |
| 46 | ~RefreshRateConfigsTest(); |
Alec Mouri | 0a1cc96 | 2019-03-14 12:33:02 -0700 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | RefreshRateConfigsTest::RefreshRateConfigsTest() { |
| 50 | const ::testing::TestInfo* const test_info = |
| 51 | ::testing::UnitTest::GetInstance()->current_test_info(); |
| 52 | ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name()); |
| 53 | } |
| 54 | |
| 55 | RefreshRateConfigsTest::~RefreshRateConfigsTest() { |
| 56 | const ::testing::TestInfo* const test_info = |
| 57 | ::testing::UnitTest::GetInstance()->current_test_info(); |
| 58 | ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name()); |
| 59 | } |
| 60 | |
| 61 | namespace { |
| 62 | /* ------------------------------------------------------------------------ |
| 63 | * Test cases |
| 64 | */ |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 65 | TEST_F(RefreshRateConfigsTest, oneDeviceConfig_SwitchingSupported) { |
| 66 | std::vector<RefreshRateConfigs::InputConfig> configs{ |
| 67 | {{HWC_CONFIG_ID_60, HWC_GROUP_ID_0, VSYNC_60}}}; |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 68 | auto refreshRateConfigs = |
| 69 | std::make_unique<RefreshRateConfigs>(/*refreshRateSwitching=*/true, configs, |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 70 | /*currentConfigId=*/HWC_CONFIG_ID_60); |
| 71 | ASSERT_TRUE(refreshRateConfigs->refreshRateSwitchingSupported()); |
| 72 | } |
| 73 | |
| 74 | TEST_F(RefreshRateConfigsTest, oneDeviceConfig_SwitchingNotSupported) { |
| 75 | std::vector<RefreshRateConfigs::InputConfig> configs{ |
| 76 | {{HWC_CONFIG_ID_60, HWC_GROUP_ID_0, VSYNC_60}}}; |
| 77 | auto refreshRateConfigs = |
| 78 | std::make_unique<RefreshRateConfigs>(/*refreshRateSwitching=*/false, configs, |
| 79 | /*currentConfigId=*/HWC_CONFIG_ID_60); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 80 | ASSERT_FALSE(refreshRateConfigs->refreshRateSwitchingSupported()); |
Alec Mouri | 0a1cc96 | 2019-03-14 12:33:02 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 83 | TEST_F(RefreshRateConfigsTest, invalidPolicy) { |
| 84 | std::vector<RefreshRateConfigs::InputConfig> configs{ |
| 85 | {{HWC_CONFIG_ID_60, HWC_GROUP_ID_0, VSYNC_60}}}; |
| 86 | auto refreshRateConfigs = |
| 87 | std::make_unique<RefreshRateConfigs>(/*refreshRateSwitching=*/true, configs, |
| 88 | /*currentConfigId=*/HWC_CONFIG_ID_60); |
| 89 | ASSERT_LT(refreshRateConfigs->setPolicy(HwcConfigIndexType(10), 60, 60, nullptr), 0); |
| 90 | ASSERT_LT(refreshRateConfigs->setPolicy(HWC_CONFIG_ID_60, 20, 40, nullptr), 0); |
| 91 | } |
| 92 | |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 93 | TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_storesFullRefreshRateMap) { |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 94 | std::vector<RefreshRateConfigs::InputConfig> configs{ |
| 95 | {{HWC_CONFIG_ID_60, HWC_GROUP_ID_0, VSYNC_60}, |
| 96 | {HWC_CONFIG_ID_90, HWC_GROUP_ID_0, VSYNC_90}}}; |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 97 | auto refreshRateConfigs = |
| 98 | std::make_unique<RefreshRateConfigs>(/*refreshRateSwitching=*/true, configs, |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 99 | /*currentConfigId=*/HWC_CONFIG_ID_60); |
Alec Mouri | 0a1cc96 | 2019-03-14 12:33:02 -0700 | [diff] [blame] | 100 | |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame] | 101 | ASSERT_TRUE(refreshRateConfigs->refreshRateSwitchingSupported()); |
Alec Mouri | 0a1cc96 | 2019-03-14 12:33:02 -0700 | [diff] [blame] | 102 | |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 103 | const auto minRate = refreshRateConfigs->getMinRefreshRate(); |
| 104 | const auto performanceRate = refreshRateConfigs->getMaxRefreshRate(); |
Alec Mouri | 0a1cc96 | 2019-03-14 12:33:02 -0700 | [diff] [blame] | 105 | |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 106 | RefreshRate expectedDefaultConfig = {HWC_CONFIG_ID_60, VSYNC_60, HWC_GROUP_ID_0, "60fps", 60}; |
| 107 | ASSERT_EQ(expectedDefaultConfig, minRate); |
| 108 | RefreshRate expectedPerformanceConfig = {HWC_CONFIG_ID_90, VSYNC_90, HWC_GROUP_ID_0, "90fps", |
| 109 | 90}; |
| 110 | ASSERT_EQ(expectedPerformanceConfig, performanceRate); |
| 111 | |
| 112 | const auto minRateByPolicy = refreshRateConfigs->getMinRefreshRateByPolicy(); |
| 113 | const auto performanceRateByPolicy = refreshRateConfigs->getMaxRefreshRateByPolicy(); |
| 114 | ASSERT_EQ(minRateByPolicy, minRate); |
| 115 | ASSERT_EQ(performanceRateByPolicy, performanceRate); |
Alec Mouri | 0a1cc96 | 2019-03-14 12:33:02 -0700 | [diff] [blame] | 116 | } |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 117 | |
| 118 | TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_storesFullRefreshRateMap_differentGroups) { |
| 119 | std::vector<RefreshRateConfigs::InputConfig> configs{ |
| 120 | {{HWC_CONFIG_ID_60, HWC_GROUP_ID_0, VSYNC_60}, |
| 121 | {HWC_CONFIG_ID_90, HWC_GROUP_ID_1, VSYNC_90}}}; |
| 122 | auto refreshRateConfigs = |
| 123 | std::make_unique<RefreshRateConfigs>(/*refreshRateSwitching=*/true, configs, |
| 124 | /*currentConfigId=*/HWC_CONFIG_ID_60); |
| 125 | |
| 126 | ASSERT_TRUE(refreshRateConfigs->refreshRateSwitchingSupported()); |
| 127 | const auto minRate = refreshRateConfigs->getMinRefreshRateByPolicy(); |
| 128 | const auto performanceRate = refreshRateConfigs->getMaxRefreshRate(); |
| 129 | const auto minRate60 = refreshRateConfigs->getMinRefreshRateByPolicy(); |
| 130 | const auto performanceRate60 = refreshRateConfigs->getMaxRefreshRateByPolicy(); |
| 131 | |
| 132 | RefreshRate expectedDefaultConfig = {HWC_CONFIG_ID_60, VSYNC_60, HWC_GROUP_ID_0, "60fps", 60}; |
| 133 | ASSERT_EQ(expectedDefaultConfig, minRate); |
| 134 | ASSERT_EQ(expectedDefaultConfig, minRate60); |
| 135 | ASSERT_EQ(expectedDefaultConfig, performanceRate60); |
| 136 | |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 137 | ASSERT_GE(refreshRateConfigs->setPolicy(HWC_CONFIG_ID_90, 60, 90, nullptr), 0); |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 138 | refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90); |
| 139 | |
| 140 | ASSERT_TRUE(refreshRateConfigs->refreshRateSwitchingSupported()); |
| 141 | const auto minRate90 = refreshRateConfigs->getMinRefreshRateByPolicy(); |
| 142 | const auto performanceRate90 = refreshRateConfigs->getMaxRefreshRateByPolicy(); |
| 143 | |
| 144 | RefreshRate expectedPerformanceConfig = {HWC_CONFIG_ID_90, VSYNC_90, HWC_GROUP_ID_1, "90fps", |
| 145 | 90}; |
| 146 | ASSERT_EQ(expectedPerformanceConfig, performanceRate); |
| 147 | ASSERT_EQ(expectedPerformanceConfig, minRate90); |
| 148 | ASSERT_EQ(expectedPerformanceConfig, performanceRate90); |
| 149 | } |
| 150 | |
| 151 | TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_policyChange) { |
| 152 | std::vector<RefreshRateConfigs::InputConfig> configs{ |
| 153 | {{HWC_CONFIG_ID_60, HWC_GROUP_ID_0, VSYNC_60}, |
| 154 | {HWC_CONFIG_ID_90, HWC_GROUP_ID_0, VSYNC_90}}}; |
| 155 | auto refreshRateConfigs = |
| 156 | std::make_unique<RefreshRateConfigs>(/*refreshRateSwitching=*/true, configs, |
| 157 | /*currentConfigId=*/HWC_CONFIG_ID_60); |
| 158 | ASSERT_TRUE(refreshRateConfigs->refreshRateSwitchingSupported()); |
| 159 | auto minRate = refreshRateConfigs->getMinRefreshRateByPolicy(); |
| 160 | auto performanceRate = refreshRateConfigs->getMaxRefreshRateByPolicy(); |
| 161 | |
| 162 | RefreshRate expectedDefaultConfig = {HWC_CONFIG_ID_60, VSYNC_60, HWC_GROUP_ID_0, "60fps", 60}; |
| 163 | ASSERT_EQ(expectedDefaultConfig, minRate); |
| 164 | RefreshRate expectedPerformanceConfig = {HWC_CONFIG_ID_90, VSYNC_90, HWC_GROUP_ID_0, "90fps", |
| 165 | 90}; |
| 166 | ASSERT_EQ(expectedPerformanceConfig, performanceRate); |
| 167 | |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 168 | ASSERT_GE(refreshRateConfigs->setPolicy(HWC_CONFIG_ID_60, 60, 60, nullptr), 0); |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 169 | ASSERT_TRUE(refreshRateConfigs->refreshRateSwitchingSupported()); |
| 170 | |
| 171 | auto minRate60 = refreshRateConfigs->getMinRefreshRateByPolicy(); |
| 172 | auto performanceRate60 = refreshRateConfigs->getMaxRefreshRateByPolicy(); |
| 173 | ASSERT_EQ(expectedDefaultConfig, minRate60); |
| 174 | ASSERT_EQ(expectedDefaultConfig, performanceRate60); |
| 175 | } |
| 176 | |
| 177 | TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_getCurrentRefreshRate) { |
| 178 | std::vector<RefreshRateConfigs::InputConfig> configs{ |
| 179 | {{HWC_CONFIG_ID_60, HWC_GROUP_ID_0, VSYNC_60}, |
| 180 | {HWC_CONFIG_ID_90, HWC_GROUP_ID_0, VSYNC_90}}}; |
| 181 | auto refreshRateConfigs = |
| 182 | std::make_unique<RefreshRateConfigs>(/*refreshRateSwitching=*/true, configs, |
| 183 | /*currentConfigId=*/HWC_CONFIG_ID_60); |
| 184 | { |
| 185 | auto current = refreshRateConfigs->getCurrentRefreshRate(); |
| 186 | EXPECT_EQ(current.configId, HWC_CONFIG_ID_60); |
| 187 | } |
| 188 | |
| 189 | refreshRateConfigs->setCurrentConfigId(HWC_CONFIG_ID_90); |
| 190 | { |
| 191 | auto current = refreshRateConfigs->getCurrentRefreshRate(); |
| 192 | EXPECT_EQ(current.configId, HWC_CONFIG_ID_90); |
| 193 | } |
| 194 | |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 195 | ASSERT_GE(refreshRateConfigs->setPolicy(HWC_CONFIG_ID_90, 90, 90, nullptr), 0); |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 196 | { |
| 197 | auto current = refreshRateConfigs->getCurrentRefreshRate(); |
| 198 | EXPECT_EQ(current.configId, HWC_CONFIG_ID_90); |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_getRefreshRateForContent) { |
| 203 | std::vector<RefreshRateConfigs::InputConfig> configs{ |
| 204 | {{HWC_CONFIG_ID_60, HWC_GROUP_ID_0, VSYNC_60}, |
| 205 | {HWC_CONFIG_ID_90, HWC_GROUP_ID_0, VSYNC_90}}}; |
| 206 | auto refreshRateConfigs = |
| 207 | std::make_unique<RefreshRateConfigs>(/*refreshRateSwitching=*/true, configs, |
| 208 | /*currentConfigId=*/HWC_CONFIG_ID_60); |
| 209 | |
| 210 | ASSERT_TRUE(refreshRateConfigs->refreshRateSwitchingSupported()); |
| 211 | |
| 212 | RefreshRate expected60Config = {HWC_CONFIG_ID_60, VSYNC_60, HWC_GROUP_ID_0, "60fps", 60}; |
| 213 | RefreshRate expected90Config = {HWC_CONFIG_ID_90, VSYNC_90, HWC_GROUP_ID_0, "90fps", 90}; |
| 214 | |
| 215 | ASSERT_EQ(expected90Config, refreshRateConfigs->getRefreshRateForContent(90.0f)); |
| 216 | ASSERT_EQ(expected60Config, refreshRateConfigs->getRefreshRateForContent(60.0f)); |
| 217 | ASSERT_EQ(expected90Config, refreshRateConfigs->getRefreshRateForContent(45.0f)); |
| 218 | ASSERT_EQ(expected60Config, refreshRateConfigs->getRefreshRateForContent(30.0f)); |
| 219 | ASSERT_EQ(expected60Config, refreshRateConfigs->getRefreshRateForContent(24.0f)); |
| 220 | |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 221 | ASSERT_GE(refreshRateConfigs->setPolicy(HWC_CONFIG_ID_60, 60, 60, nullptr), 0); |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 222 | ASSERT_EQ(expected60Config, refreshRateConfigs->getRefreshRateForContent(90.0f)); |
| 223 | ASSERT_EQ(expected60Config, refreshRateConfigs->getRefreshRateForContent(60.0f)); |
| 224 | ASSERT_EQ(expected60Config, refreshRateConfigs->getRefreshRateForContent(45.0f)); |
| 225 | ASSERT_EQ(expected60Config, refreshRateConfigs->getRefreshRateForContent(30.0f)); |
| 226 | ASSERT_EQ(expected60Config, refreshRateConfigs->getRefreshRateForContent(24.0f)); |
| 227 | |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 228 | ASSERT_GE(refreshRateConfigs->setPolicy(HWC_CONFIG_ID_90, 90, 90, nullptr), 0); |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 229 | ASSERT_EQ(expected90Config, refreshRateConfigs->getRefreshRateForContent(90.0f)); |
| 230 | ASSERT_EQ(expected90Config, refreshRateConfigs->getRefreshRateForContent(60.0f)); |
| 231 | ASSERT_EQ(expected90Config, refreshRateConfigs->getRefreshRateForContent(45.0f)); |
| 232 | ASSERT_EQ(expected90Config, refreshRateConfigs->getRefreshRateForContent(30.0f)); |
| 233 | ASSERT_EQ(expected90Config, refreshRateConfigs->getRefreshRateForContent(24.0f)); |
Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 234 | ASSERT_GE(refreshRateConfigs->setPolicy(HWC_CONFIG_ID_60, 0, 120, nullptr), 0); |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 235 | ASSERT_EQ(expected90Config, refreshRateConfigs->getRefreshRateForContent(90.0f)); |
| 236 | ASSERT_EQ(expected60Config, refreshRateConfigs->getRefreshRateForContent(60.0f)); |
| 237 | ASSERT_EQ(expected90Config, refreshRateConfigs->getRefreshRateForContent(45.0f)); |
| 238 | ASSERT_EQ(expected60Config, refreshRateConfigs->getRefreshRateForContent(30.0f)); |
| 239 | ASSERT_EQ(expected60Config, refreshRateConfigs->getRefreshRateForContent(24.0f)); |
| 240 | } |
| 241 | |
Ana Krulec | 72f0d6e | 2020-01-06 15:24:47 -0800 | [diff] [blame^] | 242 | TEST_F(RefreshRateConfigsTest, testInPolicy) { |
| 243 | RefreshRate expectedDefaultConfig = {HWC_CONFIG_ID_60, VSYNC_60_POINT_4, HWC_GROUP_ID_0, |
| 244 | "60fps", 60}; |
| 245 | ASSERT_TRUE(expectedDefaultConfig.inPolicy(60.000004, 60.000004)); |
| 246 | ASSERT_TRUE(expectedDefaultConfig.inPolicy(59.0f, 60.1f)); |
| 247 | ASSERT_FALSE(expectedDefaultConfig.inPolicy(75.0, 90.0)); |
| 248 | ASSERT_FALSE(expectedDefaultConfig.inPolicy(60.0011, 90.0)); |
| 249 | ASSERT_FALSE(expectedDefaultConfig.inPolicy(50.0, 59.998)); |
| 250 | } |
| 251 | |
Alec Mouri | 0a1cc96 | 2019-03-14 12:33:02 -0700 | [diff] [blame] | 252 | } // namespace |
| 253 | } // namespace scheduler |
| 254 | } // namespace android |