Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3483b0ad authored by Mikhail Naganov's avatar Mikhail Naganov
Browse files

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
parent 4f51da1c
Loading
Loading
Loading
Loading
+14 −4
Original line number Diff line number Diff line
@@ -36,9 +36,14 @@ using namespace ::android::hardware::audio::CPP_VERSION;
std::vector<DeviceConfigParameter> generateOutputDeviceConfigParameters(bool oneProfilePerDevice) {
    std::vector<DeviceConfigParameter> result;
    for (const auto& device : getDeviceParameters()) {
        auto module =
                getCachedPolicyConfig().getModuleFromName(std::get<PARAM_DEVICE_NAME>(device));
        const std::string moduleName = std::get<PARAM_DEVICE_NAME>(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<DeviceConfigParameter>& getOutputDeviceSingleConfigParameters(
std::vector<DeviceConfigParameter> generateInputDeviceConfigParameters(bool oneProfilePerDevice) {
    std::vector<DeviceConfigParameter> result;
    for (const auto& device : getDeviceParameters()) {
        auto module =
                getCachedPolicyConfig().getModuleFromName(std::get<PARAM_DEVICE_NAME>(device));
        const std::string moduleName = std::get<PARAM_DEVICE_NAME>(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();
+6 −21
Original line number Diff line number Diff line
@@ -499,18 +499,10 @@ static const std::vector<DeviceConfigParameter>& getOutputDevicePcmOnlyConfigPar
            return xsd::isLinearPcm(std::get<PARAM_CONFIG>(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<PARAM_DEVICE_NAME>(std::get<PARAM_DEVICE>(cfg)),
                                    std::get<PARAM_PORT_NAME>(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<DeviceConfigParameter>& 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<PARAM_DEVICE_NAME>(
                                                    std::get<PARAM_DEVICE>(cfg)),
                                            std::get<PARAM_PORT_NAME>(cfg))
                                    .empty();
                                   }) == flags.end();
                });
        return pcmParams;
    }();
+14 −4
Original line number Diff line number Diff line
@@ -95,11 +95,16 @@ static AudioOffloadInfo generateOffloadInfo(const AudioConfigBase& base) {
std::vector<DeviceConfigParameter> generateOutputDeviceConfigParameters(bool oneProfilePerDevice) {
    std::vector<DeviceConfigParameter> result;
    for (const auto& device : getDeviceParameters()) {
        auto module =
                getCachedPolicyConfig().getModuleFromName(std::get<PARAM_DEVICE_NAME>(device));
        const std::string moduleName = std::get<PARAM_DEVICE_NAME>(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<DeviceConfigParameter>& getOutputDeviceInvalidConfigParameters
std::vector<DeviceConfigParameter> generateInputDeviceConfigParameters(bool oneProfilePerDevice) {
    std::vector<DeviceConfigParameter> result;
    for (const auto& device : getDeviceParameters()) {
        auto module =
                getCachedPolicyConfig().getModuleFromName(std::get<PARAM_DEVICE_NAME>(device));
        const std::string moduleName = std::get<PARAM_DEVICE_NAME>(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<AudioInOutFlag> flags;
            if (mixPort.hasFlags()) {
                std::transform(mixPort.getFlags().begin(), mixPort.getFlags().end(),
+2 −0
Original line number Diff line number Diff line
@@ -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",
}
+60 −0
Original line number Diff line number Diff line
@@ -76,6 +76,16 @@ class PolicyConfig : private PolicyConfigData, public android::AudioPolicyConfig
    const std::set<std::string>& 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<std::string>& attachedDevices,
                                   const std::set<std::string>& possibleDevices) const {
        for (const auto& device : attachedDevices) {
            if (possibleDevices.count(device)) return device;
        }
        return {};
    }
    std::vector<std::string> getAttachedDevices(const std::string& moduleName) const {
        if (auto iter = mAttachedDevicesPerModule.find(moduleName);
            iter != mAttachedDevicesPerModule.end()) {
            return iter->second;
        }
        return {};
    }
    std::set<std::string> getSinkDevicesForMixPort(const std::string& moduleName,
                                                   const std::string& mixPortName) const {
        std::set<std::string> 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<std::string> getSourceDevicesForMixPort(const std::string& moduleName,
                                                     const std::string& mixPortName) const {
        std::set<std::string> 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<const android::HwModule> mPrimaryModule = nullptr;
    std::set<std::string> mModulesWithDevicesNames;
    std::map<std::string, std::vector<std::string>> mAttachedDevicesPerModule;
};
Loading