VtsHalAudioEffectV2_0TargetTest.cpp revision 9f2890458a2e0b9fa09ceeba64c869bf3f1560c3
1/* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#define LOG_TAG "AudioEffectHidlHalTest" 18#include <android-base/logging.h> 19#include <system/audio.h> 20 21#include <android/hardware/audio/effect/2.0/IEffect.h> 22#include <android/hardware/audio/effect/2.0/IEffectsFactory.h> 23#include <android/hardware/audio/effect/2.0/IEqualizerEffect.h> 24#include <android/hardware/audio/effect/2.0/ILoudnessEnhancerEffect.h> 25#include <android/hardware/audio/effect/2.0/types.h> 26#include <android/hidl/allocator/1.0/IAllocator.h> 27#include <android/hidl/memory/1.0/IMemory.h> 28 29#include <VtsHalHidlTargetTestBase.h> 30 31using android::hardware::audio::common::V2_0::AudioDevice; 32using android::hardware::audio::common::V2_0::AudioHandleConsts; 33using android::hardware::audio::common::V2_0::AudioMode; 34using android::hardware::audio::common::V2_0::Uuid; 35using android::hardware::audio::effect::V2_0::AudioBuffer; 36using android::hardware::audio::effect::V2_0::EffectBufferConfig; 37using android::hardware::audio::effect::V2_0::EffectConfig; 38using android::hardware::audio::effect::V2_0::EffectDescriptor; 39using android::hardware::audio::effect::V2_0::EffectOffloadParameter; 40using android::hardware::audio::effect::V2_0::IEffect; 41using android::hardware::audio::effect::V2_0::IEffectsFactory; 42using android::hardware::audio::effect::V2_0::IEqualizerEffect; 43using android::hardware::audio::effect::V2_0::ILoudnessEnhancerEffect; 44using android::hardware::audio::effect::V2_0::Result; 45using android::hardware::MQDescriptorSync; 46using android::hardware::Return; 47using android::hardware::Void; 48using android::hardware::hidl_memory; 49using android::hardware::hidl_string; 50using android::hardware::hidl_vec; 51using android::hidl::allocator::V1_0::IAllocator; 52using android::hidl::memory::V1_0::IMemory; 53using android::sp; 54 55#ifndef ARRAY_SIZE 56#define ARRAY_SIZE(a) (sizeof(a) / sizeof(*(a))) 57#endif 58 59// The main test class for Audio Effects Factory HIDL HAL. 60class AudioEffectsFactoryHidlTest : public ::testing::VtsHalHidlTargetTestBase { 61 public: 62 void SetUp() override { 63 effectsFactory = 64 ::testing::VtsHalHidlTargetTestBase::getService<IEffectsFactory>(); 65 ASSERT_NE(effectsFactory, nullptr); 66 } 67 68 void TearDown() override { effectsFactory.clear(); } 69 70 protected: 71 static void description(const std::string& description) { 72 RecordProperty("description", description); 73 } 74 75 sp<IEffectsFactory> effectsFactory; 76}; 77 78TEST_F(AudioEffectsFactoryHidlTest, EnumerateEffects) { 79 description("Verify that EnumerateEffects returns at least one effect"); 80 Result retval = Result::NOT_INITIALIZED; 81 size_t effectCount = 0; 82 Return<void> ret = effectsFactory->getAllDescriptors( 83 [&](Result r, const hidl_vec<EffectDescriptor>& result) { 84 retval = r; 85 effectCount = result.size(); 86 }); 87 EXPECT_TRUE(ret.isOk()); 88 EXPECT_EQ(Result::OK, retval); 89 EXPECT_GT(effectCount, 0u); 90} 91 92TEST_F(AudioEffectsFactoryHidlTest, CreateEffect) { 93 description("Verify that an effect can be created via CreateEffect"); 94 bool gotEffect = false; 95 Uuid effectUuid; 96 Return<void> ret = effectsFactory->getAllDescriptors( 97 [&](Result r, const hidl_vec<EffectDescriptor>& result) { 98 if (r == Result::OK && result.size() > 0) { 99 gotEffect = true; 100 effectUuid = result[0].uuid; 101 } 102 }); 103 ASSERT_TRUE(ret.isOk()); 104 ASSERT_TRUE(gotEffect); 105 Result retval = Result::NOT_INITIALIZED; 106 sp<IEffect> effect; 107 ret = effectsFactory->createEffect( 108 effectUuid, 1 /*session*/, 1 /*ioHandle*/, 109 [&](Result r, const sp<IEffect>& result, uint64_t /*effectId*/) { 110 retval = r; 111 if (r == Result::OK) { 112 effect = result; 113 } 114 }); 115 EXPECT_TRUE(ret.isOk()); 116 EXPECT_EQ(Result::OK, retval); 117 EXPECT_NE(nullptr, effect.get()); 118} 119 120TEST_F(AudioEffectsFactoryHidlTest, GetDescriptor) { 121 description( 122 "Verify that effects factory can provide an effect descriptor via " 123 "GetDescriptor"); 124 hidl_vec<EffectDescriptor> allDescriptors; 125 Return<void> ret = effectsFactory->getAllDescriptors( 126 [&](Result r, const hidl_vec<EffectDescriptor>& result) { 127 if (r == Result::OK) { 128 allDescriptors = result; 129 } 130 }); 131 ASSERT_TRUE(ret.isOk()); 132 ASSERT_GT(allDescriptors.size(), 0u); 133 for (size_t i = 0; i < allDescriptors.size(); ++i) { 134 ret = effectsFactory->getDescriptor( 135 allDescriptors[i].uuid, [&](Result r, const EffectDescriptor& result) { 136 EXPECT_EQ(r, Result::OK); 137 EXPECT_EQ(result, allDescriptors[i]); 138 }); 139 } 140 EXPECT_TRUE(ret.isOk()); 141} 142 143// Equalizer effect is required by CDD, but only the type is fixed. 144// This is the same UUID as AudioEffect.EFFECT_TYPE_EQUALIZER in Java. 145static const Uuid EQUALIZER_EFFECT_TYPE = { 146 0x0bed4300, 0xddd6, 0x11db, 0x8f34, 147 std::array<uint8_t, 6>{{0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}}; 148// Loudness Enhancer effect is required by CDD, but only the type is fixed. 149// This is the same UUID as AudioEffect.EFFECT_TYPE_LOUDNESS_ENHANCER in Java. 150static const Uuid LOUDNESS_ENHANCER_EFFECT_TYPE = { 151 0xfe3199be, 0xaed0, 0x413f, 0x87bb, 152 std::array<uint8_t, 6>{{0x11, 0x26, 0x0e, 0xb6, 0x3c, 0xf1}}}; 153 154// The main test class for Audio Effect HIDL HAL. 155class AudioEffectHidlTest : public ::testing::VtsHalHidlTargetTestBase { 156 public: 157 void SetUp() override { 158 effectsFactory = 159 ::testing::VtsHalHidlTargetTestBase::getService<IEffectsFactory>(); 160 ASSERT_NE(nullptr, effectsFactory.get()); 161 162 findAndCreateEffect(getEffectType()); 163 ASSERT_NE(nullptr, effect.get()); 164 165 Return<Result> ret = effect->init(); 166 ASSERT_TRUE(ret.isOk()); 167 ASSERT_EQ(Result::OK, ret); 168 } 169 170 void TearDown() override { 171 effect.clear(); 172 effectsFactory.clear(); 173 } 174 175 protected: 176 static void description(const std::string& description) { 177 RecordProperty("description", description); 178 } 179 180 virtual Uuid getEffectType() { return EQUALIZER_EFFECT_TYPE; } 181 182 void findAndCreateEffect(const Uuid& type); 183 void findEffectInstance(const Uuid& type, Uuid* uuid); 184 void getChannelCount(uint32_t* channelCount); 185 186 sp<IEffectsFactory> effectsFactory; 187 sp<IEffect> effect; 188}; 189 190void AudioEffectHidlTest::findAndCreateEffect(const Uuid& type) { 191 Uuid effectUuid; 192 findEffectInstance(type, &effectUuid); 193 Return<void> ret = effectsFactory->createEffect( 194 effectUuid, 1 /*session*/, 1 /*ioHandle*/, 195 [&](Result r, const sp<IEffect>& result, uint64_t /*effectId*/) { 196 if (r == Result::OK) { 197 effect = result; 198 } 199 }); 200 ASSERT_TRUE(ret.isOk()); 201} 202 203void AudioEffectHidlTest::findEffectInstance(const Uuid& type, Uuid* uuid) { 204 bool effectFound = false; 205 Return<void> ret = effectsFactory->getAllDescriptors( 206 [&](Result r, const hidl_vec<EffectDescriptor>& result) { 207 if (r == Result::OK) { 208 for (const auto& desc : result) { 209 if (desc.type == type) { 210 effectFound = true; 211 *uuid = desc.uuid; 212 break; 213 } 214 } 215 } 216 }); 217 ASSERT_TRUE(ret.isOk()); 218 ASSERT_TRUE(effectFound); 219} 220 221void AudioEffectHidlTest::getChannelCount(uint32_t* channelCount) { 222 Result retval; 223 EffectConfig currentConfig; 224 Return<void> ret = effect->getConfig([&](Result r, const EffectConfig& conf) { 225 retval = r; 226 if (r == Result::OK) { 227 currentConfig = conf; 228 } 229 }); 230 ASSERT_TRUE(ret.isOk()); 231 ASSERT_EQ(Result::OK, retval); 232 ASSERT_TRUE(audio_channel_mask_is_valid( 233 static_cast<audio_channel_mask_t>(currentConfig.outputCfg.channels))); 234 *channelCount = audio_channel_count_from_out_mask( 235 static_cast<audio_channel_mask_t>(currentConfig.outputCfg.channels)); 236} 237 238TEST_F(AudioEffectHidlTest, Close) { 239 description("Verify that an effect can be closed"); 240 Return<Result> ret = effect->close(); 241 EXPECT_TRUE(ret.isOk()); 242 EXPECT_EQ(Result::OK, ret); 243} 244 245TEST_F(AudioEffectHidlTest, GetDescriptor) { 246 description( 247 "Verify that an effect can return its own descriptor via GetDescriptor"); 248 Result retval = Result::NOT_INITIALIZED; 249 Uuid actualType; 250 Return<void> ret = 251 effect->getDescriptor([&](Result r, const EffectDescriptor& desc) { 252 retval = r; 253 if (r == Result::OK) { 254 actualType = desc.type; 255 } 256 }); 257 EXPECT_TRUE(ret.isOk()); 258 EXPECT_EQ(Result::OK, retval); 259 EXPECT_EQ(getEffectType(), actualType); 260} 261 262TEST_F(AudioEffectHidlTest, GetSetConfig) { 263 description( 264 "Verify that it is possible to manipulate effect config via Get / " 265 "SetConfig"); 266 Result retval = Result::NOT_INITIALIZED; 267 EffectConfig currentConfig; 268 Return<void> ret = effect->getConfig([&](Result r, const EffectConfig& conf) { 269 retval = r; 270 if (r == Result::OK) { 271 currentConfig = conf; 272 } 273 }); 274 EXPECT_TRUE(ret.isOk()); 275 EXPECT_EQ(Result::OK, retval); 276 Return<Result> ret2 = effect->setConfig(currentConfig, nullptr, nullptr); 277 EXPECT_TRUE(ret2.isOk()); 278 EXPECT_EQ(Result::OK, ret2); 279} 280 281// Not generated automatically because AudioBuffer contains 282// instances of hidl_memory which can't be compared properly 283// in general case due to presence of handles. 284// 285// However, in this particular case, handles must not present 286// thus comparison is possible. 287// 288// operator== must be defined in the same namespace as the structures. 289namespace android { 290namespace hardware { 291namespace audio { 292namespace effect { 293namespace V2_0 { 294inline bool operator==(const AudioBuffer& lhs, const AudioBuffer& rhs) { 295 return lhs.id == rhs.id && lhs.frameCount == rhs.frameCount && 296 lhs.data.handle() == nullptr && rhs.data.handle() == nullptr; 297} 298 299inline bool operator==(const EffectBufferConfig& lhs, 300 const EffectBufferConfig& rhs) { 301 return lhs.buffer == rhs.buffer && lhs.samplingRateHz == rhs.samplingRateHz && 302 lhs.channels == rhs.channels && lhs.format == rhs.format && 303 lhs.accessMode == rhs.accessMode && lhs.mask == rhs.mask; 304} 305 306inline bool operator==(const EffectConfig& lhs, const EffectConfig& rhs) { 307 return lhs.inputCfg == rhs.inputCfg && lhs.outputCfg == rhs.outputCfg; 308} 309} // namespace V2_0 310} // namespace effect 311} // namespace audio 312} // namespace hardware 313} // namespace android 314 315TEST_F(AudioEffectHidlTest, Reset) { 316 description("Verify that Reset preserves effect configuration"); 317 Result retval = Result::NOT_INITIALIZED; 318 EffectConfig originalConfig; 319 Return<void> ret = effect->getConfig([&](Result r, const EffectConfig& conf) { 320 retval = r; 321 if (r == Result::OK) { 322 originalConfig = conf; 323 } 324 }); 325 ASSERT_TRUE(ret.isOk()); 326 ASSERT_EQ(Result::OK, retval); 327 Return<Result> ret2 = effect->reset(); 328 EXPECT_TRUE(ret2.isOk()); 329 EXPECT_EQ(Result::OK, ret2); 330 EffectConfig configAfterReset; 331 ret = effect->getConfig([&](Result r, const EffectConfig& conf) { 332 retval = r; 333 if (r == Result::OK) { 334 configAfterReset = conf; 335 } 336 }); 337 EXPECT_EQ(originalConfig, configAfterReset); 338} 339 340TEST_F(AudioEffectHidlTest, DisableEnableDisable) { 341 description("Verify Disable -> Enable -> Disable sequence for an effect"); 342 Return<Result> ret = effect->disable(); 343 EXPECT_TRUE(ret.isOk()); 344 EXPECT_EQ(Result::INVALID_ARGUMENTS, ret); 345 ret = effect->enable(); 346 EXPECT_TRUE(ret.isOk()); 347 EXPECT_EQ(Result::OK, ret); 348 ret = effect->disable(); 349 EXPECT_TRUE(ret.isOk()); 350 EXPECT_EQ(Result::OK, ret); 351} 352 353TEST_F(AudioEffectHidlTest, SetDevice) { 354 description("Verify that SetDevice works for an output chain effect"); 355 Return<Result> ret = effect->setDevice(AudioDevice::OUT_SPEAKER); 356 EXPECT_TRUE(ret.isOk()); 357 EXPECT_EQ(Result::OK, ret); 358} 359 360TEST_F(AudioEffectHidlTest, SetAndGetVolume) { 361 description("Verify that SetAndGetVolume method works for an effect"); 362 uint32_t channelCount; 363 getChannelCount(&channelCount); 364 hidl_vec<uint32_t> volumes; 365 volumes.resize(channelCount); 366 for (uint32_t i = 0; i < channelCount; ++i) { 367 volumes[i] = 0; 368 } 369 Result retval = Result::NOT_INITIALIZED; 370 Return<void> ret = effect->setAndGetVolume( 371 volumes, [&](Result r, const hidl_vec<uint32_t>&) { retval = r; }); 372 EXPECT_TRUE(ret.isOk()); 373 EXPECT_EQ(Result::OK, retval); 374} 375 376TEST_F(AudioEffectHidlTest, VolumeChangeNotification) { 377 description("Verify that effect accepts VolumeChangeNotification"); 378 uint32_t channelCount; 379 getChannelCount(&channelCount); 380 hidl_vec<uint32_t> volumes; 381 volumes.resize(channelCount); 382 for (uint32_t i = 0; i < channelCount; ++i) { 383 volumes[i] = 0; 384 } 385 Return<Result> ret = effect->volumeChangeNotification(volumes); 386 EXPECT_TRUE(ret.isOk()); 387 EXPECT_EQ(Result::OK, ret); 388} 389 390TEST_F(AudioEffectHidlTest, SetAudioMode) { 391 description("Verify that SetAudioMode works for an effect"); 392 Return<Result> ret = effect->setAudioMode(AudioMode::NORMAL); 393 EXPECT_TRUE(ret.isOk()); 394 EXPECT_EQ(Result::OK, ret); 395} 396 397TEST_F(AudioEffectHidlTest, Offload) { 398 description("Verify that calling Offload methods works for an effect"); 399 EffectOffloadParameter offloadParam; 400 offloadParam.isOffload = false; 401 offloadParam.ioHandle = 402 static_cast<int>(AudioHandleConsts::AUDIO_IO_HANDLE_NONE); 403 Return<Result> ret = effect->offload(offloadParam); 404 EXPECT_TRUE(ret.isOk()); 405 EXPECT_EQ(Result::OK, ret); 406} 407 408TEST_F(AudioEffectHidlTest, PrepareForProcessing) { 409 description("Verify that PrepareForProcessing method works for an effect"); 410 Result retval = Result::NOT_INITIALIZED; 411 Return<void> ret = effect->prepareForProcessing( 412 [&](Result r, const MQDescriptorSync<Result>&) { retval = r; }); 413 EXPECT_TRUE(ret.isOk()); 414 EXPECT_EQ(Result::OK, retval); 415} 416 417TEST_F(AudioEffectHidlTest, SetProcessBuffers) { 418 description("Verify that SetProcessBuffers works for an effect"); 419 sp<IAllocator> ashmem = IAllocator::getService("ashmem"); 420 ASSERT_NE(nullptr, ashmem.get()); 421 bool success = false; 422 AudioBuffer buffer; 423 Return<void> ret = 424 ashmem->allocate(1024, [&](bool s, const hidl_memory& memory) { 425 success = s; 426 if (s) { 427 buffer.data = memory; 428 } 429 }); 430 ASSERT_TRUE(ret.isOk()); 431 ASSERT_TRUE(success); 432 Return<Result> ret2 = effect->setProcessBuffers(buffer, buffer); 433 EXPECT_TRUE(ret2.isOk()); 434 EXPECT_EQ(Result::OK, ret2); 435} 436 437// Testing getConfigReverse, getAuxChannelsConfig, 438// getSupportedAuxChannelsConfigs, setAudioSource, setConfigReverse, 439// setInputDevice doesn't make sense, because normally they are not supported by 440// the Equalizer, but it wouldn't be a problem if some vendor implementation 441// supports them, thus we can't test these methods neither for success, nor for 442// failure. 443 444// command, getParameter, getSupportedConfigsForFeature, 445// getCurrentConfigForFeature, setCurrentConfigForFeature, setParameter are 446// opaque channels between vendor apps and HALs, and can't be meaningfully 447// tested with effects that don't support them. 448 449// The main test class for Equalizer Audio Effect HIDL HAL. 450class EqualizerAudioEffectHidlTest : public AudioEffectHidlTest { 451 public: 452 void SetUp() override { 453 AudioEffectHidlTest::SetUp(); 454 equalizer = IEqualizerEffect::castFrom(effect); 455 ASSERT_NE(nullptr, equalizer.get()); 456 } 457 458 protected: 459 Uuid getEffectType() override { return EQUALIZER_EFFECT_TYPE; } 460 void getNumBands(uint16_t* numBands); 461 void getLevelRange(int16_t* minLevel, int16_t* maxLevel); 462 void getBandFrequencyRange(uint16_t band, uint32_t* minFreq, 463 uint32_t* centerFreq, uint32_t* maxFreq); 464 void getPresetCount(size_t* count); 465 466 sp<IEqualizerEffect> equalizer; 467}; 468 469void EqualizerAudioEffectHidlTest::getNumBands(uint16_t* numBands) { 470 Result retval = Result::NOT_INITIALIZED; 471 Return<void> ret = equalizer->getNumBands([&](Result r, uint16_t b) { 472 retval = r; 473 if (retval == Result::OK) { 474 *numBands = b; 475 } 476 }); 477 ASSERT_TRUE(ret.isOk()); 478 ASSERT_EQ(Result::OK, retval); 479} 480 481void EqualizerAudioEffectHidlTest::getLevelRange(int16_t* minLevel, 482 int16_t* maxLevel) { 483 Result retval = Result::NOT_INITIALIZED; 484 Return<void> ret = 485 equalizer->getLevelRange([&](Result r, int16_t min, int16_t max) { 486 retval = r; 487 if (retval == Result::OK) { 488 *minLevel = min; 489 *maxLevel = max; 490 } 491 }); 492 ASSERT_TRUE(ret.isOk()); 493 ASSERT_EQ(Result::OK, retval); 494} 495 496void EqualizerAudioEffectHidlTest::getBandFrequencyRange(uint16_t band, 497 uint32_t* minFreq, 498 uint32_t* centerFreq, 499 uint32_t* maxFreq) { 500 Result retval = Result::NOT_INITIALIZED; 501 Return<void> ret = equalizer->getBandFrequencyRange( 502 band, [&](Result r, uint32_t min, uint32_t max) { 503 retval = r; 504 if (retval == Result::OK) { 505 *minFreq = min; 506 *maxFreq = max; 507 } 508 }); 509 ASSERT_TRUE(ret.isOk()); 510 ASSERT_EQ(Result::OK, retval); 511 ret = equalizer->getBandCenterFrequency(band, [&](Result r, uint32_t center) { 512 retval = r; 513 if (retval == Result::OK) { 514 *centerFreq = center; 515 } 516 }); 517 ASSERT_TRUE(ret.isOk()); 518 ASSERT_EQ(Result::OK, retval); 519} 520 521void EqualizerAudioEffectHidlTest::getPresetCount(size_t* count) { 522 Result retval = Result::NOT_INITIALIZED; 523 Return<void> ret = equalizer->getPresetNames( 524 [&](Result r, const hidl_vec<hidl_string>& names) { 525 retval = r; 526 if (retval == Result::OK) { 527 *count = names.size(); 528 } 529 }); 530 ASSERT_TRUE(ret.isOk()); 531 ASSERT_EQ(Result::OK, retval); 532} 533 534TEST_F(EqualizerAudioEffectHidlTest, GetNumBands) { 535 description("Verify that Equalizer effect reports at least one band"); 536 uint16_t numBands = 0; 537 getNumBands(&numBands); 538 EXPECT_GT(numBands, 0); 539} 540 541TEST_F(EqualizerAudioEffectHidlTest, GetLevelRange) { 542 description("Verify that Equalizer effect reports adequate band level range"); 543 int16_t minLevel = 0x7fff, maxLevel = 0; 544 getLevelRange(&minLevel, &maxLevel); 545 EXPECT_GT(maxLevel, minLevel); 546} 547 548TEST_F(EqualizerAudioEffectHidlTest, GetSetBandLevel) { 549 description( 550 "Verify that manipulating band levels works for Equalizer effect"); 551 uint16_t numBands = 0; 552 getNumBands(&numBands); 553 ASSERT_GT(numBands, 0); 554 int16_t levels[3]{0x7fff, 0, 0}; 555 getLevelRange(&levels[0], &levels[2]); 556 ASSERT_GT(levels[2], levels[0]); 557 levels[1] = (levels[2] + levels[0]) / 2; 558 for (uint16_t i = 0; i < numBands; ++i) { 559 for (size_t j = 0; j < ARRAY_SIZE(levels); ++j) { 560 Return<Result> ret = equalizer->setBandLevel(i, levels[j]); 561 EXPECT_TRUE(ret.isOk()); 562 EXPECT_EQ(Result::OK, ret); 563 Result retval = Result::NOT_INITIALIZED; 564 int16_t actualLevel; 565 Return<void> ret2 = equalizer->getBandLevel(i, [&](Result r, int16_t l) { 566 retval = r; 567 if (retval == Result::OK) { 568 actualLevel = l; 569 } 570 }); 571 EXPECT_TRUE(ret2.isOk()); 572 EXPECT_EQ(Result::OK, retval); 573 EXPECT_EQ(levels[j], actualLevel); 574 } 575 } 576} 577 578TEST_F(EqualizerAudioEffectHidlTest, GetBandCenterFrequencyAndRange) { 579 description( 580 "Verify that Equalizer effect reports adequate band frequency range"); 581 uint16_t numBands = 0; 582 getNumBands(&numBands); 583 ASSERT_GT(numBands, 0); 584 for (uint16_t i = 0; i < numBands; ++i) { 585 uint32_t minFreq = 0xffffffff, centerFreq = 0xffffffff, 586 maxFreq = 0xffffffff; 587 getBandFrequencyRange(i, &minFreq, ¢erFreq, &maxFreq); 588 // Note: NXP legacy implementation reports "1" as upper bound for last band, 589 // so this check fails. 590 EXPECT_GE(maxFreq, centerFreq); 591 EXPECT_GE(centerFreq, minFreq); 592 } 593} 594 595TEST_F(EqualizerAudioEffectHidlTest, GetBandForFrequency) { 596 description( 597 "Verify that Equalizer effect supports GetBandForFrequency correctly"); 598 uint16_t numBands = 0; 599 getNumBands(&numBands); 600 ASSERT_GT(numBands, 0); 601 for (uint16_t i = 0; i < numBands; ++i) { 602 uint32_t freqs[3]{0, 0, 0}; 603 getBandFrequencyRange(i, &freqs[0], &freqs[1], &freqs[2]); 604 // NXP legacy implementation reports "1" as upper bound for last band, some 605 // of the checks fail. 606 for (size_t j = 0; j < ARRAY_SIZE(freqs); ++j) { 607 if (j == 0) { 608 freqs[j]++; 609 } // Min frequency is an open interval. 610 Result retval = Result::NOT_INITIALIZED; 611 uint16_t actualBand = numBands + 1; 612 Return<void> ret = 613 equalizer->getBandForFrequency(freqs[j], [&](Result r, uint16_t b) { 614 retval = r; 615 if (retval == Result::OK) { 616 actualBand = b; 617 } 618 }); 619 EXPECT_TRUE(ret.isOk()); 620 EXPECT_EQ(Result::OK, retval); 621 EXPECT_EQ(i, actualBand) << "Frequency: " << freqs[j]; 622 } 623 } 624} 625 626TEST_F(EqualizerAudioEffectHidlTest, GetPresetNames) { 627 description("Verify that Equalizer effect reports at least one preset"); 628 size_t presetCount; 629 getPresetCount(&presetCount); 630 EXPECT_GT(presetCount, 0u); 631} 632 633TEST_F(EqualizerAudioEffectHidlTest, GetSetCurrentPreset) { 634 description( 635 "Verify that manipulating the current preset for Equalizer effect"); 636 size_t presetCount; 637 getPresetCount(&presetCount); 638 ASSERT_GT(presetCount, 0u); 639 for (uint16_t i = 0; i < presetCount; ++i) { 640 Return<Result> ret = equalizer->setCurrentPreset(i); 641 EXPECT_TRUE(ret.isOk()); 642 EXPECT_EQ(Result::OK, ret); 643 Result retval = Result::NOT_INITIALIZED; 644 uint16_t actualPreset = 0xffff; 645 Return<void> ret2 = equalizer->getCurrentPreset([&](Result r, uint16_t p) { 646 retval = r; 647 if (retval == Result::OK) { 648 actualPreset = p; 649 } 650 }); 651 EXPECT_TRUE(ret2.isOk()); 652 EXPECT_EQ(Result::OK, retval); 653 EXPECT_EQ(i, actualPreset); 654 } 655} 656 657TEST_F(EqualizerAudioEffectHidlTest, GetSetAllProperties) { 658 description( 659 "Verify that setting band levels and presets works via Get / " 660 "SetAllProperties for Equalizer effect"); 661 using AllProperties = 662 android::hardware::audio::effect::V2_0::IEqualizerEffect::AllProperties; 663 uint16_t numBands = 0; 664 getNumBands(&numBands); 665 ASSERT_GT(numBands, 0); 666 AllProperties props; 667 props.bandLevels.resize(numBands); 668 for (size_t i = 0; i < numBands; ++i) { 669 props.bandLevels[i] = 0; 670 } 671 672 AllProperties actualProps; 673 Result retval = Result::NOT_INITIALIZED; 674 675 // Verify setting of the band levels via properties. 676 props.curPreset = -1; 677 Return<Result> ret = equalizer->setAllProperties(props); 678 EXPECT_TRUE(ret.isOk()); 679 EXPECT_EQ(Result::OK, ret); 680 Return<void> ret2 = 681 equalizer->getAllProperties([&](Result r, AllProperties p) { 682 retval = r; 683 if (retval == Result::OK) { 684 actualProps = p; 685 } 686 }); 687 EXPECT_TRUE(ret2.isOk()); 688 EXPECT_EQ(Result::OK, retval); 689 EXPECT_EQ(props.bandLevels, actualProps.bandLevels); 690 691 // Verify setting of the current preset via properties. 692 props.curPreset = 0; // Assuming there is at least one preset. 693 ret = equalizer->setAllProperties(props); 694 EXPECT_TRUE(ret.isOk()); 695 EXPECT_EQ(Result::OK, ret); 696 ret2 = equalizer->getAllProperties([&](Result r, AllProperties p) { 697 retval = r; 698 if (retval == Result::OK) { 699 actualProps = p; 700 } 701 }); 702 EXPECT_TRUE(ret2.isOk()); 703 EXPECT_EQ(Result::OK, retval); 704 EXPECT_EQ(props.curPreset, actualProps.curPreset); 705} 706 707// The main test class for Equalizer Audio Effect HIDL HAL. 708class LoudnessEnhancerAudioEffectHidlTest : public AudioEffectHidlTest { 709 public: 710 void SetUp() override { 711 AudioEffectHidlTest::SetUp(); 712 enhancer = ILoudnessEnhancerEffect::castFrom(effect); 713 ASSERT_NE(nullptr, enhancer.get()); 714 } 715 716 protected: 717 Uuid getEffectType() override { return LOUDNESS_ENHANCER_EFFECT_TYPE; } 718 719 sp<ILoudnessEnhancerEffect> enhancer; 720}; 721 722TEST_F(LoudnessEnhancerAudioEffectHidlTest, GetSetTargetGain) { 723 description( 724 "Verify that manipulating the target gain works for Loudness Enhancer " 725 "effect"); 726 const int32_t gain = 100; 727 Return<Result> ret = enhancer->setTargetGain(gain); 728 EXPECT_TRUE(ret.isOk()); 729 EXPECT_EQ(Result::OK, ret); 730 int32_t actualGain = 0; 731 Result retval; 732 Return<void> ret2 = enhancer->getTargetGain([&](Result r, int32_t g) { 733 retval = r; 734 if (retval == Result::OK) { 735 actualGain = g; 736 } 737 }); 738 EXPECT_TRUE(ret2.isOk()); 739 EXPECT_EQ(Result::OK, retval); 740 EXPECT_EQ(gain, actualGain); 741} 742