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