• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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(nullptr, true);
51     EXPECT_EQ(tracker->fencesQueued_.load(), 0);
52 
53     tracker->TrackFence(fence, true);
54     EXPECT_EQ(tracker->fencesQueued_.load(), 1);
55 
56     tracker->isGpuFence_ = true;
57     tracker->TrackFence(fence, true);
58     EXPECT_EQ(tracker->fencesQueued_.load(), 2);
59 
60     tracker->TrackFence(fence, false);
61     EXPECT_EQ(tracker->fencesQueued_.load(), 2);
62 
63     tracker->isGpuFence_ = false;
64     tracker->TrackFence(fence, true);
65     EXPECT_EQ(tracker->fencesQueued_.load(), 3);
66 
67     tracker->TrackFence(fence, false);
68     EXPECT_EQ(tracker->fencesQueued_.load(), 4);
69     delete tracker;
70 }
71 
72 /*
73 * Function: CheckGpuSubhealthEventLimit
74 * Type: Function
75 * Rank: Important(2)
76 * EnvConditions: N/A
77 * CaseDescription: 1. call CheckGpuSubhealthEventLimit
78 *                  2. check ret
79 */
80 HWTEST_F(SyncFenceTrackerTest, CheckGpuSubhealthEventLimit001, Function | MediumTest | Level2)
81 {
82     auto tracker = new SyncFenceTracker("CheckGpuSubhealthEventLimit001");
83     tracker->gpuSubhealthEventNum_ = 0;
84     ASSERT_EQ(tracker->CheckGpuSubhealthEventLimit(), true);
85     tracker->gpuSubhealthEventDay_ = 0;
86     ASSERT_EQ(tracker->CheckGpuSubhealthEventLimit(), true);
87     tracker->gpuSubhealthEventNum_ = 1;
88     tracker->gpuSubhealthEventDay_ = 0xFFFFFFF;
89     ASSERT_EQ(tracker->CheckGpuSubhealthEventLimit(), true);
90     tracker->gpuSubhealthEventDay_ = 0xFFFFFFF;
91     tracker->gpuSubhealthEventNum_ = 0xFFFFFFF;
92     ASSERT_EQ(tracker->CheckGpuSubhealthEventLimit(), false);
93     delete tracker;
94 }
95 
96 /*
97 * Function: GetFrameRate
98 * Type: Function
99 * Rank: Important(2)
100 * EnvConditions: N/A
101 * CaseDescription: 1. call GetFrameRate
102 *                  2. check ret
103 */
104 HWTEST_F(SyncFenceTrackerTest, GetFrameRate001, Function | MediumTest | Level2)
105 {
106     auto tracker = new SyncFenceTracker("GetFrameRate001");
107     int32_t frameRate = tracker->GetFrameRate();
108     EXPECT_EQ(frameRate, 0);
109 
110     for (int32_t i = 0; i < 2; i++) {
111         tracker->frameStartTimes_->push(1);
112     }
113     frameRate = tracker->GetFrameRate();
114     EXPECT_EQ(frameRate, 0);
115 
116     tracker->frameStartTimes_->push(2);
117     frameRate = tracker->GetFrameRate();
118     EXPECT_EQ(frameRate, 2000);
119 
120     delete tracker;
121 }
122 
123 /*
124 * Function: ReportEventGpuSubhealth
125 * Type: Function
126 * Rank: Important(2)
127 * EnvConditions: N/A
128 * CaseDescription: 1. call ReportEventGpuSubhealth
129 *                  2. check ret
130 */
131 HWTEST_F(SyncFenceTrackerTest, ReportEventGpuSubhealth001, Function | MediumTest | Level2)
132 {
133     auto tracker = new SyncFenceTracker("ReportEventGpuSubhealth001");
134     EXPECT_NE(tracker->handler_, nullptr);
135     tracker->ReportEventGpuSubhealth(0);
136     tracker->handler_ = nullptr;
137     tracker->ReportEventGpuSubhealth(0);
138     delete tracker;
139 }
140 
141 /*
142 * Function: WaitFence
143 * Type: Function
144 * Rank: Important(2)
145 * EnvConditions: N/A
146 * CaseDescription: 1. call WaitFence
147 *                  2. check ret
148 */
149 HWTEST_F(SyncFenceTrackerTest, WaitFence001, Function | MediumTest | Level2)
150 {
151     auto tracker = new SyncFenceTracker("WaitFence001");
152     auto fence = SyncFence::INVALID_FENCE;
153 
154     tracker->isGpuFence_ = true;
155     tracker->isGpuEnable_ = true;
156     int32_t retCode = tracker->WaitFence(fence);
157     EXPECT_EQ(retCode, -1);
158 
159     tracker->isGpuFence_ = true;
160     tracker->isGpuEnable_ = false;
161     tracker->WaitFence(fence);
162     EXPECT_EQ(retCode, -1);
163 
164     tracker->isGpuFence_ = false;
165     tracker->isGpuEnable_ = true;
166     tracker->WaitFence(fence);
167     EXPECT_EQ(retCode, -1);
168 
169     tracker->isGpuFence_ = false;
170     tracker->isGpuEnable_ = false;
171     tracker->WaitFence(fence);
172     EXPECT_EQ(retCode, -1);
173 
174     delete tracker;
175 }
176 
177 /*
178 * Function: SetBlurSize
179 * Type: Function
180 * Rank: Important(2)
181 * EnvConditions: N/A
182 * CaseDescription: 1. call SetBlurSize
183 *                  2. check ret
184 */
185 HWTEST_F(SyncFenceTrackerTest, SetBlurSize001, Function | MediumTest | Level2)
186 {
187     auto tracker = new SyncFenceTracker("SetBlurSize001");
188     tracker->handler_ = nullptr;
189     ASSERT_EQ(tracker->handler_, nullptr);
190     tracker->SetBlurSize(0);
191     delete tracker;
192 }
193 
194 /*
195 * Function: SetContainerNodeNum
196 * Type: Function
197 * Rank: Important(2)
198 * EnvConditions: N/A
199 * CaseDescription: 1. call SetContainerNodeNum
200 *                  2. check ret
201 */
202 HWTEST_F(SyncFenceTrackerTest, SetContainerNodeNum001, Function | MediumTest | Level2)
203 {
204     auto tracker = new SyncFenceTracker("SetContainerNodeNum001");
205     tracker->isGpuEnable_ = true;
206     tracker->processedNodeNum_ = 0;
207     tracker->SetContainerNodeNum(1);
208     EXPECT_EQ(tracker->processedNodeNum_, 1);
209 
210     tracker->isGpuEnable_ = false;
211     tracker->SetContainerNodeNum(1);
212     EXPECT_EQ(tracker->processedNodeNum_, 1);
213 
214     delete tracker;
215 }
216 }