1 /*
2 * Copyright (c) 2021 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 /**
17 * @addtogroup Audio
18 * @{
19 *
20 * @brief Test audio-related APIs, including custom data types and functions for loading drivers,
21 * accessing a driver ADM interface lib, and captureing audios
22 *
23 * @since 1.0
24 * @version 1.0
25 */
26
27 /**
28 * @file audio_lib_common.h
29 *
30 * @brief Declares APIs for operations related to the audio ADM interface lib.
31 *
32 * @since 1.0
33 * @version 1.0
34 */
35 #include "audio_lib_common.h"
36 #include "audio_libcapture_test.h"
37
38 using namespace std;
39 using namespace testing::ext;
40 using namespace HMOS::Audio;
41
42 namespace {
43 const string BIND_CONTROL = "control";
44 const string BIND_CAPTURE = "capture";
45 const string BIND_NAME_ERROR = "rendeo";
46 const string ADAPTER_NAME_INTERNAL = "internal";
47
48 class AudioLibCaptureTest : public testing::Test {
49 public:
50 static void SetUpTestCase(void);
51 static void TearDownTestCase(void);
52 void SetUp();
53 void TearDown();
54 static struct DevHandle *(*BindServiceCaptureSo)(const char *);
55 static int32_t (*InterfaceLibOutputCapture)(struct DevHandle *, int, struct AudioHwCaptureParam *);
56 static int32_t (*InterfaceLibCtlCapture)(struct DevHandle *, int, struct AudioHwCaptureParam *);
57 static void (*CloseServiceCaptureSo)(struct DevHandle *);
58 #ifdef AUDIO_MPI_SO
59 static int32_t (*SdkInit)();
60 static void (*SdkExit)();
61 #endif
62 static void *PtrHandle;
63 int32_t BindServiceAndHwCapture(struct AudioHwCapture *&hwCapture, const std::string BindName,
64 const std::string adapterNameCase, struct DevHandle *&handle) const;
65 };
66
67 struct DevHandle *(*AudioLibCaptureTest::BindServiceCaptureSo)(const char *) = nullptr;
68 int32_t (*AudioLibCaptureTest::InterfaceLibOutputCapture)(struct DevHandle *, int,
69 struct AudioHwCaptureParam *) = nullptr;
70 int32_t (*AudioLibCaptureTest::InterfaceLibCtlCapture)(struct DevHandle *, int, struct AudioHwCaptureParam *) = nullptr;
71 void (*AudioLibCaptureTest::CloseServiceCaptureSo)(struct DevHandle *) = nullptr;
72 #ifdef AUDIO_MPI_SO
73 int32_t (*AudioLibCaptureTest::SdkInit)() = nullptr;
74 void (*AudioLibCaptureTest::SdkExit)() = nullptr;
75 #endif
76 void *AudioLibCaptureTest::PtrHandle = nullptr;
77
SetUpTestCase(void)78 void AudioLibCaptureTest::SetUpTestCase(void)
79 {
80 char resolvedPath[] = HDF_LIBRARY_FULL_PATH("libhdi_audio_interface_lib_capture");
81 PtrHandle = dlopen(resolvedPath, RTLD_LAZY);
82 if (PtrHandle == nullptr) {
83 return;
84 }
85 BindServiceCaptureSo = (struct DevHandle* (*)(const char *))dlsym(PtrHandle, "AudioBindServiceCapture");
86 InterfaceLibOutputCapture = (int32_t (*)(struct DevHandle *, int,
87 struct AudioHwCaptureParam *))dlsym(PtrHandle, "AudioInterfaceLibOutputCapture");
88 InterfaceLibCtlCapture = (int32_t (*)(struct DevHandle *, int,
89 struct AudioHwCaptureParam *))dlsym(PtrHandle, "AudioInterfaceLibCtlCapture");
90 CloseServiceCaptureSo = (void (*)(struct DevHandle *))dlsym(PtrHandle, "AudioCloseServiceCapture");
91 if (BindServiceCaptureSo == nullptr || CloseServiceCaptureSo == nullptr ||
92 InterfaceLibCtlCapture == nullptr || InterfaceLibOutputCapture == nullptr) {
93 dlclose(PtrHandle);
94 return;
95 }
96 #ifdef AUDIO_MPI_SO
97 SdkInit = (int32_t (*)())(dlsym(PtrHandle, "MpiSdkInit"));
98 if (SdkInit == nullptr) {
99 return;
100 }
101 SdkExit = (void (*)())(dlsym(PtrHandle, "MpiSdkExit"));
102 if (SdkExit == nullptr) {
103 return;
104 }
105 SdkInit();
106 #endif
107 }
108
TearDownTestCase(void)109 void AudioLibCaptureTest::TearDownTestCase(void)
110 {
111 if (BindServiceCaptureSo != nullptr) {
112 BindServiceCaptureSo = nullptr;
113 }
114 if (CloseServiceCaptureSo != nullptr) {
115 CloseServiceCaptureSo = nullptr;
116 }
117 if (InterfaceLibCtlCapture != nullptr) {
118 InterfaceLibCtlCapture = nullptr;
119 }
120 if (InterfaceLibOutputCapture != nullptr) {
121 InterfaceLibOutputCapture = nullptr;
122 }
123 #ifdef AUDIO_MPI_SO
124 SdkExit();
125 if (SdkInit != nullptr) {
126 SdkInit = nullptr;
127 }
128 if (SdkExit != nullptr) {
129 SdkExit = nullptr;
130 }
131 #endif
132 if (PtrHandle != nullptr) {
133 dlclose(PtrHandle);
134 PtrHandle = nullptr;
135 }
136 }
137
SetUp(void)138 void AudioLibCaptureTest::SetUp(void) {}
139
TearDown(void)140 void AudioLibCaptureTest::TearDown(void) {}
141
BindServiceAndHwCapture(struct AudioHwCapture * & hwCapture,const std::string BindName,const std::string adapterNameCase,struct DevHandle * & handle) const142 int32_t AudioLibCaptureTest::BindServiceAndHwCapture(struct AudioHwCapture *&hwCapture,
143 const std::string BindName, const std::string adapterNameCase, struct DevHandle *&handle) const
144 {
145 handle = BindServiceCaptureSo(BindName.c_str());
146 if (handle == nullptr) {
147 return HDF_FAILURE;
148 }
149 hwCapture = (struct AudioHwCapture *)calloc(1, sizeof(*hwCapture));
150 if (hwCapture == nullptr) {
151 CloseServiceCaptureSo(handle);
152 return HDF_FAILURE;
153 }
154 if (InitHwCapture(hwCapture, adapterNameCase)) {
155 free(hwCapture);
156 hwCapture = nullptr;
157 CloseServiceCaptureSo(handle);
158 return HDF_FAILURE;
159 }
160 return HDF_SUCCESS;
161 }
162
163 /**
164 * @tc.name Test AudioBindServiceCapture API via legal input
165 * @tc.number SUB_Audio_InterfaceLibBindServiceCapture_0001
166 * @tc.desc Test AudioBindServiceCapture interface,return 0 is call successfully
167 * @tc.author: wangkang
168 */
169 HWTEST_F(AudioLibCaptureTest, SUB_Audio_InterfaceLibBindServiceCapture_0001, TestSize.Level1)
170 {
171 struct DevHandle *handle = nullptr;
172 handle = BindServiceCaptureSo(BIND_CONTROL.c_str());
173 EXPECT_NE(nullptr, handle);
174 CloseServiceCaptureSo(handle);
175 }
176 /**
177 * @tc.name Test AudioBindServiceCapture API via invalid input.
178 * @tc.number SUB_Audio_InterfaceLibBindServiceCapture_0002
179 * @tc.desc test Binding failed Service which invalid service Name is rendeo.
180 * @tc.author: wangkang
181 */
182 HWTEST_F(AudioLibCaptureTest, SUB_Audio_InterfaceLibBindServicecapture_0002, TestSize.Level1)
183 {
184 struct DevHandle *handle = nullptr;
185 handle = BindServiceCaptureSo(BIND_NAME_ERROR.c_str());
186 if (handle != nullptr) {
187 CloseServiceCaptureSo(handle);
188 ASSERT_EQ(nullptr, handle);
189 }
190 EXPECT_EQ(nullptr, handle);
191 }
192 /**
193 * @tc.name Test AudioBindServiceCapture API via setting the incoming parameter handle is empty.
194 * @tc.number SUB_Audio_InterfaceLibBindServiceCapture_0003
195 * @tc.desc test Binding failed Service, nullptr pointer passed in.
196 * @tc.author: wangkang
197 */
198 HWTEST_F(AudioLibCaptureTest, SUB_Audio_InterfaceLibBindServiceCapture_0003, TestSize.Level1)
199 {
200 struct DevHandle *handle = {};
201 char *bindNameNull = nullptr;
202 handle = BindServiceCaptureSo(bindNameNull);
203 if (handle != nullptr) {
204 CloseServiceCaptureSo(handle);
205 ASSERT_EQ(nullptr, handle);
206 }
207 EXPECT_EQ(nullptr, handle);
208 }
209 /**
210 * @tc.name test BindServiceCaptureSo API via name lens is 25.
211 * @tc.number SUB_Audio_InterfaceLibBindServiceCapture_0004
212 * @tc.desc test Binding failed Service, Log printing 'service name not support!' and 'Failed to get service!'.
213 * @tc.author: wangkang
214 */
215 HWTEST_F(AudioLibCaptureTest, SUB_Audio_InterfaceLibBindServiceCapture_0004, TestSize.Level1)
216 {
217 struct DevHandle *handle = nullptr;
218 string bindNameLen = "capturecaptureededededede";
219 handle = BindServiceCaptureSo(bindNameLen.c_str());
220 if (handle != nullptr) {
221 CloseServiceCaptureSo(handle);
222 ASSERT_EQ(nullptr, handle);
223 }
224 EXPECT_EQ(nullptr, handle);
225 }
226 /**
227 * @tc.name test BindServiceCaptureSo API via name lens is 26.
228 * @tc.number SUB_Audio_InterfaceLibBindServiceCapture_0005
229 * @tc.desc test Binding failed Service, Log printing 'Failed to snprintf_s'.
230 * @tc.author: wangkang
231 */
232 HWTEST_F(AudioLibCaptureTest, SUB_Audio_InterfaceLibBindServiceCapture_0005, TestSize.Level1)
233 {
234 struct DevHandle *handle = nullptr;
235 string bindNameLen = "capturecaptureedededededer";
236 handle = BindServiceCaptureSo(bindNameLen.c_str());
237 if (handle != nullptr) {
238 CloseServiceCaptureSo(handle);
239 ASSERT_EQ(nullptr, handle);
240 }
241 EXPECT_EQ(nullptr, handle);
242 }
243 /**
244 * @tc.name test InterfaceLibCtlCapture API via writing mute value that include 1 and 0 and reading mute value.
245 * @tc.number SUB_Audio_InterfaceLibCtlCapture_MuteWrite_Read_0001
246 * @tc.desc test InterfaceLibCtlCapture ,cmdId is AUDIODRV_CTL_IOCTL_MUTE_WRITE_CAPTURE and
247 * AUDIODRV_CTL_IOCTL_MUTE_READ_CAPTURE.
248 * @tc.author: wangkang
249 */
250 HWTEST_F(AudioLibCaptureTest, SUB_Audio_InterfaceLibCtlCapture_MuteWrite_Read_0001, TestSize.Level1)
251 {
252 int32_t ret = -1;
253 bool muteValue = 1;
254 bool wishValue = 0;
255 bool expectedValue = 1;
256 struct DevHandle *handle = nullptr;
257 struct AudioHwCapture *hwCapture = nullptr;
258
259 ret = BindServiceAndHwCapture(hwCapture, BIND_CONTROL.c_str(), ADAPTER_NAME_INTERNAL, handle);
260 ASSERT_EQ(HDF_SUCCESS, ret);
261
262 hwCapture->captureParam.captureMode.ctlParam.mute = 0;
263 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_MUTE_WRITE_CAPTURE, &hwCapture->captureParam);
264 EXPECT_EQ(HDF_SUCCESS, ret);
265 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_MUTE_READ_CAPTURE, &hwCapture->captureParam);
266 EXPECT_EQ(HDF_SUCCESS, ret);
267 muteValue = hwCapture->captureParam.captureMode.ctlParam.mute;
268 EXPECT_EQ(wishValue, muteValue);
269 hwCapture->captureParam.captureMode.ctlParam.mute = 1;
270 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_MUTE_WRITE_CAPTURE, &hwCapture->captureParam);
271 EXPECT_EQ(HDF_SUCCESS, ret);
272 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_MUTE_READ_CAPTURE, &hwCapture->captureParam);
273 EXPECT_EQ(HDF_SUCCESS, ret);
274 muteValue = hwCapture->captureParam.captureMode.ctlParam.mute;
275 EXPECT_EQ(expectedValue, muteValue);
276 free(hwCapture);
277 hwCapture = nullptr;
278 CloseServiceCaptureSo(handle);
279 }
280 /**
281 * @tc.name test InterfaceLibCtlCapture API via writing mute value that is 2 and read mute value.
282 * @tc.number SUB_Audio_InterfaceLibCtlCapture_MuteWrite_Read_0002
283 * @tc.desc test InterfaceLibCtlCapture ,cmdId is AUDIODRV_CTL_IOCTL_MUTE_WRITE_CAPTURE and
284 * AUDIODRV_CTL_IOCTL_MUTE_READ_CAPTURE.
285 * @tc.author: wangkang
286 */
287 HWTEST_F(AudioLibCaptureTest, SUB_Audio_InterfaceLibCtlCapture_MuteWrite_Read_0002, TestSize.Level1)
288 {
289 int32_t ret = -1;
290 bool muteValue = 0;
291 bool wishValue = 0;
292 bool expectedValue = 1;
293 struct DevHandle *handle = nullptr;
294 struct AudioHwCapture *hwCapture = nullptr;
295 ret = BindServiceAndHwCapture(hwCapture, BIND_CONTROL.c_str(), ADAPTER_NAME_INTERNAL, handle);
296 ASSERT_EQ(HDF_SUCCESS, ret);
297
298 hwCapture->captureParam.captureMode.ctlParam.mute = 2;
299 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_MUTE_WRITE_CAPTURE, &hwCapture->captureParam);
300 EXPECT_EQ(HDF_SUCCESS, ret);
301 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_MUTE_READ_CAPTURE, &hwCapture->captureParam);
302 EXPECT_EQ(HDF_SUCCESS, ret);
303 muteValue = hwCapture->captureParam.captureMode.ctlParam.mute;
304 EXPECT_EQ(expectedValue, muteValue);
305 hwCapture->captureParam.captureMode.ctlParam.mute = 0;
306 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_MUTE_WRITE_CAPTURE, &hwCapture->captureParam);
307 EXPECT_EQ(HDF_SUCCESS, ret);
308 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_MUTE_READ_CAPTURE, &hwCapture->captureParam);
309 EXPECT_EQ(HDF_SUCCESS, ret);
310 muteValue = hwCapture->captureParam.captureMode.ctlParam.mute;
311 EXPECT_EQ(wishValue, muteValue);
312 free(hwCapture);
313 hwCapture = nullptr;
314 CloseServiceCaptureSo(handle);
315 }
316 /**
317 * @tc.name test InterfaceLibCtlCapture API via writing volume value.
318 * @tc.number SUB_Audio_InterfaceLibCtlCapture_VolumeWrite_Read_0001
319 * @tc.desc test InterfaceLibCtlCapture ,cmdId is AUDIODRV_CTL_IOCTL_ELEM_WRITE_CAPTURE and
320 * AUDIODRV_CTL_IOCTL_ELEM_READ_CAPTURE.
321 * @tc.author: wangkang
322 */
323 HWTEST_F(AudioLibCaptureTest, SUB_Audio_InterfaceLibCtlCapture_VolumeWrite_Read_0001, TestSize.Level1)
324 {
325 int32_t ret = -1;
326 float volumeValue;
327 float expectedValue1 = 86;
328 float expectedValue2 = 1;
329 float volumeThresholdValueMax = 0;
330 float volumeThresholdValueMin = 0;
331 struct DevHandle *handle = nullptr;
332 struct AudioHwCapture *hwCapture = nullptr;
333 ret = BindServiceAndHwCapture(hwCapture, BIND_CONTROL.c_str(), ADAPTER_NAME_INTERNAL, handle);
334 ASSERT_EQ(HDF_SUCCESS, ret);
335
336 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_VOL_THRESHOLD_CAPTURE, &hwCapture->captureParam);
337 EXPECT_EQ(HDF_SUCCESS, ret);
338 volumeThresholdValueMax = hwCapture->captureParam.captureMode.ctlParam.volThreshold.volMax;
339 volumeThresholdValueMin = hwCapture->captureParam.captureMode.ctlParam.volThreshold.volMin;
340
341 hwCapture->captureParam.captureMode.ctlParam.volume = volumeThresholdValueMax-1;
342 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_ELEM_WRITE_CAPTURE, &hwCapture->captureParam);
343 EXPECT_EQ(HDF_SUCCESS, ret);
344 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_ELEM_READ_CAPTURE, &hwCapture->captureParam);
345 EXPECT_EQ(HDF_SUCCESS, ret);
346 volumeValue = hwCapture->captureParam.captureMode.ctlParam.volume;
347 if (IS_ADM == false) {
348 EXPECT_EQ(126, volumeValue);
349 } else {
350 EXPECT_EQ(expectedValue1, volumeValue);
351 }
352
353 hwCapture->captureParam.captureMode.ctlParam.volume = volumeThresholdValueMin+1;
354 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_ELEM_WRITE_CAPTURE, &hwCapture->captureParam);
355 EXPECT_EQ(HDF_SUCCESS, ret);
356 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_ELEM_READ_CAPTURE, &hwCapture->captureParam);
357 EXPECT_EQ(HDF_SUCCESS, ret);
358 volumeValue = hwCapture->captureParam.captureMode.ctlParam.volume;
359 EXPECT_EQ(expectedValue2, volumeValue);
360
361 free(hwCapture);
362 hwCapture = nullptr;
363 CloseServiceCaptureSo(handle);
364 }
365 /**
366 * @tc.name test InterfaceLibCtlCapture API via writing volume value.
367 * @tc.number SUB_Audio_InterfaceLibCtlCapture_VolumeWrite_Read_0002
368 * @tc.desc test InterfaceLibCtlCapture ,cmdId is AUDIODRV_CTL_IOCTL_ELEM_WRITE_CAPTURE and
369 * AUDIODRV_CTL_IOCTL_ELEM_READ_CAPTURE.
370 * @tc.author: wangkang
371 */
372 HWTEST_F(AudioLibCaptureTest, SUB_Audio_InterfaceLibCtlCapture_VolumeWrite_Read_0002, TestSize.Level1)
373 {
374 int32_t ret = -1;
375 struct DevHandle *handle = nullptr;
376 struct AudioHwCapture *hwCapture = nullptr;
377 float volumeValue = 0;
378 float expectedValueMax = 87;
379 float expectedValueMin = 0;
380 float volumeThresholdValueMax = 0;
381 float volumeThresholdValueMin = 0;
382 ret = BindServiceAndHwCapture(hwCapture, BIND_CONTROL.c_str(), ADAPTER_NAME_INTERNAL, handle);
383 ASSERT_EQ(HDF_SUCCESS, ret);
384
385 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_VOL_THRESHOLD_CAPTURE, &hwCapture->captureParam);
386 EXPECT_EQ(HDF_SUCCESS, ret);
387 volumeThresholdValueMax = hwCapture->captureParam.captureMode.ctlParam.volThreshold.volMax;
388 volumeThresholdValueMin = hwCapture->captureParam.captureMode.ctlParam.volThreshold.volMin;
389
390 hwCapture->captureParam.captureMode.ctlParam.volume = volumeThresholdValueMin;
391 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_ELEM_WRITE_CAPTURE, &hwCapture->captureParam);
392 EXPECT_EQ(HDF_SUCCESS, ret);
393 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_ELEM_READ_CAPTURE, &hwCapture->captureParam);
394 EXPECT_EQ(HDF_SUCCESS, ret);
395 volumeValue = hwCapture->captureParam.captureMode.ctlParam.volume;
396 EXPECT_EQ(expectedValueMin, volumeValue);
397
398 hwCapture->captureParam.captureMode.ctlParam.volume = volumeThresholdValueMax;
399 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_ELEM_WRITE_CAPTURE, &hwCapture->captureParam);
400 EXPECT_EQ(HDF_SUCCESS, ret);
401 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_ELEM_READ_CAPTURE, &hwCapture->captureParam);
402 EXPECT_EQ(HDF_SUCCESS, ret);
403 volumeValue = hwCapture->captureParam.captureMode.ctlParam.volume;
404 if (IS_ADM == false) {
405 EXPECT_EQ(127, volumeValue);
406 } else {
407 EXPECT_EQ(expectedValueMax, volumeValue);
408 }
409
410 free(hwCapture);
411 hwCapture = nullptr;
412 CloseServiceCaptureSo(handle);
413 }
414 /**
415 * @tc.name test InterfaceLibCtlCapture API via writing volume value.
416 * @tc.number SUB_Audio_InterfaceLibCtlCapture_VolumeWrite_Read_0003
417 * @tc.desc test InterfaceLibCtlCapture ,cmdId is AUDIODRV_CTL_IOCTL_ELEM_WRITE_CAPTURE and
418 * AUDIODRV_CTL_IOCTL_ELEM_READ_CAPTURE.
419 * @tc.author: wangkang
420 */
421 HWTEST_F(AudioLibCaptureTest, SUB_Audio_InterfaceLibCtlCapture_VolumeWrite_Read_0003, TestSize.Level1)
422 {
423 int32_t ret = -1;
424 float volumeThresholdValueMax = 0;
425 struct AudioHwCapture *hwCapture = nullptr;
426 float volumeThresholdValueMin = 0;
427 struct DevHandle *handle = nullptr;
428 ret = BindServiceAndHwCapture(hwCapture, BIND_CONTROL.c_str(), ADAPTER_NAME_INTERNAL, handle);
429 ASSERT_EQ(HDF_SUCCESS, ret);
430
431 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_VOL_THRESHOLD_CAPTURE, &hwCapture->captureParam);
432 EXPECT_EQ(HDF_SUCCESS, ret);
433 volumeThresholdValueMax = hwCapture->captureParam.captureMode.ctlParam.volThreshold.volMax;
434 volumeThresholdValueMin = hwCapture->captureParam.captureMode.ctlParam.volThreshold.volMin;
435
436 hwCapture->captureParam.captureMode.ctlParam.volume = volumeThresholdValueMax+1;
437 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_ELEM_WRITE_CAPTURE, &hwCapture->captureParam);
438 EXPECT_EQ(HDF_FAILURE, ret);
439 hwCapture->captureParam.captureMode.ctlParam.volume = volumeThresholdValueMin-1;
440 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_ELEM_WRITE_CAPTURE, &hwCapture->captureParam);
441 EXPECT_EQ(HDF_FAILURE, ret);
442 free(hwCapture);
443 hwCapture = nullptr;
444 CloseServiceCaptureSo(handle);
445 }
446 /**
447 * @tc.name test InterfaceLibCtlCapture API via writing GetGainthreshold value of Hardware equipment.
448 * @tc.number SUB_Audio_InterfaceLibCtlCapture_GetVolthresholdRead_0001
449 * @tc.desc test InterfaceLibCtlCapture ,cmdId is AUDIODRV_CTL_IOCTL_VOL_THRESHOLD_CAPTURE.
450 * @tc.author: liutian
451 */
452 HWTEST_F(AudioLibCaptureTest, SUB_Audio_InterfaceLibCtlCapture_GetVolthresholdRead_0001, TestSize.Level1)
453 {
454 int32_t ret = -1;
455 float volumeThresholdValueMax = 0;
456 float volumeThresholdValueMin = 0;
457 float expMax = 87;
458 float expMix = 0;
459 struct DevHandle *handle = nullptr;
460 struct AudioHwCapture *hwCapture = nullptr;
461 ret = BindServiceAndHwCapture(hwCapture, BIND_CONTROL.c_str(), ADAPTER_NAME_INTERNAL, handle);
462 ASSERT_EQ(HDF_SUCCESS, ret);
463
464 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_VOL_THRESHOLD_CAPTURE, &hwCapture->captureParam);
465 EXPECT_EQ(HDF_SUCCESS, ret);
466 volumeThresholdValueMax = hwCapture->captureParam.captureMode.ctlParam.volThreshold.volMax;
467 volumeThresholdValueMin = hwCapture->captureParam.captureMode.ctlParam.volThreshold.volMin;
468 if (IS_ADM == false) {
469 EXPECT_EQ(127, volumeThresholdValueMax);
470 } else {
471 EXPECT_EQ(expMax, volumeThresholdValueMax);
472 }
473 EXPECT_EQ(expMix, volumeThresholdValueMin);
474 CloseServiceCaptureSo(handle);
475 free(hwCapture);
476 hwCapture = nullptr;
477 }
478 /**
479 * @tc.name test InterfaceLibCtlCapture API via selecting scene.
480 * @tc.number SUB_Audio_InterfaceLib_CtlCapture_SelectScene_0001
481 * @tc.desc test InterfaceLibCtlCapture,cmdId is AUDIODRV_CTL_IOCTL_SCENESELECT_CAPTURE.
482 * @tc.author: wangkang
483 */
484 HWTEST_F(AudioLibCaptureTest, SUB_Audio_InterfaceLibCtlCapture_SelectScene_0001, TestSize.Level1)
485 {
486 int32_t ret = -1;
487 struct DevHandle* handle = nullptr;
488 struct AudioHwCapture *hwCapture = nullptr;
489 ret = BindServiceAndHwCapture(hwCapture, BIND_CONTROL.c_str(), ADAPTER_NAME_INTERNAL, handle);
490 ASSERT_EQ(HDF_SUCCESS, ret);
491
492 struct AudioSceneDescriptor scene = {
493 .scene.id = 0,
494 .desc.pins = PIN_IN_HS_MIC,
495 };
496 hwCapture->captureParam.captureMode.hwInfo.pathSelect.deviceInfo.deviceNum = 1;
497 ret = strcpy_s(hwCapture->captureParam.captureMode.hwInfo.pathSelect.deviceInfo.deviceSwitchs[0].deviceSwitch,
498 PATHPLAN_COUNT, "LPGA MIC Switch");
499 hwCapture->captureParam.captureMode.hwInfo.pathSelect.deviceInfo.deviceSwitchs[0].value = 0;
500 hwCapture->captureParam.frameCaptureMode.attrs.type = (enum AudioCategory)(scene.scene.id);
501 hwCapture->captureParam.captureMode.hwInfo.deviceDescript.pins = scene.desc.pins;
502
503 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_SCENESELECT_CAPTURE, &hwCapture->captureParam);
504 EXPECT_EQ(HDF_SUCCESS, ret);
505
506 CloseServiceCaptureSo(handle);
507 free(hwCapture);
508 hwCapture = nullptr;
509 }
510 /**
511 * @tc.name test InterfaceLibCtlCapture API via writing normal value of gain and reading gain value.
512 * @tc.number SUB_Audio_InterfaceLibCtlCapture_GainWrite_Read_0001
513 * @tc.desc test InterfaceLibCtlCapture,cmdId is AUDIODRV_CTL_IOCTL_GAIN_WRITE_CAPTURE and
514 * AUDIODRV_CTL_IOCTL_GAIN_READ_CAPTURE.
515 * @tc.author: wangkang
516 */
517 HWTEST_F(AudioLibCaptureTest, SUB_Audio_InterfaceLibCtlCapture_GainWrite_Read_0001, TestSize.Level1)
518 {
519 int32_t ret = -1;
520 float gainValue = 0;
521 float gainThresholdValueMax = 0;
522 float gainThresholdValueMin = 0;
523 struct DevHandle *handle = nullptr;
524 struct AudioHwCapture *hwCapture = nullptr;
525 ret = BindServiceAndHwCapture(hwCapture, BIND_CONTROL.c_str(), ADAPTER_NAME_INTERNAL, handle);
526 ASSERT_EQ(HDF_SUCCESS, ret);
527
528 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_GAINTHRESHOLD_CAPTURE, &hwCapture->captureParam);
529 EXPECT_EQ(HDF_SUCCESS, ret);
530 gainThresholdValueMax = hwCapture->captureParam.captureMode.ctlParam.audioGain.gainMax;
531 gainThresholdValueMin = hwCapture->captureParam.captureMode.ctlParam.audioGain.gainMin;
532 ret = InitHwCaptureMode(hwCapture->captureParam.captureMode);
533 EXPECT_EQ(HDF_SUCCESS, ret);
534
535 hwCapture->captureParam.captureMode.ctlParam.audioGain.gain = gainThresholdValueMax - 1;
536 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_GAIN_WRITE_CAPTURE, &hwCapture->captureParam);
537 EXPECT_EQ(HDF_SUCCESS, ret);
538 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_GAIN_READ_CAPTURE, &hwCapture->captureParam);
539 EXPECT_EQ(HDF_SUCCESS, ret);
540 gainValue = hwCapture->captureParam.captureMode.ctlParam.audioGain.gain;
541 EXPECT_EQ(gainThresholdValueMax - 1, gainValue);
542 hwCapture->captureParam.captureMode.ctlParam.audioGain.gain = gainThresholdValueMin + 1;
543 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_GAIN_WRITE_CAPTURE, &hwCapture->captureParam);
544 EXPECT_EQ(HDF_SUCCESS, ret);
545 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_GAIN_READ_CAPTURE, &hwCapture->captureParam);
546 EXPECT_EQ(HDF_SUCCESS, ret);
547 gainValue = hwCapture->captureParam.captureMode.ctlParam.audioGain.gain;
548 EXPECT_EQ(gainThresholdValueMin + 1, gainValue);
549 hwCapture->captureParam.captureMode.ctlParam.audioGain.gain = 2.3;
550 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_GAIN_WRITE_CAPTURE, &hwCapture->captureParam);
551 EXPECT_EQ(HDF_SUCCESS, ret);
552 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_GAIN_READ_CAPTURE, &hwCapture->captureParam);
553 EXPECT_EQ(HDF_SUCCESS, ret);
554 gainValue = hwCapture->captureParam.captureMode.ctlParam.audioGain.gain;
555 EXPECT_EQ(2, gainValue);
556 CloseServiceCaptureSo(handle);
557 free(hwCapture);
558 hwCapture = nullptr;
559 }
560 /**
561 * @tc.name test InterfaceLibCtlCapture API via writing boundary value of gain and reading gain value.
562 * @tc.number SUB_Audio_InterfaceLibCtlCapture_GainWrite_Read_0002
563 * @tc.desc test InterfaceLibCtlCapture,cmdId is AUDIODRV_CTL_IOCTL_GAIN_WRITE_CAPTURE and
564 * AUDIODRV_CTL_IOCTL_GAIN_READ_CAPTURE.
565 * @tc.author: wangkang
566 */
567 HWTEST_F(AudioLibCaptureTest, SUB_Audio_InterfaceLibCtlCapture_GainWrite_Read_0002, TestSize.Level1)
568 {
569 int32_t ret = -1;
570 struct DevHandle *handle = nullptr;
571 struct AudioHwCapture *hwCapture = nullptr;
572 float gainValue = 0;
573 float gainThresholdValueMax = 0;
574 float gainThresholdValueMin = 0;
575 ret = BindServiceAndHwCapture(hwCapture, BIND_CONTROL.c_str(), ADAPTER_NAME_INTERNAL, handle);
576 ASSERT_EQ(HDF_SUCCESS, ret);
577
578 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_GAINTHRESHOLD_CAPTURE, &hwCapture->captureParam);
579 EXPECT_EQ(HDF_SUCCESS, ret);
580 gainThresholdValueMax = hwCapture->captureParam.captureMode.ctlParam.audioGain.gainMax;
581 gainThresholdValueMin = hwCapture->captureParam.captureMode.ctlParam.audioGain.gainMin;
582 ret = InitHwCaptureMode(hwCapture->captureParam.captureMode);
583 EXPECT_EQ(HDF_SUCCESS, ret);
584
585 hwCapture->captureParam.captureMode.ctlParam.audioGain.gain = gainThresholdValueMax;
586 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_GAIN_WRITE_CAPTURE, &hwCapture->captureParam);
587 EXPECT_EQ(HDF_SUCCESS, ret);
588 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_GAIN_READ_CAPTURE, &hwCapture->captureParam);
589 EXPECT_EQ(HDF_SUCCESS, ret);
590 gainValue = hwCapture->captureParam.captureMode.ctlParam.audioGain.gain;
591 EXPECT_EQ(gainThresholdValueMax, gainValue);
592 hwCapture->captureParam.captureMode.ctlParam.audioGain.gain = gainThresholdValueMin;
593 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_GAIN_WRITE_CAPTURE, &hwCapture->captureParam);
594 EXPECT_EQ(HDF_SUCCESS, ret);
595 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_GAIN_READ_CAPTURE, &hwCapture->captureParam);
596 EXPECT_EQ(HDF_SUCCESS, ret);
597 gainValue = hwCapture->captureParam.captureMode.ctlParam.audioGain.gain;
598 EXPECT_EQ(gainThresholdValueMin, gainValue);
599 CloseServiceCaptureSo(handle);
600 free(hwCapture);
601 hwCapture = nullptr;
602 }
603 /**
604 * @tc.name test InterfaceLibCtlCapture API via writing invalid value of gain.
605 * @tc.number SUB_Audio_InterfaceLibCtlCapture_GainWrite_Read_0003
606 * @tc.desc test InterfaceLibCtlCapture ,return -1,If the threshold is invalid.
607 * @tc.author: wangkang
608 */
609 HWTEST_F(AudioLibCaptureTest, SUB_Audio_InterfaceLibCtlCapture_GainWrite_Read_0003, TestSize.Level1)
610 {
611 int32_t ret = -1;
612 float gainThresholdValueMax = 0;
613 float gainThresholdValueMin = 0;
614 struct AudioHwCapture *hwCapture = nullptr;
615 struct DevHandle *handle = nullptr;
616 ret = BindServiceAndHwCapture(hwCapture, BIND_CONTROL.c_str(), ADAPTER_NAME_INTERNAL, handle);
617 ASSERT_EQ(HDF_SUCCESS, ret);
618
619 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_GAINTHRESHOLD_CAPTURE, &hwCapture->captureParam);
620 EXPECT_EQ(HDF_SUCCESS, ret);
621 gainThresholdValueMax = hwCapture->captureParam.captureMode.ctlParam.audioGain.gainMax;
622 gainThresholdValueMin = hwCapture->captureParam.captureMode.ctlParam.audioGain.gainMin;
623 ret = InitHwCaptureMode(hwCapture->captureParam.captureMode);
624 EXPECT_EQ(HDF_SUCCESS, ret);
625 hwCapture->captureParam.captureMode.ctlParam.audioGain.gain = gainThresholdValueMax + 1;
626 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_GAIN_WRITE_CAPTURE, &hwCapture->captureParam);
627 EXPECT_EQ(HDF_FAILURE, ret);
628 hwCapture->captureParam.captureMode.ctlParam.audioGain.gain = gainThresholdValueMin - 1;
629 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_GAIN_WRITE_CAPTURE, &hwCapture->captureParam);
630 EXPECT_EQ(HDF_FAILURE, ret);
631 CloseServiceCaptureSo(handle);
632 free(hwCapture);
633 hwCapture = nullptr;
634 }
635 /**
636 * @tc.name test InterfaceLibCtlCapture API via writing GetGainthreshold value.
637 * @tc.number SUB_Audio_InterfaceLibCtlCapture_GetGainthresholdRead_0001
638 * @tc.desc test InterfaceLibCtlCapture ,cmdId is AUDIODRV_CTL_IOCTL_GAINTHRESHOLD_CAPTURE(23).
639 * @tc.author: liutian
640 */
641 HWTEST_F(AudioLibCaptureTest, SUB_Audio_InterfaceLibCtlCapture_GetGainthresholdRead_0001, TestSize.Level1)
642 {
643 int32_t ret = -1;
644 float gainThresholdValueMax, gainThresholdValueMin;
645 float expMax = 10;
646 float expMix = 0;
647 struct DevHandle *handle = nullptr;
648 struct AudioHwCapture *hwCapture = nullptr;
649 ret = BindServiceAndHwCapture(hwCapture, BIND_CONTROL.c_str(), ADAPTER_NAME_INTERNAL, handle);
650 ASSERT_EQ(HDF_SUCCESS, ret);
651
652 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_GAINTHRESHOLD_CAPTURE, &hwCapture->captureParam);
653 EXPECT_EQ(HDF_SUCCESS, ret);
654 gainThresholdValueMax = hwCapture->captureParam.captureMode.ctlParam.audioGain.gainMax;
655 gainThresholdValueMin = hwCapture->captureParam.captureMode.ctlParam.audioGain.gainMin;
656 EXPECT_LT(expMax, gainThresholdValueMax);
657 EXPECT_EQ(expMix, gainThresholdValueMin);
658 CloseServiceCaptureSo(handle);
659 free(hwCapture);
660 hwCapture = nullptr;
661 }
662 /**
663 * @tc.name test InterfaceLibCtlCapture API via inputting cmdid invalid.
664 * @tc.number SUB_Audio_InterfaceLibCtlCapture_Abnormal_0001
665 * @tc.desc test InterfaceLibCtlCapture, cmdId is invalid eg 30,so return -1.
666 * @tc.author: liutian
667 */
668 HWTEST_F(AudioLibCaptureTest, SUB_Audio_InterfaceLibCtlCapture_Abnormal_0001, TestSize.Level1)
669 {
670 int32_t ret = -1;
671 struct DevHandle *handle = nullptr;
672 struct AudioHwCapture *hwCapture = nullptr;
673 ret = BindServiceAndHwCapture(hwCapture, BIND_CONTROL.c_str(), ADAPTER_NAME_INTERNAL, handle);
674 ASSERT_EQ(HDF_SUCCESS, ret);
675
676 ret = InterfaceLibCtlCapture(handle, 30, &hwCapture->captureParam);
677 if (ret == 0) {
678 CloseServiceCaptureSo(handle);
679 free(hwCapture);
680 hwCapture = nullptr;
681 ASSERT_EQ(HDF_FAILURE, ret);
682 }
683 EXPECT_EQ(HDF_FAILURE, ret);
684 CloseServiceCaptureSo(handle);
685 free(hwCapture);
686 hwCapture = nullptr;
687 }
688 /**
689 * @tc.name test InterfaceLibCtlCapture API via inputting handleData invalid.
690 * @tc.number SUB_Audio_InterfaceLibCtlCapture_Abnormal_0002
691 * @tc.desc test InterfaceLibCtlCapture, handleData is invalid,so return -1.
692 * @tc.author: liutian
693 */
694 HWTEST_F(AudioLibCaptureTest, SUB_Audio_InterfaceLibCtlCapture_Abnormal_0002, TestSize.Level1)
695 {
696 int32_t ret = -1;
697 struct DevHandle *handle = nullptr;
698 struct AudioHwCaptureParam *handleData = nullptr;
699 handle = BindServiceCaptureSo(BIND_CONTROL.c_str());
700 ASSERT_NE(nullptr, handle);
701 ret = InterfaceLibCtlCapture(handle, AUDIO_DRV_PCM_IOCTL_READ, handleData);
702 EXPECT_EQ(HDF_FAILURE, ret);
703 CloseServiceCaptureSo(handle);
704 }
705 /**
706 * @tc.name test InterfaceLibOutputCapture API via cmdid is AUDIO_DRV_PCM_IOCTL_HW_PARAMS.
707 * @tc.number SUB_Audio_InterfaceLibOutputCapture_HwParams_0001
708 * @tc.desc Test AudioOutputcapture interface,return 0 is call successfully.
709 * @tc.author: liutian
710 */
711 HWTEST_F(AudioLibCaptureTest, SUB_Audio_InterfaceLibOutputCapture_HwParams_0001, TestSize.Level1)
712 {
713 int32_t ret = -1;
714 struct DevHandle *handle = nullptr;
715 struct AudioHwCapture *hwCapture = nullptr;
716 ret = BindServiceAndHwCapture(hwCapture, BIND_CAPTURE.c_str(), ADAPTER_NAME_INTERNAL, handle);
717 ASSERT_EQ(HDF_SUCCESS, ret);
718
719 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTRL_CAPTURE_OPEN, &hwCapture->captureParam);
720 EXPECT_EQ(HDF_SUCCESS, ret);
721 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTL_HW_PARAMS, &hwCapture->captureParam);
722 EXPECT_EQ(HDF_SUCCESS, ret);
723 CloseServiceCaptureSo(handle);
724 free(hwCapture);
725 hwCapture = nullptr;
726 }
727 /**
728 * @tc.name test InterfaceLibOutputCapture API via cmdid is AUDIO_DRV_PCM_IOCTL_PREPARE_CAPTURE.
729 * @tc.number SUB_Audio_InterfaceLib_OutputCapture_Prepare_0001
730 * @tc.desc test InterfaceLibOutputCapture,cmdId is AUDIO_DRV_PCM_IOCTL_PREPARE_CAPTURE.
731 * @tc.author: liutian
732 */
733 HWTEST_F(AudioLibCaptureTest, SUB_Audio_InterfaceLibOutputCapture_Prepare_0001, TestSize.Level1)
734 {
735 int32_t ret = -1;
736 struct AudioHwCapture *hwCapture = nullptr;
737 struct DevHandle *handle = nullptr;
738 ret = BindServiceAndHwCapture(hwCapture, BIND_CAPTURE.c_str(), ADAPTER_NAME_INTERNAL, handle);
739 ASSERT_EQ(HDF_SUCCESS, ret);
740
741 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTRL_CAPTURE_OPEN, &hwCapture->captureParam);
742 EXPECT_EQ(HDF_SUCCESS, ret);
743 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTL_HW_PARAMS, &hwCapture->captureParam);
744 EXPECT_EQ(HDF_SUCCESS, ret);
745 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTL_PREPARE_CAPTURE, &hwCapture->captureParam);
746 EXPECT_EQ(HDF_SUCCESS, ret);
747 CloseServiceCaptureSo(handle);
748 free(hwCapture);
749 hwCapture = nullptr;
750 }
751 /**
752 * @tc.name test InterfaceLibOutputCapture API via cmdid is AUDIO_DRV_PCM_IOCTRL_START_CAPTURE.
753 * @tc.number SUB_Audio_InterfaceLib_OutputCapture_Start_0001
754 * @tc.desc test InterfaceLibOutputCapture,cmdId is AUDIO_DRV_PCM_IOCTRL_START_CAPTURE.
755 * @tc.author: liutian
756 */
757 HWTEST_F(AudioLibCaptureTest, SUB_Audio_InterfaceLibOutputCapture_Start_0001, TestSize.Level1)
758 {
759 struct DevHandle *handle = nullptr;
760 struct AudioHwCapture *hwCapture = nullptr;
761 int32_t ret = -1;
762 ret = BindServiceAndHwCapture(hwCapture, BIND_CAPTURE.c_str(), ADAPTER_NAME_INTERNAL, handle);
763 ASSERT_EQ(HDF_SUCCESS, ret);
764
765 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTRL_CAPTURE_OPEN, &hwCapture->captureParam);
766 EXPECT_EQ(HDF_SUCCESS, ret);
767 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTL_HW_PARAMS, &hwCapture->captureParam);
768 EXPECT_EQ(HDF_SUCCESS, ret);
769 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTL_PREPARE_CAPTURE, &hwCapture->captureParam);
770 EXPECT_EQ(HDF_SUCCESS, ret);
771 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTRL_START_CAPTURE, &hwCapture->captureParam);
772 EXPECT_EQ(HDF_SUCCESS, ret);
773 CloseServiceCaptureSo(handle);
774 free(hwCapture);
775 hwCapture = nullptr;
776 }
777 /**
778 * @tc.name Test AudioOutputcapture API via cmdid is AUDIO_DRV_PCM_IOCTL_READ.
779 and AUDIO_DRV_PCM_IOCTRL_STOP_CAPTURE.
780 * @tc.number SUB_Audio_InterfaceLibOutputCapture_Read_Stop_0001
781 * @tc.desc test InterfaceLibOutputCapture,cmdId is AUDIO_DRV_PCM_IOCTL_READ and AUDIO_DRV_PCM_IOCTRL_STOP_CAPTURE.
782 * @tc.author: liutian
783 */
784 HWTEST_F(AudioLibCaptureTest, SUB_Audio_InterfaceLibOutputCapture_Read_Stop_0001, TestSize.Level1)
785 {
786 int32_t ret = -1;
787 struct DevHandle *handle = nullptr;
788 struct AudioHwCapture *hwCapture = nullptr;
789 ret = BindServiceAndHwCapture(hwCapture, BIND_CAPTURE.c_str(), ADAPTER_NAME_INTERNAL, handle);
790 ASSERT_EQ(HDF_SUCCESS, ret);
791
792 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTRL_CAPTURE_OPEN, &hwCapture->captureParam);
793 EXPECT_EQ(HDF_SUCCESS, ret);
794 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTL_HW_PARAMS, &hwCapture->captureParam);
795 EXPECT_EQ(HDF_SUCCESS, ret);
796 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTL_PREPARE_CAPTURE, &hwCapture->captureParam);
797 EXPECT_EQ(HDF_SUCCESS, ret);
798 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTRL_START_CAPTURE, &hwCapture->captureParam);
799 EXPECT_EQ(HDF_SUCCESS, ret);
800 hwCapture->captureParam.frameCaptureMode.buffer = (char *)calloc(1, 16384);
801 if (hwCapture->captureParam.frameCaptureMode.buffer == nullptr) {
802 CloseServiceCaptureSo(handle);
803 free(hwCapture);
804 hwCapture = nullptr;
805 ASSERT_NE(nullptr, hwCapture);
806 }
807 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTL_READ, &hwCapture->captureParam);
808 EXPECT_EQ(HDF_SUCCESS, ret);
809 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTRL_STOP_CAPTURE, &hwCapture->captureParam);
810 EXPECT_EQ(HDF_SUCCESS, ret);
811 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTRL_CAPTURE_CLOSE, &hwCapture->captureParam);
812 EXPECT_EQ(HDF_SUCCESS, ret);
813 CloseServiceCaptureSo(handle);
814 free(hwCapture->captureParam.frameCaptureMode.buffer);
815 hwCapture->captureParam.frameCaptureMode.buffer = nullptr;
816 free(hwCapture);
817 hwCapture = nullptr;
818 }
819 /**
820 * @tc.name Test AudioOutputcapture API data flow and control flow are serial.
821 * @tc.number SUB_Audio_InterfaceLibOutputCapture_0001
822 * @tc.desc test Audio lib Interface CtlCapture and OutputCapture,Data stream and control stream send successful.
823 * @tc.author: liutian
824 */
825 HWTEST_F(AudioLibCaptureTest, SUB_Audio_InterfaceLibOutputCapture_0001, TestSize.Level1)
826 {
827 struct DevHandle *handle1 = nullptr;
828 struct AudioHwCapture *hwCapture = nullptr;
829 int32_t ret = BindServiceAndHwCapture(hwCapture, BIND_CONTROL.c_str(), ADAPTER_NAME_INTERNAL, handle1);
830 ASSERT_EQ(HDF_SUCCESS, ret);
831 struct DevHandle *handle2 = BindServiceCaptureSo(BIND_CAPTURE.c_str());
832 if (handle2 == nullptr) {
833 CloseServiceCaptureSo(handle1);
834 free(hwCapture);
835 ASSERT_NE(nullptr, handle2);
836 }
837 if (hwCapture != nullptr) {
838 hwCapture->captureParam.captureMode.ctlParam.mute = 0;
839 ret = InterfaceLibCtlCapture(handle1, AUDIODRV_CTL_IOCTL_MUTE_WRITE_CAPTURE, &hwCapture->captureParam);
840 EXPECT_EQ(HDF_SUCCESS, ret);
841 ret = InterfaceLibCtlCapture(handle1, AUDIODRV_CTL_IOCTL_MUTE_READ_CAPTURE, &hwCapture->captureParam);
842 EXPECT_EQ(HDF_SUCCESS, ret);
843 ret = InterfaceLibOutputCapture(handle2, AUDIO_DRV_PCM_IOCTRL_CAPTURE_OPEN, &hwCapture->captureParam);
844 EXPECT_EQ(HDF_SUCCESS, ret);
845 ret = InterfaceLibOutputCapture(handle2, AUDIO_DRV_PCM_IOCTL_HW_PARAMS, &hwCapture->captureParam);
846 EXPECT_EQ(HDF_SUCCESS, ret);
847 ret = InterfaceLibOutputCapture(handle2, AUDIO_DRV_PCM_IOCTL_PREPARE_CAPTURE, &hwCapture->captureParam);
848 EXPECT_EQ(HDF_SUCCESS, ret);
849 ret = InterfaceLibOutputCapture(handle2, AUDIO_DRV_PCM_IOCTRL_START_CAPTURE, &hwCapture->captureParam);
850 EXPECT_EQ(HDF_SUCCESS, ret);
851 hwCapture->captureParam.frameCaptureMode.buffer = (char *)calloc(1, 16384);
852 if (hwCapture->captureParam.frameCaptureMode.buffer == nullptr) {
853 CloseServiceCaptureSo(handle1);
854 CloseServiceCaptureSo(handle2);
855 free(hwCapture);
856 hwCapture = nullptr;
857 ASSERT_NE(nullptr, hwCapture);
858 }
859 ret = InterfaceLibOutputCapture(handle2, AUDIO_DRV_PCM_IOCTL_READ, &hwCapture->captureParam);
860 EXPECT_EQ(HDF_SUCCESS, ret);
861 ret = InterfaceLibOutputCapture(handle2, AUDIO_DRV_PCM_IOCTRL_STOP_CAPTURE, &hwCapture->captureParam);
862 EXPECT_EQ(HDF_SUCCESS, ret);
863 ret = InterfaceLibOutputCapture(handle2, AUDIO_DRV_PCM_IOCTRL_CAPTURE_CLOSE, &hwCapture->captureParam);
864 EXPECT_EQ(HDF_SUCCESS, ret);
865 if (hwCapture->captureParam.frameCaptureMode.buffer != nullptr) {
866 free(hwCapture->captureParam.frameCaptureMode.buffer);
867 }
868 free(hwCapture);
869 }
870 CloseServiceCaptureSo(handle1);
871 CloseServiceCaptureSo(handle2);
872 }
873 /**
874 * @tc.name test InterfaceLibOutputCapture API via pause.
875 * @tc.number SUB_Audio_InterfaceLibctlcapture_Pause_0001
876 * @tc.desc test InterfaceLibOutputCapture,cmdId is AUDIODRV_CTL_IOCTL_PAUSE_WRITE.
877 * @tc.author: wangkang
878 */
879 HWTEST_F(AudioLibCaptureTest, SUB_Audio_InterfaceLibOutputCapture_Pause_0001, TestSize.Level1)
880 {
881 int32_t ret = -1;
882 struct DevHandle *handle = {};
883 struct AudioHwCapture *hwCapture = nullptr;
884 ret = BindServiceAndHwCapture(hwCapture, BIND_CAPTURE.c_str(), ADAPTER_NAME_INTERNAL, handle);
885 ASSERT_EQ(HDF_SUCCESS, ret);
886 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTRL_CAPTURE_OPEN, &hwCapture->captureParam);
887 EXPECT_EQ(HDF_SUCCESS, ret);
888 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTL_HW_PARAMS, &hwCapture->captureParam);
889 EXPECT_EQ(HDF_SUCCESS, ret);
890 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTL_PREPARE_CAPTURE, &hwCapture->captureParam);
891 EXPECT_EQ(HDF_SUCCESS, ret);
892 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTRL_START_CAPTURE, &hwCapture->captureParam);
893 EXPECT_EQ(HDF_SUCCESS, ret);
894 hwCapture->captureParam.captureMode.ctlParam.pause = 1;
895 ret = InterfaceLibOutputCapture(handle, AUDIODRV_CTL_IOCTL_PAUSE_WRITE_CAPTURE, &hwCapture->captureParam);
896 EXPECT_EQ(HDF_SUCCESS, ret);
897 CloseServiceCaptureSo(handle);
898 free(hwCapture);
899 hwCapture = nullptr;
900 }
901 /**
902 * @tc.name test InterfaceLibOutputCapture API via resume.
903 * @tc.number SUB_Audio_InterfaceLibctlcapture_Resume_0001
904 * @tc.desc test InterfaceLibOutputCapture,cmdId is AUDIODRV_CTL_IOCTL_PAUSE_WRITE.
905 * @tc.author: wangkang
906 */
907 HWTEST_F(AudioLibCaptureTest, SUB_Audio_InterfaceLibOutputCapture_Resume_0001, TestSize.Level1)
908 {
909 int32_t ret = -1;
910 struct AudioHwCapture *hwCapture = nullptr;
911 struct DevHandle *handle = {};
912 ret = BindServiceAndHwCapture(hwCapture, BIND_CAPTURE.c_str(), ADAPTER_NAME_INTERNAL, handle);
913 ASSERT_EQ(HDF_SUCCESS, ret);
914 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTRL_CAPTURE_OPEN, &hwCapture->captureParam);
915 EXPECT_EQ(HDF_SUCCESS, ret);
916 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTL_HW_PARAMS, &hwCapture->captureParam);
917 EXPECT_EQ(HDF_SUCCESS, ret);
918 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTL_PREPARE_CAPTURE, &hwCapture->captureParam);
919 EXPECT_EQ(HDF_SUCCESS, ret);
920 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTRL_START_CAPTURE, &hwCapture->captureParam);
921 EXPECT_EQ(HDF_SUCCESS, ret);
922 hwCapture->captureParam.captureMode.ctlParam.pause = 0;
923 ret = InterfaceLibOutputCapture(handle, AUDIODRV_CTL_IOCTL_PAUSE_WRITE_CAPTURE, &hwCapture->captureParam);
924 EXPECT_EQ(HDF_SUCCESS, ret);
925 CloseServiceCaptureSo(handle);
926 free(hwCapture);
927 hwCapture = nullptr;
928 }
929 /**
930 * @tc.name Test InterfaceLibOutputCapture API via setting the cmdId(30) is invalid
931 * @tc.number SUB_Audio_InterfaceLibOutputCapture_Abnormal_0001
932 * @tc.desc test OutputCapture interface, return -1 if the cmdId is invalid.
933 * @tc.author: liutian
934 */
935 HWTEST_F(AudioLibCaptureTest, SUB_Audio_InterfaceLibOutputCapture_Abnormal_0001, TestSize.Level1)
936 {
937 int32_t ret = -1;
938 struct DevHandle *handle = nullptr;
939 struct AudioHwCapture *hwCapture = nullptr;
940 ret = BindServiceAndHwCapture(hwCapture, BIND_CAPTURE.c_str(), ADAPTER_NAME_INTERNAL, handle);
941 ASSERT_EQ(HDF_SUCCESS, ret);
942
943 ret = InterfaceLibOutputCapture(handle, 30, &hwCapture->captureParam);
944 EXPECT_EQ(HDF_FAILURE, ret);
945 CloseServiceCaptureSo(handle);
946 free(hwCapture);
947 hwCapture = nullptr;
948 }
949 /**
950 * @tc.name Test Outputcapture API via setting the incoming parameter handleData is empty
951 * @tc.number SUB_Audio_InterfaceLibOutputCapture_Abnormal_0002
952 * @tc.desc Test Outputcapture interface, return -1 if the incoming parameter handleData is empty.
953 * @tc.author: liutian
954 */
955 HWTEST_F(AudioLibCaptureTest, SUB_Audio_InterfaceLibOutputCapture_Abnormal_0002, TestSize.Level1)
956 {
957 int32_t ret = -1;
958 struct DevHandle *handle = nullptr;
959 struct AudioHwCaptureParam *handleData = nullptr;
960 struct AudioHwCapture *hwCapture = nullptr;
961 ret = BindServiceAndHwCapture(hwCapture, BIND_CAPTURE.c_str(), ADAPTER_NAME_INTERNAL, handle);
962 ASSERT_EQ(HDF_SUCCESS, ret);
963
964 ret = InterfaceLibOutputCapture(handle, AUDIO_DRV_PCM_IOCTL_READ, handleData);
965 EXPECT_EQ(HDF_FAILURE, ret);
966 CloseServiceCaptureSo(handle);
967 free(hwCapture);
968 hwCapture = nullptr;
969 }
970 }