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 7import logging 8 9from autotest_lib.client.common_lib import error 10from autotest_lib.client.cros.chameleon import chameleon_port_finder 11from autotest_lib.client.cros.chameleon import chameleon_screen_test 12from autotest_lib.server import test 13from autotest_lib.server.cros.multimedia import remote_facade_factory 14 15 16class 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_CONFIGS = [ 24 # (plugged_before_boot, plugged_after_boot) 25 (False, True), 26 (True, True), 27 (True, False), 28 ] 29 # Allowed timeout for reboot. 30 REBOOT_TIMEOUT = 30 31 32 def run_once(self, host, test_mirrored=False): 33 factory = remote_facade_factory.RemoteFacadeFactory(host) 34 display_facade = factory.create_display_facade() 35 chameleon_board = host.chameleon 36 37 chameleon_board.reset() 38 finder = chameleon_port_finder.ChameleonVideoInputFinder( 39 chameleon_board, display_facade) 40 41 errors = [] 42 for chameleon_port in finder.iterate_all_ports(): 43 screen_test = chameleon_screen_test.ChameleonScreenTest( 44 chameleon_port, display_facade, self.outputdir) 45 46 logging.info('See the display on Chameleon: port %d (%s)', 47 chameleon_port.get_connector_id(), 48 chameleon_port.get_connector_type()) 49 50 logging.info('Set mirrored: %s', test_mirrored) 51 display_facade.set_mirrored(test_mirrored) 52 53 # Keep the original connector name, for later comparison. 54 expected_connector = display_facade.get_external_connector_name() 55 resolution = display_facade.get_external_resolution() 56 logging.info('See the display on DUT: %s %r', 57 expected_connector, resolution) 58 59 for plugged_before_boot, plugged_after_boot in self.PLUG_CONFIGS: 60 logging.info('TESTING THE CASE: %s > reboot > %s', 61 'plug' if plugged_before_boot else 'unplug', 62 'plug' if plugged_after_boot else 'unplug') 63 boot_id = host.get_boot_id() 64 chameleon_port.set_plug(plugged_before_boot) 65 66 # Don't wait DUT up. Do plug/unplug while booting. 67 logging.info('Reboot...') 68 host.reboot(wait=False) 69 70 host.test_wait_for_shutdown( 71 shutdown_timeout=self.REBOOT_TIMEOUT) 72 chameleon_port.set_plug(plugged_after_boot) 73 host.test_wait_for_boot(boot_id) 74 75 if screen_test.check_external_display_connected( 76 expected_connector if plugged_after_boot else False, 77 errors): 78 # Skip the following test if an unexpected display detected. 79 continue 80 81 if plugged_after_boot: 82 if test_mirrored and ( 83 not display_facade.is_mirrored_enabled()): 84 error_message = 'Error: not rebooted to mirrored mode' 85 errors.append(error_message) 86 logging.error(error_message) 87 # Sets mirrored status for next test 88 logging.info('Set mirrored: %s', True) 89 display_facade.set_mirrored(True) 90 continue 91 92 screen_test.test_screen_with_image( 93 resolution, test_mirrored, errors) 94 95 if errors: 96 raise error.TestFail('; '.join(set(errors))) 97