From 12dbc23851c95cbabdcafe9789465d8d91a59e81 Mon Sep 17 00:00:00 2001 From: "phoglund@webrtc.org" Date: Mon, 23 Jan 2012 16:03:04 +0000 Subject: [PATCH] Rewrote volume test. BUG= TEST= Review URL: https://webrtc-codereview.appspot.com/367004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@1506 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../test/auto_test/standard/volume_test.cc | 241 ++++++++++++++++++ .../main/test/auto_test/voe_standard_test.cc | 207 --------------- .../main/test/voice_engine_tests.gypi | 1 + 3 files changed, 242 insertions(+), 207 deletions(-) create mode 100644 src/voice_engine/main/test/auto_test/standard/volume_test.cc diff --git a/src/voice_engine/main/test/auto_test/standard/volume_test.cc b/src/voice_engine/main/test/auto_test/standard/volume_test.cc new file mode 100644 index 0000000000..47cf8bc44d --- /dev/null +++ b/src/voice_engine/main/test/auto_test/standard/volume_test.cc @@ -0,0 +1,241 @@ +/* + * Copyright (c) 2012 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" + +class VolumeTest : public AfterStreamingFixture { + protected: + void SwitchToManualMicrophone() { + EXPECT_EQ(0, voe_file_->StopPlayingFileAsMicrophone(channel_)); + + TEST_LOG("You need to speak manually into the microphone for this test.\n"); + Sleep(2000); + } +}; + +TEST_F(VolumeTest, DefaultSpeakerVolumeIsAtMost255) { + unsigned int volume = 1000; + EXPECT_EQ(0, voe_volume_control_->GetSpeakerVolume(volume)); + EXPECT_LE(volume, 255u); +} + +TEST_F(VolumeTest, ManualSetVolumeWorks) { + unsigned int original_volume = 0; + EXPECT_EQ(0, voe_volume_control_->GetSpeakerVolume(original_volume)); + Sleep(1000); + + TEST_LOG("Setting speaker volume to 0 out of 255.\n"); + EXPECT_EQ(0, voe_volume_control_->SetSpeakerVolume(0)); + Sleep(1000); + + TEST_LOG("Setting speaker volume to 100 out of 255.\n"); + EXPECT_EQ(0, voe_volume_control_->SetSpeakerVolume(100)); + Sleep(1000); + + // Set the volume to 255 very briefly so we don't blast the poor user + // listening to this. This is just to test the call succeeds. + EXPECT_EQ(0, voe_volume_control_->SetSpeakerVolume(255)); + + TEST_LOG("Setting speaker volume to the original %d out of 255.\n", + original_volume); + EXPECT_EQ(0, voe_volume_control_->SetSpeakerVolume(original_volume)); + Sleep(1000); +} + +#if !defined(MAC_IPHONE) + +TEST_F(VolumeTest, DefaultMicrophoneVolumeIsAtMost255) { + unsigned int volume = 1000; + EXPECT_EQ(0, voe_volume_control_->GetMicVolume(volume)); + EXPECT_LE(volume, 255u); +} + +TEST_F(VolumeTest, ManualRequiresMicrophoneCanSetMicrophoneVolumeWithAcgOff) { + SwitchToManualMicrophone(); + EXPECT_EQ(0, voe_apm_->SetAgcStatus(false)); + + unsigned int original_volume = 0; + EXPECT_EQ(0, voe_volume_control_->GetMicVolume(original_volume)); + + TEST_LOG("Setting microphone volume to 0.\n"); + EXPECT_EQ(0, voe_volume_control_->SetMicVolume(channel_)); + Sleep(1000); + TEST_LOG("Setting microphone volume to 255.\n"); + EXPECT_EQ(0, voe_volume_control_->SetMicVolume(255)); + Sleep(1000); + TEST_LOG("Setting microphone volume back to saved value.\n"); + EXPECT_EQ(0, voe_volume_control_->SetMicVolume(original_volume)); + Sleep(1000); +} + +TEST_F(VolumeTest, ChannelScalingIsOneByDefault) { + float scaling = -1.0; + + EXPECT_EQ(0, voe_volume_control_->GetChannelOutputVolumeScaling( + channel_, scaling)); + EXPECT_FLOAT_EQ(1.0, scaling); +} + +TEST_F(VolumeTest, ManualCanSetChannelScaling) { + EXPECT_EQ(0, voe_volume_control_->SetChannelOutputVolumeScaling( + channel_, 0.1)); + + float scaling = 1.0; + EXPECT_EQ(0, voe_volume_control_->GetChannelOutputVolumeScaling( + channel_, scaling)); + + EXPECT_FLOAT_EQ(0.1, scaling); + + TEST_LOG("Channel scaling set to 0.1: audio should be barely audible.\n"); + Sleep(2000); +} + +#endif // !MAC_IPHONE + +#if !defined(WEBRTC_ANDROID) && !defined(MAC_IPHONE) + +TEST_F(VolumeTest, InputMutingIsNotEnabledByDefault) { + bool is_muted = true; + EXPECT_EQ(0, voe_volume_control_->GetInputMute(channel_, is_muted)); + EXPECT_FALSE(is_muted); +} + +TEST_F(VolumeTest, ManualInputMutingMutesMicrophone) { + SwitchToManualMicrophone(); + + // Enable muting. + EXPECT_EQ(0, voe_volume_control_->SetInputMute(channel_, true)); + bool is_muted = false; + EXPECT_EQ(0, voe_volume_control_->GetInputMute(channel_, is_muted)); + EXPECT_TRUE(is_muted); + + TEST_LOG("Muted: talk into microphone and verify you can't hear yourself.\n"); + Sleep(2000); + + // Test that we can disable muting. + EXPECT_EQ(0, voe_volume_control_->SetInputMute(channel_, false)); + EXPECT_EQ(0, voe_volume_control_->GetInputMute(channel_, is_muted)); + EXPECT_FALSE(is_muted); + + TEST_LOG("Unmuted: talk into microphone and verify you can hear yourself.\n"); + Sleep(2000); +} + +TEST_F(VolumeTest, SystemInputMutingIsNotEnabledByDefault) { + bool is_muted = true; + EXPECT_EQ(0, voe_volume_control_->GetSystemInputMute(is_muted)); + EXPECT_FALSE(is_muted); +} + +TEST_F(VolumeTest, ManualSystemInputMutingMutesMicrophone) { + SwitchToManualMicrophone(); + + // Enable system input muting. + EXPECT_EQ(0, voe_volume_control_->SetSystemInputMute(true)); + bool is_muted = false; + EXPECT_EQ(0, voe_volume_control_->GetSystemInputMute(is_muted)); + EXPECT_TRUE(is_muted); + + TEST_LOG("Muted: talk into microphone and verify you can't hear yourself.\n"); + Sleep(2000); + + // Test that we can disable system input muting. + EXPECT_EQ(0, voe_volume_control_->SetSystemInputMute(false)); + EXPECT_EQ(0, voe_volume_control_->GetSystemInputMute(is_muted)); + EXPECT_FALSE(is_muted); + + TEST_LOG("Unmuted: talk into microphone and verify you can hear yourself.\n"); + Sleep(2000); +} + +TEST_F(VolumeTest, SystemOutputMutingIsNotEnabledByDefault) { + bool is_muted = true; + EXPECT_EQ(0, voe_volume_control_->GetSystemOutputMute(is_muted)); + EXPECT_FALSE(is_muted); +} + +TEST_F(VolumeTest, ManualSystemOutputMutingMutesOutput) { + // Enable muting. + EXPECT_EQ(0, voe_volume_control_->SetSystemOutputMute(true)); + bool is_muted = false; + EXPECT_EQ(0, voe_volume_control_->GetSystemOutputMute(is_muted)); + EXPECT_TRUE(is_muted); + + TEST_LOG("Muted: you should hear no audio.\n"); + Sleep(2000); + + // Test that we can disable muting. + EXPECT_EQ(0, voe_volume_control_->SetSystemOutputMute(false)); + EXPECT_EQ(0, voe_volume_control_->GetSystemOutputMute(is_muted)); + EXPECT_FALSE(is_muted); + + TEST_LOG("Unmuted: you should hear audio.\n"); + Sleep(2000); +} + +TEST_F(VolumeTest, ManualTestInputAndOutputLevels) { + SwitchToManualMicrophone(); + + TEST_LOG("Speak and verify that the following levels look right:\n"); + for (int i = 0; i < 5; i++) { + Sleep(1000); + unsigned int input_level = 0; + unsigned int output_level = 0; + unsigned int input_level_full_range = 0; + unsigned int output_level_full_range = 0; + + EXPECT_EQ(0, voe_volume_control_->GetSpeechInputLevel( + input_level)); + EXPECT_EQ(0, voe_volume_control_->GetSpeechOutputLevel( + channel_, output_level)); + EXPECT_EQ(0, voe_volume_control_->GetSpeechInputLevelFullRange( + input_level_full_range)); + EXPECT_EQ(0, voe_volume_control_->GetSpeechOutputLevelFullRange( + channel_, output_level_full_range)); + + TEST_LOG(" warped levels (0-9) : in=%5d, out=%5d\n", + input_level, output_level); + TEST_LOG(" linear levels (0-32768): in=%5d, out=%5d\n", + input_level_full_range, output_level_full_range); + } +} + +TEST_F(VolumeTest, ChannelsAreNotPannedByDefault) { + float left = -1.0; + float right = -1.0; + + EXPECT_EQ(0, voe_volume_control_->GetOutputVolumePan(channel_, left, right)); + EXPECT_FLOAT_EQ(1.0, left); + EXPECT_FLOAT_EQ(1.0, right); +} + +TEST_F(VolumeTest, ManualTestChannelPanning) { + TEST_LOG("Panning left.\n"); + EXPECT_EQ(0, voe_volume_control_->SetOutputVolumePan(channel_, 0.8, 0.1)); + Sleep(1000); + + TEST_LOG("Back to center.\n"); + EXPECT_EQ(0, voe_volume_control_->SetOutputVolumePan(channel_, 1.0, 1.0)); + Sleep(1000); + + TEST_LOG("Panning right.\n"); + EXPECT_EQ(0, voe_volume_control_->SetOutputVolumePan(channel_, 0.1, 0.8)); + Sleep(1000); + + // To finish, verify that the getter works. + float left = 0.0; + float right = 0.0; + + EXPECT_EQ(0, voe_volume_control_->GetOutputVolumePan(channel_, left, right)); + EXPECT_FLOAT_EQ(0.1, left); + EXPECT_FLOAT_EQ(0.8, right); +} + +#endif // !WEBRTC_ANDROID && !MAC_IPHONE diff --git a/src/voice_engine/main/test/auto_test/voe_standard_test.cc b/src/voice_engine/main/test/auto_test/voe_standard_test.cc index 9da6231455..1e5f98a740 100644 --- a/src/voice_engine/main/test/auto_test/voe_standard_test.cc +++ b/src/voice_engine/main/test/auto_test/voe_standard_test.cc @@ -983,213 +983,6 @@ int VoETestManager::DoStandardTest() { if (TestStartStreaming(channel0_transport) != 0) return -1; if (TestStartPlaying() != 0) return -1; -#ifndef _TEST_BASE_ - TEST_LOG("\n\n+++ (Base) tests NOT ENABLED +++\n"); -#endif // #ifdef _TEST_BASE_ - -#ifdef WEBRTC_CODEC_RED - TEST_LOG("Enabling FEC \n"); - TEST_MUSTPASS(voe_rtp_rtcp_->SetFECStatus(0, true)); - SLEEP(2000); - - TEST_LOG("Disabling FEC\n"); - TEST_MUSTPASS(voe_rtp_rtcp_->SetFECStatus(0, false)); - SLEEP(2000); -#else - TEST_LOG("Skipping FEC tests - WEBRTC_CODEC_RED not defined \n"); -#endif // #ifdef WEBRTC_CODEC_RED - - ////////// - // Volume - -#ifdef _TEST_VOLUME_ - TEST_LOG("\n\n+++ Volume tests +++\n\n"); - -#if !defined(MAC_IPHONE) - // Speaker volume test - unsigned int vol = 1000; - TEST_LOG("Saving Speaker volume\n"); - TEST_MUSTPASS(voe_volume_control_->GetSpeakerVolume(vol)); - TEST_MUSTPASS(!(vol <= 255)); - TEST_LOG("Setting speaker volume to 0\n"); - TEST_MUSTPASS(voe_volume_control_->SetSpeakerVolume(0)); - SLEEP(1000); - TEST_LOG("Setting speaker volume to 255\n"); - TEST_MUSTPASS(voe_volume_control_->SetSpeakerVolume(255)); - SLEEP(1000); - TEST_LOG("Setting speaker volume back to saved value\n"); - TEST_MUSTPASS(voe_volume_control_->SetSpeakerVolume(vol)); - SLEEP(1000); -#endif // #if !defined(MAC_IPHONE) - if (voe_file_) { - TEST_LOG("==> Talk into the microphone \n"); - TEST_MUSTPASS(voe_file_->StopPlayingFileAsMicrophone(0)); - SLEEP(1000); - } - -#if (!defined(MAC_IPHONE) && !defined(WEBRTC_ANDROID)) - // Mic volume test -#if defined(_TEST_AUDIO_PROCESSING_) && defined(WEBRTC_VOICE_ENGINE_AGC) - bool agcTemp(true); - AgcModes agcModeTemp(kAgcAdaptiveAnalog); - TEST_MUSTPASS(voe_apm_->GetAgcStatus(agcTemp, agcModeTemp)); // current state - TEST_LOG("Turn off AGC\n"); - TEST_MUSTPASS(voe_apm_->SetAgcStatus(false)); -#endif - TEST_LOG("Saving Mic volume\n"); - TEST_MUSTPASS(voe_volume_control_->GetMicVolume(vol)); - TEST_MUSTPASS(!(vol <= 255)); - TEST_LOG("Setting Mic volume to 0\n"); - TEST_MUSTPASS(voe_volume_control_->SetMicVolume(0)); - SLEEP(1000); - TEST_LOG("Setting Mic volume to 255\n"); - TEST_MUSTPASS(voe_volume_control_->SetMicVolume(255)); - SLEEP(1000); - TEST_LOG("Setting Mic volume back to saved value\n"); - TEST_MUSTPASS(voe_volume_control_->SetMicVolume(vol)); - SLEEP(1000); -#if defined(_TEST_AUDIO_PROCESSING_) && defined(WEBRTC_VOICE_ENGINE_AGC) - TEST_LOG("Reset AGC to previous state\n"); - TEST_MUSTPASS(voe_apm_->SetAgcStatus(agcTemp, agcModeTemp)); -#endif -#endif // #if (!defined(MAC_IPHONE) && !defined(WEBRTC_ANDROID)) - // Input mute test - TEST_LOG("Enabling input muting\n"); - bool mute = true; - TEST_MUSTPASS(voe_volume_control_->GetInputMute(0, mute)); - TEST_MUSTPASS(mute); - TEST_MUSTPASS(voe_volume_control_->SetInputMute(0, true)); - TEST_MUSTPASS(voe_volume_control_->GetInputMute(0, mute)); - TEST_MUSTPASS(!mute); - SLEEP(1000); - TEST_LOG("Disabling input muting\n"); - TEST_MUSTPASS(voe_volume_control_->SetInputMute(0, false)); - TEST_MUSTPASS(voe_volume_control_->GetInputMute(0, mute)); - TEST_MUSTPASS(mute); - SLEEP(1000); - -#if (!defined(MAC_IPHONE) && !defined(WEBRTC_ANDROID)) - // System output mute test - TEST_LOG("Enabling system output muting\n"); - bool outputMute = true; - TEST_MUSTPASS(voe_volume_control_->GetSystemOutputMute(outputMute)); - TEST_MUSTPASS(outputMute); - TEST_MUSTPASS(voe_volume_control_->SetSystemOutputMute(true)); - TEST_MUSTPASS(voe_volume_control_->GetSystemOutputMute(outputMute)); - TEST_MUSTPASS(!outputMute); - SLEEP(1000); - TEST_LOG("Disabling system output muting\n"); - TEST_MUSTPASS(voe_volume_control_->SetSystemOutputMute(false)); - TEST_MUSTPASS(voe_volume_control_->GetSystemOutputMute(outputMute)); - TEST_MUSTPASS(outputMute); - SLEEP(1000); - - // System Input mute test - TEST_LOG("Enabling system input muting\n"); - bool inputMute = true; - TEST_MUSTPASS(voe_volume_control_->GetSystemInputMute(inputMute)); - TEST_MUSTPASS(inputMute); - TEST_MUSTPASS(voe_volume_control_->SetSystemInputMute(true)); - // This is needed to avoid error using pulse - SLEEP(100); - TEST_MUSTPASS(voe_volume_control_->GetSystemInputMute(inputMute)); - TEST_MUSTPASS(!inputMute); - SLEEP(1000); - TEST_LOG("Disabling system input muting\n"); - TEST_MUSTPASS(voe_volume_control_->SetSystemInputMute(false)); - // This is needed to avoid error using pulse - SLEEP(100); - TEST_MUSTPASS(voe_volume_control_->GetSystemInputMute(inputMute)); - TEST_MUSTPASS(inputMute); - SLEEP(1000); -#endif // #if (!defined(MAC_IPHONE) && !defined(WEBRTC_ANDROID)) -#if(!defined(MAC_IPHONE) && !defined(WEBRTC_ANDROID)) - // Test Input & Output levels - TEST_LOG("Testing input & output levels for 10 seconds (dT=1 second)\n"); - TEST_LOG("Speak in microphone to vary the levels...\n"); - unsigned int inputLevel(0); - unsigned int outputLevel(0); - unsigned int inputLevelFullRange(0); - unsigned int outputLevelFullRange(0); - - for (int t = 0; t < 5; t++) { - SLEEP(1000); - TEST_MUSTPASS(voe_volume_control_->GetSpeechInputLevel(inputLevel)); - TEST_MUSTPASS(voe_volume_control_->GetSpeechOutputLevel(0, outputLevel)); - TEST_MUSTPASS(voe_volume_control_->GetSpeechInputLevelFullRange( - inputLevelFullRange)); - TEST_MUSTPASS(voe_volume_control_->GetSpeechOutputLevelFullRange( - 0, outputLevelFullRange)); - TEST_LOG(" warped levels (0-9) : in=%5d, out=%5d\n", - inputLevel, outputLevel); - TEST_LOG(" linear levels (0-32768): in=%5d, out=%5d\n", - inputLevelFullRange, outputLevelFullRange); - } -#endif // #if (!defined(MAC_IPHONE) && !defined(WEBRTC_ANDROID)) - if (voe_file_) { - TEST_LOG("==> Start playing a file as microphone again \n"); - TEST_MUSTPASS(voe_file_->StartPlayingFileAsMicrophone(0, - AudioFilename(), - true, - true)); - SLEEP(1000); - } - -#if !defined(MAC_IPHONE) - // Channel scaling test - TEST_LOG("Channel scaling\n"); - float scaling = -1.0; - TEST_MUSTPASS(voe_volume_control_->GetChannelOutputVolumeScaling(0, scaling)); - TEST_MUSTPASS(1.0 != scaling); - TEST_MUSTPASS(voe_volume_control_->SetChannelOutputVolumeScaling(0, - (float)0.1)); - TEST_MUSTPASS(voe_volume_control_->GetChannelOutputVolumeScaling(0, scaling)); - TEST_MUSTPASS(!((scaling > 0.099) && (scaling < 0.101))); - SLEEP(1000); - TEST_MUSTPASS(voe_volume_control_->SetChannelOutputVolumeScaling(0, - (float)1.0)); - TEST_MUSTPASS(voe_volume_control_->GetChannelOutputVolumeScaling(0, scaling)); - TEST_MUSTPASS(1.0 != scaling); -#endif // #if !defined(MAC_IPHONE) -#if !defined(MAC_IPHONE) && !defined(WEBRTC_ANDROID) - // Channel panning test - TEST_LOG("Channel panning\n"); - float left = -1.0, right = -1.0; - TEST_MUSTPASS(voe_volume_control_->GetOutputVolumePan(0, left, right)); - TEST_MUSTPASS(!((left == 1.0) && (right == 1.0))); - TEST_LOG("Panning to left\n"); - TEST_MUSTPASS(voe_volume_control_->SetOutputVolumePan(0, (float)0.8, - (float)0.1)); - TEST_MUSTPASS(voe_volume_control_->GetOutputVolumePan(0, left, right)); - TEST_MUSTPASS(!((left > 0.799) && (left < 0.801))); - TEST_MUSTPASS(!((right > 0.099) && (right < 0.101))); - SLEEP(1000); - TEST_LOG("Back to center\n"); - TEST_MUSTPASS(voe_volume_control_->SetOutputVolumePan(0, (float)1.0, - (float)1.0)); - SLEEP(1000); - left = -1.0; - right = -1.0; - TEST_MUSTPASS(voe_volume_control_->GetOutputVolumePan(0, left, right)); - TEST_MUSTPASS(!((left == 1.0) && (right == 1.0))); - TEST_LOG("Panning channel to right\n"); - TEST_MUSTPASS(voe_volume_control_->SetOutputVolumePan(0, (float)0.1, - (float)0.8)); - SLEEP(100); - TEST_MUSTPASS(voe_volume_control_->GetOutputVolumePan(0, left, right)); - TEST_MUSTPASS(!((left > 0.099) && (left < 0.101))); - TEST_MUSTPASS(!((right > 0.799) && (right < 0.801))); - SLEEP(1000); - TEST_LOG("Channel back to center\n"); - TEST_MUSTPASS(voe_volume_control_->SetOutputVolumePan(0, (float)1.0, - (float)1.0)); - SLEEP(1000); -#else - TEST_LOG("Skipping stereo tests\n"); -#endif // #if !defined(MAC_IPHONE) && !defined(WEBRTC_ANDROID)) -#else - TEST_LOG("\n\n+++ Volume tests NOT ENABLED +++\n"); -#endif // #ifdef _TEST_VOLUME_ /////// // AudioProcessing diff --git a/src/voice_engine/main/test/voice_engine_tests.gypi b/src/voice_engine/main/test/voice_engine_tests.gypi index 6334634601..df805ca97b 100644 --- a/src/voice_engine/main/test/voice_engine_tests.gypi +++ b/src/voice_engine/main/test/voice_engine_tests.gypi @@ -48,6 +48,7 @@ 'auto_test/standard/rtp_rtcp_before_streaming_test.cc', 'auto_test/standard/rtp_rtcp_test.cc', 'auto_test/standard/voe_base_misc_test.cc', + 'auto_test/standard/volume_test.cc', 'auto_test/resource_manager.cc', 'auto_test/voe_cpu_test.cc', 'auto_test/voe_cpu_test.h',