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

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

audio: Implement VTS tests for V7.0

The major change in V7.0 is use of enum values defined
in the Audio Policy Configuration XSD schema. This allows
decoupling types used at the HIDL layer from system/audio.h.
Added a header audio_policy_configuration_V7_0-enums.h
with utility functions analogous to ones from system/audio.h
but defined for the types generated from XSD schema.

Since the code of VTS tests is shared between versions,
ensured that the VTS tests for the previous HAL versions
didn't regress.

Bug: 142480271
Test: atest VtsHalAudioV6_0TargetTest
      atest VtsHalAudioEffectV6_0TargetTest
      atest VtsHalAudioV7_0TargetTest
      atest VtsHalAudioEffectV7_0TargetTest
Change-Id: Ia7c2d49a02783725080c8fed6a25853e91bba487
Merged-In: Ia7c2d49a02783725080c8fed6a25853e91bba487
parent baf57fb1
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -16,9 +16,12 @@ hidl_interface {
cc_library {
    name: "android.hardware.audio.common@7.0-enums",
    vendor_available: true,
    generated_sources: ["audio_policy_configuration_V7_0"],
    generated_headers: ["audio_policy_configuration_V7_0"],
    generated_sources: ["audio_policy_configuration_V7_0"],
    header_libs: ["libxsdc-utils"],
    export_generated_headers: ["audio_policy_configuration_V7_0"],
    export_header_lib_headers: ["libxsdc-utils"],
    export_include_dirs: ["enums/include"],
    shared_libs: [
        "libbase",
        "liblog",
+207 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef AUDIO_POLICY_CONFIGURATION_V7_0_ENUMS_H
#define AUDIO_POLICY_CONFIGURATION_V7_0_ENUMS_H

#include <sys/types.h>

#include <audio_policy_configuration_V7_0.h>

namespace audio::policy::configuration::V7_0 {

static inline size_t getChannelCount(AudioChannelMask mask) {
    switch (mask) {
        case AudioChannelMask::AUDIO_CHANNEL_OUT_MONO:
        case AudioChannelMask::AUDIO_CHANNEL_IN_MONO:
        case AudioChannelMask::AUDIO_CHANNEL_INDEX_MASK_1:
            return 1;
        case AudioChannelMask::AUDIO_CHANNEL_OUT_STEREO:
        case AudioChannelMask::AUDIO_CHANNEL_OUT_MONO_HAPTIC_A:
        case AudioChannelMask::AUDIO_CHANNEL_OUT_HAPTIC_AB:
        case AudioChannelMask::AUDIO_CHANNEL_IN_STEREO:
        case AudioChannelMask::AUDIO_CHANNEL_IN_FRONT_BACK:
        case AudioChannelMask::AUDIO_CHANNEL_IN_VOICE_UPLINK_MONO:
        case AudioChannelMask::AUDIO_CHANNEL_IN_VOICE_DNLINK_MONO:
        case AudioChannelMask::AUDIO_CHANNEL_IN_VOICE_CALL_MONO:
        case AudioChannelMask::AUDIO_CHANNEL_INDEX_MASK_2:
            return 2;
        case AudioChannelMask::AUDIO_CHANNEL_OUT_2POINT1:
        case AudioChannelMask::AUDIO_CHANNEL_OUT_STEREO_HAPTIC_A:
        case AudioChannelMask::AUDIO_CHANNEL_OUT_MONO_HAPTIC_AB:
        case AudioChannelMask::AUDIO_CHANNEL_INDEX_MASK_3:
            return 3;
        case AudioChannelMask::AUDIO_CHANNEL_OUT_2POINT0POINT2:
        case AudioChannelMask::AUDIO_CHANNEL_OUT_QUAD:
        case AudioChannelMask::AUDIO_CHANNEL_OUT_QUAD_BACK:
        case AudioChannelMask::AUDIO_CHANNEL_OUT_QUAD_SIDE:
        case AudioChannelMask::AUDIO_CHANNEL_OUT_SURROUND:
        case AudioChannelMask::AUDIO_CHANNEL_OUT_STEREO_HAPTIC_AB:
        case AudioChannelMask::AUDIO_CHANNEL_IN_2POINT0POINT2:
        case AudioChannelMask::AUDIO_CHANNEL_INDEX_MASK_4:
            return 4;
        case AudioChannelMask::AUDIO_CHANNEL_OUT_2POINT1POINT2:
        case AudioChannelMask::AUDIO_CHANNEL_OUT_3POINT0POINT2:
        case AudioChannelMask::AUDIO_CHANNEL_OUT_PENTA:
        case AudioChannelMask::AUDIO_CHANNEL_IN_2POINT1POINT2:
        case AudioChannelMask::AUDIO_CHANNEL_IN_3POINT0POINT2:
        case AudioChannelMask::AUDIO_CHANNEL_INDEX_MASK_5:
            return 5;
        case AudioChannelMask::AUDIO_CHANNEL_OUT_3POINT1POINT2:
        case AudioChannelMask::AUDIO_CHANNEL_OUT_5POINT1:
        case AudioChannelMask::AUDIO_CHANNEL_OUT_5POINT1_BACK:
        case AudioChannelMask::AUDIO_CHANNEL_OUT_5POINT1_SIDE:
        case AudioChannelMask::AUDIO_CHANNEL_IN_6:
        case AudioChannelMask::AUDIO_CHANNEL_IN_3POINT1POINT2:
        case AudioChannelMask::AUDIO_CHANNEL_IN_5POINT1:
        case AudioChannelMask::AUDIO_CHANNEL_INDEX_MASK_6:
            return 6;
        case AudioChannelMask::AUDIO_CHANNEL_OUT_6POINT1:
        case AudioChannelMask::AUDIO_CHANNEL_INDEX_MASK_7:
            return 7;
        case AudioChannelMask::AUDIO_CHANNEL_OUT_5POINT1POINT2:
        case AudioChannelMask::AUDIO_CHANNEL_OUT_7POINT1:
        case AudioChannelMask::AUDIO_CHANNEL_INDEX_MASK_8:
            return 8;
        case AudioChannelMask::AUDIO_CHANNEL_INDEX_MASK_9:
            return 9;
        case AudioChannelMask::AUDIO_CHANNEL_OUT_5POINT1POINT4:
        case AudioChannelMask::AUDIO_CHANNEL_OUT_7POINT1POINT2:
        case AudioChannelMask::AUDIO_CHANNEL_INDEX_MASK_10:
            return 10;
        case AudioChannelMask::AUDIO_CHANNEL_INDEX_MASK_11:
            return 11;
        case AudioChannelMask::AUDIO_CHANNEL_OUT_7POINT1POINT4:
        case AudioChannelMask::AUDIO_CHANNEL_INDEX_MASK_12:
            return 12;
        case AudioChannelMask::AUDIO_CHANNEL_INDEX_MASK_13:
            return 13;
        case AudioChannelMask::AUDIO_CHANNEL_INDEX_MASK_14:
            return 14;
        case AudioChannelMask::AUDIO_CHANNEL_INDEX_MASK_15:
            return 15;
        case AudioChannelMask::AUDIO_CHANNEL_INDEX_MASK_16:
            return 16;
        case AudioChannelMask::AUDIO_CHANNEL_INDEX_MASK_17:
            return 17;
        case AudioChannelMask::AUDIO_CHANNEL_INDEX_MASK_18:
            return 18;
        case AudioChannelMask::AUDIO_CHANNEL_INDEX_MASK_19:
            return 19;
        case AudioChannelMask::AUDIO_CHANNEL_INDEX_MASK_20:
            return 20;
        case AudioChannelMask::AUDIO_CHANNEL_INDEX_MASK_21:
            return 21;
        case AudioChannelMask::AUDIO_CHANNEL_INDEX_MASK_22:
            return 22;
        case AudioChannelMask::AUDIO_CHANNEL_INDEX_MASK_23:
            return 23;
        case AudioChannelMask::AUDIO_CHANNEL_INDEX_MASK_24:
            return 24;
        case AudioChannelMask::UNKNOWN:
            return 0;
            // No default to make sure all cases are covered.
    }
    // This is to avoid undefined behavior if 'mask' isn't a valid enum value.
    return 0;
}

static inline ssize_t getChannelCount(const std::string& mask) {
    return getChannelCount(stringToAudioChannelMask(mask));
}

static inline bool isOutputDevice(AudioDevice device) {
    switch (device) {
        case AudioDevice::UNKNOWN:
        case AudioDevice::AUDIO_DEVICE_NONE:
            return false;
        case AudioDevice::AUDIO_DEVICE_OUT_EARPIECE:
        case AudioDevice::AUDIO_DEVICE_OUT_SPEAKER:
        case AudioDevice::AUDIO_DEVICE_OUT_WIRED_HEADSET:
        case AudioDevice::AUDIO_DEVICE_OUT_WIRED_HEADPHONE:
        case AudioDevice::AUDIO_DEVICE_OUT_BLUETOOTH_SCO:
        case AudioDevice::AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET:
        case AudioDevice::AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT:
        case AudioDevice::AUDIO_DEVICE_OUT_BLUETOOTH_A2DP:
        case AudioDevice::AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES:
        case AudioDevice::AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER:
        case AudioDevice::AUDIO_DEVICE_OUT_AUX_DIGITAL:
        case AudioDevice::AUDIO_DEVICE_OUT_HDMI:
        case AudioDevice::AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET:
        case AudioDevice::AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET:
        case AudioDevice::AUDIO_DEVICE_OUT_USB_ACCESSORY:
        case AudioDevice::AUDIO_DEVICE_OUT_USB_DEVICE:
        case AudioDevice::AUDIO_DEVICE_OUT_REMOTE_SUBMIX:
        case AudioDevice::AUDIO_DEVICE_OUT_TELEPHONY_TX:
        case AudioDevice::AUDIO_DEVICE_OUT_LINE:
        case AudioDevice::AUDIO_DEVICE_OUT_HDMI_ARC:
        case AudioDevice::AUDIO_DEVICE_OUT_SPDIF:
        case AudioDevice::AUDIO_DEVICE_OUT_FM:
        case AudioDevice::AUDIO_DEVICE_OUT_AUX_LINE:
        case AudioDevice::AUDIO_DEVICE_OUT_SPEAKER_SAFE:
        case AudioDevice::AUDIO_DEVICE_OUT_IP:
        case AudioDevice::AUDIO_DEVICE_OUT_BUS:
        case AudioDevice::AUDIO_DEVICE_OUT_PROXY:
        case AudioDevice::AUDIO_DEVICE_OUT_USB_HEADSET:
        case AudioDevice::AUDIO_DEVICE_OUT_HEARING_AID:
        case AudioDevice::AUDIO_DEVICE_OUT_ECHO_CANCELLER:
        case AudioDevice::AUDIO_DEVICE_OUT_DEFAULT:
        case AudioDevice::AUDIO_DEVICE_OUT_STUB:
            return true;
        case AudioDevice::AUDIO_DEVICE_IN_COMMUNICATION:
        case AudioDevice::AUDIO_DEVICE_IN_AMBIENT:
        case AudioDevice::AUDIO_DEVICE_IN_BUILTIN_MIC:
        case AudioDevice::AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET:
        case AudioDevice::AUDIO_DEVICE_IN_WIRED_HEADSET:
        case AudioDevice::AUDIO_DEVICE_IN_AUX_DIGITAL:
        case AudioDevice::AUDIO_DEVICE_IN_HDMI:
        case AudioDevice::AUDIO_DEVICE_IN_VOICE_CALL:
        case AudioDevice::AUDIO_DEVICE_IN_TELEPHONY_RX:
        case AudioDevice::AUDIO_DEVICE_IN_BACK_MIC:
        case AudioDevice::AUDIO_DEVICE_IN_REMOTE_SUBMIX:
        case AudioDevice::AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET:
        case AudioDevice::AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET:
        case AudioDevice::AUDIO_DEVICE_IN_USB_ACCESSORY:
        case AudioDevice::AUDIO_DEVICE_IN_USB_DEVICE:
        case AudioDevice::AUDIO_DEVICE_IN_FM_TUNER:
        case AudioDevice::AUDIO_DEVICE_IN_TV_TUNER:
        case AudioDevice::AUDIO_DEVICE_IN_LINE:
        case AudioDevice::AUDIO_DEVICE_IN_SPDIF:
        case AudioDevice::AUDIO_DEVICE_IN_BLUETOOTH_A2DP:
        case AudioDevice::AUDIO_DEVICE_IN_LOOPBACK:
        case AudioDevice::AUDIO_DEVICE_IN_IP:
        case AudioDevice::AUDIO_DEVICE_IN_BUS:
        case AudioDevice::AUDIO_DEVICE_IN_PROXY:
        case AudioDevice::AUDIO_DEVICE_IN_USB_HEADSET:
        case AudioDevice::AUDIO_DEVICE_IN_BLUETOOTH_BLE:
        case AudioDevice::AUDIO_DEVICE_IN_HDMI_ARC:
        case AudioDevice::AUDIO_DEVICE_IN_ECHO_REFERENCE:
        case AudioDevice::AUDIO_DEVICE_IN_DEFAULT:
        case AudioDevice::AUDIO_DEVICE_IN_STUB:
            return false;
            // No default to make sure all cases are covered.
    }
    // This is to avoid undefined behavior if 'device' isn't a valid enum value.
    return false;
}

static inline bool isOutputDevice(const std::string& device) {
    return isOutputDevice(stringToAudioDevice(device));
}

}  // namespace audio::policy::configuration::V7_0

#endif  // AUDIO_POLICY_CONFIGURATION_V7_0_ENUMS_H
+89 −11
Original line number Diff line number Diff line
@@ -16,6 +16,13 @@

#include "AudioPrimaryHidlHalTest.h"

#if MAJOR_VERSION >= 7
#include <audio_policy_configuration_V7_0.h>
#include <xsdc/XsdcSupport.h>

using android::xsdc_enum_range;
#endif

TEST_P(AudioHidlTest, OpenPrimaryDeviceUsingGetDevice) {
    doc::test("Calling openDevice(\"primary\") should return the primary device.");
    if (getDeviceName() != DeviceManager::kPrimaryDevice) {
@@ -53,14 +60,29 @@ TEST_P(AudioHidlDeviceTest, GetMicrophonesTest) {
            "Make sure getMicrophones always succeeds"
            "and getActiveMicrophones always succeeds when recording from these microphones.");
        AudioConfig config{};
#if MAJOR_VERSION <= 6
        config.channelMask = mkEnumBitfield(AudioChannelMask::IN_MONO);
        config.sampleRateHz = 8000;
        config.format = AudioFormat::PCM_16_BIT;
        auto flags = hidl_bitfield<AudioInputFlag>(AudioInputFlag::NONE);
        const SinkMetadata initMetadata = {{{.source = AudioSource::MIC, .gain = 1}}};
#elif MAJOR_VERSION >= 7
        config.base.channelMask.resize(1);
        config.base.channelMask[0] = toString(xsd::AudioChannelMask::AUDIO_CHANNEL_IN_MONO);
        config.base.sampleRateHz = 8000;
        config.base.format = toString(xsd::AudioFormat::AUDIO_FORMAT_PCM_16_BIT);
        hidl_vec<hidl_string> flags;
        const SinkMetadata initMetadata = {
                {{.source = toString(xsd::AudioSource::AUDIO_SOURCE_MIC), .gain = 1}}};
#endif
        EventFlag* efGroup;
        for (auto microphone : microphones) {
#if MAJOR_VERSION <= 6
            if (microphone.deviceAddress.device != AudioDevice::IN_BUILTIN_MIC) {
#elif MAJOR_VERSION >= 7
            if (xsd::stringToAudioDevice(microphone.deviceAddress.deviceType) !=
                xsd::AudioDevice::AUDIO_DEVICE_IN_BUILTIN_MIC) {
#endif
                continue;
            }
            sp<IStreamIn> stream;
@@ -81,7 +103,7 @@ TEST_P(AudioHidlDeviceTest, GetMicrophonesTest) {
            size_t frameSize = stream->getFrameSize();
            size_t frameCount = stream->getBufferSize() / frameSize;
            ASSERT_OK(stream->prepareForReading(
                frameSize, frameCount, [&](auto r, auto& c, auto& d, auto&, auto&) {
                    frameSize, frameCount, [&](auto r, auto& c, auto& d, auto&, auto) {
                        readRes = r;
                        if (readRes == Result::OK) {
                            commandMQ.reset(new CommandMQ(c));
@@ -116,13 +138,24 @@ TEST_P(AudioHidlDeviceTest, GetMicrophonesTest) {

TEST_P(AudioHidlDeviceTest, SetConnectedState) {
    doc::test("Check that the HAL can be notified of device connection and deconnection");
#if MAJOR_VERSION <= 6
    using AD = AudioDevice;
    for (auto deviceType : {AD::OUT_HDMI, AD::OUT_WIRED_HEADPHONE, AD::IN_USB_HEADSET}) {
#elif MAJOR_VERSION >= 7
    using AD = xsd::AudioDevice;
    for (auto deviceType :
         {toString(AD::AUDIO_DEVICE_OUT_HDMI), toString(AD::AUDIO_DEVICE_OUT_WIRED_HEADPHONE),
          toString(AD::AUDIO_DEVICE_IN_USB_HEADSET)}) {
#endif
        SCOPED_TRACE("device=" + ::testing::PrintToString(deviceType));
        for (bool state : {true, false}) {
            SCOPED_TRACE("state=" + ::testing::PrintToString(state));
            DeviceAddress address = {};
#if MAJOR_VERSION <= 6
            address.device = deviceType;
#elif MAJOR_VERSION >= 7
            address.deviceType = deviceType;
#endif
            auto ret = getDevice()->setConnectedState(address, state);
            ASSERT_TRUE(ret.isOk());
            if (ret == Result::NOT_SUPPORTED) {
@@ -148,7 +181,11 @@ static void testGetDevices(IStream* stream, AudioDevice expectedDevice) {
    }
    // The stream was constructed with one device, thus getDevices must only return one
    ASSERT_EQ(1U, devices.size());
#if MAJOR_VERSION <= 6
    AudioDevice device = devices[0].device;
#elif MAJOR_VERSION >= 7
    auto device = devices[0].deviceType;
#endif
    ASSERT_TRUE(device == expectedDevice)
        << "Expected: " << ::testing::PrintToString(expectedDevice)
        << "\n  Actual: " << ::testing::PrintToString(device);
@@ -156,12 +193,22 @@ static void testGetDevices(IStream* stream, AudioDevice expectedDevice) {

TEST_IO_STREAM(GetDevices, "Check that the stream device == the one it was opened with",
               areAudioPatchesSupported() ? doc::partialTest("Audio patches are supported")
#if MAJOR_VERSION <= 6
                                          : testGetDevices(stream.get(), address.device))
#elif MAJOR_VERSION >= 7
                                          : testGetDevices(stream.get(), address.deviceType))
#endif

static void testSetDevices(IStream* stream, const DeviceAddress& address) {
    DeviceAddress otherAddress = address;
#if MAJOR_VERSION <= 6
    otherAddress.device = (address.device & AudioDevice::BIT_IN) == 0 ? AudioDevice::OUT_SPEAKER
                                                                      : AudioDevice::IN_BUILTIN_MIC;
#elif MAJOR_VERSION >= 7
    otherAddress.deviceType = xsd::isOutputDevice(address.deviceType)
                                      ? toString(xsd::AudioDevice::AUDIO_DEVICE_OUT_SPEAKER)
                                      : toString(xsd::AudioDevice::AUDIO_DEVICE_IN_BUILTIN_MIC);
#endif
    EXPECT_RESULT(okOrNotSupported, stream->setDevices({otherAddress}));

    ASSERT_RESULT(okOrNotSupported,
@@ -186,11 +233,19 @@ TEST_IO_STREAM(GetHwAvSync, "Get hardware sync can not fail", checkGetHwAVSync(g
TEST_P(InputStreamTest, updateSinkMetadata) {
    doc::test("The HAL should not crash on metadata change");

#if MAJOR_VERSION <= 6
    hidl_enum_range<AudioSource> range;
#elif MAJOR_VERSION >= 7
    xsdc_enum_range<audio::policy::configuration::V7_0::AudioSource> range;
#endif
    // Test all possible track configuration
    for (AudioSource source : range) {
    for (auto source : range) {
        for (float volume : {0.0, 0.5, 1.0}) {
#if MAJOR_VERSION <= 6
            const SinkMetadata metadata = {{{.source = source, .gain = volume}}};
#elif MAJOR_VERSION >= 7
            const SinkMetadata metadata = {{{.source = toString(source), .gain = volume}}};
#endif
            ASSERT_OK(stream->updateSinkMetadata(metadata))
                << "source=" << toString(source) << ", volume=" << volume;
        }
@@ -213,13 +268,22 @@ TEST_P(OutputStreamTest, SelectPresentation) {
TEST_P(OutputStreamTest, updateSourceMetadata) {
    doc::test("The HAL should not crash on metadata change");

#if MAJOR_VERSION <= 6
    hidl_enum_range<AudioUsage> usageRange;
    hidl_enum_range<AudioContentType> contentRange;
#elif MAJOR_VERSION >= 7
    xsdc_enum_range<audio::policy::configuration::V7_0::AudioUsage> usageRange;
    xsdc_enum_range<audio::policy::configuration::V7_0::AudioContentType> contentRange;
#endif
    // Test all possible track configuration
    for (auto usage : usageRange) {
        for (auto content : contentRange) {
            for (float volume : {0.0, 0.5, 1.0}) {
#if MAJOR_VERSION <= 6
                const SourceMetadata metadata = {{{usage, content, volume}}};
#elif MAJOR_VERSION >= 7
                const SourceMetadata metadata = {{{toString(usage), toString(content), volume}}};
#endif
                ASSERT_OK(stream->updateSourceMetadata(metadata))
                    << "usage=" << toString(usage) << ", content=" << toString(content)
                    << ", volume=" << volume;
@@ -227,12 +291,26 @@ TEST_P(OutputStreamTest, updateSourceMetadata) {
        }
    }

    // clang-format off
    // Set many track of different configuration
    ASSERT_OK(stream->updateSourceMetadata(
#if MAJOR_VERSION <= 6
        {{{AudioUsage::MEDIA, AudioContentType::MUSIC, 0.1},
          {AudioUsage::VOICE_COMMUNICATION, AudioContentType::SPEECH, 1.0},
          {AudioUsage::ALARM, AudioContentType::SONIFICATION, 0.0},
          {AudioUsage::ASSISTANT, AudioContentType::UNKNOWN, 0.3}}}));
          {AudioUsage::ASSISTANT, AudioContentType::UNKNOWN, 0.3}}}
#elif MAJOR_VERSION >= 7
        {{{toString(xsd::AudioUsage::AUDIO_USAGE_MEDIA),
                      toString(xsd::AudioContentType::AUDIO_CONTENT_TYPE_MUSIC), 0.1},
          {toString(xsd::AudioUsage::AUDIO_USAGE_VOICE_COMMUNICATION),
                      toString(xsd::AudioContentType::AUDIO_CONTENT_TYPE_SPEECH), 1.0},
          {toString(xsd::AudioUsage::AUDIO_USAGE_ALARM),
                      toString(xsd::AudioContentType::AUDIO_CONTENT_TYPE_SONIFICATION), 0.0},
          {toString(xsd::AudioUsage::AUDIO_USAGE_ASSISTANT),
                      toString(xsd::AudioContentType::AUDIO_CONTENT_TYPE_UNKNOWN), 0.3}}}
#endif
    ));
    // clang-format on

    // Set no metadata as if all stream track had stopped
    ASSERT_OK(stream->updateSourceMetadata({}));
+3 −1
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ struct Parameters {
    }
};

#if MAJOR_VERSION <= 6
struct GetSupported {
    static auto getFormat(IStream* stream) {
        auto ret = stream->getFormat();
@@ -80,7 +81,7 @@ struct GetSupported {
        EXPECT_OK(stream->getSupportedFormats(returnIn(capabilities)));
        return Result::OK;
    }
#elif MAJOR_VERSION >= 6
#else  // MAJOR_VERSION == 6
    static Result formats(IStream* stream, hidl_vec<AudioFormat>& capabilities) {
        Result res;
        EXPECT_OK(stream->getSupportedFormats(returnIn(res, capabilities)));
@@ -88,6 +89,7 @@ struct GetSupported {
    }
#endif
};
#endif  // MAJOR_VERSION <= 6

template <class T>
auto dump(T t, hidl_handle handle) {
+30 −15
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
// pull in all the <= 5.0 tests
#include "5.0/AudioPrimaryHidlHalTest.cpp"

#if MAJOR_VERSION <= 6
const std::vector<DeviceConfigParameter>& getOutputDeviceConfigParameters() {
    static std::vector<DeviceConfigParameter> parameters = [] {
        std::vector<DeviceConfigParameter> result;
@@ -28,8 +29,8 @@ const std::vector<DeviceConfigParameter>& getOutputDeviceConfigParameters() {
                    const auto& channels = profile->getChannels();
                    const auto& sampleRates = profile->getSampleRates();
                    auto configs = ConfigHelper::combineAudioConfig(
                            vector<audio_channel_mask_t>(channels.begin(), channels.end()),
                            vector<uint32_t>(sampleRates.begin(), sampleRates.end()),
                            std::vector<audio_channel_mask_t>(channels.begin(), channels.end()),
                            std::vector<uint32_t>(sampleRates.begin(), sampleRates.end()),
                            profile->getFormat());
                    auto flags = ioProfile->getFlags();
                    for (auto& config : configs) {
@@ -46,8 +47,8 @@ const std::vector<DeviceConfigParameter>& getOutputDeviceConfigParameters() {
                            config.offloadInfo.bufferSize = 256;  // arbitrary value
                            config.offloadInfo.usage = AudioUsage::MEDIA;
                            result.emplace_back(device, config,
                                                AudioOutputFlag(AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD |
                                                                AUDIO_OUTPUT_FLAG_DIRECT));
                                                AudioOutputFlag(AudioOutputFlag::COMPRESS_OFFLOAD |
                                                                AudioOutputFlag::DIRECT));
                        } else {
                            if (flags & AUDIO_OUTPUT_FLAG_PRIMARY) {  // ignore the flag
                                flags &= ~AUDIO_OUTPUT_FLAG_PRIMARY;
@@ -74,8 +75,8 @@ const std::vector<DeviceConfigParameter>& getInputDeviceConfigParameters() {
                    const auto& channels = profile->getChannels();
                    const auto& sampleRates = profile->getSampleRates();
                    auto configs = ConfigHelper::combineAudioConfig(
                            vector<audio_channel_mask_t>(channels.begin(), channels.end()),
                            vector<uint32_t>(sampleRates.begin(), sampleRates.end()),
                            std::vector<audio_channel_mask_t>(channels.begin(), channels.end()),
                            std::vector<uint32_t>(sampleRates.begin(), sampleRates.end()),
                            profile->getFormat());
                    for (const auto& config : configs) {
                        result.emplace_back(device, config, AudioInputFlag(ioProfile->getFlags()));
@@ -87,13 +88,22 @@ const std::vector<DeviceConfigParameter>& getInputDeviceConfigParameters() {
    }();
    return parameters;
}
#endif  // MAJOR_VERSION <= 6

TEST_P(AudioHidlDeviceTest, CloseDeviceWithOpenedOutputStreams) {
    doc::test("Verify that a device can't be closed if there are streams opened");
#if MAJOR_VERSION <= 6
    DeviceAddress address{.device = AudioDevice::OUT_DEFAULT};
    AudioConfig config{};
    auto flags = hidl_bitfield<AudioOutputFlag>(AudioOutputFlag::NONE);
    SourceMetadata initMetadata = {{{AudioUsage::MEDIA, AudioContentType::MUSIC, 1 /* gain */}}};
    auto flags = hidl_bitfield<AudioOutputFlag>(AudioOutputFlag::NONE);
#elif MAJOR_VERSION >= 7
    DeviceAddress address{.deviceType = toString(xsd::AudioDevice::AUDIO_DEVICE_OUT_DEFAULT)};
    SourceMetadata initMetadata = {
            {{toString(xsd::AudioUsage::AUDIO_USAGE_MEDIA),
              toString(xsd::AudioContentType::AUDIO_CONTENT_TYPE_MUSIC), 1 /* gain */}}};
    hidl_vec<AudioInOutFlag> flags;
#endif
    AudioConfig config{};
    sp<IStreamOut> stream;
    StreamHelper<IStreamOut> helper(stream);
    AudioConfig suggestedConfig{};
@@ -111,14 +121,20 @@ TEST_P(AudioHidlDeviceTest, CloseDeviceWithOpenedOutputStreams) {

TEST_P(AudioHidlDeviceTest, CloseDeviceWithOpenedInputStreams) {
    doc::test("Verify that a device can't be closed if there are streams opened");
    auto module = getCachedPolicyConfig().getModuleFromName(getDeviceName());
    if (module->getInputProfiles().empty()) {
    if (!getCachedPolicyConfig().haveInputProfilesInModule(getDeviceName())) {
        GTEST_SKIP() << "Device doesn't have input profiles";
    }
#if MAJOR_VERSION <= 6
    DeviceAddress address{.device = AudioDevice::IN_DEFAULT};
    AudioConfig config{};
    auto flags = hidl_bitfield<AudioInputFlag>(AudioInputFlag::NONE);
    SinkMetadata initMetadata = {{{.source = AudioSource::MIC, .gain = 1}}};
    auto flags = hidl_bitfield<AudioInputFlag>(AudioInputFlag::NONE);
#elif MAJOR_VERSION >= 7
    DeviceAddress address{.deviceType = toString(xsd::AudioDevice::AUDIO_DEVICE_IN_DEFAULT)};
    SinkMetadata initMetadata = {
            {{.source = toString(xsd::AudioSource::AUDIO_SOURCE_MIC), .gain = 1}}};
    hidl_vec<AudioInOutFlag> flags;
#endif
    AudioConfig config{};
    sp<IStreamIn> stream;
    StreamHelper<IStreamIn> helper(stream);
    AudioConfig suggestedConfig{};
@@ -137,9 +153,8 @@ TEST_P(AudioHidlDeviceTest, CloseDeviceWithOpenedInputStreams) {
TEST_P(AudioPatchHidlTest, UpdatePatchInvalidHandle) {
    doc::test("Verify that passing an invalid handle to updateAudioPatch is checked");
    AudioPatchHandle ignored;
    ASSERT_OK(getDevice()->updateAudioPatch(
            static_cast<int32_t>(AudioHandleConsts::AUDIO_PATCH_HANDLE_NONE),
            hidl_vec<AudioPortConfig>(), hidl_vec<AudioPortConfig>(), returnIn(res, ignored)));
    ASSERT_OK(getDevice()->updateAudioPatch(AudioPatchHandle{}, hidl_vec<AudioPortConfig>(),
                                            hidl_vec<AudioPortConfig>(), returnIn(res, ignored)));
    ASSERT_RESULT(Result::INVALID_ARGUMENTS, res);
}

Loading