1 /*
2 * Copyright (c) 2022-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
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 FRAME_RATE = 24;
52 constexpr int32_t VIDEO_WIDHT = 640;
53 constexpr int32_t VIDEO_HEIGHT = 480;
54 constexpr int32_t BUFFER_SIZE = (640 * 480 * 3);
55 constexpr int32_t ROLE_LEN = 240;
56 constexpr int32_t FRAMERATE = (30 << 16);
57 constexpr uint32_t BUFFER_ID_ERROR = 65000;
58 constexpr int64_t APP_DATA = 64;
59 constexpr int64_t APP_DATA_MAX = 9223372036854775807;
60 constexpr int64_t APP_DATA_MIN = -9223372036854775807;
61 enum class PortIndex { PORT_INDEX_INPUT = 0, PORT_INDEX_OUTPUT = 1, PORT_INDEX_ERROR_INPUT = 2 };
62
63 template <typename T>
InitParam(T & param)64 void InitParam(T ¶m)
65 {
66 memset_s(¶m, sizeof(param), 0x0, sizeof(param));
67 param.nSize = sizeof(param);
68 param.nVersion = g_version;
69 }
70
71 struct BufferInfo {
72 std::shared_ptr<OmxCodecBuffer> omxBuffer;
73 std::shared_ptr<OHOS::Ashmem> sharedMem;
BufferInfo__anon5a16b8380111::BufferInfo74 BufferInfo()
75 {
76 omxBuffer = nullptr;
77 sharedMem = nullptr;
78 }
~BufferInfo__anon5a16b8380111::BufferInfo79 ~BufferInfo()
80 {
81 omxBuffer = nullptr;
82 if (sharedMem != nullptr) {
83 sharedMem->UnmapAshmem();
84 sharedMem->CloseAshmem();
85 sharedMem = nullptr;
86 }
87 }
88 };
89 std::map<int32_t, std::shared_ptr<BufferInfo>> inputBuffers;
90 std::map<int32_t, std::shared_ptr<BufferInfo>> outputBuffers;
InitCodecBufferWithAshMem(enum PortIndex portIndex,int bufferSize,shared_ptr<OmxCodecBuffer> omxBuffer,shared_ptr<OHOS::Ashmem> sharedMem)91 static void InitCodecBufferWithAshMem(enum PortIndex portIndex, int bufferSize, shared_ptr<OmxCodecBuffer> omxBuffer,
92 shared_ptr<OHOS::Ashmem> sharedMem)
93 {
94 omxBuffer->size = sizeof(OmxCodecBuffer);
95 omxBuffer->version = g_version;
96 omxBuffer->bufferType = CODEC_BUFFER_TYPE_AVSHARE_MEM_FD;
97 omxBuffer->bufferLen = sizeof(int);
98 omxBuffer->buffer = (uint8_t *)(uintptr_t)sharedMem->GetAshmemFd();
99 omxBuffer->allocLen = bufferSize;
100 omxBuffer->fenceFd = -1;
101 omxBuffer->pts = 0;
102 omxBuffer->flag = 0;
103 if (portIndex == PortIndex::PORT_INDEX_INPUT) {
104 omxBuffer->type = READ_ONLY_TYPE;
105 sharedMem->MapReadAndWriteAshmem();
106 } else {
107 omxBuffer->type = READ_WRITE_TYPE;
108 sharedMem->MapReadOnlyAshmem();
109 }
110 }
111
UseBufferOnPort(enum PortIndex portIndex,int bufferCount,int bufferSize)112 static bool UseBufferOnPort(enum PortIndex portIndex, int bufferCount, int bufferSize)
113 {
114 for (int i = 0; i < bufferCount; i++) {
115 std::shared_ptr<OmxCodecBuffer> omxBuffer = std::make_shared<OmxCodecBuffer>();
116 if (omxBuffer == nullptr) {
117 HDF_LOGE("%{public}s omxBuffer is null", __func__);
118 return false;
119 }
120
121 int fd = OHOS::AshmemCreate(0, bufferSize);
122 shared_ptr<OHOS::Ashmem> sharedMem = make_shared<OHOS::Ashmem>(fd, bufferSize);
123 if (sharedMem == nullptr) {
124 HDF_LOGE("%{public}s sharedMem is null", __func__);
125 if (fd >= 0) {
126 close(fd);
127 fd = -1;
128 }
129 return false;
130 }
131 InitCodecBufferWithAshMem(portIndex, bufferSize, omxBuffer, sharedMem);
132 auto err = g_component->UseBuffer(g_component, (uint32_t)portIndex, omxBuffer.get());
133 if (err != HDF_SUCCESS) {
134 HDF_LOGE("%{public}s failed to UseBuffer with portIndex[%{public}d]", __func__, portIndex);
135 sharedMem->UnmapAshmem();
136 sharedMem->CloseAshmem();
137 sharedMem = nullptr;
138 omxBuffer = nullptr;
139 return false;
140 }
141 omxBuffer->bufferLen = 0;
142 HDF_LOGI("UseBuffer returned bufferID [%{public}d]", omxBuffer->bufferId);
143 std::shared_ptr<BufferInfo> bufferInfo = std::make_shared<BufferInfo>();
144 bufferInfo->omxBuffer = omxBuffer;
145 bufferInfo->sharedMem = sharedMem;
146 if (portIndex == PortIndex::PORT_INDEX_INPUT) {
147 inputBuffers.emplace(std::make_pair(omxBuffer->bufferId, bufferInfo));
148 } else {
149 outputBuffers.emplace(std::make_pair(omxBuffer->bufferId, bufferInfo));
150 }
151 }
152 return true;
153 }
154
155 class CodecHdiAdapterTest : public testing::Test {
156 public:
SetUpTestCase()157 static void SetUpTestCase()
158 {}
TearDownTestCase()159 static void TearDownTestCase()
160 {}
SetUp()161 void SetUp()
162 {}
TearDown()163 void TearDown()
164 {}
165 };
166
167 static char g_arrayStr[ARRAY_TO_STR_LEN];
GetArrayStr(int32_t * array,int32_t arrayLen,int32_t endValue)168 static char *GetArrayStr(int32_t *array, int32_t arrayLen, int32_t endValue)
169 {
170 int32_t len = 0;
171 int32_t totalLen = 0;
172 int32_t ret;
173 char value[INT_TO_STR_LEN];
174 ret = memset_s(g_arrayStr, sizeof(g_arrayStr), 0, sizeof(g_arrayStr));
175 if (ret != EOK) {
176 HDF_LOGE("%{public}s: memset_s g_arrayStr failed, error code: %{public}d", __func__, ret);
177 return g_arrayStr;
178 }
179 for (int32_t i = 0; i < arrayLen; i++) {
180 if (array[i] == endValue) {
181 break;
182 }
183 ret = memset_s(value, sizeof(value), 0, sizeof(value));
184 if (ret != EOK) {
185 HDF_LOGE("%{public}s: memset_s value failed, error code: %{public}d", __func__, ret);
186 return g_arrayStr;
187 }
188 ret = sprintf_s(value, sizeof(value), "0x0%X, ", array[i]);
189 if (ret < 0) {
190 HDF_LOGE("%{public}s: sprintf_s value failed, error code: %{public}d", __func__, ret);
191 return g_arrayStr;
192 }
193 len = strnlen(value, ARRAY_TO_STR_LEN);
194 ret = memcpy_s(g_arrayStr + totalLen, len, value, len);
195 if (ret != EOK) {
196 HDF_LOGE("%{public}s: memcpy_s g_arrayStr failed, error code: %{public}d", __func__, ret);
197 return g_arrayStr;
198 }
199 totalLen += len;
200 }
201 return g_arrayStr;
202 }
203
PrintCapability(CodecCompCapability * cap,int32_t index)204 static void PrintCapability(CodecCompCapability *cap, int32_t index)
205 {
206 HDF_LOGI("---------------------- component capability %{public}d ---------------------", index + 1);
207 HDF_LOGI("role:%{public}d", cap->role);
208 HDF_LOGI("type:%{public}d", cap->type);
209 HDF_LOGI("compName:%{public}s", cap->compName);
210 HDF_LOGI("supportProfiles:%{public}s", GetArrayStr(cap->supportProfiles, PROFILE_NUM, INVALID_PROFILE));
211 HDF_LOGI("maxInst:%{public}d", cap->maxInst);
212 HDF_LOGI("isSoftwareCodec:%{public}d", cap->isSoftwareCodec);
213 HDF_LOGI("processModeMask:0x0%{public}x", cap->processModeMask);
214 HDF_LOGI("capsMask:0x0%{public}x", cap->capsMask);
215 HDF_LOGI("bitRate.min:%{public}d", cap->bitRate.min);
216 HDF_LOGI("bitRate.max:%{public}d", cap->bitRate.max);
217 if (strstr(cap->compName, "video") != NULL) {
218 HDF_LOGI("minSize.width:%{public}d", cap->port.video.minSize.width);
219 HDF_LOGI("minSize.height:%{public}d", cap->port.video.minSize.height);
220 HDF_LOGI("maxSize.width:%{public}d", cap->port.video.maxSize.width);
221 HDF_LOGI("maxSize.height:%{public}d", cap->port.video.maxSize.height);
222 HDF_LOGI("widthAlignment:%{public}d", cap->port.video.whAlignment.widthAlignment);
223 HDF_LOGI("heightAlignment:%{public}d", cap->port.video.whAlignment.heightAlignment);
224 HDF_LOGI("blockCount.min:%{public}d", cap->port.video.blockCount.min);
225 HDF_LOGI("blockCount.max:%{public}d", cap->port.video.blockCount.max);
226 HDF_LOGI("blocksPerSecond.min:%{public}d", cap->port.video.blocksPerSecond.min);
227 HDF_LOGI("blocksPerSecond.max:%{public}d", cap->port.video.blocksPerSecond.max);
228 HDF_LOGI("blockSize.width:%{public}d", cap->port.video.blockSize.width);
229 HDF_LOGI("blockSize.height:%{public}d", cap->port.video.blockSize.height);
230 HDF_LOGI("supportPixFmts:%{public}s", GetArrayStr(cap->port.video.supportPixFmts, PIX_FORMAT_NUM, 0));
231 } else {
232 HDF_LOGI(":%{public}s", GetArrayStr(cap->port.audio.sampleFormats, SAMPLE_FMT_NUM, AUDIO_SAMPLE_FMT_INVALID));
233 HDF_LOGI(":%{public}s", GetArrayStr(cap->port.audio.sampleRate, SAMPLE_RATE_NUM, AUD_SAMPLE_RATE_INVALID));
234 HDF_LOGI(":%{public}s", GetArrayStr(cap->port.audio.channelLayouts, CHANNEL_NUM, -1));
235 HDF_LOGI(":%{public}s", GetArrayStr(cap->port.audio.channelCount, CHANNEL_NUM, -1));
236 }
237 HDF_LOGI("-------------------------------------------------------------------");
238 }
239 /**
240 * @tc.name HdfCodecHdiGetCodecComponentManagerTest_001
241 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0010
242 * @tc.desc Invoke the GetCodecComponentManager interface to obtain component management objects
243 */
244 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0010, Function | MediumTest | Level3)
245 {
246 g_manager = GetCodecComponentManager();
247 ASSERT_TRUE(g_manager != nullptr);
248 g_callback = CodecCallbackTypeGet(nullptr);
249 ASSERT_TRUE(g_callback != nullptr);
250 }
251 /**
252 * @tc.name HdfCodecHdiGetComponentNumTest_001
253 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0020
254 * @tc.desc Invoke the GetComponentNumber interface to obtain the number of components
255 */
256 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0020, Function | MediumTest | Level3)
257 {
258 ASSERT_TRUE(g_manager != nullptr);
259 g_count = g_manager->GetComponentNum();
260 ASSERT_GT(g_count, 0);
261 }
262 /**
263 * @tc.name HdfCodecHdiGetComponentCapabilityListTest_001
264 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0030
265 * @tc.desc Invoke the GetComponentCapabilityList interface to obtain the component capability set
266 */
267 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0030, Function | MediumTest | Level3)
268 {
269 ASSERT_GT(g_count, 0);
270 ASSERT_TRUE(g_manager != nullptr);
271 CodecCompCapability *capList = (CodecCompCapability *)OsalMemAlloc(sizeof(CodecCompCapability) * g_count);
272 ASSERT_TRUE(capList != nullptr);
273 g_manager->GetComponentCapabilityList(capList, g_count);
274 for (int32_t i = 0; i < g_count; i++) {
275 PrintCapability(&capList[i], i);
276 }
277 OsalMemFree(capList);
278 capList = nullptr;
279 }
280 /**
281 * @tc.name HdfCodecHdiCreateComponentCompNameErrorTest_001
282 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0040
283 * @tc.desc If compName is a component name that does not exist, the CreateComponent
284 interface is invoked to create a component
285 */
286 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0040, Function | MediumTest | Level3)
287 {
288 ASSERT_TRUE(g_manager != nullptr);
289 ASSERT_TRUE(g_callback != nullptr);
290 char name[] = "test";
291 int32_t ret = g_manager->CreateComponent(&g_component, &g_componentId, (char *)name, APP_DATA, g_callback);
292 ASSERT_NE(ret, HDF_SUCCESS);
293 ASSERT_TRUE(g_component == nullptr);
294 }
295 /**
296 * @tc.name HdfCodecHdiCreateComponentCompNameNullptrTest_002
297 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0050
298 * @tc.desc When compName is set to Nullptr, the CreateComponent interface is invoked to create a component
299 */
300 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0050, Function | MediumTest | Level3)
301 {
302 ASSERT_TRUE(g_manager != nullptr);
303 ASSERT_TRUE(g_callback != nullptr);
304 int32_t ret = g_manager->CreateComponent(&g_component, &g_componentId, nullptr, APP_DATA, g_callback);
305 ASSERT_NE(ret, HDF_SUCCESS);
306 ASSERT_TRUE(g_component == nullptr);
307 }
308 /**
309 * @tc.name HdfCodecHdiCreateComponentAppdataMaxTest_003
310 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0060
311 * @tc.desc When Appdata is the maximum value in the value range, the CreateComponent
312 interface is invoked to create a component
313 */
314 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0060, Function | MediumTest | Level3)
315 {
316 ASSERT_TRUE(g_manager != nullptr);
317 struct CodecCallbackType *callback = CodecCallbackTypeGet(nullptr);
318 ASSERT_TRUE(callback != nullptr);
319 struct CodecComponentType *component = nullptr;
320 uint32_t componentId = 0;
321 int32_t ret = g_manager->CreateComponent(&component, &componentId, const_cast<char *>(DECODER_AVC),
322 APP_DATA_MAX, callback);
323 ASSERT_EQ(ret, HDF_SUCCESS);
324 ASSERT_TRUE(component != nullptr);
325 ret = g_manager->DestroyComponent(componentId);
326 ASSERT_EQ(ret, HDF_SUCCESS);
327 CodecCallbackTypeRelease(callback);
328 callback = nullptr;
329 }
330 /**
331 * @tc.name HdfCodecHdiCreateComponentAppdataMinTest_004
332 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0070
333 * @tc.desc When Appdata is the minimum value in the value range, the CreateComponent
334 interface is invoked to create a componentt
335 */
336 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0070, Function | MediumTest | Level3)
337 {
338 ASSERT_TRUE(g_manager != nullptr);
339 struct CodecCallbackType *callback = CodecCallbackTypeGet(nullptr);
340 ASSERT_TRUE(callback != nullptr);
341 struct CodecComponentType *component = nullptr;
342 uint32_t componentId = 0;
343 int32_t ret = g_manager->CreateComponent(&component, &componentId, const_cast<char *>(DECODER_AVC),
344 APP_DATA_MIN, callback);
345 ASSERT_EQ(ret, HDF_SUCCESS);
346 ASSERT_TRUE(component != nullptr);
347 ret = g_manager->DestroyComponent(componentId);
348 ASSERT_EQ(ret, HDF_SUCCESS);
349 CodecCallbackTypeRelease(callback);
350 callback = nullptr;
351 }
352 /**
353 * @tc.name HdfCodecHdiCreateComponentCallbackIsNullptrTest_005
354 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0080
355 * @tc.desc When callback is nullptr, the CreateComponent interface is invoked to create a component
356 */
357 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0080, Function | MediumTest | Level3)
358 {
359 ASSERT_TRUE(g_manager != nullptr);
360 struct CodecCallbackType *callback = nullptr;
361 struct CodecComponentType *component = nullptr;
362 uint32_t componentId = 0;
363 int32_t ret = g_manager->CreateComponent(&component, &componentId, const_cast<char *>(DECODER_AVC),
364 APP_DATA, callback);
365 ASSERT_NE(ret, HDF_SUCCESS);
366 }
367 /**
368 * @tc.name HdfCodecHdiCreateComponentSuccessTest_006
369 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0090
370 * @tc.desc Invoke the CreateComponent interface to create a video encoding component
371 */
372 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0090, Function | MediumTest | Level3)
373 {
374 ASSERT_TRUE(g_manager != nullptr);
375 ASSERT_TRUE(g_callback != nullptr);
376 int32_t ret = g_manager->CreateComponent(&g_component, &g_componentId, const_cast<char *>(ENCODER_AVC), APP_DATA,
377 g_callback);
378 ASSERT_EQ(ret, HDF_SUCCESS);
379 ASSERT_TRUE(g_component != nullptr);
380 }
381 // Test GetComponentVersion Adapter not support
382 /**
383 * @tc.name HdfCodecHdiGetComponentVersionUnsupportedTest_001
384 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0100
385 * @tc.desc Invoke the GetComponentVersion interface to obtain the component version
386 */
387 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0100, Function | MediumTest | Level3)
388 {
389 ASSERT_TRUE(g_component != nullptr);
390 struct CompVerInfo verInfo;
391 int32_t ret = g_component->GetComponentVersion(g_component, &verInfo);
392 g_version = verInfo.compVersion;
393 ASSERT_NE(ret, HDF_SUCCESS);
394 }
395 // Test GetParameter
396 /**
397 * @tc.name HdfCodecHdiGetParameterParamStructNullptrTest_001
398 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0110
399 * @tc.desc When paramStrut is set to nullptr, the GetParameter interface is invoked to obtain component parameters
400 */
401 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0110, Function | MediumTest | Level3)
402 {
403 ASSERT_TRUE(g_component != nullptr);
404 auto ret = g_component->GetParameter(g_component, OMX_IndexParamVideoPortFormat, nullptr, 0);
405 ASSERT_NE(ret, HDF_SUCCESS);
406 }
407 /**
408 * @tc.name HdfCodecHdiGetParameterSuccessTest_002
409 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0120
410 * @tc.desc The GetParameter interface is invoked to obtain component parameters
411 */
412 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0120, Function | MediumTest | Level3)
413 {
414 ASSERT_TRUE(g_component != nullptr);
415 OMX_VIDEO_PARAM_PORTFORMATTYPE param;
416 InitParam(param);
417 param.nPortIndex = (uint32_t)PortIndex::PORT_INDEX_INPUT;
418 param.eCompressionFormat = OMX_VIDEO_CodingAVC;
419 auto ret = g_component->GetParameter(g_component, OMX_IndexParamVideoPortFormat, reinterpret_cast<int8_t *>(¶m),
420 sizeof(param));
421 ASSERT_EQ(ret, HDF_SUCCESS);
422 }
423 /**
424 * @tc.name HdfCodecHdiGetParameterSuccessTest_002
425 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0130
426 * @tc.desc Invoke the GetParameter interface to obtain component parameters when paramIndex does not match
427 */
428 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0130, Function | MediumTest | Level3)
429 {
430 ASSERT_TRUE(g_component != nullptr);
431 OMX_VIDEO_CONFIG_BITRATETYPE param;
432 InitParam(param);
433 param.nPortIndex = (uint32_t)PortIndex::PORT_INDEX_INPUT;
434 auto ret = g_component->GetParameter(g_component, OMX_IndexParamVideoPortFormat, reinterpret_cast<int8_t *>(¶m),
435 sizeof(param));
436 ASSERT_NE(ret, HDF_SUCCESS);
437 }
438 /**
439 * @tc.name HdfCodecHdiGetParameterParamIndexUnusedTest_004
440 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0140
441 * @tc.desc When paramIndex is set to, invoke the GetParameter interface to obtain component parameters
442 */
443 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0140, Function | MediumTest | Level3)
444 {
445 ASSERT_TRUE(g_component != nullptr);
446 OMX_VIDEO_CONFIG_BITRATETYPE param;
447 InitParam(param);
448 param.nPortIndex = (uint32_t)PortIndex::PORT_INDEX_INPUT;
449 auto ret = g_component->GetParameter(g_component, OMX_IndexVideoStartUnused, reinterpret_cast<int8_t *>(¶m),
450 sizeof(param));
451 ASSERT_NE(ret, HDF_SUCCESS);
452 }
453 /**
454 * @tc.name HdfCodecHdiSetPortDefineSuccessTest_001
455 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0150
456 * @tc.desc Invoke the GetParameter interface to obtain component parameters,
457 * then invoke SetParameter interface to set back the modified component parameters
458 */
459 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiSetPortDefineSuccessTest_0150, TestSize.Level1)
460 {
461 ASSERT_TRUE(g_component != nullptr);
462 OMX_PARAM_PORTDEFINITIONTYPE param;
463 InitParam(param);
464 param.nPortIndex = (uint32_t)PortIndex::PORT_INDEX_INPUT;
465 int32_t ret = g_component->GetParameter(g_component, OMX_IndexParamPortDefinition,
466 reinterpret_cast<int8_t *>(¶m), sizeof(param));
467 ASSERT_EQ(ret, HDF_SUCCESS);
468
469 param.format.video.nFrameWidth = VIDEO_WIDHT;
470 param.format.video.nFrameHeight = VIDEO_HEIGHT;
471 ret = g_component->SetParameter(g_component, OMX_IndexParamPortDefinition,
472 reinterpret_cast<int8_t *>(¶m), sizeof(param));
473 ASSERT_EQ(ret, HDF_SUCCESS);
474 }
475 /**
476 * @tc.name HdfCodecHdiSetParameterSuccessTest_001
477 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0151
478 * @tc.desc The SetParameter interface is invoked to set component parameters
479 */
480 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0151, Function | MediumTest | Level3)
481 {
482 ASSERT_TRUE(g_component != nullptr);
483 OMX_VIDEO_PARAM_PORTFORMATTYPE param;
484 InitParam(param);
485 param.xFramerate = FRAME_RATE;
486 param.nPortIndex = (uint32_t)PortIndex::PORT_INDEX_INPUT;
487 int32_t ret = g_component->SetParameter(g_component, OMX_IndexParamVideoPortFormat,
488 reinterpret_cast<int8_t *>(¶m), sizeof(param));
489 ASSERT_EQ(ret, HDF_SUCCESS);
490 }
491 /**
492 * @tc.name HdfCodecHdiSetParameterParamStructNullptrTest_002
493 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0160
494 * @tc.desc When paramStrut is set to nullptr, the SetParameter interface is invoked to set component parameters
495 */
496 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0160, Function | MediumTest | Level3)
497 {
498 ASSERT_TRUE(g_component != nullptr);
499 int32_t ret = g_component->SetParameter(g_component, OMX_IndexParamVideoPortFormat, nullptr, 0);
500 ASSERT_NE(ret, HDF_SUCCESS);
501 }
502 /**
503 * @tc.name HdfCodecHdiSetParameterParamIndexNotMatchParamStructTest_003
504 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0170
505 * @tc.desc When paramIndex does not match paramStruct, the SetParameter
506 interface is invoked to set component parameters
507 */
508 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0170, Function | MediumTest | Level3)
509 {
510 ASSERT_TRUE(g_component != nullptr);
511 OMX_VIDEO_CONFIG_BITRATETYPE param;
512 InitParam(param);
513 param.nPortIndex = (uint32_t)PortIndex::PORT_INDEX_INPUT;
514 int32_t ret = g_component->SetParameter(g_component, OMX_IndexParamVideoPortFormat,
515 reinterpret_cast<int8_t *>(¶m), sizeof(param));
516 ASSERT_NE(ret, HDF_SUCCESS);
517 }
518 /**
519 * @tc.name HdfCodecHdiSetParameterParamIndexUnusedTest_004
520 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0180
521 * @tc.desc When paramIndex is set to OMX_IndexVideoStartUnused, the SetParameter
522 interface is invoked to set component parameters
523 */
524 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0180, Function | MediumTest | Level3)
525 {
526 ASSERT_TRUE(g_component != nullptr);
527 OMX_VIDEO_PARAM_PORTFORMATTYPE param;
528 InitParam(param);
529 param.nPortIndex = (uint32_t)PortIndex::PORT_INDEX_INPUT;
530 int32_t ret = g_component->SetParameter(g_component, OMX_IndexVideoStartUnused, reinterpret_cast<int8_t *>(¶m),
531 sizeof(param));
532 ASSERT_NE(ret, HDF_SUCCESS);
533 }
534 /**
535 * @tc.name HdfCodecHdiSetParameterCodecComponentTypeNullptrTest_005
536 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0190
537 * @tc.desc When CodecComponentType is set to nullptr, the SetParameter interface is invoked to set component parameters
538 */
539 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0190, Function | MediumTest | Level3)
540 {
541 ASSERT_TRUE(g_component != nullptr);
542 OMX_VIDEO_PARAM_PORTFORMATTYPE param;
543 InitParam(param);
544 param.nPortIndex = (uint32_t)PortIndex::PORT_INDEX_INPUT;
545 int32_t ret = g_component->SetParameter(nullptr, OMX_IndexParamVideoPortFormat, reinterpret_cast<int8_t *>(¶m),
546 sizeof(param));
547 ASSERT_NE(ret, HDF_SUCCESS);
548 }
549 /**
550 * @tc.name HdfCodecHdiSetParameterParamStructLenNotMatchTest_006
551 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0200
552 * @tc.desc Invoke the SetParameter interface to set component parameters when paramStructLen does not match
553 */
554 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0200, Function | MediumTest | Level3)
555 {
556 ASSERT_TRUE(g_component != nullptr);
557 OMX_VIDEO_PARAM_PORTFORMATTYPE param;
558 InitParam(param);
559 param.nPortIndex = (uint32_t)PortIndex::PORT_INDEX_INPUT;
560 int32_t ret = g_component->SetParameter(g_component, OMX_IndexParamVideoPortFormat,
561 reinterpret_cast<int8_t *>(¶m), 0);
562 ASSERT_NE(ret, HDF_SUCCESS);
563 }
564 /**
565 * @tc.name HdfCodecHdiGetConfigUnsupportedTest_001
566 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0210
567 * @tc.desc Invoke the GetConfig interface to obtain component configurations
568 */
569 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0210, Function | MediumTest | Level3)
570 {
571 ASSERT_TRUE(g_component != nullptr);
572 OMX_VIDEO_CONFIG_BITRATETYPE param;
573 InitParam(param);
574 param.nPortIndex = (uint32_t)PortIndex::PORT_INDEX_OUTPUT;
575 int32_t ret = g_component->GetConfig(g_component, OMX_IndexConfigVideoBitrate, reinterpret_cast<int8_t *>(¶m),
576 sizeof(param));
577 ASSERT_NE(ret, HDF_SUCCESS);
578 }
579 /**
580 * @tc.name HdfCodecHdiSetConfigUnsupportedTest_001
581 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0220
582 * @tc.desc Invoke the SetConfig interface to set component configurations
583 */
584 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0220, Function | MediumTest | Level3)
585 {
586 ASSERT_TRUE(g_component != nullptr);
587 OMX_VIDEO_CONFIG_BITRATETYPE param;
588 InitParam(param);
589 param.nPortIndex = (uint32_t)PortIndex::PORT_INDEX_OUTPUT;
590 param.nEncodeBitrate = FRAMERATE;
591 int32_t ret = g_component->SetConfig(g_component, OMX_IndexConfigVideoBitrate, reinterpret_cast<int8_t *>(¶m),
592 sizeof(param));
593 ASSERT_NE(ret, HDF_SUCCESS);
594 }
595 /**
596 * @tc.name HdfCodecHdiGetExtensionIndexUnsupportedTest_001
597 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0230
598 * @tc.desc Invoke the GetExtensionIndex interface to obtain the component extended index
599 */
600 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0230, Function | MediumTest | Level3)
601 {
602 ASSERT_TRUE(g_component != nullptr);
603 OMX_INDEXTYPE indexType;
604 int32_t ret =
605 g_component->GetExtensionIndex(g_component, "OMX.Topaz.index.param.extended_video", (uint32_t *)&indexType);
606 ASSERT_NE(ret, HDF_SUCCESS);
607 }
608 /**
609 * @tc.name HdfCodecHdiGetStateSuccessTest_001
610 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0240
611 * @tc.desc When state is set to OMX_StateLoaded, the GetState interface is invoked to obtain the component status
612 */
613 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0240, Function | MediumTest | Level3)
614 {
615 ASSERT_TRUE(g_component != nullptr);
616 OMX_STATETYPE state;
617 int32_t ret = g_component->GetState(g_component, &state);
618 ASSERT_EQ(state, OMX_StateLoaded);
619 ASSERT_EQ(ret, HDF_SUCCESS);
620 }
621 /**
622 * @tc.name HdfCodecHdiGetStateSuccessTest_002
623 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0241
624 * @tc.desc When state is set to OMX_StateInvalid, the GetState interface is invoked to obtain the component status
625 */
626 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0241, Function | MediumTest | Level3)
627 {
628 ASSERT_TRUE(g_component != nullptr);
629 OMX_STATETYPE state;
630 int32_t ret = g_component->GetState(g_component, &state);
631 ASSERT_NE(state, OMX_StateInvalid);
632 ASSERT_EQ(ret, HDF_SUCCESS);
633 }
634 /**
635 * @tc.name HdfCodecHdiGetStateSuccessTest_003
636 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0242
637 * @tc.desc When state is set to OMX_StateExecuting, the GetState interface is invoked to obtain the component status
638 */
639 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0242, Function | MediumTest | Level3)
640 {
641 ASSERT_TRUE(g_component != nullptr);
642 OMX_STATETYPE state;
643 int32_t ret = g_component->GetState(g_component, &state);
644 ASSERT_NE(state, OMX_StateExecuting);
645 ASSERT_EQ(ret, HDF_SUCCESS);
646 }
647 /**
648 * @tc.name HdfCodecHdiGetStateSuccessTest_004
649 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0243
650 * @tc.desc When state is set to OMX_StateIdle, the GetState interface is invoked to obtain the component status
651 */
652 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0243, Function | MediumTest | Level3)
653 {
654 ASSERT_TRUE(g_component != nullptr);
655 OMX_STATETYPE state;
656 int32_t ret = g_component->GetState(g_component, &state);
657 ASSERT_NE(state, OMX_StateIdle);
658 ASSERT_EQ(ret, HDF_SUCCESS);
659 }
660 /**
661 * @tc.name HdfCodecHdiGetStateSuccessTest_005
662 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0244
663 * @tc.desc When state is set to OMX_StatePause, the GetState interface is invoked to obtain the component status
664 */
665 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0244, Function | MediumTest | Level3)
666 {
667 ASSERT_TRUE(g_component != nullptr);
668 OMX_STATETYPE state;
669 int32_t ret = g_component->GetState(g_component, &state);
670 ASSERT_NE(state, OMX_StatePause);
671 ASSERT_EQ(ret, HDF_SUCCESS);
672 }
673 /**
674 * @tc.name HdfCodecHdiGetStateSuccessTest_006
675 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0245
676 * @tc.desc When state is set to OMX_StateWaitForResources, the GetState interface is invoked to obtain the component status
677 */
678 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0245, Function | MediumTest | Level3)
679 {
680 ASSERT_TRUE(g_component != nullptr);
681 OMX_STATETYPE state;
682 int32_t ret = g_component->GetState(g_component, &state);
683 ASSERT_NE(state, OMX_StateWaitForResources);
684 ASSERT_EQ(ret, HDF_SUCCESS);
685 }
686 /**
687 * @tc.name HdfCodecHdiGetStateSuccessTest_007
688 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0246
689 * @tc.desc When state is set to OMX_StateKhronosExtensions, the GetState interface is invoked to obtain the component status
690 */
691 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0246, Function | MediumTest | Level3)
692 {
693 ASSERT_TRUE(g_component != nullptr);
694 OMX_STATETYPE state;
695 int32_t ret = g_component->GetState(g_component, &state);
696 ASSERT_NE(state, OMX_StateKhronosExtensions);
697 ASSERT_EQ(ret, HDF_SUCCESS);
698 }
699 /**
700 * @tc.name HdfCodecHdiGetStateSuccessTest_008
701 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0247
702 * @tc.desc When state is set to OMX_StateVendorStartUnused, the GetState interface is invoked to obtain the component status
703 */
704 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0247, Function | MediumTest | Level3)
705 {
706 ASSERT_TRUE(g_component != nullptr);
707 OMX_STATETYPE state;
708 int32_t ret = g_component->GetState(g_component, &state);
709 ASSERT_NE(state, OMX_StateVendorStartUnused);
710 ASSERT_EQ(ret, HDF_SUCCESS);
711 }
712 /**
713 * @tc.name HdfCodecHdiGetStateSuccessTest_009
714 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0248
715 * @tc.desc When state is set to OMX_StateMax, the GetState interface is invoked to obtain the component status
716 */
717 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0248, Function | MediumTest | Level3)
718 {
719 ASSERT_TRUE(g_component != nullptr);
720 OMX_STATETYPE state;
721 int32_t ret = g_component->GetState(g_component, &state);
722 ASSERT_NE(state, OMX_StateMax);
723 ASSERT_EQ(ret, HDF_SUCCESS);
724 }
725 /**
726 * @tc.name HdfCodecHdiGetStateStateNullptrTest_002
727 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0250
728 * @tc.desc When state is set to nullptr, the GetState interface is invoked to obtain the component status
729 */
730 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0250, Function | MediumTest | Level3)
731 {
732 ASSERT_TRUE(g_component != nullptr);
733 int32_t ret = g_component->GetState(g_component, nullptr);
734 ASSERT_NE(ret, HDF_SUCCESS);
735 }
736 /**
737 * @tc.name HdfCodecHdiTunnelRequestUnsupportedTest_001
738 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0260
739 * @tc.desc Invoke the ComponentTunnelRequest interface to set component pipe communication
740 */
741 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0260, Function | MediumTest | Level3)
742 {
743 ASSERT_TRUE(g_component != nullptr);
744 const int32_t tunneledComp = 1002;
745 const uint32_t tunneledPort = 101;
746 OMX_TUNNELSETUPTYPE tunnelSetup;
747 tunnelSetup.eSupplier = OMX_BufferSupplyInput;
748
749 int32_t ret = g_component->ComponentTunnelRequest(g_component, (uint32_t)PortIndex::PORT_INDEX_OUTPUT, tunneledComp,
750 tunneledPort, &tunnelSetup);
751 ASSERT_NE(ret, HDF_SUCCESS);
752 }
753
754 /**
755 * @tc.name HdfCodecHdiTunnelRequestUnsupportedTest_002
756 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0261
757 * @tc.desc Invoke the ComponentTunnelRequest interface to set component pipe communication
758 */
759 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0261, Function | MediumTest | Level3)
760 {
761 ASSERT_TRUE(g_component != nullptr);
762 const int32_t tunneledComp = 1002;
763 const uint32_t tunneledPort = 101;
764 OMX_TUNNELSETUPTYPE tunnelSetup;
765 tunnelSetup.eSupplier = OMX_BufferSupplyUnspecified;
766
767 int32_t ret = g_component->ComponentTunnelRequest(g_component, (uint32_t)PortIndex::PORT_INDEX_OUTPUT, tunneledComp,
768 tunneledPort, &tunnelSetup);
769 ASSERT_NE(ret, HDF_SUCCESS);
770 }
771
772 /**
773 * @tc.name HdfCodecHdiTunnelRequestUnsupportedTest_003
774 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0262
775 * @tc.desc Invoke the ComponentTunnelRequest interface to set component pipe communication
776 */
777 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0262, Function | MediumTest | Level3)
778 {
779 ASSERT_TRUE(g_component != nullptr);
780 const int32_t tunneledComp = 1002;
781 const uint32_t tunneledPort = 101;
782 OMX_TUNNELSETUPTYPE tunnelSetup;
783 tunnelSetup.eSupplier = OMX_BufferSupplyOutput;
784
785 int32_t ret = g_component->ComponentTunnelRequest(g_component, (uint32_t)PortIndex::PORT_INDEX_OUTPUT, tunneledComp,
786 tunneledPort, &tunnelSetup);
787 ASSERT_NE(ret, HDF_SUCCESS);
788 }
789
790 /**
791 * @tc.name HdfCodecHdiTunnelRequestUnsupportedTest_004
792 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0263
793 * @tc.desc Invoke the ComponentTunnelRequest interface to set component pipe communication
794 */
795 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0263, Function | MediumTest | Level3)
796 {
797 ASSERT_TRUE(g_component != nullptr);
798 const int32_t tunneledComp = 1002;
799 const uint32_t tunneledPort = 101;
800 OMX_TUNNELSETUPTYPE tunnelSetup;
801 tunnelSetup.eSupplier = OMX_BufferSupplyKhronosExtensions;
802
803 int32_t ret = g_component->ComponentTunnelRequest(g_component, (uint32_t)PortIndex::PORT_INDEX_OUTPUT, tunneledComp,
804 tunneledPort, &tunnelSetup);
805 ASSERT_NE(ret, HDF_SUCCESS);
806 }
807
808 /**
809 * @tc.name HdfCodecHdiTunnelRequestUnsupportedTest_005
810 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0264
811 * @tc.desc Invoke the ComponentTunnelRequest interface to set component pipe communication
812 */
813 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0264, Function | MediumTest | Level3)
814 {
815 ASSERT_TRUE(g_component != nullptr);
816 const int32_t tunneledComp = 1002;
817 const uint32_t tunneledPort = 101;
818 OMX_TUNNELSETUPTYPE tunnelSetup;
819 tunnelSetup.eSupplier = OMX_BufferSupplyVendorStartUnused;
820
821 int32_t ret = g_component->ComponentTunnelRequest(g_component, (uint32_t)PortIndex::PORT_INDEX_OUTPUT, tunneledComp,
822 tunneledPort, &tunnelSetup);
823 ASSERT_NE(ret, HDF_SUCCESS);
824 }
825
826 /**
827 * @tc.name HdfCodecHdiTunnelRequestUnsupportedTest_006
828 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0265
829 * @tc.desc Invoke the ComponentTunnelRequest interface to set component pipe communication
830 */
831 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0265, Function | MediumTest | Level3)
832 {
833 ASSERT_TRUE(g_component != nullptr);
834 const int32_t tunneledComp = 1002;
835 const uint32_t tunneledPort = 101;
836 OMX_TUNNELSETUPTYPE tunnelSetup;
837 tunnelSetup.eSupplier = OMX_BufferSupplyMax;
838
839 int32_t ret = g_component->ComponentTunnelRequest(g_component, (uint32_t)PortIndex::PORT_INDEX_OUTPUT, tunneledComp,
840 tunneledPort, &tunnelSetup);
841 ASSERT_NE(ret, HDF_SUCCESS);
842 }
843
844 /**
845 * @tc.name HdfCodecHdiAllocateBufferInvalidInputBufferTypeTest_001
846 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0270
847 * @tc.desc When bufferType is set to InvalidInput and portIndex is set to PORT_INDEX_INPUT, the AllocateBuffer
848 interface is invoked to set the external buffer
849 */
850 struct OmxCodecBuffer allocBuffer;
851 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0270, Function | MediumTest | Level3)
852 {
853 ASSERT_TRUE(g_component != nullptr);
854 allocBuffer.bufferType = CODEC_BUFFER_TYPE_INVALID;
855 allocBuffer.fenceFd = -1;
856 allocBuffer.version = g_version;
857 allocBuffer.allocLen = BUFFER_SIZE;
858 allocBuffer.buffer = 0;
859 allocBuffer.bufferLen = 0;
860 allocBuffer.pts = 0;
861 allocBuffer.flag = 0;
862 allocBuffer.type = READ_ONLY_TYPE;
863 int32_t ret = g_component->AllocateBuffer(g_component, (uint32_t)PortIndex::PORT_INDEX_INPUT, &allocBuffer);
864 ASSERT_NE(ret, HDF_SUCCESS);
865 }
866 /**
867 * @tc.name HdfCodecHdiAllocateBufferInputBufferNotInitTest_002
868 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0280
869 * @tc.desc When the buffer is not initialized and portIndex is set to PORT_INDEX_INPUT, the AllocateBuffer
870 interface is invoked to set the external buffer
871 */
872 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0280, Function | MediumTest | Level3)
873 {
874 ASSERT_TRUE(g_component != nullptr);
875 allocBuffer.bufferType = CODEC_BUFFER_TYPE_VIRTUAL_ADDR;
876 int32_t ret = g_component->AllocateBuffer(g_component, (uint32_t)PortIndex::PORT_INDEX_INPUT, &allocBuffer);
877 ASSERT_NE(ret, HDF_SUCCESS);
878 }
879 /**
880 * @tc.name HdfCodecHdiAllocateBufferInvalidOutputBufferTypeTest_003
881 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0290
882 * @tc.desc When bufferType is set to InvalidInput and portIndex is set to PORT_INDEX_OUTPUT, the AllocateBuffer
883 interface is invoked to set the external buffer
884 */
885 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0290, Function | MediumTest | Level3)
886 {
887 ASSERT_TRUE(g_component != nullptr);
888 allocBuffer.bufferType = CODEC_BUFFER_TYPE_INVALID;
889 int32_t ret = g_component->AllocateBuffer(g_component, (uint32_t)PortIndex::PORT_INDEX_OUTPUT, &allocBuffer);
890 ASSERT_NE(ret, HDF_SUCCESS);
891 }
892 /**
893 * @tc.name HdfCodecHdiAllocateBufferOutputBufferNotInitTest_004
894 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0300
895 * @tc.desc When the buffer is not initialized and portIndex is set to PORT_INDEX_OUTPUT, the AllocateBuffer
896 interface is invoked to set the external buffer
897 */
898 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0300, Function | MediumTest | Level3)
899 {
900 ASSERT_TRUE(g_component != nullptr);
901 allocBuffer.bufferType = CODEC_BUFFER_TYPE_VIRTUAL_ADDR;
902 int32_t ret = g_component->AllocateBuffer(g_component, (uint32_t)PortIndex::PORT_INDEX_OUTPUT, &allocBuffer);
903 ASSERT_NE(ret, HDF_SUCCESS);
904 }
905 /**
906 * @tc.name HdfCodecHdiAllocateBufferAvshareMemFdInputNotInitTest_005
907 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0310
908 * @tc.desc When the buffer is not initialized and portIndex is set to PORT_INDEX_OUTPUT, the AllocateBuffer
909 interface is invoked to set the external buffer
910 */
911 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0310, Function | MediumTest | Level3)
912 {
913 ASSERT_TRUE(g_component != nullptr);
914 allocBuffer.bufferType = CODEC_BUFFER_TYPE_AVSHARE_MEM_FD;
915 int32_t ret = g_component->AllocateBuffer(g_component, (uint32_t)PortIndex::PORT_INDEX_INPUT, &allocBuffer);
916 ASSERT_NE(ret, HDF_SUCCESS);
917 }
918 /**
919 * @tc.name HdfCodecHdiAllocateBufferAvshareMemFdOutputNotInitTest_006
920 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0320
921 * @tc.desc When the buffer is not initialized and portIndex is set to PORT_INDEX_OUTPUT, the AllocateBuffer
922 interface is invoked to set the external buffer
923 */
924 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0320, Function | MediumTest | Level3)
925 {
926 ASSERT_TRUE(g_component != nullptr);
927 allocBuffer.bufferType = CODEC_BUFFER_TYPE_AVSHARE_MEM_FD;
928 int32_t ret = g_component->AllocateBuffer(g_component, (uint32_t)PortIndex::PORT_INDEX_OUTPUT, &allocBuffer);
929 ASSERT_NE(ret, HDF_SUCCESS);
930 }
931 /**
932 * @tc.name HdfCodecHdiUseBufferInvalidInputBufferTypeTest_001
933 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0330
934 * @tc.desc When bufferType is set to InvalidInput and portIndex is set to PORT_INDEX_INPUT,
935 the UseBuffer interface is invoked to set the internal buffer
936 */
937 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0330, Function | MediumTest | Level3)
938 {
939 ASSERT_TRUE(g_component != nullptr);
940 std::shared_ptr<OmxCodecBuffer> omxBuffer = std::make_shared<OmxCodecBuffer>();
941 ASSERT_TRUE(omxBuffer != nullptr);
942 omxBuffer->size = sizeof(OmxCodecBuffer);
943 omxBuffer->version = g_version;
944 omxBuffer->bufferType = CODEC_BUFFER_TYPE_INVALID;
945 omxBuffer->bufferLen = 0;
946 omxBuffer->buffer = nullptr;
947 omxBuffer->allocLen = 0;
948 omxBuffer->fenceFd = -1;
949 omxBuffer->pts = 0;
950 omxBuffer->flag = 0;
951
952 auto err = g_component->UseBuffer(g_component, (uint32_t)PortIndex::PORT_INDEX_INPUT, omxBuffer.get());
953 ASSERT_NE(err, HDF_SUCCESS);
954 }
955 /**
956 * @tc.name HdfCodecHdiUseBufferInvalidOutputBufferTypeTest_002
957 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0340
958 * @tc.desc When bufferType is set to InvalidInput and portIndex is set to PORT_INDEX_OUTPUT,
959 the UseBuffer interface is called to set the internal buffer
960 */
961 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0340, Function | MediumTest | Level3)
962 {
963 ASSERT_TRUE(g_component != nullptr);
964 std::shared_ptr<OmxCodecBuffer> omxBuffer = std::make_shared<OmxCodecBuffer>();
965 ASSERT_TRUE(omxBuffer != nullptr);
966 omxBuffer->size = sizeof(OmxCodecBuffer);
967 omxBuffer->version = g_version;
968 omxBuffer->bufferType = CODEC_BUFFER_TYPE_INVALID;
969 omxBuffer->bufferLen = 0;
970 omxBuffer->buffer = nullptr;
971 omxBuffer->allocLen = 0;
972 omxBuffer->fenceFd = -1;
973 omxBuffer->pts = 0;
974 omxBuffer->flag = 0;
975
976 auto err = g_component->UseBuffer(g_component, (uint32_t)PortIndex::PORT_INDEX_OUTPUT, omxBuffer.get());
977 ASSERT_NE(err, HDF_SUCCESS);
978 }
979 /**
980 * @tc.name HdfCodecHdiUseBufferTestVirtualAddrInputTest_003
981 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0350
982 * @tc.desc When the buffer is not initialized and portIndex is set to PORT_INDEX_INPUT,
983 the UseBuffer interface is invoked to set the internal buffer
984 */
985 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0350, Function | MediumTest | Level3)
986 {
987 ASSERT_TRUE(g_component != nullptr);
988 std::shared_ptr<OmxCodecBuffer> omxBuffer = std::make_shared<OmxCodecBuffer>();
989 ASSERT_TRUE(omxBuffer != nullptr);
990 omxBuffer->size = sizeof(OmxCodecBuffer);
991 omxBuffer->version = g_version;
992 omxBuffer->bufferType = CODEC_BUFFER_TYPE_VIRTUAL_ADDR;
993 omxBuffer->bufferLen = 0;
994 omxBuffer->buffer = nullptr;
995 omxBuffer->allocLen = 0;
996 omxBuffer->fenceFd = -1;
997 omxBuffer->pts = 0;
998 omxBuffer->flag = 0;
999
1000 auto err = g_component->UseBuffer(g_component, (uint32_t)PortIndex::PORT_INDEX_INPUT, omxBuffer.get());
1001 ASSERT_NE(err, HDF_SUCCESS);
1002 }
1003 /**
1004 * @tc.name HdfCodecHdiUseBufferTestVirtualAddrOutput_004
1005 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0360
1006 * @tc.desc When the buffer is not initialized and portIndex is set to PORT_INDEX_OUTPUT,
1007 call the UseBuffer interface to set the internal buffer
1008 */
1009 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0360, Function | MediumTest | Level3)
1010 {
1011 ASSERT_TRUE(g_component != nullptr);
1012 std::shared_ptr<OmxCodecBuffer> omxBuffer = std::make_shared<OmxCodecBuffer>();
1013 ASSERT_TRUE(omxBuffer != nullptr);
1014 omxBuffer->size = sizeof(OmxCodecBuffer);
1015 omxBuffer->version = g_version;
1016 omxBuffer->bufferType = CODEC_BUFFER_TYPE_VIRTUAL_ADDR;
1017 omxBuffer->bufferLen = 0;
1018 omxBuffer->buffer = nullptr;
1019 omxBuffer->allocLen = 0;
1020 omxBuffer->fenceFd = -1;
1021 omxBuffer->pts = 0;
1022 omxBuffer->flag = 0;
1023
1024 auto err = g_component->UseBuffer(g_component, (uint32_t)PortIndex::PORT_INDEX_OUTPUT, omxBuffer.get());
1025 ASSERT_NE(err, HDF_SUCCESS);
1026 }
1027 /**
1028 * @tc.name HdfCodecHdiUseBufferInputSuccessTest_005
1029 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0370
1030 * @tc.desc After the buffer is initialized and portIndex is set to PORT_INDEX_INPUT
1031 the UseBuffer interface is invoked to set the internal buffe
1032 */
1033 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0370, Function | MediumTest | Level3)
1034 {
1035 ASSERT_TRUE(g_component != nullptr);
1036 OMX_PARAM_PORTDEFINITIONTYPE param;
1037 InitParam(param);
1038 param.nPortIndex = (OMX_U32)PortIndex::PORT_INDEX_INPUT;
1039 auto err = g_component->GetParameter(g_component, OMX_IndexParamPortDefinition, (int8_t *)¶m, sizeof(param));
1040 ASSERT_EQ(err, HDF_SUCCESS);
1041
1042 int bufferSize = param.nBufferSize;
1043 int bufferCount = param.nBufferCountActual;
1044 bool ret = UseBufferOnPort(PortIndex::PORT_INDEX_INPUT, bufferCount, bufferSize);
1045 ASSERT_TRUE(ret);
1046 }
1047 /**
1048 * @tc.name HdfCodecHdiUseBufferOutputSuccessTest_006
1049 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0380
1050 * @tc.desc After the buffer is initialized and portIndex is set to PORT_INDEX_OUTPUT,
1051 call the UseBuffer interface to set the internal buffer
1052 */
1053 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0380, Function | MediumTest | Level3)
1054 {
1055 ASSERT_TRUE(g_component != nullptr);
1056 OMX_PARAM_PORTDEFINITIONTYPE param;
1057 InitParam(param);
1058 param.nPortIndex = (OMX_U32)PortIndex::PORT_INDEX_OUTPUT;
1059 auto err = g_component->GetParameter(g_component, OMX_IndexParamPortDefinition, (int8_t *)¶m, sizeof(param));
1060 ASSERT_EQ(err, HDF_SUCCESS);
1061
1062 int bufferSize = param.nBufferSize;
1063 int bufferCount = param.nBufferCountActual;
1064 bool ret = UseBufferOnPort(PortIndex::PORT_INDEX_OUTPUT, bufferCount, bufferSize);
1065 ASSERT_TRUE(ret);
1066 }
1067 /**
1068 * @tc.name HdfCodecHdiUseBufferDynamicHandleOutputTest_007
1069 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0390
1070 * @tc.desc When bufferType is set to DynamicHandle and portIndex is set to PORT_INDEX_INPUT,
1071 the UseBuffer interface is invoked to set the internal buffer
1072 */
1073 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0390, Function | MediumTest | Level3)
1074 {
1075 ASSERT_TRUE(g_component != nullptr);
1076 std::shared_ptr<OmxCodecBuffer> omxBuffer = std::make_shared<OmxCodecBuffer>();
1077 ASSERT_TRUE(omxBuffer != nullptr);
1078 omxBuffer->size = sizeof(OmxCodecBuffer);
1079 omxBuffer->version = g_version;
1080 omxBuffer->bufferType = CODEC_BUFFER_TYPE_DYNAMIC_HANDLE;
1081
1082 omxBuffer->bufferLen = 0;
1083 omxBuffer->buffer = nullptr;
1084 omxBuffer->allocLen = 0;
1085 omxBuffer->fenceFd = -1;
1086 omxBuffer->pts = 0;
1087 omxBuffer->flag = 0;
1088
1089 auto err = g_component->UseBuffer(g_component, (uint32_t)PortIndex::PORT_INDEX_OUTPUT, omxBuffer.get());
1090 if (err != HDF_SUCCESS) {
1091 HDF_LOGE("%{public}s failed to UseBuffer with input port", __func__);
1092 omxBuffer = nullptr;
1093 }
1094 ASSERT_NE(err, HDF_SUCCESS);
1095 }
1096 /**
1097 * @tc.name HdfCodecHdiUseBufferAbnormalPortIndexTest_008
1098 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0400
1099 * @tc.desc After the buffer is initialized and portIndex is set to PORT_INDEX_ERROR_INPUT,
1100 call the UseBuffer interface to set the internal buffer
1101 */
1102 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0400, Function | MediumTest | Level3)
1103 {
1104 ASSERT_TRUE(g_component != nullptr);
1105 OMX_PARAM_PORTDEFINITIONTYPE param;
1106 InitParam(param);
1107 param.nPortIndex = (OMX_U32)PortIndex::PORT_INDEX_INPUT;
1108 auto err = g_component->GetParameter(g_component, OMX_IndexParamPortDefinition, (int8_t *)¶m, sizeof(param));
1109 ASSERT_EQ(err, HDF_SUCCESS);
1110
1111 int bufferSize = param.nBufferSize;
1112 int bufferCount = param.nBufferCountActual;
1113 bool ret = UseBufferOnPort(PortIndex::PORT_INDEX_ERROR_INPUT, bufferCount, bufferSize);
1114 ASSERT_FALSE(ret);
1115 }
1116 /**
1117 * @tc.name HdfCodecHdiSetStateLoadedToIdleTest_001
1118 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0410
1119 * @tc.desc The status of the component that invokes the SendCommand
1120 interface changes from OMX_StateLoaded to OMX_StateIdle
1121 */
1122 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0410, Function | MediumTest | Level3)
1123 {
1124 ASSERT_TRUE(g_component != nullptr);
1125 int32_t ret = g_component->SendCommand(g_component, OMX_CommandStateSet, OMX_StateIdle, nullptr, 0);
1126 ASSERT_EQ(ret, HDF_SUCCESS);
1127 }
1128 /**
1129 * @tc.name HdfCodecHdiSetStateIdleToExecutingTest_002
1130 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0420
1131 * @tc.desc The status of the component that invokes the SendCommand
1132 interface changes from OMX_StateIdle to OMX_StateExecuting
1133 */
1134 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0420, Function | MediumTest | Level3)
1135 {
1136 ASSERT_TRUE(g_component != nullptr);
1137 int32_t ret = g_component->SendCommand(g_component, OMX_CommandStateSet, OMX_StateExecuting, nullptr, 0);
1138 ASSERT_EQ(ret, HDF_SUCCESS);
1139 }
1140 /**
1141 * @tc.name HdfCodecHdiSetStateExecutingToPauseTest_003
1142 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0430
1143 * @tc.desc The status of the component that invokes the SendCommand
1144 interface changes from OMX_StateExecuting to OMX_StatePause
1145 */
1146 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0430, Function | MediumTest | Level3)
1147 {
1148 ASSERT_TRUE(g_component != nullptr);
1149 int32_t ret = g_component->SendCommand(g_component, OMX_CommandStateSet, OMX_StatePause, nullptr, 0);
1150 ASSERT_EQ(ret, HDF_SUCCESS);
1151 }
1152 /**
1153 * @tc.name HdfCodecHdiSetStatePauseToIdleTest_004
1154 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0440
1155 * @tc.desc The status of the component that invokes the SendCommand
1156 interface changes from OMX_StatePause to OMX_StateIdle
1157 */
1158 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0440, Function | MediumTest | Level3)
1159 {
1160 ASSERT_TRUE(g_component != nullptr);
1161 int32_t ret = g_component->SendCommand(g_component, OMX_CommandStateSet, OMX_StateIdle, nullptr, 0);
1162 ASSERT_EQ(ret, HDF_SUCCESS);
1163
1164 OMX_STATETYPE state;
1165 ret = g_component->GetState(g_component, &state);
1166 ASSERT_EQ(ret, HDF_SUCCESS);
1167 }
1168 /**
1169 * @tc.name HdfCodecHdiSendCommandCodecComponentTypeNullptrTest_005
1170 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0450
1171 * @tc.desc When CodecComponentType is set to Nullptr, the SendCommand
1172 interface is invoked to send instructions
1173 */
1174 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0450, Function | MediumTest | Level3)
1175 {
1176 ASSERT_TRUE(g_component != nullptr);
1177 int32_t ret = g_component->SendCommand(nullptr, OMX_CommandStateSet, OMX_StateIdle, nullptr, 0);
1178 ASSERT_NE(ret, HDF_SUCCESS);
1179 }
1180 /**
1181 * @tc.name HdfCodecHdiSendCommandAbnormalCommandTest_006
1182 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0460
1183 * @tc.desc When OMX_COMMANDTYPE is set to OMX_StateMax, the SendCommand
1184 interface is invoked to send instructions
1185 */
1186 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0460, Function | MediumTest | Level3)
1187 {
1188 ASSERT_TRUE(g_component != nullptr);
1189 int32_t ret = g_component->SendCommand(g_component, OMX_CommandMax, OMX_StatePause, nullptr, 0);
1190 ASSERT_NE(ret, HDF_SUCCESS);
1191 }
1192
1193 /**
1194 * @tc.name HdfCodecHdiSendCommandAbnormalCommandTest_006_1
1195 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0461
1196 * @tc.desc When OMX_COMMANDTYPE is set to OMX_CommandFlush, the SendCommand
1197 interface is invoked to send instructions
1198 */
1199 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0461, Function | MediumTest | Level3)
1200 {
1201 ASSERT_TRUE(g_component != nullptr);
1202 int32_t ret = g_component->SendCommand(g_component, OMX_CommandFlush, OMX_StatePause, nullptr, 0);
1203 ASSERT_NE(ret, HDF_SUCCESS);
1204 }
1205
1206 /**
1207 * @tc.name HdfCodecHdiSendCommandAbnormalCommandTest_006_2
1208 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0462
1209 * @tc.desc When OMX_COMMANDTYPE is set to OMX_CommandPortDisable, the SendCommand
1210 interface is invoked to send instructions
1211 */
1212 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0462, Function | MediumTest | Level3)
1213 {
1214 ASSERT_TRUE(g_component != nullptr);
1215 int32_t ret = g_component->SendCommand(g_component, OMX_CommandPortDisable, OMX_StatePause, nullptr, 0);
1216 ASSERT_NE(ret, HDF_SUCCESS);
1217 }
1218
1219 /**
1220 * @tc.name HdfCodecHdiSendCommandAbnormalCommandTest_006_3
1221 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0463
1222 * @tc.desc When OMX_COMMANDTYPE is set to OMX_CommandPortEnable, the SendCommand
1223 interface is invoked to send instructions
1224 */
1225 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0463, Function | MediumTest | Level3)
1226 {
1227 ASSERT_TRUE(g_component != nullptr);
1228 int32_t ret = g_component->SendCommand(g_component, OMX_CommandPortEnable, OMX_StatePause, nullptr, 0);
1229 ASSERT_NE(ret, HDF_SUCCESS);
1230 }
1231
1232 /**
1233 * @tc.name HdfCodecHdiSendCommandAbnormalCommandTest_006_4
1234 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0464
1235 * @tc.desc When OMX_COMMANDTYPE is set to OMX_CommandMarkBuffer, the SendCommand
1236 interface is invoked to send instructions
1237 */
1238 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0464, Function | MediumTest | Level3)
1239 {
1240 ASSERT_TRUE(g_component != nullptr);
1241 int32_t ret = g_component->SendCommand(g_component, OMX_CommandMarkBuffer, OMX_StatePause, nullptr, 0);
1242 ASSERT_NE(ret, HDF_SUCCESS);
1243 }
1244
1245 /**
1246 * @tc.name HdfCodecHdiSendCommandAbnormalCommandTest_006_5
1247 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0465
1248 * @tc.desc When OMX_COMMANDTYPE is set to OMX_CommandKhronosExtensions, the SendCommand
1249 interface is invoked to send instructions
1250 */
1251 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0465, Function | MediumTest | Level3)
1252 {
1253 ASSERT_TRUE(g_component != nullptr);
1254 int32_t ret = g_component->SendCommand(g_component, OMX_CommandKhronosExtensions, OMX_StatePause, nullptr, 0);
1255 ASSERT_NE(ret, HDF_SUCCESS);
1256 }
1257
1258 /**
1259 * @tc.name HdfCodecHdiSendCommandAbnormalCommandTest_006_6
1260 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0466
1261 * @tc.desc When OMX_COMMANDTYPE is set to OMX_CommandVendorStartUnused, the SendCommand
1262 interface is invoked to send instructions
1263 */
1264 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0466, Function | MediumTest | Level3)
1265 {
1266 ASSERT_TRUE(g_component != nullptr);
1267 int32_t ret = g_component->SendCommand(g_component, OMX_CommandVendorStartUnused, OMX_StatePause, nullptr, 0);
1268 ASSERT_NE(ret, HDF_SUCCESS);
1269 }
1270
1271 /**
1272 * @tc.name HdfCodecHdiSendCommandAbnormalParamTest_007
1273 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0470
1274 * @tc.desc When the cmd command is set to OMX_StateMax, the SendCommand
1275 interface is invoked to send the command
1276 */
1277 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0470, Function | MediumTest | Level3)
1278 {
1279 ASSERT_TRUE(g_component != nullptr);
1280 int32_t ret = g_component->SendCommand(g_component, OMX_CommandStateSet, OMX_StateMax, nullptr, 0);
1281 ASSERT_NE(ret, HDF_SUCCESS);
1282 }
1283 /**
1284 * @tc.name HdfCodecHdiUseEglImageUnsupportedTest_001
1285 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0480
1286 * @tc.desc Invoke the UseEglImage interface to use the EGL image
1287 */
1288 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0480, Function | MediumTest | Level3)
1289 {
1290 ASSERT_TRUE(g_component != nullptr);
1291 struct OmxCodecBuffer buffer;
1292 buffer.fenceFd = -1;
1293 buffer.version = g_version;
1294 buffer.bufferType = CODEC_BUFFER_TYPE_AVSHARE_MEM_FD;
1295 buffer.allocLen = BUFFER_SIZE;
1296 buffer.buffer = 0;
1297 buffer.bufferLen = 0;
1298 buffer.pts = 0;
1299 buffer.flag = 0;
1300 buffer.type = READ_ONLY_TYPE;
1301 auto eglImage = std::make_unique<int8_t[]>(BUFFER_SIZE);
1302 ASSERT_TRUE(eglImage != nullptr);
1303 int32_t ret = g_component->UseEglImage(g_component, &buffer, (uint32_t)PortIndex::PORT_INDEX_INPUT, eglImage.get(),
1304 BUFFER_SIZE);
1305 ASSERT_NE(ret, HDF_SUCCESS);
1306 eglImage = nullptr;
1307 }
1308 /**
1309 * @tc.name HdfCodecHdiWaitStateIdleTest_001
1310 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0490
1311 * @tc.desc The status of the listening component changes to OMX_StateIdle
1312 */
1313 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0490, Function | MediumTest | Level3)
1314 {
1315 ASSERT_TRUE(g_component != nullptr);
1316 // wait for Idle status
1317 OMX_STATETYPE state = OMX_StateInvalid;
1318 do {
1319 usleep(100);
1320 auto ret = g_component->GetState(g_component, &state);
1321 ASSERT_EQ(ret, HDF_SUCCESS);
1322 } while (state != OMX_StateIdle);
1323 }
1324 /**
1325 * @tc.name HdfCodecHdiFillThisBufferSuccessTest_001
1326 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0500
1327 * @tc.desc Invoke the FillThisBuffer interface to execute the codec output to fill the buffer
1328 */
1329 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0500, Function | MediumTest | Level3)
1330 {
1331 ASSERT_TRUE(g_component != nullptr);
1332 auto iter = outputBuffers.begin();
1333 if (iter != outputBuffers.end()) {
1334 int32_t ret = g_component->FillThisBuffer(g_component, iter->second->omxBuffer.get());
1335 ASSERT_EQ(ret, HDF_SUCCESS);
1336 }
1337 }
1338 /**
1339 * @tc.name HdfCodecHdiFillThisBufferUseErrorBufferIdTest_002
1340 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0510
1341 * @tc.desc Invoke the FillThisBuffer interface when bufferID is set to BUFFER_ID_ERROR
1342 */
1343 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0510, Function | MediumTest | Level3)
1344 {
1345 ASSERT_TRUE(g_component != nullptr);
1346 auto iter = outputBuffers.begin();
1347 if (iter != outputBuffers.end()) {
1348 auto omxBuffer = iter->second->omxBuffer;
1349 auto tempId = omxBuffer->bufferId;
1350 omxBuffer->bufferId = BUFFER_ID_ERROR;
1351 int32_t ret = g_component->FillThisBuffer(g_component, omxBuffer.get());
1352 ASSERT_NE(ret, HDF_SUCCESS);
1353 omxBuffer->bufferId = tempId;
1354 }
1355 }
1356 /**
1357 * @tc.name HdfCodecHdiEmptyThisBufferSuccessTest_001
1358 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0520
1359 * @tc.desc The EmptyThisBuffer interface is invoked to execute the codec output to fill the buffer
1360 */
1361 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0520, Function | MediumTest | Level3)
1362 {
1363 ASSERT_TRUE(g_component != nullptr);
1364 auto iter = inputBuffers.begin();
1365 if (iter != inputBuffers.end()) {
1366 int32_t ret = g_component->EmptyThisBuffer(g_component, iter->second->omxBuffer.get());
1367 ASSERT_EQ(ret, HDF_SUCCESS);
1368 }
1369 }
1370 /**
1371 * @tc.name HdfCodecHdiEmptyThisBufferUseErrorBufferIdTest_002
1372 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0530
1373 * @tc.desc Invoke the EmptyThisBuffer interface when bufferID is set to BUFFER_ID_ERROR
1374 */
1375 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0530, Function | MediumTest | Level3)
1376 {
1377 ASSERT_TRUE(g_component != nullptr);
1378 auto iter = inputBuffers.begin();
1379 if (iter != inputBuffers.end()) {
1380 auto omxBuffer = iter->second->omxBuffer;
1381 auto tempId = omxBuffer->bufferId;
1382 omxBuffer->bufferId = BUFFER_ID_ERROR;
1383 int32_t ret = g_component->EmptyThisBuffer(g_component, iter->second->omxBuffer.get());
1384 ASSERT_NE(ret, HDF_SUCCESS);
1385 omxBuffer->bufferId = tempId;
1386 }
1387 }
1388 /**
1389 * @tc.name HdfCodecHdiSetCallbackSuccessTest_001
1390 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0540
1391 * @tc.desc The SetCallback interface is invoked to set the callback
1392 */
1393 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0540, Function | MediumTest | Level3)
1394 {
1395 ASSERT_TRUE(g_component != nullptr);
1396 if (g_callback != nullptr) {
1397 CodecCallbackTypeRelease(g_callback);
1398 }
1399 g_callback = CodecCallbackTypeGet(nullptr);
1400 ASSERT_TRUE(g_callback != nullptr);
1401 int32_t ret = g_component->SetCallbacks(g_component, g_callback, APP_DATA);
1402 ASSERT_EQ(ret, HDF_SUCCESS);
1403 }
1404 /**
1405 * @tc.name HdfCodecHdiSetCallbackAppDataLenMaxTest_002
1406 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0550
1407 * @tc.desc When AppData is set to the maximum value in the value range,
1408 the SetCallback interface is invoked to set the callback
1409 */
1410 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0550, Function | MediumTest | Level3)
1411 {
1412 ASSERT_TRUE(g_component != nullptr);
1413 if (g_callback != nullptr) {
1414 CodecCallbackTypeRelease(g_callback);
1415 }
1416 g_callback = CodecCallbackTypeGet(nullptr);
1417 ASSERT_TRUE(g_callback != nullptr); ASSERT_TRUE(g_callback != nullptr);
1418 int32_t ret = g_component->SetCallbacks(g_component, g_callback, APP_DATA_MAX);
1419 ASSERT_EQ(ret, HDF_SUCCESS);
1420 }
1421 /**
1422 * @tc.name HdfCodecHdiSetCallbackAppDataLenMinTest_003
1423 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0560
1424 * @tc.desc When AppData is set to the minimum value in the value range,
1425 the SetCallback interface is invoked to set the callback
1426 */
1427 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0560, Function | MediumTest | Level3)
1428 {
1429 ASSERT_TRUE(g_component != nullptr);
1430 if (g_callback != nullptr) {
1431 CodecCallbackTypeRelease(g_callback);
1432 }
1433 g_callback = CodecCallbackTypeGet(nullptr);
1434 ASSERT_TRUE(g_callback != nullptr);
1435 int32_t ret = g_component->SetCallbacks(g_component, g_callback, APP_DATA_MIN);
1436 ASSERT_EQ(ret, HDF_SUCCESS);
1437 }
1438 /**
1439 * @tc.name HdfCodecHdiRoleEnumUnsupportedTest_001
1440 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0570
1441 * @tc.desc Invoke the ComponentRoleEnum interface to obtain component tasks
1442 */
1443 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0570, Function | MediumTest | Level3)
1444 {
1445 ASSERT_TRUE(g_component != nullptr);
1446 uint8_t role[ROLE_LEN] = {0};
1447 int32_t ret = g_component->ComponentRoleEnum(g_component, role, ROLE_LEN, 0);
1448 ASSERT_NE(ret, HDF_SUCCESS);
1449 }
1450 /**
1451 * @tc.name HdfCodecHdiFreeBufferPortIndexOutputUnsupportedTest_001
1452 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0580
1453 * @tc.desc Set portIndex to PORT_INDEX_OUTPUT and invoke the FreeBuffer interface to obtain component tasks
1454 */
1455 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0580, Function | MediumTest | Level3)
1456 {
1457 ASSERT_TRUE(g_component != nullptr);
1458 auto iter = outputBuffers.begin();
1459 while (iter != outputBuffers.end()) {
1460 int32_t ret =
1461 g_component->FreeBuffer(g_component, (uint32_t)PortIndex::PORT_INDEX_OUTPUT, iter->second->omxBuffer.get());
1462 ASSERT_NE(ret, HDF_SUCCESS);
1463 iter = outputBuffers.erase(iter);
1464 }
1465 }
1466 /**
1467 * @tc.name HdfCodecHdiFreeBufferPortIndexInputUnsupportedTest_002
1468 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0590
1469 * @tc.desc Set portIndex to PORT_INDEX_INPUT and invoke the FreeBuffer interface to obtain component tasks
1470 */
1471 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0590, Function | MediumTest | Level3)
1472 {
1473 ASSERT_TRUE(g_component != nullptr);
1474 auto iter = inputBuffers.begin();
1475 while (iter != inputBuffers.end()) {
1476 int32_t ret =
1477 g_component->FreeBuffer(g_component, (uint32_t)PortIndex::PORT_INDEX_INPUT, iter->second->omxBuffer.get());
1478 ASSERT_NE(ret, HDF_SUCCESS);
1479 iter = inputBuffers.erase(iter);
1480 }
1481 }
1482 /**
1483 * @tc.name HdfCodecHdiSetStateIdleToLoadedTest_001
1484 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0600
1485 * @tc.desc The status of the component that invokes the SendCommand
1486 interface changes from OMX_StateIdle to OMX_StateLoaded
1487 */
1488 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0600, Function | MediumTest | Level3)
1489 {
1490 ASSERT_TRUE(g_component != nullptr);
1491 int32_t ret = g_component->SendCommand(g_component, OMX_CommandStateSet, OMX_StateLoaded, nullptr, 0);
1492 ASSERT_EQ(ret, HDF_SUCCESS);
1493
1494 OMX_STATETYPE state = OMX_StateInvalid;
1495 do {
1496 usleep(100);
1497 auto ret = g_component->GetState(g_component, &state);
1498 ASSERT_EQ(ret, HDF_SUCCESS);
1499 } while (state != OMX_StateLoaded);
1500 }
1501 /**
1502 * @tc.name HdfCodecHdiDeInitUnsupportedTest_001
1503 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0610
1504 * @tc.desc Invoke the ComponentDeInit interface to deinitialize the component
1505 */
1506 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0610, Function | MediumTest | Level3)
1507 {
1508 ASSERT_TRUE(g_component != nullptr);
1509 int32_t ret = g_component->ComponentDeInit(g_component);
1510 ASSERT_NE(ret, HDF_SUCCESS);
1511 }
1512 /**
1513 * @tc.name HdfCodecHdiDestoryComponentSuccessTest_001
1514 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0620
1515 * @tc.desc Invoke the DestoryComponent interface to destroy components
1516 */
1517 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0620, Function | MediumTest | Level3)
1518 {
1519 ASSERT_TRUE(g_component != nullptr);
1520 ASSERT_TRUE(g_manager != nullptr);
1521 int ret = g_manager->DestroyComponent(g_componentId);
1522 ASSERT_EQ(ret, HDF_SUCCESS);
1523 }
1524 /**
1525 * @tc.name HdfCodecHdiCallbackTypeReleaseAndManagerReleaseTest_001
1526 * @tc.number SUB_DriverSystem_CodecHdi_adapter_0630
1527 * @tc.desc Destroy callback events and component management objects
1528 */
1529 HWTEST_F(CodecHdiAdapterTest, SUB_DriverSystem_CodecHdi_adapter_0630, Function | MediumTest | Level3)
1530 {
1531 ASSERT_TRUE(g_manager != nullptr);
1532 ASSERT_TRUE(g_callback != nullptr);
1533 CodecCallbackTypeRelease(g_callback);
1534 CodecComponentManagerRelease();
1535 g_callback = nullptr;
1536 g_manager = nullptr;
1537 }
1538 } // namespace
1539