blob: f315a8a86cdddca8646c736e5c8abcbccb6bd360 [file] [log] [blame]
Alec Mouri0a1cc962019-03-14 12:33:02 -07001/*
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 Mouri0a1cc962019-03-14 12:33:02 -070026
27using namespace std::chrono_literals;
28using testing::_;
29
30namespace android {
31namespace scheduler {
32
33using RefreshRateType = RefreshRateConfigs::RefreshRateType;
34using RefreshRate = RefreshRateConfigs::RefreshRate;
35
36class RefreshRateConfigsTest : public testing::Test {
37protected:
38 static constexpr int CONFIG_ID_60 = 0;
Ady Abraham796beb02019-04-11 15:23:07 -070039 static constexpr hwc2_config_t HWC2_CONFIG_ID_60 = 0;
Alec Mouri0a1cc962019-03-14 12:33:02 -070040 static constexpr int CONFIG_ID_90 = 1;
Ady Abraham796beb02019-04-11 15:23:07 -070041 static constexpr hwc2_config_t HWC2_CONFIG_ID_90 = 1;
Alec Mouri0a1cc962019-03-14 12:33:02 -070042 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 Thomas2bbaabe2019-08-28 16:08:35 -070052 ASSERT_EQ(left.vsyncPeriod, right.vsyncPeriod);
Alec Mouri0a1cc962019-03-14 12:33:02 -070053 }
54};
55
56RefreshRateConfigsTest::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
62RefreshRateConfigsTest::~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
68namespace {
69/* ------------------------------------------------------------------------
70 * Test cases
71 */
Steven Thomas2bbaabe2019-08-28 16:08:35 -070072TEST_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 Mouri0a1cc962019-03-14 12:33:02 -070078}
79
Steven Thomas2bbaabe2019-08-28 16:08:35 -070080TEST_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 Mouri0a1cc962019-03-14 12:33:02 -070086
Steven Thomas2bbaabe2019-08-28 16:08:35 -070087 ASSERT_TRUE(refreshRateConfigs->refreshRateSwitchingSupported());
88 const auto& rates = refreshRateConfigs->getRefreshRateMap();
Alec Mouri0a1cc962019-03-14 12:33:02 -070089 ASSERT_EQ(2, rates.size());
Alec Mouri0a1cc962019-03-14 12:33:02 -070090 const auto& defaultRate = rates.find(RefreshRateType::DEFAULT);
91 const auto& performanceRate = rates.find(RefreshRateType::PERFORMANCE);
Alec Mouri0a1cc962019-03-14 12:33:02 -070092 ASSERT_NE(rates.end(), defaultRate);
93 ASSERT_NE(rates.end(), performanceRate);
94
Steven Thomas2bbaabe2019-08-28 16:08:35 -070095 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 Mouri0a1cc962019-03-14 12:33:02 -0700100
Steven Thomas2bbaabe2019-08-28 16:08:35 -0700101 assertRatesEqual(expectedDefaultConfig,
102 refreshRateConfigs->getRefreshRateFromType(RefreshRateType::DEFAULT));
Alec Mouri0a1cc962019-03-14 12:33:02 -0700103 assertRatesEqual(expectedPerformanceConfig,
Steven Thomas2bbaabe2019-08-28 16:08:35 -0700104 refreshRateConfigs->getRefreshRateFromType(RefreshRateType::PERFORMANCE));
Alec Mouri0a1cc962019-03-14 12:33:02 -0700105}
106} // namespace
107} // namespace scheduler
108} // namespace android