mirror of
https://github.com/Evolution-X/hardware_interfaces
synced 2026-02-01 16:50:18 +00:00
Merge "audio: Centralize audio configuration paths specification" am: c2e1f3baef
Change-Id: Ib813f7c89896fec95ece996b8cd4e0482fa797af
This commit is contained in:
@@ -51,8 +51,31 @@ namespace utility {
|
|||||||
*/
|
*/
|
||||||
template <bool atLeastOneRequired = true>
|
template <bool atLeastOneRequired = true>
|
||||||
::testing::AssertionResult validateXmlMultipleLocations(
|
::testing::AssertionResult validateXmlMultipleLocations(
|
||||||
const char* xmlFileNameExpr, const char* xmlFileLocationsExpr, const char* xsdFilePathExpr,
|
const char* xmlFileNameExpr, const char* xmlFileLocationsExpr, const char* xsdFilePathExpr,
|
||||||
const char* xmlFileName, std::vector<const char*> xmlFileLocations, const char* xsdFilePath);
|
const char* xmlFileName, const std::vector<std::string>& xmlFileLocations,
|
||||||
|
const char* xsdFilePath);
|
||||||
|
template <bool atLeastOneRequired = true>
|
||||||
|
::testing::AssertionResult validateXmlMultipleLocations(
|
||||||
|
const char* xmlFileNameExpr, const char* xmlFileLocationsExpr, const char* xsdFilePathExpr,
|
||||||
|
const char* xmlFileName, std::initializer_list<const char*> xmlFileLocations,
|
||||||
|
const char* xsdFilePath) {
|
||||||
|
return validateXmlMultipleLocations<atLeastOneRequired>(
|
||||||
|
xmlFileNameExpr, xmlFileLocationsExpr, xsdFilePathExpr, xmlFileName,
|
||||||
|
std::vector<std::string>(xmlFileLocations.begin(), xmlFileLocations.end()),
|
||||||
|
xsdFilePath);
|
||||||
|
}
|
||||||
|
template <bool atLeastOneRequired = true>
|
||||||
|
::testing::AssertionResult validateXmlMultipleLocations(const char* xmlFileNameExpr,
|
||||||
|
const char* xmlFileLocationsExpr,
|
||||||
|
const char* xsdFilePathExpr,
|
||||||
|
const char* xmlFileName,
|
||||||
|
std::vector<const char*> xmlFileLocations,
|
||||||
|
const char* xsdFilePath) {
|
||||||
|
return validateXmlMultipleLocations<atLeastOneRequired>(
|
||||||
|
xmlFileNameExpr, xmlFileLocationsExpr, xsdFilePathExpr, xmlFileName,
|
||||||
|
std::vector<std::string>(xmlFileLocations.begin(), xmlFileLocations.end()),
|
||||||
|
xsdFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
/** ASSERT that all found XML are valid according to an xsd. */
|
/** ASSERT that all found XML are valid according to an xsd. */
|
||||||
#define ASSERT_VALID_XML_MULTIPLE_LOCATIONS(xmlFileName, xmlFileLocations, xsdFilePath) \
|
#define ASSERT_VALID_XML_MULTIPLE_LOCATIONS(xmlFileName, xmlFileLocations, xsdFilePath) \
|
||||||
|
|||||||
@@ -131,14 +131,15 @@ struct Libxml2Global {
|
|||||||
|
|
||||||
template <bool atLeastOneRequired>
|
template <bool atLeastOneRequired>
|
||||||
::testing::AssertionResult validateXmlMultipleLocations(
|
::testing::AssertionResult validateXmlMultipleLocations(
|
||||||
const char* xmlFileNameExpr, const char* xmlFileLocationsExpr, const char* xsdFilePathExpr,
|
const char* xmlFileNameExpr, const char* xmlFileLocationsExpr, const char* xsdFilePathExpr,
|
||||||
const char* xmlFileName, std::vector<const char*> xmlFileLocations, const char* xsdFilePath) {
|
const char* xmlFileName, const std::vector<std::string>& xmlFileLocations,
|
||||||
|
const char* xsdFilePath) {
|
||||||
using namespace std::string_literals;
|
using namespace std::string_literals;
|
||||||
|
|
||||||
std::vector<std::string> errors;
|
std::vector<std::string> errors;
|
||||||
std::vector<std::string> foundFiles;
|
std::vector<std::string> foundFiles;
|
||||||
|
|
||||||
for (const char* location : xmlFileLocations) {
|
for (const auto& location : xmlFileLocations) {
|
||||||
std::string xmlFilePath = location + "/"s + xmlFileName;
|
std::string xmlFilePath = location + "/"s + xmlFileName;
|
||||||
if (access(xmlFilePath.c_str(), F_OK) != 0) {
|
if (access(xmlFilePath.c_str(), F_OK) != 0) {
|
||||||
// If the file does not exist ignore this location and fallback on the next one
|
// If the file does not exist ignore this location and fallback on the next one
|
||||||
@@ -166,14 +167,12 @@ template <bool atLeastOneRequired>
|
|||||||
: "\nWhere no file might exist.");
|
: "\nWhere no file might exist.");
|
||||||
}
|
}
|
||||||
|
|
||||||
template ::testing::AssertionResult validateXmlMultipleLocations<true>(const char*, const char*,
|
template ::testing::AssertionResult validateXmlMultipleLocations<true>(
|
||||||
const char*, const char*,
|
const char*, const char*, const char*, const char*, const std::vector<std::string>&,
|
||||||
std::vector<const char*>,
|
const char*);
|
||||||
const char*);
|
template ::testing::AssertionResult validateXmlMultipleLocations<false>(
|
||||||
template ::testing::AssertionResult validateXmlMultipleLocations<false>(const char*, const char*,
|
const char*, const char*, const char*, const char*, const std::vector<std::string>&,
|
||||||
const char*, const char*,
|
const char*);
|
||||||
std::vector<const char*>,
|
|
||||||
const char*);
|
|
||||||
|
|
||||||
} // namespace utility
|
} // namespace utility
|
||||||
} // namespace test
|
} // namespace test
|
||||||
|
|||||||
@@ -35,6 +35,7 @@
|
|||||||
#include <hwbinder/IPCThreadState.h>
|
#include <hwbinder/IPCThreadState.h>
|
||||||
|
|
||||||
#include <android-base/logging.h>
|
#include <android-base/logging.h>
|
||||||
|
#include <system/audio_config.h>
|
||||||
|
|
||||||
#include PATH(android/hardware/audio/FILE_VERSION/IDevice.h)
|
#include PATH(android/hardware/audio/FILE_VERSION/IDevice.h)
|
||||||
#include PATH(android/hardware/audio/FILE_VERSION/IDevicesFactory.h)
|
#include PATH(android/hardware/audio/FILE_VERSION/IDevicesFactory.h)
|
||||||
@@ -133,7 +134,6 @@ class HidlTest : public ::testing::Test {
|
|||||||
////////////////////////// Audio policy configuration ////////////////////////
|
////////////////////////// Audio policy configuration ////////////////////////
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
static const std::vector<const char*> kConfigLocations = {"/odm/etc", "/vendor/etc", "/system/etc"};
|
|
||||||
static constexpr char kConfigFileName[] = "audio_policy_configuration.xml";
|
static constexpr char kConfigFileName[] = "audio_policy_configuration.xml";
|
||||||
|
|
||||||
// Stringify the argument.
|
// Stringify the argument.
|
||||||
@@ -152,8 +152,8 @@ class PolicyConfig : private PolicyConfigData, public AudioPolicyConfig {
|
|||||||
PolicyConfig()
|
PolicyConfig()
|
||||||
: AudioPolicyConfig(hwModules, availableOutputDevices, availableInputDevices,
|
: AudioPolicyConfig(hwModules, availableOutputDevices, availableInputDevices,
|
||||||
defaultOutputDevice) {
|
defaultOutputDevice) {
|
||||||
for (const char* location : kConfigLocations) {
|
for (const auto& location : android::audio_get_configuration_paths()) {
|
||||||
std::string path = std::string(location) + '/' + kConfigFileName;
|
std::string path = location + '/' + kConfigFileName;
|
||||||
if (access(path.c_str(), F_OK) == 0) {
|
if (access(path.c_str(), F_OK) == 0) {
|
||||||
mFilePath = path;
|
mFilePath = path;
|
||||||
break;
|
break;
|
||||||
@@ -186,7 +186,7 @@ class PolicyConfig : private PolicyConfigData, public AudioPolicyConfig {
|
|||||||
std::string getError() const {
|
std::string getError() const {
|
||||||
if (mFilePath.empty()) {
|
if (mFilePath.empty()) {
|
||||||
return std::string{"Could not find "} + kConfigFileName +
|
return std::string{"Could not find "} + kConfigFileName +
|
||||||
" file in: " + testing::PrintToString(kConfigLocations);
|
" file in: " + testing::PrintToString(android::audio_get_configuration_paths());
|
||||||
} else {
|
} else {
|
||||||
return "Invalid config file: " + mFilePath;
|
return "Invalid config file: " + mFilePath;
|
||||||
}
|
}
|
||||||
@@ -302,7 +302,8 @@ TEST(CheckConfig, audioPolicyConfigurationValidation) {
|
|||||||
"is valid according to the schema");
|
"is valid according to the schema");
|
||||||
|
|
||||||
const char* xsd = "/data/local/tmp/audio_policy_configuration_" STRINGIFY(CPP_VERSION) ".xsd";
|
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 {
|
class AudioPolicyConfigTest : public AudioHidlTestWithDeviceParameter {
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
#include <iterator>
|
#include <iterator>
|
||||||
|
|
||||||
#include <media/EffectsConfig.h>
|
#include <media/EffectsConfig.h>
|
||||||
|
#include <system/audio_config.h>
|
||||||
// clang-format off
|
// clang-format off
|
||||||
#include PATH(android/hardware/audio/effect/FILE_VERSION/IEffectsFactory.h)
|
#include PATH(android/hardware/audio/effect/FILE_VERSION/IEffectsFactory.h)
|
||||||
// clang-format on
|
// clang-format on
|
||||||
@@ -41,13 +42,14 @@ TEST(CheckConfig, audioEffectsConfigurationValidation) {
|
|||||||
GTEST_SKIP() << "No Effects HAL version " STRINGIFY(CPP_VERSION) " on this device";
|
GTEST_SKIP() << "No Effects HAL version " STRINGIFY(CPP_VERSION) " on this device";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<const char*> locations(std::begin(DEFAULT_LOCATIONS), std::end(DEFAULT_LOCATIONS));
|
|
||||||
const char* xsd = "/data/local/tmp/audio_effects_conf_" STRINGIFY(CPP_VERSION) ".xsd";
|
const char* xsd = "/data/local/tmp/audio_effects_conf_" STRINGIFY(CPP_VERSION) ".xsd";
|
||||||
#if MAJOR_VERSION == 2
|
#if MAJOR_VERSION == 2
|
||||||
// In V2, audio effect XML is not required. .conf is still allowed though deprecated
|
// 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
|
#elif MAJOR_VERSION >= 4
|
||||||
// Starting with V4, audio effect XML is required
|
// 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
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,8 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include "utility/ValidateXml.h"
|
#include "utility/ValidateXml.h"
|
||||||
|
|
||||||
static const std::vector<const char*> locations = {"/odm/etc", "/vendor/etc", "/system/etc"};
|
#include <system/audio_config.h>
|
||||||
|
|
||||||
static const std::string config = "audio_policy_engine_configuration.xml";
|
static const std::string config = "audio_policy_engine_configuration.xml";
|
||||||
static const std::string schema =
|
static const std::string schema =
|
||||||
std::string(XSD_DIR) + "/audio_policy_engine_configuration_V1_0.xsd";
|
std::string(XSD_DIR) + "/audio_policy_engine_configuration_V1_0.xsd";
|
||||||
@@ -42,7 +43,8 @@ TEST(ValidateConfiguration, audioPolicyEngineConfiguration) {
|
|||||||
RecordProperty("description",
|
RecordProperty("description",
|
||||||
"Verify that the audio policy engine configuration file "
|
"Verify that the audio policy engine configuration file "
|
||||||
"is valid according to the schemas");
|
"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() {
|
static bool deviceUsesConfigurableEngine() {
|
||||||
return android::hardware::audio::common::test::utility::validateXmlMultipleLocations<true>(
|
return android::hardware::audio::common::test::utility::validateXmlMultipleLocations<true>(
|
||||||
"", "", "", 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<true>(
|
android::hardware::audio::common::test::utility::validateXmlMultipleLocations<true>(
|
||||||
"", "", "", configurableConfig.c_str(), locations, configurableSchemas.c_str());
|
"", "", "", configurableConfig.c_str(), android::audio_get_configuration_paths(),
|
||||||
|
configurableSchemas.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(ValidateConfiguration, audioPolicyEngineConfigurable) {
|
TEST(ValidateConfiguration, audioPolicyEngineConfigurable) {
|
||||||
|
|||||||
Reference in New Issue
Block a user