1 /*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 // pull in all the <= 5.0 tests
18 #include "5.0/AudioPrimaryHidlHalTest.cpp"
19
20 class SingleConfigOutputStreamTest : public OutputStreamTest {};
TEST_P(SingleConfigOutputStreamTest,CloseDeviceWithOpenedOutputStreams)21 TEST_P(SingleConfigOutputStreamTest, CloseDeviceWithOpenedOutputStreams) {
22 doc::test("Verify that a device can't be closed if there are output streams opened");
23 // Opening of the stream is done in SetUp.
24 ASSERT_RESULT(Result::INVALID_STATE, getDevice()->close());
25 ASSERT_OK(closeStream(true /*clear*/));
26 ASSERT_OK(getDevice()->close());
27 ASSERT_TRUE(resetDevice());
28 }
29 INSTANTIATE_TEST_CASE_P(SingleConfigOutputStream, SingleConfigOutputStreamTest,
30 ::testing::ValuesIn(getOutputDeviceSingleConfigParameters()),
31 &DeviceConfigParameterToString);
32 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(SingleConfigOutputStreamTest);
33
34 class SingleConfigInputStreamTest : public InputStreamTest {};
TEST_P(SingleConfigInputStreamTest,CloseDeviceWithOpenedInputStreams)35 TEST_P(SingleConfigInputStreamTest, CloseDeviceWithOpenedInputStreams) {
36 doc::test("Verify that a device can't be closed if there are input streams opened");
37 // Opening of the stream is done in SetUp.
38 ASSERT_RESULT(Result::INVALID_STATE, getDevice()->close());
39 ASSERT_OK(closeStream(true /*clear*/));
40 ASSERT_OK(getDevice()->close());
41 ASSERT_TRUE(resetDevice());
42 }
43 INSTANTIATE_TEST_CASE_P(SingleConfigInputStream, SingleConfigInputStreamTest,
44 ::testing::ValuesIn(getInputDeviceSingleConfigParameters()),
45 &DeviceConfigParameterToString);
46 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(SingleConfigInputStreamTest);
47
TEST_P(AudioPatchHidlTest,UpdatePatchInvalidHandle)48 TEST_P(AudioPatchHidlTest, UpdatePatchInvalidHandle) {
49 doc::test("Verify that passing an invalid handle to updateAudioPatch is checked");
50 AudioPatchHandle ignored;
51 ASSERT_OK(getDevice()->updateAudioPatch(AudioPatchHandle{}, hidl_vec<AudioPortConfig>(),
52 hidl_vec<AudioPortConfig>(), returnIn(res, ignored)));
53 ASSERT_RESULT(Result::INVALID_ARGUMENTS, res);
54 }
55
56 using DualMonoModeAccessorHidlTest = AccessorHidlTest<DualMonoMode, OutputStreamTest>;
TEST_P(DualMonoModeAccessorHidlTest,DualMonoModeTest)57 TEST_P(DualMonoModeAccessorHidlTest, DualMonoModeTest) {
58 doc::test("Check that dual mono mode can be set and retrieved");
59 testAccessors<OPTIONAL>(&OutputStreamTest::getStream, "dual mono mode",
60 Initial{DualMonoMode::OFF},
61 {DualMonoMode::LR, DualMonoMode::LL, DualMonoMode::RR},
62 &::android::hardware::audio::CPP_VERSION::IStreamOut::setDualMonoMode,
63 &::android::hardware::audio::CPP_VERSION::IStreamOut::getDualMonoMode);
64 }
65
66 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(DualMonoModeAccessorHidlTest);
67 INSTANTIATE_TEST_CASE_P(DualMonoModeHidl, DualMonoModeAccessorHidlTest,
68 ::testing::ValuesIn(getOutputDeviceConfigParameters()),
69 &DeviceConfigParameterToString);
70
71 using AudioDescriptionMixLevelHidlTest = AccessorHidlTest<float, OutputStreamTest>;
TEST_P(AudioDescriptionMixLevelHidlTest,AudioDescriptionMixLevelTest)72 TEST_P(AudioDescriptionMixLevelHidlTest, AudioDescriptionMixLevelTest) {
73 doc::test("Check that audio description mix level can be set and retrieved");
74 testAccessors<OPTIONAL>(
75 &OutputStreamTest::getStream, "audio description mix level",
76 Initial{-std::numeric_limits<float>::infinity()}, {-48.0f, -1.0f, 0.0f, 1.0f, 48.0f},
77 &::android::hardware::audio::CPP_VERSION::IStreamOut::setAudioDescriptionMixLevel,
78 &::android::hardware::audio::CPP_VERSION::IStreamOut::getAudioDescriptionMixLevel,
79 {48.5f, 1000.0f, std::numeric_limits<float>::infinity()});
80 }
81
82 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(AudioDescriptionMixLevelHidlTest);
83 INSTANTIATE_TEST_CASE_P(AudioDescriptionMixLevelHidl, AudioDescriptionMixLevelHidlTest,
84 ::testing::ValuesIn(getOutputDeviceConfigParameters()),
85 &DeviceConfigParameterToString);
86
87 using PlaybackRateParametersHidlTest = AccessorHidlTest<PlaybackRate, OutputStreamTest>;
TEST_P(PlaybackRateParametersHidlTest,PlaybackRateParametersTest)88 TEST_P(PlaybackRateParametersHidlTest, PlaybackRateParametersTest) {
89 doc::test("Check that playback rate parameters can be set and retrieved");
90 testAccessors<OPTIONAL>(
91 &OutputStreamTest::getStream, "playback rate parameters",
92 Initial{PlaybackRate{1.0f, 1.0f, TimestretchMode::DEFAULT,
93 TimestretchFallbackMode::FAIL}},
94 {// Speed and pitch values in the range from 0.5f to 2.0f must be supported
95 // (see the definition of IStreamOut::setPlaybackRateParameters).
96 PlaybackRate{1.0f, 1.0f, TimestretchMode::DEFAULT, TimestretchFallbackMode::MUTE},
97 PlaybackRate{2.0f, 2.0f, TimestretchMode::DEFAULT, TimestretchFallbackMode::MUTE},
98 PlaybackRate{0.5f, 0.5f, TimestretchMode::DEFAULT, TimestretchFallbackMode::MUTE},
99 // Gross speed / pitch values must not be rejected if the fallback mode is "mute"
100 PlaybackRate{1000.0f, 1000.0f, TimestretchMode::DEFAULT,
101 TimestretchFallbackMode::MUTE},
102 // Default speed / pitch values must not be rejected in "fail" fallback mode
103 PlaybackRate{1.0f, 1.0f, TimestretchMode::DEFAULT, TimestretchFallbackMode::FAIL},
104 // Same for "voice" mode
105 PlaybackRate{1.0f, 1.0f, TimestretchMode::VOICE, TimestretchFallbackMode::MUTE},
106 PlaybackRate{2.0f, 2.0f, TimestretchMode::VOICE, TimestretchFallbackMode::MUTE},
107 PlaybackRate{0.5f, 0.5f, TimestretchMode::VOICE, TimestretchFallbackMode::MUTE},
108 PlaybackRate{1000.0f, 1000.0f, TimestretchMode::VOICE, TimestretchFallbackMode::MUTE},
109 PlaybackRate{1.0f, 1.0f, TimestretchMode::VOICE, TimestretchFallbackMode::FAIL}},
110 &::android::hardware::audio::CPP_VERSION::IStreamOut::setPlaybackRateParameters,
111 &::android::hardware::audio::CPP_VERSION::IStreamOut::getPlaybackRateParameters,
112 {PlaybackRate{1000.0f, 1000.0f, TimestretchMode::DEFAULT,
113 TimestretchFallbackMode::FAIL},
114 PlaybackRate{1000.0f, 1000.0f, TimestretchMode::VOICE,
115 TimestretchFallbackMode::FAIL}});
116 }
117
118 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(PlaybackRateParametersHidlTest);
119 INSTANTIATE_TEST_CASE_P(PlaybackRateParametersHidl, PlaybackRateParametersHidlTest,
120 ::testing::ValuesIn(getOutputDeviceConfigParameters()),
121 &DeviceConfigParameterToString);
122
123 /** Stub implementation of IStreamOutEventCallback **/
124 class MockOutEventCallbacks : public IStreamOutEventCallback {
onCodecFormatChanged(const hidl_vec<uint8_t> & audioMetadata __unused)125 Return<void> onCodecFormatChanged(const hidl_vec<uint8_t>& audioMetadata __unused) override {
126 return {};
127 }
128 };
129
TEST_P(OutputStreamTest,SetEventCallback)130 TEST_P(OutputStreamTest, SetEventCallback) {
131 doc::test("If supported, set event callback for output stream should never fail");
132 auto res = stream->setEventCallback(new MockOutEventCallbacks);
133 EXPECT_RESULT(okOrNotSupported, res);
134 if (res == Result::OK) {
135 ASSERT_OK(stream->setEventCallback(nullptr));
136 } else {
137 doc::partialTest("The stream does not support event callback");
138 }
139 }
140