2 * Copyright (C) 2017 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #define LOG_TAG "VtsHalAudioV2_0TargetTest"
26 #include <type_traits>
29 #include <VtsHalHidlTargetTestBase.h>
31 #include <android-base/logging.h>
33 #include <android/hardware/audio/2.0/IDevice.h>
34 #include <android/hardware/audio/2.0/IDevicesFactory.h>
35 #include <android/hardware/audio/2.0/IPrimaryDevice.h>
36 #include <android/hardware/audio/2.0/types.h>
37 #include <android/hardware/audio/common/2.0/types.h>
39 #include "utility/AssertOk.h"
40 #include "utility/PrettyPrintAudioTypes.h"
41 #include "utility/ReturnIn.h"
48 using ::android::hardware::Return;
49 using ::android::hardware::hidl_handle;
50 using ::android::hardware::hidl_string;
51 using ::android::hardware::hidl_vec;
52 using ::android::hardware::MQDescriptorSync;
53 using ::android::hardware::audio::V2_0::AudioDrain;
54 using ::android::hardware::audio::V2_0::DeviceAddress;
55 using ::android::hardware::audio::V2_0::IDevice;
56 using ::android::hardware::audio::V2_0::IPrimaryDevice;
57 using TtyMode = ::android::hardware::audio::V2_0::IPrimaryDevice::TtyMode;
58 using ::android::hardware::audio::V2_0::IDevicesFactory;
59 using ::android::hardware::audio::V2_0::IStream;
60 using ::android::hardware::audio::V2_0::IStreamIn;
61 using ::android::hardware::audio::V2_0::TimeSpec;
62 using ReadParameters =
63 ::android::hardware::audio::V2_0::IStreamIn::ReadParameters;
64 using ReadStatus = ::android::hardware::audio::V2_0::IStreamIn::ReadStatus;
65 using ::android::hardware::audio::V2_0::IStreamOut;
66 using ::android::hardware::audio::V2_0::IStreamOutCallback;
67 using ::android::hardware::audio::V2_0::MmapBufferInfo;
68 using ::android::hardware::audio::V2_0::MmapPosition;
69 using ::android::hardware::audio::V2_0::ParameterValue;
70 using ::android::hardware::audio::V2_0::Result;
71 using ::android::hardware::audio::common::V2_0::AudioChannelMask;
72 using ::android::hardware::audio::common::V2_0::AudioConfig;
73 using ::android::hardware::audio::common::V2_0::AudioDevice;
74 using ::android::hardware::audio::common::V2_0::AudioFormat;
75 using ::android::hardware::audio::common::V2_0::AudioHandleConsts;
76 using ::android::hardware::audio::common::V2_0::AudioInputFlag;
77 using ::android::hardware::audio::common::V2_0::AudioIoHandle;
78 using ::android::hardware::audio::common::V2_0::AudioMode;
79 using ::android::hardware::audio::common::V2_0::AudioOffloadInfo;
80 using ::android::hardware::audio::common::V2_0::AudioOutputFlag;
81 using ::android::hardware::audio::common::V2_0::AudioSource;
82 using ::android::hardware::audio::common::V2_0::ThreadInfo;
84 using utility::returnIn;
86 const char* getTestName() {
87 return ::testing::UnitTest::GetInstance()->current_test_info()->name();
91 /** Document the current test case.
92 * Eg: calling `doc::test("Dump the state of the hal")` in the "debugDump" test
94 * <testcase name="debugDump" status="run" time="6"
95 * classname="AudioPrimaryHidlTest"
96 description="Dump the state of the hal." />
98 https://github.com/google/googletest/blob/master/googletest/docs/AdvancedGuide.md#logging-additional-information
100 void test(const std::string& testCaseDocumentation) {
101 ::testing::Test::RecordProperty("description", testCaseDocumentation);
104 /** Document why a test was not fully run. Usually due to an optional feature
105 * not implemented. */
106 void partialTest(const std::string& reason) {
107 LOG(INFO) << "Test " << getTestName() << " partially run: " << reason;
108 ::testing::Test::RecordProperty("partialyRunTest", reason);
111 /** Add a note to the test. */
112 void note(const std::string& note) {
113 LOG(INFO) << "Test " << getTestName() << " noted: " << note;
114 ::testing::Test::RecordProperty("note", note);
118 // Register callback for static object destruction
119 // Avoid destroying static objects after main return.
120 // Post main return destruction leads to incorrect gtest timing measurements as
122 // debuging if anything goes wrong during destruction.
123 class Environment : public ::testing::Environment {
125 using TearDownFunc = std::function<void()>;
126 void registerTearDown(TearDownFunc&& tearDown) {
127 tearDowns.push_back(std::move(tearDown));
131 void TearDown() override {
132 // Call the tear downs in reverse order of insertion
133 for (auto& tearDown : tearDowns) {
137 std::list<TearDownFunc> tearDowns;
139 // Instance to register global tearDown
140 static Environment* environment;
142 class HidlTest : public ::testing::VtsHalHidlTargetTestBase {
144 // Convenient member to store results
148 //////////////////////////////////////////////////////////////////////////////
149 ////////////////////// getService audio_devices_factory //////////////////////
150 //////////////////////////////////////////////////////////////////////////////
152 // Test all audio devices
153 class AudioHidlTest : public HidlTest {
155 void SetUp() override {
156 ASSERT_NO_FATAL_FAILURE(HidlTest::SetUp()); // setup base
158 if (devicesFactory == nullptr) {
159 environment->registerTearDown([] { devicesFactory.clear(); });
160 devicesFactory = ::testing::VtsHalHidlTargetTestBase::getService<
163 ASSERT_TRUE(devicesFactory != nullptr);
167 // Cache the devicesFactory retrieval to speed up each test by ~0.5s
168 static sp<IDevicesFactory> devicesFactory;
170 sp<IDevicesFactory> AudioHidlTest::devicesFactory;
172 TEST_F(AudioHidlTest, GetAudioDevicesFactoryService) {
173 doc::test("test the getService (called in SetUp)");
176 TEST_F(AudioHidlTest, OpenDeviceInvalidParameter) {
177 doc::test("test passing an invalid parameter to openDevice");
178 IDevicesFactory::Result result;
180 ASSERT_OK(devicesFactory->openDevice(IDevicesFactory::Device(-1),
181 returnIn(result, device)));
182 ASSERT_EQ(IDevicesFactory::Result::INVALID_ARGUMENTS, result);
183 ASSERT_TRUE(device == nullptr);
186 //////////////////////////////////////////////////////////////////////////////
187 /////////////////////////////// openDevice primary ///////////////////////////
188 //////////////////////////////////////////////////////////////////////////////
190 // Test the primary device
191 class AudioPrimaryHidlTest : public AudioHidlTest {
193 /** Primary HAL test are NOT thread safe. */
194 void SetUp() override {
195 ASSERT_NO_FATAL_FAILURE(AudioHidlTest::SetUp()); // setup base
197 if (device == nullptr) {
198 IDevicesFactory::Result result;
199 sp<IDevice> baseDevice;
201 devicesFactory->openDevice(IDevicesFactory::Device::PRIMARY,
202 returnIn(result, baseDevice)));
204 ASSERT_TRUE(baseDevice != nullptr);
206 environment->registerTearDown([] { device.clear(); });
207 device = IPrimaryDevice::castFrom(baseDevice);
208 ASSERT_TRUE(device != nullptr);
213 // Cache the device opening to speed up each test by ~0.5s
214 static sp<IPrimaryDevice> device;
216 sp<IPrimaryDevice> AudioPrimaryHidlTest::device;
218 TEST_F(AudioPrimaryHidlTest, OpenPrimaryDevice) {
219 doc::test("Test the openDevice (called in SetUp)");
222 TEST_F(AudioPrimaryHidlTest, Init) {
223 doc::test("Test that the audio primary hal initialized correctly");
224 ASSERT_OK(device->initCheck());
227 //////////////////////////////////////////////////////////////////////////////
228 ///////////////////// {set,get}{Master,Mic}{Mute,Volume} /////////////////////
229 //////////////////////////////////////////////////////////////////////////////
231 template <class Property>
232 class AccessorPrimaryHidlTest : public AudioPrimaryHidlTest {
234 /** Test a property getter and setter. */
235 template <class Getter, class Setter>
236 void testAccessors(const string& propertyName,
237 const vector<Property>& valuesToTest, Setter setter,
239 const vector<Property>& invalidValues = {}) {
240 Property initialValue; // Save initial value to restore it at the end
242 ASSERT_OK((device.get()->*getter)(returnIn(res, initialValue)));
245 for (Property setValue : valuesToTest) {
246 SCOPED_TRACE("Test " + propertyName + " getter and setter for " +
247 testing::PrintToString(setValue));
248 ASSERT_OK((device.get()->*setter)(setValue));
250 // Make sure the getter returns the same value just set
251 ASSERT_OK((device.get()->*getter)(returnIn(res, getValue)));
253 EXPECT_EQ(setValue, getValue);
256 for (Property invalidValue : invalidValues) {
257 SCOPED_TRACE("Try to set " + propertyName +
258 " with the invalid value " +
259 testing::PrintToString(invalidValue));
260 EXPECT_RESULT(Result::INVALID_ARGUMENTS,
261 (device.get()->*setter)(invalidValue));
265 (device.get()->*setter)(initialValue)); // restore initial value
268 /** Test the getter and setter of an optional feature. */
269 template <class Getter, class Setter>
270 void testOptionalAccessors(const string& propertyName,
271 const vector<Property>& valuesToTest,
272 Setter setter, Getter getter,
273 const vector<Property>& invalidValues = {}) {
274 doc::test("Test the optional " + propertyName + " getters and setter");
276 SCOPED_TRACE("Test feature support by calling the getter");
277 Property initialValue;
278 ASSERT_OK((device.get()->*getter)(returnIn(res, initialValue)));
279 if (res == Result::NOT_SUPPORTED) {
280 doc::partialTest(propertyName + " getter is not supported");
283 ASSERT_OK(res); // If it is supported it must succeed
285 // The feature is supported, test it
286 testAccessors(propertyName, valuesToTest, setter, getter,
291 using BoolAccessorPrimaryHidlTest = AccessorPrimaryHidlTest<bool>;
293 TEST_F(BoolAccessorPrimaryHidlTest, MicMuteTest) {
294 doc::test("Check that the mic can be muted and unmuted");
295 testAccessors("mic mute", {true, false, true}, &IDevice::setMicMute,
296 &IDevice::getMicMute);
297 // TODO: check that the mic is really muted (all sample are 0)
300 TEST_F(BoolAccessorPrimaryHidlTest, MasterMuteTest) {
302 "If master mute is supported, try to mute and unmute the master "
304 testOptionalAccessors("master mute", {true, false, true},
305 &IDevice::setMasterMute, &IDevice::getMasterMute);
306 // TODO: check that the master volume is really muted
309 using FloatAccessorPrimaryHidlTest = AccessorPrimaryHidlTest<float>;
310 TEST_F(FloatAccessorPrimaryHidlTest, MasterVolumeTest) {
311 doc::test("Test the master volume if supported");
312 testOptionalAccessors("master volume", {0, 0.5, 1},
313 &IDevice::setMasterVolume, &IDevice::getMasterVolume,
314 {-0.1, 1.1, NAN, INFINITY, -INFINITY,
315 1 + std::numeric_limits<float>::epsilon()});
316 // TODO: check that the master volume is really changed
319 //////////////////////////////////////////////////////////////////////////////
320 //////////////////////////////// AudioPatches ////////////////////////////////
321 //////////////////////////////////////////////////////////////////////////////
323 class AudioPatchPrimaryHidlTest : public AudioPrimaryHidlTest {
325 bool areAudioPatchesSupported() {
326 auto result = device->supportsAudioPatches();
327 EXPECT_IS_OK(result);
332 TEST_F(AudioPatchPrimaryHidlTest, AudioPatches) {
333 doc::test("Test if audio patches are supported");
334 if (!areAudioPatchesSupported()) {
335 doc::partialTest("Audio patches are not supported");
338 // TODO: test audio patches
341 //////////////////////////////////////////////////////////////////////////////
342 //////////////// Required and recommended audio format support ///////////////
344 // https://source.android.com/compatibility/android-cdd.html#5_4_audio_recording
346 // https://source.android.com/compatibility/android-cdd.html#5_5_audio_playback
347 /////////// TODO: move to the beginning of the file for easier update ////////
348 //////////////////////////////////////////////////////////////////////////////
350 class AudioConfigPrimaryTest : public AudioPatchPrimaryHidlTest {
353 static const vector<AudioConfig> getRequiredSupportPlaybackAudioConfig() {
354 return combineAudioConfig(
355 {AudioChannelMask::OUT_STEREO, AudioChannelMask::OUT_MONO},
356 {8000, 11025, 16000, 22050, 32000, 44100},
357 {AudioFormat::PCM_16_BIT});
360 static const vector<AudioConfig>
361 getRecommendedSupportPlaybackAudioConfig() {
362 return combineAudioConfig(
363 {AudioChannelMask::OUT_STEREO, AudioChannelMask::OUT_MONO},
364 {24000, 48000}, {AudioFormat::PCM_16_BIT});
367 static const vector<AudioConfig> getSupportedPlaybackAudioConfig() {
368 // TODO: retrieve audio config supported by the platform
369 // as declared in the policy configuration
373 static const vector<AudioConfig> getRequiredSupportCaptureAudioConfig() {
374 return combineAudioConfig({AudioChannelMask::IN_MONO},
375 {8000, 11025, 16000, 44100},
376 {AudioFormat::PCM_16_BIT});
378 static const vector<AudioConfig> getRecommendedSupportCaptureAudioConfig() {
379 return combineAudioConfig({AudioChannelMask::IN_STEREO}, {22050, 48000},
380 {AudioFormat::PCM_16_BIT});
382 static const vector<AudioConfig> getSupportedCaptureAudioConfig() {
383 // TODO: retrieve audio config supported by the platform
384 // as declared in the policy configuration
389 static const vector<AudioConfig> combineAudioConfig(
390 vector<AudioChannelMask> channelMasks, vector<uint32_t> sampleRates,
391 vector<AudioFormat> formats) {
392 vector<AudioConfig> configs;
393 for (auto channelMask : channelMasks) {
394 for (auto sampleRate : sampleRates) {
395 for (auto format : formats) {
396 AudioConfig config{};
397 // leave offloadInfo to 0
398 config.channelMask = channelMask;
399 config.sampleRateHz = sampleRate;
400 config.format = format;
401 // FIXME: leave frameCount to 0 ?
402 configs.push_back(config);
410 /** Generate a test name based on an audio config.
412 * As the only parameter changing are channel mask and sample rate,
413 * only print those ones in the test name.
415 static string generateTestName(
416 const testing::TestParamInfo<AudioConfig>& info) {
417 const AudioConfig& config = info.param;
418 return to_string(info.index) + "__" + to_string(config.sampleRateHz) + "_" +
419 // "MONO" is more clear than "FRONT_LEFT"
420 ((config.channelMask == AudioChannelMask::OUT_MONO ||
421 config.channelMask == AudioChannelMask::IN_MONO)
423 : toString(config.channelMask));
426 //////////////////////////////////////////////////////////////////////////////
427 ///////////////////////////// getInputBufferSize /////////////////////////////
428 //////////////////////////////////////////////////////////////////////////////
430 // FIXME: execute input test only if platform declares
431 // android.hardware.microphone
432 // how to get this value ? is it a property ???
434 class AudioCaptureConfigPrimaryTest
435 : public AudioConfigPrimaryTest,
436 public ::testing::WithParamInterface<AudioConfig> {
438 void inputBufferSizeTest(const AudioConfig& audioConfig,
439 bool supportRequired) {
442 device->getInputBufferSize(audioConfig, returnIn(res, bufferSize)));
445 case Result::INVALID_ARGUMENTS:
446 EXPECT_FALSE(supportRequired);
449 // Check that the buffer is of a sane size
450 // For now only that it is > 0
451 EXPECT_GT(bufferSize, uint64_t(0));
454 FAIL() << "Invalid return status: "
455 << ::testing::PrintToString(res);
460 // Test that the required capture config and those declared in the policy are
462 class RequiredInputBufferSizeTest : public AudioCaptureConfigPrimaryTest {};
463 TEST_P(RequiredInputBufferSizeTest, RequiredInputBufferSizeTest) {
465 "Input buffer size must be retrievable for a format with required "
467 inputBufferSizeTest(GetParam(), true);
469 INSTANTIATE_TEST_CASE_P(
470 RequiredInputBufferSize, RequiredInputBufferSizeTest,
472 AudioConfigPrimaryTest::getRequiredSupportCaptureAudioConfig()),
474 INSTANTIATE_TEST_CASE_P(
475 SupportedInputBufferSize, RequiredInputBufferSizeTest,
477 AudioConfigPrimaryTest::getSupportedCaptureAudioConfig()),
480 // Test that the recommended capture config are supported or lead to a
481 // INVALID_ARGUMENTS return
482 class OptionalInputBufferSizeTest : public AudioCaptureConfigPrimaryTest {};
483 TEST_P(OptionalInputBufferSizeTest, OptionalInputBufferSizeTest) {
485 "Input buffer size should be retrievable for a format with recommended "
487 inputBufferSizeTest(GetParam(), false);
489 INSTANTIATE_TEST_CASE_P(
490 RecommendedCaptureAudioConfigSupport, OptionalInputBufferSizeTest,
492 AudioConfigPrimaryTest::getRecommendedSupportCaptureAudioConfig()),
495 //////////////////////////////////////////////////////////////////////////////
496 /////////////////////////////// setScreenState ///////////////////////////////
497 //////////////////////////////////////////////////////////////////////////////
499 TEST_F(AudioPrimaryHidlTest, setScreenState) {
500 doc::test("Check that the hal can receive the screen state");
501 for (bool turnedOn : {false, true, true, false, false}) {
502 auto ret = device->setScreenState(turnedOn);
505 auto okOrNotSupported = {Result::OK, Result::NOT_SUPPORTED};
506 ASSERT_RESULT(okOrNotSupported, result);
510 //////////////////////////////////////////////////////////////////////////////
511 //////////////////////////// {get,set}Parameters /////////////////////////////
512 //////////////////////////////////////////////////////////////////////////////
514 TEST_F(AudioPrimaryHidlTest, getParameters) {
515 doc::test("Check that the hal can set and get parameters");
516 hidl_vec<hidl_string> keys;
517 hidl_vec<ParameterValue> values;
518 ASSERT_OK(device->getParameters(keys, returnIn(res, values)));
519 ASSERT_OK(device->setParameters(values));
521 ASSERT_OK(device->setParameters(values));
524 //////////////////////////////////////////////////////////////////////////////
525 //////////////////////////////// debugDebug //////////////////////////////////
526 //////////////////////////////////////////////////////////////////////////////
528 template <class DebugDump>
529 static void testDebugDump(DebugDump debugDump) {
530 // Dump in a temporary file
531 // Note that SELinux must be deactivate for this test to work
532 FILE* file = tmpfile();
533 ASSERT_NE(nullptr, file) << errno;
535 // Wrap the temporary file file descriptor in a native handle
536 auto* nativeHandle = native_handle_create(1, 0);
537 ASSERT_NE(nullptr, nativeHandle);
538 nativeHandle->data[0] = fileno(file);
540 // Wrap this native handle in a hidl handle
542 handle.setTo(nativeHandle, true /*take ownership*/);
544 ASSERT_OK(debugDump(handle));
546 // Check that at least one bit was written by the hal
547 // TODO: debugDump does not return a Result.
548 // This mean that the hal can not report that it not implementing the
550 rewind(file); // can not fail
552 if (fread(&buff, sizeof(buff), 1, file) != 1) {
553 doc::note("debugDump does not seem implemented");
555 EXPECT_EQ(0, fclose(file)) << errno;
558 TEST_F(AudioPrimaryHidlTest, DebugDump) {
559 doc::test("Check that the hal can dump its state without error");
560 testDebugDump([](const auto& handle) { return device->debugDump(handle); });
563 TEST_F(AudioPrimaryHidlTest, DebugDumpInvalidArguments) {
564 doc::test("Check that the hal dump doesn't crash on invalid arguments");
565 ASSERT_OK(device->debugDump(hidl_handle()));
568 //////////////////////////////////////////////////////////////////////////////
569 ////////////////////////// open{Output,Input}Stream //////////////////////////
570 //////////////////////////////////////////////////////////////////////////////
572 template <class Stream>
573 class OpenStreamTest : public AudioConfigPrimaryTest,
574 public ::testing::WithParamInterface<AudioConfig> {
576 template <class Open>
577 void testOpen(Open openStream, const AudioConfig& config) {
578 // FIXME: Open a stream without an IOHandle
579 // This is not required to be accepted by hal implementations
580 AudioIoHandle ioHandle =
581 (AudioIoHandle)AudioHandleConsts::AUDIO_IO_HANDLE_NONE;
582 AudioConfig suggestedConfig{};
583 ASSERT_OK(openStream(ioHandle, config,
584 returnIn(res, stream, suggestedConfig)));
586 // TODO: only allow failure for RecommendedPlaybackAudioConfig
589 ASSERT_TRUE(stream != nullptr);
590 audioConfig = config;
592 case Result::INVALID_ARGUMENTS:
593 ASSERT_TRUE(stream == nullptr);
594 AudioConfig suggestedConfigRetry;
595 // Could not open stream with config, try again with the
598 openStream(ioHandle, suggestedConfig,
599 returnIn(res, stream, suggestedConfigRetry)));
600 // This time it must succeed
602 ASSERT_TRUE(stream != nullptr);
603 audioConfig = suggestedConfig;
606 FAIL() << "Invalid return status: "
607 << ::testing::PrintToString(res);
612 Return<Result> closeStream() {
614 return stream->close();
618 void TearDown() override {
620 ASSERT_OK(stream->close());
625 AudioConfig audioConfig;
626 DeviceAddress address = {};
631 ////////////////////////////// openOutputStream //////////////////////////////
633 class OutputStreamTest : public OpenStreamTest<IStreamOut> {
634 virtual void SetUp() override {
635 ASSERT_NO_FATAL_FAILURE(OpenStreamTest::SetUp()); // setup base
636 address.device = AudioDevice::OUT_DEFAULT;
637 const AudioConfig& config = GetParam();
638 AudioOutputFlag flags =
639 AudioOutputFlag::NONE; // TODO: test all flag combination
641 [&](AudioIoHandle handle, AudioConfig config, auto cb) {
642 return device->openOutputStream(handle, address, config, flags,
648 TEST_P(OutputStreamTest, OpenOutputStreamTest) {
650 "Check that output streams can be open with the required and "
651 "recommended config");
652 // Open done in SetUp
654 INSTANTIATE_TEST_CASE_P(
655 RequiredOutputStreamConfigSupport, OutputStreamTest,
657 AudioConfigPrimaryTest::getRequiredSupportPlaybackAudioConfig()),
659 INSTANTIATE_TEST_CASE_P(
660 SupportedOutputStreamConfig, OutputStreamTest,
662 AudioConfigPrimaryTest::getSupportedPlaybackAudioConfig()),
665 INSTANTIATE_TEST_CASE_P(
666 RecommendedOutputStreamConfigSupport, OutputStreamTest,
668 AudioConfigPrimaryTest::getRecommendedSupportPlaybackAudioConfig()),
671 ////////////////////////////// openInputStream //////////////////////////////
673 class InputStreamTest : public OpenStreamTest<IStreamIn> {
674 virtual void SetUp() override {
675 ASSERT_NO_FATAL_FAILURE(OpenStreamTest::SetUp()); // setup base
676 address.device = AudioDevice::IN_DEFAULT;
677 const AudioConfig& config = GetParam();
678 AudioInputFlag flags =
679 AudioInputFlag::NONE; // TODO: test all flag combination
681 AudioSource::DEFAULT; // TODO: test all flag combination
683 [&](AudioIoHandle handle, AudioConfig config, auto cb) {
684 return device->openInputStream(handle, address, config, flags,
691 TEST_P(InputStreamTest, OpenInputStreamTest) {
693 "Check that input streams can be open with the required and "
694 "recommended config");
695 // Open done in setup
697 INSTANTIATE_TEST_CASE_P(
698 RequiredInputStreamConfigSupport, InputStreamTest,
700 AudioConfigPrimaryTest::getRequiredSupportCaptureAudioConfig()),
702 INSTANTIATE_TEST_CASE_P(
703 SupportedInputStreamConfig, InputStreamTest,
705 AudioConfigPrimaryTest::getSupportedCaptureAudioConfig()),
708 INSTANTIATE_TEST_CASE_P(
709 RecommendedInputStreamConfigSupport, InputStreamTest,
711 AudioConfigPrimaryTest::getRecommendedSupportCaptureAudioConfig()),
714 //////////////////////////////////////////////////////////////////////////////
715 ////////////////////////////// IStream getters ///////////////////////////////
716 //////////////////////////////////////////////////////////////////////////////
718 /** Unpack the provided result.
719 * If the result is not OK, register a failure and return an undefined value. */
721 static R extract(Return<R> ret) {
729 /* Could not find a way to write a test for two parametrized class fixure
730 * thus use this macro do duplicate tests for Input and Output stream */
731 #define TEST_IO_STREAM(test_name, documentation, code) \
732 TEST_P(InputStreamTest, test_name) { \
733 doc::test(documentation); \
736 TEST_P(OutputStreamTest, test_name) { \
737 doc::test(documentation); \
743 "Check that the stream frame count == the one it was opened with",
744 ASSERT_EQ(audioConfig.frameCount, extract(stream->getFrameCount())))
746 TEST_IO_STREAM(GetSampleRate, "Check that the stream sample rate == the one it was opened with",
747 ASSERT_EQ(audioConfig.sampleRateHz, extract(stream->getSampleRate())))
749 TEST_IO_STREAM(GetChannelMask, "Check that the stream channel mask == the one it was opened with",
750 ASSERT_EQ(audioConfig.channelMask, extract(stream->getChannelMask())))
752 TEST_IO_STREAM(GetFormat,
753 "Check that the stream format == the one it was opened with",
754 ASSERT_EQ(audioConfig.format, extract(stream->getFormat())))
756 // TODO: for now only check that the framesize is not incoherent
757 TEST_IO_STREAM(GetFrameSize,
758 "Check that the stream frame size == the one it was opened with",
759 ASSERT_GT(extract(stream->getFrameSize()), 0U))
761 TEST_IO_STREAM(GetBufferSize,
762 "Check that the stream buffer size== the one it was opened with",
763 ASSERT_GE(extract(stream->getBufferSize()),
764 extract(stream->getFrameSize())));
766 template <class Property, class CapabilityGetter, class Getter, class Setter>
767 static void testCapabilityGetter(const string& name, IStream* stream,
768 Property currentValue,
769 CapabilityGetter capablityGetter,
770 Getter getter, Setter setter) {
771 hidl_vec<Property> capabilities;
772 ASSERT_OK((stream->*capablityGetter)(returnIn(capabilities)));
773 if (capabilities.size() == 0) {
774 // The default hal should probably return a NOT_SUPPORTED if the hal
776 // capability retrieval. For now it returns an empty list if not
778 doc::partialTest(name + " is not supported");
781 // TODO: This code has never been tested on a hal that supports
782 // getSupportedSampleRates
783 EXPECT_NE(std::find(capabilities.begin(), capabilities.end(), currentValue),
785 << "current " << name << " is not in the list of the supported ones "
786 << toString(capabilities);
788 // Check that all declared supported values are indeed supported
789 for (auto capability : capabilities) {
790 ASSERT_OK((stream->*setter)(capability));
791 ASSERT_EQ(capability, extract((stream->*getter)()));
795 TEST_IO_STREAM(SupportedSampleRate,
796 "Check that the stream sample rate is declared as supported",
797 testCapabilityGetter("getSupportedSampleRate", stream.get(),
798 extract(stream->getSampleRate()),
799 &IStream::getSupportedSampleRates,
800 &IStream::getSampleRate,
801 &IStream::setSampleRate))
803 TEST_IO_STREAM(SupportedChannelMask,
804 "Check that the stream channel mask is declared as supported",
805 testCapabilityGetter("getSupportedChannelMask", stream.get(),
806 extract(stream->getChannelMask()),
807 &IStream::getSupportedChannelMasks,
808 &IStream::getChannelMask,
809 &IStream::setChannelMask))
811 TEST_IO_STREAM(SupportedFormat,
812 "Check that the stream format is declared as supported",
813 testCapabilityGetter("getSupportedFormat", stream.get(),
814 extract(stream->getFormat()),
815 &IStream::getSupportedFormats,
816 &IStream::getFormat, &IStream::setFormat))
818 static void testGetDevice(IStream* stream, AudioDevice expectedDevice) {
819 // Unfortunately the interface does not allow the implementation to return
821 // Thus allow NONE as signaling that the call is not supported.
822 auto ret = stream->getDevice();
824 AudioDevice device = ret;
825 ASSERT_TRUE(device == expectedDevice || device == AudioDevice::NONE)
826 << "Expected: " << ::testing::PrintToString(expectedDevice)
827 << "\n Actual: " << ::testing::PrintToString(device);
830 TEST_IO_STREAM(GetDevice,
831 "Check that the stream device == the one it was opened with",
832 areAudioPatchesSupported()
833 ? doc::partialTest("Audio patches are supported")
834 : testGetDevice(stream.get(), address.device))
836 static void testSetDevice(IStream* stream, const DeviceAddress& address) {
837 DeviceAddress otherAddress = address;
838 otherAddress.device = (address.device & AudioDevice::BIT_IN) == 0
839 ? AudioDevice::OUT_SPEAKER
840 : AudioDevice::IN_BUILTIN_MIC;
841 EXPECT_OK(stream->setDevice(otherAddress));
843 ASSERT_OK(stream->setDevice(address)); // Go back to the original value
848 "Check that the stream can be rerouted to SPEAKER or BUILTIN_MIC",
849 areAudioPatchesSupported() ? doc::partialTest("Audio patches are supported")
850 : testSetDevice(stream.get(), address))
852 static void testGetAudioProperties(IStream* stream, AudioConfig expectedConfig) {
853 uint32_t sampleRateHz;
854 AudioChannelMask mask;
857 stream->getAudioProperties(returnIn(sampleRateHz, mask, format));
859 // FIXME: the qcom hal it does not currently negotiate the sampleRate &
861 EXPECT_EQ(expectedConfig.sampleRateHz, sampleRateHz);
862 EXPECT_EQ(expectedConfig.channelMask, mask);
863 EXPECT_EQ(expectedConfig.format, format);
866 TEST_IO_STREAM(GetAudioProperties,
867 "Check that the stream audio properties == the ones it was opened with",
868 testGetAudioProperties(stream.get(), audioConfig))
870 static void testConnectedState(IStream* stream) {
871 DeviceAddress address = {};
872 using AD = AudioDevice;
874 {AD::OUT_HDMI, AD::OUT_WIRED_HEADPHONE, AD::IN_USB_HEADSET}) {
875 address.device = device;
877 ASSERT_OK(stream->setConnectedState(address, true));
878 ASSERT_OK(stream->setConnectedState(address, false));
881 TEST_IO_STREAM(SetConnectedState,
882 "Check that the stream can be notified of device connection and "
884 testConnectedState(stream.get()))
886 static auto invalidArgsOrNotSupportedOrOK = {Result::INVALID_ARGUMENTS,
887 Result::NOT_SUPPORTED, Result::OK};
888 TEST_IO_STREAM(SetHwAvSync, "Try to set hardware sync to an invalid value",
889 ASSERT_RESULT(invalidArgsOrNotSupportedOrOK,
890 stream->setHwAvSync(666)))
892 TEST_IO_STREAM(GetHwAvSync, "Get hardware sync can not fail",
893 ASSERT_IS_OK(device->getHwAvSync()));
895 static void checkGetNoParameter(IStream* stream, hidl_vec<hidl_string> keys,
896 vector<Result> expectedResults) {
897 hidl_vec<ParameterValue> parameters;
899 ASSERT_OK(stream->getParameters(keys, returnIn(res, parameters)));
900 ASSERT_RESULT(expectedResults, res);
901 if (res == Result::OK) {
902 for (auto& parameter : parameters) {
903 ASSERT_EQ(0U, parameter.value.size()) << toString(parameter);
908 /* Get/Set parameter is intended to be an opaque channel between vendors app and
910 * Thus can not be meaningfully tested.
912 TEST_IO_STREAM(getEmptySetParameter, "Retrieve the values of an empty set",
913 checkGetNoParameter(stream.get(), {} /* keys */, {Result::OK}))
915 TEST_IO_STREAM(getNonExistingParameter,
916 "Retrieve the values of an non existing parameter",
917 checkGetNoParameter(stream.get(),
918 {"Non existing key"} /* keys */,
919 {Result::NOT_SUPPORTED}))
921 TEST_IO_STREAM(setEmptySetParameter,
922 "Set the values of an empty set of parameters",
923 ASSERT_RESULT(Result::OK, stream->setParameters({})))
926 setNonExistingParameter, "Set the values of an non existing parameter",
927 // Unfortunately, the set_parameter legacy interface did not return any
928 // error code when a key is not supported.
929 // To allow implementation to just wrapped the legacy one, consider OK as a
930 // valid result for setting a non existing parameter.
931 ASSERT_RESULT(invalidArgsOrNotSupportedOrOK,
932 stream->setParameters({{"non existing key", "0"}})))
934 TEST_IO_STREAM(DebugDump,
935 "Check that a stream can dump its state without error",
936 testDebugDump([this](const auto& handle) {
937 return stream->debugDump(handle);
940 TEST_IO_STREAM(DebugDumpInvalidArguments,
941 "Check that the stream dump doesn't crash on invalid arguments",
942 ASSERT_OK(stream->debugDump(hidl_handle())))
944 //////////////////////////////////////////////////////////////////////////////
945 ////////////////////////////// addRemoveEffect ///////////////////////////////
946 //////////////////////////////////////////////////////////////////////////////
948 TEST_IO_STREAM(AddNonExistingEffect, "Adding a non existing effect should fail",
949 ASSERT_RESULT(Result::INVALID_ARGUMENTS, stream->addEffect(666)))
950 TEST_IO_STREAM(RemoveNonExistingEffect,
951 "Removing a non existing effect should fail",
952 ASSERT_RESULT(Result::INVALID_ARGUMENTS,
953 stream->removeEffect(666)))
955 // TODO: positive tests
957 //////////////////////////////////////////////////////////////////////////////
958 /////////////////////////////// Control ////////////////////////////////
959 //////////////////////////////////////////////////////////////////////////////
961 TEST_IO_STREAM(standby, "Make sure the stream can be put in stanby",
962 ASSERT_OK(stream->standby())) // can not fail
964 static vector<Result> invalidStateOrNotSupported = {Result::INVALID_STATE,
965 Result::NOT_SUPPORTED};
967 TEST_IO_STREAM(startNoMmap,
968 "Starting a mmaped stream before mapping it should fail",
969 ASSERT_RESULT(invalidStateOrNotSupported, stream->start()))
971 TEST_IO_STREAM(stopNoMmap,
972 "Stopping a mmaped stream before mapping it should fail",
973 ASSERT_RESULT(invalidStateOrNotSupported, stream->stop()))
975 TEST_IO_STREAM(getMmapPositionNoMmap,
976 "Get a stream Mmap position before mapping it should fail",
977 ASSERT_RESULT(invalidStateOrNotSupported, stream->stop()))
979 TEST_IO_STREAM(close, "Make sure a stream can be closed",
980 ASSERT_OK(closeStream()))
981 TEST_IO_STREAM(closeTwice, "Make sure a stream can not be closed twice",
982 ASSERT_OK(closeStream());
983 ASSERT_RESULT(Result::INVALID_STATE, closeStream()))
985 static auto invalidArgsOrNotSupported = {Result::INVALID_ARGUMENTS,
986 Result::NOT_SUPPORTED};
987 static void testCreateTooBigMmapBuffer(IStream* stream) {
990 // Assume that int max is a value too big to be allocated
991 // This is true currently with a 32bit media server, but might not when it
992 // will run in 64 bit
993 auto minSizeFrames = std::numeric_limits<int32_t>::max();
994 ASSERT_OK(stream->createMmapBuffer(minSizeFrames, returnIn(res, info)));
995 ASSERT_RESULT(invalidArgsOrNotSupported, res);
998 TEST_IO_STREAM(CreateTooBigMmapBuffer, "Create mmap buffer too big should fail",
999 testCreateTooBigMmapBuffer(stream.get()))
1001 static void testGetMmapPositionOfNonMmapedStream(IStream* stream) {
1003 MmapPosition position;
1004 ASSERT_OK(stream->getMmapPosition(returnIn(res, position)));
1005 ASSERT_RESULT(invalidArgsOrNotSupported, res);
1009 GetMmapPositionOfNonMmapedStream,
1010 "Retrieving the mmap position of a non mmaped stream should fail",
1011 testGetMmapPositionOfNonMmapedStream(stream.get()))
1013 //////////////////////////////////////////////////////////////////////////////
1014 ///////////////////////////////// StreamIn ///////////////////////////////////
1015 //////////////////////////////////////////////////////////////////////////////
1017 TEST_P(InputStreamTest, GetAudioSource) {
1019 "Retrieving the audio source of an input stream should always succeed");
1021 ASSERT_OK(stream->getAudioSource(returnIn(res, source)));
1022 if (res == Result::NOT_SUPPORTED) {
1023 doc::partialTest("getAudioSource is not supported");
1027 ASSERT_EQ(AudioSource::DEFAULT, source);
1030 static void testUnitaryGain(std::function<Return<Result>(float)> setGain) {
1032 (float[]){-INFINITY, -1.0, 1.0 + std::numeric_limits<float>::epsilon(),
1033 2.0, INFINITY, NAN}) {
1034 EXPECT_RESULT(Result::INVALID_ARGUMENTS, setGain(value)) << "value="
1037 // Do not consider -0.0 as an invalid value as it is == with 0.0
1038 for (float value : {-0.0, 0.0, 0.01, 0.5, 0.09, 1.0 /* Restore volume*/}) {
1039 EXPECT_OK(setGain(value)) << "value=" << value;
1043 static void testOptionalUnitaryGain(
1044 std::function<Return<Result>(float)> setGain, string debugName) {
1045 auto result = setGain(1);
1046 ASSERT_IS_OK(result);
1047 if (result == Result::NOT_SUPPORTED) {
1048 doc::partialTest(debugName + " is not supported");
1051 testUnitaryGain(setGain);
1054 TEST_P(InputStreamTest, SetGain) {
1055 doc::test("The gain of an input stream should only be set between [0,1]");
1056 testOptionalUnitaryGain(
1057 [this](float volume) { return stream->setGain(volume); },
1058 "InputStream::setGain");
1061 static void testPrepareForReading(IStreamIn* stream, uint32_t frameSize,
1062 uint32_t framesCount) {
1064 // Ignore output parameters as the call should fail
1065 ASSERT_OK(stream->prepareForReading(
1066 frameSize, framesCount,
1067 [&res](auto r, auto&, auto&, auto&, auto&) { res = r; }));
1068 EXPECT_RESULT(Result::INVALID_ARGUMENTS, res);
1071 TEST_P(InputStreamTest, PrepareForReadingWithZeroBuffer) {
1073 "Preparing a stream for reading with a 0 sized buffer should fail");
1074 testPrepareForReading(stream.get(), 0, 0);
1077 TEST_P(InputStreamTest, PrepareForReadingWithHugeBuffer) {
1079 "Preparing a stream for reading with a 2^32 sized buffer should fail");
1080 testPrepareForReading(stream.get(), 1,
1081 std::numeric_limits<uint32_t>::max());
1084 TEST_P(InputStreamTest, PrepareForReadingCheckOverflow) {
1086 "Preparing a stream for reading with a overflowing sized buffer should "
1088 auto uintMax = std::numeric_limits<uint32_t>::max();
1089 testPrepareForReading(stream.get(), uintMax, uintMax);
1092 TEST_P(InputStreamTest, GetInputFramesLost) {
1094 "The number of frames lost on a never started stream should be 0");
1095 auto ret = stream->getInputFramesLost();
1097 uint32_t framesLost{ret};
1098 ASSERT_EQ(0U, framesLost);
1101 TEST_P(InputStreamTest, getCapturePosition) {
1103 "The capture position of a non prepared stream should not be "
1107 ASSERT_OK(stream->getCapturePosition(returnIn(res, frames, time)));
1108 ASSERT_RESULT(invalidStateOrNotSupported, res);
1111 //////////////////////////////////////////////////////////////////////////////
1112 ///////////////////////////////// StreamIn ///////////////////////////////////
1113 //////////////////////////////////////////////////////////////////////////////
1115 TEST_P(OutputStreamTest, getLatency) {
1116 doc::test("Make sure latency is over 0");
1117 auto result = stream->getLatency();
1118 ASSERT_IS_OK(result);
1119 ASSERT_GT(result, 0U);
1122 TEST_P(OutputStreamTest, setVolume) {
1123 doc::test("Try to set the output volume");
1124 testOptionalUnitaryGain(
1125 [this](float volume) { return stream->setVolume(volume, volume); },
1129 static void testPrepareForWriting(IStreamOut* stream, uint32_t frameSize,
1130 uint32_t framesCount) {
1132 // Ignore output parameters as the call should fail
1133 ASSERT_OK(stream->prepareForWriting(
1134 frameSize, framesCount,
1135 [&res](auto r, auto&, auto&, auto&, auto&) { res = r; }));
1136 EXPECT_RESULT(Result::INVALID_ARGUMENTS, res);
1139 TEST_P(OutputStreamTest, PrepareForWriteWithZeroBuffer) {
1141 "Preparing a stream for writing with a 0 sized buffer should fail");
1142 testPrepareForWriting(stream.get(), 0, 0);
1145 TEST_P(OutputStreamTest, PrepareForWriteWithHugeBuffer) {
1147 "Preparing a stream for writing with a 2^32 sized buffer should fail");
1148 testPrepareForWriting(stream.get(), 1,
1149 std::numeric_limits<uint32_t>::max());
1152 TEST_P(OutputStreamTest, PrepareForWritingCheckOverflow) {
1154 "Preparing a stream for writing with a overflowing sized buffer should "
1156 auto uintMax = std::numeric_limits<uint32_t>::max();
1157 testPrepareForWriting(stream.get(), uintMax, uintMax);
1161 Capability(IStreamOut* stream) {
1162 EXPECT_OK(stream->supportsPauseAndResume(returnIn(pause, resume)));
1163 auto ret = stream->supportsDrain();
1170 bool resume = false;
1174 TEST_P(OutputStreamTest, SupportsPauseAndResumeAndDrain) {
1176 "Implementation must expose pause, resume and drain capabilities");
1177 Capability(stream.get());
1180 template <class Value>
1181 static void checkInvalidStateOr0(Result res, Value value) {
1183 case Result::INVALID_STATE:
1186 ASSERT_EQ(0U, value);
1189 FAIL() << "Unexpected result " << toString(res);
1193 TEST_P(OutputStreamTest, GetRenderPosition) {
1194 doc::test("A new stream render position should be 0 or INVALID_STATE");
1196 ASSERT_OK(stream->getRenderPosition(returnIn(res, dspFrames)));
1197 if (res == Result::NOT_SUPPORTED) {
1198 doc::partialTest("getRenderPosition is not supported");
1201 checkInvalidStateOr0(res, dspFrames);
1204 TEST_P(OutputStreamTest, GetNextWriteTimestamp) {
1205 doc::test("A new stream next write timestamp should be 0 or INVALID_STATE");
1206 uint64_t timestampUs;
1207 ASSERT_OK(stream->getNextWriteTimestamp(returnIn(res, timestampUs)));
1208 if (res == Result::NOT_SUPPORTED) {
1209 doc::partialTest("getNextWriteTimestamp is not supported");
1212 checkInvalidStateOr0(res, timestampUs);
1215 /** Stub implementation of out stream callback. */
1216 class MockOutCallbacks : public IStreamOutCallback {
1217 Return<void> onWriteReady() override { return {}; }
1218 Return<void> onDrainReady() override { return {}; }
1219 Return<void> onError() override { return {}; }
1222 static bool isAsyncModeSupported(IStreamOut* stream) {
1223 auto res = stream->setCallback(new MockOutCallbacks);
1224 stream->clearCallback(); // try to restore the no callback state, ignore
1226 auto okOrNotSupported = {Result::OK, Result::NOT_SUPPORTED};
1227 EXPECT_RESULT(okOrNotSupported, res);
1228 return res.isOk() ? res == Result::OK : false;
1231 TEST_P(OutputStreamTest, SetCallback) {
1233 "If supported, registering callback for async operation should never "
1235 if (!isAsyncModeSupported(stream.get())) {
1236 doc::partialTest("The stream does not support async operations");
1239 ASSERT_OK(stream->setCallback(new MockOutCallbacks));
1240 ASSERT_OK(stream->setCallback(new MockOutCallbacks));
1243 TEST_P(OutputStreamTest, clearCallback) {
1245 "If supported, clearing a callback to go back to sync operation should "
1247 if (!isAsyncModeSupported(stream.get())) {
1248 doc::partialTest("The stream does not support async operations");
1251 // TODO: Clarify if clearing a non existing callback should fail
1252 ASSERT_OK(stream->setCallback(new MockOutCallbacks));
1253 ASSERT_OK(stream->clearCallback());
1256 TEST_P(OutputStreamTest, Resume) {
1258 "If supported, a stream should fail to resume if not previously "
1260 if (!Capability(stream.get()).resume) {
1261 doc::partialTest("The output stream does not support resume");
1264 ASSERT_RESULT(Result::INVALID_STATE, stream->resume());
1267 TEST_P(OutputStreamTest, Pause) {
1269 "If supported, a stream should fail to pause if not previously "
1271 if (!Capability(stream.get()).pause) {
1272 doc::partialTest("The output stream does not support pause");
1275 ASSERT_RESULT(Result::INVALID_STATE, stream->resume());
1278 static void testDrain(IStreamOut* stream, AudioDrain type) {
1279 if (!Capability(stream).drain) {
1280 doc::partialTest("The output stream does not support drain");
1283 ASSERT_RESULT(Result::OK, stream->drain(type));
1286 TEST_P(OutputStreamTest, DrainAll) {
1287 doc::test("If supported, a stream should always succeed to drain");
1288 testDrain(stream.get(), AudioDrain::ALL);
1291 TEST_P(OutputStreamTest, DrainEarlyNotify) {
1292 doc::test("If supported, a stream should always succeed to drain");
1293 testDrain(stream.get(), AudioDrain::EARLY_NOTIFY);
1296 TEST_P(OutputStreamTest, FlushStop) {
1297 doc::test("If supported, a stream should always succeed to flush");
1298 auto ret = stream->flush();
1300 if (ret == Result::NOT_SUPPORTED) {
1301 doc::partialTest("Flush is not supported");
1307 TEST_P(OutputStreamTest, GetPresentationPositionStop) {
1309 "If supported, a stream should always succeed to retrieve the "
1310 "presentation position");
1313 ASSERT_OK(stream->getPresentationPosition(returnIn(res, frames, mesureTS)));
1314 if (res == Result::NOT_SUPPORTED) {
1315 doc::partialTest("getpresentationPosition is not supported");
1318 ASSERT_EQ(0U, frames);
1320 if (mesureTS.tvNSec == 0 && mesureTS.tvSec == 0) {
1321 // As the stream has never written a frame yet,
1322 // the timestamp does not really have a meaning, allow to return 0
1326 // Make sure the return measure is not more than 1s old.
1327 struct timespec currentTS;
1328 ASSERT_EQ(0, clock_gettime(CLOCK_MONOTONIC, ¤tTS)) << errno;
1330 auto toMicroSec = [](uint64_t sec, auto nsec) {
1331 return sec * 1e+6 + nsec / 1e+3;
1333 auto currentTime = toMicroSec(currentTS.tv_sec, currentTS.tv_nsec);
1334 auto mesureTime = toMicroSec(mesureTS.tvSec, mesureTS.tvNSec);
1335 ASSERT_PRED2([](auto c, auto m) { return c - m < 1e+6; }, currentTime,
1339 //////////////////////////////////////////////////////////////////////////////
1340 /////////////////////////////// PrimaryDevice ////////////////////////////////
1341 //////////////////////////////////////////////////////////////////////////////
1343 TEST_F(AudioPrimaryHidlTest, setVoiceVolume) {
1344 doc::test("Make sure setVoiceVolume only succeed if volume is in [0,1]");
1345 testUnitaryGain([](float volume) { return device->setVoiceVolume(volume); });
1348 TEST_F(AudioPrimaryHidlTest, setMode) {
1350 "Make sure setMode always succeeds if mode is valid "
1351 "and fails otherwise");
1352 // Test Invalid values
1353 for (AudioMode mode :
1354 {AudioMode::INVALID, AudioMode::CURRENT, AudioMode::CNT}) {
1355 SCOPED_TRACE("mode=" + toString(mode));
1356 ASSERT_RESULT(Result::INVALID_ARGUMENTS, device->setMode(mode));
1358 // Test valid values
1359 for (AudioMode mode :
1360 {AudioMode::IN_CALL, AudioMode::IN_COMMUNICATION, AudioMode::RINGTONE,
1361 AudioMode::NORMAL /* Make sure to leave the test in normal mode */}) {
1362 SCOPED_TRACE("mode=" + toString(mode));
1363 ASSERT_OK(device->setMode(mode));
1367 TEST_F(BoolAccessorPrimaryHidlTest, BtScoNrecEnabled) {
1368 doc::test("Query and set the BT SCO NR&EC state");
1369 testOptionalAccessors("BtScoNrecEnabled", {true, false, true},
1370 &IPrimaryDevice::setBtScoNrecEnabled,
1371 &IPrimaryDevice::getBtScoNrecEnabled);
1374 TEST_F(BoolAccessorPrimaryHidlTest, setGetBtScoWidebandEnabled) {
1375 doc::test("Query and set the SCO whideband state");
1376 testOptionalAccessors("BtScoWideband", {true, false, true},
1377 &IPrimaryDevice::setBtScoWidebandEnabled,
1378 &IPrimaryDevice::getBtScoWidebandEnabled);
1381 using TtyModeAccessorPrimaryHidlTest = AccessorPrimaryHidlTest<TtyMode>;
1382 TEST_F(TtyModeAccessorPrimaryHidlTest, setGetTtyMode) {
1383 doc::test("Query and set the TTY mode state");
1384 testOptionalAccessors(
1385 "TTY mode", {TtyMode::OFF, TtyMode::HCO, TtyMode::VCO, TtyMode::FULL},
1386 &IPrimaryDevice::setTtyMode, &IPrimaryDevice::getTtyMode);
1389 TEST_F(BoolAccessorPrimaryHidlTest, setGetHac) {
1390 doc::test("Query and set the HAC state");
1391 testOptionalAccessors("HAC", {true, false, true},
1392 &IPrimaryDevice::setHacEnabled,
1393 &IPrimaryDevice::getHacEnabled);
1396 //////////////////////////////////////////////////////////////////////////////
1397 //////////////////// Clean caches on global tear down ////////////////////////
1398 //////////////////////////////////////////////////////////////////////////////
1400 int main(int argc, char** argv) {
1401 environment = new Environment;
1402 ::testing::AddGlobalTestEnvironment(environment);
1403 ::testing::InitGoogleTest(&argc, argv);
1404 int status = RUN_ALL_TESTS();
1405 LOG(INFO) << "Test result = " << status;