• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 #include "display_buffer_ut.h"
16 #include <securec.h>
17 
18 #include "gtest/gtest.h"
19 #include "v1_2/display_buffer_type.h"
20 #include "v1_2/display_composer_type.h"
21 #include "hdf_base.h"
22 #include "hdf_log.h"
23 
24 namespace OHOS {
25 namespace HDI {
26 namespace Display {
27 namespace TEST {
28 using namespace testing::ext;
29 using namespace OHOS::HDI::Display::Composer::V1_2;
30 using namespace OHOS::HDI::Display::Buffer::V1_1;
31 using OHOS::HDI::Display::Buffer::V1_0::AllocInfo;
32 using OHOS::HDI::Display::Composer::V1_2::HBM_USE_MEM_DMA;
33 using OHOS::HDI::Display::Composer::V1_2::HBM_USE_CPU_READ;
34 using OHOS::HDI::Display::Composer::V1_2::HBM_USE_CPU_WRITE;
35 using OHOS::HDI::Display::Composer::V1_1::PIXEL_FMT_RGBX_8888;
36 using OHOS::HDI::Display::Composer::V1_1::PIXEL_FMT_RGBA_8888;
37 using OHOS::HDI::Display::Composer::V1_1::PIXEL_FMT_BGRA_8888;
38 using OHOS::HDI::Display::Composer::V1_1::PIXEL_FMT_YCBCR_420_SP;
39 using OHOS::HDI::Display::Composer::V1_1::PIXEL_FMT_YCRCB_420_SP;
40 using OHOS::HDI::Display::Composer::V1_1::PIXEL_FMT_YCBCR_420_P;
41 using OHOS::HDI::Display::Composer::V1_1::PIXEL_FMT_YCRCB_420_P;
42 using OHOS::HDI::Display::Composer::V1_1::PIXEL_FMT_RGB_888;
43 using OHOS::HDI::Display::Composer::V1_1::PIXEL_FMT_BGRX_8888;
44 using OHOS::HDI::Display::Composer::V1_1::PIXEL_FMT_RGBA_4444;
45 using OHOS::HDI::Display::Composer::V1_1::PIXEL_FMT_RGBX_4444;
46 using OHOS::HDI::Display::Composer::V1_1::PIXEL_FMT_BGRA_4444;
47 using OHOS::HDI::Display::Composer::V1_1::PIXEL_FMT_BGRX_4444;
48 using OHOS::HDI::Display::Composer::V1_1::PIXEL_FMT_BGR_565;
49 using OHOS::HDI::Display::Composer::V1_1::PIXEL_FMT_BGRA_5551;
50 using OHOS::HDI::Display::Composer::V1_1::PIXEL_FMT_BGRX_5551;
51 using OHOS::HDI::Display::Composer::V1_1::PIXEL_FMT_RGBA_1010102;
52 #define TEST_INFO (1<<27)
53 #ifndef DISPLAY_TEST_CHK_RETURN
54 #define DISPLAY_TEST_CHK_RETURN(val, ret, ...) \
55     do {                                       \
56         if (val) {                             \
57             __VA_ARGS__;                       \
58             return (ret);                      \
59         }                                      \
60     } while (0)
61 #endif
62 
63 const uint32_t ALLOC_SIZE_1080 = 1080; // alloc size 1080
64 const uint32_t ALLOC_SIZE_1920 = 1920; // alloc size 1920
65 const uint32_t ALLOC_SIZE_1280 = 1280; // alloc size 1280
66 const uint32_t ALLOC_SIZE_720 = 720; // alloc size 720
67 
68 const AllocInfo DISPLAY_BUFFER_TEST_SETS[] = {
69     // num0
70     {
71         .width = ALLOC_SIZE_1920,
72         .height = ALLOC_SIZE_1080,
73         .usage = HBM_USE_MEM_DMA | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
74         .format = PIXEL_FMT_RGBX_8888
75     },
76     // num1
77     {
78         .width = ALLOC_SIZE_1080,
79         .height = ALLOC_SIZE_1920,
80         .usage = HBM_USE_MEM_DMA | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
81         .format = PIXEL_FMT_RGBX_8888
82     },
83     // num2
84     {
85         .width = ALLOC_SIZE_1280,
86         .height = ALLOC_SIZE_720,
87         .usage = HBM_USE_MEM_DMA | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
88         .format = PIXEL_FMT_RGBX_8888
89     },
90     // num3
91     {
92         .width = ALLOC_SIZE_1080,
93         .height = ALLOC_SIZE_1920,
94         .usage = HBM_USE_MEM_DMA | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
95         .format = PIXEL_FMT_RGBA_8888
96     },
97     // num4
98     {
99         .width = ALLOC_SIZE_1080,
100         .height = ALLOC_SIZE_1920,
101         .usage = HBM_USE_MEM_DMA | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
102         .format = PIXEL_FMT_BGRA_8888
103     },
104     // num5
105     {
106         .width = ALLOC_SIZE_1080,
107         .height = ALLOC_SIZE_1920,
108         .usage = HBM_USE_MEM_DMA | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
109         .format = PIXEL_FMT_YCBCR_420_SP
110     },
111     // num6
112     {
113         .width = ALLOC_SIZE_1080,
114         .height = ALLOC_SIZE_1920,
115         .usage = HBM_USE_MEM_DMA | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
116         .format = PIXEL_FMT_YCRCB_420_SP
117     },
118     // num7
119     {
120         .width = ALLOC_SIZE_1080,
121         .height = ALLOC_SIZE_1920,
122         .usage = HBM_USE_MEM_DMA | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
123         .format = PIXEL_FMT_YCBCR_420_P
124     },
125     // num8
126     {
127         .width = ALLOC_SIZE_1080,
128         .height = ALLOC_SIZE_1920,
129         .usage = HBM_USE_MEM_DMA | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
130         .format = PIXEL_FMT_YCRCB_420_P
131     },
132     // num9
133     {
134         .width = ALLOC_SIZE_1080,
135         .height = ALLOC_SIZE_1920,
136         .usage = HBM_USE_MEM_DMA,
137         .format = PIXEL_FMT_RGBX_8888
138     },
139     // num10
140     {
141         .width = ALLOC_SIZE_1080,
142         .height = ALLOC_SIZE_1920,
143         .usage = HBM_USE_MEM_DMA | HBM_USE_CPU_READ,
144         .format = PIXEL_FMT_RGBX_8888
145     },
146     // num11
147     {
148         .width = ALLOC_SIZE_1080,
149         .height = ALLOC_SIZE_1920,
150         .usage = HBM_USE_MEM_DMA | HBM_USE_CPU_WRITE,
151         .format = PIXEL_FMT_RGBX_8888
152     },
153     //HBM_USE_CPU_HW_BOTH
154     // num12
155     {
156         .width = ALLOC_SIZE_1920,
157         .height = ALLOC_SIZE_1080,
158         .usage = HBM_USE_CPU_HW_BOTH | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
159         .format = PIXEL_FMT_RGBX_8888
160     },
161     // num13
162     {
163         .width = ALLOC_SIZE_1080,
164         .height = ALLOC_SIZE_1920,
165         .usage = HBM_USE_CPU_HW_BOTH | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
166         .format = PIXEL_FMT_RGBX_8888
167     },
168     // num14
169     {
170         .width = ALLOC_SIZE_1280,
171         .height = ALLOC_SIZE_720,
172         .usage = HBM_USE_CPU_HW_BOTH | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
173         .format = PIXEL_FMT_RGBX_8888
174     },
175     // num15
176     {
177         .width = ALLOC_SIZE_1080,
178         .height = ALLOC_SIZE_1920,
179         .usage = HBM_USE_CPU_HW_BOTH | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
180         .format = PIXEL_FMT_RGBA_8888
181     },
182     // num16
183     {
184         .width = ALLOC_SIZE_1080,
185         .height = ALLOC_SIZE_1920,
186         .usage = HBM_USE_CPU_HW_BOTH | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
187         .format = PIXEL_FMT_BGRA_8888
188     },
189     // num17
190     {
191         .width = ALLOC_SIZE_1080,
192         .height = ALLOC_SIZE_1920,
193         .usage = HBM_USE_CPU_HW_BOTH | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
194         .format = PIXEL_FMT_YCBCR_420_SP
195     },
196     // num18
197     {
198         .width = ALLOC_SIZE_1080,
199         .height = ALLOC_SIZE_1920,
200         .usage = HBM_USE_CPU_HW_BOTH | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
201         .format = PIXEL_FMT_YCRCB_420_SP
202     },
203     // num19
204     {
205         .width = ALLOC_SIZE_1080,
206         .height = ALLOC_SIZE_1920,
207         .usage = HBM_USE_CPU_HW_BOTH | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
208         .format = PIXEL_FMT_YCBCR_420_P
209     },
210     // num20
211     {
212         .width = ALLOC_SIZE_1080,
213         .height = ALLOC_SIZE_1920,
214         .usage = HBM_USE_CPU_HW_BOTH | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
215         .format = PIXEL_FMT_YCRCB_420_P
216     },
217     // num21
218     {
219         .width = ALLOC_SIZE_1080,
220         .height = ALLOC_SIZE_1920,
221         .usage = HBM_USE_CPU_HW_BOTH,
222         .format = PIXEL_FMT_RGBX_8888
223     },
224     // num22
225     {
226         .width = ALLOC_SIZE_1080,
227         .height = ALLOC_SIZE_1920,
228         .usage = HBM_USE_CPU_HW_BOTH | HBM_USE_CPU_READ,
229         .format = PIXEL_FMT_RGBX_8888
230     },
231     // num23
232     {
233         .width = ALLOC_SIZE_1080,
234         .height = ALLOC_SIZE_1920,
235         .usage = HBM_USE_CPU_HW_BOTH | HBM_USE_CPU_WRITE,
236         .format = PIXEL_FMT_RGBX_8888
237     },
238 #ifdef DISPLAY_COMMUNITY
239      // num24
240     {
241         .width = ALLOC_SIZE_1080,
242         .height = ALLOC_SIZE_1920,
243         .usage = HBM_USE_MEM_DMA | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
244         .format = PIXEL_FMT_RGB_888
245     },
246     // num25
247     {
248         .width = ALLOC_SIZE_1080,
249         .height = ALLOC_SIZE_1920,
250         .usage = HBM_USE_MEM_DMA | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
251         .format = PIXEL_FMT_BGRX_8888
252     },
253     // num26
254     {
255         .width = ALLOC_SIZE_1080,
256         .height = ALLOC_SIZE_1920,
257         .usage = HBM_USE_MEM_DMA | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
258         .format = PIXEL_FMT_RGBA_4444
259     },
260     // num27
261     {
262         .width = ALLOC_SIZE_1080,
263         .height = ALLOC_SIZE_1920,
264         .usage = HBM_USE_MEM_DMA | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
265         .format = PIXEL_FMT_RGBX_4444
266     },
267     // num28
268     {
269         .width = ALLOC_SIZE_1080,
270         .height = ALLOC_SIZE_1920,
271         .usage = HBM_USE_MEM_DMA | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
272         .format = PIXEL_FMT_BGRA_4444
273     },
274     // num29
275     {
276         .width = ALLOC_SIZE_1080,
277         .height = ALLOC_SIZE_1920,
278         .usage = HBM_USE_MEM_DMA | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
279         .format = PIXEL_FMT_BGRX_4444
280     },
281     // num30
282     {
283         .width = ALLOC_SIZE_1080,
284         .height = ALLOC_SIZE_1920,
285         .usage = HBM_USE_MEM_DMA | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
286         .format = PIXEL_FMT_BGR_565
287     },
288     // num31
289     {
290         .width = ALLOC_SIZE_1080,
291         .height = ALLOC_SIZE_1920,
292         .usage = HBM_USE_MEM_DMA | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
293         .format = PIXEL_FMT_BGRA_5551
294     },
295     // num32
296     {
297         .width = ALLOC_SIZE_1080,
298         .height = ALLOC_SIZE_1920,
299         .usage = HBM_USE_MEM_DMA | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
300         .format = PIXEL_FMT_BGRX_5551
301     },
302     //HBM_USE_CPU_HW_BOTH
303     // num33
304     {
305         .width = ALLOC_SIZE_1080,
306         .height = ALLOC_SIZE_1920,
307         .usage = HBM_USE_CPU_HW_BOTH | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
308         .format = PIXEL_FMT_RGB_888
309     },
310     // num34
311     {
312         .width = ALLOC_SIZE_1080,
313         .height = ALLOC_SIZE_1920,
314         .usage = HBM_USE_CPU_HW_BOTH | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
315         .format = PIXEL_FMT_BGRX_8888
316     },
317     // num35
318     {
319         .width = ALLOC_SIZE_1080,
320         .height = ALLOC_SIZE_1920,
321         .usage = HBM_USE_CPU_HW_BOTH | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
322         .format = PIXEL_FMT_RGBA_4444
323     },
324     // num36
325     {
326         .width = ALLOC_SIZE_1080,
327         .height = ALLOC_SIZE_1920,
328         .usage = HBM_USE_CPU_HW_BOTH | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
329         .format = PIXEL_FMT_RGBX_4444
330     },
331     // num37
332     {
333         .width = ALLOC_SIZE_1080,
334         .height = ALLOC_SIZE_1920,
335         .usage = HBM_USE_CPU_HW_BOTH | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
336         .format = PIXEL_FMT_BGRA_4444
337     },
338     // num38
339     {
340         .width = ALLOC_SIZE_1080,
341         .height = ALLOC_SIZE_1920,
342         .usage = HBM_USE_CPU_HW_BOTH | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
343         .format = PIXEL_FMT_BGRX_4444
344     },
345     // num39
346     {
347         .width = ALLOC_SIZE_1080,
348         .height = ALLOC_SIZE_1920,
349         .usage = HBM_USE_CPU_HW_BOTH | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
350         .format = PIXEL_FMT_BGR_565
351     },
352     // num40
353     {
354         .width = ALLOC_SIZE_1080,
355         .height = ALLOC_SIZE_1920,
356         .usage = HBM_USE_CPU_HW_BOTH | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
357         .format = PIXEL_FMT_BGRA_5551
358     },
359     // num41
360     {
361         .width = ALLOC_SIZE_1080,
362         .height = ALLOC_SIZE_1920,
363         .usage = HBM_USE_CPU_HW_BOTH | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
364         .format = PIXEL_FMT_BGRX_5551
365     },
366 #else
367     // num42
368     {
369         .width = ALLOC_SIZE_1080,
370         .height = ALLOC_SIZE_1920,
371         .usage = HBM_USE_MEM_DMA | HBM_USE_CPU_WRITE,
372         .format = PIXEL_FMT_RGBA_1010102
373     },
374     //HBM_USE_CPU_HW_BOTH
375     // num43
376     {
377         .width = ALLOC_SIZE_1080,
378         .height = ALLOC_SIZE_1920,
379         .usage = HBM_USE_CPU_HW_BOTH | HBM_USE_CPU_WRITE,
380         .format = PIXEL_FMT_RGBA_1010102
381     },
382 #endif // DISPLAY_COMMUNITY
383 };
384 
SetUp()385 void DisplayBufferUt::SetUp()
386 {
387     displayBuffer_ = IDisplayBuffer::Get();
388     if (displayBuffer_ == nullptr) {
389         HDF_LOGE("IDisplayBuffer get failed");
390         ASSERT_TRUE(0);
391     }
392 }
393 
TearDown()394 void DisplayBufferUt::TearDown()
395 {
396 }
397 
MetadataTest(BufferHandle & handle)398 void DisplayBufferUt::MetadataTest(BufferHandle& handle)
399 {
400     int32_t ret = displayBuffer_->RegisterBuffer(handle);
401     EXPECT_TRUE(ret == DISPLAY_NOT_SUPPORT || ret == DISPLAY_SUCCESS);
402 
403     uint32_t key = 1;
404     std::vector<uint8_t> values = {1, 2, 3};
405     std::vector<uint32_t> keys = {};
406     std::vector<uint8_t> rets = {};
407     ret = displayBuffer_->SetMetadata(handle, key, values);
408     EXPECT_TRUE(ret == DISPLAY_NOT_SUPPORT || ret == DISPLAY_SUCCESS);
409     ret = displayBuffer_->GetMetadata(handle, key, rets);
410     EXPECT_TRUE(ret == DISPLAY_NOT_SUPPORT || ret == DISPLAY_SUCCESS);
411     if (ret != DISPLAY_NOT_SUPPORT) {
412         EXPECT_TRUE(rets == values);
413     }
414 
415     ret = displayBuffer_->ListMetadataKeys(handle, keys);
416     EXPECT_TRUE(ret == DISPLAY_NOT_SUPPORT || ret == DISPLAY_SUCCESS);
417     if (ret != DISPLAY_NOT_SUPPORT) {
418         EXPECT_TRUE(keys.size() == 1 && keys[0] == key);
419     }
420 
421     ret = displayBuffer_->EraseMetadataKey(handle, key);
422     EXPECT_TRUE(ret == DISPLAY_NOT_SUPPORT || ret == DISPLAY_SUCCESS);
423     if (ret != DISPLAY_NOT_SUPPORT) {
424         rets = {};
425         ret = displayBuffer_->GetMetadata(handle, key, rets);
426         EXPECT_TRUE(ret != DISPLAY_SUCCESS);
427     }
428 }
429 
AllocMemTest(AllocInfo & info)430 int32_t DisplayBufferUt::AllocMemTest(AllocInfo& info)
431 {
432     int ret;
433     BufferHandle *buffer = nullptr;
434     const int TEST_COUNT = 40; // test 40 times
435     for (int i = 0; i < TEST_COUNT; i++) {
436         ret = displayBuffer_->AllocMem(info, buffer);
437         if (ret == DISPLAY_NOT_SUPPORT) {
438             HDF_LOGE("%{public}s: AllocMem not support, ret=%{public}d", __func__, ret);
439             return DISPLAY_SUCCESS;
440         }
441         if (ret != DISPLAY_SUCCESS || buffer == nullptr) {
442             HDF_LOGE("AllocMem failed");
443             return ret;
444         }
445         MetadataTest(*buffer);
446         void *vAddr = displayBuffer_->Mmap(*buffer);
447         if (vAddr == nullptr) {
448             HDF_LOGE("Mmap failed");
449             displayBuffer_->FreeMem(*buffer);
450             return DISPLAY_FAILURE;
451         }
452         if (info.usage & (HBM_USE_CPU_READ | HBM_USE_CPU_WRITE)) {
453             ret = displayBuffer_->InvalidateCache(*buffer);
454             if (ret != DISPLAY_SUCCESS) {
455                 HDF_LOGE("InvalidateCache failed");
456                 displayBuffer_->Unmap(*buffer);
457                 displayBuffer_->FreeMem(*buffer);
458                 return ret;
459             }
460         }
461         if (memset_s(vAddr, buffer->size, 0, buffer->size) != EOK) {
462             HDF_LOGE("Insufficient memory");
463             displayBuffer_->Unmap(*buffer);
464             displayBuffer_->FreeMem(*buffer);
465             return DISPLAY_NOMEM;
466         }
467         if (info.usage & (HBM_USE_CPU_READ | HBM_USE_CPU_WRITE)) {
468             ret = displayBuffer_->FlushCache(*buffer);
469             if (ret != DISPLAY_SUCCESS) {
470                 HDF_LOGE("FlushCache failed");
471                 displayBuffer_->Unmap(*buffer);
472                 displayBuffer_->FreeMem(*buffer);
473                 return ret;
474             }
475         }
476         displayBuffer_->Unmap(*buffer);
477         displayBuffer_->FreeMem(*buffer);
478     }
479     return DISPLAY_SUCCESS;
480 }
481 
TEST_P(DisplayBufferUt,DisplayBufferUt)482 TEST_P(DisplayBufferUt, DisplayBufferUt)
483 {
484     AllocInfo params = GetParam();
485     int ret = AllocMemTest(params);
486     ASSERT_TRUE(ret == DISPLAY_SUCCESS);
487 }
488 
489 INSTANTIATE_TEST_SUITE_P(AllocTest, DisplayBufferUt, ::testing::ValuesIn(DISPLAY_BUFFER_TEST_SETS));
490 
491 HWTEST_F(DisplayBufferUt, test_ReAllocMemTest001, TestSize.Level1)
492 {
493     int ret;
494     AllocInfo info = {
495         .width = ALLOC_SIZE_1080,
496         .height = ALLOC_SIZE_1920,
497         .usage = HBM_USE_MEM_DMA | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
498         .format = PIXEL_FMT_YCBCR_420_P
499     };
500     BufferHandle* inBuffer = nullptr;
501     ret = displayBuffer_->AllocMem(info, inBuffer);
502     EXPECT_TRUE(ret == DISPLAY_SUCCESS);
503     EXPECT_NE(inBuffer, nullptr);
504 
505     BufferHandle* outBuffer = nullptr;
506     AllocInfo newInfo = {
507         .width = ALLOC_SIZE_1920,
508         .height = ALLOC_SIZE_1080,
509         .usage = HBM_USE_MEM_DMA | Composer::V1_0::HBM_USE_VIDEO_DECODER | Composer::V1_0::HBM_USE_HW_COMPOSER,
510         .format = PIXEL_FMT_YCBCR_420_P
511     };
512 
513     ret = displayBuffer_->ReAllocMem(newInfo, *inBuffer, outBuffer);
514     EXPECT_TRUE(ret == DISPLAY_SUCCESS);
515     EXPECT_NE(inBuffer, nullptr);
516     EXPECT_NE(outBuffer, nullptr);
517 
518     AllocInfo nullInfo;
519     ret = displayBuffer_->ReAllocMem(nullInfo, *inBuffer, outBuffer);
520     EXPECT_TRUE(ret != DISPLAY_SUCCESS);
521 
522     displayBuffer_->FreeMem(*inBuffer);
523     displayBuffer_->FreeMem(*outBuffer);
524 }
525 
526 HWTEST_F(DisplayBufferUt, test_ReAllocMemTest002, TestSize.Level1)
527 {
528     int ret;
529     AllocInfo info = {
530         .width = ALLOC_SIZE_720,
531         .height = ALLOC_SIZE_1920,
532         .usage = HBM_USE_MEM_DMA | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
533         .format = PIXEL_FMT_YCBCR_420_P
534     };
535     BufferHandle* inBuffer = nullptr;
536     ret = displayBuffer_->AllocMem(info, inBuffer);
537     EXPECT_TRUE(ret == DISPLAY_SUCCESS);
538     EXPECT_NE(inBuffer, nullptr);
539 
540     BufferHandle* outBuffer = nullptr;
541     AllocInfo newInfo = {
542         .width = ALLOC_SIZE_1920,
543         .height = ALLOC_SIZE_1080,
544         .usage = HBM_USE_MEM_DMA | Composer::V1_0::HBM_USE_VIDEO_DECODER | Composer::V1_0::HBM_USE_HW_COMPOSER,
545         .format = PIXEL_FMT_YCBCR_420_P
546     };
547 
548     ret = displayBuffer_->ReAllocMem(newInfo, *inBuffer, outBuffer);
549     EXPECT_TRUE(ret == DISPLAY_SUCCESS);
550     EXPECT_NE(inBuffer, nullptr);
551     EXPECT_NE(outBuffer, nullptr);
552 
553     AllocInfo nullInfo;
554     ret = displayBuffer_->ReAllocMem(nullInfo, *inBuffer, outBuffer);
555     EXPECT_TRUE(ret != DISPLAY_SUCCESS);
556 
557     displayBuffer_->FreeMem(*inBuffer);
558     displayBuffer_->FreeMem(*outBuffer);
559 }
560 
561 HWTEST_F(DisplayBufferUt, test_ReAllocMemTest003, TestSize.Level1)
562 {
563     int ret;
564     AllocInfo info = {
565         .width = ALLOC_SIZE_1280,
566         .height = ALLOC_SIZE_1920,
567         .usage = HBM_USE_MEM_DMA | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
568         .format = PIXEL_FMT_YCBCR_420_P
569     };
570     BufferHandle* inBuffer = nullptr;
571     ret = displayBuffer_->AllocMem(info, inBuffer);
572     EXPECT_TRUE(ret == DISPLAY_SUCCESS);
573     EXPECT_NE(inBuffer, nullptr);
574 
575     BufferHandle* outBuffer = nullptr;
576     AllocInfo newInfo = {
577         .width = ALLOC_SIZE_1920,
578         .height = ALLOC_SIZE_1080,
579         .usage = HBM_USE_MEM_DMA | Composer::V1_0::HBM_USE_VIDEO_DECODER | Composer::V1_0::HBM_USE_HW_COMPOSER,
580         .format = PIXEL_FMT_YCBCR_420_P
581     };
582 
583     ret = displayBuffer_->ReAllocMem(newInfo, *inBuffer, outBuffer);
584     EXPECT_TRUE(ret == DISPLAY_SUCCESS);
585     EXPECT_NE(inBuffer, nullptr);
586     EXPECT_NE(outBuffer, nullptr);
587 
588     AllocInfo nullInfo;
589     ret = displayBuffer_->ReAllocMem(nullInfo, *inBuffer, outBuffer);
590     EXPECT_TRUE(ret != DISPLAY_SUCCESS);
591 
592     displayBuffer_->FreeMem(*inBuffer);
593     displayBuffer_->FreeMem(*outBuffer);
594 }
595 
PassthroughTest(AllocInfo & info)596 int32_t DisplayBufferUt::PassthroughTest(AllocInfo& info)
597 {
598     int ret;
599     BufferHandle *buffer = nullptr;
600     ret = displayBuffer_->AllocMem(info, buffer);
601     if (ret == DISPLAY_NOT_SUPPORT) {
602         HDF_LOGE("%{public}s: AllocMem not support, ret=%{public}d", __func__, ret);
603         return DISPLAY_SUCCESS;
604     }
605     if (ret != DISPLAY_SUCCESS || buffer == nullptr) {
606         HDF_LOGE("AllocMem failed");
607         return ret;
608     }
609     displayBuffer_->FreeMem(*buffer);
610     return DISPLAY_SUCCESS;
611 }
612 
613 HWTEST_F(DisplayBufferUt, test_PassthroughTest, TestSize.Level1)
614 {
615     AllocInfo info = {
616         .width = ALLOC_SIZE_1080,
617         .height = ALLOC_SIZE_1920,
618         .usage = TEST_INFO,
619         .format = PIXEL_FMT_YCBCR_420_P
620     };
621     int ret = PassthroughTest(info);
622     ASSERT_TRUE(ret == DISPLAY_SUCCESS);
623 }
624 } // OHOS
625 } // HDI
626 } // DISPLAY
627 } // TEST