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

Commit 6166ef40 authored by Kevin Rocard's avatar Kevin Rocard
Browse files

Audio VTS: Move version specific code to its own file



Move most version specific VTS in their own files.
Keeping the mostly common code in a header.

Bug: 118203066
Test: compile
Change-Id: I458e120c702cc0199104ec13244752d5587686bd
Signed-off-by: default avatarKevin Rocard <krocard@google.com>
parent f5305b36
Loading
Loading
Loading
Loading
+78 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 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.
 */

#include "AudioPrimaryHidlHalTest.h"

static void testGetDevice(IStream* stream, AudioDevice expectedDevice) {
    // Unfortunately the interface does not allow the implementation to return
    // NOT_SUPPORTED
    // Thus allow NONE as signaling that the call is not supported.
    auto ret = stream->getDevice();
    ASSERT_IS_OK(ret);
    AudioDevice device = ret;
    ASSERT_TRUE(device == expectedDevice || device == AudioDevice::NONE)
        << "Expected: " << ::testing::PrintToString(expectedDevice)
        << "\n  Actual: " << ::testing::PrintToString(device);
}

TEST_IO_STREAM(GetDevice, "Check that the stream device == the one it was opened with",
               areAudioPatchesSupported() ? doc::partialTest("Audio patches are supported")
                                          : testGetDevice(stream.get(), address.device))

static void testSetDevice(IStream* stream, const DeviceAddress& address) {
    DeviceAddress otherAddress = address;
    otherAddress.device = (address.device & AudioDevice::BIT_IN) == 0 ? AudioDevice::OUT_SPEAKER
                                                                      : AudioDevice::IN_BUILTIN_MIC;
    EXPECT_OK(stream->setDevice(otherAddress));

    ASSERT_OK(stream->setDevice(address));  // Go back to the original value
}

TEST_IO_STREAM(SetDevice, "Check that the stream can be rerouted to SPEAKER or BUILTIN_MIC",
               areAudioPatchesSupported() ? doc::partialTest("Audio patches are supported")
                                          : testSetDevice(stream.get(), address))

static void testConnectedState(IStream* stream) {
    DeviceAddress address = {};
    using AD = AudioDevice;
    for (auto device : {AD::OUT_HDMI, AD::OUT_WIRED_HEADPHONE, AD::IN_USB_HEADSET}) {
        address.device = device;

        ASSERT_OK(stream->setConnectedState(address, true));
        ASSERT_OK(stream->setConnectedState(address, false));
    }
}
TEST_IO_STREAM(SetConnectedState,
               "Check that the stream can be notified of device connection and "
               "deconnection",
               testConnectedState(stream.get()))

TEST_IO_STREAM(GetHwAvSync, "Get hardware sync can not fail", ASSERT_IS_OK(device->getHwAvSync()));

TEST_F(AudioPrimaryHidlTest, setMode) {
    doc::test("Make sure setMode always succeeds if mode is valid and fails otherwise");
    // Test Invalid values
    for (AudioMode mode : {AudioMode::INVALID, AudioMode::CURRENT, AudioMode::CNT}) {
        SCOPED_TRACE("mode=" + toString(mode));
        ASSERT_RESULT(Result::INVALID_ARGUMENTS, device->setMode(mode));
    }
    // Test valid values
    for (AudioMode mode : {AudioMode::IN_CALL, AudioMode::IN_COMMUNICATION, AudioMode::RINGTONE,
                           AudioMode::NORMAL /* Make sure to leave the test in normal mode */}) {
        SCOPED_TRACE("mode=" + toString(mode));
        ASSERT_OK(device->setMode(mode));
    }
}
+74 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 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.
 */

#include <android/hardware/audio/2.0/IStream.h>
#include <android/hardware/audio/2.0/types.h>
#include <android/hardware/audio/common/2.0/types.h>
#include <hidl/HidlSupport.h>

using ::android::hardware::hidl_handle;
using ::android::hardware::hidl_string;
using ::android::hardware::hidl_vec;
using ::android::hardware::audio::common::V2_0::AudioChannelMask;
using ::android::hardware::audio::common::V2_0::AudioFormat;
using ::android::hardware::audio::V2_0::IStream;
using ::android::hardware::audio::V2_0::ParameterValue;
using ::android::hardware::audio::V2_0::Result;

using namespace ::android::hardware::audio::common::test::utility;

struct Parameters {
    template <class T, class ReturnIn>
    static auto get(T t, hidl_vec<hidl_string> keys, ReturnIn returnIn) {
        return t->getParameters(keys, returnIn);
    }
    template <class T>
    static auto set(T t, hidl_vec<ParameterValue> values) {
        return t->setParameters(values);
    }
};

// The default hal should probably return a NOT_SUPPORTED if the hal
// does not expose
// capability retrieval. For now it returns an empty list if not
// implemented
struct GetSupported {
    template <class Vec>
    static Result convertToResult(const Vec& vec) {
        return vec.size() == 0 ? Result::NOT_SUPPORTED : Result::OK;
    }

    static Result sampleRates(IStream* stream, hidl_vec<uint32_t>& rates) {
        EXPECT_OK(stream->getSupportedSampleRates(returnIn(rates)));
        return convertToResult(rates);
    }

    static Result channelMasks(IStream* stream, hidl_vec<AudioChannelMask>& channels) {
        EXPECT_OK(stream->getSupportedChannelMasks(returnIn(channels)));
        return convertToResult(channels);
    }

    static Result formats(IStream* stream, hidl_vec<AudioFormat>& capabilities) {
        EXPECT_OK(stream->getSupportedFormats(returnIn(capabilities)));
        // TODO: this should be an optional function
        return Result::OK;
    }
};

template <class T>
auto dump(T t, hidl_handle handle) {
    return t->debugDump(handle);
}
+1 −1
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@ cc_test {
    name: "VtsHalAudioV2_0TargetTest",
    defaults: ["VtsHalTargetTestDefaults"],
    srcs: [
        "AudioPrimaryHidlHalTest.cpp",
        "2.0/AudioPrimaryHidlHalTest.cpp",
        "ValidateAudioConfiguration.cpp"
    ],
    static_libs: [
+3 −104
Original line number Diff line number Diff line
@@ -52,6 +52,9 @@
#include "utility/PrettyPrintAudioTypes.h"
#include "utility/ReturnIn.h"

/** Provide version specific functions that are used in the generic tests */
#include "2.0/AudioPrimaryHidlHalUtils.h"

using std::initializer_list;
using std::list;
using std::string;
@@ -477,17 +480,6 @@ TEST_F(AudioPrimaryHidlTest, setScreenState) {
//////////////////////////// {get,set}Parameters /////////////////////////////
//////////////////////////////////////////////////////////////////////////////

struct Parameters {
    template <class T, class ReturnIn>
    static auto get(T t, hidl_vec<hidl_string> keys, ReturnIn returnIn) {
        return t->getParameters(keys, returnIn);
    }
    template <class T>
    static auto set(T t, hidl_vec<ParameterValue> values) {
        return t->setParameters(values);
    }
};

TEST_F(AudioPrimaryHidlTest, getParameters) {
    doc::test("Check that the hal can set and get parameters");
    hidl_vec<ParameterValue> context;
@@ -537,11 +529,6 @@ static void testDebugDump(DebugDump debugDump) {
    EXPECT_EQ(0, close(fds[1])) << errno;
}

template <class T>
auto dump(T t, hidl_handle handle) {
    return t->debugDump(handle);
}

TEST_F(AudioPrimaryHidlTest, DebugDump) {
    doc::test("Check that the hal can dump its state without error");
    testDebugDump([](const auto& handle) { return dump(device, handle); });
@@ -770,33 +757,6 @@ static void testCapabilityGetter(const string& name, IStream* stream,
    }
}

// The default hal should probably return a NOT_SUPPORTED if the hal
// does not expose
// capability retrieval. For now it returns an empty list if not
// implemented
struct GetSupported {
    template <class Vec>
    static Result convertToResult(const Vec& vec) {
        return vec.size() == 0 ? Result::NOT_SUPPORTED : Result::OK;
    }

    static Result sampleRates(IStream* stream, hidl_vec<uint32_t>& rates) {
        EXPECT_OK(stream->getSupportedSampleRates(returnIn(rates)));
        return convertToResult(rates);
    }

    static Result channelMasks(IStream* stream, hidl_vec<AudioChannelMask>& channels) {
        EXPECT_OK(stream->getSupportedChannelMasks(returnIn(channels)));
        return convertToResult(channels);
    }

    static Result formats(IStream* stream, hidl_vec<AudioFormat>& capabilities) {
        EXPECT_OK(stream->getSupportedFormats(returnIn(capabilities)));
        // TODO: this should be an optional function
        return Result::OK;
    }
};

TEST_IO_STREAM(SupportedSampleRate, "Check that the stream sample rate is declared as supported",
               testCapabilityGetter("getSupportedSampleRate", stream.get(),
                                    &GetSupported::sampleRates, &IStream::getSampleRate,
@@ -815,35 +775,6 @@ TEST_IO_STREAM(SupportedFormat, "Check that the stream format is declared as sup
               testCapabilityGetter("getSupportedFormat", stream.get(), &GetSupported::formats,
                                    &IStream::getFormat, &IStream::setFormat))

static void testGetDevice(IStream* stream, AudioDevice expectedDevice) {
    // Unfortunately the interface does not allow the implementation to return
    // NOT_SUPPORTED
    // Thus allow NONE as signaling that the call is not supported.
    auto ret = stream->getDevice();
    ASSERT_IS_OK(ret);
    AudioDevice device = ret;
    ASSERT_TRUE(device == expectedDevice || device == AudioDevice::NONE)
        << "Expected: " << ::testing::PrintToString(expectedDevice)
        << "\n  Actual: " << ::testing::PrintToString(device);
}

TEST_IO_STREAM(GetDevice, "Check that the stream device == the one it was opened with",
               areAudioPatchesSupported() ? doc::partialTest("Audio patches are supported")
                                          : testGetDevice(stream.get(), address.device))

static void testSetDevice(IStream* stream, const DeviceAddress& address) {
    DeviceAddress otherAddress = address;
    otherAddress.device = (address.device & AudioDevice::BIT_IN) == 0 ? AudioDevice::OUT_SPEAKER
                                                                      : AudioDevice::IN_BUILTIN_MIC;
    EXPECT_OK(stream->setDevice(otherAddress));

    ASSERT_OK(stream->setDevice(address));  // Go back to the original value
}

TEST_IO_STREAM(SetDevice, "Check that the stream can be rerouted to SPEAKER or BUILTIN_MIC",
               areAudioPatchesSupported() ? doc::partialTest("Audio patches are supported")
                                          : testSetDevice(stream.get(), address))

static void testGetAudioProperties(IStream* stream, AudioConfig expectedConfig) {
    uint32_t sampleRateHz;
    auto mask = mkEnumBitfield<AudioChannelMask>({});
@@ -865,23 +796,6 @@ TEST_IO_STREAM(GetAudioProperties,
TEST_IO_STREAM(SetHwAvSync, "Try to set hardware sync to an invalid value",
               ASSERT_RESULT(okOrNotSupportedOrInvalidArgs, stream->setHwAvSync(666)))

static void testConnectedState(IStream* stream) {
    DeviceAddress address = {};
    using AD = AudioDevice;
    for (auto device : {AD::OUT_HDMI, AD::OUT_WIRED_HEADPHONE, AD::IN_USB_HEADSET}) {
        address.device = device;

        ASSERT_OK(stream->setConnectedState(address, true));
        ASSERT_OK(stream->setConnectedState(address, false));
    }
}
TEST_IO_STREAM(SetConnectedState,
               "Check that the stream can be notified of device connection and "
               "deconnection",
               testConnectedState(stream.get()))

TEST_IO_STREAM(GetHwAvSync, "Get hardware sync can not fail", ASSERT_IS_OK(device->getHwAvSync()));

static void checkGetNoParameter(IStream* stream, hidl_vec<hidl_string> keys,
                                initializer_list<Result> expectedResults) {
    hidl_vec<ParameterValue> parameters;
@@ -1298,21 +1212,6 @@ TEST_F(AudioPrimaryHidlTest, setVoiceVolume) {
    testUnitaryGain([](float volume) { return device->setVoiceVolume(volume); });
}

TEST_F(AudioPrimaryHidlTest, setMode) {
    doc::test("Make sure setMode always succeeds if mode is valid and fails otherwise");
    // Test Invalid values
    for (AudioMode mode : {AudioMode::INVALID, AudioMode::CURRENT, AudioMode::CNT}) {
        SCOPED_TRACE("mode=" + toString(mode));
        ASSERT_RESULT(Result::INVALID_ARGUMENTS, device->setMode(mode));
    }
    // Test valid values
    for (AudioMode mode : {AudioMode::IN_CALL, AudioMode::IN_COMMUNICATION, AudioMode::RINGTONE,
                           AudioMode::NORMAL /* Make sure to leave the test in normal mode */}) {
        SCOPED_TRACE("mode=" + toString(mode));
        ASSERT_OK(device->setMode(mode));
    }
}

TEST_F(BoolAccessorPrimaryHidlTest, BtScoNrecEnabled) {
    doc::test("Query and set the BT SCO NR&EC state");
    testAccessors<OPTIONAL>("BtScoNrecEnabled", Initial{false, OPTIONAL}, {true},
+299 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading