From 5a6ffb21a59d6575a359eb30f35855615839a9c2 Mon Sep 17 00:00:00 2001 From: Mikhail Naganov Date: Tue, 14 Apr 2020 14:53:22 -0700 Subject: [PATCH] audio: Centralize audio configuration paths specification The list of possible paths for the audio configuration files is now retrieved using audio_get_configuration_paths() function. All duplicated lists of known configuration directories have been removed. Bug: 153680356 Test: atest VtsHalAudioV5_0TargetTest \ VtsHalAudioPolicyV1_0TargetTest \ VtsHalAudioEffectV5_0TargetTest Change-Id: I1e40fdf8d6e3a5ac339f7f138f62063bb87bd3da --- .../utility/include/utility/ValidateXml.h | 27 +++++++++++++++++-- .../test/utility/src/ValidateXml.cpp | 21 +++++++-------- .../vts/functional/AudioPrimaryHidlHalTest.h | 11 ++++---- .../ValidateAudioEffectsConfiguration.cpp | 8 +++--- .../ValidateEngineConfiguration.cpp | 12 ++++++--- 5 files changed, 54 insertions(+), 25 deletions(-) diff --git a/audio/common/all-versions/test/utility/include/utility/ValidateXml.h b/audio/common/all-versions/test/utility/include/utility/ValidateXml.h index ee206f7458..274a10b515 100644 --- a/audio/common/all-versions/test/utility/include/utility/ValidateXml.h +++ b/audio/common/all-versions/test/utility/include/utility/ValidateXml.h @@ -51,8 +51,31 @@ namespace utility { */ template ::testing::AssertionResult validateXmlMultipleLocations( - const char* xmlFileNameExpr, const char* xmlFileLocationsExpr, const char* xsdFilePathExpr, - const char* xmlFileName, std::vector xmlFileLocations, const char* xsdFilePath); + const char* xmlFileNameExpr, const char* xmlFileLocationsExpr, const char* xsdFilePathExpr, + const char* xmlFileName, const std::vector& xmlFileLocations, + const char* xsdFilePath); +template +::testing::AssertionResult validateXmlMultipleLocations( + const char* xmlFileNameExpr, const char* xmlFileLocationsExpr, const char* xsdFilePathExpr, + const char* xmlFileName, std::initializer_list xmlFileLocations, + const char* xsdFilePath) { + return validateXmlMultipleLocations( + xmlFileNameExpr, xmlFileLocationsExpr, xsdFilePathExpr, xmlFileName, + std::vector(xmlFileLocations.begin(), xmlFileLocations.end()), + xsdFilePath); +} +template +::testing::AssertionResult validateXmlMultipleLocations(const char* xmlFileNameExpr, + const char* xmlFileLocationsExpr, + const char* xsdFilePathExpr, + const char* xmlFileName, + std::vector xmlFileLocations, + const char* xsdFilePath) { + return validateXmlMultipleLocations( + xmlFileNameExpr, xmlFileLocationsExpr, xsdFilePathExpr, xmlFileName, + std::vector(xmlFileLocations.begin(), xmlFileLocations.end()), + xsdFilePath); +} /** ASSERT that all found XML are valid according to an xsd. */ #define ASSERT_VALID_XML_MULTIPLE_LOCATIONS(xmlFileName, xmlFileLocations, xsdFilePath) \ diff --git a/audio/common/all-versions/test/utility/src/ValidateXml.cpp b/audio/common/all-versions/test/utility/src/ValidateXml.cpp index bdafa82d6b..a866104b38 100644 --- a/audio/common/all-versions/test/utility/src/ValidateXml.cpp +++ b/audio/common/all-versions/test/utility/src/ValidateXml.cpp @@ -131,14 +131,15 @@ struct Libxml2Global { template ::testing::AssertionResult validateXmlMultipleLocations( - const char* xmlFileNameExpr, const char* xmlFileLocationsExpr, const char* xsdFilePathExpr, - const char* xmlFileName, std::vector xmlFileLocations, const char* xsdFilePath) { + const char* xmlFileNameExpr, const char* xmlFileLocationsExpr, const char* xsdFilePathExpr, + const char* xmlFileName, const std::vector& xmlFileLocations, + const char* xsdFilePath) { using namespace std::string_literals; std::vector errors; std::vector foundFiles; - for (const char* location : xmlFileLocations) { + for (const auto& location : xmlFileLocations) { std::string xmlFilePath = location + "/"s + xmlFileName; if (access(xmlFilePath.c_str(), F_OK) != 0) { // If the file does not exist ignore this location and fallback on the next one @@ -166,14 +167,12 @@ template : "\nWhere no file might exist."); } -template ::testing::AssertionResult validateXmlMultipleLocations(const char*, const char*, - const char*, const char*, - std::vector, - const char*); -template ::testing::AssertionResult validateXmlMultipleLocations(const char*, const char*, - const char*, const char*, - std::vector, - const char*); +template ::testing::AssertionResult validateXmlMultipleLocations( + const char*, const char*, const char*, const char*, const std::vector&, + const char*); +template ::testing::AssertionResult validateXmlMultipleLocations( + const char*, const char*, const char*, const char*, const std::vector&, + const char*); } // namespace utility } // namespace test diff --git a/audio/core/all-versions/vts/functional/AudioPrimaryHidlHalTest.h b/audio/core/all-versions/vts/functional/AudioPrimaryHidlHalTest.h index da30adeec0..af6e9e8177 100644 --- a/audio/core/all-versions/vts/functional/AudioPrimaryHidlHalTest.h +++ b/audio/core/all-versions/vts/functional/AudioPrimaryHidlHalTest.h @@ -35,6 +35,7 @@ #include #include +#include #include PATH(android/hardware/audio/FILE_VERSION/IDevice.h) #include PATH(android/hardware/audio/FILE_VERSION/IDevicesFactory.h) @@ -133,7 +134,6 @@ class HidlTest : public ::testing::Test { ////////////////////////// Audio policy configuration //////////////////////// ////////////////////////////////////////////////////////////////////////////// -static const std::vector kConfigLocations = {"/odm/etc", "/vendor/etc", "/system/etc"}; static constexpr char kConfigFileName[] = "audio_policy_configuration.xml"; // Stringify the argument. @@ -152,8 +152,8 @@ class PolicyConfig : private PolicyConfigData, public AudioPolicyConfig { PolicyConfig() : AudioPolicyConfig(hwModules, availableOutputDevices, availableInputDevices, defaultOutputDevice) { - for (const char* location : kConfigLocations) { - std::string path = std::string(location) + '/' + kConfigFileName; + for (const auto& location : android::audio_get_configuration_paths()) { + std::string path = location + '/' + kConfigFileName; if (access(path.c_str(), F_OK) == 0) { mFilePath = path; break; @@ -186,7 +186,7 @@ class PolicyConfig : private PolicyConfigData, public AudioPolicyConfig { std::string getError() const { if (mFilePath.empty()) { return std::string{"Could not find "} + kConfigFileName + - " file in: " + testing::PrintToString(kConfigLocations); + " file in: " + testing::PrintToString(android::audio_get_configuration_paths()); } else { return "Invalid config file: " + mFilePath; } @@ -302,7 +302,8 @@ TEST(CheckConfig, audioPolicyConfigurationValidation) { "is valid according to the schema"); const char* xsd = "/data/local/tmp/audio_policy_configuration_" STRINGIFY(CPP_VERSION) ".xsd"; - EXPECT_ONE_VALID_XML_MULTIPLE_LOCATIONS(kConfigFileName, kConfigLocations, xsd); + EXPECT_ONE_VALID_XML_MULTIPLE_LOCATIONS(kConfigFileName, + android::audio_get_configuration_paths(), xsd); } class AudioPolicyConfigTest : public AudioHidlTestWithDeviceParameter { diff --git a/audio/effect/all-versions/vts/functional/ValidateAudioEffectsConfiguration.cpp b/audio/effect/all-versions/vts/functional/ValidateAudioEffectsConfiguration.cpp index 9c0135bf93..f2516349d4 100644 --- a/audio/effect/all-versions/vts/functional/ValidateAudioEffectsConfiguration.cpp +++ b/audio/effect/all-versions/vts/functional/ValidateAudioEffectsConfiguration.cpp @@ -18,6 +18,7 @@ #include #include +#include // clang-format off #include PATH(android/hardware/audio/effect/FILE_VERSION/IEffectsFactory.h) // clang-format on @@ -41,13 +42,14 @@ TEST(CheckConfig, audioEffectsConfigurationValidation) { GTEST_SKIP() << "No Effects HAL version " STRINGIFY(CPP_VERSION) " on this device"; } - std::vector locations(std::begin(DEFAULT_LOCATIONS), std::end(DEFAULT_LOCATIONS)); const char* xsd = "/data/local/tmp/audio_effects_conf_" STRINGIFY(CPP_VERSION) ".xsd"; #if MAJOR_VERSION == 2 // In V2, audio effect XML is not required. .conf is still allowed though deprecated - EXPECT_VALID_XML_MULTIPLE_LOCATIONS(DEFAULT_NAME, locations, xsd); + EXPECT_VALID_XML_MULTIPLE_LOCATIONS(DEFAULT_NAME, android::audio_get_configuration_paths(), + xsd); #elif MAJOR_VERSION >= 4 // Starting with V4, audio effect XML is required - EXPECT_ONE_VALID_XML_MULTIPLE_LOCATIONS(DEFAULT_NAME, locations, xsd); + EXPECT_ONE_VALID_XML_MULTIPLE_LOCATIONS(DEFAULT_NAME, android::audio_get_configuration_paths(), + xsd); #endif } diff --git a/audio/policy/1.0/vts/functional/ValidateEngineConfiguration.cpp b/audio/policy/1.0/vts/functional/ValidateEngineConfiguration.cpp index a0aaa6e89f..5741fa97cc 100644 --- a/audio/policy/1.0/vts/functional/ValidateEngineConfiguration.cpp +++ b/audio/policy/1.0/vts/functional/ValidateEngineConfiguration.cpp @@ -23,7 +23,8 @@ #include #include "utility/ValidateXml.h" -static const std::vector locations = {"/odm/etc", "/vendor/etc", "/system/etc"}; +#include + static const std::string config = "audio_policy_engine_configuration.xml"; static const std::string schema = std::string(XSD_DIR) + "/audio_policy_engine_configuration_V1_0.xsd"; @@ -42,7 +43,8 @@ TEST(ValidateConfiguration, audioPolicyEngineConfiguration) { RecordProperty("description", "Verify that the audio policy engine configuration file " "is valid according to the schemas"); - EXPECT_VALID_XML_MULTIPLE_LOCATIONS(config.c_str(), locations, schema.c_str()); + EXPECT_VALID_XML_MULTIPLE_LOCATIONS(config.c_str(), android::audio_get_configuration_paths(), + schema.c_str()); } /** @@ -52,9 +54,11 @@ TEST(ValidateConfiguration, audioPolicyEngineConfiguration) { */ static bool deviceUsesConfigurableEngine() { return android::hardware::audio::common::test::utility::validateXmlMultipleLocations( - "", "", "", config.c_str(), locations, schema.c_str()) && + "", "", "", config.c_str(), android::audio_get_configuration_paths(), + schema.c_str()) && android::hardware::audio::common::test::utility::validateXmlMultipleLocations( - "", "", "", configurableConfig.c_str(), locations, configurableSchemas.c_str()); + "", "", "", configurableConfig.c_str(), android::audio_get_configuration_paths(), + configurableSchemas.c_str()); } TEST(ValidateConfiguration, audioPolicyEngineConfigurable) {