VoEVolumeTest: Enabled Linux flaky tests

Fixed error checks only on Linux to be able to turn on flaky tests. The cause of flaky failures is due to late values in pulse audio.

Related (deleted) CLs:
https://webrtc-codereview.appspot.com/19469007/
https://webrtc-codereview.appspot.com/19469004/

BUG=367
TESTED=trybots, voe_auto_test repeated
R=henrikg@webrtc.org, tina.legrand@webrtc.org, xians@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/17509004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@6195 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/webrtc/voice_engine/test/auto_test/standard/volume_test.cc b/webrtc/voice_engine/test/auto_test/standard/volume_test.cc
index a59f134..eabb7e8 100644
--- a/webrtc/voice_engine/test/auto_test/standard/volume_test.cc
+++ b/webrtc/voice_engine/test/auto_test/standard/volume_test.cc
@@ -25,12 +25,59 @@
 }  // namespace
 
 class VolumeTest : public AfterStreamingFixture {
+ public:
+  void SetAndVerifyMicVolume(unsigned int volume) {
+    bool success = voe_volume_control_->SetMicVolume(volume) == 0;
+#if !defined(WEBRTC_LINUX)
+    EXPECT_TRUE(success);
+#endif
+    if (!success) {
+      TEST_LOG("Failed to set microphone volume to %u.\n", volume);
+      return;
+    }
+
+    unsigned int test_volume = 1000;
+    success = voe_volume_control_->GetMicVolume(test_volume) == 0;
+#if !defined(WEBRTC_LINUX)
+    EXPECT_TRUE(success);
+#endif
+    if (success) {
+      EXPECT_EQ(volume, test_volume);
+    } else {
+      TEST_LOG("Failed to get the microphone volume.");
+      EXPECT_EQ(1000u, test_volume);
+    }
+  }
+
+  void SetAndVerifyInputMute(bool enable) {
+    bool success = voe_volume_control_->SetInputMute(channel_, enable) == 0;
+#if !defined(WEBRTC_LINUX)
+    EXPECT_TRUE(success);
+#endif
+    if (!success) {
+      TEST_LOG("Failed to %smute input.\n", enable ? "" : "un");
+      return;
+    }
+
+    bool is_muted = !enable;
+    success = voe_volume_control_->GetInputMute(channel_, is_muted) == 0;
+#if !defined(WEBRTC_LINUX)
+    EXPECT_TRUE(success);
+#endif
+    if (success) {
+      EXPECT_EQ(enable, is_muted);
+    } else {
+      TEST_LOG("Failed to mute the input.");
+      EXPECT_NE(enable, is_muted);
+    }
+  }
 };
 
-// TODO(phoglund): a number of tests are disabled here on Linux, all pending
-// investigation in
-// http://code.google.com/p/webrtc/issues/detail?id=367
-
+// Some tests are flaky on Linux (Pulse Audio), which boils down to some system
+// values not being acquired in time. In Pulse Audio we make one retry if
+// needed, but if we fail then, a -1 is returned propagating up through VoE.
+// To avoid possible bugs slipping through on other platforms we make adequate
+// changes on Linux only.
 TEST_F(VolumeTest, VerifyCorrectErrorReturns) {
   // All tests run on correct initialization which eliminates one possible error
   // return. In addition, we assume the audio_device returning values without
@@ -114,29 +161,44 @@
 
 TEST_F(VolumeTest, DefaultMicrophoneVolumeIsAtMost255) {
   unsigned int volume = 1000;
-  if (voe_volume_control_->GetMicVolume(volume) == 0)
+  bool could_get_mic_volume = voe_volume_control_->GetMicVolume(volume) == 0;
+#if !defined(WEBRTC_LINUX)
+  EXPECT_TRUE(could_get_mic_volume);
+#endif
+  if (could_get_mic_volume) {
     EXPECT_LE(volume, 255u);
-  else
+  } else {
+    TEST_LOG("Failed to get the microphone volume.");
     EXPECT_EQ(1000u, volume);
+  }
 }
 
-TEST_F(VolumeTest, DISABLED_ON_LINUX(
-          ManualRequiresMicrophoneCanSetMicrophoneVolumeWithAcgOff)) {
+TEST_F(VolumeTest, ManualRequiresMicrophoneCanSetMicrophoneVolumeWithAgcOff) {
   SwitchToManualMicrophone();
   EXPECT_EQ(0, voe_apm_->SetAgcStatus(false));
 
   unsigned int original_volume = 0;
-  EXPECT_EQ(0, voe_volume_control_->GetMicVolume(original_volume));
+  bool could_get_mic_volume =
+      (voe_volume_control_->GetMicVolume(original_volume) == 0);
+#if !defined(WEBRTC_LINUX)
+  EXPECT_TRUE(could_get_mic_volume);
+#endif
+  if (could_get_mic_volume)
+    TEST_LOG("Current microphone volume is %u.\n", original_volume);
+  else
+    TEST_LOG("Failed to fetch current microphone volume.\n");
 
   TEST_LOG("Setting microphone volume to 0.\n");
-  EXPECT_EQ(0, voe_volume_control_->SetMicVolume(channel_));
+  SetAndVerifyMicVolume(0);
   Sleep(1000);
   TEST_LOG("Setting microphone volume to 255.\n");
-  EXPECT_EQ(0, voe_volume_control_->SetMicVolume(255));
+  SetAndVerifyMicVolume(255);
   Sleep(1000);
-  TEST_LOG("Setting microphone volume back to saved value.\n");
-  EXPECT_EQ(0, voe_volume_control_->SetMicVolume(original_volume));
-  Sleep(1000);
+  if (could_get_mic_volume) {
+    TEST_LOG("Setting microphone volume back to %u.\n", original_volume);
+    SetAndVerifyMicVolume(original_volume);
+    Sleep(1000);
+  }
 }
 
 TEST_F(VolumeTest, ChannelScalingIsOneByDefault) {
@@ -167,23 +229,15 @@
   EXPECT_FALSE(is_muted);
 }
 
-TEST_F(VolumeTest, DISABLED_ON_LINUX(ManualInputMutingMutesMicrophone)) {
+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);
-
+  SetAndVerifyInputMute(true);
   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);
-
+  SetAndVerifyInputMute(false);
   TEST_LOG("Unmuted: talk into microphone and verify you can hear yourself.\n");
   Sleep(2000);
 }