STOUT_FACTORY: factory_AudioLoop: self._result should be set when test fail.

self._result is undefined when audio_loopback() fails. Assign its default
to False in test setup. And rename it to _test_result to be more clear.

BUG=none
TEST=manual
Use the following test_list:
TEST_LIST = [
    OperatorTest(
        id='InternalMic',
        label_zh=u'内建麦克风',
        autotest_name='factory_AudioLoop',
        dargs={'input_devices': ['hw:0,0'],
               'output_devices': ['hw:0,0'],
               'device_to_mute': 'headphone',
	       'audiofuntest': False}),
]

Reviewed-on: https://gerrit.chromium.org/gerrit/37887
Commit-Ready: Shuo-Peng Liao <deanliao@chromium.org>
Reviewed-by: Shuo-Peng Liao <deanliao@chromium.org>
Tested-by: Shuo-Peng Liao <deanliao@chromium.org>
(cherry picked from commit 97e66df482abfa23a73af3565852d884fcd761c2)

Change-Id: I55681a159c05516fffcebc68620853c2cf1f1822
Signed-off-by: Dean Liao <deanliao@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/37893
diff --git a/client/site_tests/factory_AudioLoop/factory_AudioLoop.py b/client/site_tests/factory_AudioLoop/factory_AudioLoop.py
index 1406897..ba7e920 100755
--- a/client/site_tests/factory_AudioLoop/factory_AudioLoop.py
+++ b/client/site_tests/factory_AudioLoop/factory_AudioLoop.py
@@ -98,11 +98,12 @@
             if m is not None:
                  if (hasattr(self, '_last_success_rate') and
                          self._last_success_rate is not None):
-                     self._result = self._last_success_rate > _PASS_THRESHOLD
+                     self._test_result = (
+                         self._last_success_rate > _PASS_THRESHOLD)
                      break
 
         # Show instant message and wait for a while
-        if hasattr(self, '_result') and self._result:
+        if self._test_result:
             return True
         elif hasattr(self, '_last_success_rate'):
             self.ui.CallJSFunction('testFailResult', self._last_success_rate)
@@ -132,7 +133,7 @@
                             lambda ch: self.playback_sine(ch, output_device),
                             self.check_recorded_audio)
 
-        if self._result is True:
+        if self._test_result:
             self.ui.CallJSFunction('testPassResult')
             time.sleep(0.5)
             self.ui.Pass()
@@ -145,9 +146,10 @@
     def check_recorded_audio(self, sox_output):
         freq = self._ah.get_rough_freq(sox_output)
         if abs(freq - self._freq) > _DEFAULT_FREQ_THRESHOLD_HZ:
+            self._test_result = False
             self.ui.Fail('Test Fail at frequency %d' % freq)
         else:
-            self._result = True
+            self._test_result = True
             factory.console.info('Got frequency %d' % freq)
 
     def run_once(self, audiofuntest=True, audiofuntest_duration=10,
@@ -170,6 +172,9 @@
         self._mute_right_mixer_settings = mute_right_mixer_settings
         self._mute_device_mixer_settings = mute_device_mixer_settings
 
+        # Used in run_audiofuntest() and audio_loop() for test result.
+        self._test_result = False
+
         # Create a default audio helper to do the setup jobs.
         self._ah = audio_helper.AudioHelper(self, record_duration=duration)
         if mixer_controls is not None: