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