Loading audio/2.0/default/ParametersUtil.cpp +17 −7 Original line number Diff line number Diff line Loading @@ -22,7 +22,9 @@ namespace audio { namespace V2_0 { namespace implementation { // Static method and not private method to avoid leaking status_t dependency /** Converts a status_t in Result according to the rules of AudioParameter::get* * Note: Static method and not private method to avoid leaking status_t dependency */ static Result getHalStatusToResult(status_t status) { switch (status) { case OK: Loading Loading @@ -141,12 +143,20 @@ Result ParametersUtil::setParametersImpl( Result ParametersUtil::setParams(const AudioParameter& param) { int halStatus = halSetParameters(param.toString().string()); if (halStatus == OK) return Result::OK; else if (halStatus == -ENOSYS) return Result::INVALID_STATE; else return Result::INVALID_ARGUMENTS; switch (halStatus) { case OK: return Result::OK; case -EINVAL: return Result::INVALID_ARGUMENTS; case -ENODATA: return Result::INVALID_STATE; case -ENODEV: return Result::NOT_INITIALIZED; // The rest of the API (*::analyseStatus) returns NOT_SUPPORTED // when the legacy API returns -ENOSYS // However the legacy API explicitly state that for get_paramers, // -ENOSYS should be returned if // "the implementation does not accept a parameter change while the // output is active but the parameter is acceptable otherwise" case -ENOSYS: return Result::INVALID_STATE; default: return Result::INVALID_ARGUMENTS; } } } // namespace implementation Loading audio/2.0/vts/functional/ValidateAudioConfiguration.cpp +6 −10 Original line number Diff line number Diff line Loading @@ -20,15 +20,11 @@ #include "utility/ValidateXml.h" TEST(CheckConfig, audioPolicyConfigurationValidation) { const char* configName = "audio_policy_configuration.xml"; const char* possibleConfigLocations[] = {"/odm/etc", "/vendor/etc", "/system/etc"}; const char* configSchemaPath = "/data/local/tmp/audio_policy_configuration.xsd"; RecordProperty("description", "Verify that the audio policy configuration file " "is valid according to the schema"); for (std::string folder : possibleConfigLocations) { const auto configPath = folder + '/' + configName; if (access(configPath.c_str(), R_OK) == 0) { ASSERT_VALID_XML(configPath.c_str(), configSchemaPath); return; // The framework does not read past the first config file found } } std::vector<const char*> locations = {"/odm/etc", "/vendor/etc", "/system/etc"}; EXPECT_ONE_VALID_XML_MULTIPLE_LOCATIONS("audio_policy_configuration.xml", locations, "/data/local/tmp/audio_policy_configuration.xsd"); } audio/common/test/utility/include/utility/ValidateXml.h +33 −2 Original line number Diff line number Diff line Loading @@ -32,13 +32,44 @@ namespace utility { * See ASSERT_VALID_XML for a helper macro. */ ::testing::AssertionResult validateXml(const char* xmlFilePathExpr, const char* xsdFilePathExpr, const char* xmlFilePath, const char* xsdPathName); const char* xmlFilePath, const char* xsdFilePath); /** Helper gtest ASSERT to test xml validity against an xsd. */ /** Helper gtest ASSERT to test XML validity against an XSD. */ #define ASSERT_VALID_XML(xmlFilePath, xsdFilePath) \ ASSERT_PRED_FORMAT2(::android::hardware::audio::common::test::utility::validateXml, \ xmlFilePath, xsdFilePath) /** Helper gtest EXPECT to test XML validity against an XSD. */ #define EXPECT_VALID_XML(xmlFilePath, xsdFilePath) \ EXPECT_PRED_FORMAT2(::android::hardware::audio::common::test::utility::validateXml, \ xmlFilePath, xsdFilePath) /** Validate an XML according to an xsd. * The XML file must be in at least one of the provided locations. * If multiple are found, all are validated. */ ::testing::AssertionResult validateXmlMultipleLocations( const char* xmlFileNameExpr, const char* xmlFileLocationsExpr, const char* xsdFilePathExpr, const char* xmlFileName, std::vector<const char*> xmlFileLocations, const char* xsdFilePath); /** ASSERT that an XML is valid according to an xsd. * The XML file must be in at least one of the provided locations. * If multiple are found, all are validated. */ #define ASSERT_ONE_VALID_XML_MULTIPLE_LOCATIONS(xmlFileName, xmlFileLocations, xsdFilePath) \ ASSERT_PRED_FORMAT3( \ ::android::hardware::audio::common::test::utility::validateXmlMultipleLocations, \ xmlFileName, xmlFileLocations, xsdFilePath) /** EXPECT an XML to be valid according to an xsd. * The XML file must be in at least one of the provided locations. * If multiple are found, all are validated. */ #define EXPECT_ONE_VALID_XML_MULTIPLE_LOCATIONS(xmlFileName, xmlFileLocations, xsdFilePath) \ EXPECT_PRED_FORMAT3( \ ::android::hardware::audio::common::test::utility::validateXmlMultipleLocations, \ xmlFileName, xmlFileLocations, xsdFilePath) } // utility } // test } // common Loading audio/common/test/utility/src/ValidateXml.cpp +39 −3 Original line number Diff line number Diff line Loading @@ -17,6 +17,8 @@ #define LOG_TAG "ValidateAudioConfig" #include <utils/Log.h> #include <numeric> #define LIBXML_SCHEMAS_ENABLED #include <libxml/xmlschemastypes.h> #define LIBXML_XINCLUDE_ENABLED Loading Loading @@ -96,7 +98,7 @@ struct Libxml2Global { auto context = [&]() { return std::string() + " While validating: " + xmlFilePathExpr + "\n Which is: " + xmlFilePath + "\nAgainst the schema: " + xsdFilePathExpr + "\n Which is: " + xsdFilePath + "Libxml2 errors\n" + libxml2.getErrors(); "\n Which is: " + xsdFilePath + "\nLibxml2 errors:\n" + libxml2.getErrors(); }; auto schemaParserCtxt = make_xmlUnique(xmlSchemaNewParserCtxt(xsdFilePath)); Loading @@ -117,7 +119,7 @@ struct Libxml2Global { auto schemaCtxt = make_xmlUnique(xmlSchemaNewValidCtxt(schema.get())); int ret = xmlSchemaValidateDoc(schemaCtxt.get(), doc.get()); if (ret > 0) { return ::testing::AssertionFailure() << "xml is not valid according to the xsd.\n" return ::testing::AssertionFailure() << "XML is not valid according to the xsd\n" << context(); } if (ret < 0) { Loading @@ -127,6 +129,40 @@ struct Libxml2Global { return ::testing::AssertionSuccess(); } ::testing::AssertionResult validateXmlMultipleLocations( const char* xmlFileNameExpr, const char* xmlFileLocationsExpr, const char* xsdFilePathExpr, const char* xmlFileName, std::vector<const char*> xmlFileLocations, const char* xsdFilePath) { using namespace std::string_literals; std::vector<std::string> errors; std::vector<std::string> foundFiles; for (const char* 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 continue; } foundFiles.push_back(" " + xmlFilePath + '\n'); auto result = validateXml("xmlFilePath", xsdFilePathExpr, xmlFilePath.c_str(), xsdFilePath); if (!result) { errors.push_back(result.message()); } } if (foundFiles.empty()) { errors.push_back("No xml file found in provided locations.\n"); } return ::testing::AssertionResult(errors.empty()) << errors.size() << " error" << (errors.size() == 1 ? " " : "s ") << std::accumulate(begin(errors), end(errors), "occurred during xml validation:\n"s) << " While validating all: " << xmlFileNameExpr << "\n Which is: " << xmlFileName << "\n In the following folders: " << xmlFileLocationsExpr << "\n Which is: " << ::testing::PrintToString(xmlFileLocations); } } // utility } // test } // common Loading audio/effect/2.0/vts/functional/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ cc_test { "libxml2", ], shared_libs: [ "libeffectsconfig", "libicuuc", ], } Loading
audio/2.0/default/ParametersUtil.cpp +17 −7 Original line number Diff line number Diff line Loading @@ -22,7 +22,9 @@ namespace audio { namespace V2_0 { namespace implementation { // Static method and not private method to avoid leaking status_t dependency /** Converts a status_t in Result according to the rules of AudioParameter::get* * Note: Static method and not private method to avoid leaking status_t dependency */ static Result getHalStatusToResult(status_t status) { switch (status) { case OK: Loading Loading @@ -141,12 +143,20 @@ Result ParametersUtil::setParametersImpl( Result ParametersUtil::setParams(const AudioParameter& param) { int halStatus = halSetParameters(param.toString().string()); if (halStatus == OK) return Result::OK; else if (halStatus == -ENOSYS) return Result::INVALID_STATE; else return Result::INVALID_ARGUMENTS; switch (halStatus) { case OK: return Result::OK; case -EINVAL: return Result::INVALID_ARGUMENTS; case -ENODATA: return Result::INVALID_STATE; case -ENODEV: return Result::NOT_INITIALIZED; // The rest of the API (*::analyseStatus) returns NOT_SUPPORTED // when the legacy API returns -ENOSYS // However the legacy API explicitly state that for get_paramers, // -ENOSYS should be returned if // "the implementation does not accept a parameter change while the // output is active but the parameter is acceptable otherwise" case -ENOSYS: return Result::INVALID_STATE; default: return Result::INVALID_ARGUMENTS; } } } // namespace implementation Loading
audio/2.0/vts/functional/ValidateAudioConfiguration.cpp +6 −10 Original line number Diff line number Diff line Loading @@ -20,15 +20,11 @@ #include "utility/ValidateXml.h" TEST(CheckConfig, audioPolicyConfigurationValidation) { const char* configName = "audio_policy_configuration.xml"; const char* possibleConfigLocations[] = {"/odm/etc", "/vendor/etc", "/system/etc"}; const char* configSchemaPath = "/data/local/tmp/audio_policy_configuration.xsd"; RecordProperty("description", "Verify that the audio policy configuration file " "is valid according to the schema"); for (std::string folder : possibleConfigLocations) { const auto configPath = folder + '/' + configName; if (access(configPath.c_str(), R_OK) == 0) { ASSERT_VALID_XML(configPath.c_str(), configSchemaPath); return; // The framework does not read past the first config file found } } std::vector<const char*> locations = {"/odm/etc", "/vendor/etc", "/system/etc"}; EXPECT_ONE_VALID_XML_MULTIPLE_LOCATIONS("audio_policy_configuration.xml", locations, "/data/local/tmp/audio_policy_configuration.xsd"); }
audio/common/test/utility/include/utility/ValidateXml.h +33 −2 Original line number Diff line number Diff line Loading @@ -32,13 +32,44 @@ namespace utility { * See ASSERT_VALID_XML for a helper macro. */ ::testing::AssertionResult validateXml(const char* xmlFilePathExpr, const char* xsdFilePathExpr, const char* xmlFilePath, const char* xsdPathName); const char* xmlFilePath, const char* xsdFilePath); /** Helper gtest ASSERT to test xml validity against an xsd. */ /** Helper gtest ASSERT to test XML validity against an XSD. */ #define ASSERT_VALID_XML(xmlFilePath, xsdFilePath) \ ASSERT_PRED_FORMAT2(::android::hardware::audio::common::test::utility::validateXml, \ xmlFilePath, xsdFilePath) /** Helper gtest EXPECT to test XML validity against an XSD. */ #define EXPECT_VALID_XML(xmlFilePath, xsdFilePath) \ EXPECT_PRED_FORMAT2(::android::hardware::audio::common::test::utility::validateXml, \ xmlFilePath, xsdFilePath) /** Validate an XML according to an xsd. * The XML file must be in at least one of the provided locations. * If multiple are found, all are validated. */ ::testing::AssertionResult validateXmlMultipleLocations( const char* xmlFileNameExpr, const char* xmlFileLocationsExpr, const char* xsdFilePathExpr, const char* xmlFileName, std::vector<const char*> xmlFileLocations, const char* xsdFilePath); /** ASSERT that an XML is valid according to an xsd. * The XML file must be in at least one of the provided locations. * If multiple are found, all are validated. */ #define ASSERT_ONE_VALID_XML_MULTIPLE_LOCATIONS(xmlFileName, xmlFileLocations, xsdFilePath) \ ASSERT_PRED_FORMAT3( \ ::android::hardware::audio::common::test::utility::validateXmlMultipleLocations, \ xmlFileName, xmlFileLocations, xsdFilePath) /** EXPECT an XML to be valid according to an xsd. * The XML file must be in at least one of the provided locations. * If multiple are found, all are validated. */ #define EXPECT_ONE_VALID_XML_MULTIPLE_LOCATIONS(xmlFileName, xmlFileLocations, xsdFilePath) \ EXPECT_PRED_FORMAT3( \ ::android::hardware::audio::common::test::utility::validateXmlMultipleLocations, \ xmlFileName, xmlFileLocations, xsdFilePath) } // utility } // test } // common Loading
audio/common/test/utility/src/ValidateXml.cpp +39 −3 Original line number Diff line number Diff line Loading @@ -17,6 +17,8 @@ #define LOG_TAG "ValidateAudioConfig" #include <utils/Log.h> #include <numeric> #define LIBXML_SCHEMAS_ENABLED #include <libxml/xmlschemastypes.h> #define LIBXML_XINCLUDE_ENABLED Loading Loading @@ -96,7 +98,7 @@ struct Libxml2Global { auto context = [&]() { return std::string() + " While validating: " + xmlFilePathExpr + "\n Which is: " + xmlFilePath + "\nAgainst the schema: " + xsdFilePathExpr + "\n Which is: " + xsdFilePath + "Libxml2 errors\n" + libxml2.getErrors(); "\n Which is: " + xsdFilePath + "\nLibxml2 errors:\n" + libxml2.getErrors(); }; auto schemaParserCtxt = make_xmlUnique(xmlSchemaNewParserCtxt(xsdFilePath)); Loading @@ -117,7 +119,7 @@ struct Libxml2Global { auto schemaCtxt = make_xmlUnique(xmlSchemaNewValidCtxt(schema.get())); int ret = xmlSchemaValidateDoc(schemaCtxt.get(), doc.get()); if (ret > 0) { return ::testing::AssertionFailure() << "xml is not valid according to the xsd.\n" return ::testing::AssertionFailure() << "XML is not valid according to the xsd\n" << context(); } if (ret < 0) { Loading @@ -127,6 +129,40 @@ struct Libxml2Global { return ::testing::AssertionSuccess(); } ::testing::AssertionResult validateXmlMultipleLocations( const char* xmlFileNameExpr, const char* xmlFileLocationsExpr, const char* xsdFilePathExpr, const char* xmlFileName, std::vector<const char*> xmlFileLocations, const char* xsdFilePath) { using namespace std::string_literals; std::vector<std::string> errors; std::vector<std::string> foundFiles; for (const char* 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 continue; } foundFiles.push_back(" " + xmlFilePath + '\n'); auto result = validateXml("xmlFilePath", xsdFilePathExpr, xmlFilePath.c_str(), xsdFilePath); if (!result) { errors.push_back(result.message()); } } if (foundFiles.empty()) { errors.push_back("No xml file found in provided locations.\n"); } return ::testing::AssertionResult(errors.empty()) << errors.size() << " error" << (errors.size() == 1 ? " " : "s ") << std::accumulate(begin(errors), end(errors), "occurred during xml validation:\n"s) << " While validating all: " << xmlFileNameExpr << "\n Which is: " << xmlFileName << "\n In the following folders: " << xmlFileLocationsExpr << "\n Which is: " << ::testing::PrintToString(xmlFileLocations); } } // utility } // test } // common Loading
audio/effect/2.0/vts/functional/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ cc_test { "libxml2", ], shared_libs: [ "libeffectsconfig", "libicuuc", ], }