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, 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 /**
368 * @tc.number: SUB_Driver_Display_HEBC_0100
369 * @tc.desc: Apply for a hebc format buffer
370 * @tc.size: MediumTest
371 * @tc.type: Function
372 */
373 // num42
374 {
375 .width = ALLOC_SIZE_1080,
376 .height = ALLOC_SIZE_1920,
377 .usage = HBM_USE_MEM_DMA | HBM_USE_CPU_WRITE,
378 .format = PIXEL_FMT_RGBA_1010102
379 },
380 //HBM_USE_CPU_HW_BOTH
381 // num43
382 {
383 .width = ALLOC_SIZE_1080,
384 .height = ALLOC_SIZE_1920,
385 .usage = HBM_USE_CPU_HW_BOTH | HBM_USE_CPU_WRITE,
386 .format = PIXEL_FMT_RGBA_1010102
387 },
388 #endif // DISPLAY_COMMUNITY
389 };
390
SetUp()391 void DisplayBufferUt::SetUp()
392 {
393 displayBuffer_ = IDisplayBuffer::Get();
394 if (displayBuffer_ == nullptr) {
395 HDF_LOGE("IDisplayBuffer get failed");
396 ASSERT_TRUE(0);
397 }
398 }
399
TearDown()400 void DisplayBufferUt::TearDown()
401 {
402 }
403
MetadataTest(BufferHandle & handle)404 void DisplayBufferUt::MetadataTest(BufferHandle& handle)
405 {
406 int32_t ret = displayBuffer_->RegisterBuffer(handle);
407 EXPECT_TRUE(ret == DISPLAY_NOT_SUPPORT || ret == DISPLAY_SUCCESS);
408
409 uint32_t key = 1;
410 std::vector<uint8_t> values = {1, 2, 3};
411 std::vector<uint32_t> keys = {};
412 std::vector<uint8_t> rets = {};
413 ret = displayBuffer_->SetMetadata(handle, key, values);
414 EXPECT_TRUE(ret == DISPLAY_NOT_SUPPORT || ret == DISPLAY_SUCCESS);
415 ret = displayBuffer_->GetMetadata(handle, key, rets);
416 EXPECT_TRUE(ret == DISPLAY_NOT_SUPPORT || ret == DISPLAY_SUCCESS);
417 if (ret != DISPLAY_NOT_SUPPORT) {
418 EXPECT_TRUE(rets == values);
419 }
420
421 ret = displayBuffer_->ListMetadataKeys(handle, keys);
422 EXPECT_TRUE(ret == DISPLAY_NOT_SUPPORT || ret == DISPLAY_SUCCESS);
423 if (ret != DISPLAY_NOT_SUPPORT) {
424 EXPECT_TRUE(keys.size() == 1 && keys[0] == key);
425 }
426
427 ret = displayBuffer_->EraseMetadataKey(handle, key);
428 EXPECT_TRUE(ret == DISPLAY_NOT_SUPPORT || ret == DISPLAY_SUCCESS);
429 if (ret != DISPLAY_NOT_SUPPORT) {
430 rets = {};
431 ret = displayBuffer_->GetMetadata(handle, key, rets);
432 EXPECT_TRUE(ret != DISPLAY_SUCCESS);
433 }
434 }
435
AllocMemTest(AllocInfo & info)436 int32_t DisplayBufferUt::AllocMemTest(AllocInfo& info)
437 {
438 int ret;
439 BufferHandle *buffer = nullptr;
440 const int TEST_COUNT = 40; // test 40 times
441 for (int i = 0; i < TEST_COUNT; i++) {
442 ret = displayBuffer_->AllocMem(info, buffer);
443 if (ret == DISPLAY_NOT_SUPPORT) {
444 HDF_LOGE("%{public}s: AllocMem not support, ret=%{public}d", __func__, ret);
445 return DISPLAY_SUCCESS;
446 }
447 if (ret != DISPLAY_SUCCESS || buffer == nullptr) {
448 HDF_LOGE("AllocMem failed");
449 return ret;
450 }
451 MetadataTest(*buffer);
452 void *vAddr = displayBuffer_->Mmap(*buffer);
453 if (vAddr == nullptr) {
454 HDF_LOGE("Mmap failed");
455 displayBuffer_->FreeMem(*buffer);
456 return DISPLAY_FAILURE;
457 }
458 if (info.usage & (HBM_USE_CPU_READ | HBM_USE_CPU_WRITE)) {
459 ret = displayBuffer_->InvalidateCache(*buffer);
460 if (ret != DISPLAY_SUCCESS) {
461 HDF_LOGE("InvalidateCache failed");
462 displayBuffer_->Unmap(*buffer);
463 displayBuffer_->FreeMem(*buffer);
464 return ret;
465 }
466 }
467 if (memset_s(vAddr, buffer->size, 0, buffer->size) != EOK) {
468 HDF_LOGE("Insufficient memory");
469 displayBuffer_->Unmap(*buffer);
470 displayBuffer_->FreeMem(*buffer);
471 return DISPLAY_NOMEM;
472 }
473 if (info.usage & (HBM_USE_CPU_READ | HBM_USE_CPU_WRITE)) {
474 ret = displayBuffer_->FlushCache(*buffer);
475 if (ret != DISPLAY_SUCCESS) {
476 HDF_LOGE("FlushCache failed");
477 displayBuffer_->Unmap(*buffer);
478 displayBuffer_->FreeMem(*buffer);
479 return ret;
480 }
481 }
482 displayBuffer_->Unmap(*buffer);
483 displayBuffer_->FreeMem(*buffer);
484 }
485 return DISPLAY_SUCCESS;
486 }
487
TEST_P(DisplayBufferUt,DisplayBufferUt)488 TEST_P(DisplayBufferUt, DisplayBufferUt)
489 {
490 AllocInfo params = GetParam();
491 int ret = AllocMemTest(params);
492 ASSERT_TRUE(ret == DISPLAY_SUCCESS);
493 }
494
495 /**
496 * @tc.number: SUB_Driver_Display_HDI_0100-2100
497 * @tc.desc: Set different information testing memory interfaces
498 * @tc.size: MediumTest
499 * @tc.type: Function
500 */
501 INSTANTIATE_TEST_SUITE_P(AllocTest, DisplayBufferUt, ::testing::ValuesIn(DISPLAY_BUFFER_TEST_SETS));
502
503 /**
504 * @tc.number: SUB_Driver_Display_HDI_2200
505 * @tc.name: test_ReAllocMemTest001
506 * @tc.desc: verify different AllocInfo for the ReAllocMem interface
507 * @tc.size: MediumTest
508 * @tc.type: Function
509 */
510 HWTEST_F(DisplayBufferUt, test_ReAllocMemTest001, TestSize.Level1)
511 {
512 int ret;
513 AllocInfo info = {
514 .width = ALLOC_SIZE_1080,
515 .height = ALLOC_SIZE_1920,
516 .usage = HBM_USE_MEM_DMA | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
517 .format = PIXEL_FMT_YCBCR_420_P
518 };
519 BufferHandle* inBuffer = nullptr;
520 ret = displayBuffer_->AllocMem(info, inBuffer);
521 EXPECT_TRUE(ret == DISPLAY_SUCCESS);
522 EXPECT_NE(inBuffer, nullptr);
523
524 BufferHandle* outBuffer = nullptr;
525 AllocInfo newInfo = {
526 .width = ALLOC_SIZE_1920,
527 .height = ALLOC_SIZE_1080,
528 .usage = HBM_USE_MEM_DMA | Composer::V1_0::HBM_USE_VIDEO_DECODER | Composer::V1_0::HBM_USE_HW_COMPOSER,
529 .format = PIXEL_FMT_YCBCR_420_P
530 };
531
532 ret = displayBuffer_->ReAllocMem(newInfo, *inBuffer, outBuffer);
533 EXPECT_TRUE(ret == DISPLAY_SUCCESS);
534 EXPECT_NE(inBuffer, nullptr);
535 EXPECT_NE(outBuffer, nullptr);
536
537 AllocInfo nullInfo;
538 ret = displayBuffer_->ReAllocMem(nullInfo, *inBuffer, outBuffer);
539 EXPECT_TRUE(ret != DISPLAY_SUCCESS);
540
541 displayBuffer_->FreeMem(*inBuffer);
542 displayBuffer_->FreeMem(*outBuffer);
543 }
544
545 /**
546 * @tc.number: SUB_Driver_Display_HDI_2300
547 * @tc.name: test_ReAllocMemTest002
548 * @tc.desc: verify different AllocInfo for the ReAllocMem interface
549 * @tc.size: MediumTest
550 * @tc.type: Function
551 */
552 HWTEST_F(DisplayBufferUt, test_ReAllocMemTest002, TestSize.Level1)
553 {
554 int ret;
555 AllocInfo info = {
556 .width = ALLOC_SIZE_720,
557 .height = ALLOC_SIZE_1920,
558 .usage = HBM_USE_MEM_DMA | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
559 .format = PIXEL_FMT_YCBCR_420_P
560 };
561 BufferHandle* inBuffer = nullptr;
562 ret = displayBuffer_->AllocMem(info, inBuffer);
563 EXPECT_TRUE(ret == DISPLAY_SUCCESS);
564 EXPECT_NE(inBuffer, nullptr);
565
566 BufferHandle* outBuffer = nullptr;
567 AllocInfo newInfo = {
568 .width = ALLOC_SIZE_1920,
569 .height = ALLOC_SIZE_1080,
570 .usage = HBM_USE_MEM_DMA | Composer::V1_0::HBM_USE_VIDEO_DECODER | Composer::V1_0::HBM_USE_HW_COMPOSER,
571 .format = PIXEL_FMT_YCBCR_420_P
572 };
573
574 ret = displayBuffer_->ReAllocMem(newInfo, *inBuffer, outBuffer);
575 EXPECT_TRUE(ret == DISPLAY_SUCCESS);
576 EXPECT_NE(inBuffer, nullptr);
577 EXPECT_NE(outBuffer, nullptr);
578
579 AllocInfo nullInfo;
580 ret = displayBuffer_->ReAllocMem(nullInfo, *inBuffer, outBuffer);
581 EXPECT_TRUE(ret != DISPLAY_SUCCESS);
582
583 displayBuffer_->FreeMem(*inBuffer);
584 displayBuffer_->FreeMem(*outBuffer);
585 }
586
587 /**
588 * @tc.number: SUB_Driver_Display_HDI_2400
589 * @tc.name: test_ReAllocMemTest003
590 * @tc.desc: verify different AllocInfo for the ReAllocMem interface
591 * @tc.size: MediumTest
592 * @tc.type: Function
593 */
594 HWTEST_F(DisplayBufferUt, test_ReAllocMemTest003, TestSize.Level1)
595 {
596 int ret;
597 AllocInfo info = {
598 .width = ALLOC_SIZE_1280,
599 .height = ALLOC_SIZE_1920,
600 .usage = HBM_USE_MEM_DMA | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
601 .format = PIXEL_FMT_YCBCR_420_P
602 };
603 BufferHandle* inBuffer = nullptr;
604 ret = displayBuffer_->AllocMem(info, inBuffer);
605 EXPECT_TRUE(ret == DISPLAY_SUCCESS);
606 EXPECT_NE(inBuffer, nullptr);
607
608 BufferHandle* outBuffer = nullptr;
609 AllocInfo newInfo = {
610 .width = ALLOC_SIZE_1920,
611 .height = ALLOC_SIZE_1080,
612 .usage = HBM_USE_MEM_DMA | Composer::V1_0::HBM_USE_VIDEO_DECODER | Composer::V1_0::HBM_USE_HW_COMPOSER,
613 .format = PIXEL_FMT_YCBCR_420_P
614 };
615
616 ret = displayBuffer_->ReAllocMem(newInfo, *inBuffer, outBuffer);
617 EXPECT_TRUE(ret == DISPLAY_SUCCESS);
618 EXPECT_NE(inBuffer, nullptr);
619 EXPECT_NE(outBuffer, nullptr);
620
621 AllocInfo nullInfo;
622 ret = displayBuffer_->ReAllocMem(nullInfo, *inBuffer, outBuffer);
623 EXPECT_TRUE(ret != DISPLAY_SUCCESS);
624
625 displayBuffer_->FreeMem(*inBuffer);
626 displayBuffer_->FreeMem(*outBuffer);
627 }
628 } // OHOS
629 } // HDI
630 } // DISPLAY
631 } // TEST
632