From 3483b0ad7e1ac1aacda06223052a2dcc56e76e5b Mon Sep 17 00:00:00 2001 From: Mikhail Naganov Date: Fri, 19 Nov 2021 02:16:41 +0000 Subject: [PATCH] audio VTS: Consider only attached devices for stream tests V6 and V7 use the audio policy configuration file for generating the set of test profiles. The generator must only take into account profiles of mix ports that are routed to device ports of attached devices. Otherwise the HAL can rightfully refuse to create a stream for the profile when the device isn't attached. Bug: 205808571 Test: atest HalAudioV6_0GeneratorTest Test: atest HalAudioV7_0GeneratorTest Test: atest VtsHalAudioV6_0TargetTest Test: atest VtsHalAudioV7_0TargetTest Change-Id: I798f978c1c0bc32831c20e4b08338b462d8eea16 --- .../vts/functional/6.0/Generators.cpp | 18 +- .../7.0/AudioPrimaryHidlHalTest.cpp | 27 +- .../vts/functional/7.0/Generators.cpp | 18 +- .../all-versions/vts/functional/Android.bp | 2 + .../vts/functional/PolicyConfig.h | 60 +++ .../tests/HalAudioV6_0GeneratorTest.xml | 1 + .../tests/HalAudioV7_0GeneratorTest.xml | 1 + .../tests/apm_config_b_205808571_6_0.xml | 451 ++++++++++++++++++ .../tests/apm_config_b_205808571_7_0.xml | 446 +++++++++++++++++ .../vts/functional/tests/generators_tests.cpp | 37 +- 10 files changed, 1031 insertions(+), 30 deletions(-) create mode 100644 audio/core/all-versions/vts/functional/tests/apm_config_b_205808571_6_0.xml create mode 100644 audio/core/all-versions/vts/functional/tests/apm_config_b_205808571_7_0.xml diff --git a/audio/core/all-versions/vts/functional/6.0/Generators.cpp b/audio/core/all-versions/vts/functional/6.0/Generators.cpp index 6b4dbc17af..e3b98c909f 100644 --- a/audio/core/all-versions/vts/functional/6.0/Generators.cpp +++ b/audio/core/all-versions/vts/functional/6.0/Generators.cpp @@ -36,9 +36,14 @@ using namespace ::android::hardware::audio::CPP_VERSION; std::vector generateOutputDeviceConfigParameters(bool oneProfilePerDevice) { std::vector result; for (const auto& device : getDeviceParameters()) { - auto module = - getCachedPolicyConfig().getModuleFromName(std::get(device)); + const std::string moduleName = std::get(device); + auto module = getCachedPolicyConfig().getModuleFromName(moduleName); for (const auto& ioProfile : module->getOutputProfiles()) { + if (getCachedPolicyConfig() + .getAttachedSinkDeviceForMixPort(moduleName, ioProfile->getName()) + .empty()) { + continue; // no attached device + } for (const auto& profile : ioProfile->getAudioProfiles()) { const auto& channels = profile->getChannels(); const auto& sampleRates = profile->getSampleRates(); @@ -94,9 +99,14 @@ const std::vector& getOutputDeviceSingleConfigParameters( std::vector generateInputDeviceConfigParameters(bool oneProfilePerDevice) { std::vector result; for (const auto& device : getDeviceParameters()) { - auto module = - getCachedPolicyConfig().getModuleFromName(std::get(device)); + const std::string moduleName = std::get(device); + auto module = getCachedPolicyConfig().getModuleFromName(moduleName); for (const auto& ioProfile : module->getInputProfiles()) { + if (getCachedPolicyConfig() + .getAttachedSourceDeviceForMixPort(moduleName, ioProfile->getName()) + .empty()) { + continue; // no attached device + } for (const auto& profile : ioProfile->getAudioProfiles()) { const auto& channels = profile->getChannels(); const auto& sampleRates = profile->getSampleRates(); diff --git a/audio/core/all-versions/vts/functional/7.0/AudioPrimaryHidlHalTest.cpp b/audio/core/all-versions/vts/functional/7.0/AudioPrimaryHidlHalTest.cpp index 0cc6a5b964..27598012fe 100644 --- a/audio/core/all-versions/vts/functional/7.0/AudioPrimaryHidlHalTest.cpp +++ b/audio/core/all-versions/vts/functional/7.0/AudioPrimaryHidlHalTest.cpp @@ -499,18 +499,10 @@ static const std::vector& getOutputDevicePcmOnlyConfigPar return xsd::isLinearPcm(std::get(cfg).base.format) // MMAP NOIRQ and HW A/V Sync profiles use special writing protocols. && - std::find_if(flags.begin(), flags.end(), - [](const auto& flag) { - return flag == toString(xsd::AudioInOutFlag:: - AUDIO_OUTPUT_FLAG_MMAP_NOIRQ) || - flag == toString(xsd::AudioInOutFlag:: - AUDIO_OUTPUT_FLAG_HW_AV_SYNC); - }) == flags.end() && - !getCachedPolicyConfig() - .getAttachedSinkDeviceForMixPort( - std::get(std::get(cfg)), - std::get(cfg)) - .empty(); + std::find_if(flags.begin(), flags.end(), [](const auto& flag) { + return flag == toString(xsd::AudioInOutFlag::AUDIO_OUTPUT_FLAG_MMAP_NOIRQ) || + flag == toString(xsd::AudioInOutFlag::AUDIO_OUTPUT_FLAG_HW_AV_SYNC); + }) == flags.end(); }); return pcmParams; }(); @@ -677,20 +669,13 @@ static const std::vector& getInputDevicePcmOnlyConfigPara // reading h/w hotword might require Soundtrigger to be active. && std::find_if( - flags.begin(), flags.end(), - [](const auto& flag) { + flags.begin(), flags.end(), [](const auto& flag) { return flag == toString( xsd::AudioInOutFlag:: AUDIO_INPUT_FLAG_MMAP_NOIRQ) || flag == toString(xsd::AudioInOutFlag:: AUDIO_INPUT_FLAG_HW_HOTWORD); - }) == flags.end() && - !getCachedPolicyConfig() - .getAttachedSourceDeviceForMixPort( - std::get( - std::get(cfg)), - std::get(cfg)) - .empty(); + }) == flags.end(); }); return pcmParams; }(); diff --git a/audio/core/all-versions/vts/functional/7.0/Generators.cpp b/audio/core/all-versions/vts/functional/7.0/Generators.cpp index 8c92cbd161..42bf1d341d 100644 --- a/audio/core/all-versions/vts/functional/7.0/Generators.cpp +++ b/audio/core/all-versions/vts/functional/7.0/Generators.cpp @@ -95,11 +95,16 @@ static AudioOffloadInfo generateOffloadInfo(const AudioConfigBase& base) { std::vector generateOutputDeviceConfigParameters(bool oneProfilePerDevice) { std::vector result; for (const auto& device : getDeviceParameters()) { - auto module = - getCachedPolicyConfig().getModuleFromName(std::get(device)); + const std::string moduleName = std::get(device); + auto module = getCachedPolicyConfig().getModuleFromName(moduleName); if (!module || !module->getFirstMixPorts()) break; for (const auto& mixPort : module->getFirstMixPorts()->getMixPort()) { if (mixPort.getRole() != xsd::Role::source) continue; // not an output profile + if (getCachedPolicyConfig() + .getAttachedSinkDeviceForMixPort(moduleName, mixPort.getName()) + .empty()) { + continue; // no attached device + } auto [flags, isOffload] = generateOutFlags(mixPort); for (const auto& profile : mixPort.getProfile()) { if (!profile.hasFormat() || !profile.hasSamplingRates() || @@ -223,11 +228,16 @@ const std::vector& getOutputDeviceInvalidConfigParameters std::vector generateInputDeviceConfigParameters(bool oneProfilePerDevice) { std::vector result; for (const auto& device : getDeviceParameters()) { - auto module = - getCachedPolicyConfig().getModuleFromName(std::get(device)); + const std::string moduleName = std::get(device); + auto module = getCachedPolicyConfig().getModuleFromName(moduleName); if (!module || !module->getFirstMixPorts()) break; for (const auto& mixPort : module->getFirstMixPorts()->getMixPort()) { if (mixPort.getRole() != xsd::Role::sink) continue; // not an input profile + if (getCachedPolicyConfig() + .getAttachedSourceDeviceForMixPort(moduleName, mixPort.getName()) + .empty()) { + continue; // no attached device + } std::vector flags; if (mixPort.hasFlags()) { std::transform(mixPort.getFlags().begin(), mixPort.getFlags().end(), diff --git a/audio/core/all-versions/vts/functional/Android.bp b/audio/core/all-versions/vts/functional/Android.bp index c576060b2e..cfee26ada5 100644 --- a/audio/core/all-versions/vts/functional/Android.bp +++ b/audio/core/all-versions/vts/functional/Android.bp @@ -211,6 +211,7 @@ cc_test { data: [ "tests/apm_config_no_vx.xml", "tests/apm_config_with_vx.xml", + "tests/apm_config_b_205808571_6_0.xml", ], test_config: "tests/HalAudioV6_0GeneratorTest.xml", } @@ -240,6 +241,7 @@ cc_test { "tests/apm_config_no_vx_7_0.xml", "tests/apm_config_with_vx_7_0.xml", "tests/apm_config_b_204314749_7_0.xml", + "tests/apm_config_b_205808571_7_0.xml", ], test_config: "tests/HalAudioV7_0GeneratorTest.xml", } diff --git a/audio/core/all-versions/vts/functional/PolicyConfig.h b/audio/core/all-versions/vts/functional/PolicyConfig.h index a94041c427..171d03f42a 100644 --- a/audio/core/all-versions/vts/functional/PolicyConfig.h +++ b/audio/core/all-versions/vts/functional/PolicyConfig.h @@ -76,6 +76,16 @@ class PolicyConfig : private PolicyConfigData, public android::AudioPolicyConfig const std::set& getModulesWithDevicesNames() const { return mModulesWithDevicesNames; } + std::string getAttachedSinkDeviceForMixPort(const std::string& moduleName, + const std::string& mixPortName) const { + return findAttachedDevice(getAttachedDevices(moduleName), + getSinkDevicesForMixPort(moduleName, mixPortName)); + } + std::string getAttachedSourceDeviceForMixPort(const std::string& moduleName, + const std::string& mixPortName) const { + return findAttachedDevice(getAttachedDevices(moduleName), + getSourceDevicesForMixPort(moduleName, mixPortName)); + } bool haveInputProfilesInModule(const std::string& name) const { auto module = getModuleFromName(name); return module && !module->getInputProfiles().empty(); @@ -92,6 +102,8 @@ class PolicyConfig : private PolicyConfigData, public android::AudioPolicyConfig for (const auto& module : hwModules) { if (module->getDeclaredDevices().indexOf(device) >= 0) { mModulesWithDevicesNames.insert(module->getName()); + mAttachedDevicesPerModule[module->getName()].push_back( + device->getTagName()); break; } } @@ -100,16 +112,64 @@ class PolicyConfig : private PolicyConfigData, public android::AudioPolicyConfig for (const auto& module : hwModules) { if (module->getDeclaredDevices().indexOf(device) >= 0) { mModulesWithDevicesNames.insert(module->getName()); + mAttachedDevicesPerModule[module->getName()].push_back( + device->getTagName()); break; } } } } } + std::string findAttachedDevice(const std::vector& attachedDevices, + const std::set& possibleDevices) const { + for (const auto& device : attachedDevices) { + if (possibleDevices.count(device)) return device; + } + return {}; + } + std::vector getAttachedDevices(const std::string& moduleName) const { + if (auto iter = mAttachedDevicesPerModule.find(moduleName); + iter != mAttachedDevicesPerModule.end()) { + return iter->second; + } + return {}; + } + std::set getSinkDevicesForMixPort(const std::string& moduleName, + const std::string& mixPortName) const { + std::set result; + auto module = getModuleFromName(moduleName); + if (module != nullptr) { + for (const auto& route : module->getRoutes()) { + for (const auto& source : route->getSources()) { + if (source->getTagName() == mixPortName) { + result.insert(route->getSink()->getTagName()); + } + } + } + } + return result; + } + std::set getSourceDevicesForMixPort(const std::string& moduleName, + const std::string& mixPortName) const { + std::set result; + auto module = getModuleFromName(moduleName); + if (module != nullptr) { + for (const auto& route : module->getRoutes()) { + if (route->getSink()->getTagName() == mixPortName) { + const auto& sources = route->getSources(); + std::transform(sources.begin(), sources.end(), + std::inserter(result, result.end()), + [](const auto& source) { return source->getTagName(); }); + } + } + } + return result; + } const std::string mConfigFileName; status_t mStatus = android::NO_INIT; std::string mFilePath; sp mPrimaryModule = nullptr; std::set mModulesWithDevicesNames; + std::map> mAttachedDevicesPerModule; }; diff --git a/audio/core/all-versions/vts/functional/tests/HalAudioV6_0GeneratorTest.xml b/audio/core/all-versions/vts/functional/tests/HalAudioV6_0GeneratorTest.xml index 0c85a05838..0230447ec6 100644 --- a/audio/core/all-versions/vts/functional/tests/HalAudioV6_0GeneratorTest.xml +++ b/audio/core/all-versions/vts/functional/tests/HalAudioV6_0GeneratorTest.xml @@ -24,6 +24,7 @@