def run_once(self):
        """Entry point of this test."""

        # Multitone wav file lasts 10 seconds
        wav_path = os.path.join(self.bindir, '10SEC.wav')

        noise_file = os.path.join(self.resultsdir, 'cras_noise.wav')
        recorded_file = os.path.join(self.resultsdir, 'cras_recorded.wav')

        # Record a sample of "silence" to use as a noise profile.
        cras_utils.capture(noise_file, duration=1)

        self.wait_for_active_stream_count(0)
        p = cmd_utils.popen(cras_utils.playback_cmd(wav_path))
        try:
            self.wait_for_active_stream_count(1)
            cras_utils.capture(recorded_file, duration=TEST_DURATION)

            # Make sure the audio is still playing.
            if p.poll() != None:
                raise error.TestError('playback stopped')
        finally:
            cmd_utils.kill_or_log_returncode(p)

        rms_value = audio_helper.reduce_noise_and_get_rms(
            recorded_file, noise_file)[0]
        self.write_perf_keyval({'rms_value': rms_value})
    def run_once(self):
        """Entry point of this test."""

        # Generate sine raw file that lasts 5 seconds.
        raw_path = os.path.join(self.bindir, '5SEC.raw')
        data_format = dict(file_type='raw', sample_format='S16_LE',
                channel=2, rate=48000)
        raw_file = audio_test_data.GenerateAudioTestData(
            path=raw_path,
            data_format=data_format,
            duration_secs=5,
            frequencies=[440, 440],
            volume_scale=0.9)

        recorded_file = os.path.join(self.resultsdir, 'cras_recorded.raw')

        self.wait_for_active_stream_count(0)
        p = cmd_utils.popen(cras_utils.playback_cmd(raw_file.path))
        try:
            self.wait_for_active_stream_count(1)
            cras_utils.capture(recorded_file, duration=TEST_DURATION)

            # Make sure the audio is still playing.
            if p.poll() != None:
                raise error.TestError('playback stopped')
        finally:
            cmd_utils.kill_or_log_returncode(p)
            raw_file.delete()

        rms_value = audio_helper.get_rms(recorded_file)[0]
        self.write_perf_keyval({'rms_value': rms_value})
예제 #3
0
    def _test_audio_disabled(self, policy_value):
        """
        Verify the AudioOutputAllowed policy behaves as expected.

        Generate and play a sample audio file. When enabled, the difference
        between the muted and unmuted RMS should be greater than 0.75. When
        disabled, the RMS difference should be less than 0.05.

        @param policy_value: policy value for this case.

        @raises error.TestFail: In the case where the audio behavior
            does not match the policy value.

        """
        audio_allowed = policy_value or policy_value is None

        RAW_FILE = os.path.join(self.enterprise_dir, 'test_audio.raw')
        noise_file = os.path.join(self.resultsdir, 'noise.wav')
        recorded_file = os.path.join(self.resultsdir, 'recorded-cras.raw')
        recorded_rms = []

        # Record a sample of silence to use as a noise profile.
        cras_utils.capture(noise_file, duration=2)
        logging.info('NOISE: %s', audio_helper.get_rms(noise_file))

        # Get two RMS samples: one when muted and one when not
        for muted in [False, True]:
            cras_utils.set_system_mute(muted)

            # Play the audio file and capture the output
            self.wait_for_active_stream_count(0)
            p = cmd_utils.popen(cras_utils.playback_cmd(RAW_FILE))
            try:
                self.wait_for_active_stream_count(1)
                cras_utils.capture(recorded_file,
                                   duration=self.SAMPLE_DURATION)

                if p.poll() is not None:
                    raise error.TestError('Audio playback stopped prematurely')
            finally:
                cmd_utils.kill_or_log_returncode(p)

            rms_value = audio_helper.reduce_noise_and_get_rms(
                recorded_file, noise_file)[0]

            logging.info('muted (%s): %s' % (muted, rms_value))
            recorded_rms.append(rms_value)

        rms_diff = recorded_rms[0] - recorded_rms[1]
        self.write_perf_keyval({'rms_diff': rms_diff})

        if audio_allowed:
            if rms_diff < 0.4:
                raise error.TestFail('RMS difference not large enough between '
                                     'mute and ummute: %s' % rms_diff)
        else:
            if abs(rms_diff) > 0.05:
                raise error.TestFail('RMS difference too wide while audio '
                                     'disabled: %s' % rms_diff)
예제 #4
0
 def play_sine_tone(self, frequence, rate):
     """Plays a sine tone by cras and returns the processes.
     Args:
         frequence: the frequence of the sine wave.
         rate: the sampling rate.
     """
     p1 = cmd_utils.popen(sox_utils.generate_sine_tone_cmd(
         filename='-', rate=rate, frequence=frequence, gain=-6),
                          stdout=cmd_utils.PIPE)
     p2 = cmd_utils.popen(cras_utils.playback_cmd(playback_file='-',
                                                  rate=rate),
                          stdin=p1.stdout)
     return [p1, p2]