blob: 910e73baf276d1f7215f58b59832a1f7fb247fbb [file] [log] [blame]
Ady Abraham9e16a482019-12-03 17:19:41 -08001/*
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
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -080017// TODO(b/129481165): remove the #pragma below and fix conversion issues
18#pragma clang diagnostic push
19#pragma clang diagnostic ignored "-Wconversion"
20
Ady Abraham9e16a482019-12-03 17:19:41 -080021#undef LOG_TAG
22#define LOG_TAG "SchedulerUnittests"
23
24#include <gmock/gmock.h>
25#include <log/log.h>
26#include <thread>
27
28#include "Scheduler/PhaseOffsets.h"
29
30using namespace testing;
31
32namespace android {
33namespace scheduler {
34
35class TestablePhaseOffsetsAsDurations : public impl::PhaseDurations {
36public:
37 TestablePhaseOffsetsAsDurations(float currentFps, nsecs_t sfDuration, nsecs_t appDuration,
38 nsecs_t sfEarlyDuration, nsecs_t appEarlyDuration,
39 nsecs_t sfEarlyGlDuration, nsecs_t appEarlyGlDuration)
40 : impl::PhaseDurations({60.0f, 90.0f}, currentFps, sfDuration, appDuration,
41 sfEarlyDuration, appEarlyDuration, sfEarlyGlDuration,
42 appEarlyGlDuration) {}
43};
44
45class PhaseOffsetsTest : public testing::Test {
46protected:
47 PhaseOffsetsTest()
48 : mPhaseOffsets(60.0f, 10'500'000, 20'500'000, 16'000'000, 33'500'000, 13'500'000,
49 38'000'000) {}
50
51 ~PhaseOffsetsTest() = default;
52
53 TestablePhaseOffsetsAsDurations mPhaseOffsets;
54};
55
56namespace {
57/* ------------------------------------------------------------------------
58 * Test cases
59 */
60TEST_F(PhaseOffsetsTest, getOffsetsForRefreshRate_60Hz) {
61 mPhaseOffsets.setRefreshRateFps(60.0f);
62 auto currentOffsets = mPhaseOffsets.getCurrentOffsets();
63 auto offsets = mPhaseOffsets.getOffsetsForRefreshRate(60.0f);
64
65 EXPECT_EQ(currentOffsets, offsets);
66 EXPECT_EQ(offsets.late.sf, 6'166'667);
67
68 EXPECT_EQ(offsets.late.app, 2'333'334);
69
70 EXPECT_EQ(offsets.early.sf, 666'667);
71
72 EXPECT_EQ(offsets.early.app, 500'001);
73
74 EXPECT_EQ(offsets.earlyGl.sf, 3'166'667);
75
76 EXPECT_EQ(offsets.earlyGl.app, 15'166'668);
77}
78
79TEST_F(PhaseOffsetsTest, getOffsetsForRefreshRate_90Hz) {
80 mPhaseOffsets.setRefreshRateFps(90.0f);
81 auto currentOffsets = mPhaseOffsets.getCurrentOffsets();
82 auto offsets = mPhaseOffsets.getOffsetsForRefreshRate(90.0f);
83
84 EXPECT_EQ(currentOffsets, offsets);
85 EXPECT_EQ(offsets.late.sf, 611'111);
86
87 EXPECT_EQ(offsets.late.app, 2'333'333);
88
89 EXPECT_EQ(offsets.early.sf, -4'888'889);
90
91 EXPECT_EQ(offsets.early.app, 6'055'555);
92
93 EXPECT_EQ(offsets.earlyGl.sf, -2'388'889);
94
95 EXPECT_EQ(offsets.earlyGl.app, 4'055'555);
96}
97
98TEST_F(PhaseOffsetsTest, getOffsetsForRefreshRate_DefaultOffsets) {
99 TestablePhaseOffsetsAsDurations phaseOffsetsWithDefaultValues(60.0f, -1, -1, -1, -1, -1, -1);
100
101 auto validateOffsets = [](auto& offsets) {
102 EXPECT_EQ(offsets.late.sf, 1'000'000);
103
104 EXPECT_EQ(offsets.late.app, 1'000'000);
105
106 EXPECT_EQ(offsets.early.sf, 1'000'000);
107
108 EXPECT_EQ(offsets.early.app, 1'000'000);
109
110 EXPECT_EQ(offsets.earlyGl.sf, 1'000'000);
111
112 EXPECT_EQ(offsets.earlyGl.app, 1'000'000);
113 };
114
115 phaseOffsetsWithDefaultValues.setRefreshRateFps(90.0f);
116 auto currentOffsets = phaseOffsetsWithDefaultValues.getCurrentOffsets();
117 auto offsets = phaseOffsetsWithDefaultValues.getOffsetsForRefreshRate(90.0f);
118 EXPECT_EQ(currentOffsets, offsets);
119 validateOffsets(offsets);
120
121 phaseOffsetsWithDefaultValues.setRefreshRateFps(60.0f);
122 currentOffsets = phaseOffsetsWithDefaultValues.getCurrentOffsets();
123 offsets = phaseOffsetsWithDefaultValues.getOffsetsForRefreshRate(90.0f);
124 EXPECT_EQ(currentOffsets, offsets);
125 validateOffsets(offsets);
126}
127
128} // namespace
129} // namespace scheduler
130} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -0800131
132// TODO(b/129481165): remove the #pragma below and fix conversion issues
133#pragma clang diagnostic pop // ignored "-Wconversion"