Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 04790204 authored by Mikhail Naganov's avatar Mikhail Naganov
Browse files

audio: Run VTS tests for non-primary modules for HAL V6

Implement parsing of AudioPolicyManager config for finding
out declared modules (IDevice instances) with permanently
attached devices and run tests for them. This only applies
when running tests for HAL V6.

Change class hierarchy to use IDevice interface as much as
possible, only use IPrimaryDevice for its specific methods.

Fix the following issues found while running the tests
for "r_submix" and "msd" modules:

- IDevice::getMicrophones can return NOT_SUPPORTED status;

- IDevice::get/setParameters can return NOT_SUPPORTED.

Other changes:

- Factor out common code for getting devices via DeviceManager;

- Factor out AudioPolicyConfigTest.HasPrimaryModule test from
  SetUp code;

- Add device parameter generator for primary device only.

Bug: 141989952
Bug: 141847510
Test: atest VtsHalAudioV5_0TargetTest
      atest VtsHalAudioV6_0TargetTest
      also, run modified V5_0 test using generators for V6_0

Change-Id: I51cec21670120d8dce75609954a18b886cc0c18d
parent a494e0e2
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -260,7 +260,8 @@ interface IDevice {
    /**
     * Returns an array with available microphones in device.
     *
     * @return retval INVALID_STATE if the call is not successful,
     * @return retval NOT_SUPPORTED if there are no microphones on this device
     *                INVALID_STATE if the call is not successful,
     *                OK otherwise.
     *
     * @return microphones array with microphones info
+10 −6
Original line number Diff line number Diff line
@@ -18,15 +18,16 @@

TEST_P(AudioHidlTest, OpenPrimaryDeviceUsingGetDevice) {
    doc::test("Calling openDevice(\"primary\") should return the primary device.");
    if (getDeviceName() != DeviceManager::kPrimaryDevice) {
        GTEST_SKIP() << "No primary device on this factory";  // returns
    }

    struct WaitExecutor {
        ~WaitExecutor() { DeviceManager::waitForInstanceDestruction(); }
    } waitExecutor;  // Make sure we wait for the device destruction on exiting from the test.
    Result result;
    sp<IDevice> baseDevice;
    ASSERT_OK(getDevicesFactory()->openDevice("primary", returnIn(result, baseDevice)));
    if (result != Result::OK && isPrimaryDeviceOptional()) {
        GTEST_SKIP() << "No primary device on this factory";  // returns
    }
    ASSERT_OK(result);
    ASSERT_TRUE(baseDevice != nullptr);

@@ -39,10 +40,13 @@ TEST_P(AudioHidlTest, OpenPrimaryDeviceUsingGetDevice) {
/////////////////////////// get(Active)Microphones ///////////////////////////
//////////////////////////////////////////////////////////////////////////////

TEST_P(AudioPrimaryHidlTest, GetMicrophonesTest) {
TEST_P(AudioHidlDeviceTest, GetMicrophonesTest) {
    doc::test("Make sure getMicrophones always succeeds");
    hidl_vec<MicrophoneInfo> microphones;
    ASSERT_OK(getDevice()->getMicrophones(returnIn(res, microphones)));
    if (res == Result::NOT_SUPPORTED) {
        GTEST_SKIP() << "getMicrophones is not supported";  // returns
    }
    ASSERT_OK(res);
    if (microphones.size() > 0) {
        // When there is microphone on the phone, try to open an input stream
@@ -120,7 +124,7 @@ TEST_P(AudioPrimaryHidlTest, GetMicrophonesTest) {
    }
}

TEST_P(AudioPrimaryHidlTest, SetConnectedState) {
TEST_P(AudioHidlDeviceTest, SetConnectedState) {
    doc::test("Check that the HAL can be notified of device connection and deconnection");
    using AD = AudioDevice;
    for (auto deviceType : {AD::OUT_HDMI, AD::OUT_WIRED_HEADPHONE, AD::IN_USB_HEADSET}) {
@@ -142,7 +146,7 @@ TEST_P(AudioPrimaryHidlTest, SetConnectedState) {
    // Because there is no way of knowing if the devices were connected before
    // calling setConnectedState, there is no way to restore the HAL to its
    // initial state. To workaround this, destroy the HAL at the end of this test.
    ASSERT_TRUE(DeviceManager::getInstance().resetPrimary(getFactoryName()));
    ASSERT_TRUE(resetDevice());
}

static void testGetDevices(IStream* stream, AudioDevice expectedDevice) {
+48 −0
Original line number Diff line number Diff line
@@ -16,3 +16,51 @@

// pull in all the <= 5.0 tests
#include "5.0/AudioPrimaryHidlHalTest.cpp"

const std::vector<DeviceParameter>& getDeviceParametersForFactoryTests() {
    static std::vector<DeviceParameter> parameters = [] {
        std::vector<DeviceParameter> result;
        const auto factories =
                ::android::hardware::getAllHalInstanceNames(IDevicesFactory::descriptor);
        for (const auto& factoryName : factories) {
            result.emplace_back(factoryName,
                                DeviceManager::getInstance().getPrimary(factoryName) != nullptr
                                        ? DeviceManager::kPrimaryDevice
                                        : "");
        }
        return result;
    }();
    return parameters;
}

const std::vector<DeviceParameter>& getDeviceParametersForPrimaryDeviceTests() {
    static std::vector<DeviceParameter> parameters = [] {
        std::vector<DeviceParameter> result;
        const auto primary = std::find_if(
                getDeviceParameters().begin(), getDeviceParameters().end(), [](const auto& elem) {
                    return std::get<PARAM_DEVICE_NAME>(elem) == DeviceManager::kPrimaryDevice;
                });
        if (primary != getDeviceParameters().end()) result.push_back(*primary);
        return result;
    }();
    return parameters;
}

const std::vector<DeviceParameter>& getDeviceParameters() {
    static std::vector<DeviceParameter> parameters = [] {
        std::vector<DeviceParameter> result;
        const auto factories =
                ::android::hardware::getAllHalInstanceNames(IDevicesFactory::descriptor);
        const auto devices = getCachedPolicyConfig().getModulesWithDevicesNames();
        result.reserve(devices.size());
        for (const auto& factoryName : factories) {
            for (const auto& deviceName : devices) {
                if (DeviceManager::getInstance().get(factoryName, deviceName) != nullptr) {
                    result.emplace_back(factoryName, deviceName);
                }
            }
        }
        return result;
    }();
    return parameters;
}
+193 −146

File changed.

Preview size limit exceeded, changes collapsed.