blob: a17d5cd92ce7036a8b365f8e972aa62f03db3d9f [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"
niklase@google.com470e71d2011-07-07 08:21:25 +000028
tina.legrand@webrtc.org554ae1a2011-12-16 10:09:04 +000029using webrtc::AudioCodingModule;
30using webrtc::Trace;
31
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +000032// This parameter is used to describe how to run the tests. It is normally
33// set to 1, but in auto test all printing is turned off, and the parameter is
34// set to 0.
35#define ACM_TEST_MODE 1
36
37// TODO(tlegrand): Add all tests as individual gtests, like already done for
38// TestAllCodecs (ACM_TEST_ALL_ENC_DEC).
39
niklase@google.com470e71d2011-07-07 08:21:25 +000040// Choose what tests to run by defining one or more of the following:
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +000041//
42// ACM_AUTO_TEST - Most common codecs and settings will be tested. All the
43// other tests will be activated.
44// ACM_TEST_ENC_DEC - You decide what to test in run time. Used for debugging
45// and for testing while implementing.
46// ACM_TEST_TWO_WAY - Mainly for debugging.
47// ACM_TEST_ALL_CODECS - Loop through all defined codecs and settings.
48// ACM_TEST_STEREO - Run stereo and spatial audio tests.
49// ACM_TEST_VAD_DTX - Run all VAD/DTX tests.
50// ACM_TEST_FEC - Test FEC (also called RED).
51// ACM_TEST_CODEC_SPEC_API - Test the iSAC has codec specfic APIs.
52// ACM_TEST_FULL_API - Test all APIs with threads (long test).
53
54#define ACM_AUTO_TEST
55//#define ACM_TEST_ENC_DEC
56//#define ACM_TEST_TWO_WAY
57//#define ACM_TEST_ALL_CODECS
58//#define ACM_TEST_STEREO
59//#define ACM_TEST_VAD_DTX
60//#define ACM_TEST_FEC
61//#define ACM_TEST_CODEC_SPEC_API
62//#define ACM_TEST_FULL_API
63
64// If Auto test is active, we activate all tests.
65#ifdef ACM_AUTO_TEST
66#undef ACM_TEST_MODE
67#define ACM_TEST_MODE 0
68#ifndef ACM_TEST_ALL_CODECS
69#define ACM_TEST_ALL_CODECS
70#endif
71#endif
niklase@google.com470e71d2011-07-07 08:21:25 +000072
tina.legrand@webrtc.org5e7ca602012-06-12 07:16:24 +000073void PopulateTests(std::vector<ACMTest*>* tests) {
74 Trace::CreateTrace();
75 Trace::SetTraceFile((webrtc::test::OutputPath() + "acm_trace.txt").c_str());
niklase@google.com470e71d2011-07-07 08:21:25 +000076
tina.legrand@webrtc.org5e7ca602012-06-12 07:16:24 +000077 printf("The following tests will be executed:\n");
niklase@google.com470e71d2011-07-07 08:21:25 +000078#ifdef ACM_AUTO_TEST
tina.legrand@webrtc.org5e7ca602012-06-12 07:16:24 +000079 printf(" ACM auto test\n");
80 tests->push_back(new webrtc::EncodeDecodeTest(0));
81 tests->push_back(new webrtc::TwoWayCommunication(0));
tina.legrand@webrtc.org5e7ca602012-06-12 07:16:24 +000082 tests->push_back(new webrtc::TestStereo(0));
83 tests->push_back(new webrtc::TestVADDTX(0));
84 tests->push_back(new webrtc::TestFEC(0));
85 tests->push_back(new webrtc::ISACTest(0));
niklase@google.com470e71d2011-07-07 08:21:25 +000086#endif
87#ifdef ACM_TEST_ENC_DEC
tina.legrand@webrtc.org5e7ca602012-06-12 07:16:24 +000088 printf(" ACM encode-decode test\n");
89 tests->push_back(new webrtc::EncodeDecodeTest(2));
niklase@google.com470e71d2011-07-07 08:21:25 +000090#endif
91#ifdef ACM_TEST_TWO_WAY
tina.legrand@webrtc.org5e7ca602012-06-12 07:16:24 +000092 printf(" ACM two-way communication test\n");
93 tests->push_back(new webrtc::TwoWayCommunication(1));
niklase@google.com470e71d2011-07-07 08:21:25 +000094#endif
niklase@google.com470e71d2011-07-07 08:21:25 +000095#ifdef ACM_TEST_STEREO
tina.legrand@webrtc.org5e7ca602012-06-12 07:16:24 +000096 printf(" ACM stereo test\n");
97 tests->push_back(new webrtc::TestStereo(1));
niklase@google.com470e71d2011-07-07 08:21:25 +000098#endif
99#ifdef ACM_TEST_VAD_DTX
tina.legrand@webrtc.org5e7ca602012-06-12 07:16:24 +0000100 printf(" ACM VAD-DTX test\n");
101 tests->push_back(new webrtc::TestVADDTX(1));
niklase@google.com470e71d2011-07-07 08:21:25 +0000102#endif
103#ifdef ACM_TEST_FEC
tina.legrand@webrtc.org5e7ca602012-06-12 07:16:24 +0000104 printf(" ACM FEC test\n");
105 tests->push_back(new webrtc::TestFEC(1));
niklase@google.com470e71d2011-07-07 08:21:25 +0000106#endif
107#ifdef ACM_TEST_CODEC_SPEC_API
tina.legrand@webrtc.org5e7ca602012-06-12 07:16:24 +0000108 printf(" ACM codec API test\n");
109 tests->push_back(new webrtc::ISACTest(1));
niklase@google.com470e71d2011-07-07 08:21:25 +0000110#endif
111#ifdef ACM_TEST_FULL_API
tina.legrand@webrtc.org5e7ca602012-06-12 07:16:24 +0000112 printf(" ACM full API test\n");
113 tests->push_back(new webrtc::APITest());
niklase@google.com470e71d2011-07-07 08:21:25 +0000114#endif
tina.legrand@webrtc.org5e7ca602012-06-12 07:16:24 +0000115 printf("\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000116}
117
kjellander@webrtc.org5490c712011-12-21 13:34:18 +0000118// TODO(kjellander): Make this a proper gtest instead of using this single test
119// to run all the tests.
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000120
121#ifdef ACM_TEST_ALL_CODECS
122TEST(AudioCodingModuleTest, TestAllCodecs) {
123 Trace::CreateTrace();
124 Trace::SetTraceFile((webrtc::test::OutputPath() +
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000125 "acm_allcodecs_trace.txt").c_str());
tina.legrand@webrtc.org50d5ca52012-06-18 13:35:52 +0000126 webrtc::TestAllCodecs(ACM_TEST_MODE).Perform();
127 Trace::ReturnTrace();
128}
129#endif
130
tina.legrand@webrtc.org73222cf2013-03-15 13:29:17 +0000131TEST(AudioCodingModuleTest, TestOpus) {
132 Trace::CreateTrace();
133 Trace::SetTraceFile((webrtc::test::OutputPath() +
tina.legrand@webrtc.orgd5726a12013-05-03 07:34:12 +0000134 "acm_opus_trace.txt").c_str());
tina.legrand@webrtc.org73222cf2013-03-15 13:29:17 +0000135 webrtc::OpusTest().Perform();
136 Trace::ReturnTrace();
137}
138
tina.legrand@webrtc.org5e7ca602012-06-12 07:16:24 +0000139TEST(AudioCodingModuleTest, RunAllTests) {
140 std::vector<ACMTest*> tests;
141 PopulateTests(&tests);
142 std::vector<ACMTest*>::iterator it;
143 for (it = tests.begin(); it < tests.end(); it++) {
144 (*it)->Perform();
145 delete (*it);
146 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000147
tina.legrand@webrtc.org5e7ca602012-06-12 07:16:24 +0000148 Trace::ReturnTrace();
149 printf("ACM test completed\n");
niklase@google.com470e71d2011-07-07 08:21:25 +0000150}