1 /*
2  * Copyright (c) 2024 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 
18 #include "sync_fence_tracker.h"
19 
20 using namespace testing;
21 using namespace testing::ext;
22 
23 namespace OHOS {
24 class SyncFenceTrackerTest : public testing::Test {
25 public:
26     static void SetUpTestCase();
27     static void TearDownTestCase();
28 };
29 
SetUpTestCase()30 void SyncFenceTrackerTest::SetUpTestCase()
31 {
32 }
33 
TearDownTestCase()34 void SyncFenceTrackerTest::TearDownTestCase()
35 {
36 }
37 
38 /*
39 * Function: TrackFence
40 * Type: Function
41 * Rank: Important(2)
42 * EnvConditions: N/A
43 * CaseDescription: 1. call TrackFence
44 *                  2. check ret
45 */
46 HWTEST_F(SyncFenceTrackerTest, TrackFenceTest001, Function | MediumTest | Level2)
47 {
48     auto tracker = new SyncFenceTracker("TrackFenceTest001");
49     sptr<SyncFence> fence = new SyncFence(0);
50     tracker->TrackFence(fence, true);
51     tracker->isGpuFence_ = true;
52     tracker->TrackFence(fence, true);
53     tracker->TrackFence(fence, false);
54     tracker->isGpuFence_ = false;
55     tracker->TrackFence(fence, true);
56     tracker->TrackFence(fence, false);
57     delete tracker;
58 }
59 
60 /*
61 * Function: CheckGpuSubhealthEventLimit
62 * Type: Function
63 * Rank: Important(2)
64 * EnvConditions: N/A
65 * CaseDescription: 1. call CheckGpuSubhealthEventLimit
66 *                  2. check ret
67 */
68 HWTEST_F(SyncFenceTrackerTest, CheckGpuSubhealthEventLimit001, Function | MediumTest | Level2)
69 {
70     auto tracker = new SyncFenceTracker("CheckGpuSubhealthEventLimit001");
71     tracker->gpuSubhealthEventNum_ = 0;
72     ASSERT_EQ(tracker->CheckGpuSubhealthEventLimit(), true);
73     tracker->gpuSubhealthEventDay_ = 0;
74     ASSERT_EQ(tracker->CheckGpuSubhealthEventLimit(), true);
75     tracker->gpuSubhealthEventNum_ = 1;
76     tracker->gpuSubhealthEventDay_ = 0xFFFFFFF;
77     ASSERT_EQ(tracker->CheckGpuSubhealthEventLimit(), true);
78     tracker->gpuSubhealthEventDay_ = 0xFFFFFFF;
79     tracker->gpuSubhealthEventNum_ = 0xFFFFFFF;
80     ASSERT_EQ(tracker->CheckGpuSubhealthEventLimit(), false);
81     delete tracker;
82 }
83 
84 /*
85 * Function: GetFrameRate
86 * Type: Function
87 * Rank: Important(2)
88 * EnvConditions: N/A
89 * CaseDescription: 1. call GetFrameRate
90 *                  2. check ret
91 */
92 HWTEST_F(SyncFenceTrackerTest, GetFrameRate001, Function | MediumTest | Level2)
93 {
94     auto tracker = new SyncFenceTracker("GetFrameRate001");
95     tracker->GetFrameRate();
96     for (int32_t i = 0; i < 2; i++) {
97         tracker->frameStartTimes_->push(1);
98     }
99     tracker->GetFrameRate();
100     tracker->frameStartTimes_->push(2);
101     tracker->GetFrameRate();
102     delete tracker;
103 }
104 
105 /*
106 * Function: ReportEventGpuSubhealth
107 * Type: Function
108 * Rank: Important(2)
109 * EnvConditions: N/A
110 * CaseDescription: 1. call ReportEventGpuSubhealth
111 *                  2. check ret
112 */
113 HWTEST_F(SyncFenceTrackerTest, ReportEventGpuSubhealth001, Function | MediumTest | Level2)
114 {
115     auto tracker = new SyncFenceTracker("ReportEventGpuSubhealth001");
116     tracker->handler_ = nullptr;
117     tracker->ReportEventGpuSubhealth(0);
118     delete tracker;
119 }
120 
121 /*
122 * Function: WaitFence
123 * Type: Function
124 * Rank: Important(2)
125 * EnvConditions: N/A
126 * CaseDescription: 1. call WaitFence
127 *                  2. check ret
128 */
129 HWTEST_F(SyncFenceTrackerTest, WaitFence001, Function | MediumTest | Level2)
130 {
131     auto tracker = new SyncFenceTracker("WaitFence001");
132     sptr<SyncFence> fence = new SyncFence(0);
133     tracker->isGpuFence_ = true;
134     tracker->isGpuEnable_ = true;
135     tracker->WaitFence(fence);
136     tracker->isGpuFence_ = true;
137     tracker->isGpuEnable_ = false;
138     tracker->WaitFence(fence);
139     tracker->isGpuFence_ = false;
140     tracker->isGpuEnable_ = true;
141     tracker->WaitFence(fence);
142     tracker->isGpuFence_ = false;
143     tracker->isGpuEnable_ = false;
144     tracker->WaitFence(fence);
145     delete tracker;
146 }
147 
148 /*
149 * Function: SetBlurSize
150 * Type: Function
151 * Rank: Important(2)
152 * EnvConditions: N/A
153 * CaseDescription: 1. call SetBlurSize
154 *                  2. check ret
155 */
156 HWTEST_F(SyncFenceTrackerTest, SetBlurSize001, Function | MediumTest | Level2)
157 {
158     auto tracker = new SyncFenceTracker("SetBlurSize001");
159     tracker->handler_ = nullptr;
160     tracker->SetBlurSize(0);
161     delete tracker;
162 }
163 
164 /*
165 * Function: SetContainerNodeNum
166 * Type: Function
167 * Rank: Important(2)
168 * EnvConditions: N/A
169 * CaseDescription: 1. call SetContainerNodeNum
170 *                  2. check ret
171 */
172 HWTEST_F(SyncFenceTrackerTest, SetContainerNodeNum001, Function | MediumTest | Level2)
173 {
174     auto tracker = new SyncFenceTracker("SetContainerNodeNum001");
175     tracker->isGpuEnable_ = true;
176     tracker->SetContainerNodeNum(0);
177     tracker->isGpuEnable_ = false;
178     tracker->SetContainerNodeNum(0);
179     delete tracker;
180 }
181 }