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 server side resolution display test using the Chameleon board.""" 6 7 import logging 8 import os 9 import time 10 11 from autotest_lib.client.bin import utils 12 from autotest_lib.client.common_lib import error 13 from autotest_lib.client.cros.chameleon import chameleon_port_finder 14 from autotest_lib.client.cros.chameleon import chameleon_screen_test 15 from autotest_lib.client.cros.chameleon import edid 16 from autotest_lib.server import test 17 from autotest_lib.server.cros.multimedia import remote_facade_factory 18 19 20 class display_ResolutionList(test.test): 21 """Server side external display test. 22 23 This test iterates the resolution list obtained from the display options 24 dialog and verifies that each of them works. 25 """ 26 27 version = 1 28 DEFAULT_RESOLUTION_LIST = [ 29 ('HDMI', 1920, 1080), 30 ('DP', 1920, 1080), 31 ] 32 RESOLUTION_CHANGE_TIME = 2 33 34 # TODO: Allow reading testcase_spec from command line. 35 def run_once(self, host, test_mirrored=False, resolution_list=None): 36 if not host.get_board_type() == 'CHROMEBOOK': 37 raise error.TestNAError('DUT is not Chromebook. Test Skipped') 38 if resolution_list is None: 39 resolution_list = self.DEFAULT_RESOLUTION_LIST 40 factory = remote_facade_factory.RemoteFacadeFactory(host) 41 display_facade = factory.create_display_facade() 42 chameleon_board = host.chameleon 43 44 chameleon_board.reset() 45 finder = chameleon_port_finder.ChameleonVideoInputFinder( 46 chameleon_board, display_facade) 47 48 errors = [] 49 for chameleon_port in finder.iterate_all_ports(): 50 screen_test = chameleon_screen_test.ChameleonScreenTest( 51 chameleon_port, display_facade, self.outputdir) 52 chameleon_port_name = chameleon_port.get_connector_type() 53 logging.info('Detected %s chameleon port.', chameleon_port_name) 54 for interface, width, height in resolution_list: 55 if not chameleon_port_name.startswith(interface): 56 continue 57 test_resolution = (width, height) 58 test_name = "%s_%dx%d" % ((interface,) + test_resolution) 59 60 if not edid.is_edid_supported(host, interface, width, height): 61 logging.info('Skip unsupported EDID: %s', test_name) 62 continue 63 edid_path = os.path.join(self.bindir, 'test_data', 'edids', 64 test_name) 65 66 logging.info('Use EDID: %s', test_name) 67 68 with chameleon_port.use_edid_file(edid_path): 69 index = utils.wait_for_value_changed( 70 display_facade.get_first_external_display_index, 71 old_value=False) 72 if not index: 73 raise error.TestFail("No external display is found.") 74 75 # In mirror mode only display index is '0', as external 76 # is treated same as internal(single resolution applies) 77 if test_mirrored: 78 index = 0 79 logging.info('Set mirrored: %s', test_mirrored) 80 display_facade.set_mirrored(test_mirrored) 81 settings_resolution_list = ( 82 display_facade.get_available_resolutions(index)) 83 if len(settings_resolution_list) == 0: 84 raise error.TestFail("No resolution list is found.") 85 logging.info('External display %d: %d resolutions found.', 86 index, len(settings_resolution_list)) 87 88 for r in settings_resolution_list: 89 # FIXME: send a keystroke to keep display on. 90 # This is to work around a problem where the display may be 91 # turned off if the test has run for a long time (e.g., 92 # greater than 15 min). When the display is off, 93 # set_resolution() will fail. 94 display_facade.hide_cursor() 95 96 logging.info('Set resolution to %dx%d', *r) 97 display_facade.set_resolution(index, *r) 98 time.sleep(self.RESOLUTION_CHANGE_TIME) 99 100 chameleon_port.wait_video_input_stable() 101 screen_test.test_screen_with_image(r, test_mirrored, errors) 102 103 if errors: 104 raise error.TestFail('; '.join(set(errors))) 105