1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <gtest/gtest.h>
17 #include <test_header.h>
18
19 #include "hgm_core.h"
20 #include "hgm_frame_rate_manager.h"
21
22 using namespace testing;
23 using namespace testing::ext;
24
25 namespace OHOS {
26 namespace Rosen {
27 namespace {
28 int32_t width = 720;
29 int32_t height = 1080;
30 int32_t phyWidth = 685;
31 int32_t phyHeight = 1218;
32 ScreenSize screenSize = {width, height, phyWidth, phyHeight};
33 }
34 class HgmFrameRateMgrTest : public testing::Test {
35 public:
36 static void SetUpTestCase();
37 static void TearDownTestCase();
38 void SetUp();
39 void TearDown();
40 };
41
SetUpTestCase()42 void HgmFrameRateMgrTest::SetUpTestCase() {}
TearDownTestCase()43 void HgmFrameRateMgrTest::TearDownTestCase() {}
SetUp()44 void HgmFrameRateMgrTest::SetUp() {}
TearDown()45 void HgmFrameRateMgrTest::TearDown() {}
46
47 /**
48 * @tc.name: UniProcessDataForLtpo
49 * @tc.desc: Verify the result of UniProcessDataForLtpo function
50 * @tc.type: FUNC
51 * @tc.require: I7DMS1
52 */
53 HWTEST_F(HgmFrameRateMgrTest, UniProcessDataForLtpo, Function | SmallTest | Level1)
54 {
55 auto &instance = HgmCore::Instance();
56 ScreenId id = 8;
57 sptr<HgmScreen> screen = nullptr;
58 int32_t width = 1344;
59 int32_t height = 2772;
60 uint32_t rate = 120;
61 uint32_t rate2 = 60;
62 uint32_t rate3 = 90;
63 int32_t mode = 1;
64 int32_t mode2 = 2;
65 int32_t mode3 = 3;
66 instance.AddScreen(id, 1, screenSize);
67 instance.AddScreenInfo(id, width, height, rate, mode);
68 instance.AddScreenInfo(id, width, height, rate2, mode2);
69 instance.AddScreenInfo(id, width, height, rate3, mode3);
70
71 std::shared_ptr<RSRenderFrameRateLinker> rsFrameRateLinker = std::make_shared<RSRenderFrameRateLinker>();
72 ASSERT_NE(rsFrameRateLinker, nullptr);
73 rsFrameRateLinker->SetExpectedRange({0, 120, 60});
74
75 std::shared_ptr<RSRenderFrameRateLinker> appFrameLinker1 = std::make_shared<RSRenderFrameRateLinker>();
76 ASSERT_NE(appFrameLinker1, nullptr);
77 appFrameLinker1->SetExpectedRange({0, 120, 90});
78 std::shared_ptr<RSRenderFrameRateLinker> appFrameLinker2 = std::make_shared<RSRenderFrameRateLinker>();
79 ASSERT_NE(appFrameLinker2, nullptr);
80 appFrameLinker2->SetExpectedRange({0, 120, 120});
81 std::unordered_map<FrameRateLinkerId, std::shared_ptr<RSRenderFrameRateLinker>> appFrameLinkers =
82 {{1, appFrameLinker1}, {2, appFrameLinker2}};
83
84 uint64_t timestamp = 10000000;
85 bool flag = false;
86 sptr<VSyncGenerator> vsyncGenerator = CreateVSyncGenerator();
87 sptr<VSyncController> rsController = new VSyncController(vsyncGenerator, 0);
88 sptr<VSyncController> appController = new VSyncController(vsyncGenerator, 0);
89 std::shared_ptr<HgmVSyncGeneratorController> controller =
90 std::make_shared<HgmVSyncGeneratorController>(rsController, appController, vsyncGenerator);
91 ASSERT_NE(controller, nullptr);
92 std::unique_ptr<HgmFrameRateManager> frameRateMgr = std::make_unique<HgmFrameRateManager>();
93 PART("CaseDescription") {
94 STEP("1. get a HgmFrameRateManager") {
95 ASSERT_NE(frameRateMgr, nullptr);
96 frameRateMgr->Init(rsController, appController, vsyncGenerator);
97 }
98 STEP("2. check the result of UniProcessDataForLtpo") {
__anonee08b69c0202(bool idleTimerExpired, bool forceUpdate) 99 frameRateMgr->SetForceUpdateCallback([](bool idleTimerExpired, bool forceUpdate) {});
100 frameRateMgr->UniProcessDataForLtpo(timestamp, rsFrameRateLinker, appFrameLinkers, flag);
101 }
102 }
103 }
104
105 /**
106 * @tc.name: UniProcessDataForLtps
107 * @tc.desc: Verify the result of UniProcessDataForLtps function
108 * @tc.type: FUNC
109 * @tc.require: I7DMS1
110 */
111 HWTEST_F(HgmFrameRateMgrTest, UniProcessDataForLtps, Function | SmallTest | Level1)
112 {
113 bool flag = false;
114 std::unique_ptr<HgmFrameRateManager> frameRateMgr = std::make_unique<HgmFrameRateManager>();
115 PART("CaseDescription") {
116 STEP("1. check the result of UniProcessDataForLtps") {
117 frameRateMgr->UniProcessDataForLtps(flag);
118 }
119 }
120 }
121
122 /**
123 * @tc.name: HgmOneShotTimerTest
124 * @tc.desc: Verify the result of HgmOneShotTimerTest
125 * @tc.type: FUNC
126 * @tc.require: I7DMS1
127 */
128 HWTEST_F(HgmFrameRateMgrTest, HgmOneShotTimerTest, Function | SmallTest | Level2)
129 {
130 std::unique_ptr<HgmFrameRateManager> mgr = std::make_unique<HgmFrameRateManager>();
131 ScreenId id = 1;
132 int32_t interval = 200; // 200ms means waiting time
133
134 PART("CaseDescription") {
135 STEP("1. set force update callback") {
__anonee08b69c0302(bool idleTimerExpired, bool forceUpdate) 136 mgr->SetForceUpdateCallback([](bool idleTimerExpired, bool forceUpdate) {});
137 }
138 STEP("2. insert and start screenTimer") {
139 mgr->StartScreenTimer(id, interval, nullptr, nullptr);
140 auto timer = mgr->GetScreenTimer(id);
141 STEP_ASSERT_NE(timer, nullptr);
142 }
143 STEP("3. reset screenTimer") {
144 mgr->ResetScreenTimer(id);
145 auto timer = mgr->GetScreenTimer(id);
146 STEP_ASSERT_NE(timer, nullptr);
147 }
148 }
149 }
150 } // namespace Rosen
151 } // namespace OHOS