Always build all iOS unittests, even on the simulator.
Also, make the iOS audio unittests not run on the simulator by default,
and if someone wants to run the tests one can do
by using the WEBRTC_IOS_RUN_AUDIO_TESTS environment variable.
Bug: webrtc:7812
Change-Id: Ie9fc70872c6617516e2f2c21039489df309b85fb
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/292621
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Commit-Queue: Daniel.L (Byoungchan) Lee <daniel.l@hpcnt.com>
Reviewed-by: Kári Helgason <kthelgason@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#39306}
diff --git a/sdk/BUILD.gn b/sdk/BUILD.gn
index a361656..971a323 100644
--- a/sdk/BUILD.gn
+++ b/sdk/BUILD.gn
@@ -1114,6 +1114,8 @@
sources = [
"objc/unittests/ObjCVideoTrackSource_xctest.mm",
+ "objc/unittests/RTCAudioDeviceModule_xctest.mm",
+ "objc/unittests/RTCAudioDevice_xctest.mm",
"objc/unittests/RTCAudioSessionTest.mm",
"objc/unittests/RTCCVPixelBuffer_xctest.mm",
"objc/unittests/RTCCallbackLogger_xctest.m",
@@ -1146,15 +1148,6 @@
# workaround.
defines = [ "GLES_SILENCE_DEPRECATION" ]
- # TODO(peterhanspers): Reenable these tests on simulator.
- # See bugs.webrtc.org/7812
- if (target_environment != "simulator") {
- sources += [
- "objc/unittests/RTCAudioDeviceModule_xctest.mm",
- "objc/unittests/RTCAudioDevice_xctest.mm",
- ]
- }
-
deps = [
":audio_device",
":audio_session_objc",
diff --git a/sdk/objc/unittests/RTCAudioDeviceModule_xctest.mm b/sdk/objc/unittests/RTCAudioDeviceModule_xctest.mm
index f8ce844..f7439f3 100644
--- a/sdk/objc/unittests/RTCAudioDeviceModule_xctest.mm
+++ b/sdk/objc/unittests/RTCAudioDeviceModule_xctest.mm
@@ -10,6 +10,8 @@
#import <XCTest/XCTest.h>
+#include <stdlib.h>
+
#if defined(WEBRTC_IOS)
#import "sdk/objc/native/api/audio_device_module.h"
#endif
@@ -126,6 +128,7 @@
static const NSUInteger kNumIgnoreFirstCallbacks = 50;
@interface RTCAudioDeviceModuleTests : XCTestCase {
+ bool _testEnabled;
rtc::scoped_refptr<webrtc::AudioDeviceModule> audioDeviceModule;
MockAudioTransport mock;
}
@@ -142,6 +145,17 @@
- (void)setUp {
[super setUp];
+#if defined(WEBRTC_IOS) && TARGET_OS_SIMULATOR
+ // TODO(peterhanspers): Reenable these tests on simulator.
+ // See bugs.webrtc.org/7812
+ _testEnabled = false;
+ if (::getenv("WEBRTC_IOS_RUN_AUDIO_TESTS") != nullptr) {
+ _testEnabled = true;
+ }
+#else
+ _testEnabled = true;
+#endif
+
audioDeviceModule = webrtc::CreateAudioDeviceModule();
XCTAssertEqual(0, audioDeviceModule->Init());
XCTAssertEqual(0, audioDeviceModule->GetPlayoutAudioParameters(&playoutParameters));
@@ -192,10 +206,12 @@
#pragma mark - Tests
- (void)testConstructDestruct {
+ XCTSkipIf(!_testEnabled);
// Using the test fixture to create and destruct the audio device module.
}
- (void)testInitTerminate {
+ XCTSkipIf(!_testEnabled);
// Initialization is part of the test fixture.
XCTAssertTrue(audioDeviceModule->Initialized());
XCTAssertEqual(0, audioDeviceModule->Terminate());
@@ -205,6 +221,7 @@
// Tests that playout can be initiated, started and stopped. No audio callback
// is registered in this test.
- (void)testStartStopPlayout {
+ XCTSkipIf(!_testEnabled);
[self startPlayout];
[self stopPlayout];
[self startPlayout];
@@ -214,6 +231,7 @@
// Tests that recording can be initiated, started and stopped. No audio callback
// is registered in this test.
- (void)testStartStopRecording {
+ XCTSkipIf(!_testEnabled);
[self startRecording];
[self stopRecording];
[self startRecording];
@@ -224,6 +242,7 @@
// StartPlayout() while being uninitialized since doing so will hit a
// RTC_DCHECK.
- (void)testStopPlayoutRequiresInitToRestart {
+ XCTSkipIf(!_testEnabled);
XCTAssertEqual(0, audioDeviceModule->InitPlayout());
XCTAssertEqual(0, audioDeviceModule->StartPlayout());
XCTAssertEqual(0, audioDeviceModule->StopPlayout());
@@ -236,6 +255,7 @@
// explicitly verify correct audio session calls but instead focuses on
// ensuring that audio starts for both ADMs.
- (void)testStartPlayoutOnTwoInstances {
+ XCTSkipIf(!_testEnabled);
// Create and initialize a second/extra ADM instance. The default ADM is
// created by the test harness.
rtc::scoped_refptr<webrtc::AudioDeviceModule> secondAudioDeviceModule =
@@ -319,7 +339,7 @@
// Start playout and verify that the native audio layer starts asking for real
// audio samples to play out using the NeedMorePlayData callback.
- (void)testStartPlayoutVerifyCallbacks {
-
+ XCTSkipIf(!_testEnabled);
XCTestExpectation *playoutExpectation = [self expectationWithDescription:@"NeedMorePlayoutData"];
__block int num_callbacks = 0;
mock.expectNeedMorePlayData(^int32_t(const size_t nSamples,
@@ -352,6 +372,7 @@
// Start recording and verify that the native audio layer starts feeding real
// audio samples via the RecordedDataIsAvailable callback.
- (void)testStartRecordingVerifyCallbacks {
+ XCTSkipIf(!_testEnabled);
XCTestExpectation *recordExpectation =
[self expectationWithDescription:@"RecordedDataIsAvailable"];
__block int num_callbacks = 0;
@@ -390,6 +411,7 @@
// Start playout and recording (full-duplex audio) and verify that audio is
// active in both directions.
- (void)testStartPlayoutAndRecordingVerifyCallbacks {
+ XCTSkipIf(!_testEnabled);
XCTestExpectation *playoutExpectation = [self expectationWithDescription:@"NeedMorePlayoutData"];
__block NSUInteger callbackCount = 0;
@@ -453,6 +475,7 @@
// asks for data to play out. Real audio is played out in this test but it does
// not contain any explicit verification that the audio quality is perfect.
- (void)testRunPlayoutWithFileAsSource {
+ XCTSkipIf(!_testEnabled);
XCTAssertEqual(1u, playoutParameters.channels());
// Using XCTestExpectation to count callbacks is very slow.
@@ -488,6 +511,7 @@
}
- (void)testDevices {
+ XCTSkipIf(!_testEnabled);
// Device enumeration is not supported. Verify fixed values only.
XCTAssertEqual(1, audioDeviceModule->PlayoutDevices());
XCTAssertEqual(1, audioDeviceModule->RecordingDevices());
@@ -507,6 +531,7 @@
// TODO(henrika): tune the final test parameters after running tests on several
// different devices.
- (void)testRunPlayoutAndRecordingInFullDuplex {
+ XCTSkipIf(!_testEnabled);
XCTAssertEqual(recordParameters.channels(), playoutParameters.channels());
XCTAssertEqual(recordParameters.sample_rate(), playoutParameters.sample_rate());
diff --git a/sdk/objc/unittests/RTCAudioDevice_xctest.mm b/sdk/objc/unittests/RTCAudioDevice_xctest.mm
index e01fdbd..eec9e17 100644
--- a/sdk/objc/unittests/RTCAudioDevice_xctest.mm
+++ b/sdk/objc/unittests/RTCAudioDevice_xctest.mm
@@ -10,6 +10,8 @@
#import <XCTest/XCTest.h>
+#include <stdlib.h>
+
#include "api/task_queue/default_task_queue_factory.h"
#import "sdk/objc/components/audio/RTCAudioSession+Private.h"
@@ -17,6 +19,7 @@
#import "sdk/objc/native/src/audio/audio_device_ios.h"
@interface RTCAudioDeviceTests : XCTestCase {
+ bool _testEnabled;
rtc::scoped_refptr<webrtc::AudioDeviceModule> _audioDeviceModule;
std::unique_ptr<webrtc::ios_adm::AudioDeviceIOS> _audio_device;
}
@@ -31,6 +34,16 @@
- (void)setUp {
[super setUp];
+#if defined(WEBRTC_IOS) && TARGET_OS_SIMULATOR
+ // TODO(peterhanspers): Reenable these tests on simulator.
+ // See bugs.webrtc.org/7812
+ _testEnabled = false;
+ if (::getenv("WEBRTC_IOS_RUN_AUDIO_TESTS") != nullptr) {
+ _testEnabled = true;
+ }
+#else
+ _testEnabled = true;
+#endif
_audioDeviceModule = webrtc::CreateAudioDeviceModule();
_audio_device.reset(new webrtc::ios_adm::AudioDeviceIOS(/*bypass_voice_processing=*/false));
@@ -78,6 +91,7 @@
// AudioDeviceIOS's is_interrupted_ flag to RTC_OBJC_TYPE(RTCAudioSession)'s isInterrupted
// flag in AudioDeviceIOS.InitPlayOrRecord.
- (void)testInterruptedAudioSession {
+ XCTSkipIf(!_testEnabled);
XCTAssertTrue(self.audioSession.isActive);
XCTAssertTrue([self.audioSession.category isEqual:AVAudioSessionCategoryPlayAndRecord] ||
[self.audioSession.category isEqual:AVAudioSessionCategoryPlayback]);