2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
11 #include "webrtc/voice_engine/test/auto_test/voe_standard_test.h"
17 #include "webrtc/engine_configurations.h"
18 #include "webrtc/system_wrappers/interface/event_wrapper.h"
19 #include "webrtc/voice_engine/include/voe_neteq_stats.h"
20 #include "webrtc/voice_engine/test/auto_test/automated_mode.h"
21 #include "webrtc/voice_engine/test/auto_test/voe_cpu_test.h"
22 #include "webrtc/voice_engine/test/auto_test/voe_stress_test.h"
23 #include "webrtc/voice_engine/test/auto_test/voe_test_defines.h"
24 #include "webrtc/voice_engine/voice_engine_defines.h"
26 DEFINE_bool(include_timing_dependent_tests, true,
27 "If true, we will include tests / parts of tests that are known "
28 "to break in slow execution environments (such as valgrind).");
29 DEFINE_bool(automated, false,
30 "If true, we'll run the automated tests we have in noninteractive "
33 using namespace webrtc;
37 int dummy = 0; // Dummy used in different functions to avoid warnings
39 void SubAPIManager::DisplayStatus() const {
40 TEST_LOG("Supported sub APIs:\n\n");
48 TEST_LOG(" ExternalMedia\n");
52 TEST_LOG(" Hardware\n");
54 TEST_LOG(" NetEqStats\n");
56 TEST_LOG(" Network\n");
58 TEST_LOG(" RTP_RTCP\n");
60 TEST_LOG(" VideoSync\n");
62 TEST_LOG(" VolumeControl\n");
64 TEST_LOG(" AudioProcessing\n");
66 TEST_LOG("Excluded sub APIs:\n\n");
74 TEST_LOG(" ExternamMedia\n");
78 TEST_LOG(" Hardware\n");
80 TEST_LOG(" NetEqStats\n");
82 TEST_LOG(" Network\n");
84 TEST_LOG(" RTP_RTCP\n");
86 TEST_LOG(" VideoSync\n");
88 TEST_LOG(" VolumeControl\n");
90 TEST_LOG(" AudioProcessing\n");
94 VoETestManager::VoETestManager()
95 : initialized_(false),
104 #ifdef WEBRTC_VOICE_ENGINE_NETEQ_STATS_API
105 voe_neteq_stats_(NULL),
109 voe_volume_control_(0),
113 VoETestManager::~VoETestManager() {
116 bool VoETestManager::Init() {
120 if (VoiceEngine::SetTraceFile(NULL) != -1) {
121 // should not be possible to call a Trace method before the VoE is
123 TEST_LOG("\nError at line: %i (VoiceEngine::SetTraceFile()"
124 "should fail)!\n", __LINE__);
128 voice_engine_ = VoiceEngine::Create();
129 if (!voice_engine_) {
130 TEST_LOG("Failed to create VoiceEngine\n");
137 void VoETestManager::GetInterfaces() {
139 voe_base_ = VoEBase::GetInterface(voice_engine_);
140 voe_codec_ = VoECodec::GetInterface(voice_engine_);
141 voe_volume_control_ = VoEVolumeControl::GetInterface(voice_engine_);
142 voe_dtmf_ = VoEDtmf::GetInterface(voice_engine_);
143 voe_rtp_rtcp_ = VoERTP_RTCP::GetInterface(voice_engine_);
144 voe_apm_ = VoEAudioProcessing::GetInterface(voice_engine_);
145 voe_network_ = VoENetwork::GetInterface(voice_engine_);
146 voe_file_ = VoEFile::GetInterface(voice_engine_);
147 #ifdef _TEST_VIDEO_SYNC_
148 voe_vsync_ = VoEVideoSync::GetInterface(voice_engine_);
150 voe_hardware_ = VoEHardware::GetInterface(voice_engine_);
151 // Set the audio layer to use in all tests
153 int res = voe_hardware_->SetAudioDeviceLayer(TESTED_AUDIO_LAYER);
155 printf("\nERROR: failed to set audio layer to use in "
158 printf("\nAudio layer %d will be used in testing\n",
163 voe_xmedia_ = VoEExternalMedia::GetInterface(voice_engine_);
165 #ifdef WEBRTC_VOICE_ENGINE_NETEQ_STATS_API
166 voe_neteq_stats_ = VoENetEqStats::GetInterface(voice_engine_);
171 int VoETestManager::ReleaseInterfaces() {
172 bool releaseOK(true);
175 voe_base_->Release();
179 voe_codec_->Release();
182 if (voe_volume_control_) {
183 voe_volume_control_->Release();
184 voe_volume_control_ = NULL;
187 voe_dtmf_->Release();
191 voe_rtp_rtcp_->Release();
192 voe_rtp_rtcp_ = NULL;
199 voe_network_->Release();
203 voe_file_->Release();
206 #ifdef _TEST_VIDEO_SYNC_
208 voe_vsync_->Release();
213 voe_hardware_->Release();
214 voe_hardware_ = NULL;
218 voe_xmedia_->Release();
222 #ifdef WEBRTC_VOICE_ENGINE_NETEQ_STATS_API
223 if (voe_neteq_stats_) {
224 voe_neteq_stats_->Release();
225 voe_neteq_stats_ = NULL;
228 if (false == VoiceEngine::Delete(voice_engine_)) {
229 TEST_LOG("\n\nVoiceEngine::Delete() failed. \n");
233 if (VoiceEngine::SetTraceFile(NULL) != -1) {
234 TEST_LOG("\nError at line: %i (VoiceEngine::SetTraceFile()"
235 "should fail)!\n", __LINE__);
238 return (releaseOK == true) ? 0 : -1;
241 int run_auto_test(TestType test_type) {
242 assert(test_type != Standard);
244 SubAPIManager api_manager;
245 api_manager.DisplayStatus();
247 ////////////////////////////////////
248 // Create VoiceEngine and sub API:s
250 voetest::VoETestManager test_manager;
251 if (!test_manager.Init()) {
254 test_manager.GetInterfaces();
257 if (test_type == Stress) {
258 VoEStressTest stressTest(test_manager);
259 result = stressTest.DoTest();
260 } else if (test_type == CPU) {
261 VoECpuTest cpuTest(test_manager);
262 result = cpuTest.DoTest();
264 // Should never end up here
271 int release_ok = test_manager.ReleaseInterfaces();
273 if ((0 == result) && (release_ok != -1)) {
274 TEST_LOG("\n\n*** All tests passed *** \n\n");
276 TEST_LOG("\n\n*** Test failed! *** \n");
281 } // namespace voetest
283 int RunInManualMode() {
284 using namespace voetest;
286 SubAPIManager api_manager;
287 api_manager.DisplayStatus();
289 printf("----------------------------\n");
290 printf("Select type of test\n\n");
291 printf(" (0) Quit\n");
292 printf(" (1) Standard test\n");
293 printf(" (2) [OBSOLETE: Extended test(s)...]\n");
294 printf(" (3) Stress test(s)...\n");
295 printf(" (4) [OBSOLETE: Unit test(s)...]\n");
296 printf(" (5) CPU & memory reference test [Windows]...\n");
300 dummy = scanf("%d", &selection);
302 TestType test_type = Invalid;
307 test_type = Standard;
320 TEST_LOG("Invalid selection!\n");
324 if (test_type == Standard) {
325 TEST_LOG("\n\n+++ Running standard tests +++\n\n");
327 // Currently, all googletest-rewritten tests are in the "automated" suite.
328 return RunInAutomatedMode();
331 // Function that can be called from other entry functions.
332 return run_auto_test(test_type);
335 // ----------------------------------------------------------------------------
337 // ----------------------------------------------------------------------------
339 #if !defined(WEBRTC_IOS)
340 int main(int argc, char** argv) {
341 // This function and RunInAutomatedMode is defined in automated_mode.cc
342 // to avoid macro clashes with googletest (for instance ASSERT_TRUE).
343 InitializeGoogleTest(&argc, argv);
344 // AllowCommandLineParsing allows us to ignore flags passed on to us by
345 // Chromium build bots without having to explicitly disable them.
346 google::AllowCommandLineReparsing();
347 google::ParseCommandLineFlags(&argc, &argv, true);
349 if (FLAGS_automated) {
350 return RunInAutomatedMode();
353 return RunInManualMode();
355 #endif //#if !defined(WEBRTC_IOS)