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)
def cras_rms_test_setup(): """Setups for the cras_rms_tests. To make sure the line_out-to-mic_in path is all green. """ # TODO(owenlin): Now, the nodes are choosed by chrome. # We should do it here. cras_utils.set_system_volume(_DEFAULT_PLAYBACK_VOLUME) cras_utils.set_selected_output_node_volume(_DEFAULT_PLAYBACK_VOLUME) cras_utils.set_system_mute(False) cras_utils.set_capture_mute(False)
def _test_unmute_disabled(self, policy_value): """ Verify AudioOutputAllowed does not allow unmuting when disabled. Attempt to unmute the system with CRAS and check the system state after. @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 cras_utils.set_system_mute(False) if not audio_allowed and not self.is_muted(): raise error.TestFail('System should be muted, but is not') elif audio_allowed and self.is_muted(): raise error.TestFail('System is muted but should not be')