Fix the flakiness in FileBeforeStreamingTest

BUG = 619
TEST = voe_auto_test
Review URL: https://webrtc-codereview.appspot.com/658006

git-svn-id: http://webrtc.googlecode.com/svn/trunk@2437 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
braveyao@webrtc.org
2012-06-22 10:41:11 +00:00
parent 7450896a12
commit 77e18124f9

View File

@ -11,19 +11,20 @@
#include "after_initialization_fixture.h" #include "after_initialization_fixture.h"
#include "test/testsupport/fileutils.h" #include "test/testsupport/fileutils.h"
namespace { namespace {
const int kSampleRateHz = 16000; const int kSampleRateHz = 16000;
const int kTestDurationMs = 1000; const int kTestDurationMs = 1000;
const int16_t kInputValue = 15000; const int kSkipOutputMs = 50;
const int16_t kSilenceValue = 0; const int16_t kInputValue = 15000;
const int16_t kSilenceValue = 0;
} // namespace } // namespace
class FileBeforeStreamingTest : public AfterInitializationFixture { class FileBeforeStreamingTest : public AfterInitializationFixture {
protected: protected:
FileBeforeStreamingTest() FileBeforeStreamingTest()
: input_filename_(webrtc::test::OutputPath() + "file_test_input.pcm"), : input_filename_(webrtc::test::OutputPath() + "file_test_input.pcm"),
output_filename_(webrtc::test::OutputPath() + "file_test_output.pcm") { output_filename_(webrtc::test::OutputPath() + "file_test_output.pcm") {
} }
@ -34,57 +35,60 @@ class FileBeforeStreamingTest : public AfterInitializationFixture {
void TearDown() { void TearDown() {
voe_base_->DeleteChannel(channel_); voe_base_->DeleteChannel(channel_);
} }
// TODO(andrew): consolidate below methods in a shared place? // TODO(andrew): consolidate below methods in a shared place?
// Generate input file with constant values as |kInputValue|. The file // Generate input file with constant values as |kInputValue|. The file
// will be one second longer than the duration of the test. // will be one second longer than the duration of the test.
void GenerateInputFile() { void GenerateInputFile() {
FILE* input_file = fopen(input_filename_.c_str(), "wb"); FILE* input_file = fopen(input_filename_.c_str(), "wb");
ASSERT_TRUE(input_file != NULL); ASSERT_TRUE(input_file != NULL);
for (int i = 0; i < kSampleRateHz / 1000 * (kTestDurationMs + 1000); i++) { for (int i = 0; i < kSampleRateHz / 1000 * (kTestDurationMs + 1000); i++) {
ASSERT_EQ(1u, fwrite(&kInputValue, sizeof(kInputValue), 1, input_file)); ASSERT_EQ(1u, fwrite(&kInputValue, sizeof(kInputValue), 1, input_file));
} }
ASSERT_EQ(0, fclose(input_file)); ASSERT_EQ(0, fclose(input_file));
} }
void RecordOutput() { void RecordOutput() {
// Start recording the mixed output for |kTestDurationMs| long. // Start recording the mixed output for |kTestDurationMs| long.
EXPECT_EQ(0, voe_file_->StartRecordingPlayout(-1, EXPECT_EQ(0, voe_file_->StartRecordingPlayout(-1,
output_filename_.c_str())); output_filename_.c_str()));
Sleep(kTestDurationMs); Sleep(kTestDurationMs);
EXPECT_EQ(0, voe_file_->StopRecordingPlayout(-1)); EXPECT_EQ(0, voe_file_->StopRecordingPlayout(-1));
} }
void VerifyOutput(int16_t target_value) { void VerifyOutput(int16_t target_value) {
FILE* output_file = fopen(output_filename_.c_str(), "rb"); FILE* output_file = fopen(output_filename_.c_str(), "rb");
ASSERT_TRUE(output_file != NULL); ASSERT_TRUE(output_file != NULL);
int16_t output_value = 0; int16_t output_value = 0;
int samples_read = 0; int samples_read = 0;
while (fread(&output_value, sizeof(output_value), 1, output_file) == 1) { // Skip the first segment to avoid initialization and ramping-in effects.
samples_read++; EXPECT_EQ(0, fseek(output_file, sizeof(output_value) *
EXPECT_EQ(output_value, target_value); kSampleRateHz / 1000 * kSkipOutputMs, SEEK_SET));
} while (fread(&output_value, sizeof(output_value), 1, output_file) == 1) {
samples_read++;
// Ensure the recording length is close to the duration of the test. EXPECT_EQ(output_value, target_value);
ASSERT_GE((samples_read * 1000.0) / kSampleRateHz, 0.9 * kTestDurationMs); }
// Ensure we read the entire file. // Ensure the recording length is close to the duration of the test.
ASSERT_NE(0, feof(output_file)); ASSERT_GE((samples_read * 1000.0) / kSampleRateHz, 0.9 * kTestDurationMs);
ASSERT_EQ(0, fclose(output_file));
// Ensure we read the entire file.
ASSERT_NE(0, feof(output_file));
ASSERT_EQ(0, fclose(output_file));
} }
void VerifyEmptyOutput() { void VerifyEmptyOutput() {
FILE* output_file = fopen(output_filename_.c_str(), "rb"); FILE* output_file = fopen(output_filename_.c_str(), "rb");
ASSERT_TRUE(output_file != NULL); ASSERT_TRUE(output_file != NULL);
ASSERT_EQ(0, fseek(output_file, 0, SEEK_END)); ASSERT_EQ(0, fseek(output_file, 0, SEEK_END));
EXPECT_EQ(0, ftell(output_file)); EXPECT_EQ(0, ftell(output_file));
ASSERT_EQ(0, fclose(output_file)); ASSERT_EQ(0, fclose(output_file));
} }
int channel_; int channel_;
const std::string input_filename_; const std::string input_filename_;
const std::string output_filename_; const std::string output_filename_;
}; };
@ -94,8 +98,7 @@ void VerifyEmptyOutput() {
// 1. the same DC signal if file is played out, // 1. the same DC signal if file is played out,
// 2. total silence if file is not played out, // 2. total silence if file is not played out,
// 3. no output if playout is not started. // 3. no output if playout is not started.
TEST_F(FileBeforeStreamingTest, TEST_F(FileBeforeStreamingTest, TestStartPlayingFileLocallyWithStartPlayout) {
DISABLED_TestStartPlayingFileLocallyWithStartPlayout) {
GenerateInputFile(); GenerateInputFile();
TEST_LOG("Playout is not started. File will not be played out.\n"); TEST_LOG("Playout is not started. File will not be played out.\n");