• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 <OMX_Component.h>
17 #include <OMX_Core.h>
18 #include <OMX_Video.h>
19 #include <OMX_VideoExt.h>
20 #include <ashmem.h>
21 #include <gtest/gtest.h>
22 #include <hdf_log.h>
23 #include <osal_mem.h>
24 #include <securec.h>
25 #include <servmgr_hdi.h>
26 
27 #include "codec_component_manager.h"
28 #include "codec_component_type.h"
29 #include "hdf_io_service_if.h"
30 #include "codec_omx_ext.h"
31 
32 #define HDF_LOG_TAG codec_hdi_test
33 
34 using namespace std;
35 using namespace testing::ext;
36 
37 namespace {
38 struct CodecComponentManager *g_manager = nullptr;
39 struct CodecComponentType *g_component = nullptr;
40 uint32_t g_componentId = 0;
41 struct CodecCallbackType *g_callback = nullptr;
42 int32_t g_count = 0;
43 
44 constexpr const char *ENCODER_AVC = "rk.video_encoder.avc";
45 constexpr const char *DECODER_AVC = "rk.video_decoder.avc";
46 
47 constexpr int32_t INT_TO_STR_LEN = 32;
48 constexpr int32_t ARRAY_TO_STR_LEN = 1000;
49 
50 union OMX_VERSIONTYPE g_version;
51 constexpr int32_t BUFFER_SIZE = (640 * 480 * 3);
52 constexpr int32_t ROLE_LEN = 240;
53 constexpr int32_t FRAMERATE = (30 << 16);
54 constexpr uint32_t BUFFER_ID_ERROR = 65000;
55 constexpr int64_t APP_DATA = 64;
56 constexpr int64_t APP_DATA_MAX = 9223372036854775807;
57 constexpr int64_t APP_DATA_MIN = -9223372036854775807;
58 enum class PortIndex { PORT_INDEX_INPUT = 0, PORT_INDEX_OUTPUT = 1, PORT_INDEX_ERROR_INPUT = 2 };
59 
60 template <typename T>
InitParam(T & param)61 void InitParam(T &param)
62 {
63     memset_s(&param, sizeof(param), 0x0, sizeof(param));
64     param.nSize = sizeof(param);
65     param.nVersion = g_version;
66 }
67 
68 struct BufferInfo {
69     std::shared_ptr<OmxCodecBuffer> omxBuffer;
70     std::shared_ptr<OHOS::Ashmem> sharedMem;
BufferInfo__anonbd6f05190111::BufferInfo71     BufferInfo()
72     {
73         omxBuffer = nullptr;
74         sharedMem = nullptr;
75     }
~BufferInfo__anonbd6f05190111::BufferInfo76     ~BufferInfo()
77     {
78         omxBuffer = nullptr;
79         if (sharedMem != nullptr) {
80             sharedMem->UnmapAshmem();
81             sharedMem->CloseAshmem();
82             sharedMem = nullptr;
83         }
84     }
85 };
86 std::map<int32_t, std::shared_ptr<BufferInfo>> inputBuffers;
87 std::map<int32_t, std::shared_ptr<BufferInfo>> outputBuffers;
InitCodecBufferWithAshMem(enum PortIndex portIndex,int bufferSize,shared_ptr<OmxCodecBuffer> omxBuffer,shared_ptr<OHOS::Ashmem> sharedMem)88 static void InitCodecBufferWithAshMem(enum PortIndex portIndex, int bufferSize, shared_ptr<OmxCodecBuffer> omxBuffer,
89                                       shared_ptr<OHOS::Ashmem> sharedMem)
90 {
91     omxBuffer->size = sizeof(OmxCodecBuffer);
92     omxBuffer->version = g_version;
93     omxBuffer->bufferType = CODEC_BUFFER_TYPE_AVSHARE_MEM_FD;
94     omxBuffer->bufferLen = sizeof(int);
95     omxBuffer->buffer = (uint8_t *)(uintptr_t)sharedMem->GetAshmemFd();
96     omxBuffer->allocLen = bufferSize;
97     omxBuffer->fenceFd = -1;
98     omxBuffer->pts = 0;
99     omxBuffer->flag = 0;
100     if (portIndex == PortIndex::PORT_INDEX_INPUT) {
101         omxBuffer->type = READ_ONLY_TYPE;
102         sharedMem->MapReadAndWriteAshmem();
103     } else {
104         omxBuffer->type = READ_WRITE_TYPE;
105         sharedMem->MapReadOnlyAshmem();
106     }
107 }
108 
UseBufferOnPort(enum PortIndex portIndex,int bufferCount,int bufferSize)109 static bool UseBufferOnPort(enum PortIndex portIndex, int bufferCount, int bufferSize)
110 {
111     for (int i = 0; i < bufferCount; i++) {
112         std::shared_ptr<OmxCodecBuffer> omxBuffer = std::make_shared<OmxCodecBuffer>();
113         if (omxBuffer == nullptr) {
114             HDF_LOGE("%{public}s omxBuffer is null", __func__);
115             return false;
116         }
117 
118         int fd = OHOS::AshmemCreate(0, bufferSize);
119         shared_ptr<OHOS::Ashmem> sharedMem = make_shared<OHOS::Ashmem>(fd, bufferSize);
120         if (sharedMem == nullptr) {
121             HDF_LOGE("%{public}s sharedMem is null", __func__);
122             if (fd >= 0) {
123                 close(fd);
124                 fd = -1;
125             }
126             return false;
127         }
128         InitCodecBufferWithAshMem(portIndex, bufferSize, omxBuffer, sharedMem);
129         auto err = g_component->UseBuffer(g_component, (uint32_t)portIndex, omxBuffer.get());
130         if (err != HDF_SUCCESS) {
131             HDF_LOGE("%{public}s failed to UseBuffer with  portIndex[%{public}d]", __func__, portIndex);
132             sharedMem->UnmapAshmem();
133             sharedMem->CloseAshmem();
134             sharedMem = nullptr;
135             omxBuffer = nullptr;
136             return false;
137         }
138         omxBuffer->bufferLen = 0;
139         HDF_LOGI("UseBuffer returned bufferID [%{public}d]", omxBuffer->bufferId);
140         std::shared_ptr<BufferInfo> bufferInfo = std::make_shared<BufferInfo>();
141         bufferInfo->omxBuffer = omxBuffer;
142         bufferInfo->sharedMem = sharedMem;
143         if (portIndex == PortIndex::PORT_INDEX_INPUT) {
144             inputBuffers.emplace(std::make_pair(omxBuffer->bufferId, bufferInfo));
145         } else {
146             outputBuffers.emplace(std::make_pair(omxBuffer->bufferId, bufferInfo));
147         }
148     }
149     return true;
150 }
151 
152 class CodecHdiAdapterTest : public testing::Test {
153 public:
SetUpTestCase()154     static void SetUpTestCase()
155     {}
TearDownTestCase()156     static void TearDownTestCase()
157     {}
SetUp()158     void SetUp()
159     {}
TearDown()160     void TearDown()
161     {}
162 };
163 
164 static char g_arrayStr[ARRAY_TO_STR_LEN];
GetArrayStr(int32_t * array,int32_t arrayLen,int32_t endValue)165 static char *GetArrayStr(int32_t *array, int32_t arrayLen, int32_t endValue)
166 {
167     int32_t len = 0;
168     int32_t totalLen = 0;
169     int32_t ret;
170     char value[INT_TO_STR_LEN];
171     ret = memset_s(g_arrayStr, sizeof(g_arrayStr), 0, sizeof(g_arrayStr));
172     if (ret != EOK) {
173         HDF_LOGE("%{public}s: memset_s g_arrayStr failed, error code: %{public}d", __func__, ret);
174         return g_arrayStr;
175     }
176     for (int32_t i = 0; i < arrayLen; i++) {
177         if (array[i] == endValue) {
178             break;
179         }
180         ret = memset_s(value, sizeof(value), 0, sizeof(value));
181         if (ret != EOK) {
182             HDF_LOGE("%{public}s: memset_s value failed, error code: %{public}d", __func__, ret);
183             return g_arrayStr;
184         }
185         ret = sprintf_s(value, sizeof(value), "0x0%X, ", array[i]);
186         if (ret < 0) {
187             HDF_LOGE("%{public}s: sprintf_s value failed, error code: %{public}d", __func__, ret);
188             return g_arrayStr;
189         }
190         len = strnlen(value, ARRAY_TO_STR_LEN);
191         ret = memcpy_s(g_arrayStr + totalLen, len, value, len);
192         if (ret != EOK) {
193             HDF_LOGE("%{public}s: memcpy_s g_arrayStr failed, error code: %{public}d", __func__, ret);
194             return g_arrayStr;
195         }
196         totalLen += len;
197     }
198     return g_arrayStr;
199 }
200 
PrintCapability(CodecCompCapability * cap,int32_t index)201 static void PrintCapability(CodecCompCapability *cap, int32_t index)
202 {
203     HDF_LOGI("---------------------- component capability %{public}d ---------------------", index + 1);
204     HDF_LOGI("role:%{public}d", cap->role);
205     HDF_LOGI("type:%{public}d", cap->type);
206     HDF_LOGI("compName:%{public}s", cap->compName);
207     HDF_LOGI("supportProfiles:%{public}s", GetArrayStr(cap->supportProfiles, PROFILE_NUM, INVALID_PROFILE));
208     HDF_LOGI("maxInst:%{public}d", cap->maxInst);
209     HDF_LOGI("isSoftwareCodec:%{public}d", cap->isSoftwareCodec);
210     HDF_LOGI("processModeMask:0x0%{public}x", cap->processModeMask);
211     HDF_LOGI("capsMask:0x0%{public}x", cap->capsMask);
212     HDF_LOGI("bitRate.min:%{public}d", cap->bitRate.min);
213     HDF_LOGI("bitRate.max:%{public}d", cap->bitRate.max);
214     if (strstr(cap->compName, "video") != NULL) {
215         HDF_LOGI("minSize.width:%{public}d", cap->port.video.minSize.width);
216         HDF_LOGI("minSize.height:%{public}d", cap->port.video.minSize.height);
217         HDF_LOGI("maxSize.width:%{public}d", cap->port.video.maxSize.width);
218         HDF_LOGI("maxSize.height:%{public}d", cap->port.video.maxSize.height);
219         HDF_LOGI("widthAlignment:%{public}d", cap->port.video.whAlignment.widthAlignment);
220         HDF_LOGI("heightAlignment:%{public}d", cap->port.video.whAlignment.heightAlignment);
221         HDF_LOGI("blockCount.min:%{public}d", cap->port.video.blockCount.min);
222         HDF_LOGI("blockCount.max:%{public}d", cap->port.video.blockCount.max);
223         HDF_LOGI("blocksPerSecond.min:%{public}d", cap->port.video.blocksPerSecond.min);
224         HDF_LOGI("blocksPerSecond.max:%{public}d", cap->port.video.blocksPerSecond.max);
225         HDF_LOGI("blockSize.width:%{public}d", cap->port.video.blockSize.width);
226         HDF_LOGI("blockSize.height:%{public}d", cap->port.video.blockSize.height);
227         HDF_LOGI("supportPixFmts:%{public}s", GetArrayStr(cap->port.video.supportPixFmts, PIX_FORMAT_NUM, 0));
228     } else {
229         HDF_LOGI(":%{public}s", GetArrayStr(cap->port.audio.sampleFormats, SAMPLE_FMT_NUM, AUDIO_SAMPLE_FMT_INVALID));
230         HDF_LOGI(":%{public}s", GetArrayStr(cap->port.audio.sampleRate, SAMPLE_RATE_NUM, AUD_SAMPLE_RATE_INVALID));
231         HDF_LOGI(":%{public}s", GetArrayStr(cap->port.audio.channelLayouts, CHANNEL_NUM, -1));
232         HDF_LOGI(":%{public}s", GetArrayStr(cap->port.audio.channelCount, CHANNEL_NUM, -1));
233     }
234     HDF_LOGI("-------------------------------------------------------------------");
235 }
236 /**
237 * @tc.name  HdfCodecHdiGetCodecComponentManagerTest_001
238 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0010
239 * @tc.desc Invoke the GetCodecComponentManager interface to obtain component management objects
240 */
241 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0010, Function | MediumTest | Level3)
242 {
243     g_manager = GetCodecComponentManager();
244     ASSERT_TRUE(g_manager != nullptr);
245     g_callback = CodecCallbackTypeGet(nullptr);
246     ASSERT_TRUE(g_callback != nullptr);
247 }
248 /**
249 * @tc.name  HdfCodecHdiGetComponentNumTest_001
250 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0020
251 * @tc.desc Invoke the GetComponentNumber interface to obtain the number of components
252 */
253 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0020, Function | MediumTest | Level3)
254 {
255     ASSERT_TRUE(g_manager != nullptr);
256     g_count = g_manager->GetComponentNum();
257     ASSERT_GT(g_count, 0);
258 }
259 /**
260 * @tc.name  HdfCodecHdiGetComponentCapabilityListTest_001
261 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0030
262 * @tc.desc Invoke the GetComponentCapabilityList interface to obtain the component capability set
263 */
264 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0030, Function | MediumTest | Level3)
265 {
266     ASSERT_GT(g_count, 0);
267     ASSERT_TRUE(g_manager != nullptr);
268     CodecCompCapability *capList = (CodecCompCapability *)OsalMemAlloc(sizeof(CodecCompCapability) * g_count);
269     ASSERT_TRUE(capList != nullptr);
270     g_manager->GetComponentCapabilityList(capList, g_count);
271     for (int32_t i = 0; i < g_count; i++) {
272         PrintCapability(&capList[i], i);
273     }
274     OsalMemFree(capList);
275     capList = nullptr;
276 }
277 /**
278 * @tc.name  HdfCodecHdiCreateComponentCompNameErrorTest_001
279 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0040
280 * @tc.desc If compName is a component name that does not exist, the CreateComponent
281            interface is invoked to create a component
282 */
283 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0040, Function | MediumTest | Level3)
284 {
285     ASSERT_TRUE(g_manager != nullptr);
286     ASSERT_TRUE(g_callback != nullptr);
287     char name[] = "test";
288     int32_t ret = g_manager->CreateComponent(&g_component, &g_componentId, (char *)name, APP_DATA, g_callback);
289     ASSERT_NE(ret, HDF_SUCCESS);
290     ASSERT_TRUE(g_component == nullptr);
291 }
292 /**
293 * @tc.name  HdfCodecHdiCreateComponentCompNameNullptrTest_002
294 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0050
295 * @tc.desc When compName is set to Nullptr, the CreateComponent interface is invoked to create a component
296 */
297 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0050, Function | MediumTest | Level3)
298 {
299     ASSERT_TRUE(g_manager != nullptr);
300     ASSERT_TRUE(g_callback != nullptr);
301     int32_t ret = g_manager->CreateComponent(&g_component, &g_componentId, nullptr, APP_DATA, g_callback);
302     ASSERT_NE(ret, HDF_SUCCESS);
303     ASSERT_TRUE(g_component == nullptr);
304 }
305 /**
306 * @tc.name  HdfCodecHdiCreateComponentAppdataMaxTest_003
307 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0060
308 * @tc.desc When Appdata is the maximum value in the value range, the CreateComponent
309            interface is invoked to create a component
310 */
311 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0060, Function | MediumTest | Level3)
312 {
313     ASSERT_TRUE(g_manager != nullptr);
314     struct CodecCallbackType *callback = CodecCallbackTypeGet(nullptr);
315     ASSERT_TRUE(callback != nullptr);
316     struct CodecComponentType *component = nullptr;
317     uint32_t componentId = 0;
318     int32_t ret = g_manager->CreateComponent(&component, &componentId, const_cast<char *>(DECODER_AVC),
319                                              APP_DATA_MAX, callback);
320     ASSERT_EQ(ret, HDF_SUCCESS);
321     ASSERT_TRUE(component != nullptr);
322     ret = g_manager->DestroyComponent(componentId);
323     ASSERT_EQ(ret, HDF_SUCCESS);
324     CodecCallbackTypeRelease(callback);
325     callback = nullptr;
326 }
327 /**
328 * @tc.name HdfCodecHdiCreateComponentAppdataMinTest_004
329 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0070
330 * @tc.desc When Appdata is the minimum value in the value range, the CreateComponent
331            interface is invoked to create a componentt
332 */
333 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0070, Function | MediumTest | Level3)
334 {
335     ASSERT_TRUE(g_manager != nullptr);
336     struct CodecCallbackType *callback = CodecCallbackTypeGet(nullptr);
337     ASSERT_TRUE(callback != nullptr);
338     struct CodecComponentType *component = nullptr;
339     uint32_t componentId = 0;
340     int32_t ret = g_manager->CreateComponent(&component, &componentId, const_cast<char *>(DECODER_AVC),
341                                              APP_DATA_MIN, callback);
342     ASSERT_EQ(ret, HDF_SUCCESS);
343     ASSERT_TRUE(component != nullptr);
344     ret = g_manager->DestroyComponent(componentId);
345     ASSERT_EQ(ret, HDF_SUCCESS);
346     CodecCallbackTypeRelease(callback);
347     callback = nullptr;
348 }
349 /**
350 * @tc.name HdfCodecHdiCreateComponentCallbackIsNullptrTest_005
351 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0080
352 * @tc.desc When callback is nullptr, the CreateComponent interface is invoked to create a component
353 */
354 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0080, Function | MediumTest | Level3)
355 {
356     ASSERT_TRUE(g_manager != nullptr);
357     struct CodecCallbackType *callback = nullptr;
358     struct CodecComponentType *component = nullptr;
359     uint32_t componentId = 0;
360     int32_t ret = g_manager->CreateComponent(&component, &componentId, const_cast<char *>(DECODER_AVC),
361                                              APP_DATA, callback);
362     ASSERT_NE(ret, HDF_SUCCESS);
363 }
364 /**
365 * @tc.name HdfCodecHdiCreateComponentSuccessTest_006
366 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0090
367 * @tc.desc Invoke the CreateComponent interface to create a video encoding component
368 */
369 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0090, Function | MediumTest | Level3)
370 {
371     ASSERT_TRUE(g_manager != nullptr);
372     ASSERT_TRUE(g_callback != nullptr);
373     int32_t ret = g_manager->CreateComponent(&g_component, &g_componentId, const_cast<char *>(ENCODER_AVC), APP_DATA,
374                                              g_callback);
375     ASSERT_EQ(ret, HDF_SUCCESS);
376     ASSERT_TRUE(g_component != nullptr);
377 }
378 // Test GetComponentVersion Adapter not support
379 /**
380 * @tc.name HdfCodecHdiGetComponentVersionUnsupportedTest_001
381 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0100
382 * @tc.desc Invoke the GetComponentVersion interface to obtain the component version
383 */
384 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0100, Function | MediumTest | Level3)
385 {
386     ASSERT_TRUE(g_component != nullptr);
387     struct CompVerInfo verInfo;
388     int32_t ret = g_component->GetComponentVersion(g_component, &verInfo);
389     g_version = verInfo.compVersion;
390     ASSERT_NE(ret, HDF_SUCCESS);
391 }
392 // Test GetParameter
393 /**
394 * @tc.name HdfCodecHdiGetParameterParamStructNullptrTest_001
395 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0110
396 * @tc.desc When paramStrut is set to nullptr, the GetParameter interface is invoked to obtain component parameters
397 */
398 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0110, Function | MediumTest | Level3)
399 {
400     ASSERT_TRUE(g_component != nullptr);
401     auto ret = g_component->GetParameter(g_component, OMX_IndexParamVideoPortFormat, nullptr, 0);
402     ASSERT_NE(ret, HDF_SUCCESS);
403 }
404 /**
405 * @tc.name HdfCodecHdiGetParameterSuccessTest_002
406 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0120
407 * @tc.desc The GetParameter interface is invoked to obtain component parameters
408 */
409 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0120, Function | MediumTest | Level3)
410 {
411     ASSERT_TRUE(g_component != nullptr);
412     OMX_VIDEO_PARAM_PORTFORMATTYPE param;
413     InitParam(param);
414     param.nPortIndex = (uint32_t)PortIndex::PORT_INDEX_INPUT;
415     param.eCompressionFormat = OMX_VIDEO_CodingAVC;
416     auto ret = g_component->GetParameter(g_component, OMX_IndexParamVideoPortFormat, reinterpret_cast<int8_t *>(&param),
417                                          sizeof(param));
418     ASSERT_EQ(ret, HDF_SUCCESS);
419 }
420 /**
421 * @tc.name HdfCodecHdiGetParameterSuccessTest_002
422 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0130
423 * @tc.desc Invoke the GetParameter interface to obtain component parameters when paramIndex does not match
424 */
425 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0130, Function | MediumTest | Level3)
426 {
427     ASSERT_TRUE(g_component != nullptr);
428     OMX_VIDEO_CONFIG_BITRATETYPE param;
429     InitParam(param);
430     param.nPortIndex = (uint32_t)PortIndex::PORT_INDEX_INPUT;
431     auto ret = g_component->GetParameter(g_component, OMX_IndexParamVideoPortFormat, reinterpret_cast<int8_t *>(&param),
432                                          sizeof(param));
433     ASSERT_NE(ret, HDF_SUCCESS);
434 }
435 /**
436 * @tc.name HdfCodecHdiGetParameterParamIndexUnusedTest_004
437 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0140
438 * @tc.desc When paramIndex is set to, invoke the GetParameter interface to obtain component parameters
439 */
440 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0140, Function | MediumTest | Level3)
441 {
442     ASSERT_TRUE(g_component != nullptr);
443     OMX_VIDEO_CONFIG_BITRATETYPE param;
444     InitParam(param);
445     param.nPortIndex = (uint32_t)PortIndex::PORT_INDEX_INPUT;
446     auto ret = g_component->GetParameter(g_component, OMX_IndexVideoStartUnused, reinterpret_cast<int8_t *>(&param),
447                                          sizeof(param));
448     ASSERT_NE(ret, HDF_SUCCESS);
449 }
450 /**
451 * @tc.name HdfCodecHdiSetParameterSuccessTest_001
452 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0150
453 * @tc.desc The SetParameter interface is invoked to set component parameters
454 */
455 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0150, Function | MediumTest | Level3)
456 {
457     ASSERT_TRUE(g_component != nullptr);
458     OMX_VIDEO_PARAM_PORTFORMATTYPE param;
459     InitParam(param);
460     param.nPortIndex = (uint32_t)PortIndex::PORT_INDEX_INPUT;
461     int32_t ret = g_component->SetParameter(g_component, OMX_IndexParamVideoPortFormat,
462                                             reinterpret_cast<int8_t *>(&param), sizeof(param));
463     ASSERT_EQ(ret, HDF_SUCCESS);
464 }
465 /**
466 * @tc.name HdfCodecHdiSetParameterParamStructNullptrTest_002
467 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0160
468 * @tc.desc When paramStrut is set to nullptr, the SetParameter interface is invoked to set component parameters
469 */
470 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0160, Function | MediumTest | Level3)
471 {
472     ASSERT_TRUE(g_component != nullptr);
473     int32_t ret = g_component->SetParameter(g_component, OMX_IndexParamVideoPortFormat, nullptr, 0);
474     ASSERT_NE(ret, HDF_SUCCESS);
475 }
476 /**
477 * @tc.name HdfCodecHdiSetParameterParamIndexNotMatchParamStructTest_003
478 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0170
479 * @tc.desc When paramIndex does not match paramStruct, the SetParameter
480            interface is invoked to set component parameters
481 */
482 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0170, Function | MediumTest | Level3)
483 {
484     ASSERT_TRUE(g_component != nullptr);
485     OMX_VIDEO_CONFIG_BITRATETYPE param;
486     InitParam(param);
487     param.nPortIndex = (uint32_t)PortIndex::PORT_INDEX_INPUT;
488     int32_t ret = g_component->SetParameter(g_component, OMX_IndexParamVideoPortFormat,
489                                             reinterpret_cast<int8_t *>(&param), sizeof(param));
490     ASSERT_NE(ret, HDF_SUCCESS);
491 }
492 /**
493 * @tc.name HdfCodecHdiSetParameterParamIndexUnusedTest_004
494 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0180
495 * @tc.desc When paramIndex is set to OMX_IndexVideoStartUnused, the SetParameter
496            interface is invoked to set component parameters
497 */
498 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0180, Function | MediumTest | Level3)
499 {
500     ASSERT_TRUE(g_component != nullptr);
501     OMX_VIDEO_PARAM_PORTFORMATTYPE param;
502     InitParam(param);
503     param.nPortIndex = (uint32_t)PortIndex::PORT_INDEX_INPUT;
504     int32_t ret = g_component->SetParameter(g_component, OMX_IndexVideoStartUnused, reinterpret_cast<int8_t *>(&param),
505                                             sizeof(param));
506     ASSERT_NE(ret, HDF_SUCCESS);
507 }
508 /**
509 * @tc.name HdfCodecHdiSetParameterCodecComponentTypeNullptrTest_005
510 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0190
511 * @tc.desc When CodecComponentType is set to nullptr, the SetParameter interface is invoked to set component parameters
512 */
513 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0190, Function | MediumTest | Level3)
514 {
515     ASSERT_TRUE(g_component != nullptr);
516     OMX_VIDEO_PARAM_PORTFORMATTYPE param;
517     InitParam(param);
518     param.nPortIndex = (uint32_t)PortIndex::PORT_INDEX_INPUT;
519     int32_t ret = g_component->SetParameter(nullptr, OMX_IndexParamVideoPortFormat, reinterpret_cast<int8_t *>(&param),
520                                             sizeof(param));
521     ASSERT_NE(ret, HDF_SUCCESS);
522 }
523 /**
524 * @tc.name HdfCodecHdiSetParameterParamStructLenNotMatchTest_006
525 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0200
526 * @tc.desc Invoke the SetParameter interface to set component parameters when paramStructLen does not match
527 */
528 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0200, Function | MediumTest | Level3)
529 {
530     ASSERT_TRUE(g_component != nullptr);
531     OMX_VIDEO_PARAM_PORTFORMATTYPE param;
532     InitParam(param);
533     param.nPortIndex = (uint32_t)PortIndex::PORT_INDEX_INPUT;
534     int32_t ret = g_component->SetParameter(g_component, OMX_IndexParamVideoPortFormat,
535                                  reinterpret_cast<int8_t *>(&param), 0);
536     ASSERT_NE(ret, HDF_SUCCESS);
537 }
538 /**
539 * @tc.name HdfCodecHdiGetConfigUnsupportedTest_001
540 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0210
541 * @tc.desc Invoke the GetConfig interface to obtain component configurations
542 */
543 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0210, Function | MediumTest | Level3)
544 {
545     ASSERT_TRUE(g_component != nullptr);
546     OMX_VIDEO_CONFIG_BITRATETYPE param;
547     InitParam(param);
548     param.nPortIndex = (uint32_t)PortIndex::PORT_INDEX_OUTPUT;
549     int32_t ret = g_component->GetConfig(g_component, OMX_IndexConfigVideoBitrate, reinterpret_cast<int8_t *>(&param),
550                                          sizeof(param));
551     ASSERT_NE(ret, HDF_SUCCESS);
552 }
553 /**
554 * @tc.name HdfCodecHdiSetConfigUnsupportedTest_001
555 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0220
556 * @tc.desc Invoke the SetConfig interface to set component configurations
557 */
558 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0220, Function | MediumTest | Level3)
559 {
560     ASSERT_TRUE(g_component != nullptr);
561     OMX_VIDEO_CONFIG_BITRATETYPE param;
562     InitParam(param);
563     param.nPortIndex = (uint32_t)PortIndex::PORT_INDEX_OUTPUT;
564     param.nEncodeBitrate = FRAMERATE;
565     int32_t ret = g_component->SetConfig(g_component, OMX_IndexConfigVideoBitrate, reinterpret_cast<int8_t *>(&param),
566                                          sizeof(param));
567     ASSERT_NE(ret, HDF_SUCCESS);
568 }
569 /**
570 * @tc.name HdfCodecHdiGetExtensionIndexUnsupportedTest_001
571 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0230
572 * @tc.desc Invoke the GetExtensionIndex interface to obtain the component extended index
573 */
574 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0230, Function | MediumTest | Level3)
575 {
576     ASSERT_TRUE(g_component != nullptr);
577     OMX_INDEXTYPE indexType;
578     int32_t ret =
579         g_component->GetExtensionIndex(g_component, "OMX.Topaz.index.param.extended_video", (uint32_t *)&indexType);
580     ASSERT_NE(ret, HDF_SUCCESS);
581 }
582 /**
583 * @tc.name HdfCodecHdiGetStateSuccessTest_001
584 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0240
585 * @tc.desc When state is set to OMX_StateLoaded, the GetState interface is invoked to obtain the component status
586 */
587 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0240, Function | MediumTest | Level3)
588 {
589     ASSERT_TRUE(g_component != nullptr);
590     OMX_STATETYPE state;
591     int32_t ret = g_component->GetState(g_component, &state);
592     ASSERT_EQ(state, OMX_StateLoaded);
593     ASSERT_EQ(ret, HDF_SUCCESS);
594 }
595 /**
596 * @tc.name HdfCodecHdiGetStateStateNullptrTest_002
597 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0250
598 * @tc.desc When state is set to nullptr, the GetState interface is invoked to obtain the component status
599 */
600 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0250, Function | MediumTest | Level3)
601 {
602     ASSERT_TRUE(g_component != nullptr);
603     int32_t ret = g_component->GetState(g_component, nullptr);
604     ASSERT_NE(ret, HDF_SUCCESS);
605 }
606 /**
607 * @tc.name HdfCodecHdiTunnelRequestUnsupportedTest_001
608 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0260
609 * @tc.desc Invoke the ComponentTunnelRequest interface to set component pipe communication
610 */
611 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0260, Function | MediumTest | Level3)
612 {
613     ASSERT_TRUE(g_component != nullptr);
614     const int32_t tunneledComp = 1002;
615     const uint32_t tunneledPort = 101;
616     OMX_TUNNELSETUPTYPE tunnelSetup;
617     tunnelSetup.eSupplier = OMX_BufferSupplyInput;
618 
619     int32_t ret = g_component->ComponentTunnelRequest(g_component, (uint32_t)PortIndex::PORT_INDEX_OUTPUT, tunneledComp,
620                                                       tunneledPort, &tunnelSetup);
621     ASSERT_NE(ret, HDF_SUCCESS);
622 }
623 /**
624 * @tc.name HdfCodecHdiAllocateBufferInvalidInputBufferTypeTest_001
625 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0270
626 * @tc.desc When bufferType is set to InvalidInput and portIndex is set to PORT_INDEX_INPUT, the AllocateBuffer
627            interface is invoked to set the external buffer
628 */
629 struct OmxCodecBuffer allocBuffer;
630 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0270, Function | MediumTest | Level3)
631 {
632     ASSERT_TRUE(g_component != nullptr);
633     allocBuffer.bufferType = CODEC_BUFFER_TYPE_INVALID;
634     allocBuffer.fenceFd = -1;
635     allocBuffer.version = g_version;
636     allocBuffer.allocLen = BUFFER_SIZE;
637     allocBuffer.buffer = 0;
638     allocBuffer.bufferLen = 0;
639     allocBuffer.pts = 0;
640     allocBuffer.flag = 0;
641     allocBuffer.type = READ_ONLY_TYPE;
642     int32_t ret = g_component->AllocateBuffer(g_component, (uint32_t)PortIndex::PORT_INDEX_INPUT, &allocBuffer);
643     ASSERT_NE(ret, HDF_SUCCESS);
644 }
645 /**
646 * @tc.name HdfCodecHdiAllocateBufferInputBufferNotInitTest_002
647 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0280
648 * @tc.desc When the buffer is not initialized and portIndex is set to PORT_INDEX_INPUT, the AllocateBuffer
649            interface is invoked to set the external buffer
650 */
651 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0280, Function | MediumTest | Level3)
652 {
653     ASSERT_TRUE(g_component != nullptr);
654     allocBuffer.bufferType = CODEC_BUFFER_TYPE_VIRTUAL_ADDR;
655     int32_t ret = g_component->AllocateBuffer(g_component, (uint32_t)PortIndex::PORT_INDEX_INPUT, &allocBuffer);
656     ASSERT_NE(ret, HDF_SUCCESS);
657 }
658 /**
659 * @tc.name HdfCodecHdiAllocateBufferInvalidOutputBufferTypeTest_003
660 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0290
661 * @tc.desc When bufferType is set to InvalidInput and portIndex is set to PORT_INDEX_OUTPUT, the AllocateBuffer
662            interface is invoked to set the external buffer
663 */
664 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0290, Function | MediumTest | Level3)
665 {
666     ASSERT_TRUE(g_component != nullptr);
667     allocBuffer.bufferType = CODEC_BUFFER_TYPE_INVALID;
668     int32_t ret = g_component->AllocateBuffer(g_component, (uint32_t)PortIndex::PORT_INDEX_OUTPUT, &allocBuffer);
669     ASSERT_NE(ret, HDF_SUCCESS);
670 }
671 /**
672 * @tc.name HdfCodecHdiAllocateBufferOutputBufferNotInitTest_004
673 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0300
674 * @tc.desc When the buffer is not initialized and portIndex is set to PORT_INDEX_OUTPUT, the AllocateBuffer
675            interface is invoked to set the external buffer
676 */
677 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0300, Function | MediumTest | Level3)
678 {
679     ASSERT_TRUE(g_component != nullptr);
680     allocBuffer.bufferType = CODEC_BUFFER_TYPE_VIRTUAL_ADDR;
681     int32_t ret = g_component->AllocateBuffer(g_component, (uint32_t)PortIndex::PORT_INDEX_OUTPUT, &allocBuffer);
682     ASSERT_NE(ret, HDF_SUCCESS);
683 }
684 /**
685 * @tc.name HdfCodecHdiAllocateBufferAvshareMemFdInputNotInitTest_005
686 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0310
687 * @tc.desc When the buffer is not initialized and portIndex is set to PORT_INDEX_OUTPUT, the AllocateBuffer
688            interface is invoked to set the external buffer
689 */
690 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0310, Function | MediumTest | Level3)
691 {
692     ASSERT_TRUE(g_component != nullptr);
693     allocBuffer.bufferType = CODEC_BUFFER_TYPE_AVSHARE_MEM_FD;
694     int32_t ret = g_component->AllocateBuffer(g_component, (uint32_t)PortIndex::PORT_INDEX_INPUT, &allocBuffer);
695     ASSERT_NE(ret, HDF_SUCCESS);
696 }
697 /**
698 * @tc.name HdfCodecHdiAllocateBufferAvshareMemFdOutputNotInitTest_006
699 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0320
700 * @tc.desc When the buffer is not initialized and portIndex is set to PORT_INDEX_OUTPUT, the AllocateBuffer
701            interface is invoked to set the external buffer
702 */
703 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0320, Function | MediumTest | Level3)
704 {
705     ASSERT_TRUE(g_component != nullptr);
706     allocBuffer.bufferType = CODEC_BUFFER_TYPE_AVSHARE_MEM_FD;
707     int32_t ret = g_component->AllocateBuffer(g_component, (uint32_t)PortIndex::PORT_INDEX_OUTPUT, &allocBuffer);
708     ASSERT_NE(ret, HDF_SUCCESS);
709 }
710 /**
711 * @tc.name HdfCodecHdiUseBufferInvalidInputBufferTypeTest_001
712 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0330
713 * @tc.desc When bufferType is set to InvalidInput and portIndex is set to PORT_INDEX_INPUT,
714            the UseBuffer interface is invoked to set the internal buffer
715 */
716 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0330, Function | MediumTest | Level3)
717 {
718     ASSERT_TRUE(g_component != nullptr);
719     std::shared_ptr<OmxCodecBuffer> omxBuffer = std::make_shared<OmxCodecBuffer>();
720     ASSERT_TRUE(omxBuffer != nullptr);
721     omxBuffer->size = sizeof(OmxCodecBuffer);
722     omxBuffer->version = g_version;
723     omxBuffer->bufferType = CODEC_BUFFER_TYPE_INVALID;
724     omxBuffer->bufferLen = 0;
725     omxBuffer->buffer = nullptr;
726     omxBuffer->allocLen = 0;
727     omxBuffer->fenceFd = -1;
728     omxBuffer->pts = 0;
729     omxBuffer->flag = 0;
730 
731     auto err = g_component->UseBuffer(g_component, (uint32_t)PortIndex::PORT_INDEX_INPUT, omxBuffer.get());
732     ASSERT_NE(err, HDF_SUCCESS);
733 }
734 /**
735 * @tc.name HdfCodecHdiUseBufferInvalidOutputBufferTypeTest_002
736 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0340
737 * @tc.desc When bufferType is set to InvalidInput and portIndex is set to PORT_INDEX_OUTPUT,
738            the UseBuffer interface is called to set the internal buffer
739 */
740 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0340, Function | MediumTest | Level3)
741 {
742     ASSERT_TRUE(g_component != nullptr);
743     std::shared_ptr<OmxCodecBuffer> omxBuffer = std::make_shared<OmxCodecBuffer>();
744     ASSERT_TRUE(omxBuffer != nullptr);
745     omxBuffer->size = sizeof(OmxCodecBuffer);
746     omxBuffer->version = g_version;
747     omxBuffer->bufferType = CODEC_BUFFER_TYPE_INVALID;
748     omxBuffer->bufferLen = 0;
749     omxBuffer->buffer = nullptr;
750     omxBuffer->allocLen = 0;
751     omxBuffer->fenceFd = -1;
752     omxBuffer->pts = 0;
753     omxBuffer->flag = 0;
754 
755     auto err = g_component->UseBuffer(g_component, (uint32_t)PortIndex::PORT_INDEX_OUTPUT, omxBuffer.get());
756     ASSERT_NE(err, HDF_SUCCESS);
757 }
758 /**
759 * @tc.name HdfCodecHdiUseBufferTestVirtualAddrInputTest_003
760 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0350
761 * @tc.desc When the buffer is not initialized and portIndex is set to PORT_INDEX_INPUT,
762            the UseBuffer interface is invoked to set the internal buffer
763 */
764 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0350, Function | MediumTest | Level3)
765 {
766     ASSERT_TRUE(g_component != nullptr);
767     std::shared_ptr<OmxCodecBuffer> omxBuffer = std::make_shared<OmxCodecBuffer>();
768     ASSERT_TRUE(omxBuffer != nullptr);
769     omxBuffer->size = sizeof(OmxCodecBuffer);
770     omxBuffer->version = g_version;
771     omxBuffer->bufferType = CODEC_BUFFER_TYPE_VIRTUAL_ADDR;
772     omxBuffer->bufferLen = 0;
773     omxBuffer->buffer = nullptr;
774     omxBuffer->allocLen = 0;
775     omxBuffer->fenceFd = -1;
776     omxBuffer->pts = 0;
777     omxBuffer->flag = 0;
778 
779     auto err = g_component->UseBuffer(g_component, (uint32_t)PortIndex::PORT_INDEX_INPUT, omxBuffer.get());
780     ASSERT_NE(err, HDF_SUCCESS);
781 }
782 /**
783 * @tc.name HdfCodecHdiUseBufferTestVirtualAddrOutput_004
784 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0360
785 * @tc.desc When the buffer is not initialized and portIndex is set to PORT_INDEX_OUTPUT,
786            call the UseBuffer interface to set the internal buffer
787 */
788 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0360, Function | MediumTest | Level3)
789 {
790     ASSERT_TRUE(g_component != nullptr);
791     std::shared_ptr<OmxCodecBuffer> omxBuffer = std::make_shared<OmxCodecBuffer>();
792     ASSERT_TRUE(omxBuffer != nullptr);
793     omxBuffer->size = sizeof(OmxCodecBuffer);
794     omxBuffer->version = g_version;
795     omxBuffer->bufferType = CODEC_BUFFER_TYPE_VIRTUAL_ADDR;
796     omxBuffer->bufferLen = 0;
797     omxBuffer->buffer = nullptr;
798     omxBuffer->allocLen = 0;
799     omxBuffer->fenceFd = -1;
800     omxBuffer->pts = 0;
801     omxBuffer->flag = 0;
802 
803     auto err = g_component->UseBuffer(g_component, (uint32_t)PortIndex::PORT_INDEX_OUTPUT, omxBuffer.get());
804     ASSERT_NE(err, HDF_SUCCESS);
805 }
806 /**
807 * @tc.name HdfCodecHdiUseBufferInputSuccessTest_005
808 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0370
809 * @tc.desc After the buffer is initialized and portIndex is set to PORT_INDEX_INPUT
810            the UseBuffer interface is invoked to set the internal buffe
811 */
812 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0370, Function | MediumTest | Level3)
813 {
814     ASSERT_TRUE(g_component != nullptr);
815     OMX_PARAM_PORTDEFINITIONTYPE param;
816     InitParam(param);
817     param.nPortIndex = (OMX_U32)PortIndex::PORT_INDEX_INPUT;
818     auto err = g_component->GetParameter(g_component, OMX_IndexParamPortDefinition, (int8_t *)&param, sizeof(param));
819     ASSERT_EQ(err, HDF_SUCCESS);
820 
821     int bufferSize = param.nBufferSize;
822     int bufferCount = param.nBufferCountActual;
823     bool ret = UseBufferOnPort(PortIndex::PORT_INDEX_INPUT, bufferCount, bufferSize);
824     ASSERT_TRUE(ret);
825 }
826 /**
827 * @tc.name HdfCodecHdiUseBufferOutputSuccessTest_006
828 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0380
829 * @tc.desc After the buffer is initialized and portIndex is set to PORT_INDEX_OUTPUT,
830            call the UseBuffer interface to set the internal buffer
831 */
832 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0380, Function | MediumTest | Level3)
833 {
834     ASSERT_TRUE(g_component != nullptr);
835     OMX_PARAM_PORTDEFINITIONTYPE param;
836     InitParam(param);
837     param.nPortIndex = (OMX_U32)PortIndex::PORT_INDEX_OUTPUT;
838     auto err = g_component->GetParameter(g_component, OMX_IndexParamPortDefinition, (int8_t *)&param, sizeof(param));
839     ASSERT_EQ(err, HDF_SUCCESS);
840 
841     int bufferSize = param.nBufferSize;
842     int bufferCount = param.nBufferCountActual;
843     bool ret = UseBufferOnPort(PortIndex::PORT_INDEX_OUTPUT, bufferCount, bufferSize);
844     ASSERT_TRUE(ret);
845 }
846 /**
847 * @tc.name HdfCodecHdiUseBufferDynamicHandleOutputTest_007
848 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0390
849 * @tc.desc When bufferType is set to DynamicHandle and portIndex is set to PORT_INDEX_INPUT,
850            the UseBuffer interface is invoked to set the internal buffer
851 */
852 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0390, Function | MediumTest | Level3)
853 {
854     ASSERT_TRUE(g_component != nullptr);
855     std::shared_ptr<OmxCodecBuffer> omxBuffer = std::make_shared<OmxCodecBuffer>();
856     ASSERT_TRUE(omxBuffer != nullptr);
857     omxBuffer->size = sizeof(OmxCodecBuffer);
858     omxBuffer->version = g_version;
859     omxBuffer->bufferType = CODEC_BUFFER_TYPE_DYNAMIC_HANDLE;
860 
861     omxBuffer->bufferLen = 0;
862     omxBuffer->buffer = nullptr;
863     omxBuffer->allocLen = 0;
864     omxBuffer->fenceFd = -1;
865     omxBuffer->pts = 0;
866     omxBuffer->flag = 0;
867 
868     auto err = g_component->UseBuffer(g_component, (uint32_t)PortIndex::PORT_INDEX_OUTPUT, omxBuffer.get());
869     if (err != HDF_SUCCESS) {
870         HDF_LOGE("%{public}s failed to UseBuffer with  input port", __func__);
871         omxBuffer = nullptr;
872     }
873     ASSERT_NE(err, HDF_SUCCESS);
874 }
875 /**
876 * @tc.name HdfCodecHdiUseBufferAbnormalPortIndexTest_008
877 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0400
878 * @tc.desc After the buffer is initialized and portIndex is set to PORT_INDEX_ERROR_INPUT,
879            call the UseBuffer interface to set the internal buffer
880 */
881 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0400, Function | MediumTest | Level3)
882 {
883     ASSERT_TRUE(g_component != nullptr);
884     OMX_PARAM_PORTDEFINITIONTYPE param;
885     InitParam(param);
886     param.nPortIndex = (OMX_U32)PortIndex::PORT_INDEX_INPUT;
887     auto err = g_component->GetParameter(g_component, OMX_IndexParamPortDefinition, (int8_t *)&param, sizeof(param));
888     ASSERT_EQ(err, HDF_SUCCESS);
889 
890     int bufferSize = param.nBufferSize;
891     int bufferCount = param.nBufferCountActual;
892     bool ret = UseBufferOnPort(PortIndex::PORT_INDEX_ERROR_INPUT, bufferCount, bufferSize);
893     ASSERT_FALSE(ret);
894 }
895 /**
896 * @tc.name HdfCodecHdiSetStateLoadedToIdleTest_001
897 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0410
898 * @tc.desc The status of the component that invokes the SendCommand
899            interface changes from OMX_StateLoaded to OMX_StateIdle
900 */
901 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0410, Function | MediumTest | Level3)
902 {
903     ASSERT_TRUE(g_component != nullptr);
904     int32_t ret = g_component->SendCommand(g_component, OMX_CommandStateSet, OMX_StateIdle, nullptr, 0);
905     ASSERT_EQ(ret, HDF_SUCCESS);
906 }
907 /**
908 * @tc.name HdfCodecHdiSetStateIdleToExecutingTest_002
909 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0420
910 * @tc.desc The status of the component that invokes the SendCommand
911            interface changes from OMX_StateIdle to OMX_StateExecuting
912 */
913 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0420, Function | MediumTest | Level3)
914 {
915     ASSERT_TRUE(g_component != nullptr);
916     int32_t ret = g_component->SendCommand(g_component, OMX_CommandStateSet, OMX_StateExecuting, nullptr, 0);
917     ASSERT_EQ(ret, HDF_SUCCESS);
918 }
919 /**
920 * @tc.name HdfCodecHdiSetStateExecutingToPauseTest_003
921 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0430
922 * @tc.desc The status of the component that invokes the SendCommand
923            interface changes from OMX_StateExecuting to OMX_StatePause
924 */
925 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0430, Function | MediumTest | Level3)
926 {
927     ASSERT_TRUE(g_component != nullptr);
928     int32_t ret = g_component->SendCommand(g_component, OMX_CommandStateSet, OMX_StatePause, nullptr, 0);
929     ASSERT_EQ(ret, HDF_SUCCESS);
930 }
931 /**
932 * @tc.name HdfCodecHdiSetStatePauseToIdleTest_004
933 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0440
934 * @tc.desc The status of the component that invokes the SendCommand
935            interface changes from OMX_StatePause to OMX_StateIdle
936 */
937 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0440, Function | MediumTest | Level3)
938 {
939     ASSERT_TRUE(g_component != nullptr);
940     int32_t ret = g_component->SendCommand(g_component, OMX_CommandStateSet, OMX_StateIdle, nullptr, 0);
941     ASSERT_EQ(ret, HDF_SUCCESS);
942 
943     OMX_STATETYPE state;
944     ret = g_component->GetState(g_component, &state);
945     ASSERT_EQ(ret, HDF_SUCCESS);
946 }
947 /**
948 * @tc.name HdfCodecHdiSendCommandCodecComponentTypeNullptrTest_005
949 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0450
950 * @tc.desc When CodecComponentType is set to Nullptr, the SendCommand
951            interface is invoked to send instructions
952 */
953 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0450, Function | MediumTest | Level3)
954 {
955     ASSERT_TRUE(g_component != nullptr);
956     int32_t ret = g_component->SendCommand(nullptr, OMX_CommandStateSet, OMX_StateIdle, nullptr, 0);
957     ASSERT_NE(ret, HDF_SUCCESS);
958 }
959 /**
960 * @tc.name HdfCodecHdiSendCommandAbnormalCommandTest_006
961 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0460
962 * @tc.desc When OMX_COMMANDTYPE is set to OMX_StateMax, the SendCommand
963            interface is invoked to send instructions
964 */
965 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0460, Function | MediumTest | Level3)
966 {
967     ASSERT_TRUE(g_component != nullptr);
968     int32_t ret = g_component->SendCommand(g_component, OMX_CommandMax, OMX_StatePause, nullptr, 0);
969     ASSERT_NE(ret, HDF_SUCCESS);
970 }
971 /**
972 * @tc.name HdfCodecHdiSendCommandAbnormalParamTest_007
973 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0470
974 * @tc.desc When the cmd command is set to OMX_StateMax, the SendCommand
975            interface is invoked to send the command
976 */
977 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0470, Function | MediumTest | Level3)
978 {
979     ASSERT_TRUE(g_component != nullptr);
980     int32_t ret = g_component->SendCommand(g_component, OMX_CommandStateSet, OMX_StateMax, nullptr, 0);
981     ASSERT_NE(ret, HDF_SUCCESS);
982 }
983 /**
984 * @tc.name HdfCodecHdiUseEglImageUnsupportedTest_001
985 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0480
986 * @tc.desc Invoke the UseEglImage interface to use the EGL image
987 */
988 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0480, Function | MediumTest | Level3)
989 {
990     ASSERT_TRUE(g_component != nullptr);
991     struct OmxCodecBuffer buffer;
992     buffer.fenceFd = -1;
993     buffer.version = g_version;
994     buffer.bufferType = CODEC_BUFFER_TYPE_AVSHARE_MEM_FD;
995     buffer.allocLen = BUFFER_SIZE;
996     buffer.buffer = 0;
997     buffer.bufferLen = 0;
998     buffer.pts = 0;
999     buffer.flag = 0;
1000     buffer.type = READ_ONLY_TYPE;
1001     auto eglImage = std::make_unique<int8_t[]>(BUFFER_SIZE);
1002     ASSERT_TRUE(eglImage != nullptr);
1003     int32_t ret = g_component->UseEglImage(g_component, &buffer, (uint32_t)PortIndex::PORT_INDEX_INPUT, eglImage.get(),
1004                                            BUFFER_SIZE);
1005     ASSERT_NE(ret, HDF_SUCCESS);
1006     eglImage = nullptr;
1007 }
1008 /**
1009 * @tc.name HdfCodecHdiWaitStateIdleTest_001
1010 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0490
1011 * @tc.desc The status of the listening component changes to OMX_StateIdle
1012 */
1013 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0490, Function | MediumTest | Level3)
1014 {
1015     ASSERT_TRUE(g_component != nullptr);
1016     // wait for Idle status
1017     OMX_STATETYPE state = OMX_StateInvalid;
1018     do {
1019         usleep(100);
1020         auto ret = g_component->GetState(g_component, &state);
1021         ASSERT_EQ(ret, HDF_SUCCESS);
1022     } while (state != OMX_StateIdle);
1023 }
1024 /**
1025 * @tc.name HdfCodecHdiFillThisBufferSuccessTest_001
1026 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0500
1027 * @tc.desc Invoke the FillThisBuffer interface to execute the codec output to fill the buffer
1028 */
1029 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0500, Function | MediumTest | Level3)
1030 {
1031     ASSERT_TRUE(g_component != nullptr);
1032     auto iter = outputBuffers.begin();
1033     if (iter != outputBuffers.end()) {
1034         int32_t ret = g_component->FillThisBuffer(g_component, iter->second->omxBuffer.get());
1035         ASSERT_EQ(ret, HDF_SUCCESS);
1036     }
1037 }
1038 /**
1039 * @tc.name HdfCodecHdiFillThisBufferUseErrorBufferIdTest_002
1040 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0510
1041 * @tc.desc Invoke the FillThisBuffer interface when bufferID is set to BUFFER_ID_ERROR
1042 */
1043 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0510, Function | MediumTest | Level3)
1044 {
1045     ASSERT_TRUE(g_component != nullptr);
1046     auto iter = outputBuffers.begin();
1047     if (iter != outputBuffers.end()) {
1048         auto omxBuffer = iter->second->omxBuffer;
1049         auto tempId = omxBuffer->bufferId;
1050         omxBuffer->bufferId = BUFFER_ID_ERROR;
1051         int32_t ret = g_component->FillThisBuffer(g_component, omxBuffer.get());
1052         ASSERT_NE(ret, HDF_SUCCESS);
1053         omxBuffer->bufferId = tempId;
1054     }
1055 }
1056 /**
1057 * @tc.name HdfCodecHdiEmptyThisBufferSuccessTest_001
1058 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0520
1059 * @tc.desc The EmptyThisBuffer interface is invoked to execute the codec output to fill the buffer
1060 */
1061 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0520, Function | MediumTest | Level3)
1062 {
1063     ASSERT_TRUE(g_component != nullptr);
1064     auto iter = inputBuffers.begin();
1065     if (iter != inputBuffers.end()) {
1066         int32_t ret = g_component->EmptyThisBuffer(g_component, iter->second->omxBuffer.get());
1067         ASSERT_EQ(ret, HDF_SUCCESS);
1068     }
1069 }
1070 /**
1071 * @tc.name HdfCodecHdiEmptyThisBufferUseErrorBufferIdTest_002
1072 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0530
1073 * @tc.desc Invoke the EmptyThisBuffer interface when bufferID is set to BUFFER_ID_ERROR
1074 */
1075 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0530, Function | MediumTest | Level3)
1076 {
1077     ASSERT_TRUE(g_component != nullptr);
1078     auto iter = inputBuffers.begin();
1079     if (iter != inputBuffers.end()) {
1080         auto omxBuffer = iter->second->omxBuffer;
1081         auto tempId = omxBuffer->bufferId;
1082         omxBuffer->bufferId = BUFFER_ID_ERROR;
1083         int32_t ret = g_component->EmptyThisBuffer(g_component, iter->second->omxBuffer.get());
1084         ASSERT_NE(ret, HDF_SUCCESS);
1085         omxBuffer->bufferId = tempId;
1086     }
1087 }
1088 /**
1089 * @tc.name HdfCodecHdiSetCallbackSuccessTest_001
1090 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0540
1091 * @tc.desc The SetCallback interface is invoked to set the callback
1092 */
1093 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0540, Function | MediumTest | Level3)
1094 {
1095     ASSERT_TRUE(g_component != nullptr);
1096     if (g_callback != nullptr) {
1097         CodecCallbackTypeRelease(g_callback);
1098     }
1099     g_callback = CodecCallbackTypeGet(nullptr);
1100     ASSERT_TRUE(g_callback != nullptr);
1101     int32_t ret = g_component->SetCallbacks(g_component, g_callback, APP_DATA);
1102     ASSERT_EQ(ret, HDF_SUCCESS);
1103 }
1104 /**
1105 * @tc.name HdfCodecHdiSetCallbackAppDataLenMaxTest_002
1106 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0550
1107 * @tc.desc When AppData is set to the maximum value in the value range,
1108            the SetCallback interface is invoked to set the callback
1109 */
1110 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0550, Function | MediumTest | Level3)
1111 {
1112     ASSERT_TRUE(g_component != nullptr);
1113     if (g_callback != nullptr) {
1114         CodecCallbackTypeRelease(g_callback);
1115     }
1116     g_callback = CodecCallbackTypeGet(nullptr);
1117     ASSERT_TRUE(g_callback != nullptr);    ASSERT_TRUE(g_callback != nullptr);
1118     int32_t ret = g_component->SetCallbacks(g_component, g_callback, APP_DATA_MAX);
1119     ASSERT_EQ(ret, HDF_SUCCESS);
1120 }
1121 /**
1122 * @tc.name HdfCodecHdiSetCallbackAppDataLenMinTest_003
1123 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0560
1124 * @tc.desc When AppData is set to the minimum value in the value range,
1125       the SetCallback interface is invoked to set the callback
1126 */
1127 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0560, Function | MediumTest | Level3)
1128 {
1129     ASSERT_TRUE(g_component != nullptr);
1130     if (g_callback != nullptr) {
1131         CodecCallbackTypeRelease(g_callback);
1132     }
1133     g_callback = CodecCallbackTypeGet(nullptr);
1134     ASSERT_TRUE(g_callback != nullptr);
1135     int32_t ret = g_component->SetCallbacks(g_component, g_callback, APP_DATA_MIN);
1136     ASSERT_EQ(ret, HDF_SUCCESS);
1137 }
1138 /**
1139 * @tc.name HdfCodecHdiRoleEnumUnsupportedTest_001
1140 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0570
1141 * @tc.desc Invoke the ComponentRoleEnum interface to obtain component tasks
1142 */
1143 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0570, Function | MediumTest | Level3)
1144 {
1145     ASSERT_TRUE(g_component != nullptr);
1146     uint8_t role[ROLE_LEN] = {0};
1147     int32_t ret = g_component->ComponentRoleEnum(g_component, role, ROLE_LEN, 0);
1148     ASSERT_NE(ret, HDF_SUCCESS);
1149 }
1150 /**
1151 * @tc.name HdfCodecHdiFreeBufferPortIndexOutputUnsupportedTest_001
1152 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0580
1153 * @tc.desc Set portIndex to PORT_INDEX_OUTPUT and invoke the FreeBuffer interface to obtain component tasks
1154 */
1155 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0580, Function | MediumTest | Level3)
1156 {
1157     ASSERT_TRUE(g_component != nullptr);
1158     auto iter = outputBuffers.begin();
1159     while (iter != outputBuffers.end()) {
1160         int32_t ret =
1161             g_component->FreeBuffer(g_component, (uint32_t)PortIndex::PORT_INDEX_OUTPUT, iter->second->omxBuffer.get());
1162         ASSERT_NE(ret, HDF_SUCCESS);
1163         iter = outputBuffers.erase(iter);
1164     }
1165 }
1166 /**
1167 * @tc.name HdfCodecHdiFreeBufferPortIndexInputUnsupportedTest_002
1168 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0590
1169 * @tc.desc Set portIndex to PORT_INDEX_INPUT and invoke the FreeBuffer interface to obtain component tasks
1170 */
1171 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0590, Function | MediumTest | Level3)
1172 {
1173     ASSERT_TRUE(g_component != nullptr);
1174     auto iter = inputBuffers.begin();
1175     while (iter != inputBuffers.end()) {
1176         int32_t ret =
1177             g_component->FreeBuffer(g_component, (uint32_t)PortIndex::PORT_INDEX_INPUT, iter->second->omxBuffer.get());
1178         ASSERT_NE(ret, HDF_SUCCESS);
1179         iter = inputBuffers.erase(iter);
1180     }
1181 }
1182 /**
1183 * @tc.name HdfCodecHdiSetStateIdleToLoadedTest_001
1184 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0600
1185 * @tc.desc The status of the component that invokes the SendCommand
1186            interface changes from OMX_StateIdle to OMX_StateLoaded
1187 */
1188 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0600, Function | MediumTest | Level3)
1189 {
1190     ASSERT_TRUE(g_component != nullptr);
1191     int32_t ret = g_component->SendCommand(g_component, OMX_CommandStateSet, OMX_StateLoaded, nullptr, 0);
1192     ASSERT_EQ(ret, HDF_SUCCESS);
1193 
1194     OMX_STATETYPE state = OMX_StateInvalid;
1195     do {
1196         usleep(100);
1197         auto ret = g_component->GetState(g_component, &state);
1198         ASSERT_EQ(ret, HDF_SUCCESS);
1199     } while (state != OMX_StateLoaded);
1200 }
1201 /**
1202 * @tc.name HdfCodecHdiDeInitUnsupportedTest_001
1203 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0610
1204 * @tc.desc Invoke the ComponentDeInit interface to deinitialize the component
1205 */
1206 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0610, Function | MediumTest | Level3)
1207 {
1208     ASSERT_TRUE(g_component != nullptr);
1209     int32_t ret = g_component->ComponentDeInit(g_component);
1210     ASSERT_NE(ret, HDF_SUCCESS);
1211 }
1212 /**
1213 * @tc.name HdfCodecHdiDestoryComponentSuccessTest_001
1214 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0620
1215 * @tc.desc Invoke the DestoryComponent interface to destroy components
1216 */
1217 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0620, Function | MediumTest | Level3)
1218 {
1219     ASSERT_TRUE(g_component != nullptr);
1220     ASSERT_TRUE(g_manager != nullptr);
1221     int ret = g_manager->DestroyComponent(g_componentId);
1222     ASSERT_EQ(ret, HDF_SUCCESS);
1223 }
1224 /**
1225 * @tc.name HdfCodecHdiCallbackTypeReleaseAndManagerReleaseTest_001
1226 * @tc.number  SUB_DriverSystem_CodecHdi_adapter_0630
1227 * @tc.desc Destroy callback events and component management objects
1228 */
1229 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0630, Function | MediumTest | Level3)
1230 {
1231     ASSERT_TRUE(g_manager != nullptr);
1232     ASSERT_TRUE(g_callback != nullptr);
1233     CodecCallbackTypeRelease(g_callback);
1234     CodecComponentManagerRelease();
1235     g_callback = nullptr;
1236     g_manager = nullptr;
1237 }
1238 }  // namespace
1239