Home | History | Annotate | Download | only in auto_test
      1 /*
      2  *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
      3  *
      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.
      9  */
     10 
     11 #include "webrtc/voice_engine/test/auto_test/voe_standard_test.h"
     12 
     13 #include <assert.h>
     14 #include <stdio.h>
     15 #include <string.h>
     16 
     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"
     25 
     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 "
     31             "mode.");
     32 
     33 using namespace webrtc;
     34 
     35 namespace voetest {
     36 
     37 int dummy = 0;  // Dummy used in different functions to avoid warnings
     38 
     39 void SubAPIManager::DisplayStatus() const {
     40   TEST_LOG("Supported sub APIs:\n\n");
     41   if (_base)
     42     TEST_LOG("  Base\n");
     43   if (_codec)
     44     TEST_LOG("  Codec\n");
     45   if (_dtmf)
     46     TEST_LOG("  Dtmf\n");
     47   if (_externalMedia)
     48     TEST_LOG("  ExternalMedia\n");
     49   if (_file)
     50     TEST_LOG("  File\n");
     51   if (_hardware)
     52     TEST_LOG("  Hardware\n");
     53   if (_netEqStats)
     54     TEST_LOG("  NetEqStats\n");
     55   if (_network)
     56     TEST_LOG("  Network\n");
     57   if (_rtp_rtcp)
     58     TEST_LOG("  RTP_RTCP\n");
     59   if (_videoSync)
     60     TEST_LOG("  VideoSync\n");
     61   if (_volumeControl)
     62     TEST_LOG("  VolumeControl\n");
     63   if (_apm)
     64     TEST_LOG("  AudioProcessing\n");
     65   ANL();
     66   TEST_LOG("Excluded sub APIs:\n\n");
     67   if (!_base)
     68     TEST_LOG("  Base\n");
     69   if (!_codec)
     70     TEST_LOG("  Codec\n");
     71   if (!_dtmf)
     72     TEST_LOG("  Dtmf\n");
     73   if (!_externalMedia)
     74     TEST_LOG("  ExternamMedia\n");
     75   if (!_file)
     76     TEST_LOG("  File\n");
     77   if (!_hardware)
     78     TEST_LOG("  Hardware\n");
     79   if (!_netEqStats)
     80     TEST_LOG("  NetEqStats\n");
     81   if (!_network)
     82     TEST_LOG("  Network\n");
     83   if (!_rtp_rtcp)
     84     TEST_LOG("  RTP_RTCP\n");
     85   if (!_videoSync)
     86     TEST_LOG("  VideoSync\n");
     87   if (!_volumeControl)
     88     TEST_LOG("  VolumeControl\n");
     89   if (!_apm)
     90     TEST_LOG("  AudioProcessing\n");
     91   ANL();
     92 }
     93 
     94 VoETestManager::VoETestManager()
     95     : initialized_(false),
     96       voice_engine_(NULL),
     97       voe_base_(0),
     98       voe_codec_(0),
     99       voe_dtmf_(0),
    100       voe_xmedia_(0),
    101       voe_file_(0),
    102       voe_hardware_(0),
    103       voe_network_(0),
    104 #ifdef WEBRTC_VOICE_ENGINE_NETEQ_STATS_API
    105       voe_neteq_stats_(NULL),
    106 #endif
    107       voe_rtp_rtcp_(0),
    108       voe_vsync_(0),
    109       voe_volume_control_(0),
    110       voe_apm_(0) {
    111 }
    112 
    113 VoETestManager::~VoETestManager() {
    114 }
    115 
    116 bool VoETestManager::Init() {
    117   if (initialized_)
    118     return true;
    119 
    120   if (VoiceEngine::SetTraceFile(NULL) != -1) {
    121     // should not be possible to call a Trace method before the VoE is
    122     // created
    123     TEST_LOG("\nError at line: %i (VoiceEngine::SetTraceFile()"
    124       "should fail)!\n", __LINE__);
    125     return false;
    126   }
    127 
    128   voice_engine_ = VoiceEngine::Create();
    129   if (!voice_engine_) {
    130     TEST_LOG("Failed to create VoiceEngine\n");
    131     return false;
    132   }
    133 
    134   return true;
    135 }
    136 
    137 void VoETestManager::GetInterfaces() {
    138   if (voice_engine_) {
    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_);
    149 #endif
    150     voe_hardware_ = VoEHardware::GetInterface(voice_engine_);
    151     // Set the audio layer to use in all tests
    152     if (voe_hardware_) {
    153       int res = voe_hardware_->SetAudioDeviceLayer(TESTED_AUDIO_LAYER);
    154       if (res < 0) {
    155         printf("\nERROR: failed to set audio layer to use in "
    156           "testing\n");
    157       } else {
    158         printf("\nAudio layer %d will be used in testing\n",
    159                TESTED_AUDIO_LAYER);
    160       }
    161     }
    162 #ifdef _TEST_XMEDIA_
    163     voe_xmedia_ = VoEExternalMedia::GetInterface(voice_engine_);
    164 #endif
    165 #ifdef WEBRTC_VOICE_ENGINE_NETEQ_STATS_API
    166     voe_neteq_stats_ = VoENetEqStats::GetInterface(voice_engine_);
    167 #endif
    168   }
    169 }
    170 
    171 int VoETestManager::ReleaseInterfaces() {
    172   bool releaseOK(true);
    173 
    174   if (voe_base_) {
    175     voe_base_->Release();
    176     voe_base_ = NULL;
    177   }
    178   if (voe_codec_) {
    179     voe_codec_->Release();
    180     voe_codec_ = NULL;
    181   }
    182   if (voe_volume_control_) {
    183     voe_volume_control_->Release();
    184     voe_volume_control_ = NULL;
    185   }
    186   if (voe_dtmf_) {
    187     voe_dtmf_->Release();
    188     voe_dtmf_ = NULL;
    189   }
    190   if (voe_rtp_rtcp_) {
    191     voe_rtp_rtcp_->Release();
    192     voe_rtp_rtcp_ = NULL;
    193   }
    194   if (voe_apm_) {
    195     voe_apm_->Release();
    196     voe_apm_ = NULL;
    197   }
    198   if (voe_network_) {
    199     voe_network_->Release();
    200     voe_network_ = NULL;
    201   }
    202   if (voe_file_) {
    203     voe_file_->Release();
    204     voe_file_ = NULL;
    205   }
    206 #ifdef _TEST_VIDEO_SYNC_
    207   if (voe_vsync_) {
    208     voe_vsync_->Release();
    209     voe_vsync_ = NULL;
    210   }
    211 #endif
    212   if (voe_hardware_) {
    213     voe_hardware_->Release();
    214     voe_hardware_ = NULL;
    215   }
    216 #ifdef _TEST_XMEDIA_
    217   if (voe_xmedia_) {
    218     voe_xmedia_->Release();
    219     voe_xmedia_ = NULL;
    220   }
    221 #endif
    222 #ifdef WEBRTC_VOICE_ENGINE_NETEQ_STATS_API
    223   if (voe_neteq_stats_) {
    224     voe_neteq_stats_->Release();
    225     voe_neteq_stats_ = NULL;
    226   }
    227 #endif
    228   if (false == VoiceEngine::Delete(voice_engine_)) {
    229     TEST_LOG("\n\nVoiceEngine::Delete() failed. \n");
    230     releaseOK = false;
    231   }
    232 
    233   if (VoiceEngine::SetTraceFile(NULL) != -1) {
    234     TEST_LOG("\nError at line: %i (VoiceEngine::SetTraceFile()"
    235       "should fail)!\n", __LINE__);
    236   }
    237 
    238   return (releaseOK == true) ? 0 : -1;
    239 }
    240 
    241 int run_auto_test(TestType test_type) {
    242   assert(test_type != Standard);
    243 
    244   SubAPIManager api_manager;
    245   api_manager.DisplayStatus();
    246 
    247   ////////////////////////////////////
    248   // Create VoiceEngine and sub API:s
    249 
    250   voetest::VoETestManager test_manager;
    251   if (!test_manager.Init()) {
    252     return -1;
    253   }
    254   test_manager.GetInterfaces();
    255 
    256   int result = -1;
    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();
    263   } else {
    264     // Should never end up here
    265     assert(false);
    266   }
    267 
    268   //////////////////
    269   // Release/Delete
    270 
    271   int release_ok = test_manager.ReleaseInterfaces();
    272 
    273   if ((0 == result) && (release_ok != -1)) {
    274     TEST_LOG("\n\n*** All tests passed *** \n\n");
    275   } else {
    276     TEST_LOG("\n\n*** Test failed! *** \n");
    277   }
    278 
    279   return 0;
    280 }
    281 }  // namespace voetest
    282 
    283 int RunInManualMode() {
    284   using namespace voetest;
    285 
    286   SubAPIManager api_manager;
    287   api_manager.DisplayStatus();
    288 
    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");
    297   printf("\n: ");
    298 
    299   int selection(0);
    300   dummy = scanf("%d", &selection);
    301 
    302   TestType test_type = Invalid;
    303   switch (selection) {
    304     case 0:
    305       return 0;
    306     case 1:
    307       test_type = Standard;
    308       break;
    309     case 2:
    310       break;
    311     case 3:
    312       test_type = Stress;
    313       break;
    314     case 4:
    315       break;
    316     case 5:
    317       test_type = CPU;
    318       break;
    319     default:
    320       TEST_LOG("Invalid selection!\n");
    321       return 0;
    322   }
    323 
    324   if (test_type == Standard) {
    325     TEST_LOG("\n\n+++ Running standard tests +++\n\n");
    326 
    327     // Currently, all googletest-rewritten tests are in the "automated" suite.
    328     return RunInAutomatedMode();
    329   }
    330 
    331   // Function that can be called from other entry functions.
    332   return run_auto_test(test_type);
    333 }
    334 
    335 // ----------------------------------------------------------------------------
    336 //                                       main
    337 // ----------------------------------------------------------------------------
    338 
    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);
    348 
    349   if (FLAGS_automated) {
    350     return RunInAutomatedMode();
    351   }
    352 
    353   return RunInManualMode();
    354 }
    355 #endif //#if !defined(WEBRTC_IOS)
    356