• 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_0/display_buffer_type.h"
20  #include "v1_0/display_composer_type.h"
21  #include "v1_0/include/idisplay_buffer.h"
22  #include "hdf_base.h"
23  #include "hdf_log.h"
24  
25  namespace OHOS {
26  namespace HDI {
27  namespace Display {
28  namespace TEST {
29  using namespace OHOS::HDI::Display::Composer::V1_0;
30  using namespace OHOS::HDI::Display::Buffer::V1_0;
31  
32  #ifndef DISPLAY_TEST_CHK_RETURN
33  #define DISPLAY_TEST_CHK_RETURN(val, ret, ...) \
34      do {                                       \
35          if (val) {                             \
36              __VA_ARGS__;                       \
37              return (ret);                      \
38          }                                      \
39      } while (0)
40  #endif
41  
42  const uint32_t ALLOC_SIZE_1080 = 1080; // alloc size 1080
43  const uint32_t ALLOC_SIZE_1920 = 1920; // alloc size 1920
44  const uint32_t ALLOC_SIZE_1280 = 1280; // alloc size 1280
45  const uint32_t ALLOC_SIZE_720 = 720; // alloc size 720
46  
47  const AllocInfo DISPLAY_BUFFER_TEST_SETS[] = {
48      // num0
49      // SUB_DriverSystem_DisplayHdi_0050
50      {
51          .width = ALLOC_SIZE_1920,
52          .height = ALLOC_SIZE_1080,
53          .usage = HBM_USE_MEM_DMA | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
54          .format = PIXEL_FMT_RGBX_8888
55      },
56      // num1
57      // SUB_DriverSystem_DisplayHdi_0060
58      {
59          .width = ALLOC_SIZE_1080,
60          .height = ALLOC_SIZE_1920,
61          .usage = HBM_USE_MEM_DMA | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
62          .format = PIXEL_FMT_RGBX_8888
63      },
64      // num2
65      // SUB_DriverSystem_DisplayHdi_0070
66      {
67          .width = ALLOC_SIZE_1280,
68          .height = ALLOC_SIZE_720,
69          .usage = HBM_USE_MEM_DMA | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
70          .format = PIXEL_FMT_RGBX_8888
71      },
72      // num3
73      // SUB_DriverSystem_DisplayHdi_0080
74      {
75          .width = ALLOC_SIZE_1080,
76          .height = ALLOC_SIZE_1920,
77          .usage = HBM_USE_MEM_DMA | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
78          .format = PIXEL_FMT_RGBA_8888
79      },
80      // num4
81      // SUB_DriverSystem_DisplayHdi_0090
82      {
83          .width = ALLOC_SIZE_1080,
84          .height = ALLOC_SIZE_1920,
85          .usage = HBM_USE_MEM_DMA | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
86          .format = PIXEL_FMT_BGRA_8888
87      },
88  
89      // num5
90      // SUB_DriverSystem_DisplayHdi_0100
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_YCBCR_420_SP
96      },
97      // num6
98      // SUB_DriverSystem_DisplayHdi_0110
99      {
100          .width = ALLOC_SIZE_1080,
101          .height = ALLOC_SIZE_1920,
102          .usage = HBM_USE_MEM_DMA | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
103          .format = PIXEL_FMT_YCRCB_420_SP
104      },
105      // num7
106      // SUB_DriverSystem_DisplayHdi_0120
107      {
108          .width = ALLOC_SIZE_1080,
109          .height = ALLOC_SIZE_1920,
110          .usage = HBM_USE_MEM_DMA | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
111          .format = PIXEL_FMT_YCBCR_420_P
112      },
113      // num8
114      // SUB_DriverSystem_DisplayHdi_0130
115      {
116          .width = ALLOC_SIZE_1080,
117          .height = ALLOC_SIZE_1920,
118          .usage = HBM_USE_MEM_DMA | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
119          .format = PIXEL_FMT_YCRCB_420_P
120      },
121      // num9
122      // SUB_DriverSystem_DisplayHdi_0140
123      {
124          .width = ALLOC_SIZE_1080,
125          .height = ALLOC_SIZE_1920,
126          .usage = HBM_USE_MEM_DMA,
127          .format = PIXEL_FMT_RGBX_8888
128      },
129      // num10
130      // SUB_DriverSystem_DisplayHdi_0150
131      {
132          .width = ALLOC_SIZE_1080,
133          .height = ALLOC_SIZE_1920,
134          .usage = HBM_USE_MEM_DMA | HBM_USE_CPU_READ,
135          .format = PIXEL_FMT_RGBX_8888
136      },
137      // num11
138      // SUB_DriverSystem_DisplayHdi_0160
139      {
140          .width = ALLOC_SIZE_1080,
141          .height = ALLOC_SIZE_1920,
142          .usage = HBM_USE_MEM_DMA | HBM_USE_CPU_WRITE,
143          .format = PIXEL_FMT_RGBX_8888
144      },
145  #ifdef DISPLAY_COMMUNITY
146      // num12
147      // SUB_DriverSystem_DisplayHdi_0170
148      {
149          .width = ALLOC_SIZE_1080,
150          .height = ALLOC_SIZE_1920,
151          .usage = HBM_USE_MEM_DMA | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
152          .format = PIXEL_FMT_RGB_888
153      },
154      // num13
155      // SUB_DriverSystem_DisplayHdi_0180
156      {
157          .width = ALLOC_SIZE_1080,
158          .height = ALLOC_SIZE_1920,
159          .usage = HBM_USE_MEM_DMA | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
160          .format = PIXEL_FMT_BGRX_8888
161      },
162      // num14
163      // SUB_DriverSystem_DisplayHdi_0190
164      {
165          .width = ALLOC_SIZE_1080,
166          .height = ALLOC_SIZE_1920,
167          .usage = HBM_USE_MEM_DMA | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
168          .format = PIXEL_FMT_RGBA_4444
169      },
170      // num15
171      // SUB_DriverSystem_DisplayHdi_0200
172      {
173          .width = ALLOC_SIZE_1080,
174          .height = ALLOC_SIZE_1920,
175          .usage = HBM_USE_MEM_DMA | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
176          .format = PIXEL_FMT_RGBX_4444
177      },
178      // num16
179      // SUB_DriverSystem_DisplayHdi_0210
180      {
181          .width = ALLOC_SIZE_1080,
182          .height = ALLOC_SIZE_1920,
183          .usage = HBM_USE_MEM_DMA | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
184          .format = PIXEL_FMT_BGRA_4444
185      },
186      // num17
187      // SUB_DriverSystem_DisplayHdi_0220
188      {
189          .width = ALLOC_SIZE_1080,
190          .height = ALLOC_SIZE_1920,
191          .usage = HBM_USE_MEM_DMA | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
192          .format = PIXEL_FMT_BGRX_4444
193      },
194      // num18
195      // SUB_DriverSystem_DisplayHdi_0230
196      {
197          .width = ALLOC_SIZE_1080,
198          .height = ALLOC_SIZE_1920,
199          .usage = HBM_USE_MEM_DMA | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
200          .format = PIXEL_FMT_BGR_565
201      },
202      // num19
203      // SUB_DriverSystem_DisplayHdi_0240
204      {
205          .width = ALLOC_SIZE_1080,
206          .height = ALLOC_SIZE_1920,
207          .usage = HBM_USE_MEM_DMA | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
208          .format = PIXEL_FMT_BGRA_5551
209      },
210      // num20
211      // SUB_DriverSystem_DisplayHdi_0250
212      {
213          .width = ALLOC_SIZE_1080,
214          .height = ALLOC_SIZE_1920,
215          .usage = HBM_USE_MEM_DMA | HBM_USE_CPU_READ | HBM_USE_CPU_WRITE,
216          .format = PIXEL_FMT_BGRX_5551
217      },
218  #elif RGBA_1010102
219      // num21
220      {
221          .width = ALLOC_SIZE_1080,
222          .height = ALLOC_SIZE_1920,
223          .usage = HBM_USE_MEM_DMA | HBM_USE_CPU_WRITE,
224          .format = PIXEL_FMT_RGBA_1010102
225      },
226  #endif // DISPLAY_COMMUNITY
227  };
228  
SetUp()229  void DisplayBufferUt::SetUp()
230  {
231      displayBuffer_ = IDisplayBuffer::Get();
232      if (displayBuffer_ == nullptr) {
233          HDF_LOGE("IDisplayBuffer get failed");
234          ASSERT_TRUE(0);
235      }
236  }
237  
TearDown()238  void DisplayBufferUt::TearDown()
239  {
240  }
241  
AllocMemTest(AllocInfo & info)242  int32_t DisplayBufferUt::AllocMemTest(AllocInfo& info)
243  {
244      int ret;
245      BufferHandle *buffer = nullptr;
246      const int TEST_COUNT = 40; // test 40 times
247      for (int i = 0; i < TEST_COUNT; i++) {
248          ret = displayBuffer_->AllocMem(info, buffer);
249          if (ret != DISPLAY_SUCCESS || buffer == nullptr) {
250              HDF_LOGE("AllocMem failed");
251              return ret;
252          }
253          void *vAddr = displayBuffer_->Mmap(*buffer);
254          if (vAddr == nullptr) {
255              HDF_LOGE("Mmap failed");
256              displayBuffer_->FreeMem(*buffer);
257              return DISPLAY_FAILURE;
258          }
259  
260          if (info.usage & (HBM_USE_CPU_READ | HBM_USE_CPU_WRITE)) {
261              ret = displayBuffer_->InvalidateCache(*buffer);
262              if (ret != DISPLAY_SUCCESS) {
263                  HDF_LOGE("InvalidateCache failed");
264                  displayBuffer_->Unmap(*buffer);
265                  displayBuffer_->FreeMem(*buffer);
266                  return ret;
267              }
268          }
269          if (memset_s(vAddr, buffer->size, 0, buffer->size) != EOK) {
270              HDF_LOGE("Insufficient memory");
271              displayBuffer_->Unmap(*buffer);
272              displayBuffer_->FreeMem(*buffer);
273              return DISPLAY_NOMEM;
274          }
275  
276          if (info.usage & (HBM_USE_CPU_READ | HBM_USE_CPU_WRITE)) {
277              ret = displayBuffer_->FlushCache(*buffer);
278              if (ret != DISPLAY_SUCCESS) {
279                  HDF_LOGE("FlushCache failed");
280                  displayBuffer_->Unmap(*buffer);
281                  displayBuffer_->FreeMem(*buffer);
282                  return ret;
283              }
284          }
285          displayBuffer_->Unmap(*buffer);
286          displayBuffer_->FreeMem(*buffer);
287      }
288      return DISPLAY_SUCCESS;
289  }
290  
TEST_P(DisplayBufferUt,DisplayBufferUt)291  TEST_P(DisplayBufferUt, DisplayBufferUt)
292  {
293      AllocInfo params = GetParam();
294      int ret = AllocMemTest(params);
295      ASSERT_TRUE(ret == DISPLAY_SUCCESS);
296  }
297  
298  INSTANTIATE_TEST_SUITE_P(AllocTest, DisplayBufferUt, ::testing::ValuesIn(DISPLAY_BUFFER_TEST_SETS));
299  } // OHOS
300  } // HDI
301  } // DISPLAY
302  } // TEST
303