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_extended_test.h"
23 #include "webrtc/voice_engine/test/auto_test/voe_stress_test.h"
24 #include "webrtc/voice_engine/test/auto_test/voe_test_defines.h"
25 #include "webrtc/voice_engine/test/auto_test/voe_unit_test.h"
26 #include "webrtc/voice_engine/voice_engine_defines.h"
28 DEFINE_bool(include_timing_dependent_tests, true,
29 "If true, we will include tests / parts of tests that are known "
30 "to break in slow execution environments (such as valgrind).");
31 DEFINE_bool(automated, false,
32 "If true, we'll run the automated tests we have in noninteractive "
34 DEFINE_bool(use_acm_version_2, false,
35 "If true, we'll run the tests with Audio Coding Module version 2.");
37 using namespace webrtc;
41 int dummy = 0; // Dummy used in different functions to avoid warnings
43 void SubAPIManager::DisplayStatus() const {
44 TEST_LOG("Supported sub APIs:\n\n");
48 TEST_LOG(" CallReport\n");
54 TEST_LOG(" Encryption\n");
56 TEST_LOG(" ExternalMedia\n");
60 TEST_LOG(" Hardware\n");
62 TEST_LOG(" NetEqStats\n");
64 TEST_LOG(" Network\n");
66 TEST_LOG(" RTP_RTCP\n");
68 TEST_LOG(" VideoSync\n");
70 TEST_LOG(" VolumeControl\n");
72 TEST_LOG(" AudioProcessing\n");
74 TEST_LOG("Excluded sub APIs:\n\n");
78 TEST_LOG(" CallReport\n");
84 TEST_LOG(" Encryption\n");
86 TEST_LOG(" ExternamMedia\n");
90 TEST_LOG(" Hardware\n");
92 TEST_LOG(" NetEqStats\n");
94 TEST_LOG(" Network\n");
96 TEST_LOG(" RTP_RTCP\n");
98 TEST_LOG(" VideoSync\n");
100 TEST_LOG(" VolumeControl\n");
102 TEST_LOG(" AudioProcessing\n");
106 bool SubAPIManager::GetExtendedMenuSelection(ExtendedSelection& sel) {
107 printf("------------------------------------------------\n");
108 printf("Select extended test\n\n");
109 printf(" (0) None\n");
110 printf("- - - - - - - - - - - - - - - - - - - - - - - - \n");
116 printf(" (2) CallReport");
121 printf(" (3) Codec");
131 printf(" (5) Encryption");
136 printf(" (6) VoEExternalMedia");
146 printf(" (8) Hardware");
151 printf(" (9) NetEqStats");
156 printf(" (10) Network");
161 printf(" (11) RTP_RTCP");
166 printf(" (12) VideoSync");
171 printf(" (13) VolumeControl");
178 ExtendedSelection xsel(XSEL_Invalid);
180 dummy = scanf("%d", &selection);
192 xsel = XSEL_CallReport;
204 xsel = XSEL_Encryption;
208 xsel = XSEL_ExternalMedia;
216 xsel = XSEL_Hardware;
220 xsel = XSEL_NetEqStats;
228 xsel = XSEL_RTP_RTCP;
232 xsel = XSEL_VideoSync;
236 xsel = XSEL_VolumeControl;
242 if (xsel == XSEL_Invalid)
243 printf("Invalid selection!\n");
248 return (xsel != XSEL_Invalid);
251 VoETestManager::VoETestManager()
252 : initialized_(false),
263 #ifdef WEBRTC_VOICE_ENGINE_NETEQ_STATS_API
264 voe_neteq_stats_(NULL),
268 voe_volume_control_(0),
272 VoETestManager::~VoETestManager() {
275 bool VoETestManager::Init() {
279 if (VoiceEngine::SetTraceFile(NULL) != -1) {
280 // should not be possible to call a Trace method before the VoE is
282 TEST_LOG("\nError at line: %i (VoiceEngine::SetTraceFile()"
283 "should fail)!\n", __LINE__);
287 // TODO(minyue): Remove when the old ACM is removed (latest 2014-04-01).
288 config_.Set<AudioCodingModuleFactory>(FLAGS_use_acm_version_2 ?
289 new NewAudioCodingModuleFactory() :
290 new AudioCodingModuleFactory());
291 voice_engine_ = VoiceEngine::Create(config_);
293 if (!voice_engine_) {
294 TEST_LOG("Failed to create VoiceEngine\n");
301 void VoETestManager::GetInterfaces() {
303 voe_base_ = VoEBase::GetInterface(voice_engine_);
304 voe_codec_ = VoECodec::GetInterface(voice_engine_);
305 voe_volume_control_ = VoEVolumeControl::GetInterface(voice_engine_);
306 voe_dtmf_ = VoEDtmf::GetInterface(voice_engine_);
307 voe_rtp_rtcp_ = VoERTP_RTCP::GetInterface(voice_engine_);
308 voe_apm_ = VoEAudioProcessing::GetInterface(voice_engine_);
309 voe_network_ = VoENetwork::GetInterface(voice_engine_);
310 voe_file_ = VoEFile::GetInterface(voice_engine_);
311 #ifdef _TEST_VIDEO_SYNC_
312 voe_vsync_ = VoEVideoSync::GetInterface(voice_engine_);
314 voe_encrypt_ = VoEEncryption::GetInterface(voice_engine_);
315 voe_hardware_ = VoEHardware::GetInterface(voice_engine_);
316 // Set the audio layer to use in all tests
318 int res = voe_hardware_->SetAudioDeviceLayer(TESTED_AUDIO_LAYER);
320 printf("\nERROR: failed to set audio layer to use in "
323 printf("\nAudio layer %d will be used in testing\n",
328 voe_xmedia_ = VoEExternalMedia::GetInterface(voice_engine_);
330 #ifdef _TEST_CALL_REPORT_
331 voe_call_report_ = VoECallReport::GetInterface(voice_engine_);
333 #ifdef WEBRTC_VOICE_ENGINE_NETEQ_STATS_API
334 voe_neteq_stats_ = VoENetEqStats::GetInterface(voice_engine_);
339 int VoETestManager::ReleaseInterfaces() {
340 bool releaseOK(true);
343 voe_base_->Release();
347 voe_codec_->Release();
350 if (voe_volume_control_) {
351 voe_volume_control_->Release();
352 voe_volume_control_ = NULL;
355 voe_dtmf_->Release();
359 voe_rtp_rtcp_->Release();
360 voe_rtp_rtcp_ = NULL;
367 voe_network_->Release();
371 voe_file_->Release();
374 #ifdef _TEST_VIDEO_SYNC_
376 voe_vsync_->Release();
381 voe_encrypt_->Release();
385 voe_hardware_->Release();
386 voe_hardware_ = NULL;
390 voe_xmedia_->Release();
394 #ifdef _TEST_CALL_REPORT_
395 if (voe_call_report_) {
396 voe_call_report_->Release();
397 voe_call_report_ = NULL;
400 #ifdef WEBRTC_VOICE_ENGINE_NETEQ_STATS_API
401 if (voe_neteq_stats_) {
402 voe_neteq_stats_->Release();
403 voe_neteq_stats_ = NULL;
406 if (false == VoiceEngine::Delete(voice_engine_)) {
407 TEST_LOG("\n\nVoiceEngine::Delete() failed. \n");
411 if (VoiceEngine::SetTraceFile(NULL) != -1) {
412 TEST_LOG("\nError at line: %i (VoiceEngine::SetTraceFile()"
413 "should fail)!\n", __LINE__);
416 return (releaseOK == true) ? 0 : -1;
419 int run_auto_test(TestType test_type,
420 ExtendedSelection ext_selection) {
421 assert(test_type != Standard);
423 SubAPIManager api_manager;
424 api_manager.DisplayStatus();
426 ////////////////////////////////////
427 // Create VoiceEngine and sub API:s
429 voetest::VoETestManager test_manager;
430 if (!test_manager.Init()) {
433 test_manager.GetInterfaces();
436 if (test_type == Extended) {
437 VoEExtendedTest xtend(test_manager);
440 while (ext_selection != XSEL_None) {
441 if (ext_selection == XSEL_Base || ext_selection == XSEL_All) {
442 if ((result = xtend.TestBase()) == -1)
444 xtend.TestPassed("Base");
446 if (ext_selection == XSEL_CallReport || ext_selection == XSEL_All) {
447 if ((result = xtend.TestCallReport()) == -1)
449 xtend.TestPassed("CallReport");
451 if (ext_selection == XSEL_Codec || ext_selection == XSEL_All) {
452 if ((result = xtend.TestCodec()) == -1)
454 xtend.TestPassed("Codec");
456 if (ext_selection == XSEL_DTMF || ext_selection == XSEL_All) {
457 if ((result = xtend.TestDtmf()) == -1)
459 xtend.TestPassed("Dtmf");
461 if (ext_selection == XSEL_Encryption || ext_selection == XSEL_All) {
462 if ((result = xtend.TestEncryption()) == -1)
464 xtend.TestPassed("Encryption");
466 if (ext_selection == XSEL_ExternalMedia || ext_selection == XSEL_All) {
467 if ((result = xtend.TestExternalMedia()) == -1)
469 xtend.TestPassed("ExternalMedia");
471 if (ext_selection == XSEL_File || ext_selection == XSEL_All) {
472 if ((result = xtend.TestFile()) == -1)
474 xtend.TestPassed("File");
476 if (ext_selection == XSEL_Hardware || ext_selection == XSEL_All) {
477 if ((result = xtend.TestHardware()) == -1)
479 xtend.TestPassed("Hardware");
481 if (ext_selection == XSEL_NetEqStats || ext_selection == XSEL_All) {
482 if ((result = xtend.TestNetEqStats()) == -1)
484 xtend.TestPassed("NetEqStats");
486 if (ext_selection == XSEL_Network || ext_selection == XSEL_All) {
487 if ((result = xtend.TestNetwork()) == -1)
489 xtend.TestPassed("Network");
491 if (ext_selection == XSEL_RTP_RTCP || ext_selection == XSEL_All) {
492 if ((result = xtend.TestRTP_RTCP()) == -1)
494 xtend.TestPassed("RTP_RTCP");
496 if (ext_selection == XSEL_VideoSync || ext_selection == XSEL_All) {
497 if ((result = xtend.TestVideoSync()) == -1)
499 xtend.TestPassed("VideoSync");
501 if (ext_selection == XSEL_VolumeControl || ext_selection == XSEL_All) {
502 if ((result = xtend.TestVolumeControl()) == -1)
504 xtend.TestPassed("VolumeControl");
506 api_manager.GetExtendedMenuSelection(ext_selection);
507 } // while (extendedSel != XSEL_None)
508 } else if (test_type == Stress) {
509 VoEStressTest stressTest(test_manager);
510 result = stressTest.DoTest();
511 } else if (test_type == Unit) {
512 VoEUnitTest unitTest(test_manager);
513 result = unitTest.DoTest();
514 } else if (test_type == CPU) {
515 VoECpuTest cpuTest(test_manager);
516 result = cpuTest.DoTest();
518 // Should never end up here
525 int release_ok = test_manager.ReleaseInterfaces();
527 if ((0 == result) && (release_ok != -1)) {
528 TEST_LOG("\n\n*** All tests passed *** \n\n");
530 TEST_LOG("\n\n*** Test failed! *** \n");
535 } // namespace voetest
537 int RunInManualMode() {
538 using namespace voetest;
540 SubAPIManager api_manager;
541 api_manager.DisplayStatus();
543 printf("----------------------------\n");
544 printf("Select type of test\n\n");
545 printf(" (0) Quit\n");
546 printf(" (1) Standard test\n");
547 printf(" (2) Extended test(s)...\n");
548 printf(" (3) Stress test(s)...\n");
549 printf(" (4) Unit test(s)...\n");
550 printf(" (5) CPU & memory reference test [Windows]...\n");
554 dummy = scanf("%d", &selection);
556 ExtendedSelection ext_selection = XSEL_Invalid;
557 TestType test_type = Invalid;
563 test_type = Standard;
566 test_type = Extended;
567 while (!api_manager.GetExtendedMenuSelection(ext_selection))
580 TEST_LOG("Invalid selection!\n");
584 if (test_type == Standard) {
585 TEST_LOG("\n\n+++ Running standard tests +++\n\n");
587 // Currently, all googletest-rewritten tests are in the "automated" suite.
588 return RunInAutomatedMode();
591 // Function that can be called from other entry functions.
592 return run_auto_test(test_type, ext_selection);
595 // ----------------------------------------------------------------------------
597 // ----------------------------------------------------------------------------
599 #if !defined(WEBRTC_IOS)
600 int main(int argc, char** argv) {
601 // This function and RunInAutomatedMode is defined in automated_mode.cc
602 // to avoid macro clashes with googletest (for instance ASSERT_TRUE).
603 InitializeGoogleTest(&argc, argv);
604 google::ParseCommandLineFlags(&argc, &argv, true);
606 if (FLAGS_automated) {
607 return RunInAutomatedMode();
610 return RunInManualMode();
612 #endif //#if !defined(WEBRTC_IOS)