Exemplo n.º 1
0
    def _disable_internet(self, ping_server='google.com'):
        """Disable the internet connection"""
        self._internet_was_disabled = True
        try:
            logging.debug('Before disconnect: %s', utils.run('ifconfig'))
            # DUTs in the lab have a service called recover_duts that is used to
            # check that the DUT is online and if it is not it will bring it
            # back online. We will need to stop this service for the length
            # of this test.
            utils.stop_service('recover_duts', ignore_status=True)
            for eth in self._NETWORK_INTERFACES:
                result = utils.run('ifconfig %s down' % eth,
                                   ignore_status=True)
                logging.debug(result)

            # Print ifconfig to help debug DUTs that stay online.
            logging.debug('After disconnect: %s', utils.run('ifconfig'))

            # Make sure we are offline
            utils.poll_for_condition(
                lambda: utils.ping(ping_server, deadline=5, timeout=5) != 0,
                timeout=60,
                sleep_interval=1,
                desc='Ping failure while offline.')
        except (error.CmdError, utils.TimeoutError):
            logging.exception('Failed to disconnect one or more interfaces.')
            logging.debug(utils.run('ifconfig', ignore_status=True))
            raise error.TestFail('Disabling the internet connection failed.')
Exemplo n.º 2
0
    def run_once(self):
        """Entry point of this test."""

        # Sine wav file lasts 5 seconds
        wav_path = os.path.join(self.bindir, '5SEC.wav')
        data_format = dict(file_type='wav',
                           sample_format='S16_LE',
                           channel=2,
                           rate=48000)
        wav_file = audio_test_data.GenerateAudioTestData(
            path=wav_path,
            data_format=data_format,
            duration_secs=5,
            frequencies=[440, 440],
            volume_scale=0.9)

        recorded_file = os.path.join(self.resultsdir, 'hw_recorded.wav')

        # Get selected input and output devices.
        cras_input = cras_utils.get_selected_input_device_name()
        cras_output = cras_utils.get_selected_output_device_name()
        logging.debug("Selected input=%s, output=%s", cras_input, cras_output)
        if cras_input is None:
            raise error.TestFail("Fail to get selected input device.")
        if cras_output is None:
            raise error.TestFail("Fail to get selected output device.")
        alsa_input = alsa_utils.convert_device_name(cras_input)
        alsa_output = alsa_utils.convert_device_name(cras_output)

        (output_type, input_type) = cras_utils.get_selected_node_types()
        if not any(t in input_type for t in ['MIC', 'USB']):
            raise error.TestFail("Wrong input type=%s", input_type)
        if not any(t in output_type for t in ['HEADPHONE', 'USB']):
            raise error.TestFail("Wrong output type=%s", output_type)

        # Stop CRAS to make sure the audio device won't be occupied.
        utils.stop_service('cras', ignore_status=True)

        p = cmd_utils.popen(
            alsa_utils.playback_cmd(wav_file.path, device=alsa_output))
        try:
            # Wait one second to make sure the playback has been started.
            time.sleep(1)
            alsa_utils.record(recorded_file,
                              duration=TEST_DURATION,
                              device=alsa_input)

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

            # Restart CRAS.
            utils.start_service('cras', ignore_status=True)

        rms_value = audio_helper.get_rms(recorded_file)[0]

        self.write_perf_keyval({'rms_value': rms_value})
Exemplo n.º 3
0
    def run_once(self, to_test):
        """Run alsa_api_test binary and verify its result.

        Checks the source code of alsa_api_test in audiotest repo for detail.

        @param to_test: support these test items:
                        move: Checks snd_pcm_forward API.
                        fill: Checks snd_pcm_mmap_begin API.
                        drop: Checks snd_pcm_drop API.

        """
        # Skip test_drop on boards that do not implement snd_pcm_drop
        # correctly, as it cannot pass.
        board = utils.get_board().lower()
        if to_test == 'drop' and board in self._BOARDS_WITHOUT_DROP_SUPPORT:
            logging.info('Skipping test_drop for unsupported board: %s', board)
            return

        self._cardnames = alsa_utils.get_soundcard_names()
        self._devices = []
        self._find_sound_devices()
        method_name = '_test_' + to_test
        method = getattr(self, method_name)

        # Stop CRAS to make sure the audio device won't be occupied.
        utils.stop_service('cras', ignore_status=True)

        try:
            for card_index, device_index in self._devices:
                device = 'hw:%s,%s' % (card_index, device_index)
                method(device)
        finally:
            # Restart CRAS.
            utils.start_service('cras', ignore_status=True)
Exemplo n.º 4
0
    def run_once(self, duration=1, output_node="INTERNAL_SPEAKER"):
        """Run aplay and verify its output is as expected.

        @param duration: The duration to run aplay in seconds.
        @param output_node: The type of output device to test. It should be
                            INTERNAL_SPEAKER or HEADPHONE.
        """

        # Check CRAS server is alive. If not, restart it and wait a second to
        # get server ready.
        if utils.get_service_pid('cras') == 0:
            logging.debug("CRAS server is down. Restart it.")
            utils.start_service('cras', ignore_status=True)
            time.sleep(1)

        # Skip test if there is no internal speaker on the board.
        if output_node == "INTERNAL_SPEAKER":
            board_type = utils.get_board_type()
            board_name = utils.get_board()
            if not audio_spec.has_internal_speaker(board_type, board_name):
                logging.debug("No internal speaker. Skipping the test.")
                return

        cras_utils.set_single_selected_output_node(output_node)

        cras_device_type = cras_utils.get_selected_output_device_type()
        logging.debug("Selected output device type=%s", cras_device_type)
        if cras_device_type != output_node:
            raise error.TestFail("Fail to select output device.")

        cras_device_name = cras_utils.get_selected_output_device_name()
        logging.debug("Selected output device name=%s", cras_device_name)
        if cras_device_name is None:
            raise error.TestFail("Fail to get selected output device.")

        alsa_device_name = alsa_utils.convert_device_name(cras_device_name)

        # Stop CRAS to make sure the audio device won't be occupied.
        utils.stop_service('cras', ignore_status=True)
        try:
            _check_play(alsa_device_name, duration, APLAY_EXPECTED)
        finally:
            #Restart CRAS
            utils.start_service('cras', ignore_status=True)
Exemplo n.º 5
0
 def warmup(self):
     super(cras_rms_test, self).warmup()
     # Stop ui to make sure there are not other streams.
     utils.stop_service('ui', ignore_status=True)
     cras_rms_test_setup()
def stop(allow_fail=False):
    return utils.stop_service("ui", ignore_status=allow_fail)