• 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 <cstddef>
17 #include "gtest/gtest.h"
18 #include "skia_adapter/skia_gpu_context.h"
19 #include "text/font.h"
20 #ifdef USE_M133_SKIA
21 #include "include/gpu/ganesh/mock/GrMockTypes.h"
22 #endif
23 
24 using namespace testing;
25 using namespace testing::ext;
26 
27 namespace OHOS {
28 namespace Rosen {
29 namespace Drawing {
30 class SkiaGPUContextTest : public testing::Test {
31 public:
32     static void SetUpTestCase();
33     static void TearDownTestCase();
34     void SetUp() override;
35     void TearDown() override;
36 };
37 
SetUpTestCase()38 void SkiaGPUContextTest::SetUpTestCase() {}
TearDownTestCase()39 void SkiaGPUContextTest::TearDownTestCase() {}
SetUp()40 void SkiaGPUContextTest::SetUp() {}
TearDown()41 void SkiaGPUContextTest::TearDown() {}
42 
43 #ifdef RS_ENABLE_VK
44 /**
45  * @tc.name: BuildFromVK001
46  * @tc.desc: Test BuildFromVK
47  * @tc.type: FUNC
48  * @tc.require: I91F9L
49  */
50 HWTEST_F(SkiaGPUContextTest, BuildFromVK001, TestSize.Level1)
51 {
52     auto gpuContext = std::make_shared<SkiaGPUContext>();
53     ASSERT_TRUE(gpuContext != nullptr);
54     GrVkBackendContext grVkBackendContext;
55     gpuContext->BuildFromVK(grVkBackendContext);
56 }
57 
58 /**
59  * @tc.name: storeVkPipelineCacheData001
60  * @tc.desc: Test storeVkPipelineCacheData
61  * @tc.type: FUNC
62  * @tc.require: I91F9L
63  */
64 HWTEST_F(SkiaGPUContextTest, storeVkPipelineCacheData001, TestSize.Level1)
65 {
66     auto gpuContext = std::make_shared<SkiaGPUContext>();
67     ASSERT_TRUE(gpuContext != nullptr);
68     gpuContext->storeVkPipelineCacheData();
69     GrMockOptions options;
70     gpuContext->SetGrContext(GrDirectContext::MakeMock(&options));
71     gpuContext->storeVkPipelineCacheData();
72 }
73 #endif
74 
75 /**
76  * @tc.name: GetResourceCacheUsage001
77  * @tc.desc: Test GetResourceCacheUsage
78  * @tc.type: FUNC
79  * @tc.require: I91F9L
80  */
81 HWTEST_F(SkiaGPUContextTest, GetResourceCacheUsage001, TestSize.Level1)
82 {
83     auto gpuContext = std::make_shared<SkiaGPUContext>();
84     ASSERT_TRUE(gpuContext != nullptr);
85     gpuContext->GetResourceCacheUsage(nullptr, nullptr);
86     GrMockOptions options;
87     gpuContext->SetGrContext(GrDirectContext::MakeMock(&options));
88     int resourceCount = 1;
89     size_t resourceBytes = 1;
90     gpuContext->GetResourceCacheUsage(&resourceCount, &resourceBytes);
91 }
92 
93 /**
94  * @tc.name: FreeGpuResources001
95  * @tc.desc: Test FreeGpuResources
96  * @tc.type: FUNC
97  * @tc.require: I91F9L
98  */
99 HWTEST_F(SkiaGPUContextTest, FreeGpuResources001, TestSize.Level1)
100 {
101     auto gpuContext = std::make_shared<SkiaGPUContext>();
102     ASSERT_TRUE(gpuContext != nullptr);
103     gpuContext->FreeGpuResources();
104 }
105 
106 /**
107  * @tc.name: DumpGpuStats001
108  * @tc.desc: Test DumpGpuStats
109  * @tc.type: FUNC
110  * @tc.require: I91F9L
111  */
112 HWTEST_F(SkiaGPUContextTest, DumpGpuStats001, TestSize.Level1)
113 {
114     auto gpuContext = std::make_shared<SkiaGPUContext>();
115     ASSERT_TRUE(gpuContext != nullptr);
116     std::string out = "11";
117     gpuContext->DumpGpuStats(out);
118 }
119 
120 /**
121  * @tc.name: ReleaseResourcesAndAbandonContext001
122  * @tc.desc: Test ReleaseResourcesAndAbandonContext
123  * @tc.type: FUNC
124  * @tc.require: I91F9L
125  */
126 HWTEST_F(SkiaGPUContextTest, ReleaseResourcesAndAbandonContext001, TestSize.Level1)
127 {
128     auto gpuContext = std::make_shared<SkiaGPUContext>();
129     ASSERT_TRUE(gpuContext != nullptr);
130     gpuContext->ReleaseResourcesAndAbandonContext();
131     GrMockOptions options;
132     gpuContext->SetGrContext(GrDirectContext::MakeMock(&options));
133     gpuContext->ReleaseResourcesAndAbandonContext();
134 }
135 
136 /**
137  * @tc.name: PurgeUnlockedResources001
138  * @tc.desc: Test PurgeUnlockedResources
139  * @tc.type: FUNC
140  * @tc.require: I91F9L
141  */
142 HWTEST_F(SkiaGPUContextTest, PurgeUnlockedResources001, TestSize.Level1)
143 {
144     auto gpuContext = std::make_shared<SkiaGPUContext>();
145     ASSERT_TRUE(gpuContext != nullptr);
146     gpuContext->PurgeUnlockedResources(true);
147 }
148 
149 /**
150  * @tc.name: PurgeUnlockedResourcesByTag001
151  * @tc.desc: Test PurgeUnlockedResourcesByTag
152  * @tc.type: FUNC
153  * @tc.require: I91F9L
154  */
155 HWTEST_F(SkiaGPUContextTest, PurgeUnlockedResourcesByTag001, TestSize.Level1)
156 {
157     auto gpuContext = std::make_shared<SkiaGPUContext>();
158     ASSERT_TRUE(gpuContext != nullptr);
159     GPUResourceTag tag;
160     gpuContext->PurgeUnlockedResourcesByTag(true, tag);
161 }
162 
163 /**
164  * @tc.name: PurgeUnlockedResourcesByPid001
165  * @tc.desc: Test PurgeUnlockedResourcesByPid
166  * @tc.type: FUNC
167  * @tc.require: I91F9L
168  */
169 HWTEST_F(SkiaGPUContextTest, PurgeUnlockedResourcesByPid001, TestSize.Level1)
170 {
171     auto gpuContext = std::make_shared<SkiaGPUContext>();
172     ASSERT_TRUE(gpuContext != nullptr);
173     GPUResourceTag tag;
174     std::set<pid_t> pidset;
175     gpuContext->PurgeUnlockedResourcesByPid(true, pidset);
176     GrMockOptions options;
177     gpuContext->SetGrContext(GrDirectContext::MakeMock(&options));
178     gpuContext->PurgeUnlockedResourcesByPid(true, pidset);
179 }
180 
181 /**
182  * @tc.name: PurgeUnlockAndSafeCacheGpuResources001
183  * @tc.desc: Test PurgeUnlockAndSafeCacheGpuResources
184  * @tc.type: FUNC
185  * @tc.require: I91F9L
186  */
187 HWTEST_F(SkiaGPUContextTest, PurgeUnlockAndSafeCacheGpuResources001, TestSize.Level1)
188 {
189     auto gpuContext = std::make_shared<SkiaGPUContext>();
190     ASSERT_TRUE(gpuContext != nullptr);
191     gpuContext->PurgeUnlockAndSafeCacheGpuResources();
192 }
193 
194 /**
195  * @tc.name: Submit001
196  * @tc.desc: Test Submit
197  * @tc.type: FUNC
198  * @tc.require: I91F9L
199  */
200 HWTEST_F(SkiaGPUContextTest, Submit001, TestSize.Level1)
201 {
202     auto gpuContext = std::make_shared<SkiaGPUContext>();
203     ASSERT_TRUE(gpuContext != nullptr);
204     gpuContext->Submit();
205 }
206 
207 /**
208  * @tc.name: ReleaseByTag001
209  * @tc.desc: Test ReleaseByTag
210  * @tc.type: FUNC
211  * @tc.require: I91F9L
212  */
213 HWTEST_F(SkiaGPUContextTest, ReleaseByTag001, TestSize.Level1)
214 {
215     auto gpuContext = std::make_shared<SkiaGPUContext>();
216     ASSERT_TRUE(gpuContext != nullptr);
217     GPUResourceTag tag;
218     gpuContext->ReleaseByTag(tag);
219 }
220 
221 /**
222  * @tc.name: DumpMemoryStatisticsByTag001
223  * @tc.desc: Test DumpMemoryStatisticsByTag
224  * @tc.type: FUNC
225  * @tc.require: I91F9L
226  */
227 HWTEST_F(SkiaGPUContextTest, DumpMemoryStatisticsByTag001, TestSize.Level1)
228 {
229     auto gpuContext = std::make_shared<SkiaGPUContext>();
230     ASSERT_TRUE(gpuContext != nullptr);
231     GPUResourceTag tag;
232     gpuContext->DumpMemoryStatisticsByTag(nullptr, tag);
233     gpuContext->SetGrContext(nullptr);
234     gpuContext->DumpMemoryStatisticsByTag(nullptr, tag);
235 }
236 
237 /**
238  * @tc.name: DumpMemoryStatistics001
239  * @tc.desc: Test DumpMemoryStatistics
240  * @tc.type: FUNC
241  * @tc.require: I91F9L
242  */
243 HWTEST_F(SkiaGPUContextTest, DumpMemoryStatistics001, TestSize.Level1)
244 {
245     auto gpuContext = std::make_shared<SkiaGPUContext>();
246     ASSERT_TRUE(gpuContext != nullptr);
247     gpuContext->DumpMemoryStatistics(nullptr);
248 }
249 
250 /**
251  * @tc.name: RegisterVulkanErrorCallback001
252  * @tc.desc: Test RegisterVulkanErrorCallback
253  * @tc.type: FUNC
254  * @tc.require: IBOLWU
255  */
256 HWTEST_F(SkiaGPUContextTest, RegisterVulkanErrorCallback001, TestSize.Level1)
257 {
258     auto gpuContext = std::make_shared<SkiaGPUContext>();
259     ASSERT_TRUE(gpuContext != nullptr);
260     gpuContext->RegisterVulkanErrorCallback(nullptr);
261 }
262 
263 /**
264  * @tc.name: SetEarlyZFlagTest001
265  * @tc.desc: Test SetEarlyZEnabled
266  * @tc.type: FUNC
267  * @tc.require: IBOLWU
268  */
269 HWTEST_F(SkiaGPUContextTest, SetEarlyZFlagTest001, TestSize.Level1)
270 {
271     auto gpuContext = std::make_shared<SkiaGPUContext>();
272     ASSERT_TRUE(gpuContext != nullptr);
273     gpuContext->SetEarlyZEnabled(true);
274 }
275 
276 /**
277  * @tc.name: SetCurrentGpuResourceTag001
278  * @tc.desc: Test SetCurrentGpuResourceTag
279  * @tc.type: FUNC
280  * @tc.require: I91F9L
281  */
282 HWTEST_F(SkiaGPUContextTest, SetCurrentGpuResourceTag001, TestSize.Level1)
283 {
284     auto gpuContext = std::make_shared<SkiaGPUContext>();
285     ASSERT_TRUE(gpuContext != nullptr);
286     GPUResourceTag gPUResourceTag;
287     gpuContext->SetCurrentGpuResourceTag(gPUResourceTag);
288 }
289 
290 /**
291  * @tc.name: GetCurrentGpuResourceTag001
292  * @tc.desc: Test GetCurrentGpuResourceTag
293  * @tc.type: FUNC
294  * @tc.require:
295  */
296 HWTEST_F(SkiaGPUContextTest, GetCurrentGpuResourceTag001, TestSize.Level1)
297 {
298     auto gpuContext = std::make_shared<SkiaGPUContext>();
299     ASSERT_TRUE(gpuContext != nullptr);
300     GPUResourceTag gPUResourceTag;
301     gpuContext->SetCurrentGpuResourceTag(gPUResourceTag);
302     GPUResourceTag tagGet = gpuContext->GetCurrentGpuResourceTag();
303     ASSERT_TRUE(tagGet.fPid == gPUResourceTag.fPid);
304     ASSERT_TRUE(tagGet.fTid == gPUResourceTag.fTid);
305     ASSERT_TRUE(tagGet.fWid == gPUResourceTag.fWid);
306     ASSERT_TRUE(tagGet.fFid == gPUResourceTag.fFid);
307     ASSERT_TRUE(tagGet.fSid == gPUResourceTag.fSid);
308 }
309 
310 } // namespace Drawing
311 } // namespace Rosen
312 } // namespace OHOS