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

Commit 606caa65 authored by Mikhail Naganov's avatar Mikhail Naganov
Browse files

Fix/skip libaudioclient tests on Automotive

Routing tests were failing because Automotive uses a different
policy for routing which affects the choice of devices. This is
the same problem that happened to some CTS tests. The decision
was to skip these tests on the automotive platform.

Another type of failure was occurring because tests assumed
existence of the SPEAKER device. However, on the automotive
platform the speaker may be implemented as a BUS device.
Change the test to use any output device.

Bug: 379596346
Test: atest audiorecord_tests audiorouting_tests \
            trackplayerbase_tests audiosystem_tests audioeffect_tests
Change-Id: Ied03cc9d689b7fde19f96d0ac723fbc5bf53f50d
parent 86c1d76b
Loading
Loading
Loading
Loading
+49 −16
Original line number Original line Diff line number Diff line
@@ -18,6 +18,8 @@
#define LOG_TAG "AudioTestUtils"
#define LOG_TAG "AudioTestUtils"


#include <android-base/file.h>
#include <android-base/file.h>
#include <android/content/pm/IPackageManagerNative.h>
#include <binder/IServiceManager.h>
#include <system/audio_config.h>
#include <system/audio_config.h>
#include <utils/Log.h>
#include <utils/Log.h>


@@ -641,6 +643,28 @@ uint32_t AudioCapture::waitAndGetReceivedCbMarkerCount() const {
    return mReceivedCbMarkerCount.value_or(0);
    return mReceivedCbMarkerCount.value_or(0);
}
}


status_t isAutomotivePlatform(bool* isAutomotive) {
    const sp<IServiceManager> sm = defaultServiceManager();
    if (sm == nullptr) {
        ALOGE("%s: failed to retrieve defaultServiceManager", __func__);
        return NO_INIT;
    }
    sp<IBinder> binder = sm->checkService(String16{"package_native"});
    if (binder == nullptr) {
        ALOGE("%s: failed to retrieve native package manager", __func__);
        return NO_INIT;
    }
    *isAutomotive = false;
    const auto pm = interface_cast<content::pm::IPackageManagerNative>(binder);
    if (pm != nullptr) {
        const auto status =
                pm->hasSystemFeature(String16("android.hardware.type.automotive"), 0, isAutomotive);
        return status.isOk() ? OK : status.transactionError();
    }
    ALOGE("%s: failed to cast to IPackageManagerNative", __func__);
    return NO_INIT;
}

status_t listAudioPorts(std::vector<audio_port_v7>& portsVec) {
status_t listAudioPorts(std::vector<audio_port_v7>& portsVec) {
    int attempts = 5;
    int attempts = 5;
    status_t status;
    status_t status;
@@ -670,34 +694,43 @@ status_t listAudioPorts(std::vector<audio_port_v7>& portsVec) {
    return status;
    return status;
}
}


status_t getPortById(const audio_port_handle_t portId, audio_port_v7& port) {
namespace {

using PortPredicate = std::function<bool(const struct audio_port_v7& port)>;
status_t getPort(PortPredicate pred, audio_port_v7& port) {
    std::vector<struct audio_port_v7> ports;
    std::vector<struct audio_port_v7> ports;
    status_t status = listAudioPorts(ports);
    status_t status = listAudioPorts(ports);
    if (status != OK) return status;
    if (status != OK) return status;
    for (auto i = 0; i < ports.size(); i++) {
    for (const auto& p : ports) {
        if (ports[i].id == portId) {
        if (pred(p)) {
            port = ports[i];
            port = p;
            return OK;
            return OK;
        }
        }
    }
    }
    return BAD_VALUE;
    return BAD_VALUE;
}
}


}  // namespace

status_t getAnyPort(audio_port_role_t role, audio_port_type_t type, audio_port_v7& port) {
    return getPort([&](const struct audio_port_v7& p) { return p.role == role && p.type == type; },
                   port);
}

status_t getPortById(const audio_port_handle_t portId, audio_port_v7& port) {
    return getPort([&](const struct audio_port_v7& p) { return p.id == portId; }, port);
}

status_t getPortByAttributes(audio_port_role_t role, audio_port_type_t type,
status_t getPortByAttributes(audio_port_role_t role, audio_port_type_t type,
                             audio_devices_t deviceType, const std::string& address,
                             audio_devices_t deviceType, const std::string& address,
                             audio_port_v7& port) {
                             audio_port_v7& port) {
    std::vector<struct audio_port_v7> ports;
    return getPort(
    status_t status = listAudioPorts(ports);
            [&](const struct audio_port_v7& p) {
    if (status != OK) return status;
                return p.role == role && p.type == type && p.ext.device.type == deviceType &&
    for (auto i = 0; i < ports.size(); i++) {
                       !strncmp(p.ext.device.address, address.c_str(),
        if (ports[i].role == role && ports[i].type == type &&
                                AUDIO_DEVICE_MAX_ADDRESS_LEN);
            ports[i].ext.device.type == deviceType &&
            },
            !strncmp(ports[i].ext.device.address, address.c_str(), AUDIO_DEVICE_MAX_ADDRESS_LEN)) {
            port);
            port = ports[i];
            return OK;
        }
    }
    return BAD_VALUE;
}
}


status_t listAudioPatches(std::vector<struct audio_patch>& patchesVec) {
status_t listAudioPatches(std::vector<struct audio_patch>& patchesVec) {
+2 −0
Original line number Original line Diff line number Diff line
@@ -45,8 +45,10 @@ struct Route {
    std::string sink;
    std::string sink;
};
};


status_t isAutomotivePlatform(bool* isAutomotive);
status_t listAudioPorts(std::vector<audio_port_v7>& portsVec);
status_t listAudioPorts(std::vector<audio_port_v7>& portsVec);
status_t listAudioPatches(std::vector<struct audio_patch>& patchesVec);
status_t listAudioPatches(std::vector<struct audio_patch>& patchesVec);
status_t getAnyPort(audio_port_role_t role, audio_port_type_t type, audio_port_v7& port);
status_t getPortByAttributes(audio_port_role_t role, audio_port_type_t type,
status_t getPortByAttributes(audio_port_role_t role, audio_port_type_t type,
                             audio_devices_t deviceType, const std::string& address,
                             audio_devices_t deviceType, const std::string& address,
                             audio_port_v7& port);
                             audio_port_v7& port);
+10 −0
Original line number Original line Diff line number Diff line
@@ -98,6 +98,11 @@ public:
};
};


TEST_P(AudioTrackTest, DefaultRoutingTest) {
TEST_P(AudioTrackTest, DefaultRoutingTest) {
    bool isAutomotive;
    ASSERT_EQ(OK, isAutomotivePlatform(&isAutomotive));
    if (isAutomotive) {
        GTEST_SKIP() << "auto uses its own policy for routing";
    }
    audio_port_v7 port;
    audio_port_v7 port;
    if (OK != getPortByAttributes(AUDIO_PORT_ROLE_SOURCE, AUDIO_PORT_TYPE_DEVICE,
    if (OK != getPortByAttributes(AUDIO_PORT_ROLE_SOURCE, AUDIO_PORT_TYPE_DEVICE,
                                  AUDIO_DEVICE_IN_REMOTE_SUBMIX, "0", port)) {
                                  AUDIO_DEVICE_IN_REMOTE_SUBMIX, "0", port)) {
@@ -154,6 +159,11 @@ INSTANTIATE_TEST_SUITE_P(
class AudioRoutingTest : public ::testing::Test {
class AudioRoutingTest : public ::testing::Test {
  public:
  public:
    void SetUp() override {
    void SetUp() override {
        bool isAutomotive;
        ASSERT_EQ(OK, isAutomotivePlatform(&isAutomotive));
        if (isAutomotive) {
            GTEST_SKIP() << "auto uses its own policy for routing";
        }
        audio_port_v7 port;
        audio_port_v7 port;
        if (OK != getPortByAttributes(AUDIO_PORT_ROLE_SOURCE, AUDIO_PORT_TYPE_DEVICE,
        if (OK != getPortByAttributes(AUDIO_PORT_ROLE_SOURCE, AUDIO_PORT_TYPE_DEVICE,
                                      AUDIO_DEVICE_IN_REMOTE_SUBMIX, "0", port)) {
                                      AUDIO_DEVICE_IN_REMOTE_SUBMIX, "0", port)) {
+16 −10
Original line number Original line Diff line number Diff line
@@ -562,12 +562,15 @@ TEST_F(AudioSystemTest, UidDeviceAffinities) {
    AudioDeviceTypeAddrVector inputDevices = {inputDevice};
    AudioDeviceTypeAddrVector inputDevices = {inputDevice};
    EXPECT_EQ(BAD_VALUE, AudioSystem::setUidDeviceAffinities(uid, inputDevices));
    EXPECT_EQ(BAD_VALUE, AudioSystem::setUidDeviceAffinities(uid, inputDevices));


    audio_port_v7 port;
    if (OK == getAnyPort(AUDIO_PORT_ROLE_SINK, AUDIO_PORT_TYPE_DEVICE, port)) {
        // Test valid device for example audio_is_output_device
        // Test valid device for example audio_is_output_device
    AudioDeviceTypeAddr outputDevice(AUDIO_DEVICE_OUT_SPEAKER, "");
        AudioDeviceTypeAddr outputDevice(port.ext.device.type, port.ext.device.address);
        AudioDeviceTypeAddrVector outputDevices = {outputDevice};
        AudioDeviceTypeAddrVector outputDevices = {outputDevice};
        EXPECT_EQ(NO_ERROR, AudioSystem::setUidDeviceAffinities(uid, outputDevices));
        EXPECT_EQ(NO_ERROR, AudioSystem::setUidDeviceAffinities(uid, outputDevices));
        EXPECT_EQ(NO_ERROR, AudioSystem::removeUidDeviceAffinities(uid));
        EXPECT_EQ(NO_ERROR, AudioSystem::removeUidDeviceAffinities(uid));
    }
    }
}


TEST_F(AudioSystemTest, UserIdDeviceAffinities) {
TEST_F(AudioSystemTest, UserIdDeviceAffinities) {
    int userId = 200;
    int userId = 200;
@@ -577,12 +580,15 @@ TEST_F(AudioSystemTest, UserIdDeviceAffinities) {
    AudioDeviceTypeAddrVector inputDevices = {inputDevice};
    AudioDeviceTypeAddrVector inputDevices = {inputDevice};
    EXPECT_EQ(BAD_VALUE, AudioSystem::setUserIdDeviceAffinities(userId, inputDevices));
    EXPECT_EQ(BAD_VALUE, AudioSystem::setUserIdDeviceAffinities(userId, inputDevices));


    // Test valid device for ezample audio_is_output_device
    audio_port_v7 port;
    AudioDeviceTypeAddr outputDevice(AUDIO_DEVICE_OUT_SPEAKER, "");
    if (OK == getAnyPort(AUDIO_PORT_ROLE_SINK, AUDIO_PORT_TYPE_DEVICE, port)) {
        // Test valid device for example audio_is_output_device
        AudioDeviceTypeAddr outputDevice(port.ext.device.type, port.ext.device.address);
        AudioDeviceTypeAddrVector outputDevices = {outputDevice};
        AudioDeviceTypeAddrVector outputDevices = {outputDevice};
        EXPECT_EQ(NO_ERROR, AudioSystem::setUserIdDeviceAffinities(userId, outputDevices));
        EXPECT_EQ(NO_ERROR, AudioSystem::setUserIdDeviceAffinities(userId, outputDevices));
        EXPECT_EQ(NO_ERROR, AudioSystem::removeUserIdDeviceAffinities(userId));
        EXPECT_EQ(NO_ERROR, AudioSystem::removeUserIdDeviceAffinities(userId));
    }
    }
}


namespace {
namespace {