• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 the delayTime of audio playback interface.
21  *
22  * @since 1.0
23  * @version 1.0
24  */
25 
26 /**
27  * @file audio_hdi_common.h
28  *
29  * @brief Declares APIs for operations related to the audio delayTime.
30  *
31  * @since 1.0
32  * @version 1.0
33  */
34 #include <benchmark/benchmark.h>
35 #include <string>
36 #include <vector>
37 #include "audio_hdi_common.h"
38 #include "audio_hdirender_performace_test.h"
39 
40 using namespace std;
41 using namespace testing::ext;
42 using namespace OHOS::Audio;
43 namespace {
44 class AudioHdiRenderBenchmarkTest : public benchmark::Fixture {
45 public:
46     void SetUp(const ::benchmark::State &state);
47     void TearDown(const ::benchmark::State &state);
48     static TestAudioManager *(*GetAudioManager)();
49     static void *handleSo;
50 };
51 
52 TestAudioManager *(*AudioHdiRenderBenchmarkTest::GetAudioManager)() = nullptr;
53 void *AudioHdiRenderBenchmarkTest::handleSo = nullptr;
54 
SetUp(const::benchmark::State & state)55 void AudioHdiRenderBenchmarkTest::SetUp(const ::benchmark::State &state)
56 {
57     char absPath[PATH_MAX] = {0};
58     if (realpath(RESOLVED_PATH.c_str(), absPath) == nullptr) {
59         return;
60     }
61     handleSo = dlopen(absPath, RTLD_LAZY);
62     if (handleSo == nullptr) {
63         return;
64     }
65     GetAudioManager = (TestAudioManager *(*)())(dlsym(handleSo, FUNCTION_NAME.c_str()));
66     if (GetAudioManager == nullptr) {
67         return;
68     }
69 }
70 
TearDown(const::benchmark::State & state)71 void AudioHdiRenderBenchmarkTest::TearDown(const ::benchmark::State &state)
72 {
73     if (handleSo != nullptr) {
74         dlclose(handleSo);
75         handleSo = nullptr;
76     }
77     if (GetAudioManager != nullptr) {
78         GetAudioManager = nullptr;
79     }
80 }
81 /**
82 * @tc.name  the performace of AudioManagerGetAllAdapters
83 * @tc.number  SUB_DriverSystem_Benchmark_AudioManagerGetAllAdapters_0001
84 * @tc.desc  tests the performace of AudioManagerGetAllAdapters interface by executing 100 times,
85 *           and calculates the delay time and average of Delay Time.
86 */
BENCHMARK_F(AudioHdiRenderBenchmarkTest,SUB_DriverSystem_Benchmark_AudioManagerGetAllAdapters_0001)87 BENCHMARK_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioManagerGetAllAdapters_0001)
88     (benchmark::State &st)
89 {
90     int32_t ret = -1;
91     int size = 0;
92     struct PrepareAudioPara audiopara = { .totalTime = 0 };
93 
94     ASSERT_NE(nullptr, GetAudioManager);
95     audiopara.manager = GetAudioManager();
96     ASSERT_NE(nullptr, audiopara.manager);
97 
98     for (auto _ : st) {
99         ret = audiopara.manager->GetAllAdapters(audiopara.manager, &audiopara.descs, &size);
100     }
101     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
102 }
103 BENCHMARK_REGISTER_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioManagerGetAllAdapters_0001)->
104     Iterations(100)->Repetitions(3)->ReportAggregatesOnly();
105 /**
106 * @tc.name  the performace of AudioManagerLoadAdapter
107 * @tc.number  SUB_DriverSystem_Benchmark_AudioManagerLoadAdapter_0001
108 * @tc.desc  tests the performace of AudioManagerLoadAdapter interface by executing 100 times,
109 *           and calculates the delay time and average of Delay Time.
110 */
BENCHMARK_F(AudioHdiRenderBenchmarkTest,SUB_DriverSystem_Benchmark_AudioManagerLoadAdapter_0001)111 BENCHMARK_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioManagerLoadAdapter_0001)
112     (benchmark::State &st)
113 {
114     int32_t ret = -1;
115     int size = 0;
116     struct PrepareAudioPara audiopara = { .totalTime = 0 };
117     ASSERT_NE(nullptr, GetAudioManager);
118     audiopara.manager = GetAudioManager();
119     ASSERT_NE(nullptr, audiopara.manager);
120     ret = audiopara.manager->GetAllAdapters(audiopara.manager, &audiopara.descs, &size);
121     ASSERT_EQ(AUDIO_HAL_SUCCESS, ret);
122     audiopara.desc = &audiopara.descs[0];
123     ASSERT_NE(nullptr, audiopara.desc);
124 
125     for (auto _ : st) {
126 
127         ret = audiopara.manager->LoadAdapter(audiopara.manager, audiopara.desc, &audiopara.adapter);
128         audiopara.manager->UnloadAdapter(audiopara.manager, audiopara.adapter);
129         audiopara.adapter = nullptr;
130     }
131     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
132 }
133 BENCHMARK_REGISTER_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioManagerLoadAdapter_0001)->
134     Iterations(100)->Repetitions(3)->ReportAggregatesOnly();
135 /**
136 * @tc.name  the performace of AudioManagerUnLoadAdapter
137 * @tc.number  SUB_DriverSystem_Benchmark_AudioManagerUnLoadAdapter_0001
138 * @tc.desc  tests the performace of AudioManagerLoadAdapter interface by executing 100 times,
139 *           and calculates the delay time and average of Delay Time.
140 */
BENCHMARK_F(AudioHdiRenderBenchmarkTest,SUB_DriverSystem_Benchmark_AudioManagerUnLoadAdapter_0001)141 BENCHMARK_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioManagerUnLoadAdapter_0001)
142     (benchmark::State &st)
143 {
144     int32_t ret = -1;
145     int size = 0;
146     struct PrepareAudioPara audiopara = { .totalTime = 0 };
147     ASSERT_NE(nullptr, GetAudioManager);
148     audiopara.manager = GetAudioManager();
149     ASSERT_NE(nullptr, audiopara.manager);
150     ret = audiopara.manager->GetAllAdapters(audiopara.manager, &audiopara.descs, &size);
151     ASSERT_EQ(AUDIO_HAL_SUCCESS, ret);
152     audiopara.desc = &audiopara.descs[0];
153     ASSERT_NE(nullptr, audiopara.desc);
154 
155     for (auto _ : st) {
156         ret = audiopara.manager->LoadAdapter(audiopara.manager, audiopara.desc, &audiopara.adapter);
157         audiopara.manager->UnloadAdapter(audiopara.manager, audiopara.adapter);
158         audiopara.adapter = nullptr;
159     }
160     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
161 }
162 BENCHMARK_REGISTER_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioManagerUnLoadAdapter_0001)->
163     Iterations(100)->Repetitions(3)->ReportAggregatesOnly();
164 /**
165 * @tc.name  the performace of AudioInitAllPorts
166 * @tc.number  SUB_DriverSystem_Benchmark_AudioManagerInitAllPorts_0001
167 * @tc.desc  tests the performace of AudioInitAllPorts interface by executing 100 times,
168 *           and calculates the delay time and average of Delay Time.
169 */
BENCHMARK_F(AudioHdiRenderBenchmarkTest,SUB_DriverSystem_Benchmark_AudioManagerInitAllPorts_0001)170 BENCHMARK_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioManagerInitAllPorts_0001)
171     (benchmark::State &st)
172 {
173     int32_t ret = -1;
174     struct PrepareAudioPara audiopara = {
175         .portType = PORT_OUT, .adapterName = ADAPTER_NAME.c_str(), .totalTime = 0
176     };
177     ASSERT_NE(nullptr, GetAudioManager);
178     audiopara.manager = GetAudioManager();
179     ASSERT_NE(nullptr, audiopara.manager);
180     ret = GetLoadAdapter(audiopara.manager, audiopara.portType, audiopara.adapterName,
181                          &audiopara.adapter, audiopara.audioPort);
182     ASSERT_EQ(AUDIO_HAL_SUCCESS, ret);
183     for (auto _ : st) {
184         ret = audiopara.adapter->InitAllPorts(audiopara.adapter);
185     }
186     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
187     audiopara.manager->UnloadAdapter(audiopara.manager, audiopara.adapter);
188     audiopara.adapter = nullptr;
189 }
190 BENCHMARK_REGISTER_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioManagerInitAllPorts_0001)->
191     Iterations(100)->Repetitions(3)->ReportAggregatesOnly();
192 /**
193 * @tc.name  the performace of AudioGetPortCapability
194 * @tc.number  SUB_DriverSystem_Benchmark_AudioGetPortCapability_0001
195 * @tc.desc  tests the performace of AudioGetPortCapability interface by executing 100 times,
196 *           and calculates the delay time and average of Delay Time.
197 */
BENCHMARK_F(AudioHdiRenderBenchmarkTest,SUB_DriverSystem_Benchmark_AudioGetPortCapability_0001)198 BENCHMARK_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioGetPortCapability_0001)
199     (benchmark::State &st)
200 {
201     int32_t ret = -1;
202     struct PrepareAudioPara audiopara = {
203         .portType = PORT_OUT, .adapterName = ADAPTER_NAME.c_str(), .totalTime = 0
204     };
205     ASSERT_NE(nullptr, GetAudioManager);
206     audiopara.manager = GetAudioManager();
207     ASSERT_NE(nullptr, audiopara.manager);
208     ret = GetLoadAdapter(audiopara.manager, audiopara.portType, audiopara.adapterName,
209                          &audiopara.adapter, audiopara.audioPort);
210     ASSERT_EQ(AUDIO_HAL_SUCCESS, ret);
211     ret = audiopara.adapter->InitAllPorts(audiopara.adapter);
212     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
213     for (auto _ : st) {
214         ret = audiopara.adapter->GetPortCapability(audiopara.adapter, audiopara.audioPort, &audiopara.capability);
215     }
216     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
217     audiopara.manager->UnloadAdapter(audiopara.manager, audiopara.adapter);
218     audiopara.adapter = nullptr;
219 }
220 BENCHMARK_REGISTER_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioGetPortCapability_0001)->
221     Iterations(100)->Repetitions(3)->ReportAggregatesOnly();
222 /**
223 * @tc.name  the performace of AudioSetPassthroughMode
224 * @tc.number  SUB_DriverSystem_Benchmark_AudioSetPassthroughMode_0001
225 * @tc.desc  tests the performace of AudioSetPassthroughMode interface by executing 100 times,
226 *           and calculates the delay time and average of Delay Time.
227 */
BENCHMARK_F(AudioHdiRenderBenchmarkTest,SUB_DriverSystem_Benchmark_AudioSetPassthroughMode_0001)228 BENCHMARK_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioSetPassthroughMode_0001)
229     (benchmark::State &st)
230 {
231     int32_t ret = -1;
232     struct PrepareAudioPara audiopara = {
233         .portType = PORT_OUT, .adapterName = ADAPTER_NAME.c_str(), .mode = PORT_PASSTHROUGH_LPCM,
234         .totalTime = 0
235     };
236     ASSERT_NE(nullptr, GetAudioManager);
237     audiopara.manager = GetAudioManager();
238     ASSERT_NE(nullptr, audiopara.manager);
239     ret = GetLoadAdapter(audiopara.manager, audiopara.portType, audiopara.adapterName,
240                          &audiopara.adapter, audiopara.audioPort);
241     ASSERT_EQ(AUDIO_HAL_SUCCESS, ret);
242     ret = audiopara.adapter->InitAllPorts(audiopara.adapter);
243     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
244     for (auto _ : st) {
245         ret = audiopara.adapter->SetPassthroughMode(audiopara.adapter, audiopara.audioPort, audiopara.mode);
246     }
247     ret = audiopara.adapter->GetPassthroughMode(audiopara.adapter, audiopara.audioPort, &audiopara.mode);
248     EXPECT_EQ(PORT_PASSTHROUGH_LPCM, audiopara.mode);
249     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
250     audiopara.manager->UnloadAdapter(audiopara.manager, audiopara.adapter);
251     audiopara.adapter = nullptr;
252 }
253 BENCHMARK_REGISTER_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioSetPassthroughMode_0001)->
254     Iterations(100)->Repetitions(3)->ReportAggregatesOnly();
255 /**
256 * @tc.name  the performace of AudioGetPassthroughMode
257 * @tc.number  SUB_DriverSystem_Benchmark_AudioGetPassthroughMode_0001
258 * @tc.desc  tests the performace of AudioGetPassthroughMode interface by executing 100 times,
259 * and calculates the delay time and average of Delay Time.
260 */
BENCHMARK_F(AudioHdiRenderBenchmarkTest,SUB_DriverSystem_Benchmark_AudioGetPassthroughMode_0001)261 BENCHMARK_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioGetPassthroughMode_0001)
262     (benchmark::State &st)
263 {
264     int32_t ret = -1;
265     struct PrepareAudioPara audiopara = {
266         .portType = PORT_OUT, .adapterName = ADAPTER_NAME.c_str(), .mode = PORT_PASSTHROUGH_LPCM,
267         .totalTime = 0
268     };
269     ASSERT_NE(nullptr, GetAudioManager);
270     audiopara.manager = GetAudioManager();
271     ASSERT_NE(nullptr, audiopara.manager);
272     ret = GetLoadAdapter(audiopara.manager, audiopara.portType, audiopara.adapterName,
273                          &audiopara.adapter, audiopara.audioPort);
274     ASSERT_EQ(AUDIO_HAL_SUCCESS, ret);
275     ret = audiopara.adapter->InitAllPorts(audiopara.adapter);
276     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
277     ret = audiopara.adapter->SetPassthroughMode(audiopara.adapter, audiopara.audioPort, audiopara.mode);
278     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
279     for (auto _ : st) {
280         ret = audiopara.adapter->GetPassthroughMode(audiopara.adapter, audiopara.audioPort, &audiopara.mode);
281     }
282     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
283     EXPECT_EQ(PORT_PASSTHROUGH_LPCM, audiopara.mode);
284     audiopara.manager->UnloadAdapter(audiopara.manager, audiopara.adapter);
285     audiopara.adapter = nullptr;
286 }
287 BENCHMARK_REGISTER_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioGetPassthroughMode_0001)->
288     Iterations(100)->Repetitions(3)->ReportAggregatesOnly();
289 /**
290 * @tc.name  the performace of AudioRenderGetLatency
291 * @tc.number  SUB_DriverSystem_Benchmark_AudioRenderGetLatency_0001
292 * @tc.desc  tests the performace of AudioRenderGetLatency interface by executing 100 times,
293 * and calculates the delay time and average of Delay Time.
294 */
BENCHMARK_F(AudioHdiRenderBenchmarkTest,SUB_DriverSystem_Benchmark_AudioRenderGetLatency_0001)295 BENCHMARK_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioRenderGetLatency_0001)
296     (benchmark::State &st)
297 {
298     int32_t ret = -1;
299     struct PrepareAudioPara audiopara = {
300         .portType = PORT_OUT, .adapterName = ADAPTER_NAME.c_str(), .pins = PIN_OUT_SPEAKER,
301         .path = AUDIO_FILE.c_str(), .totalTime = 0
302     };
303     uint32_t latencyTimeExpc = 0;
304     uint32_t latencyTime = 0;
305     ASSERT_NE(nullptr, GetAudioManager);
306     audiopara.manager = GetAudioManager();
307     ASSERT_NE(nullptr, audiopara.manager);
308     ret = PlayAudioFile(audiopara);
309     ASSERT_EQ(AUDIO_HAL_SUCCESS, ret);
310     for (auto _ : st) {
311         ret = audiopara.render->GetLatency(audiopara.render, &latencyTime);
312     }
313 
314     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
315     EXPECT_LT(latencyTimeExpc, latencyTime);
316     ret = StopAudio(audiopara);
317     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
318 }
319 BENCHMARK_REGISTER_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioRenderGetLatency_0001)
320     ->Iterations(100)->Repetitions(3)->ReportAggregatesOnly();
321 /**
322 * @tc.name  the performace of AudioCreateRender
323 * @tc.number  SUB_DriverSystem_Benchmark_AudioCreateRender_0001
324 * @tc.desc  tests the performace of AudioCreateRender interface by executing 100 times,
325 *           and calculates the delay time and average of Delay Time.
326 */
BENCHMARK_F(AudioHdiRenderBenchmarkTest,SUB_DriverSystem_Benchmark_AudioCreateRender_0001)327 BENCHMARK_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioCreateRender_0001)
328     (benchmark::State &st)
329 {
330     int32_t ret = -1;
331     struct PrepareAudioPara audiopara = {
332         .portType = PORT_OUT, .adapterName = ADAPTER_NAME.c_str(), .pins = PIN_OUT_SPEAKER,
333         .totalTime = 0
334     };
335     ASSERT_NE(nullptr, GetAudioManager);
336     audiopara.manager = GetAudioManager();
337     ASSERT_NE(nullptr, audiopara.manager);
338     ret = GetLoadAdapter(audiopara.manager, audiopara.portType, audiopara.adapterName,
339                          &audiopara.adapter, audiopara.audioPort);
340     ASSERT_EQ(AUDIO_HAL_SUCCESS, ret);
341     InitAttrs(audiopara.attrs);
342     InitDevDesc(audiopara.devDesc, audiopara.audioPort->portId, audiopara.pins);
343 
344     for (auto _ : st) {
345         ret = audiopara.adapter->CreateRender(audiopara.adapter, &audiopara.devDesc, &audiopara.attrs,
346                                               &audiopara.render);
347         audiopara.adapter->DestroyRender(audiopara.adapter, audiopara.render);
348     }
349     audiopara.manager->UnloadAdapter(audiopara.manager, audiopara.adapter);
350     audiopara.adapter = nullptr;
351 }
352 BENCHMARK_REGISTER_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioCreateRender_0001)->
353     Iterations(100)->Repetitions(3)->ReportAggregatesOnly();
354 /**
355 * @tc.name  the performace of AudioDestroyRender
356 * @tc.number  SUB_DriverSystem_Benchmark_AudioDestroyRender_0001
357 * @tc.desc  tests the performace of AudioDestroyRender interface by executing 100 times,
358 *           and calculates the delay time and average of Delay Time.
359 */
BENCHMARK_F(AudioHdiRenderBenchmarkTest,SUB_DriverSystem_Benchmark_AudioDestroyRender_0001)360 BENCHMARK_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioDestroyRender_0001)
361     (benchmark::State &st)
362 {
363     int32_t ret = -1;
364     struct PrepareAudioPara audiopara = {
365         .portType = PORT_OUT, .adapterName = ADAPTER_NAME.c_str(), .pins = PIN_OUT_SPEAKER,
366         .totalTime = 0
367     };
368     ASSERT_NE(nullptr, GetAudioManager);
369     audiopara.manager = GetAudioManager();
370     ASSERT_NE(nullptr, audiopara.manager);
371     ret = GetLoadAdapter(audiopara.manager, audiopara.portType, audiopara.adapterName,
372                          &audiopara.adapter, audiopara.audioPort);
373     ASSERT_EQ(AUDIO_HAL_SUCCESS, ret);
374     InitAttrs(audiopara.attrs);
375     InitDevDesc(audiopara.devDesc, audiopara.audioPort->portId, audiopara.pins);
376     for (auto _ : st) {
377         ret = audiopara.adapter->CreateRender(audiopara.adapter, &audiopara.devDesc, &audiopara.attrs,
378                                               &audiopara.render);
379         audiopara.adapter->DestroyRender(audiopara.adapter, audiopara.render);
380     }
381     audiopara.manager->UnloadAdapter(audiopara.manager, audiopara.adapter);
382     audiopara.adapter = nullptr;
383 }
384 BENCHMARK_REGISTER_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioDestroyRender_0001)->
385     Iterations(100)->Repetitions(3)->ReportAggregatesOnly();
386 /**
387 * @tc.name  the performace of AudioRenderGetRenderPosition
388 * @tc.number  SUB_DriverSystem_Benchmark_AudioRenderGetRenderPosition_0001
389 * @tc.desc  tests the performace of AudioRenderGetRenderPosition interface by executing 100 times,
390 *           and calculates the delay time and average of Delay Time.
391 */
BENCHMARK_F(AudioHdiRenderBenchmarkTest,SUB_DriverSystem_Benchmark_AudioRenderGetRenderPosition_0001)392 BENCHMARK_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioRenderGetRenderPosition_0001)
393     (benchmark::State &st)
394 {
395     int32_t ret = -1;
396     struct PrepareAudioPara audiopara = {
397         .portType = PORT_OUT, .adapterName = ADAPTER_NAME.c_str(), .pins = PIN_OUT_SPEAKER,
398         .path = AUDIO_FILE.c_str(), .totalTime = 0
399     };
400     ASSERT_NE(nullptr, GetAudioManager);
401     audiopara.manager = GetAudioManager();
402     ASSERT_NE(nullptr, audiopara.manager);
403     ret = PlayAudioFile(audiopara);
404     ASSERT_EQ(AUDIO_HAL_SUCCESS, ret);
405     for (auto _ : st) {
406         ret = audiopara.render->GetRenderPosition(audiopara.render, &audiopara.character.getframes,
407                 &audiopara.time);
408     }
409     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
410     ret = StopAudio(audiopara);
411     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
412 }
413 BENCHMARK_REGISTER_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioRenderGetRenderPosition_0001)->
414     Iterations(100)->Repetitions(3)->ReportAggregatesOnly();
415 /**
416 * @tc.name  the performace of AudioRenderSetRenderSpeed
417 * @tc.number  SUB_DriverSystem_Benchmark_AudioRenderSetRenderSpeed_0001
418 * @tc.desc  tests the performace of AudioRenderSetRenderSpeed interface by executing 100 times,
419 *           and calculates the delay time and average of Delay Time.
420 */
BENCHMARK_F(AudioHdiRenderBenchmarkTest,SUB_DriverSystem_Benchmark_AudioRenderSetRenderSpeed_0001)421 BENCHMARK_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioRenderSetRenderSpeed_0001)
422     (benchmark::State &st)
423 {
424     int32_t ret = -1;
425     float speedNormal = 30;
426     struct PrepareAudioPara audiopara = {
427         .portType = PORT_OUT, .adapterName = ADAPTER_NAME.c_str(), .pins = PIN_OUT_SPEAKER,
428         .totalTime = 0
429     };
430     ASSERT_NE(nullptr, GetAudioManager);
431     audiopara.manager = GetAudioManager();
432     ASSERT_NE(nullptr, audiopara.manager);
433     ret = AudioCreateRender(audiopara.manager, audiopara.pins, audiopara.adapterName, &audiopara.adapter,
434                             &audiopara.render);
435     ASSERT_EQ(AUDIO_HAL_SUCCESS, ret);
436     ret = audiopara.render->control.Start((AudioHandle)audiopara.render);
437     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
438 
439     for (auto _ : st) {
440         ret = audiopara.render->SetRenderSpeed(audiopara.render, speedNormal);
441     }
442     ret = audiopara.render->GetRenderSpeed(audiopara.render, &speedNormal);
443     EXPECT_EQ(HDF_ERR_NOT_SUPPORT, ret);
444     ret = StopAudio(audiopara);
445     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
446 }
447 BENCHMARK_REGISTER_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioRenderSetRenderSpeed_0001)->
448     Iterations(100)->Repetitions(3)->ReportAggregatesOnly();
449 /**
450 * @tc.name  the performace of AudioRenderGetRenderSpeed
451 * @tc.number  SUB_DriverSystem_Benchmark_AudioRenderGetRenderSpeed_0001
452 * @tc.desc  tests the performace of AudioRenderGetRenderSpeed interface by executing 100 times,
453 *           and calculates the delay time and average of Delay Time.
454 */
BENCHMARK_F(AudioHdiRenderBenchmarkTest,SUB_DriverSystem_Benchmark_AudioRenderGetRenderSpeed_0001)455 BENCHMARK_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioRenderGetRenderSpeed_0001)
456     (benchmark::State &st)
457 {
458     int32_t ret = -1;
459     float speedValue = 30;
460     struct PrepareAudioPara audiopara = {
461         .portType = PORT_OUT, .adapterName = ADAPTER_NAME.c_str(), .pins = PIN_OUT_SPEAKER,
462         .totalTime = 0
463     };
464     ASSERT_NE(nullptr, GetAudioManager);
465     audiopara.manager = GetAudioManager();
466     ASSERT_NE(nullptr, audiopara.manager);
467     ret = AudioCreateRender(audiopara.manager, audiopara.pins, audiopara.adapterName, &audiopara.adapter,
468                             &audiopara.render);
469     ASSERT_EQ(AUDIO_HAL_SUCCESS, ret);
470     ret = audiopara.render->control.Start((AudioHandle)audiopara.render);
471     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
472 
473     for (auto _ : st) {
474         ret = audiopara.render->GetRenderSpeed(audiopara.render, &speedValue);
475     }
476     EXPECT_EQ(HDF_ERR_NOT_SUPPORT, ret);
477     ret = StopAudio(audiopara);
478     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
479 }
480 BENCHMARK_REGISTER_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioRenderGetRenderSpeed_0001)->
481     Iterations(100)->Repetitions(3)->ReportAggregatesOnly();
482 /**
483 * @tc.name  the performace of AudioRenderSetChannelMode
484 * @tc.number  SUB_DriverSystem_Benchmark_AudioRenderSetChannelMode_0001
485 * @tc.desc  tests the performace of AudioRenderSetChannelMode interface by executing 100 times,
486 *           and calculates the delay time and average of Delay Time.
487 */
BENCHMARK_F(AudioHdiRenderBenchmarkTest,SUB_DriverSystem_Benchmark_AudioRenderSetChannelMode_0001)488 BENCHMARK_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioRenderSetChannelMode_0001)
489     (benchmark::State &st)
490 {
491     int32_t ret = -1;
492     enum AudioChannelMode mode = AUDIO_CHANNEL_NORMAL;
493     struct PrepareAudioPara audiopara = {
494         .portType = PORT_OUT, .adapterName = ADAPTER_NAME.c_str(), .pins = PIN_OUT_SPEAKER,
495         .totalTime = 0
496     };
497     ASSERT_NE(nullptr, GetAudioManager);
498     audiopara.manager = GetAudioManager();
499     ASSERT_NE(nullptr, audiopara.manager);
500     ret = AudioCreateRender(audiopara.manager, audiopara.pins, audiopara.adapterName, &audiopara.adapter,
501                             &audiopara.render);
502     ASSERT_EQ(AUDIO_HAL_SUCCESS, ret);
503     ret = audiopara.render->control.Start((AudioHandle)audiopara.render);
504     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
505     for (auto _ : st) {
506         ret = audiopara.render->SetChannelMode(audiopara.render, mode);
507     }
508     ret = audiopara.render->GetChannelMode(audiopara.render, &mode);
509     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
510     EXPECT_EQ(AUDIO_CHANNEL_NORMAL, mode);
511     ret = StopAudio(audiopara);
512     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
513 }
514 BENCHMARK_REGISTER_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioRenderSetChannelMode_0001)->
515     Iterations(100)->Repetitions(3)->ReportAggregatesOnly();
516 /**
517 * @tc.name  the performace of AudioRenderGetChannelMode
518 * @tc.number  SUB_DriverSystem_Benchmark_AudioRenderGetChannelMode_0001
519 * @tc.desc  tests the performace of AudioRenderGetChannelMode interface by executing 100 times,
520 *           and calculates the delay time and average of Delay Time.
521 */
BENCHMARK_F(AudioHdiRenderBenchmarkTest,SUB_DriverSystem_Benchmark_AudioRenderGetChannelMode_0001)522 BENCHMARK_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioRenderGetChannelMode_0001)
523     (benchmark::State &st)
524 {
525     int32_t ret = -1;
526     enum AudioChannelMode mode = AUDIO_CHANNEL_NORMAL;
527     struct PrepareAudioPara audiopara = {
528         .portType = PORT_OUT, .adapterName = ADAPTER_NAME.c_str(), .pins = PIN_OUT_SPEAKER,
529         .totalTime = 0
530     };
531     ASSERT_NE(nullptr, GetAudioManager);
532     audiopara.manager = GetAudioManager();
533     ASSERT_NE(nullptr, audiopara.manager);
534     ret = AudioCreateRender(audiopara.manager, audiopara.pins, audiopara.adapterName, &audiopara.adapter,
535                             &audiopara.render);
536     ASSERT_EQ(AUDIO_HAL_SUCCESS, ret);
537     ret = audiopara.render->control.Start((AudioHandle)audiopara.render);
538     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
539     ret = audiopara.render->SetChannelMode(audiopara.render, mode);
540     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
541 
542     for (auto _ : st) {
543         ret = audiopara.render->GetChannelMode(audiopara.render, &mode);
544     }
545     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
546     EXPECT_EQ(AUDIO_CHANNEL_NORMAL, mode);
547     ret = StopAudio(audiopara);
548     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
549 }
550 BENCHMARK_REGISTER_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioRenderGetChannelMode_0001)->
551     Iterations(100)->Repetitions(3)->ReportAggregatesOnly();
552 /**
553 * @tc.name  the performace of AudioRenderGetFrameCount
554 * @tc.number  SUB_DriverSystem_Benchmark_AudioRenderGetFrameCount_0001
555 * @tc.desc  tests the performace of AudioRenderGetFrameCount interface by executing 100 times,
556 *           and calculates the delay time and average of Delay Time.
557 */
BENCHMARK_F(AudioHdiRenderBenchmarkTest,SUB_DriverSystem_Benchmark_AudioRenderGetFrameCount_0001)558 BENCHMARK_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioRenderGetFrameCount_0001)
559     (benchmark::State &st)
560 {
561     int32_t ret = -1;
562     struct PrepareAudioPara audiopara = {
563         .portType = PORT_OUT, .adapterName = ADAPTER_NAME.c_str(), .pins = PIN_OUT_SPEAKER,
564         .totalTime = 0
565     };
566     ASSERT_NE(nullptr, GetAudioManager);
567     audiopara.manager = GetAudioManager();
568     ASSERT_NE(nullptr, audiopara.manager);
569     ret = AudioCreateRender(audiopara.manager, audiopara.pins, audiopara.adapterName, &audiopara.adapter,
570                             &audiopara.render);
571     ASSERT_EQ(AUDIO_HAL_SUCCESS, ret);
572     ret = audiopara.render->control.Start((AudioHandle)audiopara.render);
573     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
574 
575     for (auto _ : st) {
576         ret = audiopara.render->attr.GetFrameCount(audiopara.render, &audiopara.character.getframecount);
577     }
578     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
579     ret = StopAudio(audiopara);
580     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
581 }
582 BENCHMARK_REGISTER_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioRenderGetFrameCount_0001)->
583     Iterations(100)->Repetitions(3)->ReportAggregatesOnly();
584 /**
585 * @tc.name  the performace of AudioRenderGetCurrentChannelId
586 * @tc.number  SUB_DriverSystem_Benchmark_AudioRenderGetCurrentChannelId_0001
587 * @tc.desc  tests the performace of AudioRenderGetCurrentChannelId interface by executing 100 times,
588 *           and calculates the delay time and average of Delay Time.
589 */
BENCHMARK_F(AudioHdiRenderBenchmarkTest,SUB_DriverSystem_Benchmark_AudioRenderGetCurrentChannelId_0001)590 BENCHMARK_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioRenderGetCurrentChannelId_0001)
591     (benchmark::State &st)
592 {
593     int32_t ret = -1;
594     struct PrepareAudioPara audiopara = {
595         .portType = PORT_OUT, .adapterName = ADAPTER_NAME.c_str(), .pins = PIN_OUT_SPEAKER,
596         .totalTime = 0
597     };
598     ASSERT_NE(nullptr, GetAudioManager);
599     audiopara.manager = GetAudioManager();
600     ASSERT_NE(nullptr, audiopara.manager);
601     ret = AudioCreateRender(audiopara.manager, audiopara.pins, audiopara.adapterName, &audiopara.adapter,
602                             &audiopara.render);
603     ASSERT_EQ(AUDIO_HAL_SUCCESS, ret);
604 
605     for (auto _ : st) {
606         ret = audiopara.render->attr.GetCurrentChannelId(audiopara.render, &audiopara.character.getcurrentchannelId);
607     }
608     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
609     audiopara.adapter->DestroyRender(audiopara.adapter, audiopara.render);
610     audiopara.manager->UnloadAdapter(audiopara.manager, audiopara.adapter);
611     audiopara.render = nullptr;
612     audiopara.adapter = nullptr;
613 }
614 BENCHMARK_REGISTER_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioRenderGetCurrentChannelId_0001)->
615     Iterations(100)->Repetitions(3)->ReportAggregatesOnly();
616 /**
617 * @tc.name  the performace of AudioRenderFlush
618 * @tc.number  SUB_DriverSystem_Benchmark_AudioRenderFlush_0001
619 * @tc.desc  tests the performace of AudioRenderFlush interface by executing 100 times,
620 *           and calculates the delay time and average of Delay Time.
621 */
BENCHMARK_F(AudioHdiRenderBenchmarkTest,SUB_DriverSystem_Benchmark_AudioRenderFlush_0001)622 BENCHMARK_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioRenderFlush_0001)
623     (benchmark::State &st)
624 {
625     int32_t ret = -1;
626     struct PrepareAudioPara audiopara = {
627         .portType = PORT_OUT, .adapterName = ADAPTER_NAME.c_str(), .pins = PIN_OUT_SPEAKER,
628         .totalTime = 0
629     };
630     ASSERT_NE(nullptr, GetAudioManager);
631     audiopara.manager = GetAudioManager();
632     ASSERT_NE(nullptr, audiopara.manager);
633     AudioCreateRender(audiopara.manager, audiopara.pins, audiopara.adapterName, &audiopara.adapter,
634                                 &audiopara.render);
635     audiopara.render->control.Start((AudioHandle)audiopara.render);
636     for (auto _ : st) {
637         ret = audiopara.render->control.Flush((AudioHandle)audiopara.render);
638     }
639     StopAudio(audiopara);
640     EXPECT_EQ(HDF_ERR_NOT_SUPPORT, ret);
641 }
642 BENCHMARK_REGISTER_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioRenderFlush_0001)->
643     Iterations(100)->Repetitions(3)->ReportAggregatesOnly();
644 /**
645 * @tc.name  the performace of AudioRenderGetFrameSize
646 * @tc.number  SUB_DriverSystem_Benchmark_AudioRenderGetFrameSize_0001
647 * @tc.desc  tests the performace of AudioRenderGetFrameSize interface by executing 100 times,
648 *           and calculates the delay time and average of Delay Time.
649 */
BENCHMARK_F(AudioHdiRenderBenchmarkTest,SUB_DriverSystem_Benchmark_AudioRenderGetFrameSize_0001)650 BENCHMARK_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioRenderGetFrameSize_0001)
651     (benchmark::State &st)
652 {
653     int32_t ret = -1;
654     uint64_t zero = 0;
655     struct PrepareAudioPara audiopara = {
656         .portType = PORT_OUT, .adapterName = ADAPTER_NAME.c_str(), .pins = PIN_OUT_SPEAKER,
657         .totalTime = 0
658     };
659     ASSERT_NE(nullptr, GetAudioManager);
660     audiopara.manager = GetAudioManager();
661     ASSERT_NE(nullptr, audiopara.manager);
662     ret = AudioCreateRender(audiopara.manager, audiopara.pins, audiopara.adapterName, &audiopara.adapter,
663                             &audiopara.render);
664     ASSERT_EQ(AUDIO_HAL_SUCCESS, ret);
665     audiopara.render->control.Start((AudioHandle)audiopara.render);
666     for (auto _ : st) {
667         ret = audiopara.render->attr.GetFrameSize(audiopara.render, &audiopara.character.getframesize);
668     }
669     audiopara.render->control.Stop((AudioHandle)audiopara.render);
670     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
671     EXPECT_GT(audiopara.character.getframesize, zero);
672     audiopara.adapter->DestroyRender(audiopara.adapter, audiopara.render);
673     audiopara.manager->UnloadAdapter(audiopara.manager, audiopara.adapter);
674     audiopara.render = nullptr;
675     audiopara.adapter = nullptr;
676 }
677 BENCHMARK_REGISTER_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioRenderGetFrameSize_0001)->
678     Iterations(100)->Repetitions(3)->ReportAggregatesOnly();
679 
680 /**
681 * @tc.name  the performace of AudioRenderCheckSceneCapability
682 * @tc.number  SUB_DriverSystem_Benchmark_AudioRenderCheckSceneCapability_0001
683 * @tc.desc  tests the performace of AudioRenderCheckSceneCapability interface by executing 100 times,
684 *           and calculates the delay time and average of Delay Time.
685 */
BENCHMARK_F(AudioHdiRenderBenchmarkTest,SUB_DriverSystem_Benchmark_AudioRenderCheckSceneCapability_0001)686 BENCHMARK_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioRenderCheckSceneCapability_0001)
687     (benchmark::State &st)
688 {
689     int32_t ret = -1;
690     struct PrepareAudioPara audiopara = {
691         .portType = PORT_OUT, .adapterName = ADAPTER_NAME.c_str(), .pins = PIN_OUT_SPEAKER,
692         .totalTime = 0
693     };
694     struct AudioSceneDescriptor scenes = {.scene.id = 0, .desc.pins = PIN_OUT_SPEAKER};
695     ASSERT_NE(nullptr, GetAudioManager);
696     audiopara.manager = GetAudioManager();
697     ASSERT_NE(nullptr, audiopara.manager);
698     ret = AudioCreateRender(audiopara.manager, audiopara.pins, audiopara.adapterName, &audiopara.adapter,
699                             &audiopara.render);
700     ASSERT_EQ(AUDIO_HAL_SUCCESS, ret);
701     for (auto _ : st) {
702         ret = audiopara.render->scene.CheckSceneCapability(audiopara.render, &scenes, &audiopara.character.supported);
703     }
704 #ifdef AUDIO_HAL_NOTSUPPORT_PATHSELECT
705     EXPECT_EQ(AUDIO_HAL_ERR_NOT_SUPPORT, ret);
706 #else
707     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
708 #endif
709     audiopara.adapter->DestroyRender(audiopara.adapter, audiopara.render);
710     audiopara.manager->UnloadAdapter(audiopara.manager, audiopara.adapter);
711     audiopara.render = nullptr;
712     audiopara.adapter = nullptr;
713 }
714 BENCHMARK_REGISTER_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioRenderCheckSceneCapability_0001)->
715     Iterations(100)->Repetitions(3)->ReportAggregatesOnly();
716 /**
717 * @tc.name  the performace of AudioRenderSelectScene
718 * @tc.number  SUB_DriverSystem_Benchmark_AudioRenderSelectScene_0001
719 * @tc.desc  tests the performace of AudioRenderSelectScene interface by executing 100 times,
720 *           and calculates the delay time and average of Delay Time.
721 */
BENCHMARK_F(AudioHdiRenderBenchmarkTest,SUB_DriverSystem_Benchmark_AudioRenderSelectScene_0001)722 BENCHMARK_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioRenderSelectScene_0001)
723     (benchmark::State &st)
724 {
725     int32_t ret = -1;
726     struct PrepareAudioPara audiopara = {
727         .portType = PORT_OUT, .adapterName = ADAPTER_NAME.c_str(), .pins = PIN_OUT_SPEAKER,
728         .totalTime = 0
729     };
730     struct AudioSceneDescriptor scenes = {.scene.id = 0, .desc.pins = PIN_OUT_SPEAKER};
731     ASSERT_NE(nullptr, GetAudioManager);
732     audiopara.manager = GetAudioManager();
733     ASSERT_NE(nullptr, audiopara.manager);
734     ret = AudioCreateRender(audiopara.manager, audiopara.pins, audiopara.adapterName, &audiopara.adapter,
735                             &audiopara.render);
736     ASSERT_EQ(AUDIO_HAL_SUCCESS, ret);
737 
738     for (auto _ : st) {
739         ret = audiopara.render->scene.SelectScene(audiopara.render, &scenes);
740     }
741 #ifdef AUDIO_HAL_NOTSUPPORT_PATHSELECT
742     EXPECT_EQ(AUDIO_HAL_ERR_NOT_SUPPORT, ret);
743 #else
744     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
745 #endif
746     audiopara.adapter->DestroyRender(audiopara.adapter, audiopara.render);
747     audiopara.manager->UnloadAdapter(audiopara.manager, audiopara.adapter);
748     audiopara.render = nullptr;
749     audiopara.adapter = nullptr;
750 }
751 BENCHMARK_REGISTER_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioRenderSelectScene_0001)->
752     Iterations(100)->Repetitions(3)->ReportAggregatesOnly();
753 /**
754 * @tc.name  the performace of AudiorenderSetMute
755 * @tc.number  SUB_DriverSystem_Benchmark_AudiorenderSetMute_0001
756 * @tc.desc  tests the performace of AudiorenderSetMute interface by executing 100 times,
757 *           and calculates the delay time and average of Delay Time.
758 */
BENCHMARK_F(AudioHdiRenderBenchmarkTest,SUB_DriverSystem_Benchmark_AudiorenderSetMute_0001)759 BENCHMARK_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudiorenderSetMute_0001)
760     (benchmark::State &st)
761 {
762     int32_t ret = -1;
763     struct PrepareAudioPara audiopara = {
764         .portType = PORT_OUT, .adapterName = ADAPTER_NAME.c_str(), .pins = PIN_OUT_SPEAKER,
765         .totalTime = 0
766     };
767     ASSERT_NE(nullptr, GetAudioManager);
768     audiopara.manager = GetAudioManager();
769     ASSERT_NE(nullptr, audiopara.manager);
770     ret = AudioCreateRender(audiopara.manager, audiopara.pins, audiopara.adapterName, &audiopara.adapter,
771                             &audiopara.render);
772     ASSERT_EQ(AUDIO_HAL_SUCCESS, ret);
773     for (auto _ : st) {
774         ret = audiopara.render->volume.SetMute(audiopara.render, false);
775     }
776     ret = audiopara.render->volume.GetMute(audiopara.render, &audiopara.character.getmute);
777     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
778     EXPECT_FALSE(audiopara.character.getmute);
779     audiopara.adapter->DestroyRender(audiopara.adapter, audiopara.render);
780     audiopara.manager->UnloadAdapter(audiopara.manager, audiopara.adapter);
781     audiopara.render = nullptr;
782     audiopara.adapter = nullptr;
783 }
784 BENCHMARK_REGISTER_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudiorenderSetMute_0001)->
785     Iterations(100)->Repetitions(3)->ReportAggregatesOnly();
786 /**
787 * @tc.name  the performace of AudiorenderGetMute
788 * @tc.number  SUB_DriverSystem_Benchmark_AudiorenderGetMute_0001
789 * @tc.desc  tests the performace of AudiorenderGetMute interface by executing 100 times,
790 *           and calculates the delay time and average of Delay Time.
791 */
BENCHMARK_F(AudioHdiRenderBenchmarkTest,SUB_DriverSystem_Benchmark_AudiorenderGetMute_0001)792 BENCHMARK_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudiorenderGetMute_0001)
793     (benchmark::State &st)
794 {
795     int32_t ret = -1;
796     struct PrepareAudioPara audiopara = {
797         .portType = PORT_OUT, .adapterName = ADAPTER_NAME.c_str(), .pins = PIN_OUT_SPEAKER,
798         .totalTime = 0
799     };
800     ASSERT_NE(nullptr, GetAudioManager);
801     audiopara.manager = GetAudioManager();
802     ASSERT_NE(nullptr, audiopara.manager);
803     ret = AudioCreateRender(audiopara.manager, audiopara.pins, audiopara.adapterName, &audiopara.adapter,
804                             &audiopara.render);
805     ASSERT_EQ(AUDIO_HAL_SUCCESS, ret);
806     ret = audiopara.render->volume.SetMute(audiopara.render, false);
807     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
808     for (auto _ : st) {
809         ret = audiopara.render->volume.GetMute(audiopara.render, &audiopara.character.getmute);
810     }
811     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
812     EXPECT_FALSE(audiopara.character.getmute);
813     audiopara.adapter->DestroyRender(audiopara.adapter, audiopara.render);
814     audiopara.manager->UnloadAdapter(audiopara.manager, audiopara.adapter);
815     audiopara.render = nullptr;
816     audiopara.adapter = nullptr;
817 }
818 BENCHMARK_REGISTER_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudiorenderGetMute_0001)->
819     Iterations(100)->Repetitions(3)->ReportAggregatesOnly();
820 /**
821 * @tc.name  the performace of AudiorenderSetVolume
822 * @tc.number  SUB_DriverSystem_Benchmark_AudiorenderSetVolume_0001
823 * @tc.desc  tests the performace of AudiorenderSetVolume interface by executing 100 times,
824 *           and calculates the delay time and average of Delay Time.
825 */
BENCHMARK_F(AudioHdiRenderBenchmarkTest,SUB_DriverSystem_Benchmark_AudiorenderSetVolume_0001)826 BENCHMARK_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudiorenderSetVolume_0001)
827     (benchmark::State &st)
828 {
829     int32_t ret = -1;
830     struct PrepareAudioPara audiopara = {
831         .portType = PORT_OUT, .adapterName = ADAPTER_NAME.c_str(), .pins = PIN_OUT_SPEAKER,
832         .character.setvolume = 0.8, .totalTime = 0
833     };
834     ASSERT_NE(nullptr, GetAudioManager);
835     audiopara.manager = GetAudioManager();
836     ASSERT_NE(nullptr, audiopara.manager);
837     ret = AudioCreateRender(audiopara.manager, audiopara.pins, audiopara.adapterName, &audiopara.adapter,
838                             &audiopara.render);
839     ASSERT_EQ(AUDIO_HAL_SUCCESS, ret);
840 
841     for (auto _ : st) {
842         ret = audiopara.render->volume.SetVolume(audiopara.render, audiopara.character.setvolume);
843     }
844     ret = audiopara.render->volume.GetVolume(audiopara.render, &audiopara.character.getvolume);
845     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
846     EXPECT_EQ(audiopara.character.setvolume, audiopara.character.getvolume);
847     audiopara.adapter->DestroyRender(audiopara.adapter, audiopara.render);
848     audiopara.manager->UnloadAdapter(audiopara.manager, audiopara.adapter);
849     audiopara.render = nullptr;
850     audiopara.adapter = nullptr;
851 }
852 BENCHMARK_REGISTER_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudiorenderSetVolume_0001)->
853     Iterations(100)->Repetitions(3)->ReportAggregatesOnly();
854 /**
855 * @tc.name  the performace of AudiorenderGetVolume
856 * @tc.number  SUB_DriverSystem_Benchmark_AudiorenderGetVolume_0001
857 * @tc.desc  tests the performace of AudiorenderGetVolume interface by executing 100 times,
858 *           and calculates the delay time and average of Delay Time.
859 */
BENCHMARK_F(AudioHdiRenderBenchmarkTest,SUB_DriverSystem_Benchmark_AudiorenderGetVolume_0001)860 BENCHMARK_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudiorenderGetVolume_0001)
861     (benchmark::State &st)
862 {
863     int32_t ret = -1;
864     struct PrepareAudioPara audiopara = {
865         .portType = PORT_OUT, .adapterName = ADAPTER_NAME.c_str(), .pins = PIN_OUT_SPEAKER,
866         .totalTime = 0
867     };
868     ASSERT_NE(nullptr, GetAudioManager);
869     audiopara.manager = GetAudioManager();
870     ASSERT_NE(nullptr, audiopara.manager);
871     ret = AudioCreateRender(audiopara.manager, audiopara.pins, audiopara.adapterName, &audiopara.adapter,
872                             &audiopara.render);
873     ASSERT_EQ(AUDIO_HAL_SUCCESS, ret);
874 
875     for (auto _ : st) {
876         ret = audiopara.render->volume.GetVolume(audiopara.render, &audiopara.character.getvolume);
877     }
878     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
879     audiopara.adapter->DestroyRender(audiopara.adapter, audiopara.render);
880     audiopara.manager->UnloadAdapter(audiopara.manager, audiopara.adapter);
881     audiopara.render = nullptr;
882     audiopara.adapter = nullptr;
883 }
884 BENCHMARK_REGISTER_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudiorenderGetVolume_0001)->
885     Iterations(100)->Repetitions(3)->ReportAggregatesOnly();
886 /**
887 * @tc.name  the performace of AudiorenderGetGainThreshold
888 * @tc.number  SUB_DriverSystem_Benchmark_AudiorenderGetGainThreshold_0001
889 * @tc.desc  tests the performace of AudiorenderGetGainThreshold interface by executing 100 times,
890 *           and calculates the delay time and average of Delay Time.
891 */
BENCHMARK_F(AudioHdiRenderBenchmarkTest,SUB_DriverSystem_Benchmark_AudiorenderGetGainThreshold_0001)892 BENCHMARK_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudiorenderGetGainThreshold_0001)
893     (benchmark::State &st)
894 {
895     int32_t ret = -1;
896     struct PrepareAudioPara audiopara = {
897         .portType = PORT_OUT, .adapterName = ADAPTER_NAME.c_str(), .pins = PIN_OUT_SPEAKER,
898         .totalTime = 0
899     };
900     ASSERT_NE(nullptr, GetAudioManager);
901     audiopara.manager = GetAudioManager();
902     ASSERT_NE(nullptr, audiopara.manager);
903     ret = AudioCreateRender(audiopara.manager, audiopara.pins, audiopara.adapterName, &audiopara.adapter,
904                             &audiopara.render);
905     ASSERT_EQ(AUDIO_HAL_SUCCESS, ret);
906 
907     for (auto _ : st) {
908         ret = audiopara.render->volume.GetGainThreshold(audiopara.render, &audiopara.character.gainthresholdmin,
909                 &audiopara.character.gainthresholdmax);
910     }
911     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
912     audiopara.adapter->DestroyRender(audiopara.adapter, audiopara.render);
913     audiopara.manager->UnloadAdapter(audiopara.manager, audiopara.adapter);
914     audiopara.render = nullptr;
915     audiopara.adapter = nullptr;
916 }
917 BENCHMARK_REGISTER_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudiorenderGetGainThreshold_0001)->
918     Iterations(100)->Repetitions(3)->ReportAggregatesOnly();
919 /**
920 * @tc.name  the performace of AudiorenderGetGain
921 * @tc.number  SUB_DriverSystem_Benchmark_AudiorenderGetGain_0001
922 * @tc.desc  tests the performace of AudiorenderGetGain interface by executing 100 times,
923 *           and calculates the delay time and average of Delay Time.
924 */
BENCHMARK_F(AudioHdiRenderBenchmarkTest,SUB_DriverSystem_Benchmark_AudiorenderGetGain_0001)925 BENCHMARK_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudiorenderGetGain_0001)
926     (benchmark::State &st)
927 {
928     int32_t ret = -1;
929     struct PrepareAudioPara audiopara = {
930         .portType = PORT_OUT, .adapterName = ADAPTER_NAME.c_str(), .pins = PIN_OUT_SPEAKER,
931         .totalTime = 0
932     };
933     ASSERT_NE(nullptr, GetAudioManager);
934     audiopara.manager = GetAudioManager();
935     ASSERT_NE(nullptr, audiopara.manager);
936     ret = AudioCreateRender(audiopara.manager, audiopara.pins, audiopara.adapterName, &audiopara.adapter,
937                             &audiopara.render);
938     ASSERT_EQ(AUDIO_HAL_SUCCESS, ret);
939     for (auto _ : st) {
940         ret = audiopara.render->volume.GetGain(audiopara.render, &audiopara.character.getgain);
941     }
942     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
943     audiopara.adapter->DestroyRender(audiopara.adapter, audiopara.render);
944     audiopara.manager->UnloadAdapter(audiopara.manager, audiopara.adapter);
945     audiopara.render = nullptr;
946     audiopara.adapter = nullptr;
947 }
948 BENCHMARK_REGISTER_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudiorenderGetGain_0001)->
949     Iterations(100)->Repetitions(3)->ReportAggregatesOnly();
950 /**
951 * @tc.name  the performace of AudiorenderSetGain
952 * @tc.number  SUB_DriverSystem_Benchmark_AudiorenderSetGain_0001
953 * @tc.desc  tests the performace of AudiorenderSetGain interface by executing 100 times,
954 *           and calculates the delay time and average of Delay Time.
955 */
BENCHMARK_F(AudioHdiRenderBenchmarkTest,SUB_DriverSystem_Benchmark_AudiorenderSetGain_0001)956 BENCHMARK_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudiorenderSetGain_0001)
957     (benchmark::State &st)
958 {
959     int32_t ret = -1;
960     struct PrepareAudioPara audiopara = {
961         .portType = PORT_OUT, .adapterName = ADAPTER_NAME.c_str(), .pins = PIN_OUT_SPEAKER,
962         .character.setgain = 7, .totalTime = 0
963     };
964     ASSERT_NE(nullptr, GetAudioManager);
965     audiopara.manager = GetAudioManager();
966     ASSERT_NE(nullptr, audiopara.manager);
967     ret = AudioCreateRender(audiopara.manager, audiopara.pins, audiopara.adapterName, &audiopara.adapter,
968                             &audiopara.render);
969     ASSERT_EQ(AUDIO_HAL_SUCCESS, ret);
970 
971     for (auto _ : st) {
972         ret = audiopara.render->volume.SetGain(audiopara.render, audiopara.character.setgain);
973     }
974     ret = audiopara.render->volume.GetGain(audiopara.render, &audiopara.character.getgain);
975     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
976     EXPECT_EQ(audiopara.character.setgain, audiopara.character.getgain);
977     audiopara.adapter->DestroyRender(audiopara.adapter, audiopara.render);
978     audiopara.manager->UnloadAdapter(audiopara.manager, audiopara.adapter);
979     audiopara.render = nullptr;
980     audiopara.adapter = nullptr;
981 }
982 BENCHMARK_REGISTER_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudiorenderSetGain_0001)->
983     Iterations(100)->Repetitions(3)->ReportAggregatesOnly();
984 /**
985 * @tc.name  the performace of AudioRenderFrame
986 * @tc.number  SUB_DriverSystem_Benchmark_AudioRenderFrame_0001
987 * @tc.desc  tests the performace of AudioRenderFrame interface by executing 100 times,
988 *           and calculates the delay time and average of Delay Time.
989 */
BENCHMARK_F(AudioHdiRenderBenchmarkTest,SUB_DriverSystem_Benchmark_AudioRenderFrame_0001)990 BENCHMARK_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioRenderFrame_0001)
991     (benchmark::State &st)
992 {
993     int32_t ret = -1;
994     struct PrepareAudioPara audiopara = {
995         .portType = PORT_OUT, .adapterName = ADAPTER_NAME.c_str(), .pins = PIN_OUT_SPEAKER,
996         .path = AUDIO_FILE.c_str(), .totalTime = 0
997     };
998     ASSERT_NE(nullptr, GetAudioManager);
999     audiopara.manager = GetAudioManager();
1000     ASSERT_NE(nullptr, audiopara.manager);
1001     ret = AudioCreateRender(audiopara.manager, audiopara.pins, audiopara.adapterName, &audiopara.adapter,
1002                             &audiopara.render);
1003     ASSERT_EQ(AUDIO_HAL_SUCCESS, ret);
1004     ret = audiopara.render->control.Start((AudioHandle)audiopara.render);
1005     if (ret < 0) {
1006         audiopara.adapter->DestroyRender(audiopara.adapter, audiopara.render);
1007         audiopara.manager->UnloadAdapter(audiopara.manager, audiopara.adapter);
1008         audiopara.render = nullptr;
1009         audiopara.adapter = nullptr;
1010         ASSERT_EQ(AUDIO_HAL_SUCCESS, ret);
1011     }
1012     ret = RenderFramePrepare(audiopara.path, audiopara.frame, audiopara.requestBytes);
1013     if (ret < 0) {
1014         audiopara.adapter->DestroyRender(audiopara.adapter, audiopara.render);
1015         audiopara.manager->UnloadAdapter(audiopara.manager, audiopara.adapter);
1016         audiopara.render = nullptr;
1017         audiopara.adapter = nullptr;
1018         ASSERT_EQ(AUDIO_HAL_SUCCESS, ret);
1019     }
1020     for (auto _ : st) {
1021         ret = audiopara.render->RenderFrame(audiopara.render, audiopara.frame, audiopara.requestBytes,
1022                                             &audiopara.replyBytes);
1023     }
1024     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
1025     ret = StopAudio(audiopara);
1026     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
1027     if (audiopara.frame != nullptr) {
1028         free(audiopara.frame);
1029         audiopara.frame = nullptr;
1030     }
1031 }
1032 BENCHMARK_REGISTER_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioRenderFrame_0001)->
1033     Iterations(100)->Repetitions(3)->ReportAggregatesOnly();
1034 /**
1035 * @tc.name  the performace of AudioRenderStart
1036 * @tc.number  SUB_DriverSystem_Benchmark_AudioRenderStart_0001
1037 * @tc.desc  tests the performace of AudioRenderStart interface by executing 100 times,
1038 *           and calculates the delay time and average of Delay Time.
1039 */
BENCHMARK_F(AudioHdiRenderBenchmarkTest,SUB_DriverSystem_Benchmark_AudioRenderStart_0001)1040 BENCHMARK_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioRenderStart_0001)
1041     (benchmark::State &st)
1042 {
1043     int32_t ret = -1;
1044     struct PrepareAudioPara audiopara = {
1045         .portType = PORT_OUT, .adapterName = ADAPTER_NAME.c_str(), .pins = PIN_OUT_SPEAKER,
1046         .totalTime = 0
1047     };
1048     ASSERT_NE(nullptr, GetAudioManager);
1049     audiopara.manager = GetAudioManager();
1050     ASSERT_NE(nullptr, audiopara.manager);
1051     ret = AudioCreateRender(audiopara.manager, audiopara.pins, audiopara.adapterName, &audiopara.adapter,
1052                                 &audiopara.render);
1053     for (auto _ : st) {
1054         ret = audiopara.render->control.Start((AudioHandle)audiopara.render);
1055         audiopara.render->control.Stop((AudioHandle)audiopara.render);
1056     }
1057     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
1058 }
1059 BENCHMARK_REGISTER_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioRenderStart_0001)->
1060     Iterations(100)->Repetitions(3)->ReportAggregatesOnly();
1061 /**
1062 * @tc.name  the performace of AudioRenderStop
1063 * @tc.number  SUB_DriverSystem_Benchmark_AudioRenderStop_0001
1064 * @tc.desc  tests the performace of AudioRenderStop interface by executing 100 times,
1065 *           and calculates the delay time and average of Delay Time.
1066 */
BENCHMARK_F(AudioHdiRenderBenchmarkTest,SUB_DriverSystem_Benchmark_AudioRenderStop_0001)1067 BENCHMARK_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioRenderStop_0001)
1068     (benchmark::State &st)
1069 {
1070     int32_t ret = -1;
1071     struct PrepareAudioPara audiopara = {
1072         .portType = PORT_OUT, .adapterName = ADAPTER_NAME.c_str(), .pins = PIN_OUT_SPEAKER, .totalTime = 0
1073     };
1074     ASSERT_NE(nullptr, GetAudioManager);
1075     audiopara.manager = GetAudioManager();
1076     ASSERT_NE(nullptr, audiopara.manager);
1077     ret = AudioCreateRender(audiopara.manager, audiopara.pins, audiopara.adapterName, &audiopara.adapter,
1078                                 &audiopara.render);
1079     for (auto _ : st) {
1080         ret = audiopara.render->control.Start((AudioHandle)audiopara.render);
1081         ret = audiopara.render->control.Stop((AudioHandle)audiopara.render);
1082     }
1083     audiopara.adapter->DestroyRender(audiopara.adapter, audiopara.render);
1084     audiopara.manager->UnloadAdapter(audiopara.manager, audiopara.adapter);
1085     audiopara.render = nullptr;
1086     audiopara.adapter = nullptr;
1087 }
1088 BENCHMARK_REGISTER_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioRenderStop_0001)->
1089     Iterations(100)->Repetitions(3)->ReportAggregatesOnly();
1090 /**
1091 * @tc.name  the performace of AudioRenderSetSampleAttributes
1092 * @tc.number  SUB_DriverSystem_Benchmark_AudioRenderSetSampleAttributes_0001
1093 * @tc.desc  tests the performace of AudioRenderSetSampleAttributes interface by executing 100 times,
1094 *           and calculates the delay time and average of Delay Time.
1095 */
BENCHMARK_F(AudioHdiRenderBenchmarkTest,SUB_DriverSystem_Benchmark_AudioRenderSetSampleAttributes_0001)1096 BENCHMARK_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioRenderSetSampleAttributes_0001)
1097     (benchmark::State &st)
1098 {
1099     int32_t ret = -1;
1100     struct PrepareAudioPara audiopara = {
1101         .portType = PORT_OUT, .adapterName = ADAPTER_NAME.c_str(), .pins = PIN_OUT_SPEAKER, .totalTime = 0
1102     };
1103     ASSERT_NE(nullptr, GetAudioManager);
1104     audiopara.manager = GetAudioManager();
1105     ASSERT_NE(nullptr, audiopara.manager);
1106     ret = AudioCreateRender(audiopara.manager, audiopara.pins, audiopara.adapterName, &audiopara.adapter,
1107                             &audiopara.render);
1108     ASSERT_EQ(AUDIO_HAL_SUCCESS, ret);
1109     InitAttrs(audiopara.attrs);
1110     for (auto _ : st) {
1111         ret = audiopara.render->attr.SetSampleAttributes(audiopara.render, &audiopara.attrs);
1112     }
1113     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
1114     audiopara.adapter->DestroyRender(audiopara.adapter, audiopara.render);
1115     audiopara.manager->UnloadAdapter(audiopara.manager, audiopara.adapter);
1116     audiopara.render = nullptr;
1117     audiopara.adapter = nullptr;
1118 }
1119 BENCHMARK_REGISTER_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioRenderSetSampleAttributes_0001)->
1120     Iterations(100)->Repetitions(3)->ReportAggregatesOnly();
1121 /**
1122 * @tc.name  the performace of AudioRenderPause
1123 * @tc.number  SUB_DriverSystem_Benchmark_AudioRenderPause_0001
1124 * @tc.desc  tests the performace of AudioRenderPause interface by executing 100 times,
1125 *           and calculates the delay time and average of Delay Time.
1126 */
BENCHMARK_F(AudioHdiRenderBenchmarkTest,SUB_DriverSystem_Benchmark_AudioRenderPause_0001)1127 BENCHMARK_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioRenderPause_0001)
1128     (benchmark::State &st)
1129 {
1130     int32_t ret = -1;
1131     struct PrepareAudioPara audiopara = {
1132         .portType = PORT_OUT, .adapterName = ADAPTER_NAME.c_str(), .pins = PIN_OUT_SPEAKER,
1133         .totalTime = 0
1134     };
1135     ASSERT_NE(nullptr, GetAudioManager);
1136     audiopara.manager = GetAudioManager();
1137     ASSERT_NE(nullptr, audiopara.manager);
1138     ret = AudioCreateRender(audiopara.manager, audiopara.pins, audiopara.adapterName, &audiopara.adapter,
1139                             &audiopara.render);
1140     ASSERT_EQ(AUDIO_HAL_SUCCESS, ret);
1141     ret = audiopara.render->control.Start((AudioHandle)audiopara.render);
1142     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
1143     for (auto _ : st) {
1144         ret = audiopara.render->control.Pause((AudioHandle)audiopara.render);
1145         ret = audiopara.render->control.Resume((AudioHandle)audiopara.render);
1146     }
1147     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
1148     ret = StopAudio(audiopara);
1149     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
1150 }
1151 BENCHMARK_REGISTER_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioRenderPause_0001)->
1152     Iterations(100)->Repetitions(3)->ReportAggregatesOnly();
1153 /**
1154 * @tc.name  the performace of AudioRenderResume
1155 * @tc.number  SUB_DriverSystem_Benchmark_AudioRenderResume_0001
1156 * @tc.desc  tests the performace of AudioRenderResume interface by executing 100 times,
1157 *           and calculates the delay time and average of Delay Time.
1158 */
BENCHMARK_F(AudioHdiRenderBenchmarkTest,SUB_DriverSystem_Benchmark_AudioRenderResume_0001)1159 BENCHMARK_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioRenderResume_0001)
1160     (benchmark::State &st)
1161 {
1162     int32_t ret = -1;
1163     struct PrepareAudioPara audiopara = {
1164         .portType = PORT_OUT, .adapterName = ADAPTER_NAME.c_str(), .pins = PIN_OUT_SPEAKER,
1165         .totalTime = 0
1166     };
1167     ASSERT_NE(nullptr, GetAudioManager);
1168     audiopara.manager = GetAudioManager();
1169     ASSERT_NE(nullptr, audiopara.manager);
1170     ret = AudioCreateRender(audiopara.manager, audiopara.pins, audiopara.adapterName, &audiopara.adapter,
1171                             &audiopara.render);
1172     ASSERT_EQ(AUDIO_HAL_SUCCESS, ret);
1173     ret = audiopara.render->control.Start((AudioHandle)audiopara.render);
1174     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
1175     for (auto _ : st) {
1176         audiopara.render->control.Pause((AudioHandle)audiopara.render);
1177         ret = audiopara.render->control.Resume((AudioHandle)audiopara.render);
1178     }
1179     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
1180     ret = StopAudio(audiopara);
1181     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
1182 }
1183 BENCHMARK_REGISTER_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioRenderResume_0001)->
1184     Iterations(100)->Repetitions(3)->ReportAggregatesOnly();
1185 /**
1186 * @tc.name  the performace of AudioRenderGetSampleAttributes
1187 * @tc.number  SUB_DriverSystem_Benchmark_AudioRenderGetSampleAttributes_0001
1188 * @tc.desc  tests the performace of AudioRenderGetSampleAttributes interface by executing 100 times,
1189 *           and calculates the delay time and average of Delay Time.
1190 */
BENCHMARK_F(AudioHdiRenderBenchmarkTest,SUB_DriverSystem_Benchmark_AudioRenderGetSampleAttributes_0001)1191 BENCHMARK_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioRenderGetSampleAttributes_0001)
1192     (benchmark::State &st)
1193 {
1194     int32_t ret = -1;
1195     struct PrepareAudioPara audiopara = {
1196         .portType = PORT_OUT, .adapterName = ADAPTER_NAME.c_str(), .pins = PIN_OUT_SPEAKER,
1197         .totalTime = 0
1198     };
1199     ASSERT_NE(nullptr, GetAudioManager);
1200     audiopara.manager = GetAudioManager();
1201     ASSERT_NE(nullptr, audiopara.manager);
1202     ret = AudioCreateRender(audiopara.manager, audiopara.pins, audiopara.adapterName, &audiopara.adapter,
1203                             &audiopara.render);
1204     ASSERT_EQ(AUDIO_HAL_SUCCESS, ret);
1205     InitAttrs(audiopara.attrs);
1206 
1207     for (auto _ : st) {
1208         ret = audiopara.render->attr.GetSampleAttributes(audiopara.render, &audiopara.attrs);
1209     }
1210     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
1211     audiopara.adapter->DestroyRender(audiopara.adapter, audiopara.render);
1212     audiopara.manager->UnloadAdapter(audiopara.manager, audiopara.adapter);
1213     audiopara.render = nullptr;
1214     audiopara.adapter = nullptr;
1215 }
1216 BENCHMARK_REGISTER_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioRenderGetSampleAttributes_0001)->
1217     Iterations(100)->Repetitions(3)->ReportAggregatesOnly();
1218 /**
1219 * @tc.name  the performace of AudioRenderReqMmapBuffer
1220 * @tc.number  SUB_DriverSystem_Benchmark_AudioRenderReqMmapBuffer_0001
1221 * @tc.desc  tests the performace of AudioRenderReqMmapBuffer interface by executing 100 times,
1222 *           and calculates the delay time and average of Delay Time.
1223 */
BENCHMARK_F(AudioHdiRenderBenchmarkTest,SUB_DriverSystem_Benchmark_AudioRenderReqMmapBuffer_0001)1224 BENCHMARK_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioRenderReqMmapBuffer_0001)
1225     (benchmark::State &st)
1226 {
1227     int32_t ret = -1;
1228     bool isRender = true;
1229     int32_t reqSize = 0;
1230     struct AudioMmapBufferDescripter desc = {};
1231     struct PrepareAudioPara audiopara = {
1232         .portType = PORT_OUT, .adapterName = ADAPTER_NAME.c_str(), .pins = PIN_OUT_SPEAKER, .totalTime = 0
1233     };
1234     ASSERT_NE(nullptr, GetAudioManager);
1235     audiopara.manager = GetAudioManager();
1236     ASSERT_NE(nullptr, audiopara.manager);
1237 
1238     audiopara.render = nullptr;
1239     FILE *fp = fopen(LOW_LATENCY_AUDIO_FILE.c_str(), "rb+");
1240     ASSERT_NE(nullptr, fp);
1241     ret = AudioCreateRender(audiopara.manager, audiopara.pins, audiopara.adapterName, &audiopara.adapter,
1242                             &audiopara.render);
1243     if (ret < 0 || audiopara.render == nullptr) {
1244         fclose(fp);
1245         ASSERT_EQ(AUDIO_HAL_SUCCESS, ret);
1246         ASSERT_EQ(nullptr, audiopara.render);
1247     }
1248     InitAttrs(audiopara.attrs);
1249     audiopara.attrs.startThreshold = 0;
1250     ret = audiopara.render->attr.SetSampleAttributes(audiopara.render, &(audiopara.attrs));
1251     ret = InitMmapDesc(fp, desc, reqSize, isRender);
1252     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
1253     ret = audiopara.render->control.Start((AudioHandle)audiopara.render);
1254     for (auto _ : st) {
1255         ret = audiopara.render->attr.ReqMmapBuffer((AudioHandle)audiopara.render, reqSize, &desc);
1256     }
1257     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
1258     if (ret == 0) {
1259         munmap(desc.memoryAddress, reqSize);
1260     }
1261 
1262     audiopara.render->control.Stop((AudioHandle)audiopara.render);
1263     audiopara.adapter->DestroyRender(audiopara.adapter, audiopara.render);
1264     audiopara.manager->UnloadAdapter(audiopara.manager, audiopara.adapter);
1265     audiopara.render = nullptr;
1266     audiopara.adapter = nullptr;
1267     fclose(fp);
1268     usleep(500);
1269 }
1270 BENCHMARK_REGISTER_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioRenderReqMmapBuffer_0001)->
1271     Iterations(100)->Repetitions(3)->ReportAggregatesOnly();
1272 /**
1273 * @tc.name  the performace of AudioRenderGetMmapPosition
1274 * @tc.number  SUB_DriverSystem_Benchmark_AudioRenderGetMmapPosition_0001
1275 * @tc.desc  tests the performace of AudioRenderRenderGetMmapPosition interface by executing 100 times,
1276 *           and calculates the delay time and average of Delay Time.
1277 */
BENCHMARK_F(AudioHdiRenderBenchmarkTest,SUB_DriverSystem_Benchmark_AudioRenderGetMmapPosition_0001)1278 BENCHMARK_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioRenderGetMmapPosition_0001)
1279     (benchmark::State &st)
1280 {
1281     int32_t ret = -1;
1282     uint64_t framesRendering = 0;
1283     struct PrepareAudioPara audiopara = {
1284         .portType = PORT_OUT, .adapterName = ADAPTER_NAME.c_str(), .pins = PIN_OUT_SPEAKER,
1285         .path = LOW_LATENCY_AUDIO_FILE.c_str(), .totalTime = 0
1286     };
1287     ASSERT_NE(nullptr, GetAudioManager);
1288     audiopara.manager = GetAudioManager();
1289     ASSERT_NE(nullptr, audiopara.manager);
1290     ret = AudioCreateRender(audiopara.manager, audiopara.pins, audiopara.adapterName, &audiopara.adapter,
1291                             &audiopara.render);
1292     ASSERT_EQ(AUDIO_HAL_SUCCESS, ret);
1293 
1294     ret = PlayMapAudioFile(audiopara);
1295     if (ret != 0) {
1296         audiopara.adapter->DestroyRender(audiopara.adapter, audiopara.render);
1297         audiopara.manager->UnloadAdapter(audiopara.manager, audiopara.adapter);
1298         audiopara.render = nullptr;
1299         audiopara.adapter = nullptr;
1300         ASSERT_EQ(AUDIO_HAL_SUCCESS, ret);
1301     }
1302     for (auto _ : st) {
1303         ret = audiopara.render->attr.GetMmapPosition(audiopara.render, &framesRendering, &(audiopara.time));
1304     }
1305 
1306     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
1307     audiopara.adapter->DestroyRender(audiopara.adapter, audiopara.render);
1308     audiopara.manager->UnloadAdapter(audiopara.manager, audiopara.adapter);
1309     audiopara.render = nullptr;
1310     audiopara.adapter = nullptr;
1311 }
1312 BENCHMARK_REGISTER_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioRenderGetMmapPosition_0001)->
1313     Iterations(100)->Repetitions(3)->ReportAggregatesOnly();
1314 /**
1315 * @tc.name  the performace of AudioRenderSetExtraParams
1316 * @tc.number  SUB_DriverSystem_Benchmark_AudioRenderSetExtraParams_0001
1317 * @tc.desc  tests the performace of AudioRenderSetExtraParams interface by executing 100 times,
1318 *           and calculates the delay time and average of Delay Time.
1319 */
BENCHMARK_F(AudioHdiRenderBenchmarkTest,SUB_DriverSystem_Benchmark_AudioRenderSetExtraParams_0001)1320 BENCHMARK_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioRenderSetExtraParams_0001)
1321     (benchmark::State &st)
1322 {
1323     int32_t ret = -1;
1324     char keyValueList[] = "attr-route=1;attr-format=32;attr-channels=2;attr-frame-count=82;attr-sampling-rate=48000";
1325     struct PrepareAudioPara audiopara = {
1326         .portType = PORT_OUT, .adapterName = ADAPTER_NAME.c_str(), .self = this, .pins = PIN_OUT_SPEAKER,
1327     };
1328     ASSERT_NE(nullptr, GetAudioManager);
1329     audiopara.manager = GetAudioManager();
1330     ASSERT_NE(nullptr, audiopara.manager);
1331     ret = AudioCreateStartRender(audiopara.manager, &audiopara.render, &audiopara.adapter, ADAPTER_NAME);
1332     ASSERT_EQ(AUDIO_HAL_SUCCESS, ret);
1333 
1334     for (auto _ : st) {
1335         ret = audiopara.render->attr.SetExtraParams((AudioHandle)audiopara.render, keyValueList);
1336     }
1337     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
1338     ret = StopAudio(audiopara);
1339     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
1340 }
1341 BENCHMARK_REGISTER_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioRenderSetExtraParams_0001)->
1342     Iterations(100)->Repetitions(3)->ReportAggregatesOnly();
1343 /**
1344 * @tc.name  the performace of AudioRenderGetExtraParams
1345 * @tc.number  SUB_DriverSystem_Benchmark_AudioRenderGetExtraParams_0001
1346 * @tc.desc  tests the performace of AudioRenderGetExtraParams interface by executing 100 times,
1347 *           and calculates the delay time and average of Delay Time.
1348 */
BENCHMARK_F(AudioHdiRenderBenchmarkTest,SUB_DriverSystem_Benchmark_AudioRenderGetExtraParams_0001)1349 BENCHMARK_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioRenderGetExtraParams_0001)
1350     (benchmark::State &st)
1351 {
1352     int32_t ret = -1;
1353     struct PrepareAudioPara audiopara = {
1354         .portType = PORT_OUT, .self = this, .pins = PIN_OUT_SPEAKER, .path = AUDIO_FILE.c_str()
1355     };
1356     char keyValueList[] = "attr-format=24;attr-frame-count=4096;";
1357     char keyValueListExp[] = "attr-route=0;attr-format=24;attr-channels=2;attr-frame-count=4096;\
1358 attr-sampling-rate=48000";
1359     int32_t listLenth = 256;
1360     ASSERT_NE(nullptr, GetAudioManager);
1361     audiopara.manager = GetAudioManager();
1362     ASSERT_NE(nullptr, audiopara.manager);
1363 
1364     ret = AudioCreateStartRender(audiopara.manager, &audiopara.render, &audiopara.adapter, ADAPTER_NAME);
1365     ASSERT_EQ(AUDIO_HAL_SUCCESS, ret);
1366     ret = audiopara.render->attr.SetExtraParams((AudioHandle)audiopara.render, keyValueList);
1367     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
1368     char keyValueListValue[256] = {};
1369     for (auto _ : st) {
1370         (void)memset_s(&keyValueListValue, sizeof(keyValueListValue), 0, sizeof(keyValueListValue));
1371         ret = audiopara.render->attr.GetExtraParams((AudioHandle)audiopara.render, keyValueListValue, listLenth);
1372     }
1373     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
1374     EXPECT_STREQ(keyValueListExp, keyValueListValue);
1375     ret = StopAudio(audiopara);
1376     EXPECT_EQ(AUDIO_HAL_SUCCESS, ret);
1377 }
1378 BENCHMARK_REGISTER_F(AudioHdiRenderBenchmarkTest, SUB_DriverSystem_Benchmark_AudioRenderGetExtraParams_0001)->
1379     Iterations(100)->Repetitions(3)->ReportAggregatesOnly();
1380 }
1381 BENCHMARK_MAIN();