blob: e50b91205fa3c72160c4d835698088d742c702d4 [file] [log] [blame]
Kevin Rocardf0357882017-02-10 16:19:28 -08001/*
2 * Copyright (C) 2017 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#define LOG_TAG "VtsHalAudioV2_0TargetTest"
18
19#include <algorithm>
20#include <cmath>
21#include <cstddef>
22#include <cstdio>
23#include <limits>
24#include <list>
25#include <string>
26#include <type_traits>
27#include <vector>
28
Yuexi Ma161b5642017-03-10 13:44:22 -080029#include <VtsHalHidlTargetTestBase.h>
Kevin Rocardf0357882017-02-10 16:19:28 -080030
31#include <android-base/logging.h>
32
33#include <android/hardware/audio/2.0/IDevice.h>
34#include <android/hardware/audio/2.0/IDevicesFactory.h>
Kevin Rocard3c405a72017-03-08 16:46:51 -080035#include <android/hardware/audio/2.0/IPrimaryDevice.h>
Kevin Rocardf0357882017-02-10 16:19:28 -080036#include <android/hardware/audio/2.0/types.h>
37#include <android/hardware/audio/common/2.0/types.h>
38
39#include "utility/ReturnIn.h"
40#include "utility/AssertOk.h"
41#include "utility/PrettyPrintAudioTypes.h"
42
43using std::string;
44using std::to_string;
45using std::vector;
46
47using ::android::sp;
48using ::android::hardware::Return;
49using ::android::hardware::hidl_handle;
50using ::android::hardware::hidl_string;
51using ::android::hardware::hidl_vec;
Kevin Rocardc9963522017-03-10 18:47:37 -080052using ::android::hardware::MQDescriptorSync;
Kevin Rocardf0357882017-02-10 16:19:28 -080053using ::android::hardware::audio::V2_0::DeviceAddress;
54using ::android::hardware::audio::V2_0::IDevice;
Kevin Rocard3c405a72017-03-08 16:46:51 -080055using ::android::hardware::audio::V2_0::IPrimaryDevice;
56using TtyMode = ::android::hardware::audio::V2_0::IPrimaryDevice::TtyMode;
Kevin Rocardf0357882017-02-10 16:19:28 -080057using ::android::hardware::audio::V2_0::IDevicesFactory;
58using ::android::hardware::audio::V2_0::IStream;
59using ::android::hardware::audio::V2_0::IStreamIn;
Kevin Rocardc9963522017-03-10 18:47:37 -080060using ReadParameters = ::android::hardware::audio::V2_0::IStreamIn::ReadParameters;
61using ReadStatus = ::android::hardware::audio::V2_0::IStreamIn::ReadStatus;
Kevin Rocardf0357882017-02-10 16:19:28 -080062using ::android::hardware::audio::V2_0::IStreamOut;
Kevin Rocard8878b4b2017-03-10 18:47:37 -080063using ::android::hardware::audio::V2_0::MmapBufferInfo;
64using ::android::hardware::audio::V2_0::MmapPosition;
Kevin Rocardf0357882017-02-10 16:19:28 -080065using ::android::hardware::audio::V2_0::ParameterValue;
66using ::android::hardware::audio::V2_0::Result;
67using ::android::hardware::audio::common::V2_0::AudioChannelMask;
68using ::android::hardware::audio::common::V2_0::AudioConfig;
69using ::android::hardware::audio::common::V2_0::AudioDevice;
70using ::android::hardware::audio::common::V2_0::AudioFormat;
71using ::android::hardware::audio::common::V2_0::AudioHandleConsts;
72using ::android::hardware::audio::common::V2_0::AudioInputFlag;
73using ::android::hardware::audio::common::V2_0::AudioIoHandle;
Kevin Rocard3c405a72017-03-08 16:46:51 -080074using ::android::hardware::audio::common::V2_0::AudioMode;
Kevin Rocardf0357882017-02-10 16:19:28 -080075using ::android::hardware::audio::common::V2_0::AudioOffloadInfo;
76using ::android::hardware::audio::common::V2_0::AudioOutputFlag;
77using ::android::hardware::audio::common::V2_0::AudioSource;
Kevin Rocardc9963522017-03-10 18:47:37 -080078using ::android::hardware::audio::common::V2_0::ThreadInfo;
Kevin Rocardf0357882017-02-10 16:19:28 -080079
80using utility::returnIn;
81
82namespace doc {
83/** Document the current test case.
84 * Eg: calling `doc::test("Dump the state of the hal")` in the "debugDump" test will output:
85 * <testcase name="debugDump" status="run" time="6" classname="AudioPrimaryHidlTest"
86 description="Dump the state of the hal." />
87 * see https://github.com/google/googletest/blob/master/googletest/docs/AdvancedGuide.md#logging-additional-information
88 */
89void test(const std::string& testCaseDocumentation) {
90 ::testing::Test::RecordProperty("description", testCaseDocumentation);
91}
92
93/** Document why a test was not fully run. Usually due to an optional feature not implemented. */
94void partialTest(const std::string& reason) {
95 ::testing::Test::RecordProperty("partialyRunTest", reason);
96}
97}
98
99// Register callback for static object destruction
100// Avoid destroying static objects after main return.
101// Post main return destruction leads to incorrect gtest timing measurements as well as harder
102// debuging if anything goes wrong during destruction.
103class Environment : public ::testing::Environment {
104public:
105 using TearDownFunc = std::function<void ()>;
106 void registerTearDown(TearDownFunc&& tearDown) {
107 tearDowns.push_back(std::move(tearDown));
108 }
109
110private:
111 void TearDown() override {
112 // Call the tear downs in reverse order of insertion
113 for (auto& tearDown : tearDowns) {
114 tearDown();
115 }
116 }
117 std::list<TearDownFunc> tearDowns;
118};
119// Instance to register global tearDown
120static Environment* environment;
121
Yuexi Ma161b5642017-03-10 13:44:22 -0800122class HidlTest : public ::testing::VtsHalHidlTargetTestBase {
Kevin Rocardf0357882017-02-10 16:19:28 -0800123protected:
124 // Convenient member to store results
125 Result res;
126};
127
128//////////////////////////////////////////////////////////////////////////////
129////////////////////// getService audio_devices_factory //////////////////////
130//////////////////////////////////////////////////////////////////////////////
131
132// Test all audio devices
133class AudioHidlTest : public HidlTest {
134public:
135 void SetUp() override {
136 ASSERT_NO_FATAL_FAILURE(HidlTest::SetUp()); // setup base
137
138 if (devicesFactory == nullptr) {
139 environment->registerTearDown([]{ devicesFactory.clear(); });
Yuexi Ma161b5642017-03-10 13:44:22 -0800140 devicesFactory = ::testing::VtsHalHidlTargetTestBase::getService<IDevicesFactory>();
Kevin Rocardf0357882017-02-10 16:19:28 -0800141 }
142 ASSERT_TRUE(devicesFactory != nullptr);
143 }
144
145protected:
146 // Cache the devicesFactory retrieval to speed up each test by ~0.5s
147 static sp<IDevicesFactory> devicesFactory;
148};
149sp<IDevicesFactory> AudioHidlTest::devicesFactory;
150
151TEST_F(AudioHidlTest, GetAudioDevicesFactoryService) {
152 doc::test("test the getService (called in SetUp)");
153}
154
155//////////////////////////////////////////////////////////////////////////////
156/////////////////////////////// openDevice primary ///////////////////////////
157//////////////////////////////////////////////////////////////////////////////
158
159// Test the primary device
160class AudioPrimaryHidlTest : public AudioHidlTest {
161public:
162 /** Primary HAL test are NOT thread safe. */
163 void SetUp() override {
164 ASSERT_NO_FATAL_FAILURE(AudioHidlTest::SetUp()); // setup base
165
166 if (device == nullptr) {
Kevin Rocardf0357882017-02-10 16:19:28 -0800167 IDevicesFactory::Result result;
Kevin Rocard3c405a72017-03-08 16:46:51 -0800168 sp<IDevice> baseDevice;
Kevin Rocardf0357882017-02-10 16:19:28 -0800169 ASSERT_OK(devicesFactory->openDevice(IDevicesFactory::Device::PRIMARY,
Kevin Rocard3c405a72017-03-08 16:46:51 -0800170 returnIn(result, baseDevice)));
171 ASSERT_TRUE(baseDevice != nullptr);
172
173 environment->registerTearDown([]{ device.clear(); });
174 device = IPrimaryDevice::castFrom(baseDevice);
175 ASSERT_TRUE(device != nullptr);
Kevin Rocardf0357882017-02-10 16:19:28 -0800176 }
Kevin Rocardf0357882017-02-10 16:19:28 -0800177 }
178
179protected:
180 // Cache the device opening to speed up each test by ~0.5s
Kevin Rocard3c405a72017-03-08 16:46:51 -0800181 static sp<IPrimaryDevice> device;
Kevin Rocardf0357882017-02-10 16:19:28 -0800182};
Kevin Rocard3c405a72017-03-08 16:46:51 -0800183sp<IPrimaryDevice> AudioPrimaryHidlTest::device;
Kevin Rocardf0357882017-02-10 16:19:28 -0800184
185TEST_F(AudioPrimaryHidlTest, OpenPrimaryDevice) {
186 doc::test("Test the openDevice (called in SetUp)");
187}
188
189TEST_F(AudioPrimaryHidlTest, Init) {
190 doc::test("Test that the audio primary hal initialized correctly");
191 ASSERT_OK(device->initCheck());
192}
193
194//////////////////////////////////////////////////////////////////////////////
Kevin Rocard92ce35d2017-03-08 17:17:25 -0800195///////////////////// {set,get}{Master,Mic}{Mute,Volume} /////////////////////
Kevin Rocardf0357882017-02-10 16:19:28 -0800196//////////////////////////////////////////////////////////////////////////////
197
Kevin Rocard3c405a72017-03-08 16:46:51 -0800198template <class Property>
199class AccessorPrimaryHidlTest : public AudioPrimaryHidlTest {
Kevin Rocardf0357882017-02-10 16:19:28 -0800200protected:
Kevin Rocard3c405a72017-03-08 16:46:51 -0800201
202 /** Test a property getter and setter. */
Kevin Rocardf0357882017-02-10 16:19:28 -0800203 template <class Getter, class Setter>
Kevin Rocard3c405a72017-03-08 16:46:51 -0800204 void testAccessors(const string& propertyName, const vector<Property>& valuesToTest,
Kevin Rocard92ce35d2017-03-08 17:17:25 -0800205 Setter setter, Getter getter,
206 const vector<Property>& invalidValues = {}) {
Kevin Rocard3c405a72017-03-08 16:46:51 -0800207
208 Property initialValue; // Save initial value to restore it at the end of the test
209 ASSERT_OK((device.get()->*getter)(returnIn(res, initialValue)));
210 ASSERT_OK(res);
211
212 for (Property setValue : valuesToTest) {
Kevin Rocard92ce35d2017-03-08 17:17:25 -0800213 SCOPED_TRACE("Test " + propertyName + " getter and setter for " +
214 testing::PrintToString(setValue));
Kevin Rocard3c405a72017-03-08 16:46:51 -0800215 ASSERT_OK((device.get()->*setter)(setValue));
216 Property getValue;
217 // Make sure the getter returns the same value just set
218 ASSERT_OK((device.get()->*getter)(returnIn(res, getValue)));
Kevin Rocardf0357882017-02-10 16:19:28 -0800219 ASSERT_OK(res);
Kevin Rocard3c405a72017-03-08 16:46:51 -0800220 EXPECT_EQ(setValue, getValue);
Kevin Rocardf0357882017-02-10 16:19:28 -0800221 }
Kevin Rocard3c405a72017-03-08 16:46:51 -0800222
Kevin Rocard92ce35d2017-03-08 17:17:25 -0800223 for (Property invalidValue : invalidValues) {
224 SCOPED_TRACE("Try to set " + propertyName + " with the invalid value " +
225 testing::PrintToString(invalidValue));
Kevin Rocard20e7af62017-03-10 17:10:43 -0800226 EXPECT_RESULT(Result::INVALID_ARGUMENTS, (device.get()->*setter)(invalidValue));
Kevin Rocard92ce35d2017-03-08 17:17:25 -0800227 }
228
Kevin Rocard3c405a72017-03-08 16:46:51 -0800229 ASSERT_OK((device.get()->*setter)(initialValue)); // restore initial value
230 }
231
232 /** Test the getter and setter of an optional feature. */
233 template <class Getter, class Setter>
234 void testOptionalAccessors(const string& propertyName, const vector<Property>& valuesToTest,
Kevin Rocard92ce35d2017-03-08 17:17:25 -0800235 Setter setter, Getter getter,
236 const vector<Property>& invalidValues = {}) {
Kevin Rocard3c405a72017-03-08 16:46:51 -0800237 doc::test("Test the optional " + propertyName + " getters and setter");
238 {
239 SCOPED_TRACE("Test feature support by calling the getter");
240 Property initialValue;
241 ASSERT_OK((device.get()->*getter)(returnIn(res, initialValue)));
242 if (res == Result::NOT_SUPPORTED) {
243 doc::partialTest(propertyName + " getter is not supported");
244 return;
245 }
246 ASSERT_OK(res); // If it is supported it must succeed
247 }
248 // The feature is supported, test it
Kevin Rocard92ce35d2017-03-08 17:17:25 -0800249 testAccessors(propertyName, valuesToTest, setter, getter, invalidValues);
Kevin Rocardf0357882017-02-10 16:19:28 -0800250 }
251};
252
Kevin Rocard3c405a72017-03-08 16:46:51 -0800253using BoolAccessorPrimaryHidlTest = AccessorPrimaryHidlTest<bool>;
254
Kevin Rocardf0357882017-02-10 16:19:28 -0800255TEST_F(BoolAccessorPrimaryHidlTest, MicMuteTest) {
256 doc::test("Check that the mic can be muted and unmuted");
Kevin Rocard3c405a72017-03-08 16:46:51 -0800257 testAccessors("mic mute", {true, false, true}, &IDevice::setMicMute, &IDevice::getMicMute);
Kevin Rocardf0357882017-02-10 16:19:28 -0800258 // TODO: check that the mic is really muted (all sample are 0)
259}
260
261TEST_F(BoolAccessorPrimaryHidlTest, MasterMuteTest) {
262 doc::test("If master mute is supported, try to mute and unmute the master output");
Kevin Rocard3c405a72017-03-08 16:46:51 -0800263 testOptionalAccessors("master mute", {true, false, true},
264 &IDevice::setMasterMute, &IDevice::getMasterMute);
Kevin Rocardf0357882017-02-10 16:19:28 -0800265 // TODO: check that the master volume is really muted
266}
267
Kevin Rocard92ce35d2017-03-08 17:17:25 -0800268using FloatAccessorPrimaryHidlTest = AccessorPrimaryHidlTest<float>;
269TEST_F(FloatAccessorPrimaryHidlTest, MasterVolumeTest) {
270 doc::test("Test the master volume if supported");
271 testOptionalAccessors("master volume", {0, 0.5, 1},
272 &IDevice::setMasterVolume, &IDevice::getMasterVolume,
273 {-0.1, 1.1, NAN, INFINITY, -INFINITY,
274 1 + std::numeric_limits<float>::epsilon()});
275 // TODO: check that the master volume is really changed
276}
277
Kevin Rocardf0357882017-02-10 16:19:28 -0800278//////////////////////////////////////////////////////////////////////////////
Kevin Rocard8878b4b2017-03-10 18:47:37 -0800279//////////////////////////////// AudioPatches ////////////////////////////////
280//////////////////////////////////////////////////////////////////////////////
281
282class AudioPatchPrimaryHidlTest : public AudioPrimaryHidlTest {
283protected:
284 bool areAudioPatchesSupported() {
285 auto result = device->supportsAudioPatches();
286 EXPECT_TRUE(result.isOk());
287 return result;
288 }
289};
290
291TEST_F(AudioPatchPrimaryHidlTest, AudioPatches) {
292 doc::test("Test if audio patches are supported");
293 if (!areAudioPatchesSupported()) {
294 doc::partialTest("Audio patches are not supported");
295 return;
296 }
297 // TODO: test audio patches
298}
299
300
301//////////////////////////////////////////////////////////////////////////////
Kevin Rocardf0357882017-02-10 16:19:28 -0800302//////////////// Required and recommended audio format support ///////////////
303// From: https://source.android.com/compatibility/android-cdd.html#5_4_audio_recording
304// From: https://source.android.com/compatibility/android-cdd.html#5_5_audio_playback
305/////////// TODO: move to the beginning of the file for easier update ////////
306//////////////////////////////////////////////////////////////////////////////
307
Kevin Rocard8878b4b2017-03-10 18:47:37 -0800308class AudioConfigPrimaryTest : public AudioPatchPrimaryHidlTest {
Kevin Rocardf0357882017-02-10 16:19:28 -0800309public:
310 // Cache result ?
311 static const vector<AudioConfig> getRequiredSupportPlaybackAudioConfig() {
312 return combineAudioConfig({AudioChannelMask::OUT_STEREO, AudioChannelMask::OUT_MONO},
313 {8000, 11025, 16000, 22050, 32000, 44100},
314 {AudioFormat::PCM_16_BIT});
315 }
316
317 static const vector<AudioConfig> getRecommendedSupportPlaybackAudioConfig() {
318 return combineAudioConfig({AudioChannelMask::OUT_STEREO, AudioChannelMask::OUT_MONO},
319 {24000, 48000},
320 {AudioFormat::PCM_16_BIT});
321 }
322
323 static const vector<AudioConfig> getSupportedPlaybackAudioConfig() {
324 // TODO: retrieve audio config supported by the platform
325 // as declared in the policy configuration
326 return {};
327 }
328
329 static const vector<AudioConfig> getRequiredSupportCaptureAudioConfig() {
330 return combineAudioConfig({AudioChannelMask::IN_MONO},
331 {8000, 11025, 16000, 44100},
332 {AudioFormat::PCM_16_BIT});
333 }
334 static const vector<AudioConfig> getRecommendedSupportCaptureAudioConfig() {
335 return combineAudioConfig({AudioChannelMask::IN_STEREO},
336 {22050, 48000},
337 {AudioFormat::PCM_16_BIT});
338 }
339 static const vector<AudioConfig> getSupportedCaptureAudioConfig() {
340 // TODO: retrieve audio config supported by the platform
341 // as declared in the policy configuration
342 return {};
343 }
344private:
345 static const vector<AudioConfig> combineAudioConfig(
346 vector<AudioChannelMask> channelMasks,
347 vector<uint32_t> sampleRates,
348 vector<AudioFormat> formats) {
349 vector<AudioConfig> configs;
350 for (auto channelMask: channelMasks) {
351 for (auto sampleRate : sampleRates) {
352 for (auto format : formats) {
353 AudioConfig config{};
354 // leave offloadInfo to 0
355 config.channelMask = channelMask;
356 config.sampleRateHz = sampleRate;
357 config.format = format;
358 // FIXME: leave frameCount to 0 ?
359 configs.push_back(config);
360 }
361 }
362 }
363 return configs;
364 }
365};
366
Kevin Rocard9c369142017-03-08 17:17:25 -0800367/** Generate a test name based on an audio config.
368 *
369 * As the only parameter changing are channel mask and sample rate,
370 * only print those ones in the test name.
371 */
372static string generateTestName(const testing::TestParamInfo<AudioConfig>& info) {
373 const AudioConfig& config = info.param;
374 return to_string(info.index) + "__" + to_string(config.sampleRateHz)+ "_" +
375 // "MONO" is more clear than "FRONT_LEFT"
376 ((config.channelMask == AudioChannelMask::OUT_MONO ||
377 config.channelMask == AudioChannelMask::IN_MONO) ?
378 "MONO" : toString(config.channelMask));
379}
380
Kevin Rocardf0357882017-02-10 16:19:28 -0800381//////////////////////////////////////////////////////////////////////////////
382///////////////////////////// getInputBufferSize /////////////////////////////
383//////////////////////////////////////////////////////////////////////////////
384
385// FIXME: execute input test only if platform declares android.hardware.microphone
386// how to get this value ? is it a property ???
387
388class AudioCaptureConfigPrimaryTest : public AudioConfigPrimaryTest,
389 public ::testing::WithParamInterface<AudioConfig> {
390protected:
391 void inputBufferSizeTest(const AudioConfig& audioConfig, bool supportRequired) {
392 uint64_t bufferSize;
393 ASSERT_OK(device->getInputBufferSize(audioConfig, returnIn(res, bufferSize)));
394
395 switch (res) {
396 case Result::INVALID_ARGUMENTS:
397 EXPECT_FALSE(supportRequired);
398 break;
399 case Result::OK:
400 // Check that the buffer is of a sane size
401 // For now only that it is > 0
402 EXPECT_GT(bufferSize, uint64_t(0));
403 break;
404 default:
405 FAIL() << "Invalid return status: " << ::testing::PrintToString(res);
406 }
407 }
408};
409
410// Test that the required capture config and those declared in the policy are indeed supported
411class RequiredInputBufferSizeTest : public AudioCaptureConfigPrimaryTest {};
412TEST_P(RequiredInputBufferSizeTest, RequiredInputBufferSizeTest) {
413 doc::test("Input buffer size must be retrievable for a format with required support.");
414 inputBufferSizeTest(GetParam(), true);
415}
416INSTANTIATE_TEST_CASE_P(
417 RequiredInputBufferSize, RequiredInputBufferSizeTest,
Kevin Rocard9c369142017-03-08 17:17:25 -0800418 ::testing::ValuesIn(AudioConfigPrimaryTest::getRequiredSupportCaptureAudioConfig()),
419 &generateTestName);
Kevin Rocardf0357882017-02-10 16:19:28 -0800420INSTANTIATE_TEST_CASE_P(
421 SupportedInputBufferSize, RequiredInputBufferSizeTest,
Kevin Rocard9c369142017-03-08 17:17:25 -0800422 ::testing::ValuesIn(AudioConfigPrimaryTest::getSupportedCaptureAudioConfig()),
423 &generateTestName);
Kevin Rocardf0357882017-02-10 16:19:28 -0800424
425// Test that the recommended capture config are supported or lead to a INVALID_ARGUMENTS return
426class OptionalInputBufferSizeTest : public AudioCaptureConfigPrimaryTest {};
427TEST_P(OptionalInputBufferSizeTest, OptionalInputBufferSizeTest) {
428 doc::test("Input buffer size should be retrievable for a format with recommended support.");
429 inputBufferSizeTest(GetParam(), false);
430}
431INSTANTIATE_TEST_CASE_P(
432 RecommendedCaptureAudioConfigSupport, OptionalInputBufferSizeTest,
Kevin Rocard9c369142017-03-08 17:17:25 -0800433 ::testing::ValuesIn(AudioConfigPrimaryTest::getRecommendedSupportCaptureAudioConfig()),
434 &generateTestName);
Kevin Rocardf0357882017-02-10 16:19:28 -0800435
436//////////////////////////////////////////////////////////////////////////////
437/////////////////////////////// setScreenState ///////////////////////////////
438//////////////////////////////////////////////////////////////////////////////
439
440TEST_F(AudioPrimaryHidlTest, setScreenState) {
441 doc::test("Check that the hal can receive the screen state");
442 for (bool turnedOn : {false, true, true, false, false}) {
443 auto ret = device->setScreenState(turnedOn);
444 ASSERT_TRUE(ret.isOk());
445 Result result = ret;
446 ASSERT_TRUE(result == Result::OK || result == Result::NOT_SUPPORTED) << toString(result);
447 }
448}
449
450//////////////////////////////////////////////////////////////////////////////
451//////////////////////////// {get,set}Parameters /////////////////////////////
452//////////////////////////////////////////////////////////////////////////////
453
454TEST_F(AudioPrimaryHidlTest, getParameters) {
455 doc::test("Check that the hal can set and get parameters");
456 hidl_vec<hidl_string> keys;
457 hidl_vec<ParameterValue> values;
458 ASSERT_OK(device->getParameters(keys, returnIn(res, values)));
459 ASSERT_OK(device->setParameters(values));
460 values.resize(0);
461 ASSERT_OK(device->setParameters(values));
462}
463
464//////////////////////////////////////////////////////////////////////////////
465//////////////////////////////// debugDebug //////////////////////////////////
466//////////////////////////////////////////////////////////////////////////////
467
Kevin Rocardb9031242017-03-13 12:20:54 -0700468template <class DebugDump>
469static void testDebugDump(DebugDump debugDump) {
Kevin Rocardf0357882017-02-10 16:19:28 -0800470 FILE* file = tmpfile();
471 ASSERT_NE(nullptr, file) << errno;
472
473 auto* nativeHandle = native_handle_create(1, 0);
474 ASSERT_NE(nullptr, nativeHandle);
475 nativeHandle->data[0] = fileno(file);
476
477 hidl_handle handle;
478 handle.setTo(nativeHandle, true /*take ownership*/);
479
Kevin Rocardee771e92017-03-08 17:17:25 -0800480 // TODO: debugDump does not return a Result.
Kevin Rocardf0357882017-02-10 16:19:28 -0800481 // This mean that the hal can not report that it not implementing the function.
Kevin Rocardb9031242017-03-13 12:20:54 -0700482 ASSERT_OK(debugDump(handle));
Kevin Rocardee771e92017-03-08 17:17:25 -0800483
484 rewind(file); // can not fail
Kevin Rocardf0357882017-02-10 16:19:28 -0800485
486 // Check that at least one bit was written by the hal
487 char buff;
Kevin Rocardee771e92017-03-08 17:17:25 -0800488 ASSERT_EQ(size_t{1}, fread(&buff, sizeof(buff), 1, file));
Kevin Rocardf0357882017-02-10 16:19:28 -0800489 EXPECT_EQ(0, fclose(file)) << errno;
490}
491
Kevin Rocardb9031242017-03-13 12:20:54 -0700492TEST_F(AudioPrimaryHidlTest, debugDump) {
493 doc::test("Check that the hal can dump its state without error");
494 testDebugDump([this](const auto& handle){ return device->debugDump(handle); });
495}
496
Kevin Rocardf0357882017-02-10 16:19:28 -0800497//////////////////////////////////////////////////////////////////////////////
498////////////////////////// open{Output,Input}Stream //////////////////////////
499//////////////////////////////////////////////////////////////////////////////
500
501template <class Stream>
502class OpenStreamTest : public AudioConfigPrimaryTest,
503 public ::testing::WithParamInterface<AudioConfig> {
504protected:
505 template <class Open>
506 void testOpen(Open openStream, const AudioConfig& config) {
507 // FIXME: Open a stream without an IOHandle
508 // This is not required to be accepted by hal implementations
509 AudioIoHandle ioHandle = (AudioIoHandle)AudioHandleConsts::AUDIO_IO_HANDLE_NONE;
510 AudioConfig suggestedConfig{};
511 ASSERT_OK(openStream(ioHandle, config, returnIn(res, stream, suggestedConfig)));
512
513 // TODO: only allow failure for RecommendedPlaybackAudioConfig
514 switch (res) {
515 case Result::OK:
516 ASSERT_TRUE(stream != nullptr);
517 audioConfig = config;
518 break;
519 case Result::INVALID_ARGUMENTS:
520 ASSERT_TRUE(stream == nullptr);
521 AudioConfig suggestedConfigRetry;
522 // Could not open stream with config, try again with the suggested one
523 ASSERT_OK(openStream(ioHandle, suggestedConfig,
524 returnIn(res, stream, suggestedConfigRetry)));
525 // This time it must succeed
526 ASSERT_OK(res);
527 ASSERT_TRUE(stream == nullptr);
528 audioConfig = suggestedConfig;
529 break;
530 default:
531 FAIL() << "Invalid return status: " << ::testing::PrintToString(res);
532 }
533 open = true;
534 }
535
Kevin Rocard8878b4b2017-03-10 18:47:37 -0800536 Return<Result> closeStream() {
537 open = false;
538 return stream->close();
539 }
Kevin Rocardf0357882017-02-10 16:19:28 -0800540private:
541 void TearDown() override {
542 if (open) {
543 ASSERT_OK(stream->close());
544 }
545 }
546
547protected:
548
549 AudioConfig audioConfig;
Kevin Rocard8878b4b2017-03-10 18:47:37 -0800550 DeviceAddress address = {};
Kevin Rocardf0357882017-02-10 16:19:28 -0800551 sp<Stream> stream;
552 bool open = false;
553};
554
555////////////////////////////// openOutputStream //////////////////////////////
556
557class OutputStreamTest : public OpenStreamTest<IStreamOut> {
558 virtual void SetUp() override {
559 ASSERT_NO_FATAL_FAILURE(OpenStreamTest::SetUp()); // setup base
Kevin Rocard8878b4b2017-03-10 18:47:37 -0800560 address.device = AudioDevice::OUT_DEFAULT;
Kevin Rocardf0357882017-02-10 16:19:28 -0800561 const AudioConfig& config = GetParam();
Kevin Rocardf0357882017-02-10 16:19:28 -0800562 AudioOutputFlag flags = AudioOutputFlag::NONE; // TODO: test all flag combination
563 testOpen([&](AudioIoHandle handle, AudioConfig config, auto cb)
Kevin Rocard8878b4b2017-03-10 18:47:37 -0800564 { return device->openOutputStream(handle, address, config, flags, cb); },
Kevin Rocardf0357882017-02-10 16:19:28 -0800565 config);
566 }
567};
568TEST_P(OutputStreamTest, OpenOutputStreamTest) {
569 doc::test("Check that output streams can be open with the required and recommended config");
570 // Open done in SetUp
571}
572INSTANTIATE_TEST_CASE_P(
573 RequiredOutputStreamConfigSupport, OutputStreamTest,
Kevin Rocard9c369142017-03-08 17:17:25 -0800574 ::testing::ValuesIn(AudioConfigPrimaryTest::getRequiredSupportPlaybackAudioConfig()),
575 &generateTestName);
Kevin Rocardf0357882017-02-10 16:19:28 -0800576INSTANTIATE_TEST_CASE_P(
577 SupportedOutputStreamConfig, OutputStreamTest,
Kevin Rocard9c369142017-03-08 17:17:25 -0800578 ::testing::ValuesIn(AudioConfigPrimaryTest::getSupportedPlaybackAudioConfig()),
579 &generateTestName);
Kevin Rocardf0357882017-02-10 16:19:28 -0800580
581INSTANTIATE_TEST_CASE_P(
582 RecommendedOutputStreamConfigSupport, OutputStreamTest,
Kevin Rocard9c369142017-03-08 17:17:25 -0800583 ::testing::ValuesIn(AudioConfigPrimaryTest::getRecommendedSupportPlaybackAudioConfig()),
584 &generateTestName);
Kevin Rocardf0357882017-02-10 16:19:28 -0800585
586////////////////////////////// openInputStream //////////////////////////////
587
588class InputStreamTest : public OpenStreamTest<IStreamIn> {
589
590 virtual void SetUp() override {
591 ASSERT_NO_FATAL_FAILURE(OpenStreamTest::SetUp()); // setup base
Kevin Rocard8878b4b2017-03-10 18:47:37 -0800592 address.device = AudioDevice::IN_DEFAULT;
Kevin Rocardf0357882017-02-10 16:19:28 -0800593 const AudioConfig& config = GetParam();
Kevin Rocardf0357882017-02-10 16:19:28 -0800594 AudioInputFlag flags = AudioInputFlag::NONE; // TODO: test all flag combination
595 AudioSource source = AudioSource::DEFAULT; // TODO: test all flag combination
596 testOpen([&](AudioIoHandle handle, AudioConfig config, auto cb)
Kevin Rocard8878b4b2017-03-10 18:47:37 -0800597 { return device->openInputStream(handle, address, config, flags, source, cb); },
Kevin Rocardf0357882017-02-10 16:19:28 -0800598 config);
599 }
600};
601
602TEST_P(InputStreamTest, OpenInputStreamTest) {
603 doc::test("Check that input streams can be open with the required and recommended config");
604 // Open done in setup
605}
606INSTANTIATE_TEST_CASE_P(
607 RequiredInputStreamConfigSupport, InputStreamTest,
Kevin Rocard9c369142017-03-08 17:17:25 -0800608 ::testing::ValuesIn(AudioConfigPrimaryTest::getRequiredSupportCaptureAudioConfig()),
609 &generateTestName);
Kevin Rocardf0357882017-02-10 16:19:28 -0800610INSTANTIATE_TEST_CASE_P(
611 SupportedInputStreamConfig, InputStreamTest,
Kevin Rocard9c369142017-03-08 17:17:25 -0800612 ::testing::ValuesIn(AudioConfigPrimaryTest::getSupportedCaptureAudioConfig()),
613 &generateTestName);
Kevin Rocardf0357882017-02-10 16:19:28 -0800614
615INSTANTIATE_TEST_CASE_P(
616 RecommendedInputStreamConfigSupport, InputStreamTest,
Kevin Rocard9c369142017-03-08 17:17:25 -0800617 ::testing::ValuesIn(AudioConfigPrimaryTest::getRecommendedSupportCaptureAudioConfig()),
618 &generateTestName);
Kevin Rocardf0357882017-02-10 16:19:28 -0800619
620//////////////////////////////////////////////////////////////////////////////
621////////////////////////////// IStream getters ///////////////////////////////
622//////////////////////////////////////////////////////////////////////////////
623
624/** Unpack the provided result.
625 * If the result is not OK, register a failure and return an undefined value. */
626template <class R>
627static R extract(Return<R> ret) {
628 if (!ret.isOk()) {
629 ADD_FAILURE();
630 return R{};
631 }
632 return ret;
633}
634
Kevin Rocarda7df7fc2017-03-10 18:37:46 -0800635/* Could not find a way to write a test for two parametrized class fixure
636 * thus use this macro do duplicate tests for Input and Output stream */
637#define TEST_IO_STREAM(test_name, documentation, code) \
638 TEST_P(InputStreamTest, test_name) { \
639 doc::test(documentation); \
640 code; \
641 } \
642 TEST_P(OutputStreamTest, test_name) { \
643 doc::test(documentation); \
644 code; \
645 }
646
647TEST_IO_STREAM(GetFrameCount, "Check that the stream frame count == the one it was opened with",
648 ASSERT_EQ(audioConfig.frameCount, extract(stream->getFrameCount())))
649
650TEST_IO_STREAM(GetSampleRate, "Check that the stream sample rate == the one it was opened with",
651 ASSERT_EQ(audioConfig.sampleRateHz, extract(stream->getSampleRate())))
652
653TEST_IO_STREAM(GetChannelMask, "Check that the stream channel mask == the one it was opened with",
654 ASSERT_EQ(audioConfig.channelMask, extract(stream->getChannelMask())))
655
656TEST_IO_STREAM(GetFormat, "Check that the stream format == the one it was opened with",
657 ASSERT_EQ(audioConfig.format, extract(stream->getFormat())))
658
659// TODO: for now only check that the framesize is not incoherent
660TEST_IO_STREAM(GetFrameSize, "Check that the stream frame size == the one it was opened with",
661 ASSERT_GT(extract(stream->getFrameSize()), 0U))
662
663TEST_IO_STREAM(GetBufferSize, "Check that the stream buffer size== the one it was opened with",
664 ASSERT_GE(extract(stream->getBufferSize()), \
665 extract(stream->getFrameSize())));
666
Kevin Rocardf0357882017-02-10 16:19:28 -0800667template <class Property, class CapabilityGetter, class Getter, class Setter>
Kevin Rocarda7df7fc2017-03-10 18:37:46 -0800668static void testCapabilityGetter(const string& name, IStream* stream, Property currentValue,
Kevin Rocardf0357882017-02-10 16:19:28 -0800669 CapabilityGetter capablityGetter, Getter getter, Setter setter) {
670 hidl_vec<Property> capabilities;
671 ASSERT_OK((stream->*capablityGetter)(returnIn(capabilities)));
672 if (capabilities.size() == 0) {
673 // The default hal should probably return a NOT_SUPPORTED if the hal does not expose
674 // capability retrieval. For now it returns an empty list if not implemented
675 doc::partialTest(name + " is not supported");
676 return;
677 };
678 // TODO: This code has never been tested on a hal that supports getSupportedSampleRates
679 EXPECT_NE(std::find(capabilities.begin(), capabilities.end(), currentValue),
680 capabilities.end())
681 << "current " << name << " is not in the list of the supported ones "
682 << toString(capabilities);
683
684 // Check that all declared supported values are indeed supported
685 for (auto capability : capabilities) {
686 ASSERT_OK((stream->*setter)(capability));
687 ASSERT_EQ(capability, extract((stream->*getter)()));
688 }
689}
690
Kevin Rocarda7df7fc2017-03-10 18:37:46 -0800691TEST_IO_STREAM(SupportedSampleRate, "Check that the stream sample rate is declared as supported",
692 testCapabilityGetter("getSupportedSampleRate", stream.get(), \
693 extract(stream->getSampleRate()), \
694 &IStream::getSupportedSampleRates, \
695 &IStream::getSampleRate, &IStream::setSampleRate))
696
697TEST_IO_STREAM(SupportedChannelMask, "Check that the stream channel mask is declared as supported",
698 testCapabilityGetter("getSupportedChannelMask", stream.get(), \
699 extract(stream->getChannelMask()), \
700 &IStream::getSupportedChannelMasks, \
701 &IStream::getChannelMask, &IStream::setChannelMask))
702
703TEST_IO_STREAM(SupportedFormat, "Check that the stream format is declared as supported",
704 testCapabilityGetter("getSupportedFormat", stream.get(), \
705 extract(stream->getFormat()), \
706 &IStream::getSupportedFormats, \
707 &IStream::getFormat, &IStream::setFormat))
708
Kevin Rocard8878b4b2017-03-10 18:47:37 -0800709static void testGetDevice(IStream* stream, AudioDevice expectedDevice) {
710 auto ret = stream->getDevice();
711 ASSERT_TRUE(ret.isOk());
712 AudioDevice device = ret;
713 ASSERT_EQ(expectedDevice, device);
714}
715
716TEST_IO_STREAM(GetDevice, "Check that the stream device == the one it was opened with",
717 areAudioPatchesSupported() ? doc::partialTest("Audio patches are supported") : \
718 testGetDevice(stream.get(), address.device))
719
720static void testSetDevice(IStream* stream, const DeviceAddress& address) {
721 DeviceAddress otherAddress = address;
722 otherAddress.device = (address.device & AudioDevice::BIT_IN) == 0 ?
723 AudioDevice::OUT_SPEAKER : AudioDevice::IN_BUILTIN_MIC;
724 EXPECT_OK(stream->setDevice(otherAddress));
725
726 ASSERT_OK(stream->setDevice(address)); // Go back to the original value
727}
728
729TEST_IO_STREAM(SetDevice, "Check that the stream can be rerouted to SPEAKER or BUILTIN_MIC",
730 areAudioPatchesSupported() ? doc::partialTest("Audio patches are supported") : \
731 testSetDevice(stream.get(), address))
732
Kevin Rocardf0357882017-02-10 16:19:28 -0800733static void testGetAudioProperties(IStream* stream, AudioConfig expectedConfig) {
734 uint32_t sampleRateHz;
735 AudioChannelMask mask;
736 AudioFormat format;
737
738 stream->getAudioProperties(returnIn(sampleRateHz, mask, format));
739
740 // FIXME: the qcom hal it does not currently negotiate the sampleRate & channel mask
Kevin Rocardd1e98ae2017-03-08 17:17:25 -0800741 EXPECT_EQ(expectedConfig.sampleRateHz, sampleRateHz);
742 EXPECT_EQ(expectedConfig.channelMask, mask);
Kevin Rocardf0357882017-02-10 16:19:28 -0800743 EXPECT_EQ(expectedConfig.format, format);
744}
745
Kevin Rocarda7df7fc2017-03-10 18:37:46 -0800746TEST_IO_STREAM(GetAudioProperties,
747 "Check that the stream audio properties == the ones it was opened with",
748 testGetAudioProperties(stream.get(), audioConfig))
Kevin Rocardf0357882017-02-10 16:19:28 -0800749
Kevin Rocard8878b4b2017-03-10 18:47:37 -0800750static void testConnectedState(IStream* stream) {
751 DeviceAddress address = {};
752 using AD = AudioDevice;
753 for (auto device : {AD::OUT_HDMI, AD::OUT_WIRED_HEADPHONE, AD::IN_USB_HEADSET}) {
754 address.device = device;
755
756 ASSERT_OK(stream->setConnectedState(address, true));
757 ASSERT_OK(stream->setConnectedState(address, false));
758 }
759}
760TEST_IO_STREAM(SetConnectedState,
761 "Check that the stream can be notified of device connection and deconnection",
762 testConnectedState(stream.get()))
763
764
765static auto invalidArgsOrNotSupported = {Result::INVALID_ARGUMENTS, Result::NOT_SUPPORTED};
766TEST_IO_STREAM(SetHwAvSync, "Try to set hardware sync to an invalid value",
767 ASSERT_RESULT(invalidArgsOrNotSupported, stream->setHwAvSync(666)))
768
769static void checkGetParameter(IStream* stream, hidl_vec<hidl_string> keys,
770 vector<Result> expectedResults) {
771 hidl_vec<ParameterValue> parameters;
772 Result res;
773 ASSERT_OK(stream->getParameters(keys, returnIn(res, parameters)));
774 ASSERT_RESULT(expectedResults, res);
775 if (res == Result::OK) {
776 ASSERT_EQ(0U, parameters.size());
777 }
778}
779
780/* Get/Set parameter is intended to be an opaque channel between vendors app and their HALs.
781 * Thus can not be meaningfully tested.
782 * TODO: Doc missing. Should asking for an empty set of params raise an error ?
783 */
784TEST_IO_STREAM(getEmptySetParameter, "Retrieve the values of an empty set",
785 checkGetParameter(stream.get(), {} /* keys */,
786 {Result::OK, Result::INVALID_ARGUMENTS}))
787
788
789TEST_IO_STREAM(getNonExistingParameter, "Retrieve the values of an non existing parameter",
790 checkGetParameter(stream.get(), {"Non existing key"} /* keys */,
791 {Result::INVALID_ARGUMENTS}))
792
793static vector<Result> okOrNotSupported = {Result::OK, Result::INVALID_ARGUMENTS};
794TEST_IO_STREAM(setEmptySetParameter, "Set the values of an empty set of parameters",
795 ASSERT_RESULT(okOrNotSupported, stream->setParameters({})))
796
797TEST_IO_STREAM(setNonExistingParameter, "Set the values of an non existing parameter",
798 ASSERT_RESULT(Result::INVALID_ARGUMENTS,
799 stream->setParameters({{"non existing key", "0"}})))
800
Kevin Rocardb9031242017-03-13 12:20:54 -0700801TEST_IO_STREAM(DebugDump,
802 "Check that a stream can dump its state without error",
803 testDebugDump([this](const auto& handle){ return stream->debugDump(handle); }))
804
Kevin Rocardf0357882017-02-10 16:19:28 -0800805//////////////////////////////////////////////////////////////////////////////
Kevin Rocard8878b4b2017-03-10 18:47:37 -0800806////////////////////////////// addRemoveEffect ///////////////////////////////
Kevin Rocardf0357882017-02-10 16:19:28 -0800807//////////////////////////////////////////////////////////////////////////////
808
Kevin Rocard8878b4b2017-03-10 18:47:37 -0800809TEST_IO_STREAM(AddNonExistingEffect, "Adding a non existing effect should fail",
810 ASSERT_RESULT(Result::INVALID_ARGUMENTS, stream->addEffect(666)))
811TEST_IO_STREAM(RemoveNonExistingEffect, "Removing a non existing effect should fail",
812 ASSERT_RESULT(Result::INVALID_ARGUMENTS, stream->removeEffect(666)))
Kevin Rocardf0357882017-02-10 16:19:28 -0800813
Kevin Rocard8878b4b2017-03-10 18:47:37 -0800814//TODO: positive tests
815
816//////////////////////////////////////////////////////////////////////////////
817/////////////////////////////// Control ////////////////////////////////
818//////////////////////////////////////////////////////////////////////////////
819
820TEST_IO_STREAM(standby, "Make sure the stream can be put in stanby",
821 ASSERT_OK(stream->standby())) // can not fail
822
823static vector<Result> invalidStateOrNotSupported = {Result::INVALID_STATE, Result::NOT_SUPPORTED};
824
825TEST_IO_STREAM(startNoMmap, "Starting a mmaped stream before mapping it should fail",
826 ASSERT_RESULT(invalidStateOrNotSupported, stream->start()))
827
828TEST_IO_STREAM(stopNoMmap, "Stopping a mmaped stream before mapping it should fail",
829 ASSERT_RESULT(invalidStateOrNotSupported, stream->stop()))
830
831TEST_IO_STREAM(getMmapPositionNoMmap, "Get a stream Mmap position before mapping it should fail",
832 ASSERT_RESULT(invalidStateOrNotSupported, stream->stop()))
833
834TEST_IO_STREAM(close, "Make sure a stream can be closed", ASSERT_OK(closeStream()))
835TEST_IO_STREAM(closeTwice, "Make sure a stream can not be closed twice",
836 ASSERT_OK(closeStream()); \
837 ASSERT_RESULT(Result::INVALID_STATE, closeStream()))
838
839static void testCreateTooBigMmapBuffer(IStream* stream) {
840 MmapBufferInfo info;
841 Result res;
842 // Assume that int max is a value too big to be allocated
843 // This is true currently with a 32bit media server, but might not when it will run in 64 bit
844 auto minSizeFrames = std::numeric_limits<int32_t>::max();
845 ASSERT_OK(stream->createMmapBuffer(minSizeFrames, returnIn(res, info)));
846 ASSERT_RESULT(invalidArgsOrNotSupported, res);
Kevin Rocardf0357882017-02-10 16:19:28 -0800847}
848
Kevin Rocard8878b4b2017-03-10 18:47:37 -0800849TEST_IO_STREAM(CreateTooBigMmapBuffer, "Create mmap buffer too big should fail",
850 testCreateTooBigMmapBuffer(stream.get()))
851
852
853static void testGetMmapPositionOfNonMmapedStream(IStream* stream) {
854 Result res;
855 MmapPosition position;
856 ASSERT_OK(stream->getMmapPosition(returnIn(res, position)));
857 ASSERT_RESULT(invalidArgsOrNotSupported, res);
858}
859
860TEST_IO_STREAM(GetMmapPositionOfNonMmapedStream,
861 "Retrieving the mmap position of a non mmaped stream should fail",
862 testGetMmapPositionOfNonMmapedStream(stream.get()))
863
Kevin Rocardf0357882017-02-10 16:19:28 -0800864//////////////////////////////////////////////////////////////////////////////
Kevin Rocardc9963522017-03-10 18:47:37 -0800865///////////////////////////////// StreamIn ///////////////////////////////////
866//////////////////////////////////////////////////////////////////////////////
867
868TEST_P(InputStreamTest, GetAudioSource) {
869 doc::test("Retrieving the audio source of an input stream should always succeed");
870 AudioSource source;
871 ASSERT_OK(stream->getAudioSource(returnIn(res, source)));
872 ASSERT_OK(res);
873 ASSERT_EQ(AudioSource::DEFAULT, source);
874}
875
876static void testUnitaryGain(std::function<Return<Result> (float)> setGain) {
877 for (float value : {0.0, 0.01, 0.5, 0.09, 1.0}) {
878 SCOPED_TRACE("value=" + to_string(value));
879 ASSERT_OK(setGain(value));
880 }
881 for (float value : (float[]){-INFINITY,-1.0, -0.0,
882 1.0 + std::numeric_limits<float>::epsilon(), 2.0, INFINITY,
883 NAN}) {
884 SCOPED_TRACE("value=" + to_string(value));
885 // FIXME: NAN should never be accepted
886 // FIXME: Missing api doc. What should the impl do if the volume is outside [0,1] ?
887 ASSERT_RESULT(Result::INVALID_ARGUMENTS, setGain(value));
888 }
889}
890
891TEST_P(InputStreamTest, SetGain) {
892 doc::test("The gain of an input stream should only be set between [0,1]");
893 testUnitaryGain([this](float volume) { return stream->setGain(volume); });
894}
895
896static void testPrepareForReading(IStreamIn* stream, uint32_t frameSize, uint32_t framesCount) {
897 Result res;
898 // Ignore output parameters as the call should fail
899 ASSERT_OK(stream->prepareForReading(frameSize, framesCount,
900 [&res](auto r, auto&, auto&, auto&, auto&) { res = r; }));
901 EXPECT_RESULT(invalidArgsOrNotSupported, res);
902}
903
904TEST_P(InputStreamTest, PrepareForReadingWithHugeBuffer) {
905 doc::test("Preparing a stream for reading with a 2^32 sized buffer should fail");
906 testPrepareForReading(stream.get(), 1, std::numeric_limits<uint32_t>::max());
907}
908
909TEST_P(InputStreamTest, PrepareForReadingCheckOverflow) {
910 doc::test("Preparing a stream for reading with a overflowing sized buffer should fail");
911 auto uintMax = std::numeric_limits<uint32_t>::max();
912 testPrepareForReading(stream.get(), uintMax, uintMax);
913}
914
915TEST_P(InputStreamTest, getCapturePosition) {
916 doc::test("The capture position of a non prepared stream should not be retrievable");
917 uint64_t frames;
918 uint64_t time;
919 ASSERT_OK(stream->getCapturePosition(returnIn(res, frames, time)));
920 ASSERT_RESULT(invalidStateOrNotSupported, res);
921}
922
923//////////////////////////////////////////////////////////////////////////////
Kevin Rocard3c405a72017-03-08 16:46:51 -0800924/////////////////////////////// PrimaryDevice ////////////////////////////////
925//////////////////////////////////////////////////////////////////////////////
926
Kevin Rocardc9963522017-03-10 18:47:37 -0800927
Kevin Rocard3c405a72017-03-08 16:46:51 -0800928TEST_F(AudioPrimaryHidlTest, setVoiceVolume) {
929 doc::test("Make sure setVoiceVolume only succeed if volume is in [0,1]");
Kevin Rocardc9963522017-03-10 18:47:37 -0800930 testUnitaryGain([this](float volume) { return device->setVoiceVolume(volume); });
Kevin Rocard3c405a72017-03-08 16:46:51 -0800931}
932
933TEST_F(AudioPrimaryHidlTest, setMode) {
934 doc::test("Make sure setMode always succeeds if mode is valid");
935 for (AudioMode mode : {AudioMode::IN_CALL, AudioMode::IN_COMMUNICATION,
936 AudioMode::RINGTONE, AudioMode::CURRENT,
937 AudioMode::NORMAL /* Make sure to leave the test in normal mode */ }) {
938 SCOPED_TRACE("mode=" + toString(mode));
939 ASSERT_OK(device->setMode(mode));
940 }
941
942 // FIXME: Missing api doc. What should the impl do if the mode is invalid ?
Kevin Rocard20e7af62017-03-10 17:10:43 -0800943 ASSERT_RESULT(Result::INVALID_ARGUMENTS, device->setMode(AudioMode::INVALID));
Kevin Rocard3c405a72017-03-08 16:46:51 -0800944}
945
946
947TEST_F(BoolAccessorPrimaryHidlTest, BtScoNrecEnabled) {
948 doc::test("Query and set the BT SCO NR&EC state");
949 testOptionalAccessors("BtScoNrecEnabled", {true, false, true},
950 &IPrimaryDevice::setBtScoNrecEnabled,
951 &IPrimaryDevice::getBtScoNrecEnabled);
952}
953
954TEST_F(BoolAccessorPrimaryHidlTest, setGetBtScoWidebandEnabled) {
955 doc::test("Query and set the SCO whideband state");
956 testOptionalAccessors("BtScoWideband", {true, false, true},
957 &IPrimaryDevice::setBtScoWidebandEnabled,
958 &IPrimaryDevice::getBtScoWidebandEnabled);
959}
960
961using TtyModeAccessorPrimaryHidlTest = AccessorPrimaryHidlTest<TtyMode>;
962TEST_F(TtyModeAccessorPrimaryHidlTest, setGetTtyMode) {
963 doc::test("Query and set the TTY mode state");
964 testOptionalAccessors("TTY mode", {TtyMode::OFF, TtyMode::HCO, TtyMode::VCO, TtyMode::FULL},
965 &IPrimaryDevice::setTtyMode, &IPrimaryDevice::getTtyMode);
966}
967
968TEST_F(BoolAccessorPrimaryHidlTest, setGetHac) {
969 doc::test("Query and set the HAC state");
970 testAccessors("HAC", {true, false, true},
971 &IPrimaryDevice::setHacEnabled,
972 &IPrimaryDevice::getHacEnabled);
973}
974
975//////////////////////////////////////////////////////////////////////////////
Kevin Rocardf0357882017-02-10 16:19:28 -0800976//////////////////// Clean caches on global tear down ////////////////////////
977//////////////////////////////////////////////////////////////////////////////
978
979int main(int argc, char** argv) {
980 environment = new Environment;
981 ::testing::AddGlobalTestEnvironment(environment);
982 ::testing::InitGoogleTest(&argc, argv);
983 int status = RUN_ALL_TESTS();
984 LOG(INFO) << "Test result = " << status;
985 return status;
986}