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 external display test using the Chameleon board.""" 6 7import logging 8import os 9import random 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.client.cros.chameleon import edid 17from autotest_lib.server import test 18from autotest_lib.server.cros.multimedia import remote_facade_factory 19 20 21class display_SuspendStress(test.test): 22 """Server side external display test. 23 24 This test talks to a Chameleon board and a DUT to set up, run, and verify 25 external display function of the DUT with DUT being repeatedly 26 suspended and resumed. 27 """ 28 version = 1 29 DEFAULT_TESTCASE_SPEC = ('HDMI', 1920, 1080) 30 31 # TODO: Allow reading testcase_spec from command line. 32 def run_once(self, host, test_mirrored=False, testcase_spec=None, 33 repeat_count=3, suspend_time_range=(5,7)): 34 if test_mirrored and not host.get_board_type() == 'CHROMEBOOK': 35 raise error.TestNAError('DUT is not Chromebook. Test Skipped') 36 37 if testcase_spec is None: 38 testcase_spec = self.DEFAULT_TESTCASE_SPEC 39 40 test_name = "%s_%dx%d" % testcase_spec 41 _, width, height = testcase_spec 42 test_resolution = (width, height) 43 44 if not edid.is_edid_supported(host, testcase_spec[1], testcase_spec[2]): 45 raise error.TestFail('Error: EDID is not supported by the platform' 46 ': %s', test_name) 47 48 edid_path = os.path.join(self.bindir, 'test_data', 'edids', test_name) 49 50 factory = remote_facade_factory.RemoteFacadeFactory(host) 51 display_facade = factory.create_display_facade() 52 chameleon_board = host.chameleon 53 54 chameleon_board.setup_and_reset(self.outputdir) 55 finder = chameleon_port_finder.ChameleonVideoInputFinder( 56 chameleon_board, display_facade) 57 for chameleon_port in finder.iterate_all_ports(): 58 screen_test = chameleon_screen_test.ChameleonScreenTest( 59 host, chameleon_port, display_facade, self.outputdir) 60 61 logging.info('Use EDID: %s', test_name) 62 with chameleon_port.use_edid_file(edid_path): 63 # Keep the original connector name, for later comparison. 64 expected_connector = utils.wait_for_value_changed( 65 display_facade.get_external_connector_name, 66 old_value=False) 67 logging.info('See the display on DUT: %s', expected_connector) 68 69 if not expected_connector: 70 raise error.TestFail('Error: Failed to see external display' 71 ' (chameleon) from DUT: %s', test_name) 72 73 logging.info('Set mirrored: %s', test_mirrored) 74 display_facade.set_mirrored(test_mirrored) 75 logging.info('Repeat %d times Suspend and resume', repeat_count) 76 77 count = repeat_count 78 while count > 0: 79 count -= 1 80 if test_mirrored: 81 # magic sleep to make nyan_big wake up in mirrored mode 82 # TODO: find root cause 83 time.sleep(6) 84 suspend_time = random.randint(*suspend_time_range) 85 logging.info('Going to suspend, for %d seconds...', 86 suspend_time) 87 display_facade.suspend_resume(suspend_time) 88 logging.info('Resumed back') 89 90 message = screen_test.check_external_display_connected( 91 expected_connector) 92 if not message: 93 message = screen_test.test_screen_with_image( 94 test_resolution, test_mirrored) 95 if message: 96 raise error.TestFail(message) 97