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 test switching the external display mode.""" 7 8import logging, time 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_SwitchMode(test.test): 18 """External Display switch between extended and mirrored modes. 19 20 This test switches the external display mode between extended 21 and mirrored modes, and checks resolution and static test image. 22 """ 23 version = 1 24 WAIT_AFTER_SWITCH = 5 25 26 def check_external_display(self, test_mirrored): 27 """Display status check 28 29 @param test_mirrored: is mirrored mode active 30 31 """ 32 resolution = self.display_facade.get_external_resolution() 33 # Check connector 34 if self.screen_test.check_external_display_connected( 35 self.connector_used, self.errors) is None: 36 # Check test image 37 self.screen_test.test_screen_with_image( 38 resolution, test_mirrored, self.errors) 39 if self.errors: 40 raise error.TestFail('; '.join(set(self.errors))) 41 42 43 def set_mode_and_check(self, test_mirrored, no_check): 44 """Sets display mode and checks status 45 46 @param test_mirrored: is mirrored mode active 47 @param no_check: True to skip the screen check. 48 """ 49 logging.info('Set mirrored: %s', test_mirrored) 50 self.display_facade.set_mirrored(test_mirrored) 51 if not no_check: 52 time.sleep(self.WAIT_AFTER_SWITCH) 53 self.check_external_display(test_mirrored) 54 55 56 def run_once(self, host, repeat, no_check=False): 57 if not host.get_board_type() == 'CHROMEBOOK': 58 raise error.TestNAError('DUT is not Chromebook. Test Skipped') 59 60 factory = remote_facade_factory.RemoteFacadeFactory(host) 61 self.display_facade = factory.create_display_facade() 62 chameleon_board = host.chameleon 63 64 chameleon_board.setup_and_reset(self.outputdir) 65 finder = chameleon_port_finder.ChameleonVideoInputFinder( 66 chameleon_board, self.display_facade) 67 68 self.errors = [] 69 for chameleon_port in finder.iterate_all_ports(): 70 self.chameleon_port = chameleon_port 71 self.screen_test = chameleon_screen_test.ChameleonScreenTest( 72 host, chameleon_port, self.display_facade, self.outputdir) 73 74 logging.debug('See the display on Chameleon: port %d (%s)', 75 self.chameleon_port.get_connector_id(), 76 self.chameleon_port.get_connector_type()) 77 # Keep the original connector name, for later comparison. 78 self.connector_used = ( 79 self.display_facade.get_external_connector_name()) 80 81 for i in range(repeat): 82 logging.info("Iteration %d", (i + 1)) 83 self.set_mode_and_check(True, no_check) 84 self.set_mode_and_check(False, no_check) 85