audio: Require exact implementation version match

Align the behavior of minor version mismatch with the behavior
of major version mismatch. For example, trying to run VTS test
intended for V7.0 on a device with V7.1 yields no results,
similar to what happens when running a V6.0 test on V7.0 device.
This is done to avoid test failures when the device uses
features added by V7.1 in the APM XML config.

Bug: 227150535
Test: atest VtsHalAudioV7_0TargetTest
Test: atest VtsHalAudioV7_1TargetTest
Change-Id: I8ad6595a221f0bc9aedea057f27a75c172954da5
This commit is contained in:
Mikhail Naganov
2022-04-11 23:57:04 +00:00
parent 210c44dbe1
commit 7c92256c1a

View File

@@ -34,6 +34,7 @@
#include <hwbinder/IPCThreadState.h>
#include <android-base/expected.h>
#include <android-base/logging.h>
#include <system/audio_config.h>
@@ -130,6 +131,33 @@ class HidlTest : public ::testing::Test {
using IDevice = ::android::hardware::audio::CPP_VERSION::IDevice;
using IDevicesFactory = ::android::hardware::audio::CPP_VERSION::IDevicesFactory;
static android::base::expected<std::vector<std::string>, std::string> getAllFactoryInstances() {
using ::android::hardware::audio::CPP_VERSION::IDevicesFactory;
const std::string factoryDescriptor = IDevicesFactory::descriptor;
// Make sure that the instance is the exact minor version.
// Using a 7.1 factory for 7.0 test is not always possible because
// 7.1 can be configured via the XML config to use features that are
// absent in 7.0.
auto instances = ::android::hardware::getAllHalInstanceNames(factoryDescriptor);
if (instances.empty()) return instances;
// Use the default instance for checking the implementation version.
auto defaultInstance = IDevicesFactory::getService("default");
if (defaultInstance == nullptr) {
return ::android::base::unexpected("Failed to obtain IDevicesFactory/default");
}
std::string actualDescriptor;
auto intDescRet = defaultInstance->interfaceDescriptor(
[&](const auto& descriptor) { actualDescriptor = descriptor; });
if (!intDescRet.isOk()) {
return ::android::base::unexpected("Failed to obtain interface descriptor: " +
intDescRet.description());
}
if (factoryDescriptor == actualDescriptor)
return instances;
else
return {};
}
virtual ~HidlTest() = default;
// public access to avoid annoyances when using this method in template classes
// derived from test classes
@@ -174,9 +202,11 @@ const PolicyConfig& getCachedPolicyConfig() {
}
TEST(CheckConfig, audioPolicyConfigurationValidation) {
const auto factories = ::android::hardware::getAllHalInstanceNames(
::android::hardware::audio::CPP_VERSION::IDevicesFactory::descriptor);
if (factories.size() == 0) {
const auto factories = HidlTest::getAllFactoryInstances();
if (!factories.ok()) {
FAIL() << factories.error();
}
if (factories.value().size() == 0) {
GTEST_SKIP() << "Skipping audioPolicyConfigurationValidation because no factory instances "
"are found.";
}
@@ -205,11 +235,11 @@ static inline std::string DeviceParameterToString(
const std::vector<DeviceParameter>& getDeviceParameters() {
static std::vector<DeviceParameter> parameters = [] {
std::vector<DeviceParameter> result;
const auto factories = ::android::hardware::getAllHalInstanceNames(
::android::hardware::audio::CPP_VERSION::IDevicesFactory::descriptor);
const auto factories = HidlTest::getAllFactoryInstances();
if (!factories.ok()) return result;
const auto devices = getCachedPolicyConfig().getModulesWithDevicesNames();
result.reserve(devices.size());
for (const auto& factoryName : factories) {
for (const auto& factoryName : factories.value()) {
for (const auto& deviceName : devices) {
if (DeviceManager::getInstance().get(factoryName, deviceName) != nullptr) {
result.emplace_back(factoryName, deviceName);
@@ -224,9 +254,9 @@ const std::vector<DeviceParameter>& getDeviceParameters() {
const std::vector<DeviceParameter>& getDeviceParametersForFactoryTests() {
static std::vector<DeviceParameter> parameters = [] {
std::vector<DeviceParameter> result;
const auto factories = ::android::hardware::getAllHalInstanceNames(
::android::hardware::audio::CPP_VERSION::IDevicesFactory::descriptor);
for (const auto& factoryName : factories) {
const auto factories = HidlTest::getAllFactoryInstances();
if (!factories.ok()) return result;
for (const auto& factoryName : factories.value()) {
result.emplace_back(factoryName,
DeviceManager::getInstance().getPrimary(factoryName) != nullptr
? DeviceManager::kPrimaryDevice