Signed-off-by: hwx1255622 <hechunrui@huawei.com>

Change-Id: I081a3a041750c17a75d73678247ac9b0cd947233
This commit is contained in:
hwx1255622 2024-03-09 19:15:27 +08:00
parent 037e077175
commit dbe46a3d41
5 changed files with 636 additions and 121 deletions

View File

@ -13,6 +13,7 @@
import("//build/test.gni")
import("//drivers/peripheral/audio/audio.gni")
import("//drivers/peripheral/display/display_config.gni")
import("//test/xts/tools/build/suite.gni")
module_output_path = "hats/audio"
@ -21,12 +22,15 @@ ohos_moduletest_suite("HatsHdfAudioBenchmarkTest") {
module_out_path = module_output_path
include_dirs = []
defines = []
defines += display_defines
sources = [
"adapter/audio_adapter_benchmarktest.cpp",
"capture/audio_capture_benchmarktest.cpp",
"manager/audio_manager_benchmarktest.cpp",
"render/audio_render_benchmarktest.cpp",
"render/audio_render_mmap_benchmarktest.cpp",
]
if (drivers_peripheral_audio_feature_offload) {

View File

@ -48,7 +48,7 @@ public:
void InitAttrs(struct AudioSampleAttributes &attrs);
void InitDevDesc(struct AudioDeviceDescriptor &devDesc);
void AudioAdapterDescriptorFree(struct AudioAdapterDescriptor *dataBlock, bool freeSelf);
void ReleaseAdapterDescs(struct AudioAdapterDescriptor **descs, uint32_t descsLen);
void ReleaseAdapterDescs(struct AudioAdapterDescriptor *descs, uint32_t descsLen);
};
void AudioAdapterBenchmarkTest::AudioAdapterDescriptorFree(struct AudioAdapterDescriptor *dataBlock, bool freeSelf)
@ -71,17 +71,15 @@ void AudioAdapterBenchmarkTest::AudioAdapterDescriptorFree(struct AudioAdapterDe
}
}
void AudioAdapterBenchmarkTest::ReleaseAdapterDescs(struct AudioAdapterDescriptor **descs, uint32_t descsLen)
void AudioAdapterBenchmarkTest::ReleaseAdapterDescs(struct AudioAdapterDescriptor *descs, uint32_t descsLen)
{
if ((descsLen > 0) && (descs != nullptr) && ((*descs) == nullptr)) {
if ((descs == nullptr) || (descsLen == 0)) {
return;
}
for (uint32_t i = 0; i < descsLen; i++) {
AudioAdapterDescriptorFree(&(*descs)[i], false);
AudioAdapterDescriptorFree(&descs[i], false);
}
OsalMemFree(*descs);
*descs = nullptr;
}
void AudioAdapterBenchmarkTest::InitAttrs(struct AudioSampleAttributes &attrs)
@ -123,17 +121,17 @@ void AudioAdapterBenchmarkTest::SetUp(const ::benchmark::State &state)
ASSERT_EQ(HDF_SUCCESS, manager_->GetAllAdapters(manager_, adapterDescs_, &size));
if (size > g_audioAdapterNumMax) {
ReleaseAdapterDescs(&adapterDescs_, g_audioAdapterNumMax);
ReleaseAdapterDescs(adapterDescs_, g_audioAdapterNumMax);
ASSERT_LT(size, g_audioAdapterNumMax);
}
if (manager_->LoadAdapter(manager_, &adapterDescs_[0], &adapter_) != HDF_SUCCESS) {
ReleaseAdapterDescs(&adapterDescs_, g_audioAdapterNumMax);
ReleaseAdapterDescs(adapterDescs_, g_audioAdapterNumMax);
ASSERT_TRUE(false);
}
if (adapter_ == nullptr) {
ReleaseAdapterDescs(&adapterDescs_, g_audioAdapterNumMax);
ReleaseAdapterDescs(adapterDescs_, g_audioAdapterNumMax);
ASSERT_TRUE(false);
}
}
@ -144,7 +142,7 @@ void AudioAdapterBenchmarkTest::TearDown(const ::benchmark::State &state)
ASSERT_NE(adapter_, nullptr);
manager_->UnloadAdapter(manager_, adapterDescs_[0].adapterName);
ReleaseAdapterDescs(&adapterDescs_, g_audioAdapterNumMax);
ReleaseAdapterDescs(adapterDescs_, g_audioAdapterNumMax);
adapter_ = nullptr;
IAudioManagerRelease(manager_, false);
manager_ = nullptr;
@ -152,18 +150,20 @@ void AudioAdapterBenchmarkTest::TearDown(const ::benchmark::State &state)
BENCHMARK_F(AudioAdapterBenchmarkTest, InitAllPorts)(benchmark::State &state)
{
ASSERT_NE(adapter_, nullptr);
int32_t ret;
for (auto _ : state) {
ret = adapter_->InitAllPorts(adapter_);
EXPECT_EQ(HDF_SUCCESS, ret);
}
EXPECT_EQ(HDF_SUCCESS, ret);
}
BENCHMARK_REGISTER_F(AudioAdapterBenchmarkTest, InitAllPorts)->
Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
BENCHMARK_F(AudioAdapterBenchmarkTest, CreateRender)(benchmark::State &state)
BENCHMARK_F(AudioAdapterBenchmarkTest, CreateRenderAndDestroyRender)(benchmark::State &state)
{
ASSERT_NE(adapter_, nullptr);
int32_t ret;
struct IAudioRender *render = nullptr;
struct AudioDeviceDescriptor devicedesc = {};
@ -182,15 +182,16 @@ BENCHMARK_F(AudioAdapterBenchmarkTest, CreateRender)(benchmark::State &state)
ASSERT_EQ(HDF_SUCCESS, adapter_->CreateRender(adapter_, &devicedesc, &attrs, &render, &renderId_));
}
ret = adapter_->DestroyRender(adapter_, renderId_);
EXPECT_EQ(HDF_SUCCESS, ret);
}
EXPECT_EQ(HDF_SUCCESS, ret);
}
BENCHMARK_REGISTER_F(AudioAdapterBenchmarkTest, CreateRender)->
BENCHMARK_REGISTER_F(AudioAdapterBenchmarkTest, CreateRenderAndDestroyRender)->
Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
BENCHMARK_F(AudioAdapterBenchmarkTest, CreateCapture)(benchmark::State &state)
BENCHMARK_F(AudioAdapterBenchmarkTest, CreateCaptureAndDestroyCapture)(benchmark::State &state)
{
ASSERT_NE(adapter_, nullptr);
int32_t ret;
struct IAudioCapture *capture = nullptr;
struct AudioDeviceDescriptor devicedesc = {};
@ -208,15 +209,16 @@ BENCHMARK_F(AudioAdapterBenchmarkTest, CreateCapture)(benchmark::State &state)
ASSERT_EQ(HDF_SUCCESS, adapter_->CreateCapture(adapter_, &devicedesc, &attrs, &capture, &captureId_));
}
ret = adapter_->DestroyCapture(adapter_, captureId_);
EXPECT_EQ(HDF_SUCCESS, ret);
}
EXPECT_EQ(HDF_SUCCESS, ret);
}
BENCHMARK_REGISTER_F(AudioAdapterBenchmarkTest, CreateCapture)->
BENCHMARK_REGISTER_F(AudioAdapterBenchmarkTest, CreateCaptureAndDestroyCapture)->
Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
BENCHMARK_F(AudioAdapterBenchmarkTest, GetPortCapability)(benchmark::State &state)
{
ASSERT_NE(adapter_, nullptr);
int32_t ret;
struct AudioPort port = {};
struct AudioPortCapability capability = {};
@ -226,8 +228,12 @@ BENCHMARK_F(AudioAdapterBenchmarkTest, GetPortCapability)(benchmark::State &stat
for (auto _ : state) {
ret = adapter_->GetPortCapability(adapter_, &port, &capability);
#ifdef DISPLAY_COMMUNITY
ASSERT_TRUE(ret == HDF_SUCCESS);
#else
ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT);
#endif
}
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
}
BENCHMARK_REGISTER_F(AudioAdapterBenchmarkTest, GetPortCapability)->
@ -235,6 +241,7 @@ BENCHMARK_REGISTER_F(AudioAdapterBenchmarkTest, GetPortCapability)->
BENCHMARK_F(AudioAdapterBenchmarkTest, SetPassthroughMode)(benchmark::State &state)
{
ASSERT_NE(adapter_, nullptr);
int32_t ret;
struct AudioPort port = {};
port.dir = PORT_OUT;
@ -244,8 +251,8 @@ BENCHMARK_F(AudioAdapterBenchmarkTest, SetPassthroughMode)(benchmark::State &sta
for (auto _ : state) {
ret = adapter_->SetPassthroughMode(adapter_, &port, mode);
ASSERT_TRUE(ret == HDF_FAILURE);
}
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_FAILURE);
}
BENCHMARK_REGISTER_F(AudioAdapterBenchmarkTest, SetPassthroughMode)->
@ -253,6 +260,7 @@ BENCHMARK_REGISTER_F(AudioAdapterBenchmarkTest, SetPassthroughMode)->
BENCHMARK_F(AudioAdapterBenchmarkTest, GetPassthroughMode)(benchmark::State &state)
{
ASSERT_NE(adapter_, nullptr);
int32_t ret;
struct AudioPort port = {};
port.dir = PORT_OUT;
@ -262,8 +270,8 @@ BENCHMARK_F(AudioAdapterBenchmarkTest, GetPassthroughMode)(benchmark::State &sta
for (auto _ : state) {
ret = adapter_->GetPassthroughMode(adapter_, &port, &mode);
ASSERT_TRUE(ret == HDF_FAILURE);
}
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_FAILURE);
}
BENCHMARK_REGISTER_F(AudioAdapterBenchmarkTest, GetPassthroughMode)->
@ -271,13 +279,14 @@ BENCHMARK_REGISTER_F(AudioAdapterBenchmarkTest, GetPassthroughMode)->
BENCHMARK_F(AudioAdapterBenchmarkTest, GetDeviceStatus)(benchmark::State &state)
{
ASSERT_NE(adapter_, nullptr);
int32_t ret;
struct AudioDeviceStatus status = {};
for (auto _ : state) {
ret = adapter_->GetDeviceStatus(adapter_, &status);
EXPECT_EQ(HDF_SUCCESS, ret);
}
EXPECT_EQ(HDF_SUCCESS, ret);
}
BENCHMARK_REGISTER_F(AudioAdapterBenchmarkTest, GetDeviceStatus)->
@ -285,13 +294,18 @@ BENCHMARK_REGISTER_F(AudioAdapterBenchmarkTest, GetDeviceStatus)->
BENCHMARK_F(AudioAdapterBenchmarkTest, SetMicMute)(benchmark::State &state)
{
ASSERT_NE(adapter_, nullptr);
int32_t ret;
bool mute = false;
for (auto _ : state) {
ret = adapter_->SetMicMute(adapter_, mute);
#ifdef DISPLAY_COMMUNITY
ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT);
#else
ASSERT_TRUE(ret == HDF_SUCCESS);
#endif
}
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
}
BENCHMARK_REGISTER_F(AudioAdapterBenchmarkTest, SetMicMute)->
@ -299,13 +313,18 @@ BENCHMARK_REGISTER_F(AudioAdapterBenchmarkTest, SetMicMute)->
BENCHMARK_F(AudioAdapterBenchmarkTest, GetMicMute)(benchmark::State &state)
{
ASSERT_NE(adapter_, nullptr);
int32_t ret;
bool mute = false;
for (auto _ : state) {
ret = adapter_->GetMicMute(adapter_, &mute);
#ifdef DISPLAY_COMMUNITY
ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT);
#else
ASSERT_TRUE(ret == HDF_SUCCESS);
#endif
}
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
}
BENCHMARK_REGISTER_F(AudioAdapterBenchmarkTest, GetMicMute)->
@ -313,13 +332,18 @@ BENCHMARK_REGISTER_F(AudioAdapterBenchmarkTest, GetMicMute)->
BENCHMARK_F(AudioAdapterBenchmarkTest, SetVoiceVolume)(benchmark::State &state)
{
ASSERT_NE(adapter_, nullptr);
int32_t ret;
float volume = 0;
for (auto _ : state) {
ret = adapter_->SetVoiceVolume(adapter_, volume);
#ifdef DISPLAY_COMMUNITY
ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT);
#else
ASSERT_TRUE(ret == HDF_SUCCESS);
#endif
}
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
}
BENCHMARK_REGISTER_F(AudioAdapterBenchmarkTest, SetVoiceVolume)->
@ -327,6 +351,7 @@ BENCHMARK_REGISTER_F(AudioAdapterBenchmarkTest, SetVoiceVolume)->
BENCHMARK_F(AudioAdapterBenchmarkTest, SetExtraParams)(benchmark::State &state)
{
ASSERT_NE(adapter_, nullptr);
int32_t ret;
enum AudioExtParamKey key = AUDIO_EXT_PARAM_KEY_LOWPOWER;
char condition[AUDIO_ADAPTER_BUF_TEST];
@ -334,8 +359,12 @@ BENCHMARK_F(AudioAdapterBenchmarkTest, SetExtraParams)(benchmark::State &state)
for (auto _ : state) {
ret = adapter_->SetExtraParams(adapter_, key, condition, value);
#ifdef DISPLAY_COMMUNITY
ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT);
#else
ASSERT_TRUE(ret == HDF_SUCCESS);
#endif
}
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
}
BENCHMARK_REGISTER_F(AudioAdapterBenchmarkTest, SetExtraParams)->
@ -343,6 +372,7 @@ BENCHMARK_REGISTER_F(AudioAdapterBenchmarkTest, SetExtraParams)->
BENCHMARK_F(AudioAdapterBenchmarkTest, GetExtraParams)(benchmark::State &state)
{
ASSERT_NE(adapter_, nullptr);
int32_t ret;
enum AudioExtParamKey key = AUDIO_EXT_PARAM_KEY_NONE;
char condition[AUDIO_ADAPTER_BUF_TEST];
@ -350,8 +380,12 @@ BENCHMARK_F(AudioAdapterBenchmarkTest, GetExtraParams)(benchmark::State &state)
uint32_t valueLen = AUDIO_ADAPTER_BUF_TEST;
for (auto _ : state) {
ret = adapter_->GetExtraParams(adapter_, key, condition, value, valueLen);
#ifdef DISPLAY_COMMUNITY
ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT);
#else
ASSERT_TRUE(ret == HDF_FAILURE);
#endif
}
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
}
BENCHMARK_REGISTER_F(AudioAdapterBenchmarkTest, GetExtraParams)->
@ -398,7 +432,11 @@ BENCHMARK_F(AudioAdapterBenchmarkTest, RegExtraParamObserver)(benchmark::State &
for (auto _ : state) {
ret = adapter_->RegExtraParamObserver(adapter_, audioCallback, cookie);
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_INVALID_PARAM);
#ifdef DISPLAY_COMMUNITY
EXPECT_NE(ret, HDF_SUCCESS);
#else
ASSERT_TRUE(ret == HDF_ERR_INVALID_PARAM);
#endif
}
}

View File

@ -35,6 +35,8 @@ const int TEST_SAMPLE_RATE_MASK_48000 = 48000;
const int TEST_CHANNEL_COUNT = 2;
const int32_t ITERATION_FREQUENCY = 100;
const int32_t REPETITION_FREQUENCY = 3;
const int32_t RANGE_VALUE = 4;
const float GAIN_VALUE = 1.0;
const int32_t MMAP_SUGGUEST_REQ_SIZE = 1920;
class AudioCaptureBenchmarkTest : public benchmark::Fixture {
@ -51,7 +53,7 @@ public:
void InitCaptureDevDesc(struct AudioDeviceDescriptor &devDesc);
void InitCaptureAttrs(struct AudioSampleAttributes &attrs);
void FreeAdapterElements(struct AudioAdapterDescriptor *dataBlock, bool freeSelf);
void ReleaseAllAdapterDescs(struct AudioAdapterDescriptor **descs, uint32_t descsLen);
void ReleaseAllAdapterDescs(struct AudioAdapterDescriptor *descs, uint32_t descsLen);
};
uint64_t AudioCaptureBenchmarkTest::GetCaptureBufferSize()
@ -135,14 +137,13 @@ void AudioCaptureBenchmarkTest::FreeAdapterElements(struct AudioAdapterDescripto
}
}
void AudioCaptureBenchmarkTest::ReleaseAllAdapterDescs(struct AudioAdapterDescriptor **descs, uint32_t descsLen)
void AudioCaptureBenchmarkTest::ReleaseAllAdapterDescs(struct AudioAdapterDescriptor *descs, uint32_t descsLen)
{
if ((descsLen > 0) && (descs != nullptr) && ((*descs) != nullptr)) {
if (descs == nullptr || descsLen == 0) {
return;
}
for (uint32_t i = 0; i < descsLen; i++) {
FreeAdapterElements(&(*descs)[i], false);
}
OsalMemFree(*descs);
*descs = nullptr;
FreeAdapterElements(&descs[i], false);
}
}
@ -161,13 +162,13 @@ void AudioCaptureBenchmarkTest::SetUp(const ::benchmark::State &state)
EXPECT_EQ(HDF_SUCCESS, manager_->GetAllAdapters(manager_, adapterDescs_, &size));
if (size > MAX_AUDIO_ADAPTER_NUM) {
ReleaseAllAdapterDescs(&adapterDescs_, MAX_AUDIO_ADAPTER_NUM);
ReleaseAllAdapterDescs(adapterDescs_, MAX_AUDIO_ADAPTER_NUM);
ASSERT_LT(size, MAX_AUDIO_ADAPTER_NUM);
}
EXPECT_EQ(HDF_SUCCESS, manager_->LoadAdapter(manager_, &adapterDescs_[0], &adapter_));
if (adapter_ == nullptr) {
ReleaseAllAdapterDescs(&adapterDescs_, MAX_AUDIO_ADAPTER_NUM);
ReleaseAllAdapterDescs(adapterDescs_, MAX_AUDIO_ADAPTER_NUM);
EXPECT_NE(adapter_, nullptr);
}
@ -176,7 +177,7 @@ void AudioCaptureBenchmarkTest::SetUp(const ::benchmark::State &state)
EXPECT_EQ(HDF_SUCCESS, adapter_->CreateCapture(adapter_, &devDesc, &attrs, &capture_, &captureId_));
if (capture_ == nullptr) {
(void)manager_->UnloadAdapter(manager_, adapterDescs_[0].adapterName);
ReleaseAllAdapterDescs(&adapterDescs_, MAX_AUDIO_ADAPTER_NUM);
ReleaseAllAdapterDescs(adapterDescs_, MAX_AUDIO_ADAPTER_NUM);
}
ASSERT_NE(capture_, nullptr);
}
@ -191,13 +192,14 @@ void AudioCaptureBenchmarkTest::TearDown(const ::benchmark::State &state)
ASSERT_NE(manager_, nullptr);
EXPECT_EQ(HDF_SUCCESS, manager_->UnloadAdapter(manager_, adapterDescs_[0].adapterName));
ReleaseAllAdapterDescs(&adapterDescs_, MAX_AUDIO_ADAPTER_NUM);
ReleaseAllAdapterDescs(adapterDescs_, MAX_AUDIO_ADAPTER_NUM);
IAudioManagerRelease(manager_, false);
}
BENCHMARK_F(AudioCaptureBenchmarkTest, CaptureFrame)(benchmark::State &state)
{
ASSERT_NE(capture_, nullptr);
uint32_t frameLen = (uint64_t)GetCaptureBufferSize();
uint64_t requestBytes = frameLen;
@ -209,8 +211,9 @@ BENCHMARK_F(AudioCaptureBenchmarkTest, CaptureFrame)(benchmark::State &state)
for (auto _ : state) {
ret = capture_->CaptureFrame(capture_, frame, &frameLen, &requestBytes);
EXPECT_EQ(ret, HDF_SUCCESS);
}
EXPECT_EQ(ret, HDF_SUCCESS);
capture_->Stop(capture_);
if (frame != nullptr) {
@ -224,6 +227,7 @@ BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, CaptureFrame)->
BENCHMARK_F(AudioCaptureBenchmarkTest, GetCapturePosition)(benchmark::State &state)
{
ASSERT_NE(capture_, nullptr);
uint64_t frames;
struct AudioTimeStamp time;
uint32_t frameLen = (uint64_t)GetCaptureBufferSize();
@ -240,8 +244,9 @@ BENCHMARK_F(AudioCaptureBenchmarkTest, GetCapturePosition)(benchmark::State &sta
for (auto _ : state) {
ret = capture_->GetCapturePosition(capture_, &frames, &time);
ASSERT_TRUE(ret == HDF_SUCCESS);
}
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
capture_->Stop(capture_);
if (frame != nullptr) {
@ -255,12 +260,15 @@ BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetCapturePosition)->
BENCHMARK_F(AudioCaptureBenchmarkTest, StartAndStop)(benchmark::State &state)
{
ASSERT_NE(capture_, nullptr);
int32_t ret;
for (auto _ : state) {
ret = capture_->Start(capture_);
EXPECT_EQ(ret, HDF_SUCCESS);
ret = capture_->Stop(capture_);
EXPECT_EQ(ret, HDF_SUCCESS);
}
EXPECT_EQ(ret, HDF_SUCCESS);
}
BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, StartAndStop)->
@ -268,13 +276,20 @@ BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, StartAndStop)->
BENCHMARK_F(AudioCaptureBenchmarkTest, Pause)(benchmark::State &state)
{
ASSERT_NE(capture_, nullptr);
int32_t ret = capture_->Start(capture_);
EXPECT_EQ(ret, HDF_SUCCESS);
for (auto _ : state) {
ret = capture_->Pause(capture_);
#ifdef DISPLAY_COMMUNITY
ASSERT_EQ(ret, HDF_SUCCESS);
#else
ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT);
#endif
}
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT || ret == HDF_ERR_INVALID_PARAM);
ret = capture_->Stop(capture_);
ASSERT_EQ(ret, HDF_SUCCESS);
}
BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, Pause)->
@ -282,17 +297,25 @@ BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, Pause)->
BENCHMARK_F(AudioCaptureBenchmarkTest, Resume)(benchmark::State &state)
{
ASSERT_NE(capture_, nullptr);
int32_t ret = capture_->Start(capture_);
EXPECT_EQ(ret, HDF_SUCCESS);
ret = capture_->Pause(capture_);
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
#ifdef DISPLAY_COMMUNITY
ASSERT_TRUE(ret == HDF_SUCCESS);
#else
ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT);
#endif
for (auto _ : state) {
ret = capture_->Resume(capture_);
#ifdef DISPLAY_COMMUNITY
ASSERT_TRUE(ret == HDF_SUCCESS);
#else
ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT);
#endif
}
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
ret = capture_->Stop(capture_);
ASSERT_EQ(ret, HDF_SUCCESS);
}
@ -302,11 +325,13 @@ BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, Resume)->
BENCHMARK_F(AudioCaptureBenchmarkTest, Flush)(benchmark::State &state)
{
ASSERT_NE(capture_, nullptr);
int32_t ret;
for (auto _ : state) {
ret = capture_->Flush(capture_);
EXPECT_NE(ret, HDF_SUCCESS);
}
EXPECT_NE(ret, HDF_SUCCESS);
}
BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, Flush)->
@ -314,12 +339,16 @@ BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, Flush)->
BENCHMARK_F(AudioCaptureBenchmarkTest, TurnStandbyMode)(benchmark::State &state)
{
ASSERT_NE(capture_, nullptr);
int32_t ret;
for (auto _ : state) {
ret = capture_->Start(capture_);
EXPECT_EQ(ret, HDF_SUCCESS);
ret = capture_->TurnStandbyMode(capture_);
EXPECT_EQ(ret, HDF_SUCCESS);
capture_->Stop(capture_);
}
EXPECT_EQ(ret, HDF_SUCCESS);
}
BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, TurnStandbyMode)->
@ -327,8 +356,9 @@ BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, TurnStandbyMode)->
BENCHMARK_F(AudioCaptureBenchmarkTest, AudioDevDump)(benchmark::State &state)
{
ASSERT_NE(capture_, nullptr);
int32_t ret;
int32_t range = 4;
int32_t range = RANGE_VALUE;
char pathBuf[] = "/data/CaptureDump.log";
FILE *file = fopen(pathBuf, "wb+");
@ -341,8 +371,12 @@ BENCHMARK_F(AudioCaptureBenchmarkTest, AudioDevDump)(benchmark::State &state)
for (auto _ : state) {
ret = capture_->AudioDevDump(capture_, range, fd);
#ifdef DISPLAY_COMMUNITY
ASSERT_TRUE(ret == HDF_SUCCESS);
#else
ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT);
#endif
}
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
fclose(file);
}
@ -351,13 +385,18 @@ BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, AudioDevDump)->
BENCHMARK_F(AudioCaptureBenchmarkTest, SetMute)(benchmark::State &state)
{
ASSERT_NE(capture_, nullptr);
int32_t ret;
bool isSupport = false;
for (auto _ : state) {
ret = capture_->SetMute(capture_, isSupport);
#ifdef DISPLAY_COMMUNITY
ASSERT_TRUE(ret == HDF_SUCCESS);
#else
ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT);
#endif
}
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
}
BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, SetMute)->
@ -365,13 +404,18 @@ BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, SetMute)->
BENCHMARK_F(AudioCaptureBenchmarkTest, GetMute)(benchmark::State &state)
{
ASSERT_NE(capture_, nullptr);
int32_t ret;
bool isSupport = true;
for (auto _ : state) {
ret = capture_->GetMute(capture_, &isSupport);
#ifdef DISPLAY_COMMUNITY
ASSERT_TRUE(ret == HDF_SUCCESS);
#else
ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT);
#endif
}
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
}
BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetMute)->
@ -379,11 +423,16 @@ BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetMute)->
BENCHMARK_F(AudioCaptureBenchmarkTest, SetVolume)(benchmark::State &state)
{
ASSERT_NE(capture_, nullptr);
int32_t ret;
for (auto _ : state) {
ret = capture_->SetVolume(capture_, HALF_OF_MAX_VOLUME);
#ifdef DISPLAY_COMMUNITY
ASSERT_TRUE(ret == HDF_SUCCESS);
#else
ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT);
#endif
}
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
}
BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, SetVolume)->
@ -391,13 +440,18 @@ BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, SetVolume)->
BENCHMARK_F(AudioCaptureBenchmarkTest, GetVolume)(benchmark::State &state)
{
ASSERT_NE(capture_, nullptr);
int32_t ret;
float volume = 0.0;
for (auto _ : state) {
ret = capture_->GetVolume(capture_, &volume);
#ifdef DISPLAY_COMMUNITY
ASSERT_TRUE(ret == HDF_SUCCESS);
#else
ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT);
#endif
}
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
}
BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetVolume)->
@ -405,14 +459,19 @@ BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetVolume)->
BENCHMARK_F(AudioCaptureBenchmarkTest, GetGainThreshold)(benchmark::State &state)
{
ASSERT_NE(capture_, nullptr);
int32_t ret;
float bottom = 0;
float top = 0;
float bottom = 0.0;
float top = 0.0;
for (auto _ : state) {
ret = capture_->GetGainThreshold(capture_, &bottom, &top);
#ifdef DISPLAY_COMMUNITY
ASSERT_TRUE(ret == HDF_SUCCESS);
#else
ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT);
#endif
}
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
}
BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetGainThreshold)->
@ -420,14 +479,19 @@ BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetGainThreshold)->
BENCHMARK_F(AudioCaptureBenchmarkTest, SetSampleAttributes)(benchmark::State &state)
{
ASSERT_NE(capture_, nullptr);
int32_t ret;
struct AudioSampleAttributes attrs;
InitCaptureAttrs(attrs);
for (auto _ : state) {
ret = capture_->SetSampleAttributes(capture_, &attrs);
#ifdef DISPLAY_COMMUNITY
ASSERT_TRUE(ret == HDF_SUCCESS);
#else
ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT);
#endif
}
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
}
BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, SetSampleAttributes)->
@ -435,13 +499,15 @@ BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, SetSampleAttributes)->
BENCHMARK_F(AudioCaptureBenchmarkTest, GetSampleAttributes)(benchmark::State &state)
{
ASSERT_NE(capture_, nullptr);
int32_t ret;
struct AudioSampleAttributes attrs = {};
for (auto _ : state) {
ret = capture_->GetSampleAttributes(capture_, &attrs);
EXPECT_EQ(ret, HDF_SUCCESS);
}
EXPECT_EQ(ret, HDF_SUCCESS);
}
BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetSampleAttributes)->
@ -449,13 +515,14 @@ BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetSampleAttributes)->
BENCHMARK_F(AudioCaptureBenchmarkTest, GetCurrentChannelId)(benchmark::State &state)
{
ASSERT_NE(capture_, nullptr);
int32_t ret;
uint32_t channelId = 0;
for (auto _ : state) {
ret = capture_->GetCurrentChannelId(capture_, &channelId);
EXPECT_EQ(ret, HDF_SUCCESS);
}
EXPECT_EQ(ret, HDF_SUCCESS);
}
BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetCurrentChannelId)->
@ -463,14 +530,19 @@ BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetCurrentChannelId)->
BENCHMARK_F(AudioCaptureBenchmarkTest, SetExtraParams)(benchmark::State &state)
{
ASSERT_NE(capture_, nullptr);
int32_t ret;
char keyValueList[AUDIO_CAPTURE_BUF_TEST] =
"attr-route=1;attr-format=32;attr-channels=2;attr-frame-count=82;attr-sampling-rate=48000";
for (auto _ : state) {
ret = capture_->SetExtraParams(capture_, keyValueList);
#ifdef DISPLAY_COMMUNITY
ASSERT_TRUE(ret == HDF_SUCCESS);
#else
ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT);
#endif
}
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
}
BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, SetExtraParams)->
@ -478,14 +550,19 @@ BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, SetExtraParams)->
BENCHMARK_F(AudioCaptureBenchmarkTest, GetExtraParams)(benchmark::State &state)
{
ASSERT_NE(capture_, nullptr);
int32_t ret;
char keyValueListReply[AUDIO_CAPTURE_BUF_TEST] = {};
uint32_t listLenth = AUDIO_CAPTURE_BUF_TEST;
for (auto _ : state) {
ret = capture_->GetExtraParams(capture_, keyValueListReply, listLenth);
#ifdef DISPLAY_COMMUNITY
ASSERT_TRUE(ret == HDF_SUCCESS);
#else
ASSERT_TRUE(ret == HDF_ERR_INVALID_PARAM);
#endif
}
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_INVALID_PARAM);
}
BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetExtraParams)->
@ -493,6 +570,7 @@ BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetExtraParams)->
BENCHMARK_F(AudioCaptureBenchmarkTest, SelectScene)(benchmark::State &state)
{
ASSERT_NE(capture_, nullptr);
int32_t ret;
struct AudioSceneDescriptor scene;
scene.scene.id = AUDIO_IN_MEDIA;
@ -501,8 +579,8 @@ BENCHMARK_F(AudioCaptureBenchmarkTest, SelectScene)(benchmark::State &state)
for (auto _ : state) {
ret = capture_->SelectScene(capture_, &scene);
EXPECT_EQ(ret, HDF_SUCCESS);
}
EXPECT_EQ(ret, HDF_SUCCESS);
}
BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, SelectScene)->
@ -510,13 +588,18 @@ BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, SelectScene)->
BENCHMARK_F(AudioCaptureBenchmarkTest, SetGain)(benchmark::State &state)
{
ASSERT_NE(capture_, nullptr);
int32_t ret;
float gain = 1.0;
float gain = GAIN_VALUE;
for (auto _ : state) {
ret = capture_->SetGain(capture_, gain);
#ifdef DISPLAY_COMMUNITY
ASSERT_TRUE(ret == HDF_SUCCESS);
#else
ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT);
#endif
}
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
}
BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, SetGain)->
@ -524,13 +607,18 @@ BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, SetGain)->
BENCHMARK_F(AudioCaptureBenchmarkTest, GetGain)(benchmark::State &state)
{
ASSERT_NE(capture_, nullptr);
int32_t ret;
float gain;
for (auto _ : state) {
ret = capture_->GetGain(capture_, &gain);
#ifdef DISPLAY_COMMUNITY
ASSERT_TRUE(ret == HDF_SUCCESS);
#else
ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT);
#endif
}
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
}
BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetGain)->
@ -538,6 +626,7 @@ BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetGain)->
BENCHMARK_F(AudioCaptureBenchmarkTest, GetMmapPosition)(benchmark::State &state)
{
ASSERT_NE(capture_, nullptr);
int32_t ret;
uint64_t frames = 0;
struct AudioTimeStamp time;
@ -546,8 +635,12 @@ BENCHMARK_F(AudioCaptureBenchmarkTest, GetMmapPosition)(benchmark::State &state)
for (auto _ : state) {
ret = capture_->GetMmapPosition(capture_, &frames, &time);
#ifdef DISPLAY_COMMUNITY
ASSERT_TRUE(ret == HDF_SUCCESS);
#else
ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT);
#endif
}
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
}
BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetMmapPosition)->
@ -555,13 +648,14 @@ BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetMmapPosition)->
BENCHMARK_F(AudioCaptureBenchmarkTest, GetFrameSize)(benchmark::State &state)
{
ASSERT_NE(capture_, nullptr);
int32_t ret;
uint64_t frameSize = 0;
for (auto _ : state) {
ret = capture_->GetFrameSize(capture_, &frameSize);
EXPECT_EQ(ret, HDF_SUCCESS);
}
EXPECT_EQ(ret, HDF_SUCCESS);
}
BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetFrameSize)->
@ -569,13 +663,14 @@ BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetFrameSize)->
BENCHMARK_F(AudioCaptureBenchmarkTest, GetFrameCount)(benchmark::State &state)
{
ASSERT_NE(capture_, nullptr);
int32_t ret;
uint64_t frameCount = 0;
for (auto _ : state) {
ret = capture_->GetFrameCount(capture_, &frameCount);
EXPECT_EQ(ret, HDF_SUCCESS);
}
EXPECT_EQ(ret, HDF_SUCCESS);
}
BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetFrameCount)->
@ -583,6 +678,7 @@ BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, GetFrameCount)->
BENCHMARK_F(AudioCaptureBenchmarkTest, CheckSceneCapability)(benchmark::State &state)
{
ASSERT_NE(capture_, nullptr);
int32_t ret;
bool supported = false;
struct AudioSceneDescriptor scenes = {};
@ -591,8 +687,8 @@ BENCHMARK_F(AudioCaptureBenchmarkTest, CheckSceneCapability)(benchmark::State &s
scenes.desc.desc = strdup("mic");
for (auto _ : state) {
ret = capture_->CheckSceneCapability(capture_, &scenes, &supported);
EXPECT_EQ(HDF_SUCCESS, ret);
}
EXPECT_EQ(HDF_SUCCESS, ret);
free(scenes.desc.desc);
}
BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, CheckSceneCapability)->
@ -600,12 +696,17 @@ BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, CheckSceneCapability)->
BENCHMARK_F(AudioCaptureBenchmarkTest, ReqMmapBuffer)(benchmark::State &state)
{
ASSERT_NE(capture_, nullptr);
int32_t ret;
struct AudioMmapBufferDescriptor desc = {0};
for (auto _ : state) {
ret = capture_->ReqMmapBuffer(capture_, MMAP_SUGGUEST_REQ_SIZE, &desc);
#ifdef DISPLAY_COMMUNITY
ASSERT_TRUE(ret == HDF_ERR_INVALID_PARAM);
#else
ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT);
#endif
}
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT ||ret == HDF_ERR_INVALID_PARAM);
}
BENCHMARK_REGISTER_F(AudioCaptureBenchmarkTest, ReqMmapBuffer)->
Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
@ -618,10 +719,18 @@ BENCHMARK_F(AudioCaptureBenchmarkTest, AddAndRemoveAudioEffect)(benchmark::State
for (auto _ : state) {
ret = capture_->AddAudioEffect(capture_, effectId);
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT || ret == HDF_ERR_INVALID_PARAM);
#ifdef DISPLAY_COMMUNITY
ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT);
#else
ASSERT_TRUE(ret == HDF_ERR_INVALID_PARAM);
#endif
ret = capture_->RemoveAudioEffect(capture_, effectId);
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT || ret == HDF_ERR_INVALID_PARAM);
#ifdef DISPLAY_COMMUNITY
ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT);
#else
ASSERT_TRUE(ret == HDF_ERR_INVALID_PARAM);
#endif
}
}
@ -636,7 +745,11 @@ BENCHMARK_F(AudioCaptureBenchmarkTest, GetFrameBufferSize)(benchmark::State &sta
for (auto _ : state) {
ret = capture_->GetFrameBufferSize(capture_, &bufferSize);
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT || ret == HDF_ERR_INVALID_PARAM);
#ifdef DISPLAY_COMMUNITY
ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT);
#else
ASSERT_TRUE(ret == HDF_ERR_INVALID_PARAM);
#endif
}
}
@ -652,7 +765,11 @@ BENCHMARK_F(AudioCaptureBenchmarkTest, IsSupportsPauseAndResume)(benchmark::Stat
for (auto _ : state) {
ret = capture_->IsSupportsPauseAndResume(capture_, &supportPause, &supportResume);
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT || ret == HDF_ERR_INVALID_PARAM);
#ifdef DISPLAY_COMMUNITY
ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT);
#else
ASSERT_TRUE(ret == HDF_ERR_INVALID_PARAM);
#endif
}
}

View File

@ -38,7 +38,9 @@ const int32_t MAX_AUDIO_ADAPTER_DESC = 5;
const uint64_t DEFAULT_BUFFER_SIZE = 16384;
const int32_t ITERATION_FREQUENCY = 100;
const int32_t REPETITION_FREQUENCY = 3;
const int32_t MMAP_SUGGEST_BUFFER_SIZE = 1920;
const int32_t RANGE_VALUE = 4;
const float GAIN_VALUE = 1.0;
const float VOLUNE_VALUE = 0.2;
class AudioRenderBenchmarkTest : public benchmark::Fixture {
public:
@ -50,6 +52,7 @@ public:
struct AudioDeviceDescriptor devDescRender_ = {};
struct AudioSampleAttributes attrsRender_ = {};
uint32_t renderId_ = 0;
char *devDescriptorName_ = nullptr;
uint32_t size_ = MAX_AUDIO_ADAPTER_DESC;
virtual void SetUp(const ::benchmark::State &state);
virtual void TearDown(const ::benchmark::State &state);
@ -117,7 +120,6 @@ void AudioRenderBenchmarkTest::InitRenderDevDesc(struct AudioDeviceDescriptor &d
return;
}
}
free(devDesc.desc);
}
void AudioRenderBenchmarkTest::FreeAdapterElements(struct AudioAdapterDescriptor *dataBlock, bool freeSelf)
@ -171,6 +173,8 @@ void AudioRenderBenchmarkTest::SetUp(const ::benchmark::State &state)
void AudioRenderBenchmarkTest::TearDown(const ::benchmark::State &state)
{
ASSERT_NE(devDescriptorName_, nullptr);
free(devDescriptorName_);
if (adapter_ != nullptr) {
adapter_->DestroyRender(adapter_, renderId_);
render_ = nullptr;
@ -186,12 +190,14 @@ void AudioRenderBenchmarkTest::TearDown(const ::benchmark::State &state)
BENCHMARK_F(AudioRenderBenchmarkTest, StartAndStop)(benchmark::State &state)
{
ASSERT_NE(render_, nullptr);
int32_t ret;
for (auto _ : state) {
ret = render_->Start(render_);
EXPECT_EQ(ret, HDF_SUCCESS);
ret = render_->Stop(render_);
EXPECT_EQ(ret, HDF_SUCCESS);
}
EXPECT_EQ(ret, HDF_SUCCESS);
}
BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, StartAndStop)->
@ -199,13 +205,21 @@ BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, StartAndStop)->
BENCHMARK_F(AudioRenderBenchmarkTest, Pause)(benchmark::State &state)
{
ASSERT_NE(render_, nullptr);
int32_t ret = render_->Start(render_);
EXPECT_EQ(ret, HDF_SUCCESS);
for (auto _ : state) {
ret = render_->Pause(render_);
//ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT || ret == HDF_ERR_INVALID_PARAM);
#ifdef DISPLAY_COMMUNITY
ASSERT_TRUE(ret == HDF_ERR_INVALID_PARAM);
#else
ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT);
#endif
}
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT || ret == HDF_ERR_INVALID_PARAM);
ret = render_->Stop(render_);
ASSERT_EQ(ret, HDF_SUCCESS);
}
BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, Pause)->
@ -213,16 +227,25 @@ BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, Pause)->
BENCHMARK_F(AudioRenderBenchmarkTest, Resume)(benchmark::State &state)
{
ASSERT_NE(render_, nullptr);
int32_t ret = render_->Start(render_);
EXPECT_EQ(ret, HDF_SUCCESS);
ret = render_->Pause(render_);
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
#ifdef DISPLAY_COMMUNITY
ASSERT_TRUE(ret == HDF_SUCCESS);
#else
ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT);
#endif
for (auto _ : state) {
ret = render_->Resume(render_);
#ifdef DISPLAY_COMMUNITY
ASSERT_TRUE(ret == HDF_SUCCESS);
#else
ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT);
#endif
}
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
ret = render_->Stop(render_);
ASSERT_EQ(ret, HDF_SUCCESS);
@ -233,11 +256,12 @@ BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, Resume)->
BENCHMARK_F(AudioRenderBenchmarkTest, Flush)(benchmark::State &state)
{
ASSERT_NE(render_, nullptr);
int32_t ret;
for (auto _ : state) {
ret = render_->Flush(render_);
EXPECT_NE(ret, HDF_SUCCESS);
}
EXPECT_NE(ret, HDF_SUCCESS);
}
BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, Flush)->
@ -245,12 +269,15 @@ BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, Flush)->
BENCHMARK_F(AudioRenderBenchmarkTest, TurnStandbyMode)(benchmark::State &state)
{
ASSERT_NE(render_, nullptr);
int32_t ret;
for (auto _ : state) {
ret = render_->Start(render_);
EXPECT_EQ(ret, HDF_SUCCESS);
ret = render_->TurnStandbyMode(render_);
EXPECT_EQ(ret, HDF_SUCCESS);
render_->Stop(render_);
}
EXPECT_EQ(ret, HDF_SUCCESS);
}
BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, TurnStandbyMode)->
@ -258,8 +285,9 @@ BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, TurnStandbyMode)->
BENCHMARK_F(AudioRenderBenchmarkTest, AudioDevDump)(benchmark::State &state)
{
ASSERT_NE(render_, nullptr);
int32_t ret;
int32_t range = 4;
int32_t range = RANGE_VALUE;
char pathBuf[] = "/data/RenderDump.log";
FILE *file = fopen(pathBuf, "wb+");
@ -272,8 +300,12 @@ BENCHMARK_F(AudioRenderBenchmarkTest, AudioDevDump)(benchmark::State &state)
for (auto _ : state) {
ret = render_->AudioDevDump(render_, range, fd);
#ifdef DISPLAY_COMMUNITY
ASSERT_TRUE(ret == HDF_SUCCESS);
#else
ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT);
#endif
}
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
fclose(file);
}
@ -282,13 +314,14 @@ BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, AudioDevDump)->
BENCHMARK_F(AudioRenderBenchmarkTest, GetFrameSize)(benchmark::State &state)
{
ASSERT_NE(render_, nullptr);
int32_t ret;
uint64_t frameSize = 0;
for (auto _ : state) {
ret = render_->GetFrameSize(render_, &frameSize);
EXPECT_EQ(ret, HDF_SUCCESS);
}
EXPECT_EQ(ret, HDF_SUCCESS);
}
BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, GetFrameSize)->
@ -296,13 +329,14 @@ BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, GetFrameSize)->
BENCHMARK_F(AudioRenderBenchmarkTest, GetFrameCount)(benchmark::State &state)
{
ASSERT_NE(render_, nullptr);
int32_t ret;
uint64_t frameCount = 0;
for (auto _ : state) {
ret = render_->GetFrameCount(render_, &frameCount);
EXPECT_EQ(ret, HDF_SUCCESS);
}
EXPECT_EQ(ret, HDF_SUCCESS);
}
BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, GetFrameCount)->
@ -310,12 +344,13 @@ BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, GetFrameCount)->
BENCHMARK_F(AudioRenderBenchmarkTest, SetSampleAttributes)(benchmark::State &state)
{
ASSERT_NE(render_, nullptr);
int32_t ret;
struct AudioSampleAttributes attrs = attrsRender_;
for (auto _ : state) {
ret = render_->SetSampleAttributes(render_, &attrs);
EXPECT_EQ(ret, HDF_SUCCESS);
}
EXPECT_EQ(ret, HDF_SUCCESS);
}
BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, SetSampleAttributes)->
@ -323,13 +358,14 @@ BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, SetSampleAttributes)->
BENCHMARK_F(AudioRenderBenchmarkTest, GetSampleAttributes)(benchmark::State &state)
{
ASSERT_NE(render_, nullptr);
int32_t ret;
struct AudioSampleAttributes attrs = {};
for (auto _ : state) {
ret = render_->GetSampleAttributes(render_, &attrs);
EXPECT_EQ(ret, HDF_SUCCESS);
}
EXPECT_EQ(ret, HDF_SUCCESS);
}
BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, GetSampleAttributes)->
@ -337,13 +373,14 @@ BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, GetSampleAttributes)->
BENCHMARK_F(AudioRenderBenchmarkTest, GetCurrentChannelId)(benchmark::State &state)
{
ASSERT_NE(render_, nullptr);
int32_t ret;
uint32_t channelId = 0;
for (auto _ : state) {
ret = render_->GetCurrentChannelId(render_, &channelId);
EXPECT_EQ(ret, HDF_SUCCESS);
}
EXPECT_EQ(ret, HDF_SUCCESS);
}
BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, GetCurrentChannelId)->
@ -351,6 +388,7 @@ BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, GetCurrentChannelId)->
BENCHMARK_F(AudioRenderBenchmarkTest, SelectScene)(benchmark::State &state)
{
ASSERT_NE(render_, nullptr);
int32_t ret;
struct AudioSceneDescriptor scene;
scene.scene.id = AUDIO_IN_MEDIA;
@ -359,8 +397,8 @@ BENCHMARK_F(AudioRenderBenchmarkTest, SelectScene)(benchmark::State &state)
for (auto _ : state) {
ret = render_->SelectScene(render_, &scene);
EXPECT_EQ(ret, HDF_SUCCESS);
}
EXPECT_EQ(ret, HDF_SUCCESS);
}
BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, SelectScene)->
@ -368,13 +406,14 @@ BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, SelectScene)->
BENCHMARK_F(AudioRenderBenchmarkTest, GetLatency)(benchmark::State &state)
{
ASSERT_NE(render_, nullptr);
int32_t ret;
uint32_t ms = 0;
for (auto _ : state) {
ret = render_->GetLatency(render_, &ms);
EXPECT_EQ(ret, HDF_SUCCESS);
}
EXPECT_EQ(ret, HDF_SUCCESS);
}
BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, GetLatency)->
@ -382,14 +421,19 @@ BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, GetLatency)->
BENCHMARK_F(AudioRenderBenchmarkTest, GetRenderPosition)(benchmark::State &state)
{
ASSERT_NE(render_, nullptr);
int32_t ret;
uint64_t frames = 0;
struct AudioTimeStamp time;
for (auto _ : state) {
ret = render_->GetRenderPosition(render_, &frames, &time);
#ifdef DISPLAY_COMMUNITY
ASSERT_TRUE(ret == HDF_SUCCESS);
#else
ASSERT_TRUE(ret == HDF_ERR_INVALID_PARAM);
#endif
}
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_INVALID_PARAM);
}
BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, GetRenderPosition)->
@ -397,14 +441,15 @@ BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, GetRenderPosition)->
BENCHMARK_F(AudioRenderBenchmarkTest, SetExtraParams)(benchmark::State &state)
{
ASSERT_NE(render_, nullptr);
int32_t ret;
char keyValueList[AUDIO_RENDER_BUF_TEST] =
"attr-route=1;attr-format=32;attr-channels=2;attr-frame-count=82;attr-sampling-rate=48000";
for (auto _ : state) {
ret = render_->SetExtraParams(render_, keyValueList);
EXPECT_EQ(ret, HDF_SUCCESS);
}
EXPECT_EQ(ret, HDF_SUCCESS);
}
BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, SetExtraParams)->
@ -412,14 +457,15 @@ BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, SetExtraParams)->
BENCHMARK_F(AudioRenderBenchmarkTest, GetExtraParams)(benchmark::State &state)
{
ASSERT_NE(render_, nullptr);
int32_t ret;
char keyValueList[AUDIO_RENDER_BUF_TEST] = {};
uint32_t keyValueListLen = 0;
for (auto _ : state) {
ret = render_->GetExtraParams(render_, keyValueList, keyValueListLen);
EXPECT_NE(ret, HDF_SUCCESS);
}
EXPECT_NE(ret, HDF_SUCCESS);
}
BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, GetExtraParams)->
@ -427,13 +473,18 @@ BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, GetExtraParams)->
BENCHMARK_F(AudioRenderBenchmarkTest, SetGain)(benchmark::State &state)
{
ASSERT_NE(render_, nullptr);
int32_t ret;
float gain = 1.0;
float gain = GAIN_VALUE;
for (auto _ : state) {
ret = render_->SetGain(render_, gain);
#ifdef DISPLAY_COMMUNITY
ASSERT_TRUE(ret == HDF_SUCCESS);
#else
ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT);
#endif
}
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
}
BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, SetGain)->
@ -441,13 +492,18 @@ BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, SetGain)->
BENCHMARK_F(AudioRenderBenchmarkTest, GetGain)(benchmark::State &state)
{
ASSERT_NE(render_, nullptr);
int32_t ret;
float gain;
for (auto _ : state) {
ret = render_->GetGain(render_, &gain);
#ifdef DISPLAY_COMMUNITY
ASSERT_TRUE(ret == HDF_SUCCESS);
#else
ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT);
#endif
}
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
}
BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, GetGain)->
@ -455,14 +511,19 @@ BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, GetGain)->
BENCHMARK_F(AudioRenderBenchmarkTest, GetGainThreshold)(benchmark::State &state)
{
ASSERT_NE(render_, nullptr);
int32_t ret;
float min = 0.0;
float max = 1.0;
float max = GAIN_VALUE;
for (auto _ : state) {
ret = render_->GetGainThreshold(render_, &min, &max);
#ifdef DISPLAY_COMMUNITY
ASSERT_TRUE(ret == HDF_SUCCESS);
#else
ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT);
#endif
}
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
EXPECT_GE(min, MIN_GAINTHRESHOLD);
EXPECT_LE(max, MAX_GAINTHRESHOLD);
}
@ -472,6 +533,7 @@ BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, GetGainThreshold)->
BENCHMARK_F(AudioRenderBenchmarkTest, GetMmapPosition)(benchmark::State &state)
{
ASSERT_NE(render_, nullptr);
int32_t ret;
uint64_t frames = 0;
struct AudioTimeStamp time;
@ -480,8 +542,12 @@ BENCHMARK_F(AudioRenderBenchmarkTest, GetMmapPosition)(benchmark::State &state)
for (auto _ : state) {
ret = render_->GetMmapPosition(render_, &frames, &time);
#ifdef DISPLAY_COMMUNITY
ASSERT_TRUE(ret == HDF_SUCCESS);
#else
ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT);
#endif
}
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
}
BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, GetMmapPosition)->
@ -489,13 +555,18 @@ BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, GetMmapPosition)->
BENCHMARK_F(AudioRenderBenchmarkTest, SetMute)(benchmark::State &state)
{
ASSERT_NE(render_, nullptr);
int32_t ret;
bool mute = false;
for (auto _ : state) {
ret = render_->SetMute(render_, mute);
#ifdef DISPLAY_COMMUNITY
ASSERT_TRUE(ret == HDF_SUCCESS);
#else
ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT);
#endif
}
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
}
BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, SetMute)->
@ -503,13 +574,18 @@ BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, SetMute)->
BENCHMARK_F(AudioRenderBenchmarkTest, GetMute)(benchmark::State &state)
{
ASSERT_NE(render_, nullptr);
int32_t ret;
bool isMute = false;
for (auto _ : state) {
ret = render_->GetMute(render_, &isMute);
#ifdef DISPLAY_COMMUNITY
ASSERT_TRUE(ret == HDF_SUCCESS);
#else
ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT);
#endif
}
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
}
BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, GetMute)->
@ -517,13 +593,18 @@ BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, GetMute)->
BENCHMARK_F(AudioRenderBenchmarkTest, SetVolume)(benchmark::State &state)
{
ASSERT_NE(render_, nullptr);
int32_t ret;
float volume = 0.2;
float volume = VOLUNE_VALUE;
for (auto _ : state) {
ret = render_->SetVolume(render_, volume);
#ifdef DISPLAY_COMMUNITY
ASSERT_TRUE(ret == HDF_SUCCESS);
#else
ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT);
#endif
}
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_FAILURE);
}
BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, SetVolume)->
@ -531,13 +612,18 @@ BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, SetVolume)->
BENCHMARK_F(AudioRenderBenchmarkTest, GetVolume)(benchmark::State &state)
{
ASSERT_NE(render_, nullptr);
int32_t ret;
float val = 0.0;
for (auto _ : state) {
ret = render_->GetVolume(render_, &val);
#ifdef DISPLAY_COMMUNITY
ASSERT_TRUE(ret == HDF_SUCCESS);
#else
ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT);
#endif
}
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
}
BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, GetVolume)->
@ -545,6 +631,7 @@ BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, GetVolume)->
BENCHMARK_F(AudioRenderBenchmarkTest, RenderFrame)(benchmark::State &state)
{
ASSERT_NE(render_, nullptr);
int32_t ret;
uint32_t frameLen = (uint64_t)GetRenderBufferSize();
uint64_t requestBytes = frameLen;
@ -555,8 +642,8 @@ BENCHMARK_F(AudioRenderBenchmarkTest, RenderFrame)(benchmark::State &state)
for (auto _ : state) {
ret = render_->RenderFrame(render_, frame, frameLen, &requestBytes);
EXPECT_EQ(ret, HDF_SUCCESS);
}
EXPECT_EQ(ret, HDF_SUCCESS);
EXPECT_EQ(HDF_SUCCESS, render_->Stop(render_));
if (frame != nullptr) {
@ -570,13 +657,18 @@ BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, RenderFrame)->
BENCHMARK_F(AudioRenderBenchmarkTest, SetChannelMode)(benchmark::State &state)
{
ASSERT_NE(render_, nullptr);
int32_t ret;
AudioChannelMode mode = AUDIO_CHANNEL_NORMAL;
for (auto _ : state) {
ret = render_->SetChannelMode(render_, mode);
#ifdef DISPLAY_COMMUNITY
ASSERT_TRUE(ret == HDF_SUCCESS);
#else
ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT);
#endif
}
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
}
BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, SetChannelMode)->
@ -584,13 +676,18 @@ BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, SetChannelMode)->
BENCHMARK_F(AudioRenderBenchmarkTest, GetChannelMode)(benchmark::State &state)
{
ASSERT_NE(render_, nullptr);
int32_t ret;
AudioChannelMode mode = AUDIO_CHANNEL_NORMAL;
for (auto _ : state) {
ret = render_->GetChannelMode(render_, &mode);
#ifdef DISPLAY_COMMUNITY
ASSERT_TRUE(ret == HDF_SUCCESS);
#else
ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT);
#endif
}
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT);
}
BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, GetChannelMode)->
@ -598,13 +695,14 @@ BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, GetChannelMode)->
BENCHMARK_F(AudioRenderBenchmarkTest, SetRenderSpeed)(benchmark::State &state)
{
ASSERT_NE(render_, nullptr);
int32_t ret;
float speed = 2.0;
for (auto _ : state) {
ret = render_->SetRenderSpeed(render_, speed);
EXPECT_NE(ret, HDF_SUCCESS);
}
EXPECT_NE(ret, HDF_SUCCESS);
}
BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, SetRenderSpeed)->
@ -612,32 +710,75 @@ BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, SetRenderSpeed)->
BENCHMARK_F(AudioRenderBenchmarkTest, GetRenderSpeed)(benchmark::State &state)
{
ASSERT_NE(render_, nullptr);
int32_t ret;
float speed = 0;
for (auto _ : state) {
ret = render_->GetRenderSpeed(render_, &speed);
EXPECT_EQ(HDF_ERR_NOT_SUPPORT, ret);
}
EXPECT_EQ(HDF_ERR_NOT_SUPPORT, ret);
}
BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, GetRenderSpeed)->
Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
BENCHMARK_F(AudioRenderBenchmarkTest, ReqMmapBuffer)(benchmark::State &state)
BENCHMARK_F(AudioRenderBenchmarkTest, RegCallback)(benchmark::State &state)
{
ASSERT_NE(render_, nullptr);
int32_t ret;
int32_t reqSize = MMAP_SUGGEST_BUFFER_SIZE;
struct AudioMmapBufferDescriptor desc;
int8_t cookie = 0;
struct IAudioCallback *audioCallback = nullptr;
for (auto _ : state) {
ret = render_->ReqMmapBuffer(render_, reqSize, &desc);
ret = render_->RegCallback(render_, audioCallback, cookie);
#ifdef DISPLAY_COMMUNITY
ASSERT_TRUE(ret == HDF_SUCCESS);
#else
ASSERT_TRUE(ret == HDF_ERR_INVALID_PARAM);
#endif
}
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_INVALID_PARAM);
}
BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, ReqMmapBuffer)->
BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, RegCallback)->
Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
BENCHMARK_F(AudioRenderBenchmarkTest, DrainBuffer)(benchmark::State &state)
{
ASSERT_NE(render_, nullptr);
int32_t ret;
enum AudioDrainNotifyType type = AUDIO_DRAIN_NORMAL_MODE;
for (auto _ : state) {
ret = render_->DrainBuffer(render_, &type);
EXPECT_EQ(ret, HDF_ERR_NOT_SUPPORT);
}
}
BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, DrainBuffer)->
Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
BENCHMARK_F(AudioRenderBenchmarkTest, IsSupportsDrain)(benchmark::State &state)
{
ASSERT_NE(render_, nullptr);
int32_t ret;
bool support = false;
for (auto _ : state) {
ret = render_->IsSupportsDrain(render_, &support);
#ifdef DISPLAY_COMMUNITY
ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT);
#else
ASSERT_TRUE(ret == HDF_SUCCESS);
#endif
}
}
BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, IsSupportsDrain)->
Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
BENCHMARK_F(AudioRenderBenchmarkTest, CheckSceneCapability)(benchmark::State &state)
{
ASSERT_NE(render_, nullptr);
int32_t ret = -1;
bool supported = false;
struct AudioSceneDescriptor scenes = {};
@ -646,8 +787,8 @@ BENCHMARK_F(AudioRenderBenchmarkTest, CheckSceneCapability)(benchmark::State &st
scenes.desc.desc = strdup("mic");
for (auto _ : state) {
ret = render_->CheckSceneCapability(render_, &scenes, &supported);
EXPECT_EQ(HDF_SUCCESS, ret);
}
EXPECT_EQ(HDF_SUCCESS, ret);
free(scenes.desc.desc);
}
BENCHMARK_REGISTER_F(AudioRenderBenchmarkTest, CheckSceneCapability)->
@ -661,10 +802,18 @@ BENCHMARK_F(AudioRenderBenchmarkTest, AddAndRemoveAudioEffect)(benchmark::State
for (auto _ : state) {
ret = render_->AddAudioEffect(render_, effectId);
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT || ret == HDF_ERR_INVALID_PARAM);
#ifdef DISPLAY_COMMUNITY
ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT);
#else
ASSERT_TRUE(ret == HDF_ERR_INVALID_PARAM);
#endif
ret = render_->RemoveAudioEffect(render_, effectId);
ASSERT_TRUE(ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT || ret == HDF_ERR_INVALID_PARAM);
#ifdef DISPLAY_COMMUNITY
ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT);
#else
ASSERT_TRUE(ret == HDF_ERR_INVALID_PARAM);
#endif
}
}
@ -679,7 +828,11 @@ BENCHMARK_F(AudioRenderBenchmarkTest, GetFrameBufferSize)(benchmark::State &stat
for (auto _ : state) {
ret = render_->GetFrameBufferSize(render_, &bufferSize);
ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT || ret == HDF_ERR_INVALID_PARAM);
#ifdef DISPLAY_COMMUNITY
ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT);
#else
ASSERT_TRUE(ret == HDF_ERR_INVALID_PARAM);
#endif
}
}
@ -695,7 +848,11 @@ BENCHMARK_F(AudioRenderBenchmarkTest, IsSupportsPauseAndResume)(benchmark::State
for (auto _ : state) {
ret = render_->IsSupportsPauseAndResume(render_, &supportPause, &supportResume);
ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT || ret == HDF_ERR_INVALID_PARAM);
#ifdef DISPLAY_COMMUNITY
ASSERT_TRUE(ret == HDF_ERR_NOT_SUPPORT);
#else
ASSERT_TRUE(ret == HDF_ERR_INVALID_PARAM);
#endif
}
}

View File

@ -0,0 +1,199 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <benchmark/benchmark.h>
#include <climits>
#include <gtest/gtest.h>
#include "hdf_base.h"
#include "osal_mem.h"
#include "v2_0/audio_types.h"
#include "v2_0/iaudio_manager.h"
#include "v2_0/iaudio_render.h"
using namespace std;
using namespace testing::ext;
namespace {
const int BUFFER_LENTH = 1024 * 16;
const int DEEP_BUFFER_RENDER_PERIOD_SIZE = 4 * 1024;
const int MOVE_LEFT_NUM = 8;
const int32_t AUDIO_RENDER_CHANNELCOUNT = 2;
const int32_t AUDIO_SAMPLE_RATE_48K = 48000;
const int32_t MAX_AUDIO_ADAPTER_DESC = 5;
const int32_t MMAP_SUGGEST_BUFFER_SIZE = 1920;
const int32_t ITERATION_FREQUENCY = 100;
const int32_t REPETITION_FREQUENCY = 3;
class AudioRenderMmapBenchmarkTest : public benchmark::Fixture {
public:
struct IAudioManager *manager_ = nullptr;
struct AudioAdapterDescriptor descs_[MAX_AUDIO_ADAPTER_DESC];
struct AudioAdapterDescriptor *desc_;
struct IAudioAdapter *adapter_ = nullptr;
struct IAudioRender *render_ = nullptr;
struct AudioDeviceDescriptor devDescRender_ = {};
struct AudioSampleAttributes attrsRender_ = {};
uint32_t renderId_ = 0;
char *devDescriptorName_ = nullptr;
uint32_t size_ = MAX_AUDIO_ADAPTER_DESC;
virtual void SetUp(const ::benchmark::State &state);
virtual void TearDown(const ::benchmark::State &state);
void InitRenderAttrs(struct AudioSampleAttributes &attrs);
void InitRenderDevDesc(struct AudioDeviceDescriptor &devDesc);
void FreeAdapterElements(struct AudioAdapterDescriptor *dataBlock, bool freeSelf);
void ReleaseAllAdapterDescs(struct AudioAdapterDescriptor *descs, uint32_t descsLen);
};
void AudioRenderMmapBenchmarkTest::InitRenderAttrs(struct AudioSampleAttributes &attrs)
{
attrs.channelCount = AUDIO_RENDER_CHANNELCOUNT;
attrs.sampleRate = AUDIO_SAMPLE_RATE_48K;
attrs.interleaved = 0;
attrs.type = AUDIO_MMAP_NOIRQ;
attrs.period = DEEP_BUFFER_RENDER_PERIOD_SIZE;
attrs.frameSize = AUDIO_FORMAT_TYPE_PCM_16_BIT * AUDIO_RENDER_CHANNELCOUNT / MOVE_LEFT_NUM;
attrs.isBigEndian = false;
attrs.isSignedData = true;
attrs.startThreshold = DEEP_BUFFER_RENDER_PERIOD_SIZE / (attrs.format * attrs.channelCount / MOVE_LEFT_NUM);
attrs.stopThreshold = INT_MAX;
attrs.silenceThreshold = BUFFER_LENTH;
}
void AudioRenderMmapBenchmarkTest::InitRenderDevDesc(struct AudioDeviceDescriptor &devDesc)
{
devDesc.pins = PIN_OUT_SPEAKER;
devDescriptorName_ = strdup("cardname");
devDesc.desc = devDescriptorName_;
ASSERT_NE(desc_, nullptr);
ASSERT_NE(desc_->ports, nullptr);
for (uint32_t index = 0; index < desc_->portsLen; index++) {
if (desc_->ports[index].dir == PORT_OUT) {
devDesc.portId = desc_->ports[index].portId;
return;
}
}
free(devDesc.desc);
devDesc.desc = nullptr;
}
void AudioRenderMmapBenchmarkTest::FreeAdapterElements(struct AudioAdapterDescriptor *dataBlock, bool freeSelf)
{
if (dataBlock == nullptr) {
return;
}
OsalMemFree(dataBlock->adapterName);
OsalMemFree(dataBlock->ports);
if (freeSelf) {
OsalMemFree(dataBlock);
}
}
void AudioRenderMmapBenchmarkTest::ReleaseAllAdapterDescs(struct AudioAdapterDescriptor *descs, uint32_t descsLen)
{
if (descs == nullptr || descsLen == 0) {
return;
}
for (uint32_t i = 0; i < descsLen; i++) {
FreeAdapterElements(&descs[i], false);
}
}
void AudioRenderMmapBenchmarkTest::SetUp(const ::benchmark::State &state)
{
manager_ = IAudioManagerGet(false);
ASSERT_NE(manager_, nullptr);
ASSERT_EQ(HDF_SUCCESS, manager_->GetAllAdapters(manager_, descs_, &size_));
ASSERT_NE(descs_, nullptr);
EXPECT_GE(MAX_AUDIO_ADAPTER_DESC, size_);
desc_ = &descs_[0];
ASSERT_EQ(HDF_SUCCESS, manager_->LoadAdapter(manager_, desc_, &adapter_));
ASSERT_NE(adapter_, nullptr);
InitRenderDevDesc(devDescRender_);
InitRenderAttrs(attrsRender_);
attrsRender_.format = AUDIO_FORMAT_TYPE_PCM_16_BIT;
int32_t ret = adapter_->CreateRender(adapter_, &devDescRender_, &attrsRender_, &render_, &renderId_);
if (ret != HDF_SUCCESS) {
attrsRender_.format = AUDIO_FORMAT_TYPE_PCM_32_BIT;
ASSERT_EQ(HDF_SUCCESS, adapter_->CreateRender(adapter_, &devDescRender_, &attrsRender_, &render_, &renderId_));
}
ASSERT_NE(render_, nullptr);
}
void AudioRenderMmapBenchmarkTest::TearDown(const ::benchmark::State &state)
{
ASSERT_NE(devDescriptorName_, nullptr);
free(devDescriptorName_);
if (adapter_ != nullptr) {
adapter_->DestroyRender(adapter_, renderId_);
render_ = nullptr;
}
if (manager_ != nullptr) {
manager_->UnloadAdapter(manager_, desc_->adapterName);
adapter_ = nullptr;
ReleaseAllAdapterDescs(descs_, size_);
IAudioManagerRelease(manager_, false);
}
}
BENCHMARK_F(AudioRenderMmapBenchmarkTest, ReqMmapBuffer)(benchmark::State &state)
{
ASSERT_NE(render_, nullptr);
int32_t ret;
uint64_t frames = 0;
struct AudioTimeStamp time;
time.tvNSec = 0;
time.tvSec = 0;
int32_t reqSize = MMAP_SUGGEST_BUFFER_SIZE;
struct AudioMmapBufferDescriptor desc;
for (auto _ : state) {
ret = render_->ReqMmapBuffer(render_, reqSize, &desc);
#ifdef DISPLAY_COMMUNITY
ASSERT_TRUE(ret == HDF_ERR_INVALID_PARAM);
#else
ASSERT_TRUE(ret == HDF_SUCCESS);
#endif
ret = render_->Start(render_);
#ifdef DISPLAY_COMMUNITY
ASSERT_TRUE(ret == HDF_FAILURE);
#else
ASSERT_TRUE(ret == HDF_SUCCESS);
#endif
ret = render_->GetMmapPosition(render_, &frames, &time);
ASSERT_TRUE(ret == HDF_SUCCESS);
ret = render_->Stop(render_);
#ifdef DISPLAY_COMMUNITY
ASSERT_TRUE(ret == HDF_FAILURE);
#else
ASSERT_TRUE(ret == HDF_SUCCESS);
#endif
}
}
BENCHMARK_REGISTER_F(AudioRenderMmapBenchmarkTest, ReqMmapBuffer)->
Iterations(ITERATION_FREQUENCY)->Repetitions(REPETITION_FREQUENCY)->ReportAggregatesOnly();
}