• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include <benchmark/benchmark.h>
16 #include <climits>
17 #include <gtest/gtest.h>
18 #include "hdf_base.h"
19 #include "hdf_log.h"
20 #include "v1_0/effect_types.h"
21 #include "v1_0/ieffect_control.h"
22 #include "v1_0/ieffect_model.h"
23 #include "include/effect_common.h"
24 #include "osal_mem.h"
25 
26 using namespace std;
27 using namespace testing::ext;
28 constexpr bool IS_DIRECTLY_CALL = false;
29 /* the input buffer len of the send command */
30 constexpr uint32_t SEND_COMMAND_LEN = 10;
31 /* the output buffer len of the command */
32 constexpr uint32_t GET_BUFFER_LEN = 10;
33 # define AUDIO_EFFECT_COMMAND_INVALID_LARGE 20
34 
35 namespace {
36 const int32_t ITERATION_FREQUENCY = 100;
37 const int32_t REPETITION_FREQUENCY = 3;
38 class EffectControlBenchmarkTest : public benchmark::Fixture {
39 public:
40     struct IEffectControl *controller_ = nullptr;
41     struct IEffectModel *model_ = nullptr;
42     struct ControllerId contollerId_;
43     virtual void SetUp(const ::benchmark::State &state);
44     virtual void TearDown(const ::benchmark::State &state);
45     char *libName_ = nullptr;
46     char *effectId_ = nullptr;
47 };
48 
SetUp(const::benchmark::State & state)49 void EffectControlBenchmarkTest::SetUp(const ::benchmark::State &state)
50 {
51     // input testcase setup step,setup invoked before each testcases
52     libName_ = strdup("libmock_effect_lib");
53     effectId_ = strdup("aaaabbbb-8888-9999-6666-aabbccdd9966ff");
54     struct EffectInfo info = {
55         .libName = libName_,
56         .effectId = effectId_,
57         .ioDirection = 1,
58     };
59 
60     model_ = IEffectModelGet(IS_DIRECTLY_CALL);
61     ASSERT_NE(model_, nullptr);
62 
63     int32_t ret = model_->CreateEffectController(model_, &info, &controller_, &contollerId_);
64     ASSERT_EQ(ret, HDF_SUCCESS);
65     ASSERT_NE(controller_, nullptr);
66 }
67 
TearDown(const::benchmark::State & state)68 void EffectControlBenchmarkTest::TearDown(const ::benchmark::State &state)
69 {
70     // input testcase teardown step,teardown invoked after each testcases
71     if (libName_ != nullptr) {
72         free(libName_);
73         libName_ = nullptr;
74     }
75 
76     if (effectId_ != nullptr) {
77         free(effectId_);
78         effectId_ = nullptr;
79     }
80 
81     if (controller_ != nullptr && model_ != nullptr) {
82         int32_t ret = model_->DestroyEffectController(model_, &contollerId_);
83         EXPECT_EQ(ret, HDF_SUCCESS);
84     }
85 
86     if (model_ != nullptr) {
87         IEffectModelRelease(model_, IS_DIRECTLY_CALL);
88     }
89 }
90 
91 /**
92  * @tc.name: HdfAudioEffectProcess
93  * @tc.desc: Verify the EffectControlEffectProcess function.
94  */
BENCHMARK_F(EffectControlBenchmarkTest,HdfAudioEffectProcess)95 BENCHMARK_F(EffectControlBenchmarkTest, HdfAudioEffectProcess)(benchmark::State &state)
96 {
97     int32_t ret;
98     struct AudioEffectBuffer input = {0};
99     struct AudioEffectBuffer output = {0};
100     for (auto _ : state) {
101         ret = controller_->EffectProcess(controller_, &input, &output);
102     }
103     EXPECT_EQ(ret, HDF_SUCCESS);
104 }
105 BENCHMARK_REGISTER_F(EffectControlBenchmarkTest, HdfAudioEffectProcess)->
106     Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
107 
108 /**
109  * @tc.name: HdfAudioSendCommandInit
110  * @tc.desc: Verify the EffectControlEffectProcess function when cmdId is AUDIO_EFFECT_COMMAND_INIT_CONTOLLER.
111  */
BENCHMARK_F(EffectControlBenchmarkTest,HdfAudioSendCommandInit)112 BENCHMARK_F(EffectControlBenchmarkTest, HdfAudioSendCommandInit)(benchmark::State &state)
113 {
114     int32_t ret;
115     int8_t input[SEND_COMMAND_LEN] = {0};
116     int8_t output[GET_BUFFER_LEN] = {0};
117     uint32_t replyLen = GET_BUFFER_LEN;
118     for (auto _ : state) {
119         ret = controller_->SendCommand(controller_, AUDIO_EFFECT_COMMAND_INIT_CONTOLLER,
120                                            input, SEND_COMMAND_LEN, output, &replyLen);
121     }
122     EXPECT_EQ(ret, HDF_SUCCESS);
123 }
124 BENCHMARK_REGISTER_F(EffectControlBenchmarkTest, HdfAudioSendCommandInit)->
125     Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
126 /**
127  * @tc.name: HdfAudioGetDescriptor
128  * @tc.desc: Verify the EffectGetOwnDescriptor function.
129  */
BENCHMARK_F(EffectControlBenchmarkTest,HdfAudioGetDescriptor)130 BENCHMARK_F(EffectControlBenchmarkTest, HdfAudioGetDescriptor)(benchmark::State &state)
131 {
132     int32_t ret;
133     struct EffectControllerDescriptor desc;
134     for (auto _ : state) {
135         ret = controller_->GetEffectDescriptor(controller_, &desc);
136     }
137     ASSERT_EQ(ret, HDF_SUCCESS);
138     EffectControllerReleaseDesc(&desc);
139 }
140 BENCHMARK_REGISTER_F(EffectControlBenchmarkTest, HdfAudioGetDescriptor)->
141     Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
142 } // end of namespace
143