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 | |
| 33 | using RefreshRateType = RefreshRateConfigs::RefreshRateType; |
| 34 | using RefreshRate = RefreshRateConfigs::RefreshRate; |
| 35 | |
| 36 | class RefreshRateConfigsTest : public testing::Test { |
| 37 | protected: |
| 38 | static constexpr int CONFIG_ID_60 = 0; |
Ady Abraham | 796beb0 | 2019-04-11 15:23:07 -0700 | [diff] [blame] | 39 | static constexpr hwc2_config_t HWC2_CONFIG_ID_60 = 0; |
Alec Mouri | 0a1cc96 | 2019-03-14 12:33:02 -0700 | [diff] [blame] | 40 | static constexpr int CONFIG_ID_90 = 1; |
Ady Abraham | 796beb0 | 2019-04-11 15:23:07 -0700 | [diff] [blame] | 41 | static constexpr hwc2_config_t HWC2_CONFIG_ID_90 = 1; |
Alec Mouri | 0a1cc96 | 2019-03-14 12:33:02 -0700 | [diff] [blame] | 42 | static constexpr int64_t VSYNC_60 = 16666667; |
| 43 | static constexpr int64_t VSYNC_90 = 11111111; |
| 44 | |
| 45 | RefreshRateConfigsTest(); |
| 46 | ~RefreshRateConfigsTest(); |
| 47 | |
| 48 | void assertRatesEqual(const RefreshRate& left, const RefreshRate& right) { |
| 49 | ASSERT_EQ(left.configId, right.configId); |
| 50 | ASSERT_EQ(left.name, right.name); |
| 51 | ASSERT_EQ(left.fps, right.fps); |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame^] | 52 | ASSERT_EQ(left.vsyncPeriod, right.vsyncPeriod); |
Alec Mouri | 0a1cc96 | 2019-03-14 12:33:02 -0700 | [diff] [blame] | 53 | } |
| 54 | }; |
| 55 | |
| 56 | RefreshRateConfigsTest::RefreshRateConfigsTest() { |
| 57 | const ::testing::TestInfo* const test_info = |
| 58 | ::testing::UnitTest::GetInstance()->current_test_info(); |
| 59 | ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name()); |
| 60 | } |
| 61 | |
| 62 | RefreshRateConfigsTest::~RefreshRateConfigsTest() { |
| 63 | const ::testing::TestInfo* const test_info = |
| 64 | ::testing::UnitTest::GetInstance()->current_test_info(); |
| 65 | ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name()); |
| 66 | } |
| 67 | |
| 68 | namespace { |
| 69 | /* ------------------------------------------------------------------------ |
| 70 | * Test cases |
| 71 | */ |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame^] | 72 | TEST_F(RefreshRateConfigsTest, oneDeviceConfig_isRejected) { |
| 73 | std::vector<RefreshRateConfigs::InputConfig> configs{{HWC2_CONFIG_ID_60, VSYNC_60}}; |
| 74 | auto refreshRateConfigs = |
| 75 | std::make_unique<RefreshRateConfigs>(/*refreshRateSwitching=*/true, configs, |
| 76 | /*currentConfig=*/0); |
| 77 | ASSERT_FALSE(refreshRateConfigs->refreshRateSwitchingSupported()); |
Alec Mouri | 0a1cc96 | 2019-03-14 12:33:02 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame^] | 80 | TEST_F(RefreshRateConfigsTest, twoDeviceConfigs_storesFullRefreshRateMap) { |
| 81 | std::vector<RefreshRateConfigs::InputConfig> configs{{HWC2_CONFIG_ID_60, VSYNC_60}, |
| 82 | {HWC2_CONFIG_ID_90, VSYNC_90}}; |
| 83 | auto refreshRateConfigs = |
| 84 | std::make_unique<RefreshRateConfigs>(/*refreshRateSwitching=*/true, configs, |
| 85 | /*currentConfig=*/0); |
Alec Mouri | 0a1cc96 | 2019-03-14 12:33:02 -0700 | [diff] [blame] | 86 | |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame^] | 87 | ASSERT_TRUE(refreshRateConfigs->refreshRateSwitchingSupported()); |
| 88 | const auto& rates = refreshRateConfigs->getRefreshRateMap(); |
Alec Mouri | 0a1cc96 | 2019-03-14 12:33:02 -0700 | [diff] [blame] | 89 | ASSERT_EQ(2, rates.size()); |
Alec Mouri | 0a1cc96 | 2019-03-14 12:33:02 -0700 | [diff] [blame] | 90 | const auto& defaultRate = rates.find(RefreshRateType::DEFAULT); |
| 91 | const auto& performanceRate = rates.find(RefreshRateType::PERFORMANCE); |
Alec Mouri | 0a1cc96 | 2019-03-14 12:33:02 -0700 | [diff] [blame] | 92 | ASSERT_NE(rates.end(), defaultRate); |
| 93 | ASSERT_NE(rates.end(), performanceRate); |
| 94 | |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame^] | 95 | RefreshRate expectedDefaultConfig = {CONFIG_ID_60, "60fps", 60, VSYNC_60, HWC2_CONFIG_ID_60}; |
| 96 | assertRatesEqual(expectedDefaultConfig, defaultRate->second); |
| 97 | RefreshRate expectedPerformanceConfig = {CONFIG_ID_90, "90fps", 90, VSYNC_90, |
| 98 | HWC2_CONFIG_ID_90}; |
| 99 | assertRatesEqual(expectedPerformanceConfig, performanceRate->second); |
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 | assertRatesEqual(expectedDefaultConfig, |
| 102 | refreshRateConfigs->getRefreshRateFromType(RefreshRateType::DEFAULT)); |
Alec Mouri | 0a1cc96 | 2019-03-14 12:33:02 -0700 | [diff] [blame] | 103 | assertRatesEqual(expectedPerformanceConfig, |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame^] | 104 | refreshRateConfigs->getRefreshRateFromType(RefreshRateType::PERFORMANCE)); |
Alec Mouri | 0a1cc96 | 2019-03-14 12:33:02 -0700 | [diff] [blame] | 105 | } |
| 106 | } // namespace |
| 107 | } // namespace scheduler |
| 108 | } // namespace android |