Merge "audio: Skip tests if audio HAL service lacks "primary" device" am: f49cfb4462
am: ee6b54d8b0
Change-Id: I25f7480a417b712d9813dc6a522251254ddc1ac6
This commit is contained in:
commit
5defe6bd61
2 changed files with 54 additions and 32 deletions
|
@ -29,18 +29,21 @@ static void waitForDeviceDestruction() {
|
|||
|
||||
TEST_F(AudioHidlTest, OpenPrimaryDeviceUsingGetDevice) {
|
||||
doc::test("Calling openDevice(\"primary\") should return the primary device.");
|
||||
{
|
||||
Result result;
|
||||
sp<IDevice> baseDevice;
|
||||
ASSERT_OK(devicesFactory->openDevice("primary", returnIn(result, baseDevice)));
|
||||
ASSERT_OK(result);
|
||||
ASSERT_TRUE(baseDevice != nullptr);
|
||||
struct WaitExecutor {
|
||||
~WaitExecutor() { waitForDeviceDestruction(); }
|
||||
} waitExecutor; // Make sure we wait for the device destruction on exiting from the test.
|
||||
Result result;
|
||||
sp<IDevice> baseDevice;
|
||||
ASSERT_OK(devicesFactory->openDevice("primary", returnIn(result, baseDevice)));
|
||||
if (result != Result::OK && isPrimaryDeviceOptional()) {
|
||||
GTEST_SKIP() << "No primary device on this factory"; // returns
|
||||
}
|
||||
ASSERT_OK(result);
|
||||
ASSERT_TRUE(baseDevice != nullptr);
|
||||
|
||||
Return<sp<IPrimaryDevice>> primaryDevice = IPrimaryDevice::castFrom(baseDevice);
|
||||
ASSERT_TRUE(primaryDevice.isOk());
|
||||
ASSERT_TRUE(sp<IPrimaryDevice>(primaryDevice) != nullptr);
|
||||
} // Destroy local IDevice proxy
|
||||
waitForDeviceDestruction();
|
||||
Return<sp<IPrimaryDevice>> primaryDevice = IPrimaryDevice::castFrom(baseDevice);
|
||||
ASSERT_TRUE(primaryDevice.isOk());
|
||||
ASSERT_TRUE(sp<IPrimaryDevice>(primaryDevice) != nullptr);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -152,6 +155,7 @@ TEST_F(AudioPrimaryHidlTest, SetConnectedState) {
|
|||
// initial state. To workaround this, destroy the HAL at the end of this test.
|
||||
device.clear();
|
||||
waitForDeviceDestruction();
|
||||
ASSERT_NO_FATAL_FAILURE(initPrimaryDevice());
|
||||
}
|
||||
|
||||
static void testGetDevices(IStream* stream, AudioDevice expectedDevice) {
|
||||
|
|
|
@ -215,25 +215,32 @@ TEST_F(AudioPolicyConfigTest, LoadAudioPolicyXMLConfiguration) {
|
|||
// Test all audio devices
|
||||
class AudioHidlTest : public AudioPolicyConfigTest {
|
||||
public:
|
||||
void SetUp() override {
|
||||
ASSERT_NO_FATAL_FAILURE(HidlTest::SetUp()); // setup base
|
||||
static void SetUpTestSuite() {
|
||||
devicesFactory = ::testing::VtsHalHidlTargetTestBase::getService<IDevicesFactory>(
|
||||
environment->getServiceName<IDevicesFactory>());
|
||||
}
|
||||
|
||||
if (devicesFactory == nullptr) {
|
||||
environment->registerTearDown([] { devicesFactory.clear(); });
|
||||
devicesFactory = ::testing::VtsHalHidlTargetTestBase::getService<IDevicesFactory>(
|
||||
environment->getServiceName<IDevicesFactory>("default"));
|
||||
}
|
||||
ASSERT_TRUE(devicesFactory != nullptr);
|
||||
}
|
||||
static void TearDownTestSuite() { devicesFactory.clear(); }
|
||||
|
||||
void SetUp() override {
|
||||
ASSERT_NO_FATAL_FAILURE(AudioPolicyConfigTest::SetUp()); // setup base
|
||||
// Failures during SetUpTestSuite do not cause test termination.
|
||||
ASSERT_TRUE(devicesFactory != nullptr);
|
||||
}
|
||||
|
||||
protected:
|
||||
// Cache the devicesFactory retrieval to speed up each test by ~0.5s
|
||||
static sp<IDevicesFactory> devicesFactory;
|
||||
|
||||
static bool isPrimaryDeviceOptional() {
|
||||
// It's OK not to have "primary" device on non-default audio HAL service.
|
||||
return environment->getServiceName<IDevicesFactory>() != kDefaultServiceName;
|
||||
}
|
||||
};
|
||||
sp<IDevicesFactory> AudioHidlTest::devicesFactory;
|
||||
|
||||
TEST_F(AudioHidlTest, GetAudioDevicesFactoryService) {
|
||||
doc::test("Test the getService (called in SetUp)");
|
||||
doc::test("Test the getService");
|
||||
}
|
||||
|
||||
TEST_F(AudioHidlTest, OpenDeviceInvalidParameter) {
|
||||
|
@ -257,23 +264,31 @@ TEST_F(AudioHidlTest, OpenDeviceInvalidParameter) {
|
|||
// Test the primary device
|
||||
class AudioPrimaryHidlTest : public AudioHidlTest {
|
||||
public:
|
||||
/** Primary HAL test are NOT thread safe. */
|
||||
static void SetUpTestSuite() {
|
||||
ASSERT_NO_FATAL_FAILURE(AudioHidlTest::SetUpTestSuite());
|
||||
ASSERT_NO_FATAL_FAILURE(initPrimaryDevice());
|
||||
}
|
||||
|
||||
static void TearDownTestSuite() {
|
||||
device.clear();
|
||||
AudioHidlTest::TearDownTestSuite();
|
||||
}
|
||||
|
||||
void SetUp() override {
|
||||
ASSERT_NO_FATAL_FAILURE(AudioHidlTest::SetUp()); // setup base
|
||||
|
||||
if (device == nullptr) {
|
||||
initPrimaryDevice();
|
||||
ASSERT_TRUE(device != nullptr);
|
||||
environment->registerTearDown([] { device.clear(); });
|
||||
if (device == nullptr && isPrimaryDeviceOptional()) {
|
||||
GTEST_SKIP() << "No primary device on this factory";
|
||||
}
|
||||
ASSERT_TRUE(device != nullptr);
|
||||
}
|
||||
|
||||
protected:
|
||||
// Cache the device opening to speed up each test by ~0.5s
|
||||
static sp<IPrimaryDevice> device;
|
||||
|
||||
private:
|
||||
void initPrimaryDevice() {
|
||||
static void initPrimaryDevice() {
|
||||
// Failures during test suite set up do not cause test termination.
|
||||
ASSERT_TRUE(devicesFactory != nullptr);
|
||||
Result result;
|
||||
#if MAJOR_VERSION == 2
|
||||
sp<IDevice> baseDevice;
|
||||
|
@ -292,7 +307,7 @@ class AudioPrimaryHidlTest : public AudioHidlTest {
|
|||
sp<IPrimaryDevice> AudioPrimaryHidlTest::device;
|
||||
|
||||
TEST_F(AudioPrimaryHidlTest, OpenPrimaryDevice) {
|
||||
doc::test("Test the openDevice (called in SetUp)");
|
||||
doc::test("Test the openDevice (called during setup)");
|
||||
}
|
||||
|
||||
TEST_F(AudioPrimaryHidlTest, Init) {
|
||||
|
@ -692,6 +707,7 @@ class OpenStreamTest : public AudioConfigPrimaryTest,
|
|||
if (open) {
|
||||
ASSERT_OK(stream->close());
|
||||
}
|
||||
AudioConfigPrimaryTest::TearDown();
|
||||
}
|
||||
|
||||
protected:
|
||||
|
@ -704,8 +720,9 @@ class OpenStreamTest : public AudioConfigPrimaryTest,
|
|||
////////////////////////////// openOutputStream //////////////////////////////
|
||||
|
||||
class OutputStreamTest : public OpenStreamTest<IStreamOut> {
|
||||
virtual void SetUp() override {
|
||||
void SetUp() override {
|
||||
ASSERT_NO_FATAL_FAILURE(OpenStreamTest::SetUp()); // setup base
|
||||
if (IsSkipped()) return; // do not attempt to use 'device'
|
||||
address.device = AudioDevice::OUT_DEFAULT;
|
||||
const AudioConfig& config = GetParam();
|
||||
// TODO: test all flag combination
|
||||
|
@ -752,8 +769,9 @@ INSTANTIATE_TEST_CASE_P(
|
|||
////////////////////////////// openInputStream //////////////////////////////
|
||||
|
||||
class InputStreamTest : public OpenStreamTest<IStreamIn> {
|
||||
virtual void SetUp() override {
|
||||
void SetUp() override {
|
||||
ASSERT_NO_FATAL_FAILURE(OpenStreamTest::SetUp()); // setup base
|
||||
if (IsSkipped()) return; // do not attempt to use 'device'
|
||||
address.device = AudioDevice::IN_DEFAULT;
|
||||
const AudioConfig& config = GetParam();
|
||||
// TODO: test all supported flags and source
|
||||
|
|
Loading…
Reference in a new issue