1 /*
2 * Copyright (c) 2022 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 <memory>
18 #include <unistd.h>
19
20 #include "pipeline/rs_qos_thread.h"
21 #include "platform/common/rs_innovation.h"
22
23 using namespace testing;
24 using namespace testing::ext;
25
26 namespace OHOS::Rosen {
27 class RSQosThreadTest : public testing::Test {
28 public:
29 static void SetUpTestCase();
30 static void TearDownTestCase();
31 void SetUp() override;
32 void TearDown() override;
33
34 static void* CreateQosService();
35 static void QosTreadStart();
36 static void QosTreadStop();
37 static void QosSetBoundaryRate(int minRate, int maxRate);
38 static void QosRegisteFuncCB(std::function<void(uint32_t, int)> setRate,
39 std::function<void(std::vector<std::pair<uint32_t, int> >&)> requestCount);
40 static void QosOnRSVisibilityChangeCB(std::map<uint32_t, bool>& pidVisMap);
41 static void QosOnRSResetPid();
42
43 static void FakeSo();
44 };
45
SetUpTestCase()46 void RSQosThreadTest::SetUpTestCase() {}
TearDownTestCase()47 void RSQosThreadTest::TearDownTestCase()
48 {
49 RSQosThread::GetInstance()->SetQosCal(false);
50 }
SetUp()51 void RSQosThreadTest::SetUp() {}
TearDown()52 void RSQosThreadTest::TearDown() {}
53
CreateQosService()54 void* RSQosThreadTest::CreateQosService()
55 {
56 return nullptr;
57 }
QosTreadStart()58 void RSQosThreadTest::QosTreadStart() {}
QosTreadStop()59 void RSQosThreadTest::QosTreadStop() {}
QosSetBoundaryRate(int minRate,int maxRate)60 void RSQosThreadTest::QosSetBoundaryRate(int minRate, int maxRate)
61 {
62 (void)minRate;
63 (void)maxRate;
64 }
65
QosRegisteFuncCB(std::function<void (uint32_t,int)> setRate,std::function<void (std::vector<std::pair<uint32_t,int>> &)> requestCount)66 void RSQosThreadTest::QosRegisteFuncCB(std::function<void(uint32_t, int)> setRate,
67 std::function<void(std::vector<std::pair<uint32_t, int> >&)> requestCount)
68 {
69 (void)setRate;
70 (void)requestCount;
71 }
72
QosOnRSVisibilityChangeCB(std::map<uint32_t,bool> & pidVisMap)73 void RSQosThreadTest::QosOnRSVisibilityChangeCB(std::map<uint32_t, bool>& pidVisMap)
74 {
75 (void)pidVisMap;
76 }
QosOnRSResetPid()77 void RSQosThreadTest::QosOnRSResetPid() {}
78
FakeSo()79 void RSQosThreadTest::FakeSo()
80 {
81 RSInnovation::_s_createRSQosService = (void*)CreateQosService;
82 RSInnovation::_s_qosThreadStart = (void*)QosTreadStart;
83 RSInnovation::_s_qosThreadStop = (void*)QosTreadStop;
84 RSInnovation::_s_qosSetBoundaryRate = (void*)QosSetBoundaryRate;
85 RSInnovation::_s_qosOnRSVisibilityChangeCB = (void*)QosOnRSVisibilityChangeCB;
86 RSInnovation::_s_qosRegisteFuncCB = (void*)QosRegisteFuncCB;
87 RSInnovation::_s_qosOnRSResetPid = (void*)QosOnRSResetPid;
88 RSInnovation::_s_qosVsyncFuncLoaded = true;
89 }
90
91 HWTEST_F(RSQosThreadTest, QosThreadStartAndStop, TestSize.Level1)
92 {
93 RSQosThread::ThreadStart();
94 RSQosThread::ThreadStop();
95 }
96
97 HWTEST_F(RSQosThreadTest, QosOnRSVisibilityChangeCB, TestSize.Level1)
98 {
99 std::map<uint32_t, RSVisibleLevel> pidVisMap;
100
101 // qosCal not setted
102 RSQosThread::GetInstance()->OnRSVisibilityChangeCB(pidVisMap);
103 }
104
105 HWTEST_F(RSQosThreadTest, QosFakeSo, TestSize.Level1)
106 {
107 RSInnovation::OpenInnovationSo();
108 ASSERT_EQ(RSInnovation::_s_qosVsyncFuncLoaded, false);
109
110 FakeSo();
111 ASSERT_EQ(RSInnovation::_s_qosVsyncFuncLoaded, true);
112
113 RSQosThread::GetInstance();
114
115 RSQosThread::ThreadStart();
116 RSQosThread::ThreadStop();
117
118 std::map<uint32_t, RSVisibleLevel> pidVisMap;
119 RSQosThread::GetInstance()->SetQosCal(true);
120 RSQosThread::GetInstance()->OnRSVisibilityChangeCB(pidVisMap);
121 }
122
123 /**
124 * @tc.name: GetQosVSyncRateInfos
125 * @tc.desc: GetQosVSyncRateInfos test
126 * @tc.type: FUNC
127 * @tc.require: issueI7HDVG
128 */
129 HWTEST_F(RSQosThreadTest, GetQosVSyncRateInfos, TestSize.Level1)
130 {
131 RSInnovation::OpenInnovationSo();
132
133 FakeSo();
134 ASSERT_EQ(RSInnovation::_s_qosVsyncFuncLoaded, true);
135
136 RSQosThread::GetInstance();
137
138 RSQosThread::ThreadStart();
139 RSQosThread::ThreadStop();
140
141 std::vector<std::pair<uint32_t, int32_t>> appsRateVec;
142 RSQosThread::GetInstance()->SetQosVSyncRate(0, 0);
143 RSQosThread::GetInstance()->GetQosVSyncRateInfos(appsRateVec);
144 RSQosThread::GetInstance()->ResetQosPid();
145 }
146 } // OHOS::Rosen
147