Exemplo n.º 1
0
    def run_once(self, host, repeat):
        factory = remote_facade_factory.RemoteFacadeFactory(host)
        self.display_facade = factory.create_display_facade()
        chameleon_board = host.chameleon

        chameleon_board.reset()
        finder = chameleon_port_finder.ChameleonVideoInputFinder(
            chameleon_board, self.display_facade)

        self.errors = []
        for chameleon_port in finder.iterate_all_ports():
            self.chameleon_port = chameleon_port
            self.screen_test = chameleon_screen_test.ChameleonScreenTest(
                chameleon_port, self.display_facade, self.outputdir)

            logging.debug('See the display on Chameleon: port %d (%s)',
                          self.chameleon_port.get_connector_id(),
                          self.chameleon_port.get_connector_type())
            # Keep the original connector name, for later comparison.
            self.connector_used = (
                self.display_facade.get_external_connector_name())

            for i in xrange(repeat):
                logging.info("Iteration %d", (i + 1))
                self.set_mode_and_check(False)
                self.set_mode_and_check(True)
    def run_once(self, host, repeat, no_check=False):
        if not host.get_board_type() == 'CHROMEBOOK':
            raise error.TestNAError('DUT is not Chromebook. Test Skipped')

        factory = remote_facade_factory.RemoteFacadeFactory(host)
        self.display_facade = factory.create_display_facade()
        chameleon_board = host.chameleon

        chameleon_board.setup_and_reset(self.outputdir)
        finder = chameleon_port_finder.ChameleonVideoInputFinder(
            chameleon_board, self.display_facade)

        self.errors = []
        for chameleon_port in finder.iterate_all_ports():
            self.chameleon_port = chameleon_port
            self.screen_test = chameleon_screen_test.ChameleonScreenTest(
                chameleon_port, self.display_facade, self.outputdir)

            logging.debug('See the display on Chameleon: port %d (%s)',
                          self.chameleon_port.get_connector_id(),
                          self.chameleon_port.get_connector_type())
            # Keep the original connector name, for later comparison.
            self.connector_used = (
                self.display_facade.get_external_connector_name())

            for i in xrange(repeat):
                logging.info("Iteration %d", (i + 1))
                self.set_mode_and_check(True, no_check)
                self.set_mode_and_check(False, no_check)
Exemplo n.º 3
0
    def run_once(self, host, plug_status, test_mirrored=False):

        # Check for chromebook type devices
        if not host.get_board_type() == 'CHROMEBOOK':
            raise error.TestNAError('DUT is not Chromebook. Test Skipped')

        # Check for incompatible with servo chromebooks
        board_name = host.get_board().split(':')[1]
        if board_name in self.INCOMPATIBLE_SERVO_BOARDS:
            raise error.TestNAError(
                'DUT is incompatible with servo. Skipping test.')

        self.host = host
        self.test_mirrored = test_mirrored
        self.errors = list()

        # Check the servo object
        if self.host.servo is None:
            raise error.TestError('Invalid servo object found on the host.')

        factory = remote_facade_factory.RemoteFacadeFactory(host)
        display_facade = factory.create_display_facade()
        chameleon_board = host.chameleon

        chameleon_board.setup_and_reset(self.outputdir)
        finder = chameleon_port_finder.ChameleonVideoInputFinder(
            chameleon_board, display_facade)
        for chameleon_port in finder.iterate_all_ports():
            self.run_test_on_port(chameleon_port, display_facade, plug_status)
 def _find_video_port(self):
     """Finds HDMI as a video port."""
     finder = chameleon_port_finder.ChameleonVideoInputFinder(
             self._chameleon_board, self._display_facade)
     self._hdmi_video_port = finder.find_port(self.interface)
     if not self._hdmi_video_port:
         raise ChameleonHDMIInputWidgetHandlerError(
                 'Can not find HDMI port, perhaps HDMI is not connected?')
    def run_once(self, host, edid_set):

        def _get_edid_type(s):
            i = s.rfind('_') + 1
            j = len(s) - len('.txt')
            return s[i:j].upper()

        edid_path = os.path.join(self.bindir, 'test_data', 'edids',
                                 edid_set, '*')

        factory = remote_facade_factory.RemoteFacadeFactory(host)
        display_facade = factory.create_display_facade()
        chameleon_board = host.chameleon

        chameleon_board.setup_and_reset(self.outputdir)
        finder = chameleon_port_finder.ChameleonVideoInputFinder(
                chameleon_board, display_facade)
        for chameleon_port in finder.iterate_all_ports():
            screen_test = chameleon_screen_test.ChameleonScreenTest(
                chameleon_port, display_facade, self.outputdir)

            logging.info('See the display on Chameleon: port %d (%s)',
                         chameleon_port.get_connector_id(),
                         chameleon_port.get_connector_type())

            connector = chameleon_port.get_connector_type()
            supported_types = self._EDID_TYPES[connector]

            failed_edids = []
            for filepath in glob.glob(edid_path):
                filename = os.path.basename(filepath)
                edid_type = _get_edid_type(filename)
                if edid_type not in supported_types:
                    logging.info('Skip EDID: %s...', filename)
                    continue

                logging.info('Use EDID: %s...', filename)
                try:
                    with chameleon_port.use_edid(
                            edid.Edid.from_file(filepath, skip_verify=True)):
                        resolution = utils.wait_for_value_changed(
                                display_facade.get_external_resolution,
                                old_value=None)
                        if resolution is None:
                            raise error.TestFail('No external display detected on DUT')
                        if screen_test.test_resolution(resolution):
                            raise error.TestFail('Resolution test failed')
                except (error.TestFail, xmlrpclib.Fault) as e:
                    logging.warning(e)
                    logging.error('EDID not supported: %s', filename)
                    failed_edids.append(filename)

            if failed_edids:
                message = ('Total %d EDIDs not supported: ' % len(failed_edids)
                           + ', '.join(failed_edids))
                logging.error(message)
                raise error.TestFail(message)
Exemplo n.º 6
0
    def start_dock_mode_measurement(self):
        """Starts the dock mode to measure.

        It iterates the connection ports between DUT and Chameleon and uses
        the first port. Sets DUT into the dock mode. Then yields the
        connected ports.

        It is used via a with statement, like the following:

            measurer = LocalChameleonMeasurer(cros_host, args, chrome)
            with measurer.start_dock_mode_measurement() as chameleon_port:
                # chameleon_port is automatically plugged before this line
                # and lid is close to enter doc mode.
                do_some_test_on(chameleon_port)
                # chameleon_port is automatically unplugged after this line
                # and lid is open again.

        @yields the first connected ChameleonVideoInput which is ensured plugged
                before yielding.

        @raises TestFail if no connected video port or fail to enter dock mode.
        """
        finder = chameleon_port_finder.ChameleonVideoInputFinder(
            self.chameleon, self.display_facade)
        try:
            with finder.use_first_port() as chameleon_port:
                logging.info('Used Chameleon port: %s',
                             chameleon_port.get_connector_type())

                logging.info('Close lid to switch into dock mode...')
                self.host.servo.lid_close()
                time.sleep(self._WAIT_TIME_LID_TRANSITION)

                # Hide the typing cursor.
                self.display_facade.hide_typing_cursor()

                # Sleep a while to wait the pop-up window faded-out.
                time.sleep(self._TIME_WAIT_FADE_OUT)

                # Get the resolution to make sure Chameleon in a good state.
                resolution = chameleon_port.get_resolution()
                logging.info('Detected the resolution: %dx%d', *resolution)

                # Check if it is dock mode, no internal screen.
                if self.display_facade.get_internal_resolution() is not None:
                    raise error.TestError('Failed to enter dock mode: '
                                          'internal display still valid')

                yield chameleon_port

        finally:
            logging.info('Open lid again...')
            self.host.servo.lid_open()
    def _find_connected_port(self):
        """
        Gets a connected port of the pre-specified interface.

        @raises TestError if desired port was not detected.

        """
        self.chameleon_board.reset()
        finder = chameleon_port_finder.ChameleonVideoInputFinder(
            self.chameleon_board, self.display_facade)

        connected_port = finder.find_port(self.interface)

        if connected_port is None:
            msg = 'No %s port found.\n' % self.interface
            raise error.TestError(msg + str(finder))

        self.port = connected_port
        self.was_plugged = connected_port.plugged
Exemplo n.º 8
0
    def run_once(self, host):
        factory = remote_facade_factory.RemoteFacadeFactory(host)
        display_facade = factory.create_display_facade()
        chameleon_board = host.chameleon

        chameleon_board.setup_and_reset(self.outputdir)

        finder = chameleon_port_finder.ChameleonVideoInputFinder(
            chameleon_board, display_facade)
        ports = finder.find_all_ports()

        connected_ports = ports.connected
        dut_failed_ports = ports.failed

        msg = str(finder)
        logging.debug(msg)

        if dut_failed_ports or not connected_ports:
            raise error.TestFail(msg)
    def run_once(self, host, args):
        ext_paths = [constants.DISPLAY_TEST_EXTENSION]
        with chrome.Chrome(extension_paths=ext_paths, autotest_ext=True) as cr:
            factory = local_facade_factory.LocalFacadeFactory(cr)
            display_facade = factory.create_display_facade()

            chameleon_board = chameleon.create_chameleon_board(
                host.hostname, args)
            chameleon_board.setup_and_reset(self.outputdir)
            finder = chameleon_port_finder.ChameleonVideoInputFinder(
                chameleon_board, display_facade)
            ports = finder.find_all_ports()

            connected_ports = ports.connected
            dut_failed_ports = ports.failed

            msg = str(finder)
            logging.debug(msg)

            if dut_failed_ports or not connected_ports:
                raise error.TestFail(msg)
    def run_once(self, host, test_mirrored=True):
        """Checks the mode is preserved after logout

        @param host: DUT object
        @param test_mirrored: True if mirror mode
        """
        self.host = host
        self.errors = list()
        chameleon_board = host.chameleon
        factory = remote_facade_factory.RemoteFacadeFactory(
            self.host, results_dir=self.resultsdir)
        self.display_facade = factory.create_display_facade()
        self.browser_facade = factory.create_browser_facade()
        self.input_facade = factory.create_input_facade()
        chameleon_board.setup_and_reset(self.outputdir)
        finder = chameleon_port_finder.ChameleonVideoInputFinder(
            chameleon_board, self.display_facade)

        # Iterates all connected video ports and ensures every of them plugged
        for chameleon_port in finder.iterate_all_ports():
            self.run_test_on_port(chameleon_port, test_mirrored)
Exemplo n.º 11
0
    def run_once(self, host, test_mirrored=False):
        factory = remote_facade_factory.RemoteFacadeFactory(host)
        self._display_facade = factory.create_display_facade()
        self._test_tab_descriptor = None
        chameleon_board = host.chameleon

        chameleon_board.reset()
        finder = chameleon_port_finder.ChameleonVideoInputFinder(
            chameleon_board, self._display_facade)

        errors = []
        for chameleon_port in finder.iterate_all_ports():

            logging.info('Set mirrored: %s', test_mirrored)
            self._display_facade.set_mirrored(test_mirrored)

            self._test_screen_with_color_sequence(test_mirrored,
                                                  chameleon_port, errors)

        if errors:
            raise error.TestFail('; '.join(set(errors)))
Exemplo n.º 12
0
    def start_mirrored_mode_measurement(self):
        """Starts the mirrored mode to measure.

        It iterates the connection ports between DUT and Chameleon and uses
        the first port. Sets DUT into the mirrored mode. Then yields the
        connected ports.

        It is used via a with statement, like the following:

            measurer = LocalChameleonMeasurer(cros_host, args, chrome)
            with measurer.start_mirrored_mode_measurement() as chameleon_port:
                # chameleon_port is automatically plugged before this line.
                do_some_test_on(chameleon_port)
                # chameleon_port is automatically unplugged after this line.

        @yields the first connected ChameleonVideoInput which is ensured plugged
                before yielding.

        @raises TestFail if no connected video port.
        """
        finder = chameleon_port_finder.ChameleonVideoInputFinder(
            self.chameleon, self.display_facade)
        with finder.use_first_port() as chameleon_port:
            logging.info('Used Chameleon port: %s',
                         chameleon_port.get_connector_type())

            logging.info('Setting to mirrored mode')
            self.display_facade.set_mirrored(True)

            # Hide the typing cursor.
            self.display_facade.hide_typing_cursor()

            # Sleep a while to wait the pop-up window faded-out.
            time.sleep(self._TIME_WAIT_FADE_OUT)

            # Get the resolution to make sure Chameleon in a good state.
            resolution = chameleon_port.get_resolution()
            logging.info('Detected the resolution: %dx%d', *resolution)

            yield chameleon_port
Exemplo n.º 13
0
    def run_once(self, host, test_mirrored=False):
        factory = remote_facade_factory.RemoteFacadeFactory(host)
        display_facade = factory.create_display_facade()
        chameleon_board = host.chameleon

        chameleon_board.setup_and_reset(self.outputdir)
        finder = chameleon_port_finder.ChameleonVideoInputFinder(
            chameleon_board, display_facade)

        errors = []
        for chameleon_port in finder.iterate_all_ports():
            screen_test = chameleon_screen_test.ChameleonScreenTest(
                host, chameleon_port, display_facade, self.outputdir)

            with chameleon_port.use_edid(edid.NO_EDID):
                connector_name = utils.wait_for_value_changed(
                    display_facade.get_external_connector_name,
                    old_value=False)
                if not connector_name:
                    error_message = 'Failed to detect display without an EDID'
                    logging.error(error_message)
                    errors.append(error_message)
                    continue

                logging.info('Set mirrored: %s', test_mirrored)
                display_facade.set_mirrored(test_mirrored)

                resolution = display_facade.get_external_resolution()
                if resolution not in self.STANDARD_MODE_RESOLUTIONS:
                    error_message = ('Switched to a non-standard mode: %r' %
                                     resolution)
                    logging.error(error_message)
                    errors.append(error_message)
                    continue

                screen_test.test_screen_with_image(resolution, test_mirrored,
                                                   errors)

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

        # Check for chromebook type devices
        if not host.get_board_type() == 'CHROMEBOOK':
            raise error.TestNAError('DUT is not Chromebook. Test Skipped')
        self.host = host
        self.test_mirrored = test_mirrored
        self.errors = list()

        # Check the servo object
        if self.host.servo is None:
            raise error.TestError('Invalid servo object found on the host.')

        factory = remote_facade_factory.RemoteFacadeFactory(host)
        display_facade = factory.create_display_facade()
        chameleon_board = host.chameleon

        chameleon_board.reset()
        finder = chameleon_port_finder.ChameleonVideoInputFinder(
            chameleon_board, display_facade)
        for chameleon_port in finder.iterate_all_ports():
            self.run_test_on_port(chameleon_port, display_facade, plug_status)
Exemplo n.º 15
0
    def run_once(self, host, subtest, test_duration=60):
        self._host = host
        self._subtest = subtest

        factory = remote_facade_factory.RemoteFacadeFactory(host)
        self._browser_facade = factory.create_browser_facade()
        self._browser_facade.start_custom_chrome(self.CHROME_KWARGS)
        self._display_facade = factory.create_display_facade()
        self._graphics_facade = factory.create_graphics_facade()

        logging.info('Preparing local WebGL test assets.')
        self._prepare_test_assets()

        chameleon_board = host.chameleon
        chameleon_board.setup_and_reset(self.outputdir)
        finder = chameleon_port_finder.ChameleonVideoInputFinder(
            chameleon_board, self._display_facade)

        # Snapshot the DUT system logs for any prior GPU hangs
        self._graphics_facade.graphics_state_checker_initialize()

        for chameleon_port in finder.iterate_all_ports():
            logging.info('Setting Chameleon screen to extended mode.')
            self._display_facade.set_mirrored(False)
            time.sleep(self.WAIT_AFTER_SWITCH)

            logging.info('Launching WebGL windows.')
            self._setup_windows()

            logging.info('Measuring the external display update rate.')
            self._measure_external_display_fps(chameleon_port)

            logging.info('Running test for {}s.'.format(test_duration))
            time.sleep(test_duration)

            # Raise an error on new GPU hangs
            self._graphics_facade.graphics_state_checker_finalize()
Exemplo n.º 16
0
    def run_once(self, host, plug_status, test_mirrored=False):
        if test_mirrored and not host.get_board_type() == 'CHROMEBOOK':
            raise error.TestNAError('DUT is not Chromebook. Test Skipped')

        factory = remote_facade_factory.RemoteFacadeFactory(host)
        display_facade = factory.create_display_facade()
        chameleon_board = host.chameleon

        chameleon_board.setup_and_reset(self.outputdir)
        finder = chameleon_port_finder.ChameleonVideoInputFinder(
            chameleon_board, display_facade)

        errors = []
        is_display_failure = False
        for chameleon_port in finder.iterate_all_ports():
            screen_test = chameleon_screen_test.ChameleonScreenTest(
                chameleon_port, display_facade, self.outputdir)

            logging.info('See the display on Chameleon: port %d (%s)',
                         chameleon_port.get_connector_id(),
                         chameleon_port.get_connector_type())

            logging.info('Set mirrored: %s', test_mirrored)
            display_facade.set_mirrored(test_mirrored)

            # Keep the original connector name, for later comparison.
            expected_connector = display_facade.get_external_connector_name()
            resolution = display_facade.get_external_resolution()
            logging.info('See the display on DUT: %s %r', expected_connector,
                         resolution)

            for (plugged_before_suspend, plugged_after_suspend,
                 plugged_before_resume) in plug_status:
                test_case = ('TEST CASE: %s > SUSPEND > %s > %s > RESUME' %
                             ('PLUG' if plugged_before_suspend else 'UNPLUG',
                              'PLUG' if plugged_after_suspend else 'UNPLUG',
                              'PLUG' if plugged_before_resume else 'UNPLUG'))
                logging.info(test_case)
                boot_id = host.get_boot_id()
                chameleon_port.set_plug(plugged_before_suspend)

                if screen_test.check_external_display_connected(
                        expected_connector
                        if plugged_before_suspend else False, errors):
                    is_display_failure = True
                    # Skip the following test if an unexpected display detected.
                    continue

                logging.info('GOING TO SUSPEND FOR %d SECONDS...',
                             self.SUSPEND_DURATION)
                time_before_suspend = time.time()
                display_facade.suspend_resume_bg(self.SUSPEND_DURATION)

                # Confirm DUT suspended.
                logging.info('WAITING FOR SUSPEND...')
                try:
                    host.test_wait_for_sleep(self.SUSPEND_TIMEOUT)
                except error.TestFail, ex:
                    errors.append("%s - %s" % (test_case, str(ex)))
                if plugged_after_suspend is not plugged_before_suspend:
                    chameleon_port.set_plug(plugged_after_suspend)

                current_time = time.time()
                sleep_time = (self.SUSPEND_DURATION -
                              (current_time - time_before_suspend) -
                              self.TIME_MARGIN_BEFORE_RESUME)
                if sleep_time > 0:
                    logging.info('- Sleep for %.2f seconds...', sleep_time)
                    time.sleep(sleep_time)
                if plugged_before_resume is not plugged_after_suspend:
                    chameleon_port.set_plug(plugged_before_resume)
                time.sleep(self.TIME_MARGIN_BEFORE_RESUME)

                logging.info('WAITING FOR RESUME...')
                try:
                    host.test_wait_for_resume(boot_id, self.RESUME_TIMEOUT)
                except error.TestFail, ex:
                    errors.append("%s - %s" % (test_case, str(ex)))

                logging.info('Resumed back')

                if screen_test.check_external_display_connected(
                        expected_connector if plugged_before_resume else False,
                        errors):
                    # Skip the following test if an unexpected display detected.
                    continue

                if plugged_before_resume:
                    if test_mirrored and (not utils.wait_for_value(
                            display_facade.is_mirrored_enabled,
                            True,
                            timeout_sec=self.TIMEOUT_WAITING_MIRRORED)):
                        error_message = 'Error: not resumed to mirrored mode'
                        errors.append("%s - %s" % (test_case, error_message))
                        logging.error(error_message)
                        logging.info('Set mirrored: %s', True)
                        display_facade.set_mirrored(True)
                    elif screen_test.test_screen_with_image(
                            resolution, test_mirrored, errors):
                        is_display_failure = True
    def run_once(self, host, test_mirrored=False, testcase_spec=None,
                 repeat_count=3, suspend_time_range=(5,7)):
        if test_mirrored and not host.get_board_type() == 'CHROMEBOOK':
            raise error.TestNAError('DUT is not Chromebook. Test Skipped')

        if testcase_spec is None:
            testcase_spec = self.DEFAULT_TESTCASE_SPEC

        test_name = "%s_%dx%d" % testcase_spec
        _, width, height = testcase_spec
        test_resolution = (width, height)

        if not edid.is_edid_supported(host, testcase_spec[1], testcase_spec[2]):
            raise error.TestFail('Error: EDID is not supported by the platform'
                    ': %s', test_name)

        edid_path = os.path.join(self.bindir, 'test_data', 'edids', test_name)

        factory = remote_facade_factory.RemoteFacadeFactory(host)
        display_facade = factory.create_display_facade()
        chameleon_board = host.chameleon

        chameleon_board.setup_and_reset(self.outputdir)
        finder = chameleon_port_finder.ChameleonVideoInputFinder(
                chameleon_board, display_facade)
        for chameleon_port in finder.iterate_all_ports():
            screen_test = chameleon_screen_test.ChameleonScreenTest(
                    chameleon_port, display_facade, self.outputdir)

            logging.info('Use EDID: %s', test_name)
            with chameleon_port.use_edid_file(edid_path):
                # Keep the original connector name, for later comparison.
                expected_connector = utils.wait_for_value_changed(
                        display_facade.get_external_connector_name,
                        old_value=False)
                logging.info('See the display on DUT: %s', expected_connector)

                if not expected_connector:
                    raise error.TestFail('Error: Failed to see external display'
                            ' (chameleon) from DUT: %s', test_name)

                logging.info('Set mirrored: %s', test_mirrored)
                display_facade.set_mirrored(test_mirrored)
                logging.info('Repeat %d times Suspend and resume', repeat_count)

                count = repeat_count
                while count > 0:
                    count -= 1
                    if test_mirrored:
                        # magic sleep to make nyan_big wake up in mirrored mode
                        # TODO: find root cause
                        time.sleep(6)
                    suspend_time = random.randint(*suspend_time_range)
                    logging.info('Going to suspend, for %d seconds...',
                                 suspend_time)
                    display_facade.suspend_resume(suspend_time)
                    logging.info('Resumed back')

                    message = screen_test.check_external_display_connected(
                            expected_connector)
                    if not message:
                        message = screen_test.test_screen_with_image(
                                test_resolution, test_mirrored)
                    if message:
                        raise error.TestFail(message)
    def run_once(self, host, test_mirrored=False, resolution_list=None):
        if not host.get_board_type() == 'CHROMEBOOK':
            raise error.TestNAError('DUT is not Chromebook. Test Skipped')
        if resolution_list is None:
            resolution_list = self.DEFAULT_RESOLUTION_LIST
        factory = remote_facade_factory.RemoteFacadeFactory(host)
        display_facade = factory.create_display_facade()
        chameleon_board = host.chameleon

        chameleon_board.reset()
        finder = chameleon_port_finder.ChameleonVideoInputFinder(
                chameleon_board, display_facade)

        errors = []
        for chameleon_port in finder.iterate_all_ports():
            screen_test = chameleon_screen_test.ChameleonScreenTest(
                    chameleon_port, display_facade, self.outputdir)
            chameleon_port_name = chameleon_port.get_connector_type()
            logging.info('Detected %s chameleon port.', chameleon_port_name)
            for interface, width, height in resolution_list:
                if not chameleon_port_name.startswith(interface):
                    continue
                test_resolution = (width, height)
                test_name = "%s_%dx%d" % ((interface,) + test_resolution)

                if not edid.is_edid_supported(host, interface, width, height):
                    logging.info('Skip unsupported EDID: %s', test_name)
                    continue
                edid_path = os.path.join(self.bindir, 'test_data', 'edids',
                                    test_name)

                logging.info('Use EDID: %s', test_name)

                with chameleon_port.use_edid_file(edid_path):
                    index = utils.wait_for_value_changed(
                            display_facade.get_first_external_display_index,
                            old_value=False)
                    if not index:
                        raise error.TestFail("No external display is found.")

                    # In mirror mode only display index is '0', as external
                    # is treated same as internal(single resolution applies)
                    if test_mirrored:
                        index = 0
                    logging.info('Set mirrored: %s', test_mirrored)
                    display_facade.set_mirrored(test_mirrored)
                    settings_resolution_list = (
                            display_facade.get_available_resolutions(index))
                    if len(settings_resolution_list) == 0:
                        raise error.TestFail("No resolution list is found.")
                    logging.info('External display %d: %d resolutions found.',
                                index, len(settings_resolution_list))

                    for r in settings_resolution_list:
                        # FIXME: send a keystroke to keep display on.
                        # This is to work around a problem where the display may be
                        # turned off if the test has run for a long time (e.g.,
                        # greater than 15 min). When the display is off,
                        # set_resolution() will fail.
                        display_facade.hide_cursor()

                        logging.info('Set resolution to %dx%d', *r)
                        display_facade.set_resolution(index, *r)
                        time.sleep(self.RESOLUTION_CHANGE_TIME)

                        chameleon_port.wait_video_input_stable()
                        screen_test.test_screen_with_image(r, test_mirrored, errors)

            if errors:
                raise error.TestFail('; '.join(set(errors)))
Exemplo n.º 19
0
    def run_once(self,
                 source_path,
                 codec,
                 resolution,
                 host,
                 args,
                 collect_only=False):

        board = utils.get_current_board()

        file_utils.make_leaf_dir(constants.TEST_DIR)

        with chrome.Chrome(
                extension_paths=[cros_constants.MULTIMEDIA_TEST_EXTENSION],
                autotest_ext=True) as cr:

            cr.browser.platform.SetHTTPServerDirectories(self.bindir)
            html_fullpath = os.path.join(self.bindir, 'video.html')
            player = native_html5_player.NativeHtml5Player(
                tab=cr.browser.tabs[0],
                full_url=cr.browser.platform.http_server.UrlOf(html_fullpath),
                video_id='video',
                video_src_path=source_path,
                event_timeout=120)

            chameleon_board = chameleon.create_chameleon_board(
                host.hostname, args)
            display_facade = local_facade_factory.LocalFacadeFactory(
                cr).create_display_facade()

            finder = chameleon_port_finder.ChameleonVideoInputFinder(
                chameleon_board, display_facade)

            capturer = chameleon_video_capturer.ChameleonVideoCapturer(
                finder.find_port(interface='hdmi'), display_facade)

            with capturer:
                player.load_video()

                player.verify_video_can_play()

                display_facade.move_to_display(
                    display_facade.get_first_external_display_index())
                display_facade.set_fullscreen(True)
                # HACK: Unset and reset fullscreen. There is a bug in Chrome
                # that fails to move the window to a correct position.
                # Resetting fullscren helps, check http://crbug.com/574284
                display_facade.set_fullscreen(False)
                display_facade.set_fullscreen(True)
                time.sleep(5)

                box = (0, 0, constants.DESIRED_WIDTH, constants.DESIRED_HEIGHT)

                #TODO: mussa, Revisit once crbug/580736 is fixed
                for n in xrange(constants.NUM_CAPTURE_TRIES):
                    logging.debug('Trying to capture frames. TRY #%d', n + 1)
                    raw_test_checksums = capturer.capture_only(
                        player, max_frame_count=constants.FCOUNT, box=box)

                    raw_test_checksums = [
                        tuple(checksum) for checksum in raw_test_checksums
                    ]

                    overreach_counts = self.overreach_frame_counts(
                        raw_test_checksums, constants.MAX_FRAME_REPEAT_COUNT)

                    if not overreach_counts:  # no checksums exceeded threshold
                        break

                    player.pause()
                    player.seek_to(datetime.timedelta(seconds=0))

                else:
                    msg = ('Framecount overreach detected even after %d '
                           'tries. Checksums: %s' %
                           (constants.NUM_CAPTURE_TRIES, overreach_counts))
                    raise error.TestFail(msg)

                # produces unique checksums mapped to their occur. indices
                test_checksum_indices = frame_checksum_utils.checksum_indices(
                    raw_test_checksums)

                test_checksums = test_checksum_indices.keys()

                test_indices = test_checksum_indices.values()

                golden_checksums_filepath = os.path.join(
                    constants.TEST_DIR, constants.GOLDEN_CHECKSUMS_FILENAME)

                if collect_only:
                    capturer.write_images(test_indices, constants.TEST_DIR,
                                          constants.IMAGE_FORMAT)

                    logging.debug("Write golden checksum file to %s",
                                  golden_checksums_filepath)

                    with open(golden_checksums_filepath, "w+") as f:
                        for checksum in test_checksums:
                            f.write(' '.join([str(i)
                                              for i in checksum]) + '\n')
                    return

                golden_checksums_remote_filepath = os.path.join(
                    constants.GOLDEN_CHECKSUM_REMOTE_BASE_DIR, board,
                    codec + '_' + resolution,
                    constants.GOLDEN_CHECKSUMS_FILENAME)

                file_utils.download_file(golden_checksums_remote_filepath,
                                         golden_checksums_filepath)

                golden_checksums = self.read_checksum_file(
                    golden_checksums_filepath)

                golden_checksum_count = len(golden_checksums)
                test_checksum_count = len(test_checksums)

                eps = constants.MAX_DIFF_TOTAL_FCOUNT
                if golden_checksum_count - test_checksum_count > eps:
                    msg = ('Expecting about %d checksums, received %d. '
                           'Allowed delta is %d') % (golden_checksum_count,
                                                     test_checksum_count, eps)
                    raise error.TestFail(msg)

                # Some frames might be missing during either golden frame
                # collection or during a test run. Using LCS ensures we
                # ignore a few missing frames while comparing test vs golden

                lcs_len = sequence_utils.lcs_length(golden_checksums,
                                                    test_checksums)

                missing_frames_count = len(golden_checksums) - lcs_len
                unknown_frames_count = len(test_checksums) - lcs_len

                msg = ('# of matching frames : %d. # of missing frames : %d. '
                       '# of unknown test frames : %d. Max allowed # of '
                       'missing frames : %d. # of golden frames : %d. # of '
                       'test_checksums : %d' %
                       (lcs_len, missing_frames_count,
                        unknown_frames_count, constants.MAX_NONMATCHING_FCOUNT,
                        len(golden_checksums), len(test_checksums)))
                logging.debug(msg)

                if (missing_frames_count + unknown_frames_count >
                        constants.MAX_NONMATCHING_FCOUNT):
                    unknown_frames = set(test_checksums) - set(
                        golden_checksums)

                    store_indices = [
                        test_checksum_indices[c] for c in unknown_frames
                    ]

                    paths = capturer.write_images(store_indices,
                                                  constants.TEST_DIR,
                                                  constants.IMAGE_FORMAT)

                    path_publish = publisher.ImageDiffPublisher(
                        self.resultsdir)
                    path_publish.publish_paths(paths, self.tagged_testname)

                    raise error.TestFail("Too many non-matching frames")
    def run_once(self, host):
        edid_path = os.path.join(self.bindir,
                                 'test_data/edids/HDMI_DELL_U2410.txt')
        golden_file = audio_test_data.SWEEP_TEST_FILE

        # Dump audio diagnostics data for debugging.
        chameleon_board = host.chameleon
        factory = self.create_remote_facade_factory(host)

        self._system_facade = factory.create_system_facade()
        self.set_high_performance_mode()

        chameleon_board.reset()

        widget_factory = chameleon_audio_helper.AudioWidgetFactory(
            factory, host)

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

        display_facade = factory.create_display_facade()
        finder = chameleon_port_finder.ChameleonVideoInputFinder(
            chameleon_board, display_facade)
        hdmi_port = finder.find_port('HDMI')
        if not hdmi_port:
            raise error.TestFail(
                'Can not find HDMI port, perhaps HDMI is not connected?')
        with hdmi_port.use_edid_file(edid_path):

            # TODO(cychiang) remove this when issue crbug.com/450101 is fixed.
            audio_test_utils.correction_plug_unplug_for_audio(host, hdmi_port)

            with chameleon_audio_helper.bind_widgets(binder):
                audio_facade = factory.create_audio_facade()

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

                output_nodes, _ = audio_facade.get_selected_node_types()
                if output_nodes != ['HDMI']:
                    raise error.TestFail(
                        '%s rather than HDMI is selected on Cros device' %
                        output_nodes)

                # Transfer the data to Cros device first because it takes
                # several seconds.
                source.set_playback_data(golden_file)

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

                time.sleep(self.DELAY_BEFORE_PLAYBACK)

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

                logging.info('Stopped playing %s on Cros device',
                             golden_file.path)
                time.sleep(self.DELAY_AFTER_PLAYBACK)

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

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

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

            if not chameleon_audio_helper.compare_recorded_result(
                    golden_file, recorder, 'correlation'):
                raise error.TestFail(
                    'Recorded file does not match playback file')
    def run_once(self, host, test_mirrored=False, plug_status=None):
        if test_mirrored and not host.get_board_type() == 'CHROMEBOOK':
            raise error.TestNAError('DUT is not Chromebook. Test Skipped')

        factory = remote_facade_factory.RemoteFacadeFactory(host)
        display_facade = factory.create_display_facade()
        chameleon_board = host.chameleon

        chameleon_board.setup_and_reset(self.outputdir)
        finder = chameleon_port_finder.ChameleonVideoInputFinder(
            chameleon_board, display_facade)

        errors = []
        is_display_failure = False
        for chameleon_port in finder.iterate_all_ports():
            screen_test = chameleon_screen_test.ChameleonScreenTest(
                host, chameleon_port, display_facade, self.outputdir)

            logging.info('See the display on Chameleon: port %d (%s)',
                         chameleon_port.get_connector_id(),
                         chameleon_port.get_connector_type())

            logging.info('Set mirrored: %s', test_mirrored)
            display_facade.set_mirrored(test_mirrored)

            # Keep the original connector name, for later comparison.
            expected_connector = display_facade.get_external_connector_name()
            resolution = display_facade.get_external_resolution()
            logging.info('See the display on DUT: %s %r', expected_connector,
                         resolution)

            if plug_status is None:
                plug_status = self.PLUG_DEFAULT_CONFIG

            for (plugged_before_boot, plugged_after_boot) in plug_status:
                logging.info('TESTING THE CASE: %s > reboot > %s',
                             'PLUG' if plugged_before_boot else 'UNPLUG',
                             'PLUG' if plugged_after_boot else 'UNPLUG')
                boot_id = host.get_boot_id()
                chameleon_port.set_plug(plugged_before_boot)

                # Don't wait DUT up. Do plug/unplug while booting.
                logging.info('Reboot...')
                host.reboot(wait=False)

                host.test_wait_for_shutdown(
                    shutdown_timeout=self.REBOOT_TIMEOUT)
                chameleon_port.set_plug(plugged_after_boot)
                host.test_wait_for_boot(boot_id)

                if screen_test.check_external_display_connected(
                        expected_connector if plugged_after_boot else False,
                        errors):
                    is_display_failure = True
                    # Skip the following test if an unexpected display detected.
                    continue

                if plugged_after_boot:
                    if test_mirrored and (
                            not display_facade.is_mirrored_enabled()):
                        error_message = 'Error: not rebooted to mirrored mode'
                        errors.append(error_message)
                        logging.error(error_message)
                        is_display_failure = True
                        # Sets mirrored status for next test
                        logging.info('Set mirrored: %s', True)
                        display_facade.set_mirrored(True)
                        continue

                    if screen_test.test_screen_with_image(
                            resolution, test_mirrored, errors):
                        is_display_failure = True

        if errors:
            if is_display_failure:
                raise error.TestFail('; '.join(set(errors)))
            else:
                raise error.TestError('; '.join(set(errors)))
Exemplo n.º 22
0
    def run_once(self,
                 host,
                 test_mirrored=False,
                 test_suspend_resume=False,
                 test_reboot=False,
                 test_lid_close_open=False,
                 resolution_list=None):

        # Check the servo object.
        if test_lid_close_open and host.servo is None:
            raise error.TestError('Invalid servo object found on the host.')
        if test_lid_close_open and not host.get_board_type() == 'CHROMEBOOK':
            raise error.TestNAError('DUT is not Chromebook. Test Skipped')
        if test_mirrored and not host.get_board_type() == 'CHROMEBOOK':
            raise error.TestNAError('DUT is not Chromebook. Test Skipped')

        # Check for incompatible with servo chromebooks.
        board_name = host.get_board().split(':')[1]
        if board_name in self.INCOMPATIBLE_SERVO_BOARDS:
            raise error.TestNAError(
                'DUT is incompatible with servo. Skipping test.')

        factory = remote_facade_factory.RemoteFacadeFactory(host)
        display_facade = factory.create_display_facade()
        chameleon_board = host.chameleon

        chameleon_board.setup_and_reset(self.outputdir)
        finder = chameleon_port_finder.ChameleonVideoInputFinder(
            chameleon_board, display_facade)

        errors = []
        if resolution_list is None:
            resolution_list = self.DEFAULT_RESOLUTION_LIST
        chameleon_supported = True
        for chameleon_port in finder.iterate_all_ports():
            screen_test = chameleon_screen_test.ChameleonScreenTest(
                host, chameleon_port, display_facade, self.outputdir)
            chameleon_port_name = chameleon_port.get_connector_type()
            logging.info('Detected %s chameleon port.', chameleon_port_name)
            for label, width, height in resolution_list:
                test_resolution = (width, height)
                test_name = "%s_%dx%d" % ((label, ) + test_resolution)

                # The chameleon DP RX doesn't support 4K resolution.
                # The max supported resolution is 2560x1600.
                # See crbug/585900
                if (chameleon_port_name.startswith('DP') and test_resolution >
                    (2560, 1600)):
                    chameleon_supported = False

                if not edid.is_edid_supported(host, width, height):
                    logging.info('Skip unsupported EDID: %s', test_name)
                    continue

                if test_lid_close_open:
                    logging.info('Close lid...')
                    host.servo.lid_close()
                    time.sleep(self.WAIT_TIME_LID_TRANSITION)

                if test_reboot:
                    # Unplug the monitor explicitly. Otherwise, the following
                    # use_edid_file() call would expect a valid video signal,
                    # which is not true during reboot.
                    chameleon_port.unplug()
                    logging.info('Reboot...')
                    boot_id = host.get_boot_id()
                    host.reboot(wait=False)
                    host.test_wait_for_shutdown(self.REBOOT_TIMEOUT)

                path = os.path.join(self.bindir, 'test_data', 'edids',
                                    test_name)
                logging.info('Use EDID: %s', test_name)
                with chameleon_port.use_edid_file(path):
                    if test_lid_close_open:
                        logging.info('Open lid...')
                        host.servo.lid_open()
                        time.sleep(self.WAIT_TIME_LID_TRANSITION)

                    if test_reboot:
                        host.test_wait_for_boot(boot_id)
                        chameleon_port.plug()

                    utils.wait_for_value_changed(
                        display_facade.get_external_connector_name,
                        old_value=False)

                    logging.info('Set mirrored: %s', test_mirrored)
                    display_facade.set_mirrored(test_mirrored)
                    if test_suspend_resume:
                        if test_mirrored:
                            # magic sleep to wake up nyan_big in mirrored mode
                            # TODO: find root cause
                            time.sleep(6)
                        logging.info('Going to suspend...')
                        display_facade.suspend_resume()
                        logging.info('Resumed back')

                    screen_test.test_screen_with_image(test_resolution,
                                                       test_mirrored, errors,
                                                       chameleon_supported)

        if errors:
            raise error.TestFail('; '.join(set(errors)))
    def run_once(self, host, test_mirrored=False):
        if host.get_architecture() != 'arm':
            raise error.TestNAError('HDCP is not supported on a non-ARM device')

        factory = remote_facade_factory.RemoteFacadeFactory(host)
        display_facade = factory.create_display_facade()
        chameleon_board = host.chameleon

        chameleon_board.setup_and_reset(self.outputdir)
        finder = chameleon_port_finder.ChameleonVideoInputFinder(
                chameleon_board, display_facade)

        errors = []
        for chameleon_port in finder.iterate_all_ports():
            screen_test = chameleon_screen_test.ChameleonScreenTest(
                    chameleon_port, display_facade, self.outputdir)

            logging.info('See the display on Chameleon: port %d (%s)',
                         chameleon_port.get_connector_id(),
                         chameleon_port.get_connector_type())

            logging.info('Set mirrored: %s', test_mirrored)
            display_facade.set_mirrored(test_mirrored)

            resolution = display_facade.get_external_resolution()
            logging.info('Detected resolution on CrOS: %r', resolution)

            original_cros_state = display_facade.get_content_protection()
            was_chameleon_enabled = (
                    chameleon_port.is_content_protection_enabled())
            try:
                for (enable_chameleon, request_cros, expected_cros_state,
                     expected_chameleon_state) in self.TEST_CONFIGS:
                    # Do unplug and plug to emulate switching to a different
                    # display with a different content protection state.
                    chameleon_port.unplug()
                    logging.info('Set Chameleon HDCP: %r', enable_chameleon)
                    chameleon_port.set_content_protection(enable_chameleon)
                    time.sleep(self.DURATION_UNPLUG_FOR_HDCP)
                    chameleon_port.plug()
                    chameleon_port.wait_video_input_stable()

                    logging.info('Request CrOS HDCP: %s', request_cros)
                    display_facade.set_content_protection(request_cros)

                    state = utils.wait_for_value(
                            display_facade.get_content_protection, 'Enabled',
                            timeout_sec=self.TIMEOUT_HDCP_SWITCH)
                    logging.info('Got CrOS state: %s', state)
                    if state != expected_cros_state:
                        error_message = ('Failed to enable HDCP, state: %r' %
                                         state)
                        logging.error(error_message)
                        errors.append(error_message)

                    encrypted = chameleon_port.is_video_input_encrypted()
                    logging.info('Got Chameleon state: %r', encrypted)
                    if encrypted != expected_chameleon_state:
                        error_message = ('Chameleon found HDCP in wrong state: '
                                         'expected %r but got %r' %
                                         (expected_chameleon_state, encrypted))
                        logging.error(error_message)
                        errors.append(error_message)

                    logging.info('Test screen under HDCP %s...',
                                 'enabled' if encrypted else 'disabled')
                    screen_test.test_screen_with_image(
                            resolution, test_mirrored, errors)
            finally:
                display_facade.set_content_protection(original_cros_state)
                chameleon_port.set_content_protection(was_chameleon_enabled)

        if errors:
            raise error.TestFail('; '.join(set(errors)))
    def run_once(self,
                 host,
                 video_hardware_acceleration=True,
                 video_url=DEFAULT_VIDEO_URL,
                 arc=False):
        """Running audio/video synchronization quality measurement

        @param host: A host object representing the DUT.
        @param video_hardware_acceleration: Enables the hardware acceleration
                                            for video decoding.
        @param video_url: The ULR of the test video.
        @param arc: Tests on ARC with an Android Video Player App.
        """
        self.host = host

        factory = remote_facade_factory.RemoteFacadeFactory(
            host, results_dir=self.resultsdir, no_chrome=True)

        chrome_args = {
            'extension_paths':
            [constants.AUDIO_TEST_EXTENSION, constants.DISPLAY_TEST_EXTENSION],
            'extra_browser_args': [],
            'arc_mode':
            arc_common.ARC_MODE_DISABLED,
            'autotest_ext':
            True
        }
        if not video_hardware_acceleration:
            chrome_args['extra_browser_args'].append(
                '--disable-accelerated-video-decode')
        if arc:
            chrome_args['arc_mode'] = arc_common.ARC_MODE_ENABLED
        browser_facade = factory.create_browser_facade()
        browser_facade.start_custom_chrome(chrome_args)
        logging.info("created chrome")
        if arc:
            self.setup_video_app()

        chameleon_board = host.chameleon
        audio_facade = factory.create_audio_facade()
        display_facade = factory.create_display_facade()
        video_facade = factory.create_video_facade()

        audio_port_finder = chameleon_port_finder.ChameleonAudioInputFinder(
            chameleon_board)
        video_port_finder = chameleon_port_finder.ChameleonVideoInputFinder(
            chameleon_board, display_facade)
        audio_port = audio_port_finder.find_port('HDMI')
        video_port = video_port_finder.find_port('HDMI')

        chameleon_board.setup_and_reset(self.outputdir)

        _, ext = os.path.splitext(video_url)
        with tempfile.NamedTemporaryFile(prefix='playback_', suffix=ext) as f:
            # The default permission is 0o600.
            os.chmod(f.name, 0o644)

            file_utils.download_file(video_url, f.name)
            if arc:
                video_facade.prepare_arc_playback(f.name)
            else:
                video_facade.prepare_playback(f.name)

        edid_path = os.path.join(self.bindir,
                                 'test_data/edids/HDMI_DELL_U2410.txt')

        video_port.plug()
        with video_port.use_edid_file(edid_path):
            audio_facade.set_chrome_active_node_type('HDMI', None)
            audio_facade.set_chrome_active_volume(100)
            audio_test_utils.check_audio_nodes(audio_facade, (['HDMI'], None))
            display_facade.set_mirrored(True)
            video_port.start_monitoring_audio_video_capturing_delay()

            time.sleep(self.DELAY_BEFORE_CAPTURING)
            video_port.start_capturing_video((64, 64, 16, 16))
            audio_port.start_capturing_audio()

            time.sleep(self.DELAY_BEFORE_PLAYBACK)
            if arc:
                video_facade.start_arc_playback(blocking_secs=20)
            else:
                video_facade.start_playback(blocking=True)
            time.sleep(self.DELAY_AFTER_PLAYBACK)

            remote_path, _ = audio_port.stop_capturing_audio()
            video_port.stop_capturing_video()
            start_delay = video_port.get_audio_video_capturing_delay()

        local_path = os.path.join(self.resultsdir, 'recorded.raw')
        chameleon_board.host.get_file(remote_path, local_path)

        audio_data = open(local_path).read()
        video_data = video_port.get_captured_checksums()

        logging.info("audio capture %d bytes, %f seconds", len(audio_data),
                     len(audio_data) / float(self.AUDIO_CAPTURE_RATE) / 32)
        logging.info("video capture %d frames, %f seconds", len(video_data),
                     len(video_data) / float(self.VIDEO_CAPTURE_RATE))

        key_audio = self.compute_audio_keypoint(audio_data)
        key_video = self.compute_video_keypoint(video_data)
        # Use the capturing delay to align A/V
        key_video = map(lambda x: x + start_delay, key_video)

        dropped_frame_count = None
        if not arc:
            video_facade.dropped_frame_count()

        prefix = ''
        if arc:
            prefix = 'arc_'
        elif video_hardware_acceleration:
            prefix = 'hw_'
        else:
            prefix = 'sw_'

        self.log_result(prefix, key_audio, key_video, dropped_frame_count)
Exemplo n.º 25
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()
    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()
Exemplo n.º 27
0
    def run_once(self, host, test_mirrored=False):
        factory = remote_facade_factory.RemoteFacadeFactory(host)
        display_facade = factory.create_display_facade()
        chameleon_board = host.chameleon

        chameleon_board.reset()
        finder = chameleon_port_finder.ChameleonVideoInputFinder(
                chameleon_board, display_facade)

        errors = []
        warns = []
        for chameleon_port in finder.iterate_all_ports():
            screen_test = chameleon_screen_test.ChameleonScreenTest(
                    chameleon_port, display_facade, self.outputdir)

            logging.info('See the display on Chameleon: port %d (%s)',
                         chameleon_port.get_connector_id(),
                         chameleon_port.get_connector_type())

            logging.info('Set mirrored: %s', test_mirrored)
            display_facade.set_mirrored(test_mirrored)

            # Keep the original connector name, for later comparison.
            expected_connector = display_facade.get_external_connector_name()
            resolution = display_facade.get_external_resolution()
            logging.info('See the display on DUT: %s %r',
                         expected_connector, resolution)

            for (plugged_before_noise,
                 plugged_after_noise) in self.PLUG_CONFIGS:
                logging.info('TESTING THE CASE: %s > noise > %s',
                             'plug' if plugged_before_noise else 'unplug',
                             'plug' if plugged_after_noise else 'unplug')

                chameleon_port.set_plug(plugged_before_noise)

                if screen_test.check_external_display_connected(
                        expected_connector if plugged_before_noise else False,
                        errors):
                    # Skip the following test if an unexpected display detected.
                    continue

                chameleon_port.fire_mixed_hpd_pulses(
                        self.PULSES_PLUGGED if plugged_after_noise
                                            else self.PULSES_UNPLUGGED)

                if plugged_after_noise:
                    chameleon_port.wait_video_input_stable()
                    if test_mirrored:
                        # Wait for resolution change to make sure the resolution
                        # is stable before moving on. This is to deal with the
                        # case where DUT may respond slowly after the noise.
                        # If the resolution doesn't change, then we are
                        # confident that it is stable. Otherwise, a slow
                        # response is caught.
                        r = display_facade.get_internal_resolution()
                        utils.wait_for_value_changed(
                                display_facade.get_internal_resolution,
                                old_value=r)

                    err = screen_test.check_external_display_connected(
                            expected_connector)

                    if not err:
                        err = screen_test.test_screen_with_image(
                                resolution, test_mirrored)
                    if err:
                        # When something goes wrong after the noise, a normal
                        # user would try to re-plug the cable to recover.
                        # We emulate this behavior below and report error if
                        # the problem persists.
                        logging.warn('Possibly flaky: %s', err)
                        warns.append('Possibly flaky: %s' % err)
                        logging.info('Replug and retry the screen test...')
                        chameleon_port.unplug()
                        time.sleep(self.REPLUG_DELAY_SEC)
                        chameleon_port.plug()
                        chameleon_port.wait_video_input_stable()
                        screen_test.test_screen_with_image(
                                resolution, test_mirrored, errors)
                else:
                    screen_test.check_external_display_connected(False, errors)
                    time.sleep(1)

        if errors:
            raise error.TestFail('; '.join(set(errors)))
        elif warns:
            raise error.TestWarn('; '.join(set(warns)))
Exemplo n.º 28
0
    def run_once(self,
                 host,
                 test_mirrored=False,
                 test_suspend_resume=False,
                 test_reboot=False,
                 test_lid_close_open=False,
                 resolution_list=None):
        # Check the servo object
        if test_lid_close_open and host.servo is None:
            raise error.TestError('Invalid servo object found on the host.')
        if test_lid_close_open and not host.get_board_type() == 'CHROMEBOOK':
            raise error.TestNAError('DUT is not Chromebook. Test Skipped')

        factory = remote_facade_factory.RemoteFacadeFactory(host)
        display_facade = factory.create_display_facade()
        chameleon_board = host.chameleon

        chameleon_board.reset()
        finder = chameleon_port_finder.ChameleonVideoInputFinder(
            chameleon_board, display_facade)

        errors = []
        if resolution_list is None:
            resolution_list = self.DEFAULT_RESOLUTION_LIST
        for chameleon_port in finder.iterate_all_ports():
            screen_test = chameleon_screen_test.ChameleonScreenTest(
                chameleon_port, display_facade, self.outputdir)
            chameleon_port_name = chameleon_port.get_connector_type()
            logging.info('Detected %s chameleon port.', chameleon_port_name)
            for interface, width, height in resolution_list:
                if not chameleon_port_name.startswith(interface):
                    continue
                test_resolution = (width, height)
                test_name = "%s_%dx%d" % ((interface, ) + test_resolution)

                if not edid.is_edid_supported(host, interface, width, height):
                    logging.info('Skip unsupported EDID: %s', test_name)
                    continue

                if test_lid_close_open:
                    logging.info('Close lid...')
                    host.servo.lid_close()
                    time.sleep(self.WAIT_TIME_LID_TRANSITION)

                if test_reboot:
                    logging.info('Reboot...')
                    boot_id = host.get_boot_id()
                    host.reboot(wait=False)
                    host.test_wait_for_shutdown(self.REBOOT_TIMEOUT)

                path = os.path.join(self.bindir, 'test_data', 'edids',
                                    test_name)
                logging.info('Use EDID: %s', test_name)
                with chameleon_port.use_edid_file(path):
                    if test_lid_close_open:
                        logging.info('Open lid...')
                        host.servo.lid_open()
                        time.sleep(self.WAIT_TIME_LID_TRANSITION)

                    if test_reboot:
                        host.test_wait_for_boot(boot_id)

                    utils.wait_for_value_changed(
                        display_facade.get_external_connector_name,
                        old_value=False)

                    logging.info('Set mirrored: %s', test_mirrored)
                    display_facade.set_mirrored(test_mirrored)
                    if test_suspend_resume:
                        if test_mirrored:
                            # magic sleep to wake up nyan_big in mirrored mode
                            # TODO: find root cause
                            time.sleep(6)
                        logging.info('Going to suspend...')
                        display_facade.suspend_resume()
                        logging.info('Resumed back')

                    screen_test.test_screen_with_image(test_resolution,
                                                       test_mirrored, errors)

        if errors:
            raise error.TestFail('; '.join(set(errors)))