blob: 923e5371e652bb6ed36ee7afc244ecd45c16e291 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
tina.legrand@webrtc.org16b6b902012-04-12 11:02:38 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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 <stdio.h>
kjellander@webrtc.org5490c712011-12-21 13:34:18 +000012#include <string>
niklase@google.com470e71d2011-07-07 08:21:25 +000013#include <vector>
14
tina.legrand@webrtc.org73222cf2013-03-15 13:29:17 +000015#include "testing/gtest/include/gtest/gtest.h"
16#include "webrtc/modules/audio_coding/main/interface/audio_coding_module.h"
17#include "webrtc/modules/audio_coding/main/test/APITest.h"
18#include "webrtc/modules/audio_coding/main/test/EncodeDecodeTest.h"
19#include "webrtc/modules/audio_coding/main/test/iSACTest.h"
20#include "webrtc/modules/audio_coding/main/test/opus_test.h"
21#include "webrtc/modules/audio_coding/main/test/TestAllCodecs.h"
22#include "webrtc/modules/audio_coding/main/test/TestFEC.h"
23#include "webrtc/modules/audio_coding/main/test/TestStereo.h"
24#include "webrtc/modules/audio_coding/main/test/TestVADDTX.h"
25#include "webrtc/modules/audio_coding/main/test/TwoWayCommunication.h"
26#include "webrtc/system_wrappers/interface/trace.h"
27#include "webrtc/test/testsupport/fileutils.h"
henrike@webrtc.org89c67402013-08-02 16:53:47 +000028#include "webrtc/test/testsupport/gtest_disable.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000029
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000030using webrtc::AudioCodingModule;
31using webrtc::Trace;
32
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +000033// This parameter is used to describe how to run the tests. It is normally
34// set to 1, but in auto test all printing is turned off, and the parameter is
35// set to 0.
36#define ACM_TEST_MODE 1
37
38// TODO(tlegrand): Add all tests as individual gtests, like already done for
39// TestAllCodecs (ACM_TEST_ALL_ENC_DEC).
40
niklase@google.com470e71d2011-07-07 08:21:25 +000041// Choose what tests to run by defining one or more of the following:
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +000042//
43// ACM_AUTO_TEST - Most common codecs and settings will be tested. All the
44// other tests will be activated.
45// ACM_TEST_ENC_DEC - You decide what to test in run time. Used for debugging
46// and for testing while implementing.
47// ACM_TEST_TWO_WAY - Mainly for debugging.
48// ACM_TEST_ALL_CODECS - Loop through all defined codecs and settings.
49// ACM_TEST_STEREO - Run stereo and spatial audio tests.
50// ACM_TEST_VAD_DTX - Run all VAD/DTX tests.
51// ACM_TEST_FEC - Test FEC (also called RED).
52// ACM_TEST_CODEC_SPEC_API - Test the iSAC has codec specfic APIs.
53// ACM_TEST_FULL_API - Test all APIs with threads (long test).
54
55#define ACM_AUTO_TEST
56//#define ACM_TEST_ENC_DEC
57//#define ACM_TEST_TWO_WAY
58//#define ACM_TEST_ALL_CODECS
59//#define ACM_TEST_STEREO
60//#define ACM_TEST_VAD_DTX
61//#define ACM_TEST_FEC
62//#define ACM_TEST_CODEC_SPEC_API
63//#define ACM_TEST_FULL_API
64
65// If Auto test is active, we activate all tests.
66#ifdef ACM_AUTO_TEST
67#undef ACM_TEST_MODE
68#define ACM_TEST_MODE 0
69#ifndef ACM_TEST_ALL_CODECS
70#define ACM_TEST_ALL_CODECS
71#endif
72#endif
niklase@google.com470e71d2011-07-07 08:21:25 +000073
tina.legrand@webrtc.org5e7ca602012-06-12 07:16:24 +000074void PopulateTests(std::vector<ACMTest*>* tests) {
75 Trace::CreateTrace();
76 Trace::SetTraceFile((webrtc::test::OutputPath() + "acm_trace.txt").c_str());
niklase@google.com470e71d2011-07-07 08:21:25 +000077
tina.legrand@webrtc.org5e7ca602012-06-12 07:16:24 +000078 printf("The following tests will be executed:\n");
niklase@google.com470e71d2011-07-07 08:21:25 +000079#ifdef ACM_AUTO_TEST
tina.legrand@webrtc.org5e7ca602012-06-12 07:16:24 +000080 printf(" ACM auto test\n");
81 tests->push_back(new webrtc::EncodeDecodeTest(0));
82 tests->push_back(new webrtc::TwoWayCommunication(0));
tina.legrand@webrtc.org5e7ca602012-06-12 07:16:24 +000083 tests->push_back(new webrtc::TestStereo(0));
84 tests->push_back(new webrtc::TestVADDTX(0));
85 tests->push_back(new webrtc::TestFEC(0));
86 tests->push_back(new webrtc::ISACTest(0));
niklase@google.com470e71d2011-07-07 08:21:25 +000087#endif
88#ifdef ACM_TEST_ENC_DEC
tina.legrand@webrtc.org5e7ca602012-06-12 07:16:24 +000089 printf(" ACM encode-decode test\n");
90 tests->push_back(new webrtc::EncodeDecodeTest(2));
niklase@google.com470e71d2011-07-07 08:21:25 +000091#endif
92#ifdef ACM_TEST_TWO_WAY
tina.legrand@webrtc.org5e7ca602012-06-12 07:16:24 +000093 printf(" ACM two-way communication test\n");
94 tests->push_back(new webrtc::TwoWayCommunication(1));
niklase@google.com470e71d2011-07-07 08:21:25 +000095#endif
niklase@google.com470e71d2011-07-07 08:21:25 +000096#ifdef ACM_TEST_STEREO
tina.legrand@webrtc.org5e7ca602012-06-12 07:16:24 +000097 printf(" ACM stereo test\n");
98 tests->push_back(new webrtc::TestStereo(1));
niklase@google.com470e71d2011-07-07 08:21:25 +000099#endif
100#ifdef ACM_TEST_VAD_DTX
tina.legrand@webrtc.org5e7ca602012-06-12 07:16:24 +0000101 printf(" ACM VAD-DTX test\n");
102 tests->push_back(new webrtc::TestVADDTX(1));
niklase@google.com470e71d2011-07-07 08:21:25 +0000103#endif
104#ifdef ACM_TEST_FEC
tina.legrand@webrtc.org5e7ca602012-06-12 07:16:24 +0000105 printf(" ACM FEC test\n");
106 tests->push_back(new webrtc::TestFEC(1));
niklase@google.com470e71d2011-07-07 08:21:25 +0000107#endif
108#ifdef ACM_TEST_CODEC_SPEC_API
tina.legrand@webrtc.org5e7ca602012-06-12 07:16:24 +0000109 printf(" ACM codec API test\n");
110 tests->push_back(new webrtc::ISACTest(1));
niklase@google.com470e71d2011-07-07 08:21:25 +0000111#endif
112#ifdef ACM_TEST_FULL_API
tina.legrand@webrtc.org5e7ca602012-06-12 07:16:24 +0000113 printf(" ACM full API test\n");
114 tests->push_back(new webrtc::APITest());
niklase@google.com470e71d2011-07-07 08:21:25 +0000115#endif
tina.legrand@webrtc.org5e7ca602012-06-12 07:16:24 +0000116 printf("\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000117}
118
kjellander@webrtc.org5490c712011-12-21 13:34:18 +0000119// TODO(kjellander): Make this a proper gtest instead of using this single test
120// to run all the tests.
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000121
122#ifdef ACM_TEST_ALL_CODECS
123TEST(AudioCodingModuleTest, TestAllCodecs) {
124 Trace::CreateTrace();
125 Trace::SetTraceFile((webrtc::test::OutputPath() +
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000126 "acm_allcodecs_trace.txt").c_str());
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000127 webrtc::TestAllCodecs(ACM_TEST_MODE).Perform();
128 Trace::ReturnTrace();
129}
130#endif
131
tina.legrand@webrtc.org73222cf2013-03-15 13:29:17 +0000132TEST(AudioCodingModuleTest, TestOpus) {
133 Trace::CreateTrace();
134 Trace::SetTraceFile((webrtc::test::OutputPath() +
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000135 "acm_opus_trace.txt").c_str());
tina.legrand@webrtc.org73222cf2013-03-15 13:29:17 +0000136 webrtc::OpusTest().Perform();
137 Trace::ReturnTrace();
138}
139
henrike@webrtc.org89c67402013-08-02 16:53:47 +0000140TEST(AudioCodingModuleTest, DISABLED_ON_ANDROID(RunAllTests)) {
tina.legrand@webrtc.org5e7ca602012-06-12 07:16:24 +0000141 std::vector<ACMTest*> tests;
142 PopulateTests(&tests);
143 std::vector<ACMTest*>::iterator it;
144 for (it = tests.begin(); it < tests.end(); it++) {
145 (*it)->Perform();
146 delete (*it);
147 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000148
tina.legrand@webrtc.org5e7ca602012-06-12 07:16:24 +0000149 Trace::ReturnTrace();
150 printf("ACM test completed\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000151}