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 server side resolution display test using the Chameleon board.""" 7 8import logging 9import os 10import time 11 12from autotest_lib.client.bin import utils 13from autotest_lib.client.common_lib import error 14from autotest_lib.client.cros.chameleon import chameleon_port_finder 15from autotest_lib.client.cros.chameleon import chameleon_screen_test 16from autotest_lib.server import test 17from autotest_lib.server.cros.multimedia import remote_facade_factory 18 19 20class 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.setup_and_reset(self.outputdir) 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 host, 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 edid_path = os.path.join(self.bindir, 'test_data', 'edids', 61 test_name) 62 63 logging.info('Use EDID: %s', test_name) 64 65 with chameleon_port.use_edid_file(edid_path): 66 display_id = utils.wait_for_value_changed( 67 display_facade.get_first_external_display_id, 68 old_value=False) 69 if int(display_id) < 0: 70 raise error.TestFail("No external display is found.") 71 72 # In mirror mode only display id is '0', as external 73 # is treated same as internal(single resolution applies) 74 if test_mirrored: 75 display_id = display_facade.get_internal_display_id() 76 logging.info('Set mirrored: %s', test_mirrored) 77 display_facade.set_mirrored(test_mirrored) 78 settings_resolution_list = ( 79 display_facade.get_available_resolutions( 80 display_id)) 81 if len(settings_resolution_list) == 0: 82 raise error.TestFail("No resolution list is found.") 83 logging.info('External display %s: %d resolutions found.', 84 display_id, len(settings_resolution_list)) 85 86 for r in settings_resolution_list: 87 # FIXME: send a keystroke to keep display on. 88 # This is to work around a problem where the display may be 89 # turned off if the test has run for a long time (e.g., 90 # greater than 15 min). When the display is off, 91 # set_resolution() will fail. 92 display_facade.hide_cursor() 93 94 logging.info('Set resolution to %dx%d', *r) 95 display_facade.set_resolution(display_id, *r) 96 time.sleep(self.RESOLUTION_CHANGE_TIME) 97 98 chameleon_port.wait_video_input_stable() 99 screen_test.test_screen_with_image(r, test_mirrored, errors) 100 101 if errors: 102 raise error.TestFail('; '.join(set(errors))) 103