1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "audio_lib_common.h"
17 #include "audio_libcapture_hardwaredependence_test.h"
18
19 using namespace std;
20 using namespace testing::ext;
21 using namespace OHOS::Audio;
22
23 namespace {
24 const string BIND_CONTROL = "control";
25
26 #ifdef PRODUCT_RK3568
27 constexpr int MAX_VOLUME = 255;
28 constexpr int MIN_VOLUME = 0;
29 constexpr int BELOW_MAX_VOLUME = 254;
30 constexpr int OVER_MIN_VOLUME = 1;
31 #else
32 constexpr int MAX_VOLUME = 87;
33 constexpr int MIN_VOLUME = 0;
34 constexpr int BELOW_MAX_VOLUME = 86;
35 constexpr int OVER_MIN_VOLUME = 1;
36 #endif
37 constexpr float MAX_GAIN = 15;
38 constexpr float MIN_GAIN = 0;
39 class AudioLibCaptureHardwareDependenceTest : public testing::Test {
40 public:
41 static void SetUpTestCase(void);
42 static void TearDownTestCase(void);
43 void SetUp();
44 void TearDown();
45 static struct DevHandle *(*BindServiceCaptureSo)(const char *serverName);
46 static int32_t (*InterfaceLibOutputCapture)(struct DevHandle *handle, int cmdId,
47 struct AudioHwCaptureParam *handleData);
48 static int32_t (*InterfaceLibCtlCapture)(struct DevHandle *handle, int cmdId,
49 struct AudioHwCaptureParam *handleData);
50 static void (*CloseServiceCaptureSo)(struct DevHandle *handle);
51 static void *ptrHandle;
52 int32_t BindServiceAndHwCapture(struct AudioHwCapture *&hwCapture, const std::string BindName,
53 const std::string adapterNameCase, struct DevHandle *&handle) const;
54 };
55
56 struct DevHandle *(*AudioLibCaptureHardwareDependenceTest::BindServiceCaptureSo)(const char *serverName) = nullptr;
57 int32_t (*AudioLibCaptureHardwareDependenceTest::InterfaceLibOutputCapture)(struct DevHandle *handle, int cmdId,
58 struct AudioHwCaptureParam *) = nullptr;
59 int32_t (*AudioLibCaptureHardwareDependenceTest::InterfaceLibCtlCapture)(struct DevHandle *handle, int cmdId,
60 struct AudioHwCaptureParam *handleData) = nullptr;
61 void (*AudioLibCaptureHardwareDependenceTest::CloseServiceCaptureSo)(struct DevHandle *handle) = nullptr;
62 void *AudioLibCaptureHardwareDependenceTest::ptrHandle = nullptr;
63
SetUpTestCase(void)64 void AudioLibCaptureHardwareDependenceTest::SetUpTestCase(void)
65 {
66 char resolvedPath[] = HDF_LIBRARY_FULL_PATH("libhdi_audio_interface_lib_capture");
67 ptrHandle = dlopen(resolvedPath, RTLD_LAZY);
68 if (ptrHandle == nullptr) {
69 return;
70 }
71 BindServiceCaptureSo = reinterpret_cast<struct DevHandle* (*)(const char *)>(dlsym(ptrHandle,
72 "AudioBindServiceCapture"));
73 InterfaceLibOutputCapture = (int32_t (*)(struct DevHandle *handle, int cmdId,
74 struct AudioHwCaptureParam *handleData))dlsym(ptrHandle, "AudioInterfaceLibOutputCapture");
75 InterfaceLibCtlCapture = (int32_t (*)(struct DevHandle *handle, int cmdId,
76 struct AudioHwCaptureParam *handleData))dlsym(ptrHandle, "AudioInterfaceLibCtlCapture");
77 CloseServiceCaptureSo = (void (*)(struct DevHandle *))dlsym(ptrHandle, "AudioCloseServiceCapture");
78 if (BindServiceCaptureSo == nullptr || CloseServiceCaptureSo == nullptr ||
79 InterfaceLibCtlCapture == nullptr || InterfaceLibOutputCapture == nullptr) {
80 dlclose(ptrHandle);
81 return;
82 }
83 }
84
TearDownTestCase(void)85 void AudioLibCaptureHardwareDependenceTest::TearDownTestCase(void)
86 {
87 if (BindServiceCaptureSo != nullptr) {
88 BindServiceCaptureSo = nullptr;
89 }
90 if (CloseServiceCaptureSo != nullptr) {
91 CloseServiceCaptureSo = nullptr;
92 }
93 if (InterfaceLibCtlCapture != nullptr) {
94 InterfaceLibCtlCapture = nullptr;
95 }
96 if (InterfaceLibOutputCapture != nullptr) {
97 InterfaceLibOutputCapture = nullptr;
98 }
99 if (ptrHandle != nullptr) {
100 dlclose(ptrHandle);
101 ptrHandle = nullptr;
102 }
103 }
104
SetUp(void)105 void AudioLibCaptureHardwareDependenceTest::SetUp(void) {}
106
TearDown(void)107 void AudioLibCaptureHardwareDependenceTest::TearDown(void) {}
108
BindServiceAndHwCapture(struct AudioHwCapture * & hwCapture,const std::string BindName,const std::string adapterNameCase,struct DevHandle * & handle) const109 int32_t AudioLibCaptureHardwareDependenceTest::BindServiceAndHwCapture(struct AudioHwCapture *&hwCapture,
110 const std::string BindName, const std::string adapterNameCase, struct DevHandle *&handle) const
111 {
112 int32_t ret = HDF_FAILURE;
113 handle = BindServiceCaptureSo(BindName.c_str());
114 if (handle == nullptr) {
115 return HDF_FAILURE;
116 }
117 hwCapture = static_cast<struct AudioHwCapture *>(calloc(1, sizeof(*hwCapture)));
118 if (hwCapture == nullptr) {
119 CloseServiceCaptureSo(handle);
120 return HDF_FAILURE;
121 }
122 ret = InitHwCapture(hwCapture, adapterNameCase);
123 if (ret != HDF_SUCCESS) {
124 free(hwCapture);
125 hwCapture = nullptr;
126 CloseServiceCaptureSo(handle);
127 return HDF_FAILURE;
128 }
129 return HDF_SUCCESS;
130 }
131 /**
132 * @tc.name AudioInterfaceLibCtlCaptureVolumeWriteRead_001
133 * @tc.desc test InterfaceLibCtlCapture ,cmdId is AUDIODRV_CTL_IOCTL_ELEM_WRITE_CAPTURE and
134 * AUDIODRV_CTL_IOCTL_ELEM_READ_CAPTURE.
135 * @tc.type: FUNC
136 */
137 HWTEST_F(AudioLibCaptureHardwareDependenceTest, AudioInterfaceLibCtlCaptureVolumeWriteRead_001, TestSize.Level1)
138 {
139 int32_t ret = HDF_FAILURE;
140 float volumeValue;
141 float volumeThresholdValueMax = 0;
142 float volumeThresholdValueMin = 0;
143 struct DevHandle *handle = nullptr;
144 struct AudioHwCapture *hwCapture = nullptr;
145 ret = BindServiceAndHwCapture(hwCapture, BIND_CONTROL.c_str(), ADAPTER_NAME, handle);
146 ASSERT_EQ(HDF_SUCCESS, ret);
147
148 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_VOL_THRESHOLD_CAPTURE, &hwCapture->captureParam);
149 EXPECT_EQ(HDF_SUCCESS, ret);
150 volumeThresholdValueMax = hwCapture->captureParam.captureMode.ctlParam.volThreshold.volMax;
151 volumeThresholdValueMin = hwCapture->captureParam.captureMode.ctlParam.volThreshold.volMin;
152
153 hwCapture->captureParam.captureMode.ctlParam.volume = volumeThresholdValueMax - 1;
154 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_ELEM_WRITE_CAPTURE, &hwCapture->captureParam);
155 EXPECT_EQ(HDF_SUCCESS, ret);
156 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_ELEM_READ_CAPTURE, &hwCapture->captureParam);
157 EXPECT_EQ(HDF_SUCCESS, ret);
158 volumeValue = hwCapture->captureParam.captureMode.ctlParam.volume;
159 EXPECT_EQ(BELOW_MAX_VOLUME, volumeValue);
160
161 hwCapture->captureParam.captureMode.ctlParam.volume = volumeThresholdValueMin + 1;
162 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_ELEM_WRITE_CAPTURE, &hwCapture->captureParam);
163 EXPECT_EQ(HDF_SUCCESS, ret);
164 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_ELEM_READ_CAPTURE, &hwCapture->captureParam);
165 EXPECT_EQ(HDF_SUCCESS, ret);
166 volumeValue = hwCapture->captureParam.captureMode.ctlParam.volume;
167 EXPECT_EQ(OVER_MIN_VOLUME, volumeValue);
168
169 free(hwCapture);
170 hwCapture = nullptr;
171 CloseServiceCaptureSo(handle);
172 }
173 /**
174 * @tc.name AudioInterfaceLibCtlCaptureVolumeWriteRead_002
175 * @tc.desc test InterfaceLibCtlCapture ,cmdId is AUDIODRV_CTL_IOCTL_ELEM_WRITE_CAPTURE and
176 * AUDIODRV_CTL_IOCTL_ELEM_READ_CAPTURE.
177 * @tc.type: FUNC
178 */
179 HWTEST_F(AudioLibCaptureHardwareDependenceTest, AudioInterfaceLibCtlCaptureVolumeWriteRead_002, TestSize.Level1)
180 {
181 int32_t ret = HDF_FAILURE;
182 struct DevHandle *handle = nullptr;
183 struct AudioHwCapture *hwCapture = nullptr;
184 float volumeValue = 0;
185 float volumeThresholdValueMax = 0;
186 float volumeThresholdValueMin = 0;
187 ret = BindServiceAndHwCapture(hwCapture, BIND_CONTROL.c_str(), ADAPTER_NAME, handle);
188 ASSERT_EQ(HDF_SUCCESS, ret);
189
190 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_VOL_THRESHOLD_CAPTURE, &hwCapture->captureParam);
191 EXPECT_EQ(HDF_SUCCESS, ret);
192 volumeThresholdValueMax = hwCapture->captureParam.captureMode.ctlParam.volThreshold.volMax;
193 volumeThresholdValueMin = hwCapture->captureParam.captureMode.ctlParam.volThreshold.volMin;
194
195 hwCapture->captureParam.captureMode.ctlParam.volume = volumeThresholdValueMin;
196 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_ELEM_WRITE_CAPTURE, &hwCapture->captureParam);
197 EXPECT_EQ(HDF_SUCCESS, ret);
198 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_ELEM_READ_CAPTURE, &hwCapture->captureParam);
199 EXPECT_EQ(HDF_SUCCESS, ret);
200 volumeValue = hwCapture->captureParam.captureMode.ctlParam.volume;
201 EXPECT_EQ(MIN_VOLUME, volumeValue);
202
203 hwCapture->captureParam.captureMode.ctlParam.volume = volumeThresholdValueMax;
204 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_ELEM_WRITE_CAPTURE, &hwCapture->captureParam);
205 EXPECT_EQ(HDF_SUCCESS, ret);
206 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_ELEM_READ_CAPTURE, &hwCapture->captureParam);
207 EXPECT_EQ(HDF_SUCCESS, ret);
208 volumeValue = hwCapture->captureParam.captureMode.ctlParam.volume;
209 EXPECT_EQ(MAX_VOLUME, volumeValue);
210
211 free(hwCapture);
212 hwCapture = nullptr;
213 CloseServiceCaptureSo(handle);
214 }
215 /**
216 * @tc.name AudioInterfaceLibCtlCaptureVolumeWriteRead_003
217 * @tc.desc test InterfaceLibCtlCapture ,cmdId is AUDIODRV_CTL_IOCTL_ELEM_WRITE_CAPTURE and
218 * AUDIODRV_CTL_IOCTL_ELEM_READ_CAPTURE.
219 * @tc.type: FUNC
220 */
221 HWTEST_F(AudioLibCaptureHardwareDependenceTest, AudioInterfaceLibCtlCaptureVolumeWriteRead_003, TestSize.Level1)
222 {
223 int32_t ret = HDF_FAILURE;
224 float volumeThresholdValueMax = 0;
225 struct AudioHwCapture *hwCapture = nullptr;
226 float volumeThresholdValueMin = 0;
227 struct DevHandle *handle = nullptr;
228 ret = BindServiceAndHwCapture(hwCapture, BIND_CONTROL.c_str(), ADAPTER_NAME, handle);
229 ASSERT_EQ(HDF_SUCCESS, ret);
230
231 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_VOL_THRESHOLD_CAPTURE, &hwCapture->captureParam);
232 EXPECT_EQ(HDF_SUCCESS, ret);
233 volumeThresholdValueMax = hwCapture->captureParam.captureMode.ctlParam.volThreshold.volMax;
234 volumeThresholdValueMin = hwCapture->captureParam.captureMode.ctlParam.volThreshold.volMin;
235
236 hwCapture->captureParam.captureMode.ctlParam.volume = volumeThresholdValueMax + 1;
237 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_ELEM_WRITE_CAPTURE, &hwCapture->captureParam);
238 EXPECT_EQ(HDF_FAILURE, ret);
239 hwCapture->captureParam.captureMode.ctlParam.volume = volumeThresholdValueMin - 1;
240 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_ELEM_WRITE_CAPTURE, &hwCapture->captureParam);
241 EXPECT_EQ(HDF_FAILURE, ret);
242 free(hwCapture);
243 hwCapture = nullptr;
244 CloseServiceCaptureSo(handle);
245 }
246 /**
247 * @tc.name AudioInterfaceLibCtlCaptureGetVolthresholdRead_001
248 * @tc.desc test InterfaceLibCtlCapture ,cmdId is AUDIODRV_CTL_IOCTL_VOL_THRESHOLD_CAPTURE.
249 * @tc.type: FUNC
250 */
251 HWTEST_F(AudioLibCaptureHardwareDependenceTest, AudioInterfaceLibCtlCaptureGetVolthresholdRead_001,
252 TestSize.Level1)
253 {
254 int32_t ret = HDF_FAILURE;
255 float volumeThresholdValueMax = 0;
256 float volumeThresholdValueMin = 0;
257 struct DevHandle *handle = nullptr;
258 struct AudioHwCapture *hwCapture = nullptr;
259 ret = BindServiceAndHwCapture(hwCapture, BIND_CONTROL.c_str(), ADAPTER_NAME, handle);
260 ASSERT_EQ(HDF_SUCCESS, ret);
261
262 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_VOL_THRESHOLD_CAPTURE, &hwCapture->captureParam);
263 EXPECT_EQ(HDF_SUCCESS, ret);
264 volumeThresholdValueMax = hwCapture->captureParam.captureMode.ctlParam.volThreshold.volMax;
265 volumeThresholdValueMin = hwCapture->captureParam.captureMode.ctlParam.volThreshold.volMin;
266 EXPECT_EQ(MAX_VOLUME, volumeThresholdValueMax);
267 EXPECT_EQ(MIN_VOLUME, volumeThresholdValueMin);
268 CloseServiceCaptureSo(handle);
269 free(hwCapture);
270 hwCapture = nullptr;
271 }
272 /**
273 * @tc.name AudioInterfaceLibCtlCaptureSelectScene_001
274 * @tc.desc test InterfaceLibCtlCapture,cmdId is AUDIODRV_CTL_IOCTL_SCENESELECT_CAPTURE.
275 * @tc.type: FUNC
276 */
277 HWTEST_F(AudioLibCaptureHardwareDependenceTest, AudioInterfaceLibCtlCaptureSelectScene_001, TestSize.Level1)
278 {
279 int32_t ret = HDF_FAILURE;
280 struct DevHandle* handle = nullptr;
281 struct AudioHwCapture *hwCapture = nullptr;
282 ret = BindServiceAndHwCapture(hwCapture, BIND_CONTROL.c_str(), ADAPTER_NAME, handle);
283 ASSERT_EQ(HDF_SUCCESS, ret);
284
285 struct AudioSceneDescriptor scene = {
286 .scene.id = 0,
287 .desc.pins = PIN_IN_HS_MIC,
288 };
289 hwCapture->captureParam.captureMode.hwInfo.pathSelect.deviceInfo.deviceNum = 1;
290 ret = strcpy_s(hwCapture->captureParam.captureMode.hwInfo.pathSelect.deviceInfo.deviceSwitchs[0].deviceSwitch,
291 PATHPLAN_COUNT, "LPGA MIC Switch");
292 hwCapture->captureParam.captureMode.hwInfo.pathSelect.deviceInfo.deviceSwitchs[0].value = 0;
293 hwCapture->captureParam.frameCaptureMode.attrs.type = (enum AudioCategory)(scene.scene.id);
294 hwCapture->captureParam.captureMode.hwInfo.deviceDescript.pins = scene.desc.pins;
295
296 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_SCENESELECT_CAPTURE, &hwCapture->captureParam);
297 EXPECT_EQ(HDF_SUCCESS, ret);
298
299 CloseServiceCaptureSo(handle);
300 free(hwCapture);
301 hwCapture = nullptr;
302 }
303 /**
304 * @tc.name AudioInterfaceLibCtlCaptureGainWriteRead_001
305 * @tc.desc test InterfaceLibCtlCapture,cmdId is AUDIODRV_CTL_IOCTL_GAIN_WRITE_CAPTURE and
306 * AUDIODRV_CTL_IOCTL_GAIN_READ_CAPTURE.
307 * @tc.type: FUNC
308 */
309 HWTEST_F(AudioLibCaptureHardwareDependenceTest, AudioInterfaceLibCtlCaptureGainWriteRead_001, TestSize.Level1)
310 {
311 int32_t ret = HDF_FAILURE;
312 float gainValue = 0;
313 float gainThresholdValueMax = 0;
314 float gainThresholdValueMin = 0;
315 struct DevHandle *handle = nullptr;
316 struct AudioHwCapture *hwCapture = nullptr;
317 ret = BindServiceAndHwCapture(hwCapture, BIND_CONTROL.c_str(), ADAPTER_NAME, handle);
318 ASSERT_EQ(HDF_SUCCESS, ret);
319
320 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_GAINTHRESHOLD_CAPTURE, &hwCapture->captureParam);
321 EXPECT_EQ(HDF_SUCCESS, ret);
322 gainThresholdValueMax = hwCapture->captureParam.captureMode.ctlParam.audioGain.gainMax;
323 gainThresholdValueMin = hwCapture->captureParam.captureMode.ctlParam.audioGain.gainMin;
324 ret = InitHwCaptureMode(hwCapture->captureParam.captureMode);
325 EXPECT_EQ(HDF_SUCCESS, ret);
326
327 hwCapture->captureParam.captureMode.ctlParam.audioGain.gain = gainThresholdValueMax - 1;
328 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_GAIN_WRITE_CAPTURE, &hwCapture->captureParam);
329 EXPECT_EQ(HDF_SUCCESS, ret);
330 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_GAIN_READ_CAPTURE, &hwCapture->captureParam);
331 EXPECT_EQ(HDF_SUCCESS, ret);
332 gainValue = hwCapture->captureParam.captureMode.ctlParam.audioGain.gain;
333 EXPECT_EQ(gainThresholdValueMax - 1, gainValue);
334 hwCapture->captureParam.captureMode.ctlParam.audioGain.gain = gainThresholdValueMin + 1;
335 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_GAIN_WRITE_CAPTURE, &hwCapture->captureParam);
336 EXPECT_EQ(HDF_SUCCESS, ret);
337 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_GAIN_READ_CAPTURE, &hwCapture->captureParam);
338 EXPECT_EQ(HDF_SUCCESS, ret);
339 gainValue = hwCapture->captureParam.captureMode.ctlParam.audioGain.gain;
340 EXPECT_EQ(gainThresholdValueMin + 1, gainValue);
341 hwCapture->captureParam.captureMode.ctlParam.audioGain.gain = 2.3;
342 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_GAIN_WRITE_CAPTURE, &hwCapture->captureParam);
343 EXPECT_EQ(HDF_SUCCESS, ret);
344 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_GAIN_READ_CAPTURE, &hwCapture->captureParam);
345 EXPECT_EQ(HDF_SUCCESS, ret);
346 gainValue = hwCapture->captureParam.captureMode.ctlParam.audioGain.gain;
347 EXPECT_EQ(2, gainValue);
348 CloseServiceCaptureSo(handle);
349 free(hwCapture);
350 hwCapture = nullptr;
351 }
352 /**
353 * @tc.name AudioInterfaceLibCtlCaptureGainWriteRead_002
354 * @tc.desc test InterfaceLibCtlCapture,cmdId is AUDIODRV_CTL_IOCTL_GAIN_WRITE_CAPTURE and
355 * AUDIODRV_CTL_IOCTL_GAIN_READ_CAPTURE.
356 * @tc.type: FUNC
357 */
358 HWTEST_F(AudioLibCaptureHardwareDependenceTest, AudioInterfaceLibCtlCaptureGainWriteRead_002, TestSize.Level1)
359 {
360 int32_t ret = HDF_FAILURE;
361 struct DevHandle *handle = nullptr;
362 struct AudioHwCapture *hwCapture = nullptr;
363 float gainValue = 0;
364 float gainThresholdValueMax = 0;
365 float gainThresholdValueMin = 0;
366 ret = BindServiceAndHwCapture(hwCapture, BIND_CONTROL.c_str(), ADAPTER_NAME, handle);
367 ASSERT_EQ(HDF_SUCCESS, ret);
368
369 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_GAINTHRESHOLD_CAPTURE, &hwCapture->captureParam);
370 EXPECT_EQ(HDF_SUCCESS, ret);
371 gainThresholdValueMax = hwCapture->captureParam.captureMode.ctlParam.audioGain.gainMax;
372 gainThresholdValueMin = hwCapture->captureParam.captureMode.ctlParam.audioGain.gainMin;
373 ret = InitHwCaptureMode(hwCapture->captureParam.captureMode);
374 EXPECT_EQ(HDF_SUCCESS, ret);
375
376 hwCapture->captureParam.captureMode.ctlParam.audioGain.gain = gainThresholdValueMax;
377 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_GAIN_WRITE_CAPTURE, &hwCapture->captureParam);
378 EXPECT_EQ(HDF_SUCCESS, ret);
379 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_GAIN_READ_CAPTURE, &hwCapture->captureParam);
380 EXPECT_EQ(HDF_SUCCESS, ret);
381 gainValue = hwCapture->captureParam.captureMode.ctlParam.audioGain.gain;
382 EXPECT_EQ(gainThresholdValueMax, gainValue);
383 hwCapture->captureParam.captureMode.ctlParam.audioGain.gain = gainThresholdValueMin;
384 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_GAIN_WRITE_CAPTURE, &hwCapture->captureParam);
385 EXPECT_EQ(HDF_SUCCESS, ret);
386 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_GAIN_READ_CAPTURE, &hwCapture->captureParam);
387 EXPECT_EQ(HDF_SUCCESS, ret);
388 gainValue = hwCapture->captureParam.captureMode.ctlParam.audioGain.gain;
389 EXPECT_EQ(gainThresholdValueMin, gainValue);
390 CloseServiceCaptureSo(handle);
391 free(hwCapture);
392 hwCapture = nullptr;
393 }
394 /**
395 * @tc.name AudioInterfaceLibCtlCaptureGainWriteRead_003
396 * @tc.desc test InterfaceLibCtlCapture ,return -1,If the threshold is invalid.
397 * @tc.type: FUNC
398 */
399 HWTEST_F(AudioLibCaptureHardwareDependenceTest, AudioInterfaceLibCtlCaptureGainWriteRead_003, TestSize.Level1)
400 {
401 int32_t ret = HDF_FAILURE;
402 float gainThresholdValueMax = 0;
403 float gainThresholdValueMin = 0;
404 struct AudioHwCapture *hwCapture = nullptr;
405 struct DevHandle *handle = nullptr;
406 ret = BindServiceAndHwCapture(hwCapture, BIND_CONTROL.c_str(), ADAPTER_NAME, handle);
407 ASSERT_EQ(HDF_SUCCESS, ret);
408
409 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_GAINTHRESHOLD_CAPTURE, &hwCapture->captureParam);
410 EXPECT_EQ(HDF_SUCCESS, ret);
411 gainThresholdValueMax = hwCapture->captureParam.captureMode.ctlParam.audioGain.gainMax;
412 gainThresholdValueMin = hwCapture->captureParam.captureMode.ctlParam.audioGain.gainMin;
413 ret = InitHwCaptureMode(hwCapture->captureParam.captureMode);
414 EXPECT_EQ(HDF_SUCCESS, ret);
415 hwCapture->captureParam.captureMode.ctlParam.audioGain.gain = gainThresholdValueMax + 1;
416 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_GAIN_WRITE_CAPTURE, &hwCapture->captureParam);
417 EXPECT_EQ(HDF_FAILURE, ret);
418 hwCapture->captureParam.captureMode.ctlParam.audioGain.gain = gainThresholdValueMin - 1;
419 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_GAIN_WRITE_CAPTURE, &hwCapture->captureParam);
420 EXPECT_EQ(HDF_FAILURE, ret);
421 CloseServiceCaptureSo(handle);
422 free(hwCapture);
423 hwCapture = nullptr;
424 }
425 /**
426 * @tc.name AudioInterfaceLibCtlCaptureGetGainthresholdRead_001
427 * @tc.desc test InterfaceLibCtlCapture ,cmdId is AUDIODRV_CTL_IOCTL_GAINTHRESHOLD_CAPTURE(23).
428 * @tc.type: FUNC
429 */
430 HWTEST_F(AudioLibCaptureHardwareDependenceTest, AudioInterfaceLibCtlCaptureGetGainthresholdRead_001,
431 TestSize.Level1)
432 {
433 int32_t ret = HDF_FAILURE;
434 float gainThresholdValueMax, gainThresholdValueMin;
435 struct DevHandle *handle = nullptr;
436 struct AudioHwCapture *hwCapture = nullptr;
437 ret = BindServiceAndHwCapture(hwCapture, BIND_CONTROL.c_str(), ADAPTER_NAME, handle);
438 ASSERT_EQ(HDF_SUCCESS, ret);
439
440 ret = InterfaceLibCtlCapture(handle, AUDIODRV_CTL_IOCTL_GAINTHRESHOLD_CAPTURE, &hwCapture->captureParam);
441 EXPECT_EQ(HDF_SUCCESS, ret);
442 gainThresholdValueMax = hwCapture->captureParam.captureMode.ctlParam.audioGain.gainMax;
443 gainThresholdValueMin = hwCapture->captureParam.captureMode.ctlParam.audioGain.gainMin;
444 EXPECT_EQ(MAX_GAIN, gainThresholdValueMax);
445 EXPECT_EQ(MIN_GAIN, gainThresholdValueMin);
446 CloseServiceCaptureSo(handle);
447 free(hwCapture);
448 hwCapture = nullptr;
449 }
450 }
451