From a62c5df181b37bb7a066cbd154cb13a59a596345 Mon Sep 17 00:00:00 2001 From: Mikhail Naganov Date: Wed, 17 Apr 2024 17:10:31 -0700 Subject: [PATCH 1/2] audio: Skip stream I/O test for "echo reference" input device This is aligned with the HIDL implementation VTS. The echo reference device can't provide any input until certain preconditions are met, and modeling these preconditions in the test is not trivial. Also, add the information into the mix port into the trace scope for easier identification on test failure. Bug: 328010709 Test: atest VtsHalAudioCoreTargetTest Change-Id: I737479d8ef1961791ac3bd82aeb779453d2e49f4 --- audio/aidl/vts/ModuleConfig.cpp | 5 +++++ audio/aidl/vts/ModuleConfig.h | 2 ++ audio/aidl/vts/VtsHalAudioCoreModuleTargetTest.cpp | 10 ++++++++++ 3 files changed, 17 insertions(+) diff --git a/audio/aidl/vts/ModuleConfig.cpp b/audio/aidl/vts/ModuleConfig.cpp index 2b86271361..d24c4c843e 100644 --- a/audio/aidl/vts/ModuleConfig.cpp +++ b/audio/aidl/vts/ModuleConfig.cpp @@ -551,6 +551,11 @@ std::vector ModuleConfig::generateAudioDevicePortConfigs( return result; } +std::optional ModuleConfig::getPort(int32_t portId) { + auto portsIt = findById(mPorts, portId); + return portsIt != mPorts.end() ? std::optional(*portsIt) : std::nullopt; +} + ndk::ScopedAStatus ModuleConfig::onExternalDeviceConnected(IModule* module, const AudioPort& port) { RETURN_STATUS_IF_ERROR(module->getAudioPorts(&mPorts)); RETURN_STATUS_IF_ERROR(module->getAudioRoutes(&mRoutes)); diff --git a/audio/aidl/vts/ModuleConfig.h b/audio/aidl/vts/ModuleConfig.h index 4a87f8cbd2..27286e5da7 100644 --- a/audio/aidl/vts/ModuleConfig.h +++ b/audio/aidl/vts/ModuleConfig.h @@ -166,6 +166,8 @@ class ModuleConfig { return *config.begin(); } + std::optional getPort(int32_t portId); + ndk::ScopedAStatus onExternalDeviceConnected( aidl::android::hardware::audio::core::IModule* module, const aidl::android::media::audio::common::AudioPort& port); diff --git a/audio/aidl/vts/VtsHalAudioCoreModuleTargetTest.cpp b/audio/aidl/vts/VtsHalAudioCoreModuleTargetTest.cpp index 039695b360..3e306d666f 100644 --- a/audio/aidl/vts/VtsHalAudioCoreModuleTargetTest.cpp +++ b/audio/aidl/vts/VtsHalAudioCoreModuleTargetTest.cpp @@ -2978,6 +2978,11 @@ static bool skipStreamIoTestForMixPortConfig(const AudioPortConfig& portConfig) AudioOutputFlags::COMPRESS_OFFLOAD, AudioOutputFlags::INCALL_MUSIC})); } +// Certain types of devices can not be used without special preconditions. +static bool skipStreamIoTestForDevice(const AudioDevice& device) { + return device.type.type == AudioDeviceType::IN_ECHO_REFERENCE; +} + template class StreamFixtureWithWorker { public: @@ -3886,6 +3891,9 @@ class AudioStreamIo : public AudioCoreModuleBase, GTEST_SKIP() << "No mix ports have attached devices"; } for (const auto& portConfig : allPortConfigs) { + auto port = moduleConfig->getPort(portConfig.portId); + ASSERT_TRUE(port.has_value()); + SCOPED_TRACE(port->toString()); SCOPED_TRACE(portConfig.toString()); if (skipStreamIoTestForMixPortConfig(portConfig)) continue; const bool isNonBlocking = @@ -3968,6 +3976,7 @@ class AudioStreamIo : public AudioCoreModuleBase, StreamFixture stream; ASSERT_NO_FATAL_FAILURE( stream.SetUpStreamForMixPortConfig(module.get(), moduleConfig.get(), portConfig)); + if (skipStreamIoTestForDevice(stream.getDevice())) return; ASSERT_EQ("", stream.skipTestReason()); StreamLogicDefaultDriver driver(commandsAndStates, stream.getStreamContext()->getFrameSizeBytes()); @@ -3996,6 +4005,7 @@ class AudioStreamIo : public AudioCoreModuleBase, StreamFixture stream; ASSERT_NO_FATAL_FAILURE( stream.SetUpPatchForMixPortConfig(module.get(), moduleConfig.get(), portConfig)); + if (skipStreamIoTestForDevice(stream.getDevice())) return; ASSERT_EQ("", stream.skipTestReason()); ASSERT_NO_FATAL_FAILURE(stream.TeardownPatchSetUpStream(module.get())); StreamLogicDefaultDriver driver(commandsAndStates, From 8dd96d4c417f309824ac006cedc15118fd7a1363 Mon Sep 17 00:00:00 2001 From: Mikhail Naganov Date: Thu, 18 Apr 2024 13:18:09 -0700 Subject: [PATCH 2/2] audio: Fix AudioPatchTest/AudioModulePatch#UpdateInvalidPatchId VTS test The test was using '0' as an "invalid" patch ID value, however this value is valid in the context of 'IModule.setAudioPatch' method and means "create a new patch and allocate and ID for it". Bug: 328010709 Test: atest VtsHalAudioCoreTargetTest Change-Id: Icd33f3cbd1602ec5aa162fa72fc3ddd59ccffbef --- .../vts/VtsHalAudioCoreModuleTargetTest.cpp | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/audio/aidl/vts/VtsHalAudioCoreModuleTargetTest.cpp b/audio/aidl/vts/VtsHalAudioCoreModuleTargetTest.cpp index 3e306d666f..f661245628 100644 --- a/audio/aidl/vts/VtsHalAudioCoreModuleTargetTest.cpp +++ b/audio/aidl/vts/VtsHalAudioCoreModuleTargetTest.cpp @@ -133,13 +133,23 @@ auto findAny(const std::vector& v, const std::set& ids) { } template -std::vector GetNonExistentIds(const C& allIds) { +std::vector GetNonExistentIds(const C& allIds, bool includeZero = true) { if (allIds.empty()) { - return std::vector{-1, 0, 1}; + return includeZero ? std::vector{-1, 0, 1} : std::vector{-1, 1}; } std::vector nonExistentIds; - nonExistentIds.push_back(*std::min_element(allIds.begin(), allIds.end()) - 1); - nonExistentIds.push_back(*std::max_element(allIds.begin(), allIds.end()) + 1); + if (auto value = *std::min_element(allIds.begin(), allIds.end()) - 1; + includeZero || value != 0) { + nonExistentIds.push_back(value); + } else { + nonExistentIds.push_back(value - 1); + } + if (auto value = *std::max_element(allIds.begin(), allIds.end()) + 1; + includeZero || value != 0) { + nonExistentIds.push_back(value); + } else { + nonExistentIds.push_back(value + 1); + } return nonExistentIds; } @@ -4204,7 +4214,7 @@ class AudioModulePatch : public AudioCoreModule { // Then use the same patch setting, except for having an invalid ID. std::set patchIds; ASSERT_NO_FATAL_FAILURE(GetAllPatchIds(&patchIds)); - for (const auto patchId : GetNonExistentIds(patchIds)) { + for (const auto patchId : GetNonExistentIds(patchIds, false /*includeZero*/)) { AudioPatch patchWithNonExistendId = patch.get(); patchWithNonExistendId.id = patchId; EXPECT_STATUS(EX_ILLEGAL_ARGUMENT,