Commit d7bbdf99 authored by Thomas Guilbert's avatar Thomas Guilbert Committed by Commit Bot

Limit AAudio UTs to supported devices

Currently, when running AAudioOutputStream unit tests, we set a flag,
and leave it up to the AudioManager to choose which Android audio
library it uses. We don't check whether or not we are actually using
AAudio. This can result in running tests use OpenSLES, but are listed as
AAudio tests when they fail.

This CL explicitly checks whether we are using AAudio after setting the
flags, and skips tests that fallback to OpenSLES.

Bug: 1101283
Change-Id: I0e91c11f0f61c13ce1e68061f579b2637fb971ac
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2335485
Commit-Queue: Thomas Guilbert <tguilbert@chromium.org>
Reviewed-by: default avatarDale Curtis <dalecurtis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#794321}
parent 9d6a304b
...@@ -88,6 +88,8 @@ class MEDIA_EXPORT AudioManagerAndroid : public AudioManagerBase { ...@@ -88,6 +88,8 @@ class MEDIA_EXPORT AudioManagerAndroid : public AudioManagerBase {
// otherwise accounting for. // otherwise accounting for.
base::TimeDelta GetOutputLatency(); base::TimeDelta GetOutputLatency();
bool IsUsingAAudioForTesting() { return UseAAudio(); }
protected: protected:
void ShutdownOnAudioThread() override; void ShutdownOnAudioThread() override;
AudioParameters GetPreferredOutputStreamParameters( AudioParameters GetPreferredOutputStreamParameters(
......
...@@ -27,6 +27,10 @@ ...@@ -27,6 +27,10 @@
#include "media/base/media_switches.h" #include "media/base/media_switches.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#if defined(OS_ANDROID)
#include "media/audio/android/audio_manager_android.h"
#endif
namespace media { namespace media {
class AudioOutputTest : public testing::TestWithParam<bool> { class AudioOutputTest : public testing::TestWithParam<bool> {
...@@ -38,8 +42,14 @@ class AudioOutputTest : public testing::TestWithParam<bool> { ...@@ -38,8 +42,14 @@ class AudioOutputTest : public testing::TestWithParam<bool> {
std::make_unique<AudioDeviceInfoAccessorForTests>(audio_manager_.get()); std::make_unique<AudioDeviceInfoAccessorForTests>(audio_manager_.get());
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
// The only parameter is used to enable/disable AAudio. // The only parameter is used to enable/disable AAudio.
if (GetParam()) should_use_aaudio_ = GetParam();
if (should_use_aaudio_) {
features_.InitAndEnableFeature(features::kUseAAudioDriver); features_.InitAndEnableFeature(features::kUseAAudioDriver);
aaudio_is_supported_ =
reinterpret_cast<AudioManagerAndroid*>(audio_manager_.get())
->IsUsingAAudioForTesting();
}
#endif #endif
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
} }
...@@ -71,6 +81,8 @@ class AudioOutputTest : public testing::TestWithParam<bool> { ...@@ -71,6 +81,8 @@ class AudioOutputTest : public testing::TestWithParam<bool> {
std::unique_ptr<AudioDeviceInfoAccessorForTests> audio_manager_device_info_; std::unique_ptr<AudioDeviceInfoAccessorForTests> audio_manager_device_info_;
AudioParameters stream_params_; AudioParameters stream_params_;
AudioOutputStream* stream_ = nullptr; AudioOutputStream* stream_ = nullptr;
bool should_use_aaudio_ = false;
bool aaudio_is_supported_ = false;
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
base::test::ScopedFeatureList features_; base::test::ScopedFeatureList features_;
#endif #endif
...@@ -78,6 +90,9 @@ class AudioOutputTest : public testing::TestWithParam<bool> { ...@@ -78,6 +90,9 @@ class AudioOutputTest : public testing::TestWithParam<bool> {
// Test that can it be created and closed. // Test that can it be created and closed.
TEST_P(AudioOutputTest, GetAndClose) { TEST_P(AudioOutputTest, GetAndClose) {
if (should_use_aaudio_ && !aaudio_is_supported_)
return;
ABORT_AUDIO_TEST_IF_NOT(audio_manager_device_info_->HasAudioOutputDevices()); ABORT_AUDIO_TEST_IF_NOT(audio_manager_device_info_->HasAudioOutputDevices());
CreateWithDefaultParameters(); CreateWithDefaultParameters();
ASSERT_TRUE(stream_); ASSERT_TRUE(stream_);
...@@ -85,6 +100,9 @@ TEST_P(AudioOutputTest, GetAndClose) { ...@@ -85,6 +100,9 @@ TEST_P(AudioOutputTest, GetAndClose) {
// Test that it can be opened and closed. // Test that it can be opened and closed.
TEST_P(AudioOutputTest, OpenAndClose) { TEST_P(AudioOutputTest, OpenAndClose) {
if (should_use_aaudio_ && !aaudio_is_supported_)
return;
ABORT_AUDIO_TEST_IF_NOT(audio_manager_device_info_->HasAudioOutputDevices()); ABORT_AUDIO_TEST_IF_NOT(audio_manager_device_info_->HasAudioOutputDevices());
CreateWithDefaultParameters(); CreateWithDefaultParameters();
...@@ -94,6 +112,9 @@ TEST_P(AudioOutputTest, OpenAndClose) { ...@@ -94,6 +112,9 @@ TEST_P(AudioOutputTest, OpenAndClose) {
// Verify that Stop() can be called before Start(). // Verify that Stop() can be called before Start().
TEST_P(AudioOutputTest, StopBeforeStart) { TEST_P(AudioOutputTest, StopBeforeStart) {
if (should_use_aaudio_ && !aaudio_is_supported_)
return;
ABORT_AUDIO_TEST_IF_NOT(audio_manager_device_info_->HasAudioOutputDevices()); ABORT_AUDIO_TEST_IF_NOT(audio_manager_device_info_->HasAudioOutputDevices());
CreateWithDefaultParameters(); CreateWithDefaultParameters();
EXPECT_TRUE(stream_->Open()); EXPECT_TRUE(stream_->Open());
...@@ -102,6 +123,9 @@ TEST_P(AudioOutputTest, StopBeforeStart) { ...@@ -102,6 +123,9 @@ TEST_P(AudioOutputTest, StopBeforeStart) {
// Verify that Stop() can be called more than once. // Verify that Stop() can be called more than once.
TEST_P(AudioOutputTest, StopTwice) { TEST_P(AudioOutputTest, StopTwice) {
if (should_use_aaudio_ && !aaudio_is_supported_)
return;
ABORT_AUDIO_TEST_IF_NOT(audio_manager_device_info_->HasAudioOutputDevices()); ABORT_AUDIO_TEST_IF_NOT(audio_manager_device_info_->HasAudioOutputDevices());
CreateWithDefaultParameters(); CreateWithDefaultParameters();
EXPECT_TRUE(stream_->Open()); EXPECT_TRUE(stream_->Open());
...@@ -114,6 +138,9 @@ TEST_P(AudioOutputTest, StopTwice) { ...@@ -114,6 +138,9 @@ TEST_P(AudioOutputTest, StopTwice) {
// This test produces actual audio for .25 seconds on the default device. // This test produces actual audio for .25 seconds on the default device.
TEST_P(AudioOutputTest, Play200HzTone) { TEST_P(AudioOutputTest, Play200HzTone) {
if (should_use_aaudio_ && !aaudio_is_supported_)
return;
ABORT_AUDIO_TEST_IF_NOT(audio_manager_device_info_->HasAudioOutputDevices()); ABORT_AUDIO_TEST_IF_NOT(audio_manager_device_info_->HasAudioOutputDevices());
stream_params_ = stream_params_ =
...@@ -152,6 +179,9 @@ TEST_P(AudioOutputTest, Play200HzTone) { ...@@ -152,6 +179,9 @@ TEST_P(AudioOutputTest, Play200HzTone) {
// Test that SetVolume() and GetVolume() work as expected. // Test that SetVolume() and GetVolume() work as expected.
TEST_P(AudioOutputTest, VolumeControl) { TEST_P(AudioOutputTest, VolumeControl) {
if (should_use_aaudio_ && !aaudio_is_supported_)
return;
ABORT_AUDIO_TEST_IF_NOT(audio_manager_device_info_->HasAudioOutputDevices()); ABORT_AUDIO_TEST_IF_NOT(audio_manager_device_info_->HasAudioOutputDevices());
CreateWithDefaultParameters(); CreateWithDefaultParameters();
...@@ -176,8 +206,8 @@ TEST_P(AudioOutputTest, VolumeControl) { ...@@ -176,8 +206,8 @@ TEST_P(AudioOutputTest, VolumeControl) {
INSTANTIATE_TEST_SUITE_P(Base, AudioOutputTest, testing::Values(false)); INSTANTIATE_TEST_SUITE_P(Base, AudioOutputTest, testing::Values(false));
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
// Run tests with AAudio enabled. On Android O and below, this is the same as // Run tests with AAudio enabled. On Android P and below, these tests should not
// the Base test above, as we only use AAudio on P+. // run, as we only use AAudio on Q+.
INSTANTIATE_TEST_SUITE_P(AAudio, AudioOutputTest, testing::Values(true)); INSTANTIATE_TEST_SUITE_P(AAudio, AudioOutputTest, testing::Values(true));
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment