Home | History | Annotate | Download | only in display_HotPlugAtBoot
      1 # Copyright 2014 The Chromium OS Authors. All rights reserved.
      2 # Use of this source code is governed by a BSD-style license that can be
      3 # found in the LICENSE file.
      4 
      5 """This is a display hot-plug and reboot test using the Chameleon board."""
      6 
      7 import logging
      8 
      9 from autotest_lib.client.common_lib import error
     10 from autotest_lib.client.cros.chameleon import chameleon_port_finder
     11 from autotest_lib.client.cros.chameleon import chameleon_screen_test
     12 from autotest_lib.server import test
     13 from autotest_lib.server.cros.multimedia import remote_facade_factory
     14 
     15 
     16 class display_HotPlugAtBoot(test.test):
     17     """Display hot-plug and reboot test.
     18 
     19     This test talks to a Chameleon board and a DUT to set up, run, and verify
     20     DUT behavior response to different configuration of hot-plug during boot.
     21     """
     22     version = 1
     23     PLUG_DEFAULT_CONFIG = [
     24         # (plugged_before_boot, plugged_after_boot)
     25         (True,True)
     26     ]
     27     # Allowed timeout for reboot.
     28     REBOOT_TIMEOUT = 30
     29 
     30     def run_once(self, host, test_mirrored=False, plug_status=None):
     31         if test_mirrored and not host.get_board_type() == 'CHROMEBOOK':
     32             raise error.TestNAError('DUT is not Chromebook. Test Skipped')
     33 
     34         factory = remote_facade_factory.RemoteFacadeFactory(host)
     35         display_facade = factory.create_display_facade()
     36         chameleon_board = host.chameleon
     37 
     38         chameleon_board.setup_and_reset(self.outputdir)
     39         finder = chameleon_port_finder.ChameleonVideoInputFinder(
     40                 chameleon_board, display_facade)
     41 
     42         errors = []
     43         is_display_failure = False
     44         for chameleon_port in finder.iterate_all_ports():
     45             screen_test = chameleon_screen_test.ChameleonScreenTest(
     46                     host, chameleon_port, display_facade, self.outputdir)
     47 
     48             logging.info('See the display on Chameleon: port %d (%s)',
     49                          chameleon_port.get_connector_id(),
     50                          chameleon_port.get_connector_type())
     51 
     52             logging.info('Set mirrored: %s', test_mirrored)
     53             display_facade.set_mirrored(test_mirrored)
     54 
     55             # Keep the original connector name, for later comparison.
     56             expected_connector = display_facade.get_external_connector_name()
     57             resolution = display_facade.get_external_resolution()
     58             logging.info('See the display on DUT: %s %r',
     59                     expected_connector, resolution)
     60 
     61             if plug_status is None:
     62                 plug_status = self.PLUG_DEFAULT_CONFIG
     63 
     64             for (plugged_before_boot, plugged_after_boot) in plug_status:
     65                 logging.info('TESTING THE CASE: %s > reboot > %s',
     66                              'PLUG' if plugged_before_boot else 'UNPLUG',
     67                              'PLUG' if plugged_after_boot else 'UNPLUG')
     68                 boot_id = host.get_boot_id()
     69                 chameleon_port.set_plug(plugged_before_boot)
     70 
     71                 # Don't wait DUT up. Do plug/unplug while booting.
     72                 logging.info('Reboot...')
     73                 host.reboot(wait=False)
     74 
     75                 host.test_wait_for_shutdown(
     76                         shutdown_timeout=self.REBOOT_TIMEOUT)
     77                 chameleon_port.set_plug(plugged_after_boot)
     78                 host.test_wait_for_boot(boot_id)
     79 
     80                 if screen_test.check_external_display_connected(
     81                         expected_connector if plugged_after_boot else False,
     82                         errors):
     83                     is_display_failure = True
     84                     # Skip the following test if an unexpected display detected.
     85                     continue
     86 
     87                 if plugged_after_boot:
     88                     if test_mirrored and (
     89                             not display_facade.is_mirrored_enabled()):
     90                         error_message = 'Error: not rebooted to mirrored mode'
     91                         errors.append(error_message)
     92                         logging.error(error_message)
     93                         is_display_failure = True
     94                         # Sets mirrored status for next test
     95                         logging.info('Set mirrored: %s', True)
     96                         display_facade.set_mirrored(True)
     97                         continue
     98 
     99                     if screen_test.test_screen_with_image(
    100                             resolution, test_mirrored, errors):
    101                         is_display_failure = True
    102 
    103         if errors:
    104             if is_display_failure:
    105                 raise error.TestFail('; '.join(set(errors)))
    106             else:
    107                 raise error.TestError('; '.join(set(errors)))
    108