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