コード例 #1
0
    def run_once(self, host, player):
        """

        Entry point for test case.

        @param host: A reference to the DUT.
        @param player: A string representing what audio player to use. Could
                       be 'native' or 'browser'.

        """

        if not audio_test_utils.has_internal_speaker(host):
            return

        host.chameleon.setup_and_reset(self.outputdir)

        facade_factory = remote_facade_factory.RemoteFacadeFactory(
            host, results_dir=self.resultsdir)
        self.audio_facade = facade_factory.create_audio_facade()
        self.browser_facade = facade_factory.create_browser_facade()

        widget_factory = chameleon_audio_helper.AudioWidgetFactory(
            facade_factory, host)
        self.sound_source = widget_factory.create_widget(
            chameleon_audio_ids.CrosIds.SPEAKER)
        self.sound_recorder = widget_factory.create_widget(
            chameleon_audio_ids.ChameleonIds.MIC)

        self.play_and_record(host, player, 'left')
        self.process_and_save_data(channel='left')
        self.validate_recorded_data(channel='left')

        self.play_and_record(host, player, 'right')
        self.process_and_save_data(channel='right')
        self.validate_recorded_data(channel='right')
コード例 #2
0
 def check_default_nodes(self):
     """Checks default audio nodes for devices with onboard audio support."""
     if audio_test_utils.has_internal_microphone(self.host):
         audio_test_utils.check_audio_nodes(self.audio_facade,
                                            (None, ['INTERNAL_MIC']))
     if audio_test_utils.has_internal_speaker(self.host):
         audio_test_utils.check_audio_nodes(self.audio_facade,
                                            (['INTERNAL_SPEAKER'], None))
コード例 #3
0
    def run_once(self, host):
        chameleon_board = host.chameleon
        factory = self.create_remote_facade_factory(host)
        audio_facade = factory.create_audio_facade()

        chameleon_board.reset()

        jack_plugger = chameleon_board.get_audio_board().get_jack_plugger()

        expected_plugged_nodes_without_audio_jack = ([], [
            'POST_DSP_LOOPBACK', 'POST_MIX_LOOPBACK'
        ])

        expected_plugged_nodes_with_audio_jack = (['HEADPHONE'], [
            'MIC', 'POST_DSP_LOOPBACK', 'POST_MIX_LOOPBACK'
        ])

        if audio_test_utils.has_internal_speaker(host):
            expected_plugged_nodes_without_audio_jack[0].append(
                'INTERNAL_SPEAKER')
            expected_plugged_nodes_with_audio_jack[0].append(
                'INTERNAL_SPEAKER')

        if audio_test_utils.has_internal_microphone(host):
            expected_plugged_nodes_without_audio_jack[1].append('INTERNAL_MIC')
            expected_plugged_nodes_with_audio_jack[1].append('INTERNAL_MIC')

        # Modify expected nodes for special boards.
        board_name = host.get_board().split(':')[1]

        if board_name == 'link':
            expected_plugged_nodes_without_audio_jack[1].append('KEYBOARD_MIC')
            expected_plugged_nodes_with_audio_jack[1].append('KEYBOARD_MIC')

        if board_name == 'samus':
            expected_plugged_nodes_without_audio_jack[1].append('AOKR')
            expected_plugged_nodes_with_audio_jack[1].append('AOKR')

        audio_test_utils.check_plugged_nodes(
            audio_facade, expected_plugged_nodes_without_audio_jack)

        try:
            jack_plugger.plug()
            time.sleep(self.DELAY_AFTER_PLUGGING)

            audio_test_utils.dump_cros_audio_logs(host, audio_facade,
                                                  self.resultsdir)

            audio_test_utils.check_plugged_nodes(
                audio_facade, expected_plugged_nodes_with_audio_jack)

        finally:
            jack_plugger.unplug()
            time.sleep(self.DELAY_AFTER_UNPLUGGING)

        audio_test_utils.check_plugged_nodes(
            audio_facade, expected_plugged_nodes_without_audio_jack)
コード例 #4
0
    def run_once(self, host, source_id, sink_id, recorder_id, volume_spec,
                 golden_file, switch_hsp=False):
        """Running audio volume test.

        @param host: device under test CrosHost
        @param source_id: An ID defined in chameleon_audio_ids for source.
        @param sink_id: An ID defined in chameleon_audio_ids for sink if needed.
                        Currently this is only used on bluetooth.
        @param recorder: An ID defined in chameleon_audio_ids for recording.
        @param volume_spec: A tuple (low_volume, high_volume, highest_ratio).
                            Low volume and high volume specifies the two volumes
                            used in the test, and highest_ratio speficies the
                            highest acceptable value for
                            recorded_volume_low / recorded_volume_high.
                            For example, (50, 100, 0.2) asserts that
                            (recorded magnitude at volume 50) should be lower
                            than (recorded magnitude at volume 100) * 0.2.
        @param golden_file: A test file defined in audio_test_data.
        @param switch_hsp: Run a recording process on Cros device. This is
                           to trigger Cros switching from A2DP to HSP.

        """
        if (source_id == chameleon_audio_ids.CrosIds.SPEAKER and
            not audio_test_utils.has_internal_speaker(host)):
            return

        chameleon_board = host.chameleon
        factory = remote_facade_factory.RemoteFacadeFactory(
                host, results_dir=self.resultsdir)

        chameleon_board.setup_and_reset(self.outputdir)

        widget_factory = chameleon_audio_helper.AudioWidgetFactory(
                factory, host)

        source = widget_factory.create_widget(source_id)
        recorder = widget_factory.create_widget(recorder_id)

        # Chameleon Mic does not need binding.
        binding = (recorder_id != chameleon_audio_ids.ChameleonIds.MIC)

        binder = None

        if binding:
            if sink_id:
                sink = widget_factory.create_widget(sink_id)
                binder = widget_factory.create_binder(source, sink, recorder)
            else:
                binder = widget_factory.create_binder(source, recorder)

        low_volume, high_volume, highest_ratio = volume_spec
        ignore_frequencies = [50, 60]

        second_peak_ratio = audio_test_utils.get_second_peak_ratio(
                source_id=source_id,
                recorder_id=recorder_id,
                is_hsp=switch_hsp)

        with chameleon_audio_helper.bind_widgets(binder):
            # Checks the node selected by cras is correct.
            time.sleep(self.DELAY_AFTER_BINDING)
            audio_facade = factory.create_audio_facade()

            audio_test_utils.dump_cros_audio_logs(
                    host, audio_facade, self.resultsdir, 'after_binding')

            audio_test_utils.check_output_port(audio_facade, source.port_id)

            if switch_hsp:
                audio_test_utils.switch_to_hsp(audio_facade)

            logging.info('Setting playback data on Cros device')
            source.set_playback_data(golden_file)

            def playback_record(tag):
                """Playback and record.

                @param tag: file name tag.

                """
                logging.info('Start recording from Chameleon.')
                recorder.start_recording()

                logging.info('Start playing %s on Cros device',
                             golden_file.path)
                source.start_playback()

                time.sleep(self.RECORD_SECONDS)

                recorder.stop_recording()
                logging.info('Stopped recording from Chameleon.')

                audio_test_utils.dump_cros_audio_logs(
                        host, audio_facade, self.resultsdir,
                        'after_recording_' + 'tag')

                source.stop_playback()

                recorder.read_recorded_binary()
                logging.info('Read recorded binary from Chameleon.')

                recorded_file = os.path.join(
                        self.resultsdir, "recorded_%s.raw" % tag)
                logging.info('Saving recorded data to %s', recorded_file)
                recorder.save_file(recorded_file)
                recorder.remove_head(0.5)

            audio_facade.set_chrome_active_volume(low_volume)
            playback_record('low')
            low_dominant_spectrals = audio_test_utils.check_recorded_frequency(
                    golden_file, recorder,
                    second_peak_ratio=second_peak_ratio,
                    ignore_frequencies=ignore_frequencies)

            audio_facade.set_chrome_active_volume(high_volume)
            playback_record('high')
            high_dominant_spectrals = audio_test_utils.check_recorded_frequency(
                    golden_file, recorder,
                    second_peak_ratio=second_peak_ratio,
                    ignore_frequencies=ignore_frequencies)

            error_messages = []
            logging.info('low_dominant_spectrals: %s', low_dominant_spectrals)
            logging.info('high_dominant_spectrals: %s', high_dominant_spectrals)

            for channel in xrange(len(low_dominant_spectrals)):
                _, low_coeff  = low_dominant_spectrals[channel]
                _, high_coeff  = high_dominant_spectrals[channel]
                ratio = low_coeff / high_coeff
                logging.info('Channel %d volume(at %f) / volume(at %f) = %f',
                             channel, low_volume, high_volume, ratio)
                if ratio > highest_ratio:
                    error_messages.append(
                            'Channel %d volume ratio: %f is incorrect.' % (
                                    channel, ratio))
            if error_messages:
                raise error.TestFail(
                        'Failed volume check: %s' % ' '.join(error_messages))
コード例 #5
0
    def run_once(self, host, source_id, sink_id, recorder_id,
                 golden_file, switch_hsp=False,
                 mute_duration_in_secs=None,
                 volume_changes=None,
                 record_secs=None):
        """Running audio volume test.

        mute_duration_in_secs and volume_changes couldn't be both not None.

        @param host: device under test CrosHost
        @param source_id: An ID defined in chameleon_audio_ids for source.
        @param sink_id: An ID defined in chameleon_audio_ids for sink if needed.
                        Currently this is only used on bluetooth.
        @param recorder: An ID defined in chameleon_audio_ids for recording.
        @param golden_file: A test file defined in audio_test_data.
        @param switch_hsp: Run a recording process on Cros device. This is
                           to trigger Cros switching from A2DP to HSP.
        @param mute_duration_in_secs: List of each duration of mute. For example,
                                      [0.4, 0.6] will have two delays, each
                                      duration will be 0.4 secs and 0.6 secs.
                                      And, between delays, there will be
                                      KEEP_VOLUME_SECONDS secs sine wave.
        @param volume_changes: List consisting of -1 and +1, where -1 denoting
                           decreasing volume, +1 denoting increasing volume.
                           Between each changes, the volume will be kept for
                           KEEP_VOLUME_SECONDS secs.
        @param record_secs: The duration of recording in seconds. If it is not
                            set, duration of the test data will be used. If
                            duration of test data is not set either, default
                            RECORD_SECONDS will be used.

        """
        if (source_id == chameleon_audio_ids.CrosIds.SPEAKER and
            not audio_test_utils.has_internal_speaker(host)):
            return

        chameleon_board = host.chameleon
        factory = remote_facade_factory.RemoteFacadeFactory(
                host, results_dir=self.resultsdir)

        chameleon_board.setup_and_reset(self.outputdir)

        widget_factory = chameleon_audio_helper.AudioWidgetFactory(
                factory, host)

        source = widget_factory.create_widget(source_id)
        recorder = widget_factory.create_widget(recorder_id)

        # Chameleon Mic does not need binding.
        binding = (recorder_id != chameleon_audio_ids.ChameleonIds.MIC)

        binder = None

        if binding:
            if sink_id:
                sink = widget_factory.create_widget(sink_id)
                binder = widget_factory.create_binder(source, sink, recorder)
            else:
                binder = widget_factory.create_binder(source, recorder)

        start_volume, low_volume, high_volume = 75, 50, 100

        if not record_secs:
            if golden_file.duration_secs:
                record_secs = golden_file.duration_secs
            else:
                record_secs = self.RECORD_SECONDS
        logging.debug('Record duration: %f seconds', record_secs)

        # Checks if the file is local or is served on web.
        file_url = getattr(golden_file, 'url', None)

        with chameleon_audio_helper.bind_widgets(binder):
            # Checks the node selected by cras is correct.
            time.sleep(self.DELAY_AFTER_BINDING)
            audio_facade = factory.create_audio_facade()

            audio_test_utils.dump_cros_audio_logs(
                    host, audio_facade, self.resultsdir, 'after_binding')

            audio_facade.set_chrome_active_volume(start_volume)

            audio_test_utils.check_output_port(audio_facade, source.port_id)

            if switch_hsp:
                audio_test_utils.switch_to_hsp(audio_facade)

            if not file_url:
                logging.info('Setting playback data on Cros device')
                source.set_playback_data(golden_file)

            logging.info('Start recording from Chameleon.')
            recorder.start_recording()

            if not file_url:
                logging.info('Start playing %s on Cros device',
                             golden_file.path)
                source.start_playback()
            else:
                logging.info('Start playing %s on Cros device using browser',
                             file_url)
                browser_facade = factory.create_browser_facade()
                tab_descriptor = browser_facade.new_tab(file_url)

            if volume_changes:
                time.sleep(self.START_PLAYBACK_SECONDS)
                for x in volume_changes:
                    if x == -1:
                        audio_facade.set_chrome_active_volume(low_volume)
                    if x == +1:
                        audio_facade.set_chrome_active_volume(high_volume)
                    time.sleep(self.KEEP_VOLUME_SECONDS)
                passed_time_secs = self.START_PLAYBACK_SECONDS
                passed_time_secs += len(volume_changes) * self.KEEP_VOLUME_SECONDS
                rest = max(0, record_secs - passed_time_secs)
                time.sleep(rest)
            elif mute_duration_in_secs:
                time.sleep(self.START_PLAYBACK_SECONDS)
                passed_time_seconds = self.START_PLAYBACK_SECONDS
                for mute_secs in mute_duration_in_secs:
                    audio_facade.set_chrome_active_volume(0)
                    time.sleep(mute_secs)
                    audio_facade.set_chrome_active_volume(start_volume)
                    time.sleep(self.KEEP_VOLUME_SECONDS)
                    passed_time_seconds += mute_secs + self.KEEP_VOLUME_SECONDS
                rest = max(0, record_secs - passed_time_seconds)
                time.sleep(rest)
            else:
                time.sleep(record_secs)

            recorder.stop_recording()
            logging.info('Stopped recording from Chameleon.')

            audio_test_utils.dump_cros_audio_logs(
                    host, audio_facade, self.resultsdir,
                    'after_recording')

            if file_url:
                browser_facade.close_tab(tab_descriptor)
            else:
                source.stop_playback()

            recorder.read_recorded_binary()
            logging.info('Read recorded binary from Chameleon.')

            recorded_file = os.path.join(
                    self.resultsdir, "recorded.raw" )
            logging.info('Saving recorded data to %s', recorded_file)
            recorder.save_file(recorded_file)

            audio_test_utils.check_recorded_frequency(
                    golden_file, recorder,
                    check_artifacts=True,
                    mute_durations=mute_duration_in_secs,
                    volume_changes=volume_changes)
コード例 #6
0
    def run_once(self,
                 host,
                 audio_nodes,
                 golden_data,
                 bind_from=None,
                 bind_to=None,
                 source=None,
                 recorder=None,
                 is_internal=False):
        """Runs the test main workflow

        @param host: A host object representing the DUT.
        @param audio_nodes: audio nodes supposed to be selected.
        @param golden_data: audio file and low pass filter frequency
           the audio file should be test data defined in audio_test_data
        @param bind_from: audio originating entity to be binded
            should be defined in chameleon_audio_ids
        @param bind_to: audio directed_to entity to be binded
            should be defined in chameleon_audio_ids
        @param source: source widget entity
            should be defined in chameleon_audio_ids
        @param recorder: recorder widget entity
            should be defined in chameleon_audio_ids
        @param is_internal: whether internal audio is tested flag

        """
        if (recorder == chameleon_audio_ids.CrosIds.INTERNAL_MIC
                and not audio_test_utils.has_internal_microphone(host)):
            return

        if (source == chameleon_audio_ids.CrosIds.SPEAKER
                and not audio_test_utils.has_internal_speaker(host)):
            return

        self.host = host
        self.audio_nodes = audio_nodes
        self.is_internal = is_internal

        self.second_peak_ratio = audio_test_utils.DEFAULT_SECOND_PEAK_RATIO
        self.ignore_frequencies = None
        if source == chameleon_audio_ids.CrosIds.SPEAKER:
            self.second_peak_ratio = 0.1
            self.ignore_frequencies = [50, 60]
        elif recorder == chameleon_audio_ids.CrosIds.INTERNAL_MIC:
            self.second_peak_ratio = 0.2

        self.errors = []
        self.golden_file, self.low_pass_freq = golden_data
        chameleon_board = self.host.chameleon
        self.factory = self.create_remote_facade_factory(self.host)
        self.audio_facade = self.factory.create_audio_facade()
        chameleon_board.reset()
        widget_factory = chameleon_audio_helper.AudioWidgetFactory(
            self.factory, host)

        # Two widgets are binded in the factory if necessary
        binder_widget = None
        bind_from_widget = None
        bind_to_widget = None
        if bind_from != None and bind_to != None:
            bind_from_widget = widget_factory.create_widget(bind_from)
            bind_to_widget = widget_factory.create_widget(bind_to)
            binder_widget = widget_factory.create_binder(
                bind_from_widget, bind_to_widget)

        # Additional widgets that could be part of the factory
        if source == None:
            source_widget = bind_from_widget
        else:
            source_widget = widget_factory.create_widget(source)
        if recorder == None:
            recorder_widget = bind_to_widget
        else:
            recorder_widget = widget_factory.create_widget(recorder)

        self.audio_board = chameleon_board.get_audio_board()

        # If there is no audio-board, test default state.
        if self.audio_board == None:
            plug_configs = [(True, True, True)]
        else:
            plug_configs = self.PLUG_CONFIGS

        test_index = 0
        for (plugged_before_suspend, plugged_after_suspend,
             plugged_before_resume) in plug_configs:
            plugged_after_resume = True
            test_index += 1

            # Reverse plugged states, when internal audio is tested
            if self.is_internal:
                plugged_after_resume = False
                plugged_before_suspend = not plugged_before_suspend
                plugged_after_suspend = not plugged_after_suspend
                plugged_before_resume = not plugged_before_resume
            test_case = (
                'TEST CASE %d: %s > suspend > %s > %s > resume > %s' %
                (test_index, 'PLUG' if plugged_before_suspend else 'UNPLUG',
                 'PLUG' if plugged_after_suspend else 'UNPLUG',
                 'PLUG' if plugged_before_resume else 'UNPLUG',
                 'PLUG' if plugged_after_resume else 'UNPLUG'))
            logging.info(test_case)

            # Plugged status before suspended
            self.action_plug_jack(plugged_before_suspend)

            self.suspend_resume(plugged_before_suspend, plugged_after_suspend,
                                plugged_before_resume, test_case)

            # Active (plugged for external) state after resume
            self.action_plug_jack(plugged_after_resume)

            if binder_widget != None:
                with chameleon_audio_helper.bind_widgets(binder_widget):
                    self.play_and_record(source_widget, recorder_widget)
            else:
                self.play_and_record(source_widget, recorder_widget)

            success, error_message = self.save_and_check_data(recorder_widget)
            if not success:
                self.errors.append('%s: Comparison failed: %s' % test_case,
                                   error_message)

        if self.errors:
            raise error.TestFail('; '.join(set(self.errors)))
    def run_once(self, host):

        if not audio_test_utils.has_internal_speaker(host):
            return

        golden_file = audio_test_data.SIMPLE_FREQUENCY_SPEAKER_TEST_FILE

        chameleon_board = host.chameleon
        factory = remote_facade_factory.RemoteFacadeFactory(
            host, results_dir=self.resultsdir)

        chameleon_board.setup_and_reset(self.outputdir)

        widget_factory = chameleon_audio_helper.AudioWidgetFactory(
            factory, host)

        source = widget_factory.create_widget(
            chameleon_audio_ids.CrosIds.SPEAKER)

        recorder = widget_factory.create_widget(
            chameleon_audio_ids.ChameleonIds.MIC)

        audio_facade = factory.create_audio_facade()

        audio_test_utils.dump_cros_audio_logs(host, audio_facade,
                                              self.resultsdir, 'start')

        # Checks the node selected by cras is correct.
        output_nodes, _ = audio_facade.get_selected_node_types()
        if output_nodes != ['INTERNAL_SPEAKER']:
            raise error.TestFail(
                '%s rather than internal speaker is selected on Cros '
                'device' % output_nodes)

        audio_facade.set_selected_output_volume(80)

        logging.info('Setting playback data on Cros device')
        source.set_playback_data(golden_file)

        # Starts playing, waits for some time, and then starts recording.
        # This is to avoid artifact caused by codec initialization.
        logging.info('Start playing %s on Cros device', golden_file.path)
        source.start_playback()

        time.sleep(self.DELAY_BEFORE_RECORD_SECONDS)
        logging.info('Start recording from Chameleon.')
        recorder.start_recording()

        time.sleep(self.RECORD_SECONDS)

        recorder.stop_recording()
        logging.info('Stopped recording from Chameleon.')

        audio_test_utils.dump_cros_audio_logs(host, audio_facade,
                                              self.resultsdir,
                                              'after_recording')

        recorder.read_recorded_binary()
        logging.info('Read recorded binary from Chameleon.')

        recorded_file = os.path.join(self.resultsdir, "recorded.raw")
        logging.info('Saving recorded data to %s', recorded_file)
        recorder.save_file(recorded_file)

        # Removes the beginning of recorded data. This is to avoid artifact
        # caused by Chameleon codec initialization in the beginning of
        # recording.
        recorder.remove_head(0.5)

        # Removes noise by a lowpass filter.
        recorder.lowpass_filter(1000)
        recorded_file = os.path.join(self.resultsdir, "recorded_filtered.raw")
        logging.info('Saving filtered data to %s', recorded_file)
        recorder.save_file(recorded_file)

        # Compares data by frequency. Audio signal recorded by microphone has
        # gone through analog processing and through the air.
        # This suffers from codec artifacts and noise on the path.
        # Comparing data by frequency is more robust than comparing by
        # correlation, which is suitable for fully-digital audio path like USB
        # and HDMI.
        audio_test_utils.check_recorded_frequency(golden_file,
                                                  recorder,
                                                  second_peak_ratio=0.1,
                                                  ignore_frequencies=[50, 60])
コード例 #8
0
    def run_once(self, host):
        chameleon_board = host.chameleon
        factory = remote_facade_factory.RemoteFacadeFactory(
            host, results_dir=self.resultsdir)
        audio_facade = factory.create_audio_facade()

        chameleon_board.setup_and_reset(self.outputdir)

        jack_plugger = chameleon_board.get_audio_board().get_jack_plugger()

        expected_plugged_nodes_without_audio_jack = ([], [
            'POST_DSP_LOOPBACK', 'POST_MIX_LOOPBACK'
        ])

        # 'Headphone' or 'LINEOUT' will be added to expected list after jack
        # is plugged.
        expected_plugged_nodes_with_audio_jack = ([], [
            'MIC', 'POST_DSP_LOOPBACK', 'POST_MIX_LOOPBACK'
        ])

        if audio_test_utils.has_internal_speaker(host):
            expected_plugged_nodes_without_audio_jack[0].append(
                'INTERNAL_SPEAKER')
            expected_plugged_nodes_with_audio_jack[0].append(
                'INTERNAL_SPEAKER')

        if audio_test_utils.has_internal_microphone(host):
            expected_plugged_nodes_without_audio_jack[1].append('INTERNAL_MIC')
            expected_plugged_nodes_with_audio_jack[1].append('INTERNAL_MIC')

        # Modify expected nodes for special boards.
        board_name = host.get_board().split(':')[1]

        if board_name == 'link':
            expected_plugged_nodes_without_audio_jack[1].append('KEYBOARD_MIC')
            expected_plugged_nodes_with_audio_jack[1].append('KEYBOARD_MIC')

        if board_name in ['samus', 'kevin', 'eve', 'pyro']:
            expected_plugged_nodes_without_audio_jack[1].append('HOTWORD')
            expected_plugged_nodes_with_audio_jack[1].append('HOTWORD')

        audio_test_utils.check_plugged_nodes(
            audio_facade, expected_plugged_nodes_without_audio_jack)

        try:
            jack_plugger.plug()
            time.sleep(self.DELAY_AFTER_PLUGGING)

            audio_test_utils.dump_cros_audio_logs(host, audio_facade,
                                                  self.resultsdir)

            # Checks whether line-out or headphone is detected.
            hp_jack_node_type = audio_test_utils.check_hp_or_lineout_plugged(
                audio_facade)
            expected_plugged_nodes_with_audio_jack[0].append(hp_jack_node_type)

            audio_test_utils.check_plugged_nodes(
                audio_facade, expected_plugged_nodes_with_audio_jack)

        finally:
            jack_plugger.unplug()
            time.sleep(self.DELAY_AFTER_UNPLUGGING)

        audio_test_utils.check_plugged_nodes(
            audio_facade, expected_plugged_nodes_without_audio_jack)
コード例 #9
0
    def run_once(self, host, golden_data, audio_nodes, bind_from=None,
                 bind_to=None, source=None, recorder=None, is_internal=False,
                 cfm_speaker=False):
        """Runs the test main workflow.

        @param host: A host object representing the DUT.
        @param golden_data: audio file and low pass filter frequency
           the audio file should be test data defined in audio_test_data
        @param audio_nodes: audio nodes supposed to be selected
        @param bind_from: audio originating entity to be binded
            should be defined in chameleon_audio_ids
        @param bind_to: audio directed_to entity to be binded
            should be defined in chameleon_audio_ids
        @param source: source widget entity
            should be defined in chameleon_audio_ids
        @param recorder: recorder widget entity
            should be defined in chameleon_audio_ids
        @param is_internal: whether internal audio is tested flag
        @param cfm_speaker: whether cfm_speaker's audio is tested which is an
            external USB speaker on CFM (ChromeBox For Meetings) devices.

        """
        if (recorder == chameleon_audio_ids.CrosIds.INTERNAL_MIC and
            (not cfm_speaker and
            not audio_test_utils.has_internal_microphone(host))):
            return

        if (source == chameleon_audio_ids.CrosIds.SPEAKER and
            (not cfm_speaker and
            not audio_test_utils.has_internal_speaker(host))):
            return

        self.host = host
        self.audio_nodes = audio_nodes
        self.golden_file, self.low_pass_freq = golden_data
        chameleon_board = self.host.chameleon
        self.factory = remote_facade_factory.RemoteFacadeFactory(
                self.host, results_dir=self.resultsdir)
        self.audio_facade = self.factory.create_audio_facade()
        chameleon_board.setup_and_reset(self.outputdir)
        widget_factory = chameleon_audio_helper.AudioWidgetFactory(
                self.factory, host)
        self.audio_board = chameleon_board.get_audio_board()
        self.widget_link = None
        self.use_audio_bus = False

        self.second_peak_ratio = audio_test_utils.get_second_peak_ratio(
                source_id=source,
                recorder_id=recorder)

        self.ignore_frequencies = None
        if source == chameleon_audio_ids.CrosIds.SPEAKER:
            self.ignore_frequencies = [50, 60]

        # Two widgets are binded in the factory if necessary
        binder_widget = None
        bind_from_widget = None
        bind_to_widget = None
        if bind_from != None and bind_to != None:
            bind_from_widget = widget_factory.create_widget(bind_from)
            bind_to_widget = widget_factory.create_widget(bind_to)
            binder_widget = widget_factory.create_binder(bind_from_widget,
                                                         bind_to_widget)
            self.widget_link = binder_widget.get_link()
            if isinstance(self.widget_link, audio_widget_link.AudioBusLink):
                self.use_audio_bus = True

        # Additional widgets that could be part of the factory
        if source == None:
            source_widget = bind_from_widget
        else:
            source_widget = widget_factory.create_widget(source)
        if recorder == None:
            recorder_widget = bind_to_widget
        else:
            recorder_widget = widget_factory.create_widget(recorder)

        # Plug for external audio
        self.action_plug_jack(not is_internal)

        # Play only, reboot, then play and record.
        if binder_widget != None:
            with chameleon_audio_helper.bind_widgets(binder_widget):
                time.sleep(self.DELAY_AFTER_BINDING)
                self.play_reboot_play_and_record(source_widget, recorder_widget)
        else:
            self.play_reboot_play_and_record(source_widget, recorder_widget)

        self.save_and_check_data(recorder_widget)
コード例 #10
0
    def run_once(self, host, audio_nodes, audio_test_data, test_playback_file,
                 lowpass_freq=None,
                 bind_from=None, bind_to=None,
                 source=None, recorder=None,
                 tag=None):
        """Runs the test main workflow

        @param host: A host object representing the DUT.
        @param audio_nodes: audio nodes supposed to be selected.
        @param audio_test_data: audio test frequency defined in audio_test_data
        @param test_playback_file: audio media file(wav, mp3,...) to be used
            for testing
        @param lowpass_freq: frequency noise filter.
        @param bind_from: audio originating entity to be binded
            should be defined in chameleon_audio_ids
        @param bind_to: audio directed_to entity to be binded
            should be defined in chameleon_audio_ids
        @param source: source widget entity
            should be defined in chameleon_audio_ids
        @param recorder: recorder widget entity
            should be defined in chameleon_audio_ids

        """
        self.host = host
        self.audio_nodes = audio_nodes

        if (not audio_test_utils.has_internal_speaker(host) and
                tag == "internal_speaker"):
            return

        self.second_peak_ratio = audio_test_utils.get_second_peak_ratio(
                source_id=source,
                recorder_id=recorder)

        self.ignore_frequencies = None
        if source == chameleon_audio_ids.CrosIds.SPEAKER:
            self.ignore_frequencies = [50, 60]

        self.audio_test_data = audio_test_data
        self.lowpass_freq = lowpass_freq
        self.test_playback_file = test_playback_file
        chameleon_board = self.host.chameleon
        self.factory = remote_facade_factory.RemoteFacadeFactory(
                self.host, results_dir=self.resultsdir)
        self.audio_facade = self.factory.create_audio_facade()
        chameleon_board.setup_and_reset(self.outputdir)
        widget_factory = chameleon_audio_helper.AudioWidgetFactory(
                self.factory, host)

        # Two widgets are binded in the factory if necessary.
        binder_widget = None
        source_widget = None
        recorder_widget = None
        if bind_from != None and bind_to != None:
            source_widget = widget_factory.create_widget(bind_from)
            recorder_widget = widget_factory.create_widget(bind_to)
            binder_widget = widget_factory.create_binder(source_widget,
                                                         recorder_widget)
        elif source != None and recorder != None:
            source_widget = widget_factory.create_widget(source)
            recorder_widget = widget_factory.create_widget(recorder)
        else:
            raise error.TestError('Test configuration or setup problem.')

        self.audio_board = chameleon_board.get_audio_board()

        if binder_widget:
            # Headphone test which requires Chameleon LINEIN and DUT headphones
            # binding.
            with chameleon_audio_helper.bind_widgets(binder_widget):
                self.play_and_record(recorder_widget)
        else:
            # Internal speakers test.
            self.play_and_record(recorder_widget)

        self.save_and_check_data(recorder_widget)
コード例 #11
0
    def run_once(self, host, jack_node=False, hdmi_node=False, usb_node=False):
        self.host = host
        chameleon_board = host.chameleon
        audio_board = chameleon_board.get_audio_board()
        factory = self.create_remote_facade_factory(host)

        chameleon_board.reset()
        self.audio_facade = factory.create_audio_facade()
        self.display_facade = factory.create_display_facade()

        self.check_default_nodes()
        nodes = []
        if audio_test_utils.has_internal_speaker(self.host):
            self.set_active_volume_to_node_volume('INTERNAL_SPEAKER')
            nodes.append('INTERNAL_SPEAKER')
            self.switch_nodes_and_check_volume(nodes)


        if hdmi_node:
            edid_path = os.path.join(self.bindir,
                                     'test_data/edids/HDMI_DELL_U2410.txt')
            finder = chameleon_port_finder.ChameleonVideoInputFinder(
                chameleon_board, self.display_facade)
            hdmi_port = finder.find_port('HDMI')
            hdmi_port.apply_edid(edid_lib.Edid.from_file(edid_path))
            time.sleep(self._APPLY_EDID_DELAY)
            hdmi_port.set_plug(True)
            time.sleep(self._PLUG_DELAY)

            audio_test_utils.check_audio_nodes(self.audio_facade,
                                               (['HDMI'], None))

            self.set_active_volume_to_node_volume('HDMI')
            nodes.append('HDMI')
            self.switch_nodes_and_check_volume(nodes)

        if jack_node:
            jack_plugger = audio_board.get_jack_plugger()
            jack_plugger.plug()
            time.sleep(self._PLUG_DELAY)
            audio_test_utils.dump_cros_audio_logs(host, self.audio_facade,
                                                  self.resultsdir)
            audio_test_utils.check_audio_nodes(self.audio_facade,
                                               (['HEADPHONE'], ['MIC']))

            self.set_active_volume_to_node_volume('HEADPHONE')
            nodes.append('HEADPHONE')
            self.switch_nodes_and_check_volume(nodes)

        if usb_node:
            widget_factory = chameleon_audio_helper.AudioWidgetFactory(
                factory, host)

            source = widget_factory.create_widget(
                chameleon_audio_ids.CrosIds.USBOUT)
            recorder = widget_factory.create_widget(
                chameleon_audio_ids.ChameleonIds.USBIN)
            binder = widget_factory.create_binder(source, recorder)

            with chameleon_audio_helper.bind_widgets(binder):
                time.sleep(self._PLUG_DELAY)
                audio_test_utils.check_audio_nodes(self.audio_facade,
                                                   (['USB'], ['USB']))
                self.set_active_volume_to_node_volume('USB')
                nodes.append('USB')
                self.switch_nodes_and_check_volume(nodes)
            time.sleep(self._PLUG_DELAY)
            nodes.remove('USB')
            self.switch_nodes_and_check_volume(nodes)

        if jack_node:
            if usb_node:
                audio_test_utils.check_audio_nodes(self.audio_facade,
                                                   (['HEADPHONE'], ['MIC']))
            jack_plugger.unplug()
            time.sleep(self._PLUG_DELAY)
            nodes.remove('HEADPHONE')
            self.switch_nodes_and_check_volume(nodes)

        if hdmi_node:
            if usb_node or jack_node :
                audio_test_utils.check_audio_nodes(self.audio_facade,
                                                   (['HDMI'], None))
            hdmi_port.set_plug(False)
            time.sleep(self._PLUG_DELAY)
            nodes.remove('HDMI')
            self.switch_nodes_and_check_volume(nodes)

        self.check_default_nodes()
コード例 #12
0
    def run_once(self,
                 host,
                 jack_node=False,
                 hdmi_node=False,
                 usb_node=False,
                 play_audio=False):
        self.host = host
        chameleon_board = host.chameleon
        audio_board = chameleon_board.get_audio_board()
        factory = remote_facade_factory.RemoteFacadeFactory(
            host, results_dir=self.resultsdir)

        chameleon_board.setup_and_reset(self.outputdir)
        self.audio_facade = factory.create_audio_facade()
        self.display_facade = factory.create_display_facade()

        self.check_default_nodes()
        nodes = []
        if audio_test_utils.has_internal_speaker(self.host):
            self.set_active_volume_to_node_volume('INTERNAL_SPEAKER')
            nodes.append('INTERNAL_SPEAKER')
            self.switch_nodes_and_check_volume(nodes)

        if play_audio:
            self.browser_facade = factory.create_browser_facade()
            self.browser_facade.new_tab(URL)
            time.sleep(self._WAIT_TO_LOAD_VIDEO)
        if hdmi_node:
            edid_path = os.path.join(self.bindir,
                                     'test_data/edids/HDMI_DELL_U2410.txt')
            finder = chameleon_port_finder.ChameleonVideoInputFinder(
                chameleon_board, self.display_facade)
            hdmi_port = finder.find_port('HDMI')
            hdmi_port.apply_edid(edid_lib.Edid.from_file(edid_path))
            time.sleep(self._APPLY_EDID_DELAY)
            hdmi_port.set_plug(True)
            time.sleep(self._PLUG_DELAY * 2)

            audio_test_utils.check_audio_nodes(self.audio_facade,
                                               (['HDMI'], None))
            if play_audio:
                self.audio_facade.check_audio_stream_at_selected_device()
            self.set_active_volume_to_node_volume('HDMI')
            nodes.append('HDMI')
            self.switch_nodes_and_check_volume(nodes)

        if jack_node:
            jack_plugger = audio_board.get_jack_plugger()
            jack_plugger.plug()
            time.sleep(self._PLUG_DELAY)
            audio_test_utils.dump_cros_audio_logs(host, self.audio_facade,
                                                  self.resultsdir)

            # Checks whether line-out or headphone is detected.
            hp_jack_node_type = audio_test_utils.check_hp_or_lineout_plugged(
                self.audio_facade)

            audio_test_utils.check_audio_nodes(self.audio_facade,
                                               (None, ['MIC']))

            self.set_active_volume_to_node_volume(hp_jack_node_type)

            nodes.append(hp_jack_node_type)
            self.switch_nodes_and_check_volume(nodes)

        if usb_node:
            widget_factory = chameleon_audio_helper.AudioWidgetFactory(
                factory, host)

            source = widget_factory.create_widget(
                chameleon_audio_ids.CrosIds.USBOUT)
            recorder = widget_factory.create_widget(
                chameleon_audio_ids.ChameleonIds.USBIN)
            binder = widget_factory.create_binder(source, recorder)

            with chameleon_audio_helper.bind_widgets(binder):
                time.sleep(self._PLUG_DELAY)
                audio_test_utils.check_audio_nodes(self.audio_facade,
                                                   (['USB'], ['USB']))
                self.set_active_volume_to_node_volume('USB')
                nodes.append('USB')
                self.switch_nodes_and_check_volume(nodes)
            time.sleep(self._PLUG_DELAY)
            nodes.remove('USB')
            self.switch_nodes_and_check_volume(nodes)

        if jack_node:
            if usb_node:
                audio_test_utils.check_audio_nodes(
                    self.audio_facade, ([hp_jack_node_type], ['MIC']))
            jack_plugger.unplug()
            time.sleep(self._PLUG_DELAY)
            nodes.remove(hp_jack_node_type)
            self.switch_nodes_and_check_volume(nodes)

        if hdmi_node:
            if usb_node or jack_node:
                audio_test_utils.check_audio_nodes(self.audio_facade,
                                                   (['HDMI'], None))
            hdmi_port.set_plug(False)
            time.sleep(self._PLUG_DELAY)
            nodes.remove('HDMI')
            self.switch_nodes_and_check_volume(nodes)

        self.check_default_nodes()
コード例 #13
0
    def run_once(self,
                 host,
                 audio_nodes,
                 golden_data,
                 bind_from=None,
                 bind_to=None,
                 source=None,
                 recorder=None,
                 plug_status=None):
        """Runs the test main workflow

        @param host: A host object representing the DUT.
        @param audio_nodes: audio nodes supposed to be selected.
        @param golden_data: audio file and low pass filter frequency
           the audio file should be test data defined in audio_test_data
        @param bind_from: audio originating entity to be binded
            should be defined in chameleon_audio_ids
        @param bind_to: audio directed_to entity to be binded
            should be defined in chameleon_audio_ids
        @param source: source widget entity
            should be defined in chameleon_audio_ids
        @param recorder: recorder widget entity
            should be defined in chameleon_audio_ids
        @param plug_status: audio channel plug unplug sequence

        """
        if (recorder == chameleon_audio_ids.CrosIds.INTERNAL_MIC
                and not audio_test_utils.has_internal_microphone(host)):
            return

        if (source == chameleon_audio_ids.CrosIds.SPEAKER
                and not audio_test_utils.has_internal_speaker(host)):
            return

        self.host = host
        self.audio_nodes = audio_nodes

        self.second_peak_ratio = audio_test_utils.get_second_peak_ratio(
            source_id=source, recorder_id=recorder)

        self.ignore_frequencies = None
        if source == chameleon_audio_ids.CrosIds.SPEAKER:
            self.ignore_frequencies = [50, 60]

        self.errors = []
        self.golden_file, self.low_pass_freq = golden_data
        chameleon_board = self.host.chameleon
        self.factory = remote_facade_factory.RemoteFacadeFactory(
            self.host, results_dir=self.resultsdir)
        self.audio_facade = self.factory.create_audio_facade()
        chameleon_board.setup_and_reset(self.outputdir)
        widget_factory = chameleon_audio_helper.AudioWidgetFactory(
            self.factory, host)

        # Two widgets are binded in the factory if necessary
        binder_widget = None
        bind_from_widget = None
        bind_to_widget = None
        if bind_from != None and bind_to != None:
            bind_from_widget = widget_factory.create_widget(bind_from)
            bind_to_widget = widget_factory.create_widget(bind_to)
            binder_widget = widget_factory.create_binder(
                bind_from_widget, bind_to_widget)

        # Additional widgets that could be part of the factory
        if source == None:
            source_widget = bind_from_widget
        else:
            source_widget = widget_factory.create_widget(source)
        if recorder == None:
            recorder_widget = bind_to_widget
        else:
            recorder_widget = widget_factory.create_widget(recorder)

        self.audio_board = chameleon_board.get_audio_board()

        test_index = 0
        for (plugged_before_suspend, plugged_after_suspend,
             plugged_before_resume, plugged_after_resume) in plug_status:
            test_index += 1

            test_case = (
                'TEST CASE %d: %s > suspend > %s > %s > resume > %s' %
                (test_index, 'PLUG' if plugged_before_suspend else 'UNPLUG',
                 'PLUG' if plugged_after_suspend else 'UNPLUG',
                 'PLUG' if plugged_before_resume else 'UNPLUG',
                 'PLUG' if plugged_after_resume else 'UNPLUG'))
            logging.info(test_case)

            # Plugged status before suspended
            self.action_plug_jack(plugged_before_suspend)

            self.suspend_resume(plugged_before_suspend, plugged_after_suspend,
                                plugged_before_resume, test_case)

            # Active (plugged for external) state after resume
            self.action_plug_jack(plugged_after_resume)

            if binder_widget != None:
                with chameleon_audio_helper.bind_widgets(binder_widget):
                    self.play_and_record(source_widget, recorder_widget)
            else:
                self.play_and_record(source_widget, recorder_widget)

            success, error_message = self.save_and_check_data(recorder_widget)
            if not success:
                self.errors.append('%s: Comparison failed: %s' %
                                   (test_case, error_message))

        if self.errors:
            raise error.TestFail('; '.join(set(self.errors)))
コード例 #14
0
    def run_once(self,
                 host,
                 source_id,
                 sink_id,
                 recorder_id,
                 golden_file,
                 switch_hsp=False):
        """Runs record test through ARC on Cros device.

        @param host: device under test, a CrosHost.
        @param source_id: An ID defined in chameleon_audio_ids for source.
        @param sink_id: An ID defined in chameleon_audio_ids for sink if needed.
                        Currently this is only used on bluetooth.
        @param recorder_id: An ID defined in chameleon_audio_ids for recording.
        @param golden_file: A test file defined in audio_test_data.
        @param switch_hsp: Run a recording process on Cros device. This is
                           to trigger Cros switching from A2DP to HSP.

        """
        self.host = host

        if (source_id == chameleon_audio_ids.CrosIds.SPEAKER
                and not audio_test_utils.has_internal_speaker(host)):
            return

        self.client_at = None

        # Runs a client side test to start Chrome and install Play Music app.
        self.setup_playmusic_app()

        # Do not start Chrome because client side test had started it.
        # Do not install autotest because client side test had installed it.
        factory = remote_facade_factory.RemoteFacadeFactory(
            host,
            no_chrome=True,
            install_autotest=False,
            results_dir=self.resultsdir)

        # Setup Chameleon and create widgets.
        host.chameleon.setup_and_reset(self.outputdir)

        widget_factory = chameleon_audio_helper.AudioWidgetFactory(
            factory, host)

        source = widget_factory.create_widget(source_id, use_arc=True)
        recorder = widget_factory.create_widget(recorder_id)

        # Chameleon Mic does not need binding.
        binding = (recorder_id != chameleon_audio_ids.ChameleonIds.MIC)

        binder = None

        if binding:
            if sink_id:
                sink = widget_factory.create_widget(sink_id)
                binder = widget_factory.create_binder(source, sink, recorder)
            else:
                binder = widget_factory.create_binder(source, recorder)

        # Second peak ratio is determined by quality of audio path.
        second_peak_ratio = audio_test_utils.get_second_peak_ratio(
            source_id=source_id, recorder_id=recorder_id, is_hsp=switch_hsp)

        with chameleon_audio_helper.bind_widgets(binder):
            time.sleep(self.DELAY_AFTER_BINDING)

            audio_facade = factory.create_audio_facade()

            audio_test_utils.dump_cros_audio_logs(host, audio_facade,
                                                  self.resultsdir,
                                                  'after_binding')

            # Checks the node selected by CRAS is correct.
            audio_test_utils.check_output_port(audio_facade, source.port_id)

            if switch_hsp:
                audio_test_utils.switch_to_hsp(audio_facade)

            logging.info('Setting playback file on Cros device')
            source.set_playback_data(golden_file)

            logging.info('Start recording from Chameleon')
            recorder.start_recording()

            logging.info('Start playing %s on Cros device', golden_file.path)
            source.start_playback()

            time.sleep(self.WAIT_PLAYBACK_SECS)

            recorder.stop_recording()
            logging.info('Stopped recording from Chameleon.')

            audio_test_utils.dump_cros_audio_logs(host, audio_facade,
                                                  self.resultsdir,
                                                  'after_recording')

            recorder.read_recorded_binary()
            logging.info('Read recorded binary from Chameleon.')

            recorded_file = os.path.join(self.resultsdir, "recorded.raw")
            logging.info('Saving recorded data to %s', recorded_file)
            recorder.save_file(recorded_file)

            audio_test_utils.check_recorded_frequency(
                golden_file, recorder, second_peak_ratio=second_peak_ratio)
コード例 #15
0
    def run_once(self, host):
        chameleon_board = host.chameleon
        factory = remote_facade_factory.RemoteFacadeFactory(
            host, results_dir=self.resultsdir)
        audio_facade = factory.create_audio_facade()

        chameleon_board.setup_and_reset(self.outputdir)

        jack_plugger = chameleon_board.get_audio_board().get_jack_plugger()

        expected_plugged_nodes_without_audio_jack = ([], [
            'POST_DSP_LOOPBACK', 'POST_MIX_LOOPBACK'
        ])

        # 'Headphone' or 'LINEOUT' will be added to expected list after jack
        # is plugged.
        expected_plugged_nodes_with_audio_jack = ([], [
            'MIC', 'POST_DSP_LOOPBACK', 'POST_MIX_LOOPBACK'
        ])

        # Modify expected nodes for special boards.
        board_name = host.get_board().split(':')[1]
        model_name = host.get_platform()

        if audio_test_utils.has_internal_speaker(host):
            expected_plugged_nodes_without_audio_jack[0].append(
                'INTERNAL_SPEAKER')
            expected_plugged_nodes_with_audio_jack[0].append(
                'INTERNAL_SPEAKER')

        if audio_test_utils.has_internal_microphone(host):
            expected_internal_mics = cras_configs.get_plugged_internal_mics(
                board_name, model_name)
            expected_plugged_nodes_without_audio_jack[1].extend(
                expected_internal_mics)
            expected_plugged_nodes_with_audio_jack[1].extend(
                expected_internal_mics)

        if board_name == 'link':
            expected_plugged_nodes_without_audio_jack[1].append('KEYBOARD_MIC')
            expected_plugged_nodes_with_audio_jack[1].append('KEYBOARD_MIC')

        if audio_spec.has_hotwording(board_name, model_name):
            expected_plugged_nodes_without_audio_jack[1].append('HOTWORD')
            expected_plugged_nodes_with_audio_jack[1].append('HOTWORD')

        # If there is no jack plugger, check the nodes without plugging.
        host_info = host.host_info_store.get()
        if jack_plugger is None:
            if 'audio_box' in host_info.labels:
                raise error.TestError("Failed to detect jack plugger.")
            hp_jack_node_type = audio_test_utils.check_hp_or_lineout_plugged(
                audio_facade)
            expected_plugged_nodes_with_audio_jack[0].append(hp_jack_node_type)

            audio_test_utils.check_plugged_nodes(
                audio_facade, expected_plugged_nodes_with_audio_jack)
            return

        audio_test_utils.check_plugged_nodes(
            audio_facade, expected_plugged_nodes_without_audio_jack)

        try:
            jack_plugger.plug()
            time.sleep(self.DELAY_AFTER_PLUGGING)

            audio_test_utils.dump_cros_audio_logs(host, audio_facade,
                                                  self.resultsdir)

            # Checks whether line-out or headphone is detected.
            hp_jack_node_type = audio_test_utils.check_hp_or_lineout_plugged(
                audio_facade)
            expected_plugged_nodes_with_audio_jack[0].append(hp_jack_node_type)

            audio_test_utils.check_plugged_nodes(
                audio_facade, expected_plugged_nodes_with_audio_jack)

        finally:
            jack_plugger.unplug()
            time.sleep(self.DELAY_AFTER_UNPLUGGING)

        audio_test_utils.check_plugged_nodes(
            audio_facade, expected_plugged_nodes_without_audio_jack)