Rewrote the hold and netw-before-streaming tests.

Rewrote the hold test.

Abstracted out resource handling and created a new fixture for starting and stopping playing.

Rewrote network-before-streaming.

BUG=
TEST=voe_auto_test

Review URL: http://webrtc-codereview.appspot.com/331001

git-svn-id: http://webrtc.googlecode.com/svn/trunk@1228 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
phoglund@webrtc.org 2011-12-19 09:36:03 +00:00
parent 398af2337b
commit 188fc35e07
11 changed files with 292 additions and 101 deletions

View File

@ -7,12 +7,11 @@
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "gtest/gtest.h"
int RunInAutomatedMode(int argc, char** argv) {
// Initialize the testing framework.
testing::InitGoogleTest(&argc, argv);
// Run tests.
return RUN_ALL_TESTS();
}

View File

@ -0,0 +1,29 @@
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "resource_manager.h"
#include "testsupport/fileutils.h"
ResourceManager::ResourceManager() {
std::string filename = "audio_long16.pcm";
#if defined(WEBRTC_ANDROID)
long_audio_file_path_ = "/sdcard/" + filename;
#else
std::string resource_path = webrtc::test::ProjectRootPath();
if (resource_path == webrtc::test::kCannotFindProjectRootDir) {
long_audio_file_path_ = "";
} else {
long_audio_file_path_ =
resource_path + "test/data/voice_engine/" + filename;
}
#endif
}

View File

@ -0,0 +1,30 @@
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef SRC_VOICE_ENGINE_MAIN_TEST_AUTO_TEST_RESOURCE_MANAGER_H_
#define SRC_VOICE_ENGINE_MAIN_TEST_AUTO_TEST_RESOURCE_MANAGER_H_
#include <string>
class ResourceManager {
public:
ResourceManager();
// Returns the full path to a long audio file.
// Returns the empty string on failure.
const std::string& long_audio_file_path() const {
return long_audio_file_path_;
}
private:
std::string long_audio_file_path_;
};
#endif // SRC_VOICE_ENGINE_MAIN_TEST_AUTO_TEST_RESOURCE_MANAGER_H_

View File

@ -18,7 +18,9 @@ class TestErrorObserver;
// This fixture initializes the voice engine in addition to the work
// done by the before-initialization fixture. It also registers an error
// observer which will fail tests on error callbacks.
// observer which will fail tests on error callbacks. This fixture is
// useful to tests that want to run before we have started any form of
// streaming through the voice engine.
class AfterInitializationFixture : public BeforeInitializationFixture {
public:
AfterInitializationFixture();

View File

@ -0,0 +1,66 @@
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "after_streaming_fixture.h"
#include <cstring>
#include "voice_engine_defines.h"
static const char* kLoopbackIp = "127.0.0.1";
AfterStreamingFixture::AfterStreamingFixture()
: channel_(voe_base_->CreateChannel()) {
EXPECT_GE(channel_, 0);
const std::string& input_file = resource_manager_.long_audio_file_path();
ASSERT_FALSE(input_file.empty());
SetUpLocalPlayback();
StartPlaying(input_file);
}
AfterStreamingFixture::~AfterStreamingFixture() {
voe_file_->StopPlayingFileAsMicrophone(channel_);
voe_base_->StopSend(channel_);
voe_base_->StopPlayout(channel_);
voe_base_->StopReceive(channel_);
voe_base_->DeleteChannel(channel_);
}
void AfterStreamingFixture::SetUpLocalPlayback() {
EXPECT_EQ(0, voe_base_->SetSendDestination(channel_, 8000, kLoopbackIp));
EXPECT_EQ(0, voe_base_->SetLocalReceiver(0, 8000));
webrtc::CodecInst codec;
codec.channels = 1;
codec.pacsize = 160;
codec.plfreq = 8000;
codec.pltype = 0;
codec.rate = 64000;
strcpy(codec.plname, "PCMU");
voe_codec_->SetSendCodec(channel_, codec);
}
void AfterStreamingFixture::StartPlaying(const std::string& input_file) {
EXPECT_EQ(0, voe_base_->StartReceive(0));
EXPECT_EQ(0, voe_base_->StartPlayout(0));
EXPECT_EQ(0, voe_base_->StartSend(0));
EXPECT_EQ(0, voe_file_->StartPlayingFileAsMicrophone(
0, input_file.c_str(), true, true));
}
void AfterStreamingFixture::Sleep(long milliseconds) {
// Implementation note: This method is used to reduce usage of the macro and
// avoid ugly errors in Eclipse (its parser can't deal with the sleep macro).
SLEEP(milliseconds);
}

View File

@ -0,0 +1,38 @@
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef SRC_VOICE_ENGINE_MAIN_TEST_AUTO_TEST_STANDARD_AFTER_STREAMING_H_
#define SRC_VOICE_ENGINE_MAIN_TEST_AUTO_TEST_STANDARD_AFTER_STREAMING_H_
#include "after_initialization_fixture.h"
#include "resource_manager.h"
// This fixture will, in addition to the work done by its superclasses,
// create a channel and start playing a file through the fake microphone
// to simulate microphone input. The purpose is to make it convenient
// to write tests that require microphone input.
class AfterStreamingFixture : public AfterInitializationFixture {
public:
AfterStreamingFixture();
virtual ~AfterStreamingFixture();
protected:
int channel_;
ResourceManager resource_manager_;
// Use this sleep function to sleep in test (avoid sleep macro).
void Sleep(long milliseconds);
private:
void SetUpLocalPlayback();
void StartPlaying(const std::string& input_file);
};
#endif // SRC_VOICE_ENGINE_MAIN_TEST_AUTO_TEST_STANDARD_AFTER_STREAMING_H_

View File

@ -0,0 +1,43 @@
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "after_streaming_fixture.h"
// Note: This class includes sleeps and requires manual verification.
class ManualHoldTest : public AfterStreamingFixture {
};
TEST_F(ManualHoldTest, SetOnHoldStatusBlockAudio) {
TEST_LOG("Channel not on hold => should hear audio.\n");
Sleep(2000);
TEST_LOG("Put channel on hold => should *not* hear audio.\n");
EXPECT_EQ(0, voe_base_->SetOnHoldStatus(channel_, true));
Sleep(2000);
TEST_LOG("Remove on hold => should hear audio again.\n");
EXPECT_EQ(0, voe_base_->SetOnHoldStatus(channel_, false));
Sleep(2000);
TEST_LOG("Put sending on hold => should *not* hear audio.\n");
EXPECT_EQ(0, voe_base_->SetOnHoldStatus(channel_, true, webrtc::kHoldSendOnly));
Sleep(2000);
}
TEST_F(ManualHoldTest, SetOnHoldStatusBlocksLocalFileAudio) {
TEST_LOG("Start playing a file locally => "
"you should now hear this file being played out.\n");
voe_file_->StopPlayingFileAsMicrophone(channel_);
EXPECT_EQ(0, voe_file_->StartPlayingFileLocally(
channel_, resource_manager_.long_audio_file_path().c_str(), true));
Sleep(2000);
TEST_LOG("Put playing on hold => should *not* hear audio.\n");
EXPECT_EQ(0, voe_base_->SetOnHoldStatus(
channel_, true, webrtc::kHoldPlayOnly));
Sleep(2000);
}

View File

@ -0,0 +1,55 @@
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "after_initialization_fixture.h"
class NetworkBeforeStreamingTest : public AfterInitializationFixture {
protected:
void SetUp() {
channel_ = voe_base_->CreateChannel();
}
void TearDown() {
voe_base_->DeleteChannel(channel_);
}
int channel_;
};
TEST_F(NetworkBeforeStreamingTest,
GetSourceInfoReturnsEmptyValuesForUnconfiguredChannel) {
char src_ip[32] = "0.0.0.0";
int src_rtp_port = 1234;
int src_rtcp_port = 1235;
EXPECT_EQ(0, voe_network_->GetSourceInfo(
channel_, src_rtp_port, src_rtcp_port, src_ip));
EXPECT_EQ(0, src_rtp_port);
EXPECT_EQ(0, src_rtcp_port);
EXPECT_STRCASEEQ("", src_ip);
}
TEST_F(NetworkBeforeStreamingTest,
GetSourceFilterReturnsEmptyValuesForUnconfiguredChannel) {
int filter_port = -1;
int filter_port_rtcp = -1;
char filter_ip[32] = "0.0.0.0";
EXPECT_EQ(0, voe_network_->GetSourceFilter(
channel_, filter_port, filter_port_rtcp, filter_ip));
EXPECT_EQ(0, filter_port);
EXPECT_EQ(0, filter_port_rtcp);
EXPECT_STRCASEEQ("", filter_ip);
}
TEST_F(NetworkBeforeStreamingTest, SetSourceFilterSucceeds) {
EXPECT_EQ(0, voe_network_->SetSourceFilter(channel_, 0));
}

View File

@ -34,7 +34,6 @@
#include "critical_section_wrapper.h"
#include "event_wrapper.h"
#include "thread_wrapper.h"
#include "testsupport/fileutils.h"
#ifdef _TEST_NETEQ_STATS_
#include "../../interface/voe_neteq_stats.h" // Not available in delivery folder
@ -621,9 +620,7 @@ VoETestManager::VoETestManager()
voe_rtp_rtcp_(0),
voe_vsync_(0),
voe_volume_control_(0),
voe_apm_(0),
resource_path_(),
audio_filename_()
voe_apm_(0)
{
}
@ -642,18 +639,6 @@ bool VoETestManager::Init() {
return false;
}
#if defined(WEBRTC_ANDROID)
resource_path_ = "/sdcard/";
#else
resource_path_ = webrtc::test::ProjectRootPath();
if (resource_path_ == webrtc::test::kCannotFindProjectRootDir) {
TEST_LOG("Failed to get project root directory\n");
return false;
}
resource_path_ += "test/data/voice_engine/";
#endif
audio_filename_ = resource_path_ + "audio_long16.pcm";
voice_engine_ = VoiceEngine::Create();
if (!voice_engine_) {
TEST_LOG("Failed to create VoiceEngine\n");
@ -921,46 +906,6 @@ int VoETestManager::SetUp() {
return 0;
}
int VoETestManager::TestNetworkBeforeStreaming() {
///////////////////////////////////////////////
// Network (test before streaming is activated)
#ifdef _TEST_NETWORK_
TEST_LOG("\n\n+++ Network tests +++\n\n");
#ifndef WEBRTC_EXTERNAL_TRANSPORT
int filter_port = -1;
int filter_port_rtcp = -1;
char src_ip[32] = "0.0.0.0";
char filter_ip[32] = "0.0.0.0";
TEST_LOG("GetSourceInfo \n");
int src_rtp_port = 1234;
int src_rtcp_port = 1235;
TEST_MUSTPASS(voe_network_->GetSourceInfo(0, src_rtp_port, src_rtcp_port,
src_ip));
TEST_MUSTPASS(0 != src_rtp_port);
TEST_MUSTPASS(0 != src_rtcp_port);
TEST_MUSTPASS(_stricmp(src_ip, ""));
TEST_LOG("GetSourceFilter \n");
TEST_MUSTPASS(voe_network_->GetSourceFilter(0, filter_port, filter_port_rtcp,
filter_ip));
TEST_MUSTPASS(0 != filter_port);
TEST_MUSTPASS(0 != filter_port_rtcp);
TEST_MUSTPASS(_stricmp(filter_ip, ""));
TEST_LOG("SetSourceFilter \n");
TEST_MUSTPASS(voe_network_->SetSourceFilter(0, src_rtp_port));
#else
TEST_LOG("Skipping network tests - WEBRTC_EXTERNAL_TRANSPORT is defined \n");
#endif // #ifndef WEBRTC_EXTERNAL_TRANSPORT
#else
TEST_LOG("\n\n+++ Network tests NOT ENABLED +++\n");
#endif
return 0;
}
int VoETestManager::TestStartStreaming(FakeExternalTransport& channel0_transport) {
TEST_LOG("\n\n+++ Starting streaming +++\n\n");
@ -1026,35 +971,8 @@ int VoETestManager::TestStartPlaying() {
return 0;
}
int VoETestManager::TestHoldAndNetEq() {
int VoETestManager::TestNetEq() {
#ifdef _TEST_BASE_
TEST_LOG("Put channel on hold => should *not* hear audio \n");
// HOLD_SEND_AND_PLAY is the default mode.
TEST_MUSTPASS(voe_base_->SetOnHoldStatus(0, true));
SLEEP(2000);
TEST_LOG("Remove on hold => should hear audio again \n");
TEST_MUSTPASS(voe_base_->SetOnHoldStatus(0, false));
SLEEP(2000);
TEST_LOG("Put sending on hold => should *not* hear audio \n");
TEST_MUSTPASS(voe_base_->SetOnHoldStatus(0, true, kHoldSendOnly));
SLEEP(2000);
if (voe_file_) {
TEST_LOG("Start playing a file locally => "
"you should now hear this file being played out \n");
TEST_MUSTPASS(voe_file_->StartPlayingFileLocally(0, AudioFilename(),
true));
SLEEP(2000);
}
TEST_LOG("Put playing on hold => should *not* hear audio \n");
TEST_MUSTPASS(voe_base_->SetOnHoldStatus(0, true, kHoldPlayOnly));
SLEEP(2000);
TEST_LOG("Remove on hold => should hear audio again \n");
if (voe_file_) {
TEST_MUSTPASS(voe_file_->StopPlayingFileLocally(0));
}
TEST_MUSTPASS(voe_base_->SetOnHoldStatus(0, false));
SLEEP(2000);
NetEqModes mode;
TEST_MUSTPASS(voe_base_->GetNetEQPlayoutMode(0, mode));
TEST_MUSTPASS(mode != kNetEqDefault);
@ -1412,23 +1330,24 @@ int VoETestManager::TestCodecs() {
}
int VoETestManager::DoStandardTest() {
// Ensure we have all input files:
TEST_MUSTPASS(!strcmp("", AudioFilename()));
TEST_LOG("\n\n+++ Base tests +++\n\n");
if (SetUp() != 0) return -1;
if (TestNetworkBeforeStreaming() != 0) return -1;
// TODO(qhogpat): this gets verified way later - quite ugly. Make sure to
// put this into setup when rewriting the test that requires this.
TEST_MUSTPASS(voe_rtp_rtcp_->SetRTCP_CNAME(0, "Niklas"));
TEST_MUSTPASS(voe_rtp_rtcp_->SetLocalSSRC(0, 1234));
voe_network_->SetSourceFilter(0, 0);
FakeExternalTransport channel0_transport(voe_network_);
if (TestStartStreaming(channel0_transport) != 0) return -1;
if (TestStartPlaying() != 0) return -1;
if (TestHoldAndNetEq() != 0) return -1;
if (TestNetEq() != 0) return -1;
if (TestCodecs() != 0) return -1;
/////////////////////////

View File

@ -14,15 +14,15 @@
#include <stdio.h>
#include <string>
#include "resource_manager.h"
#include "voe_audio_processing.h"
#include "voe_base.h"
#include "voe_dtmf.h"
#include "voe_errors.h"
#include "voe_file.h"
#include "voe_rtp_rtcp.h"
#include "voe_test_defines.h"
#include "voe_test_interface.h"
#include "voe_errors.h"
#include "voe_base.h"
#include "voe_file.h"
#include "voe_dtmf.h"
#include "voe_rtp_rtcp.h"
#include "voe_audio_processing.h"
#ifdef WEBRTC_VOICE_ENGINE_CALL_REPORT_API
#include "voe_call_report.h"
#endif
@ -273,7 +273,11 @@ class VoETestManager {
int DoStandardTest();
const char* AudioFilename() const {
return audio_filename_.c_str();
const std::string& result = resource_manager_.long_audio_file_path();
if (result.length() == 0) {
TEST_LOG("ERROR: Failed to open input file!");
}
return result.c_str();
}
VoiceEngine* VoiceEnginePtr() const {
@ -340,7 +344,7 @@ class VoETestManager {
int TestNetworkBeforeStreaming();
int TestStartStreaming(FakeExternalTransport& channel0_transport);
int TestStartPlaying();
int TestHoldAndNetEq();
int TestNetEq();
int TestCodecs();
bool initialized_;
@ -363,8 +367,7 @@ class VoETestManager {
VoEVolumeControl* voe_volume_control_;
VoEAudioProcessing* voe_apm_;
std::string resource_path_;
std::string audio_filename_;
ResourceManager resource_manager_;
};
} // namespace voetest

View File

@ -22,17 +22,24 @@
'include_dirs': [
'auto_test',
'<(webrtc_root)/modules/interface',
# TODO(phoglund): We only depend on voice_engine_defines.h here -
# move that file to interface and then remove this dependency.
'<(webrtc_root)/voice_engine/main/source',
'<(webrtc_root)/modules/audio_device/main/interface',
],
'sources': [
'auto_test/automated_mode.cc',
'auto_test/standard/after_initialization_fixture.cc',
'auto_test/standard/after_streaming_fixture.cc',
'auto_test/standard/before_initialization_fixture.cc',
'auto_test/standard/codec_before_streaming_test.cc',
'auto_test/standard/hardware_before_initializing_test.cc',
'auto_test/standard/hardware_before_streaming_test.cc',
'auto_test/standard/manual_hold_test.cc',
'auto_test/standard/network_before_streaming_test.cc',
'auto_test/standard/rtp_rtcp_before_streaming_test.cc',
'auto_test/standard/voe_base_misc_test.cc',
'auto_test/resource_manager.cc',
'auto_test/voe_cpu_test.cc',
'auto_test/voe_cpu_test.h',
'auto_test/voe_extended_test.cc',