From a8cac48d0f736e99f2bae38de2aa955d3d7a5e1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Gaffie?= Date: Wed, 18 Dec 2019 09:29:58 +0100 Subject: [PATCH] audiopolicy: engine: Add VTS for engine configurable configuration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This CL adds VTS test for engine PFW configuration files (Skipped for default engine, the check is performed by reading the audio_policy_configuration file AND parameter-framework top configuration file) AllSchemas.xsd is made by manual inclusion from all other xsd files. It is used for API files generation. Test: build & run vts --module VtsHalAudioPolicyV1_0Target atest VtsHalAudioPolicyV1_0TargetTest Bug: 141989952 Change-Id: I62730caadafdcb5ebb3083d683625424864afe97 Merged-In: I62730caadafdcb5ebb3083d683625424864afe97 Signed-off-by: François Gaffie --- audio/policy/1.0/vts/functional/Android.bp | 30 +- .../ValidateEngineConfiguration.cpp | 75 ++ .../VtsHalAudioPolicyV1_0TargetTest.xml | 12 + .../policy/1.0/xml/pfw_schemas/AllSchemas.xsd | 754 ++++++++++++++++++ audio/policy/1.0/xml/pfw_schemas/Android.bp | 107 +++ .../1.0/xml/pfw_schemas/ComponentLibrary.xsd | 15 + .../1.0/xml/pfw_schemas/ComponentTypeSet.xsd | 39 + .../xml/pfw_schemas/ConfigurableDomain.xsd | 117 +++ .../xml/pfw_schemas/ConfigurableDomains.xsd | 37 + .../1.0/xml/pfw_schemas/FileIncluder.xsd | 15 + .../policy/1.0/xml/pfw_schemas/Parameter.xsd | 213 +++++ .../ParameterFrameworkConfiguration.xsd | 40 + .../1.0/xml/pfw_schemas/ParameterSettings.xsd | 93 +++ audio/policy/1.0/xml/pfw_schemas/README.md | 87 ++ .../policy/1.0/xml/pfw_schemas/Subsystem.xsd | 32 + .../1.0/xml/pfw_schemas/SystemClass.xsd | 17 + .../1.0/xml/pfw_schemas/W3cXmlAttributes.xsd | 146 ++++ .../1.0/xml/pfw_schemas/api/current.txt | 495 ++++++++++++ .../1.0/xml/pfw_schemas/api/last_current.txt | 0 .../1.0/xml/pfw_schemas/api/last_removed.txt | 0 .../1.0/xml/pfw_schemas/api/removed.txt | 1 + 21 files changed, 2324 insertions(+), 1 deletion(-) create mode 100644 audio/policy/1.0/xml/pfw_schemas/AllSchemas.xsd create mode 100644 audio/policy/1.0/xml/pfw_schemas/Android.bp create mode 100644 audio/policy/1.0/xml/pfw_schemas/ComponentLibrary.xsd create mode 100644 audio/policy/1.0/xml/pfw_schemas/ComponentTypeSet.xsd create mode 100644 audio/policy/1.0/xml/pfw_schemas/ConfigurableDomain.xsd create mode 100644 audio/policy/1.0/xml/pfw_schemas/ConfigurableDomains.xsd create mode 100644 audio/policy/1.0/xml/pfw_schemas/FileIncluder.xsd create mode 100644 audio/policy/1.0/xml/pfw_schemas/Parameter.xsd create mode 100644 audio/policy/1.0/xml/pfw_schemas/ParameterFrameworkConfiguration.xsd create mode 100644 audio/policy/1.0/xml/pfw_schemas/ParameterSettings.xsd create mode 100644 audio/policy/1.0/xml/pfw_schemas/README.md create mode 100644 audio/policy/1.0/xml/pfw_schemas/Subsystem.xsd create mode 100644 audio/policy/1.0/xml/pfw_schemas/SystemClass.xsd create mode 100644 audio/policy/1.0/xml/pfw_schemas/W3cXmlAttributes.xsd create mode 100644 audio/policy/1.0/xml/pfw_schemas/api/current.txt create mode 100644 audio/policy/1.0/xml/pfw_schemas/api/last_current.txt create mode 100644 audio/policy/1.0/xml/pfw_schemas/api/last_removed.txt create mode 100644 audio/policy/1.0/xml/pfw_schemas/api/removed.txt diff --git a/audio/policy/1.0/vts/functional/Android.bp b/audio/policy/1.0/vts/functional/Android.bp index f668a25fcf..b50e501d15 100644 --- a/audio/policy/1.0/vts/functional/Android.bp +++ b/audio/policy/1.0/vts/functional/Android.bp @@ -5,15 +5,31 @@ cc_test { "ValidateEngineConfiguration.cpp", ], static_libs: [ - "android.hardware.audio.common.test.utility", "libxml2", "liblog", + "libmedia_helper", + "libaudiopolicyengine_config", + "libaudiopolicycomponents", + "libaudiopolicyengineconfigurable_pfwwrapper", + "android.hardware.audio.common.test.utility", + "libparameter", + "libpfw_utility", + "libremote-processor", + "libutils", + "libcutils", + "libhidlbase", + "liblog", + "libbase", + ], + shared_libs: [ + "libaudiofoundation", ], // Use test_config for vts-core suite. // TODO(b/146104851): Add auto-gen rules and remove it. test_config: "VtsHalAudioPolicyV1_0TargetTest.xml", cflags: [ "-DXSD_DIR=\"/data/local/tmp\"", + "-DXSD_PFW_DIR=\"/data/local/tmp/Schemas\"", "-Wall", "-Werror", "-Wno-unused-function", @@ -22,6 +38,18 @@ cc_test { ], data: [ ":audio_policy_engine_conf_V1_0", + ":audio_policy_engine_configurable_configuration_V1_0", + ":audio_policy_engine_configurable_configuration_ComponentLibrary_V1_0", + ":audio_policy_engine_configurable_configuration_ComponentTypeSet_V1_0", + ":audio_policy_engine_configurable_configuration_ConfigurableDomain_V1_0", + ":audio_policy_engine_configurable_configuration_ConfigurableDomains_V1_0", + ":audio_policy_engine_configurable_configuration_FileIncluder_V1_0", + ":audio_policy_engine_configurable_configuration_Parameter_V1_0", + ":audio_policy_engine_configurable_configuration_ParameterFrameworkConfiguration_V1_0", + ":audio_policy_engine_configurable_configuration_ParameterSettings_V1_0", + ":audio_policy_engine_configurable_configuration_Subsystem_V1_0", + ":audio_policy_engine_configurable_configuration_SystemClass_V1_0", + ":audio_policy_engine_configurable_configuration_W3cXmlAttributes_V1_0", ], gtest: true, test_suites: [ diff --git a/audio/policy/1.0/vts/functional/ValidateEngineConfiguration.cpp b/audio/policy/1.0/vts/functional/ValidateEngineConfiguration.cpp index 1eb39f95c0..a0aaa6e89f 100644 --- a/audio/policy/1.0/vts/functional/ValidateEngineConfiguration.cpp +++ b/audio/policy/1.0/vts/functional/ValidateEngineConfiguration.cpp @@ -14,6 +14,9 @@ * limitations under the License. */ +#include +#include + #include #include @@ -25,6 +28,11 @@ 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"; +static const std::string configurableSchemas = + std::string(XSD_DIR) + "/audio_policy_engine_configurable_configuration_V1_0.xsd"; +static const std::string configurableConfig = + "parameter-framework/ParameterFrameworkConfigurationPolicy.xml"; + /** * @brief TEST to ensure the audio policy engine configuration file is validating schemas. * Note: this configuration file is not mandatory, an hardcoded fallback is provided, so @@ -36,3 +44,70 @@ TEST(ValidateConfiguration, audioPolicyEngineConfiguration) { "is valid according to the schemas"); EXPECT_VALID_XML_MULTIPLE_LOCATIONS(config.c_str(), locations, schema.c_str()); } + +/** + * @brief deviceUsesConfigurableEngine checks if the configuration file for + * the engine presents on the device AND + * for the configurable engine (aka Parameter-Framework top configuration file) presents. + */ +static bool deviceUsesConfigurableEngine() { + return android::hardware::audio::common::test::utility::validateXmlMultipleLocations( + "", "", "", config.c_str(), locations, schema.c_str()) && + android::hardware::audio::common::test::utility::validateXmlMultipleLocations( + "", "", "", configurableConfig.c_str(), locations, configurableSchemas.c_str()); +} + +TEST(ValidateConfiguration, audioPolicyEngineConfigurable) { + if (!deviceUsesConfigurableEngine()) { + GTEST_SKIP() << "Device using legacy engine without parameter-framework, n-op."; + } + RecordProperty("description", + "Verify that the audio policy engine PFW configuration files " + "are valid according to the schemas"); + + auto testAudioPolicyEnginePfw = [&](bool validateSchema, const std::string& schemasUri) { + auto result = android::engineConfig::parse(); + + ASSERT_NE(nullptr, result.parsedConfig) + << "failed to parse audio policy engine configuration"; + + ASSERT_EQ(result.nbSkippedElement, 0) << "skipped %zu elements " << result.nbSkippedElement; + + std::unique_ptr policyParameterMgr( + new android::audio_policy::ParameterManagerWrapper(validateSchema, schemasUri)); + ASSERT_NE(nullptr, policyParameterMgr) << "failed to create Audio Policy Engine PFW"; + + // Load the criterion types and criteria + for (auto& criterion : result.parsedConfig->criteria) { + android::engineConfig::CriterionType criterionType; + for (auto& configCriterionType : result.parsedConfig->criterionTypes) { + if (configCriterionType.name == criterion.typeName) { + criterionType = configCriterionType; + break; + } + } + ASSERT_FALSE(criterionType.name.empty()) + << "Invalid criterion type for " << criterion.name.c_str(); + policyParameterMgr->addCriterion(criterion.name, criterionType.isInclusive, + criterionType.valuePairs, + criterion.defaultLiteralValue); + } + ASSERT_EQ(0, result.nbSkippedElement) << "failed to parse Audio Policy Engine PFW criteria"; + + // If the PFW cannot validate, it will not start + std::string error; + auto status = policyParameterMgr->start(error); + ASSERT_EQ(status, android::NO_ERROR) + << "failed to " << (validateSchema ? "validate" : "start") + << " Audio Policy Engine PFW: " << error; + + ASSERT_TRUE(policyParameterMgr->isStarted()); + }; + + // First round for sanity to ensure we can launch the Audio Policy Engine PFW without + // schema validation successfully, otherwise it is not forth going on running validation... + testAudioPolicyEnginePfw(false, {}); + + // If second round fails, it means parameter-framework cannot validate schema + testAudioPolicyEnginePfw(true, {XSD_PFW_DIR}); +} diff --git a/audio/policy/1.0/vts/functional/VtsHalAudioPolicyV1_0TargetTest.xml b/audio/policy/1.0/vts/functional/VtsHalAudioPolicyV1_0TargetTest.xml index 4318e926e3..68b390f22a 100644 --- a/audio/policy/1.0/vts/functional/VtsHalAudioPolicyV1_0TargetTest.xml +++ b/audio/policy/1.0/vts/functional/VtsHalAudioPolicyV1_0TargetTest.xml @@ -27,6 +27,18 @@