[Sanitizers] Disable tests at compile-time rather than run-time.

Rationale:
 * More explicit (you won't miss that when glancing at the code).
 * More consistent (see MAYBE_* in other tests).
 * Allow to re-activate tests via CLI (--gtest_also_run_disabled_tests).
 * Tests won't wrongly show up as PASSING (bug/webrtc:10819),
   since they won't show up at all.

Bug: webrtc:9778
Change-Id: Ic32e18cb8ee2352def95206c2aa66e1dea0cc1e3
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/146200
Reviewed-by: Henrik Andreassson <henrika@webrtc.org>
Commit-Queue: Yves Gerey <yvesg@google.com>
Cr-Commit-Position: refs/heads/master@{#28617}
This commit is contained in:
Yves Gerey
2019-07-18 22:01:09 +02:00
committed by Commit Bot
parent 21f2fc9c73
commit 1afe657d5c

View File

@ -67,23 +67,13 @@ namespace {
#endif
#define PRINT(...) fprintf(stderr, __VA_ARGS__);
// Don't run these tests in combination with sanitizers.
// TODO(webrtc:9778): Re-enable on THREAD_SANITIZER?
#if defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER) || \
defined(THREAD_SANITIZER)
#define SKIP_TEST_IF_NOT(requirements_satisfied) \
do { \
GTEST_SKIP() << "Skipped for sanitizers."; \
} while (false)
#else
// Or if other audio-related requirements are not met.
// Don't run these tests if audio-related requirements are not met.
#define SKIP_TEST_IF_NOT(requirements_satisfied) \
do { \
if (!requirements_satisfied) { \
GTEST_SKIP() << "Skipped. No audio device found."; \
} \
} while (false)
#endif
// Number of callbacks (input or output) the tests waits for before we set
// an event indicating that the test was OK.
@ -510,15 +500,22 @@ class MockAudioTransport : public test::MockAudioTransport {
};
// AudioDeviceTest test fixture.
class AudioDeviceTest
// Don't run these tests in combination with sanitizers.
// TODO(webrtc:9778): Re-enable on THREAD_SANITIZER?
#if defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER) || \
defined(THREAD_SANITIZER)
#define MAYBE_AudioDeviceTest DISABLED_AudioDeviceTest
#else
#define MAYBE_AudioDeviceTest AudioDeviceTest
#endif
class MAYBE_AudioDeviceTest
: public ::testing::TestWithParam<webrtc::AudioDeviceModule::AudioLayer> {
protected:
AudioDeviceTest()
MAYBE_AudioDeviceTest()
: audio_layer_(GetParam()),
task_queue_factory_(CreateDefaultTaskQueueFactory()) {
// TODO(webrtc:9778): Re-enable on THREAD_SANITIZER?
#if !defined(ADDRESS_SANITIZER) && !defined(MEMORY_SANITIZER) && \
!defined(WEBRTC_DUMMY_AUDIO_BUILD) && !defined(THREAD_SANITIZER)
rtc::LogMessage::LogToDebug(rtc::LS_INFO);
// Add extra logging fields here if needed for debugging.
rtc::LogMessage::LogTimestamps();
@ -543,9 +540,6 @@ class AudioDeviceTest
requirements_satisfied_ =
num_playout_devices > 0 && num_record_devices > 0;
}
#else
requirements_satisfied_ = false;
#endif
if (requirements_satisfied_) {
EXPECT_EQ(0, audio_device_->SetPlayoutDevice(AUDIO_DEVICE_ID));
EXPECT_EQ(0, audio_device_->InitSpeaker());
@ -561,7 +555,7 @@ class AudioDeviceTest
}
}
virtual ~AudioDeviceTest() {
virtual ~MAYBE_AudioDeviceTest() {
if (audio_device_) {
EXPECT_EQ(0, audio_device_->Terminate());
}
@ -699,9 +693,9 @@ TEST(AudioDeviceTestWin, ConstructDestructWithFactory) {
}
// Uses the test fixture to create, initialize and destruct the ADM.
TEST_P(AudioDeviceTest, ConstructDestructDefault) {}
TEST_P(MAYBE_AudioDeviceTest, ConstructDestructDefault) {}
TEST_P(AudioDeviceTest, InitTerminate) {
TEST_P(MAYBE_AudioDeviceTest, InitTerminate) {
SKIP_TEST_IF_NOT(requirements_satisfied());
// Initialization is part of the test fixture.
EXPECT_TRUE(audio_device()->Initialized());
@ -710,7 +704,7 @@ TEST_P(AudioDeviceTest, InitTerminate) {
}
// Enumerate all available and active output devices.
TEST_P(AudioDeviceTest, PlayoutDeviceNames) {
TEST_P(MAYBE_AudioDeviceTest, PlayoutDeviceNames) {
SKIP_TEST_IF_NOT(requirements_satisfied());
char device_name[kAdmMaxDeviceNameSize];
char unique_id[kAdmMaxGuidSize];
@ -727,7 +721,7 @@ TEST_P(AudioDeviceTest, PlayoutDeviceNames) {
}
// Enumerate all available and active input devices.
TEST_P(AudioDeviceTest, RecordingDeviceNames) {
TEST_P(MAYBE_AudioDeviceTest, RecordingDeviceNames) {
SKIP_TEST_IF_NOT(requirements_satisfied());
char device_name[kAdmMaxDeviceNameSize];
char unique_id[kAdmMaxGuidSize];
@ -745,7 +739,7 @@ TEST_P(AudioDeviceTest, RecordingDeviceNames) {
}
// Counts number of active output devices and ensure that all can be selected.
TEST_P(AudioDeviceTest, SetPlayoutDevice) {
TEST_P(MAYBE_AudioDeviceTest, SetPlayoutDevice) {
SKIP_TEST_IF_NOT(requirements_satisfied());
int num_devices = audio_device()->PlayoutDevices();
if (NewWindowsAudioDeviceModuleIsUsed()) {
@ -768,7 +762,7 @@ TEST_P(AudioDeviceTest, SetPlayoutDevice) {
}
// Counts number of active input devices and ensure that all can be selected.
TEST_P(AudioDeviceTest, SetRecordingDevice) {
TEST_P(MAYBE_AudioDeviceTest, SetRecordingDevice) {
SKIP_TEST_IF_NOT(requirements_satisfied());
int num_devices = audio_device()->RecordingDevices();
if (NewWindowsAudioDeviceModuleIsUsed()) {
@ -791,14 +785,14 @@ TEST_P(AudioDeviceTest, SetRecordingDevice) {
}
// Tests Start/Stop playout without any registered audio callback.
TEST_P(AudioDeviceTest, StartStopPlayout) {
TEST_P(MAYBE_AudioDeviceTest, StartStopPlayout) {
SKIP_TEST_IF_NOT(requirements_satisfied());
StartPlayout();
StopPlayout();
}
// Tests Start/Stop recording without any registered audio callback.
TEST_P(AudioDeviceTest, StartStopRecording) {
TEST_P(MAYBE_AudioDeviceTest, StartStopRecording) {
SKIP_TEST_IF_NOT(requirements_satisfied());
StartRecording();
StopRecording();
@ -807,7 +801,7 @@ TEST_P(AudioDeviceTest, StartStopRecording) {
// Tests Init/Stop/Init recording without any registered audio callback.
// See https://bugs.chromium.org/p/webrtc/issues/detail?id=8041 for details
// on why this test is useful.
TEST_P(AudioDeviceTest, InitStopInitRecording) {
TEST_P(MAYBE_AudioDeviceTest, InitStopInitRecording) {
SKIP_TEST_IF_NOT(requirements_satisfied());
EXPECT_EQ(0, audio_device()->InitRecording());
EXPECT_TRUE(audio_device()->RecordingIsInitialized());
@ -818,7 +812,7 @@ TEST_P(AudioDeviceTest, InitStopInitRecording) {
// Verify that additional attempts to initialize or start recording while
// already being active works. Additional calls should just be ignored.
TEST_P(AudioDeviceTest, StartInitRecording) {
TEST_P(MAYBE_AudioDeviceTest, StartInitRecording) {
SKIP_TEST_IF_NOT(requirements_satisfied());
StartRecording();
// An additional attempt to initialize at this stage should be ignored.
@ -830,7 +824,7 @@ TEST_P(AudioDeviceTest, StartInitRecording) {
// Verify that additional attempts to initialize or start playou while
// already being active works. Additional calls should just be ignored.
TEST_P(AudioDeviceTest, StartInitPlayout) {
TEST_P(MAYBE_AudioDeviceTest, StartInitPlayout) {
SKIP_TEST_IF_NOT(requirements_satisfied());
StartPlayout();
// An additional attempt to initialize at this stage should be ignored.
@ -841,7 +835,7 @@ TEST_P(AudioDeviceTest, StartInitPlayout) {
}
// Tests Init/Stop/Init recording while playout is active.
TEST_P(AudioDeviceTest, InitStopInitRecordingWhilePlaying) {
TEST_P(MAYBE_AudioDeviceTest, InitStopInitRecordingWhilePlaying) {
SKIP_TEST_IF_NOT(requirements_satisfied());
StartPlayout();
EXPECT_EQ(0, audio_device()->InitRecording());
@ -853,7 +847,7 @@ TEST_P(AudioDeviceTest, InitStopInitRecordingWhilePlaying) {
}
// Tests Init/Stop/Init playout without any registered audio callback.
TEST_P(AudioDeviceTest, InitStopInitPlayout) {
TEST_P(MAYBE_AudioDeviceTest, InitStopInitPlayout) {
SKIP_TEST_IF_NOT(requirements_satisfied());
EXPECT_EQ(0, audio_device()->InitPlayout());
EXPECT_TRUE(audio_device()->PlayoutIsInitialized());
@ -863,7 +857,7 @@ TEST_P(AudioDeviceTest, InitStopInitPlayout) {
}
// Tests Init/Stop/Init playout while recording is active.
TEST_P(AudioDeviceTest, InitStopInitPlayoutWhileRecording) {
TEST_P(MAYBE_AudioDeviceTest, InitStopInitPlayoutWhileRecording) {
SKIP_TEST_IF_NOT(requirements_satisfied());
StartRecording();
EXPECT_EQ(0, audio_device()->InitPlayout());
@ -879,7 +873,7 @@ TEST_P(AudioDeviceTest, InitStopInitPlayoutWhileRecording) {
#ifdef WEBRTC_WIN
// Tests Start/Stop playout followed by a second session (emulates a restart
// triggered by a user using public APIs).
TEST_P(AudioDeviceTest, StartStopPlayoutWithExternalRestart) {
TEST_P(MAYBE_AudioDeviceTest, StartStopPlayoutWithExternalRestart) {
SKIP_TEST_IF_NOT(requirements_satisfied());
StartPlayout();
StopPlayout();
@ -891,7 +885,7 @@ TEST_P(AudioDeviceTest, StartStopPlayoutWithExternalRestart) {
// Tests Start/Stop recording followed by a second session (emulates a restart
// triggered by a user using public APIs).
TEST_P(AudioDeviceTest, StartStopRecordingWithExternalRestart) {
TEST_P(MAYBE_AudioDeviceTest, StartStopRecordingWithExternalRestart) {
SKIP_TEST_IF_NOT(requirements_satisfied());
StartRecording();
StopRecording();
@ -905,7 +899,7 @@ TEST_P(AudioDeviceTest, StartStopRecordingWithExternalRestart) {
// triggered by an internal callback e.g. corresponding to a device switch).
// Note that, internal restart is only supported in combination with the latest
// Windows ADM.
TEST_P(AudioDeviceTest, StartStopPlayoutWithInternalRestart) {
TEST_P(MAYBE_AudioDeviceTest, StartStopPlayoutWithInternalRestart) {
SKIP_TEST_IF_NOT(requirements_satisfied());
if (audio_layer() != AudioDeviceModule::kWindowsCoreAudio2) {
return;
@ -949,7 +943,7 @@ TEST_P(AudioDeviceTest, StartStopPlayoutWithInternalRestart) {
// triggered by an internal callback e.g. corresponding to a device switch).
// Note that, internal restart is only supported in combination with the latest
// Windows ADM.
TEST_P(AudioDeviceTest, StartStopRecordingWithInternalRestart) {
TEST_P(MAYBE_AudioDeviceTest, StartStopRecordingWithInternalRestart) {
SKIP_TEST_IF_NOT(requirements_satisfied());
if (audio_layer() != AudioDeviceModule::kWindowsCoreAudio2) {
return;
@ -997,7 +991,7 @@ TEST_P(AudioDeviceTest, StartStopRecordingWithInternalRestart) {
// Note that we can't add expectations on audio parameters in EXPECT_CALL
// since parameter are not provided in the each callback. We therefore test and
// verify the parameters in the fake audio transport implementation instead.
TEST_P(AudioDeviceTest, StartPlayoutVerifyCallbacks) {
TEST_P(MAYBE_AudioDeviceTest, StartPlayoutVerifyCallbacks) {
SKIP_TEST_IF_NOT(requirements_satisfied());
MockAudioTransport mock(TransportType::kPlay);
mock.HandleCallbacks(event(), nullptr, kNumCallbacks);
@ -1011,7 +1005,7 @@ TEST_P(AudioDeviceTest, StartPlayoutVerifyCallbacks) {
// Start recording and verify that the native audio layer starts providing real
// audio samples using the RecordedDataIsAvailable() callback.
TEST_P(AudioDeviceTest, StartRecordingVerifyCallbacks) {
TEST_P(MAYBE_AudioDeviceTest, StartRecordingVerifyCallbacks) {
SKIP_TEST_IF_NOT(requirements_satisfied());
MockAudioTransport mock(TransportType::kRecord);
mock.HandleCallbacks(event(), nullptr, kNumCallbacks);
@ -1026,7 +1020,7 @@ TEST_P(AudioDeviceTest, StartRecordingVerifyCallbacks) {
// Start playout and recording (full-duplex audio) and verify that audio is
// active in both directions.
TEST_P(AudioDeviceTest, StartPlayoutAndRecordingVerifyCallbacks) {
TEST_P(MAYBE_AudioDeviceTest, StartPlayoutAndRecordingVerifyCallbacks) {
SKIP_TEST_IF_NOT(requirements_satisfied());
MockAudioTransport mock(TransportType::kPlayAndRecord);
mock.HandleCallbacks(event(), nullptr, kNumCallbacks);
@ -1055,7 +1049,7 @@ TEST_P(AudioDeviceTest, StartPlayoutAndRecordingVerifyCallbacks) {
// sequence by running in loopback for a few seconds while measuring the size
// (max and average) of the FIFO. The size of the FIFO is increased by the
// recording side and decreased by the playout side.
TEST_P(AudioDeviceTest, RunPlayoutAndRecordingInFullDuplex) {
TEST_P(MAYBE_AudioDeviceTest, RunPlayoutAndRecordingInFullDuplex) {
SKIP_TEST_IF_NOT(requirements_satisfied());
NiceMock<MockAudioTransport> mock(TransportType::kPlayAndRecord);
FifoAudioStream audio_stream;
@ -1086,7 +1080,7 @@ TEST_P(AudioDeviceTest, RunPlayoutAndRecordingInFullDuplex) {
// Runs audio in full duplex until user hits Enter. Intended as a manual test
// to ensure that the audio quality is good and that real device switches works
// as intended.
TEST_P(AudioDeviceTest,
TEST_P(MAYBE_AudioDeviceTest,
DISABLED_RunPlayoutAndRecordingInFullDuplexAndWaitForEnterKey) {
SKIP_TEST_IF_NOT(requirements_satisfied());
if (audio_layer() != AudioDeviceModule::kWindowsCoreAudio2) {
@ -1123,7 +1117,7 @@ TEST_P(AudioDeviceTest,
// some sort of audio feedback loop. E.g. a headset where the mic is placed
// close to the speaker to ensure highest possible echo. It is also recommended
// to run the test at highest possible output volume.
TEST_P(AudioDeviceTest, DISABLED_MeasureLoopbackLatency) {
TEST_P(MAYBE_AudioDeviceTest, DISABLED_MeasureLoopbackLatency) {
SKIP_TEST_IF_NOT(requirements_satisfied());
NiceMock<MockAudioTransport> mock(TransportType::kPlayAndRecord);
LatencyAudioStream audio_stream;
@ -1151,14 +1145,14 @@ TEST_P(AudioDeviceTest, DISABLED_MeasureLoopbackLatency) {
// implementations) for Windows.
INSTANTIATE_TEST_SUITE_P(
AudioLayerWin,
AudioDeviceTest,
MAYBE_AudioDeviceTest,
::testing::Values(AudioDeviceModule::kPlatformDefaultAudio,
AudioDeviceModule::kWindowsCoreAudio2));
#else
// For all platforms but Windows, only test the default audio layer.
INSTANTIATE_TEST_SUITE_P(
AudioLayer,
AudioDeviceTest,
MAYBE_AudioDeviceTest,
::testing::Values(AudioDeviceModule::kPlatformDefaultAudio));
#endif