Loading audio/core/all-versions/vts/functional/4.0/AudioPrimaryHidlHalTest.cpp +15 −11 Original line number Diff line number Diff line Loading @@ -29,18 +29,21 @@ static void waitForDeviceDestruction() { TEST_F(AudioHidlTest, OpenPrimaryDeviceUsingGetDevice) { doc::test("Calling openDevice(\"primary\") should return the primary device."); { 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(); } ////////////////////////////////////////////////////////////////////////////// Loading Loading @@ -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) { Loading audio/core/all-versions/vts/functional/AudioPrimaryHidlHalTest.h +39 −19 Original line number Diff line number Diff line Loading @@ -215,25 +215,34 @@ TEST_F(AudioPolicyConfigTest, LoadAudioPolicyXMLConfiguration) { // Test all audio devices class AudioHidlTest : public AudioPolicyConfigTest { public: void SetUp() override { ASSERT_NO_FATAL_FAILURE(HidlTest::SetUp()); // setup base if (devicesFactory == nullptr) { environment->registerTearDown([] { devicesFactory.clear(); }); static void SetUpTestSuite() { devicesFactory = ::testing::VtsHalHidlTargetTestBase::getService<IDevicesFactory>( environment->getServiceName<IDevicesFactory>("default")); environment->getServiceName<IDevicesFactory>()); } 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) { Loading @@ -257,23 +266,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 && 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; Loading @@ -292,7 +309,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) { Loading Loading @@ -706,6 +723,7 @@ class OpenStreamTest : public AudioConfigPrimaryTest, if (open) { ASSERT_OK(closeStream()); } AudioConfigPrimaryTest::TearDown(); } protected: Loading @@ -718,8 +736,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 Loading Loading @@ -766,8 +785,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 Loading
audio/core/all-versions/vts/functional/4.0/AudioPrimaryHidlHalTest.cpp +15 −11 Original line number Diff line number Diff line Loading @@ -29,18 +29,21 @@ static void waitForDeviceDestruction() { TEST_F(AudioHidlTest, OpenPrimaryDeviceUsingGetDevice) { doc::test("Calling openDevice(\"primary\") should return the primary device."); { 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(); } ////////////////////////////////////////////////////////////////////////////// Loading Loading @@ -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) { Loading
audio/core/all-versions/vts/functional/AudioPrimaryHidlHalTest.h +39 −19 Original line number Diff line number Diff line Loading @@ -215,25 +215,34 @@ TEST_F(AudioPolicyConfigTest, LoadAudioPolicyXMLConfiguration) { // Test all audio devices class AudioHidlTest : public AudioPolicyConfigTest { public: void SetUp() override { ASSERT_NO_FATAL_FAILURE(HidlTest::SetUp()); // setup base if (devicesFactory == nullptr) { environment->registerTearDown([] { devicesFactory.clear(); }); static void SetUpTestSuite() { devicesFactory = ::testing::VtsHalHidlTargetTestBase::getService<IDevicesFactory>( environment->getServiceName<IDevicesFactory>("default")); environment->getServiceName<IDevicesFactory>()); } 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) { Loading @@ -257,23 +266,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 && 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; Loading @@ -292,7 +309,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) { Loading Loading @@ -706,6 +723,7 @@ class OpenStreamTest : public AudioConfigPrimaryTest, if (open) { ASSERT_OK(closeStream()); } AudioConfigPrimaryTest::TearDown(); } protected: Loading @@ -718,8 +736,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 Loading Loading @@ -766,8 +785,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