• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2025 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, Hardware
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 <parameter.h>
17 #include <parameters.h>
18 #include "gtest/gtest.h"
19 
20 #include "EGL/egl.h"
21 #include "EGL/eglext.h"
22 #include "GLES3/gl32.h"
23 
24 #include "draw/color.h"
25 #include "image/gpu_context.h"
26 #include "utils/log.h"
27 
28 #ifdef RS_ENABLE_VK
29 #include "platform/ohos/backend/rs_vulkan_context.h"
30 #endif
31 
32 using namespace testing;
33 using namespace testing::ext;
34 
35 namespace OHOS {
36 namespace Rosen {
37 namespace Drawing {
38 constexpr int32_t EGL_CONTEXT_CLIENT_VERSION_NUM = 2;
39 
40 class ShaderPersistentCache : public GPUContextOptions::PersistentCache {
41 public:
42     ShaderPersistentCache() = default;
43     ~ShaderPersistentCache() override = default;
44 
Load(const Data & key)45     std::shared_ptr<Data> Load(const Data& key) override { return nullptr; };
Store(const Data & key,const Data & data)46     void Store(const Data& key, const Data& data) override {};
47 };
48 
49 class GpuContextTest : public testing::Test {
50 public:
51     static void SetUpTestCase();
52     static void TearDownTestCase();
53     void SetUp() override;
54     void TearDown() override;
55 
56     static void InitEGL();
57     static void DestroyEGL();
58 
59 private:
60     static EGLDisplay eglDisplay_;
61     static EGLContext eglContext_;
62 };
63 
64 EGLDisplay GpuContextTest::eglDisplay_ = EGL_NO_DISPLAY;
65 EGLContext GpuContextTest::eglContext_ = EGL_NO_CONTEXT;
66 
SetUpTestCase()67 void GpuContextTest::SetUpTestCase()
68 {
69 #ifdef RS_ENABLE_VK
70     RsVulkanContext::SetRecyclable(false);
71 #endif
72     InitEGL();
73 }
74 
TearDownTestCase()75 void GpuContextTest::TearDownTestCase()
76 {
77     DestroyEGL();
78 }
79 
SetUp()80 void GpuContextTest::SetUp() {}
TearDown()81 void GpuContextTest::TearDown() {}
82 
InitEGL()83 void GpuContextTest::InitEGL()
84 {
85     LOGI("Creating EGLContext!!!");
86     eglDisplay_ = eglGetDisplay(static_cast<EGLNativeDisplayType>(EGL_DEFAULT_DISPLAY));
87     if (eglDisplay_ == EGL_NO_DISPLAY) {
88         LOGW("Failed to create EGLDisplay gl errno : %{public}x", eglGetError());
89         return;
90     }
91 
92     EGLint major, minor;
93     if (eglInitialize(eglDisplay_, &major, &minor) == EGL_FALSE) {
94         LOGE("Failed to initialize EGLDisplay");
95         return;
96     }
97 
98     if (eglBindAPI(EGL_OPENGL_ES_API) == EGL_FALSE) {
99         LOGE("Failed to bind OpenGL ES API");
100         return;
101     }
102 
103     unsigned int ret;
104     EGLConfig config;
105     EGLint count;
106     EGLint configAttribs[] = { EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8,
107         EGL_ALPHA_SIZE, 8, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT, EGL_NONE };
108 
109     ret = eglChooseConfig(eglDisplay_, configAttribs, &config, 1, &count);
110     if (!(ret && static_cast<unsigned int>(count) >= 1)) {
111         LOGE("Failed to eglChooseConfig");
112         return;
113     }
114 
115     static const EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, EGL_CONTEXT_CLIENT_VERSION_NUM, EGL_NONE };
116 
117     eglContext_ = eglCreateContext(eglDisplay_, config, EGL_NO_CONTEXT, contextAttribs);
118     if (eglContext_ == EGL_NO_CONTEXT) {
119         LOGE("Failed to create egl context %{public}x", eglGetError());
120         return;
121     }
122     if (!eglMakeCurrent(eglDisplay_, EGL_NO_SURFACE, EGL_NO_SURFACE, eglContext_)) {
123         LOGE("Failed to make current on surface, error is %{public}x", eglGetError());
124         return;
125     }
126 
127     LOGI("Create EGL context successfully, version %{public}d.%{public}d", major, minor);
128 }
129 
DestroyEGL()130 void GpuContextTest::DestroyEGL()
131 {
132     if (eglDisplay_ == EGL_NO_DISPLAY) {
133         return;
134     }
135 
136     eglDestroyContext(eglDisplay_, eglContext_);
137     eglMakeCurrent(eglDisplay_, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
138     eglTerminate(eglDisplay_);
139     eglReleaseThread();
140 
141     eglDisplay_ = EGL_NO_DISPLAY;
142     eglContext_ = EGL_NO_CONTEXT;
143 }
144 
145 /**
146  * @tc.name: GPUContextCreateTest001
147  * @tc.desc: Test for creating GPUContext.
148  * @tc.type: FUNC
149  * @tc.require: I774GD
150  */
151 HWTEST_F(GpuContextTest, GPUContextCreateTest001, TestSize.Level1)
152 {
153     std::unique_ptr<GPUContext> gpuContext = std::make_unique<GPUContext>();
154     ASSERT_TRUE(gpuContext != nullptr);
155 }
156 
157 /**
158  * @tc.name: GPUContextCreateTest001
159  * @tc.desc: Test for creating a GL GPUContext for a backend context.
160  * @tc.type: FUNC
161  * @tc.require: I774GD
162  */
163 HWTEST_F(GpuContextTest, BuildFromGLTest001, TestSize.Level1)
164 {
165     std::unique_ptr<GPUContext> gpuContext = std::make_unique<GPUContext>();
166     ASSERT_TRUE(gpuContext != nullptr);
167     GPUContextOptions options;
168     EXPECT_TRUE(gpuContext->BuildFromGL(options));
169 
170     gpuContext->Flush();
171     std::chrono::milliseconds msNotUsed;
172     gpuContext->PerformDeferredCleanup(msNotUsed);
173     int32_t maxResource = 100;
174     size_t maxResourceBytes = 1000;
175     gpuContext->GetResourceCacheLimits(&maxResource, &maxResourceBytes);
176     gpuContext->SetResourceCacheLimits(maxResource, maxResourceBytes);
177 }
178 
179 /**
180  * @tc.name: GPUContextCreateTest002
181  * @tc.desc: Test for creating a GL GPUContext for a backend context.
182  * @tc.type: FUNC
183  * @tc.require: I774GD
184  */
185 HWTEST_F(GpuContextTest, BuildFromGLTest002, TestSize.Level1)
186 {
187     std::unique_ptr<GPUContext> gpuContext = std::make_unique<GPUContext>();
188     ASSERT_TRUE(gpuContext != nullptr);
189     GPUContextOptions options;
190     auto persistentCache = std::make_shared<ShaderPersistentCache>();
191     options.SetPersistentCache(persistentCache.get());
192     EXPECT_TRUE(gpuContext->BuildFromGL(options));
193 }
194 
195 #ifdef RS_ENABLE_VK
196 /**
197  * @tc.name: GPUContextCreateTest003
198  * @tc.desc: Test for creating a VK GPUContext for a backend context.
199  * @tc.type: FUNC
200  * @tc.require: I774GD
201  */
202 HWTEST_F(GpuContextTest, BuildFromVKTest001, TestSize.Level1)
203 {
204     std::unique_ptr<GPUContext> gpuContext = std::make_unique<GPUContext>();
205     ASSERT_TRUE(gpuContext != nullptr);
206 #ifdef USE_M133_SKIA
207     skgpu::VulkanBackendContext grVkBackendContext;
208 #else
209     GrVkBackendContext grVkBackendContext;
210 #endif
211     ASSERT_FALSE(gpuContext->BuildFromVK(grVkBackendContext));
212 }
213 
214 /**
215  * @tc.name: GPUContextCreateTest004
216  * @tc.desc: Test for creating a VK GPUContext for a backend context.
217  * @tc.type: FUNC
218  * @tc.require: I774GD
219  */
220 HWTEST_F(GpuContextTest, BuildFromVKTest002, TestSize.Level1)
221 {
222     std::unique_ptr<GPUContext> gpuContext = std::make_unique<GPUContext>();
223     ASSERT_TRUE(gpuContext != nullptr);
224 #ifdef USE_M133_SKIA
225     skgpu::VulkanBackendContext grVkBackendContext;
226 #else
227     GrVkBackendContext grVkBackendContext;
228 #endif
229     GPUContextOptions options;
230     options.SetAllowPathMaskCaching(true);
231     ASSERT_FALSE(gpuContext->BuildFromVK(grVkBackendContext, options));
232 }
233 
234 /**
235  * @tc.name: GPUContextStoreVkPipelineCacheDataTest001
236  * @tc.desc: Test for storing VK pipeline cache data.
237  * @tc.type: FUNC
238  * @tc.require: I774GD
239  */
240 HWTEST_F(GpuContextTest, GPUContextStoreVkPipelineCacheDataTest001, TestSize.Level1)
241 {
242     std::unique_ptr<GPUContext> gpuContext = std::make_unique<GPUContext>();
243     ASSERT_TRUE(gpuContext != nullptr);
244     gpuContext->StoreVkPipelineCacheData();
245 }
246 #endif
247 
248 /**
249  * @tc.name: FlushTest001
250  * @tc.desc: Test for flushing to underlying 3D API specific objects.
251  * @tc.type: FUNC
252  * @tc.require: I774GD
253  */
254 HWTEST_F(GpuContextTest, FlushTest001, TestSize.Level1)
255 {
256     std::unique_ptr<GPUContext> gpuContext = std::make_unique<GPUContext>();
257     ASSERT_TRUE(gpuContext != nullptr);
258     gpuContext->Flush();
259 }
260 
261 /**
262  * @tc.name: PerformDeferredCleanupTest001
263  * @tc.desc: Test for Purging GPU resources that haven't been used in the past 'msNotUsed' milliseconds.
264  * @tc.type: FUNC
265  * @tc.require: I774GD
266  */
267 HWTEST_F(GpuContextTest, PerformDeferredCleanupTest001, TestSize.Level1)
268 {
269     std::unique_ptr<GPUContext> gpuContext = std::make_unique<GPUContext>();
270     ASSERT_TRUE(gpuContext != nullptr);
271     std::chrono::milliseconds msNotUsed;
272     gpuContext->PerformDeferredCleanup(msNotUsed);
273 }
274 
275 /**
276  * @tc.name: GetResourceCacheLimitsTest001
277  * @tc.desc: Test for geting the current GPU resource cache limits.
278  * @tc.type: FUNC
279  * @tc.require: I774GD
280  */
281 HWTEST_F(GpuContextTest, GetResourceCacheLimitsTest001, TestSize.Level1)
282 {
283     std::unique_ptr<GPUContext> gpuContext = std::make_unique<GPUContext>();
284     ASSERT_TRUE(gpuContext != nullptr);
285     int32_t maxResource = 0;
286     size_t maxResourceBytes = 0;
287     gpuContext->GetResourceCacheLimits(&maxResource, &maxResourceBytes);
288 }
289 
290 /**
291  * @tc.name: GetResourceCacheLimitsTest002
292  * @tc.desc: Test for geting the current GPU resource cache limits.
293  * @tc.type: FUNC
294  * @tc.require: I774GD
295  */
296 HWTEST_F(GpuContextTest, GetResourceCacheLimitsTest002, TestSize.Level1)
297 {
298     std::unique_ptr<GPUContext> gpuContext = std::make_unique<GPUContext>();
299     ASSERT_TRUE(gpuContext != nullptr);
300     int32_t maxResource = 10;
301     size_t maxResourceBytes = 1000;
302     gpuContext->GetResourceCacheLimits(&maxResource, &maxResourceBytes);
303 }
304 
305 /**
306  * @tc.name: SetResourceCacheLimitsTest001
307  * @tc.desc: Test for set specify the GPU resource cache limits.
308  * @tc.type: FUNC
309  * @tc.require: I774GD
310  */
311 HWTEST_F(GpuContextTest, SetResourceCacheLimitsTest001, TestSize.Level1)
312 {
313     std::unique_ptr<GPUContext> gpuContext = std::make_unique<GPUContext>();
314     ASSERT_TRUE(gpuContext != nullptr);
315     int32_t maxResource = 0;
316     size_t maxResourceBytes = 0;
317     gpuContext->SetResourceCacheLimits(maxResource, maxResourceBytes);
318 }
319 
320 /**
321  * @tc.name: SetResourceCacheLimitsTest002
322  * @tc.desc: Test for set specify the GPU resource cache limits.
323  * @tc.type: FUNC
324  * @tc.require: I774GD
325  */
326 HWTEST_F(GpuContextTest, SetResourceCacheLimitsTest002, TestSize.Level1)
327 {
328     std::unique_ptr<GPUContext> gpuContext = std::make_unique<GPUContext>();
329     ASSERT_TRUE(gpuContext != nullptr);
330     int32_t maxResource = 100;
331     size_t maxResourceBytes = 1000;
332     gpuContext->SetResourceCacheLimits(maxResource, maxResourceBytes);
333 }
334 
335 /**
336  * @tc.name: ReleaseResourcesAndAbandonContextTest001
337  * @tc.desc: Test for Purging GPU resources that haven't been used in the past 'msNotUsed' milliseconds.
338  * @tc.type: FUNC
339  * @tc.require: I774GD
340  */
341 HWTEST_F(GpuContextTest, ReleaseResourcesAndAbandonContextTest001, TestSize.Level1)
342 {
343     std::unique_ptr<GPUContext> gpuContext = std::make_unique<GPUContext>();
344     ASSERT_TRUE(gpuContext != nullptr);
345     gpuContext->ReleaseResourcesAndAbandonContext();
346 }
347 
348 /**
349  * @tc.name: PurgeUnlockedResourcesByTagTest001
350  * @tc.desc: Test for Purging GPU resources that haven't been used in the past 'msNotUsed' milliseconds.
351  * @tc.type: FUNC
352  * @tc.require: I774GD
353  */
354 HWTEST_F(GpuContextTest, PurgeUnlockedResourcesByTagTest001, TestSize.Level1)
355 {
356     std::unique_ptr<GPUContext> gpuContext = std::make_unique<GPUContext>();
357     ASSERT_TRUE(gpuContext != nullptr);
358     GPUResourceTag tag(0, 0, 0, 0, "PurgeUnlockedResourcesByTagTest001");
359     gpuContext->PurgeUnlockedResourcesByTag(true, tag);
360 }
361 
362 /**
363  * @tc.name: ReleaseByTagTest001
364  * @tc.desc: Test for Purging GPU resources that haven't been used in the past 'msNotUsed' milliseconds.
365  * @tc.type: FUNC
366  * @tc.require: I774GD
367  */
368 HWTEST_F(GpuContextTest, ReleaseByTagTest001, TestSize.Level1)
369 {
370     std::unique_ptr<GPUContext> gpuContext = std::make_unique<GPUContext>();
371     ASSERT_TRUE(gpuContext != nullptr);
372     GPUResourceTag tag(0, 0, 0, 0, "ReleaseByTagTest001");
373     gpuContext->ReleaseByTag(tag);
374 }
375 
376 /**
377  * @tc.name: FlushAndSubmitTest001
378  * @tc.desc: Test for flushing and submitting.
379  * @tc.type: FUNC
380  * @tc.require: I774GD
381  */
382 HWTEST_F(GpuContextTest, FlushAndSubmitTest001, TestSize.Level1)
383 {
384     std::unique_ptr<GPUContext> gpuContext = std::make_unique<GPUContext>();
385     ASSERT_TRUE(gpuContext != nullptr);
386     gpuContext->FlushAndSubmit();
387 }
388 
389 /**
390  * @tc.name: GetResourceCacheUsageTest001
391  * @tc.desc: Test for getting resource cache usage.
392  * @tc.type: FUNC
393  * @tc.require: I774GD
394  */
395 HWTEST_F(GpuContextTest, GetResourceCacheUsageTest001, TestSize.Level1)
396 {
397     std::unique_ptr<GPUContext> gpuContext = std::make_unique<GPUContext>();
398     ASSERT_TRUE(gpuContext != nullptr);
399     int resourceCount;
400     size_t resourceBytes;
401     gpuContext->GetResourceCacheUsage(&resourceCount, &resourceBytes);
402 }
403 
404 /**
405  * @tc.name: DumpGpuStatsTest001
406  * @tc.desc: Test for dumping gpu stats.
407  * @tc.type: FUNC
408  * @tc.require: I774GD
409  */
410 HWTEST_F(GpuContextTest, DumpGpuStatsTest001, TestSize.Level1)
411 {
412     std::unique_ptr<GPUContext> gpuContext = std::make_unique<GPUContext>();
413     ASSERT_TRUE(gpuContext != nullptr);
414     std::string out;
415     gpuContext->DumpGpuStats(out);
416 }
417 
418 /**
419  * @tc.name: PurgeUnlockedResourcesTest001
420  * @tc.desc: Test for purging unlocked resources.
421  * @tc.type: FUNC
422  * @tc.require: I774GD
423  */
424 HWTEST_F(GpuContextTest, PurgeUnlockedResourcesTest001, TestSize.Level1)
425 {
426     std::unique_ptr<GPUContext> gpuContext = std::make_unique<GPUContext>();
427     ASSERT_TRUE(gpuContext != nullptr);
428     gpuContext->PurgeUnlockedResources(true);
429     gpuContext->PurgeUnlockedResources(false);
430 }
431 
432 /**
433  * @tc.name: PurgeUnlockedResourcesByPidTest001
434  * @tc.desc: Test for purging unlocked resources by pid.
435  * @tc.type: FUNC
436  * @tc.require: I774GD
437  */
438 HWTEST_F(GpuContextTest, PurgeUnlockedResourcesByPidTest001, TestSize.Level1)
439 {
440     std::unique_ptr<GPUContext> gpuContext = std::make_unique<GPUContext>();
441     ASSERT_TRUE(gpuContext != nullptr);
442     std::set<pid_t> exitedPidSet = { 0, 1, 100 };
443     gpuContext->PurgeUnlockedResourcesByPid(true, exitedPidSet);
444     gpuContext->PurgeUnlockedResourcesByPid(false, exitedPidSet);
445 }
446 
447 /**
448  * @tc.name: PurgeUnlockAndSafeCacheGpuResourcesTest001
449  * @tc.desc: Test for purging unlocked and safe resources.
450  * @tc.type: FUNC
451  * @tc.require: I774GD
452  */
453 HWTEST_F(GpuContextTest, PurgeUnlockAndSafeCacheGpuResourcesTest001, TestSize.Level1)
454 {
455     std::unique_ptr<GPUContext> gpuContext = std::make_unique<GPUContext>();
456     ASSERT_TRUE(gpuContext != nullptr);
457     gpuContext->PurgeUnlockAndSafeCacheGpuResources();
458 }
459 
460 /**
461  * @tc.name: PurgeCacheBetweenFramesTest001
462  * @tc.desc: Test for purging cache betweem frames.
463  * @tc.type: FUNC
464  * @tc.require: I774GD
465  */
466 HWTEST_F(GpuContextTest, PurgeCacheBetweenFramesTest001, TestSize.Level1)
467 {
468     std::unique_ptr<GPUContext> gpuContext = std::make_unique<GPUContext>();
469     ASSERT_TRUE(gpuContext != nullptr);
470     std::set<pid_t> exitedPidSet = { 0, 1, 100 };
471     std::set<pid_t> protectedPidSet = { 0, 1 };
472     gpuContext->PurgeCacheBetweenFrames(true, exitedPidSet, protectedPidSet);
473     gpuContext->PurgeCacheBetweenFrames(false, exitedPidSet, protectedPidSet);
474 }
475 
476 /**
477  * @tc.name: DumpMemoryStatisticsByTagTest001
478  * @tc.desc: Test for dumping memory statistics by tag.
479  * @tc.type: FUNC
480  * @tc.require: I774GD
481  */
482 HWTEST_F(GpuContextTest, DumpMemoryStatisticsByTagTest001, TestSize.Level1)
483 {
484     std::unique_ptr<GPUContext> gpuContext = std::make_unique<GPUContext>();
485     ASSERT_TRUE(gpuContext != nullptr);
486     TraceMemoryDump traceMemoryDump("category", true);
487     GPUResourceTag tag(0, 0, 0, 0, "tag");
488     gpuContext->DumpMemoryStatisticsByTag(&traceMemoryDump, tag);
489     gpuContext->DumpMemoryStatisticsByTag(nullptr, tag);
490 }
491 
492 /**
493  * @tc.name: DumpMemoryStatisticsTest001
494  * @tc.desc: Test for dumping memory statistics.
495  * @tc.type: FUNC
496  * @tc.require: I774GD
497  */
498 HWTEST_F(GpuContextTest, DumpMemoryStatisticsTest001, TestSize.Level1)
499 {
500     std::unique_ptr<GPUContext> gpuContext = std::make_unique<GPUContext>();
501     ASSERT_TRUE(gpuContext != nullptr);
502     TraceMemoryDump traceMemoryDump("category", true);
503     gpuContext->DumpMemoryStatistics(&traceMemoryDump);
504 }
505 
506 /**
507  * @tc.name: GetUpdatedMemoryMapTest001
508  * @tc.desc: Test for getting updated memory map.
509  * @tc.type: FUNC
510  * @tc.require: I774GD
511  */
512 HWTEST_F(GpuContextTest, GetUpdatedMemoryMapTest001, TestSize.Level1)
513 {
514     std::unique_ptr<GPUContext> gpuContext = std::make_unique<GPUContext>();
515     ASSERT_TRUE(gpuContext != nullptr);
516     std::unordered_map<pid_t, size_t> out;
517     gpuContext->GetUpdatedMemoryMap(out);
518 }
519 
520 /**
521  * @tc.name: InitGpuMemoryLimitTest001
522  * @tc.desc: Test for initiating gpu memory limit.
523  * @tc.type: FUNC
524  * @tc.require: I774GD
525  */
526 HWTEST_F(GpuContextTest, InitGpuMemoryLimitTest001, TestSize.Level1)
527 {
528     std::unique_ptr<GPUContext> gpuContext = std::make_unique<GPUContext>();
529     ASSERT_TRUE(gpuContext != nullptr);
530     uint64_t size = 1024 * 2;
531     gpuContext->InitGpuMemoryLimit(nullptr, size);
532 }
533 
534 /**
535  * @tc.name: ResetContextTest001
536  * @tc.desc: Test for resetting context.
537  * @tc.type: FUNC
538  * @tc.require: I774GD
539  */
540 HWTEST_F(GpuContextTest, ResetContextTest001, TestSize.Level1)
541 {
542     std::unique_ptr<GPUContext> gpuContext = std::make_unique<GPUContext>();
543     ASSERT_TRUE(gpuContext != nullptr);
544     gpuContext->ResetContext();
545 }
546 
547 /**
548  * @tc.name: VmaDefragmentTest001
549  * @tc.desc: Test for vma defragment.
550  * @tc.type: FUNC
551  * @tc.require: I774GD
552  */
553 HWTEST_F(GpuContextTest, VmaDefragmentTest001, TestSize.Level1)
554 {
555     std::unique_ptr<GPUContext> gpuContext = std::make_unique<GPUContext>();
556     ASSERT_TRUE(gpuContext != nullptr);
557     gpuContext->VmaDefragment();
558 }
559 
560 /**
561  * @tc.name: BeginFrameTest001
562  * @tc.desc: Test for beginning frame.
563  * @tc.type: FUNC
564  * @tc.require: I774GD
565  */
566 HWTEST_F(GpuContextTest, BeginFrameTest001, TestSize.Level1)
567 {
568     std::unique_ptr<GPUContext> gpuContext = std::make_unique<GPUContext>();
569     ASSERT_TRUE(gpuContext != nullptr);
570     gpuContext->BeginFrame();
571 }
572 
573 /**
574  * @tc.name: EndFrameTest001
575  * @tc.desc: Test for ending frame.
576  * @tc.type: FUNC
577  * @tc.require: I774GD
578  */
579 HWTEST_F(GpuContextTest, EndFrameTest001, TestSize.Level1)
580 {
581     std::unique_ptr<GPUContext> gpuContext = std::make_unique<GPUContext>();
582     ASSERT_TRUE(gpuContext != nullptr);
583     gpuContext->EndFrame();
584 }
585 
586 /**
587  * @tc.name: SetGpuCacheSuppressWindowSwitchTest001
588  * @tc.desc: Test for setting gpu cache suppress window switch.
589  * @tc.type: FUNC
590  * @tc.require: I774GD
591  */
592 HWTEST_F(GpuContextTest, SetGpuCacheSuppressWindowSwitchTest001, TestSize.Level1)
593 {
594     std::unique_ptr<GPUContext> gpuContext = std::make_unique<GPUContext>();
595     ASSERT_TRUE(gpuContext != nullptr);
596     gpuContext->SetGpuCacheSuppressWindowSwitch(true);
597     gpuContext->SetGpuCacheSuppressWindowSwitch(false);
598 }
599 
600 /**
601  * @tc.name: SetGpuMemoryAsyncReclaimerSwitchTest001
602  * @tc.desc: Test for setting gpu memory async reclaimer switch.
603  * @tc.type: FUNC
604  * @tc.require: I774GD
605  */
606 HWTEST_F(GpuContextTest, SetGpuMemoryAsyncReclaimerSwitchTest001, TestSize.Level1)
607 {
608     std::unique_ptr<GPUContext> gpuContext = std::make_unique<GPUContext>();
609     ASSERT_TRUE(gpuContext != nullptr);
610     gpuContext->SetGpuMemoryAsyncReclaimerSwitch(true, nullptr);
611     gpuContext->SetGpuMemoryAsyncReclaimerSwitch(false, nullptr);
612 }
613 
614 /**
615  * @tc.name: FlushGpuMemoryInWaitQueueTest001
616  * @tc.desc: Test for flushing gpu memory in wait queue.
617  * @tc.type: FUNC
618  * @tc.require: I774GD
619  */
620 HWTEST_F(GpuContextTest, FlushGpuMemoryInWaitQueueTest001, TestSize.Level1)
621 {
622     std::unique_ptr<GPUContext> gpuContext = std::make_unique<GPUContext>();
623     ASSERT_TRUE(gpuContext != nullptr);
624     gpuContext->FlushGpuMemoryInWaitQueue();
625 }
626 
627 /**
628  * @tc.name: SuppressGpuCacheBelowCertainRatioTest001
629  * @tc.desc: Test for suppressing gpu cache below certain ratio.
630  * @tc.type: FUNC
631  * @tc.require: I774GD
632  */
633 HWTEST_F(GpuContextTest, SuppressGpuCacheBelowCertainRatioTest001, TestSize.Level1)
634 {
635     std::unique_ptr<GPUContext> gpuContext = std::make_unique<GPUContext>();
636     ASSERT_TRUE(gpuContext != nullptr);
637     gpuContext->SuppressGpuCacheBelowCertainRatio(nullptr);
638 }
639 
640 /**
641  * @tc.name: GetHpsEffectSupportTest001
642  * @tc.desc: Test for get HPS effect support status.
643  * @tc.type: FUNC
644  * @tc.require: I774GD
645 */
646 HWTEST_F(GpuContextTest, GetHpsEffectSupportTest001, TestSize.Level1)
647 {
648     std::unique_ptr<GPUContext> gpuContext = std::make_unique<GPUContext>();
649     ASSERT_TRUE(gpuContext != nullptr);
650     std::vector<const char*> extensionProperties;
651     gpuContext->GetHpsEffectSupport(extensionProperties);
652 }
653 
654 /**
655  * @tc.name: RegisterVulkanErrorCallbackTest001
656  * @tc.desc: Test for register vulkan error callback.
657  * @tc.type: FUNC
658  * @tc.require: IBOLWU
659  */
660 HWTEST_F(GpuContextTest, RegisterVulkanErrorCallbackTest001, TestSize.Level1)
661 {
662     std::unique_ptr<GPUContext> gpuContext = std::make_unique<GPUContext>();
663     ASSERT_TRUE(gpuContext != nullptr);
664     gpuContext->RegisterVulkanErrorCallback(nullptr);
665 }
666 
667 /**
668  * @tc.name: SetEarlyZFlagTest001
669  * @tc.desc: Test for set earlyz flag function.
670  * @tc.type: FUNC
671  * @tc.require: IBOLWU
672  */
673 HWTEST_F(GpuContextTest, SetEarlyZFlagTest001, TestSize.Level1)
674 {
675     std::unique_ptr<GPUContext> gpuContext = std::make_unique<GPUContext>();
676     ASSERT_TRUE(gpuContext != nullptr);
677     gpuContext->SetEarlyZEnabled(true);
678 }
679 
680 /**
681  * @tc.name: GenerateSubmitInfoTest
682  * @tc.desc: Test for GenerateSubmitInfo
683  * @tc.type: FUNC
684  * @tc.require: IC8TIV
685  */
686 HWTEST_F(GpuContextTest, GenerateSubmitInfoTest, TestSize.Level1)
687 {
688     auto gpuContext = std::make_unique<GPUContext>();
689     ASSERT_TRUE(gpuContext != nullptr);
690     gpuContext->GenerateSubmitInfo(0);
691 }
692 
693 /**
694  * @tc.name: FlushCommandsTest
695  * @tc.desc: Test for FlushCommands
696  * @tc.type: FUNC
697  * @tc.require: IC8TIV
698  */
699 HWTEST_F(GpuContextTest, FlushCommandsTest, TestSize.Level1)
700 {
701     auto gpuContext = std::make_unique<GPUContext>();
702     ASSERT_TRUE(gpuContext != nullptr);
703     gpuContext->FlushCommands();
704 }
705 
706 /**
707  * @tc.name: NewDumpMemoryStatisticsByTagTest
708  * @tc.desc: Test for dumping memory statistics by tag.
709  * @tc.type: FUNC
710  * @tc.require: ICR0OD
711  */
712 HWTEST_F(GpuContextTest, NewDumpMemoryStatisticsByTagTest, TestSize.Level1)
713 {
714     std::unique_ptr<GPUContext> gpuContext = std::make_unique<GPUContext>();
715     ASSERT_TRUE(gpuContext != nullptr);
716     TraceMemoryDump traceMemoryDump("category", true);
717     GPUResourceTag tag(0, 0, 0, 0, "tag");
718     gpuContext->NewDumpMemoryStatisticsByTag(&traceMemoryDump, tag);
719     gpuContext->NewDumpMemoryStatisticsByTag(nullptr, tag);
720 }
721 } // namespace Drawing
722 } // namespace Rosen
723 } // namespace OHOS
724