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"
16 #include "webrtc/engine_configurations.h"
17 #include "webrtc/modules/audio_coding/main/interface/audio_coding_module.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/test/auto_test/voe_unit_test.h"
25 #include "webrtc/voice_engine/voice_engine_defines.h"
27 DEFINE_bool(include_timing_dependent_tests, true,
28 "If true, we will include tests / parts of tests that are known "
29 "to break in slow execution environments (such as valgrind).");
30 DEFINE_bool(automated, false,
31 "If true, we'll run the automated tests we have in noninteractive "
33 DEFINE_bool(use_acm_version_2, false,
34 "If true, we'll run the tests with Audio Coding Module version 2.");
36 using namespace webrtc;
40 int dummy = 0; // Dummy used in different functions to avoid warnings
42 void SubAPIManager::DisplayStatus() const {
43 TEST_LOG("Supported sub APIs:\n\n");
47 TEST_LOG(" CallReport\n");
53 TEST_LOG(" Encryption\n");
55 TEST_LOG(" ExternalMedia\n");
59 TEST_LOG(" Hardware\n");
61 TEST_LOG(" NetEqStats\n");
63 TEST_LOG(" Network\n");
65 TEST_LOG(" RTP_RTCP\n");
67 TEST_LOG(" VideoSync\n");
69 TEST_LOG(" VolumeControl\n");
71 TEST_LOG(" AudioProcessing\n");
73 TEST_LOG("Excluded sub APIs:\n\n");
77 TEST_LOG(" CallReport\n");
83 TEST_LOG(" Encryption\n");
85 TEST_LOG(" ExternamMedia\n");
89 TEST_LOG(" Hardware\n");
91 TEST_LOG(" NetEqStats\n");
93 TEST_LOG(" Network\n");
95 TEST_LOG(" RTP_RTCP\n");
97 TEST_LOG(" VideoSync\n");
99 TEST_LOG(" VolumeControl\n");
101 TEST_LOG(" AudioProcessing\n");
105 VoETestManager::VoETestManager()
106 : initialized_(false),
117 #ifdef WEBRTC_VOICE_ENGINE_NETEQ_STATS_API
118 voe_neteq_stats_(NULL),
122 voe_volume_control_(0),
126 VoETestManager::~VoETestManager() {
129 bool VoETestManager::Init() {
133 if (VoiceEngine::SetTraceFile(NULL) != -1) {
134 // should not be possible to call a Trace method before the VoE is
136 TEST_LOG("\nError at line: %i (VoiceEngine::SetTraceFile()"
137 "should fail)!\n", __LINE__);
141 // TODO(minyue): Remove when the old ACM is removed (latest 2014-04-01).
142 config_.Set<AudioCodingModuleFactory>(FLAGS_use_acm_version_2 ?
143 new NewAudioCodingModuleFactory() :
144 new AudioCodingModuleFactory());
145 voice_engine_ = VoiceEngine::Create(config_);
147 if (!voice_engine_) {
148 TEST_LOG("Failed to create VoiceEngine\n");
155 void VoETestManager::GetInterfaces() {
157 voe_base_ = VoEBase::GetInterface(voice_engine_);
158 voe_codec_ = VoECodec::GetInterface(voice_engine_);
159 voe_volume_control_ = VoEVolumeControl::GetInterface(voice_engine_);
160 voe_dtmf_ = VoEDtmf::GetInterface(voice_engine_);
161 voe_rtp_rtcp_ = VoERTP_RTCP::GetInterface(voice_engine_);
162 voe_apm_ = VoEAudioProcessing::GetInterface(voice_engine_);
163 voe_network_ = VoENetwork::GetInterface(voice_engine_);
164 voe_file_ = VoEFile::GetInterface(voice_engine_);
165 #ifdef _TEST_VIDEO_SYNC_
166 voe_vsync_ = VoEVideoSync::GetInterface(voice_engine_);
168 voe_encrypt_ = VoEEncryption::GetInterface(voice_engine_);
169 voe_hardware_ = VoEHardware::GetInterface(voice_engine_);
170 // Set the audio layer to use in all tests
172 int res = voe_hardware_->SetAudioDeviceLayer(TESTED_AUDIO_LAYER);
174 printf("\nERROR: failed to set audio layer to use in "
177 printf("\nAudio layer %d will be used in testing\n",
182 voe_xmedia_ = VoEExternalMedia::GetInterface(voice_engine_);
184 #ifdef _TEST_CALL_REPORT_
185 voe_call_report_ = VoECallReport::GetInterface(voice_engine_);
187 #ifdef WEBRTC_VOICE_ENGINE_NETEQ_STATS_API
188 voe_neteq_stats_ = VoENetEqStats::GetInterface(voice_engine_);
193 int VoETestManager::ReleaseInterfaces() {
194 bool releaseOK(true);
197 voe_base_->Release();
201 voe_codec_->Release();
204 if (voe_volume_control_) {
205 voe_volume_control_->Release();
206 voe_volume_control_ = NULL;
209 voe_dtmf_->Release();
213 voe_rtp_rtcp_->Release();
214 voe_rtp_rtcp_ = NULL;
221 voe_network_->Release();
225 voe_file_->Release();
228 #ifdef _TEST_VIDEO_SYNC_
230 voe_vsync_->Release();
235 voe_encrypt_->Release();
239 voe_hardware_->Release();
240 voe_hardware_ = NULL;
244 voe_xmedia_->Release();
248 #ifdef _TEST_CALL_REPORT_
249 if (voe_call_report_) {
250 voe_call_report_->Release();
251 voe_call_report_ = NULL;
254 #ifdef WEBRTC_VOICE_ENGINE_NETEQ_STATS_API
255 if (voe_neteq_stats_) {
256 voe_neteq_stats_->Release();
257 voe_neteq_stats_ = NULL;
260 if (false == VoiceEngine::Delete(voice_engine_)) {
261 TEST_LOG("\n\nVoiceEngine::Delete() failed. \n");
265 if (VoiceEngine::SetTraceFile(NULL) != -1) {
266 TEST_LOG("\nError at line: %i (VoiceEngine::SetTraceFile()"
267 "should fail)!\n", __LINE__);
270 return (releaseOK == true) ? 0 : -1;
273 int run_auto_test(TestType test_type) {
274 assert(test_type != Standard);
276 SubAPIManager api_manager;
277 api_manager.DisplayStatus();
279 ////////////////////////////////////
280 // Create VoiceEngine and sub API:s
282 voetest::VoETestManager test_manager;
283 if (!test_manager.Init()) {
286 test_manager.GetInterfaces();
289 if (test_type == Stress) {
290 VoEStressTest stressTest(test_manager);
291 result = stressTest.DoTest();
292 } else if (test_type == Unit) {
293 VoEUnitTest unitTest(test_manager);
294 result = unitTest.DoTest();
295 } else if (test_type == CPU) {
296 VoECpuTest cpuTest(test_manager);
297 result = cpuTest.DoTest();
299 // Should never end up here
306 int release_ok = test_manager.ReleaseInterfaces();
308 if ((0 == result) && (release_ok != -1)) {
309 TEST_LOG("\n\n*** All tests passed *** \n\n");
311 TEST_LOG("\n\n*** Test failed! *** \n");
316 } // namespace voetest
318 int RunInManualMode() {
319 using namespace voetest;
321 SubAPIManager api_manager;
322 api_manager.DisplayStatus();
324 printf("----------------------------\n");
325 printf("Select type of test\n\n");
326 printf(" (0) Quit\n");
327 printf(" (1) Standard test\n");
328 printf(" (2) [OBSOLETE: Extended test(s)...]\n");
329 printf(" (3) Stress test(s)...\n");
330 printf(" (4) Unit test(s)...\n");
331 printf(" (5) CPU & memory reference test [Windows]...\n");
335 dummy = scanf("%d", &selection);
337 TestType test_type = Invalid;
342 test_type = Standard;
356 TEST_LOG("Invalid selection!\n");
360 if (test_type == Standard) {
361 TEST_LOG("\n\n+++ Running standard tests +++\n\n");
363 // Currently, all googletest-rewritten tests are in the "automated" suite.
364 return RunInAutomatedMode();
367 // Function that can be called from other entry functions.
368 return run_auto_test(test_type);
371 // ----------------------------------------------------------------------------
373 // ----------------------------------------------------------------------------
375 #if !defined(WEBRTC_IOS)
376 int main(int argc, char** argv) {
377 // This function and RunInAutomatedMode is defined in automated_mode.cc
378 // to avoid macro clashes with googletest (for instance ASSERT_TRUE).
379 InitializeGoogleTest(&argc, argv);
380 google::ParseCommandLineFlags(&argc, &argv, true);
382 if (FLAGS_automated) {
383 return RunInAutomatedMode();
386 return RunInManualMode();
388 #endif //#if !defined(WEBRTC_IOS)