1 /*
2 * Copyright (c) 2021 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 #include <gtest/gtest.h>
16 #include "vsync_distributor.h"
17 #include "vsync_controller.h"
18
19 using namespace testing;
20 using namespace testing::ext;
21
22 namespace OHOS {
23 namespace Rosen {
24 class VSyncDistributorTest : public testing::Test {
25 public:
26 static void SetUpTestCase();
27 static void TearDownTestCase();
28
29 static inline sptr<VSyncController> vsyncController = nullptr;
30 static inline sptr<VSyncDistributor> vsyncDistributor = nullptr;
31 static inline sptr<VSyncGenerator> vsyncGenerator = nullptr;
32 };
33
SetUpTestCase()34 void VSyncDistributorTest::SetUpTestCase()
35 {
36 vsyncGenerator = CreateVSyncGenerator();
37 vsyncController = new VSyncController(vsyncGenerator, 0);
38 vsyncDistributor = new VSyncDistributor(vsyncController, "VSyncConnection");
39 }
40
TearDownTestCase()41 void VSyncDistributorTest::TearDownTestCase()
42 {
43 vsyncGenerator = nullptr;
44 DestroyVSyncGenerator();
45 vsyncController = nullptr;
46 vsyncDistributor = nullptr;
47 }
48
49 namespace {
50 /*
51 * Function: AddConnection001
52 * Type: Function
53 * Rank: Important(2)
54 * EnvConditions: N/A
55 * CaseDescription: 1. call AddConnection
56 */
57 HWTEST_F(VSyncDistributorTest, AddConnection001, Function | MediumTest| Level3)
58 {
59 ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->AddConnection(nullptr), VSYNC_ERROR_NULLPTR);
60 }
61
62 /*
63 * Function: AddConnection002
64 * Type: Function
65 * Rank: Important(2)
66 * EnvConditions: N/A
67 * CaseDescription: 1. call AddConnection
68 */
69 HWTEST_F(VSyncDistributorTest, AddConnection002, Function | MediumTest| Level3)
70 {
71 sptr<VSyncConnection> conn = new VSyncConnection(vsyncDistributor, "VSyncDistributorTest");
72 ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->AddConnection(conn), VSYNC_ERROR_OK);
73 ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->AddConnection(conn), VSYNC_ERROR_INVALID_ARGUMENTS);
74 }
75
76 /*
77 * Function: RemoveConnection001
78 * Type: Function
79 * Rank: Important(2)
80 * EnvConditions: N/A
81 * CaseDescription: 1. call RemoveConnection
82 */
83 HWTEST_F(VSyncDistributorTest, RemoveConnection001, Function | MediumTest| Level3)
84 {
85 ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->RemoveConnection(nullptr), VSYNC_ERROR_NULLPTR);
86 }
87
88 /*
89 * Function: RemoveConnection002
90 * Type: Function
91 * Rank: Important(2)
92 * EnvConditions: N/A
93 * CaseDescription: 1. call RemoveConnection
94 */
95 HWTEST_F(VSyncDistributorTest, RemoveConnection002, Function | MediumTest| Level3)
96 {
97 sptr<VSyncConnection> conn = new VSyncConnection(vsyncDistributor, "VSyncDistributorTest");
98 ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->RemoveConnection(conn), VSYNC_ERROR_INVALID_ARGUMENTS);
99 }
100
101 /*
102 * Function: RemoveConnection003
103 * Type: Function
104 * Rank: Important(2)
105 * EnvConditions: N/A
106 * CaseDescription: 1. call RemoveConnection
107 */
108 HWTEST_F(VSyncDistributorTest, RemoveConnection003, Function | MediumTest| Level3)
109 {
110 sptr<VSyncConnection> conn = new VSyncConnection(vsyncDistributor, "VSyncDistributorTest");
111 VSyncDistributorTest::vsyncDistributor->AddConnection(conn);
112 ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->RemoveConnection(conn), VSYNC_ERROR_OK);
113 }
114
115 /*
116 * Function: RequestNextVSync001
117 * Type: Function
118 * Rank: Important(2)
119 * EnvConditions: N/A
120 * CaseDescription: 1. call RequestNextVSync
121 */
122 HWTEST_F(VSyncDistributorTest, RequestNextVSync001, Function | MediumTest| Level3)
123 {
124 ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->RequestNextVSync(nullptr), VSYNC_ERROR_NULLPTR);
125 }
126
127 /*
128 * Function: RequestNextVSync002
129 * Type: Function
130 * Rank: Important(2)
131 * EnvConditions: N/A
132 * CaseDescription: 1. call RequestNextVSync
133 */
134 HWTEST_F(VSyncDistributorTest, RequestNextVSync002, Function | MediumTest| Level3)
135 {
136 sptr<VSyncConnection> conn = new VSyncConnection(vsyncDistributor, "VSyncDistributorTest");
137 ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->RequestNextVSync(conn), VSYNC_ERROR_INVALID_ARGUMENTS);
138 }
139
140 /*
141 * Function: RequestNextVSync003
142 * Type: Function
143 * Rank: Important(2)
144 * EnvConditions: N/A
145 * CaseDescription: 1. call RequestNextVSync
146 */
147 HWTEST_F(VSyncDistributorTest, RequestNextVSync003, Function | MediumTest| Level3)
148 {
149 sptr<VSyncConnection> conn = new VSyncConnection(vsyncDistributor, "VSyncDistributorTest");
150 VSyncDistributorTest::vsyncDistributor->AddConnection(conn);
151 ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->RequestNextVSync(conn), VSYNC_ERROR_OK);
152 }
153
154 /*
155 * Function: RequestNextVSync004
156 * Type: Function
157 * Rank: Important(2)
158 * EnvConditions: N/A
159 * CaseDescription: 1. call RequestNextVSync
160 */
161 HWTEST_F(VSyncDistributorTest, RequestNextVSync004, Function | MediumTest| Level3)
162 {
163 sptr<VSyncConnection> conn = new VSyncConnection(vsyncDistributor, "VSyncDistributorTest");
164 VSyncDistributorTest::vsyncDistributor->AddConnection(conn);
165 ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->RequestNextVSync(conn, "unknown", 0), VSYNC_ERROR_OK);
166 }
167
168 /*
169 * Function: SetVSyncRate001
170 * Type: Function
171 * Rank: Important(2)
172 * EnvConditions: N/A
173 * CaseDescription: 1. call SetVSyncRate
174 */
175 HWTEST_F(VSyncDistributorTest, SetVSyncRate001, Function | MediumTest| Level3)
176 {
177 ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->SetVSyncRate(0, nullptr), VSYNC_ERROR_INVALID_ARGUMENTS);
178 }
179
180 /*
181 * Function: SetVSyncRate002
182 * Type: Function
183 * Rank: Important(2)
184 * EnvConditions: N/A
185 * CaseDescription: 1. call SetVSyncRate
186 */
187 HWTEST_F(VSyncDistributorTest, SetVSyncRate002, Function | MediumTest| Level3)
188 {
189 sptr<VSyncConnection> conn = new VSyncConnection(vsyncDistributor, "VSyncDistributorTest");
190 ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->SetVSyncRate(1, conn), VSYNC_ERROR_INVALID_ARGUMENTS);
191 }
192
193 /*
194 * Function: SetVSyncRate003
195 * Type: Function
196 * Rank: Important(2)
197 * EnvConditions: N/A
198 * CaseDescription: 1. call SetVSyncRate
199 */
200 HWTEST_F(VSyncDistributorTest, SetVSyncRate003, Function | MediumTest| Level3)
201 {
202 sptr<VSyncConnection> conn = new VSyncConnection(vsyncDistributor, "VSyncDistributorTest");
203 VSyncDistributorTest::vsyncDistributor->AddConnection(conn);
204 ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->SetVSyncRate(1, conn), VSYNC_ERROR_OK);
205 }
206
207 /*
208 * Function: SetVSyncRate004
209 * Type: Function
210 * Rank: Important(2)
211 * EnvConditions: N/A
212 * CaseDescription: 1. call SetVSyncRate
213 */
214 HWTEST_F(VSyncDistributorTest, SetVSyncRate004, Function | MediumTest| Level3)
215 {
216 sptr<VSyncConnection> conn = new VSyncConnection(vsyncDistributor, "VSyncDistributorTest");
217 VSyncDistributorTest::vsyncDistributor->AddConnection(conn);
218 ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->SetVSyncRate(1, conn), VSYNC_ERROR_OK);
219 ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->SetVSyncRate(1, conn), VSYNC_ERROR_INVALID_ARGUMENTS);
220 }
221
222 /*
223 * Function: SetHighPriorityVSyncRate001
224 * Type: Function
225 * Rank: Important(2)
226 * EnvConditions: N/A
227 * CaseDescription: 1. call SetHighPriorityVSyncRate with abnormal parameters and check ret
228 */
229 HWTEST_F(VSyncDistributorTest, SetHighPriorityVSyncRate001, Function | MediumTest| Level3)
230 {
231 ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->SetHighPriorityVSyncRate(0, nullptr),
232 VSYNC_ERROR_INVALID_ARGUMENTS);
233 ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->SetHighPriorityVSyncRate(1, nullptr),
234 VSYNC_ERROR_INVALID_ARGUMENTS);
235 sptr<VSyncConnection> conn = new VSyncConnection(vsyncDistributor, "VSyncDistributorTest");
236 ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->SetHighPriorityVSyncRate(1, conn), VSYNC_ERROR_INVALID_ARGUMENTS);
237 }
238
239 /*
240 * Function: SetHighPriorityVSyncRate002
241 * Type: Function
242 * Rank: Important(2)
243 * EnvConditions: N/A
244 * CaseDescription: 1. call SetHighPriorityVSyncRate with normal parameters and check ret
245 */
246 HWTEST_F(VSyncDistributorTest, SetHighPriorityVSyncRate002, Function | MediumTest| Level3)
247 {
248 sptr<VSyncConnection> conn = new VSyncConnection(vsyncDistributor, "VSyncDistributorTest");
249 VSyncDistributorTest::vsyncDistributor->AddConnection(conn);
250 ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->SetHighPriorityVSyncRate(1, conn), VSYNC_ERROR_OK);
251 ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->SetHighPriorityVSyncRate(1, conn), VSYNC_ERROR_INVALID_ARGUMENTS);
252 ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->SetHighPriorityVSyncRate(2, conn), VSYNC_ERROR_OK);
253 }
254
255 /*
256 * Function: SetFrameIsRender001
257 * Type: Function
258 * Rank: Important(2)
259 * EnvConditions: N/A
260 * CaseDescription: 1. call SetFrameIsRender with render is true
261 */
262 HWTEST_F(VSyncDistributorTest, SetFrameIsRender001, Function | MediumTest| Level3)
263 {
264 ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->IsDVsyncOn(), false);
265 VSyncDistributorTest::vsyncDistributor->SetFrameIsRender(true);
266 }
267
268 /*
269 * Function: SetFrameIsRender002
270 * Type: Function
271 * Rank: Important(2)
272 * EnvConditions: N/A
273 * CaseDescription: 1. call SetFrameIsRender with render is false
274 */
275 HWTEST_F(VSyncDistributorTest, SetFrameIsRender002, Function | MediumTest| Level3)
276 {
277 ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->IsDVsyncOn(), false);
278 VSyncDistributorTest::vsyncDistributor->SetFrameIsRender(false);
279 }
280
281 /*
282 * Function: GetRealTimeOffsetOfDvsync001
283 * Type: Function
284 * Rank: Important(2)
285 * EnvConditions: N/A
286 * CaseDescription: 1. call GetRealTimeOffsetOfDvsync
287 */
288 HWTEST_F(VSyncDistributorTest, GetRealTimeOffsetOfDvsync001, Function | MediumTest| Level3)
289 {
290 int64_t time = 1000;
291 uint64_t offset = VSyncDistributorTest::vsyncDistributor->GetRealTimeOffsetOfDvsync(time);
292 ASSERT_EQ(offset, 0);
293 }
294
295 /*
296 * Function: MarkRSAnimate001
297 * Type: Function
298 * Rank: Important(2)
299 * EnvConditions: N/A
300 * CaseDescription: 1. call MarkRSAnimate
301 */
302 HWTEST_F(VSyncDistributorTest, MarkRSAnimate001, Function | MediumTest| Level3)
303 {
304 sptr<VSyncConnection> conn = new VSyncConnection(vsyncDistributor, "VSyncDistributorTest");
305 auto res = VSyncDistributorTest::vsyncDistributor->SetUiDvsyncSwitch(true, conn);
306 ASSERT_EQ(res, VSYNC_ERROR_OK);
307 VSyncDistributorTest::vsyncDistributor->MarkRSAnimate();
308 }
309
310 /*
311 * Function: UnmarkRSAnimate001
312 * Type: Function
313 * Rank: Important(2)
314 * EnvConditions: N/A
315 * CaseDescription: 1. call UnmarkRSAnimate
316 */
317 HWTEST_F(VSyncDistributorTest, UnmarkRSAnimate001, Function | MediumTest| Level3)
318 {
319 sptr<VSyncConnection> conn = new VSyncConnection(vsyncDistributor, "VSyncDistributorTest");
320 auto res = VSyncDistributorTest::vsyncDistributor->SetUiDvsyncSwitch(false, conn);
321 ASSERT_EQ(res, VSYNC_ERROR_OK);
322 VSyncDistributorTest::vsyncDistributor->UnmarkRSAnimate();
323 }
324
325 /*
326 * Function: HasPendingUIRNV001
327 * Type: Function
328 * Rank: Important(2)
329 * EnvConditions: N/A
330 * CaseDescription: 1. call HasPendingUIRNV
331 */
332 HWTEST_F(VSyncDistributorTest, HasPendingUIRNV001, Function | MediumTest| Level3)
333 {
334 auto res = VSyncDistributorTest::vsyncDistributor->HasPendingUIRNV();
335 EXPECT_FALSE(res);
336 }
337
338
339 /*
340 * Function: UpdatePendingReferenceTime001
341 * Type: Function
342 * Rank: Important(2)
343 * EnvConditions: N/A
344 * CaseDescription: 1. call UpdatePendingReferenceTime
345 */
346 HWTEST_F(VSyncDistributorTest, UpdatePendingReferenceTime001, Function | MediumTest| Level3)
347 {
348 int64_t timeStamp = 0;
349 sptr<VSyncConnection> conn = new VSyncConnection(vsyncDistributor, "VSyncDistributorTest");
350 auto res = VSyncDistributorTest::vsyncDistributor->SetUiDvsyncSwitch(true, conn);
351 ASSERT_EQ(res, VSYNC_ERROR_OK);
352 VSyncDistributorTest::vsyncDistributor->UpdatePendingReferenceTime(timeStamp);
353 }
354
355 /*
356 * Function: SetHardwareTaskNum001
357 * Type: Function
358 * Rank: Important(2)
359 * EnvConditions: N/A
360 * CaseDescription: 1. call SetHardwareTaskNum
361 */
362 HWTEST_F(VSyncDistributorTest, SetHardwareTaskNum001, Function | MediumTest| Level3)
363 {
364 uint32_t num = 0;
365 sptr<VSyncConnection> conn = new VSyncConnection(vsyncDistributor, "VSyncDistributorTest");
366 auto res = VSyncDistributorTest::vsyncDistributor->SetUiDvsyncSwitch(true, conn);
367 ASSERT_EQ(res, VSYNC_ERROR_OK);
368 VSyncDistributorTest::vsyncDistributor->SetHardwareTaskNum(num);
369 }
370
371 /*
372 * Function: GetUiCommandDelayTime001
373 * Type: Function
374 * Rank: Important(2)
375 * EnvConditions: N/A
376 * CaseDescription: 1. call GetUiCommandDelayTime
377 */
378 HWTEST_F(VSyncDistributorTest, GetUiCommandDelayTime001, Function | MediumTest| Level3)
379 {
380 ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->GetUiCommandDelayTime(), 0);
381 }
382
383 /*
384 * Function: SetUiDvsyncConfig001
385 * Type: Function
386 * Rank: Important(2)
387 * EnvConditions: N/A
388 * CaseDescription: 1. call SetUiDvsyncConfig
389 */
390 HWTEST_F(VSyncDistributorTest, SetUiDvsyncConfig001, Function | MediumTest| Level3)
391 {
392 uint32_t bufferCount = 2;
393 ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->SetUiDvsyncConfig(bufferCount), VSYNC_ERROR_OK);
394 }
395 } // namespace
396 } // namespace Rosen
397 } // namespace OHOS