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 testcase_spec is None: 35 testcase_spec = self.DEFAULT_TESTCASE_SPEC 36 37 test_name = "%s_%dx%d" % testcase_spec 38 _, width, height = testcase_spec 39 test_resolution = (width, height) 40 41 if not edid.is_edid_supported(host, *testcase_spec): 42 raise error.TestFail('Error: EDID is not supported by the platform' 43 ': %s', test_name) 44 45 edid_path = os.path.join(self.bindir, 'test_data', 'edids', test_name) 46 47 factory = remote_facade_factory.RemoteFacadeFactory(host) 48 display_facade = factory.create_display_facade() 49 chameleon_board = host.chameleon 50 51 chameleon_board.reset() 52 finder = chameleon_port_finder.ChameleonVideoInputFinder( 53 chameleon_board, display_facade) 54 for chameleon_port in finder.iterate_all_ports(): 55 screen_test = chameleon_screen_test.ChameleonScreenTest( 56 chameleon_port, display_facade, self.outputdir) 57 58 logging.info('Use EDID: %s', test_name) 59 with chameleon_port.use_edid_file(edid_path): 60 # Keep the original connector name, for later comparison. 61 expected_connector = utils.wait_for_value_changed( 62 display_facade.get_external_connector_name, 63 old_value=False) 64 logging.info('See the display on DUT: %s', expected_connector) 65 66 if not expected_connector: 67 raise error.TestFail('Error: Failed to see external display' 68 ' (chameleon) from DUT: %s', test_name) 69 70 logging.info('Set mirrored: %s', test_mirrored) 71 display_facade.set_mirrored(test_mirrored) 72 logging.info('Repeat %d times Suspend and resume', repeat_count) 73 74 count = repeat_count 75 while count > 0: 76 count -= 1 77 if test_mirrored: 78 # magic sleep to make nyan_big wake up in mirrored mode 79 # TODO: find root cause 80 time.sleep(6) 81 suspend_time = random.randint(*suspend_time_range) 82 logging.info('Going to suspend, for %d seconds...', 83 suspend_time) 84 display_facade.suspend_resume(suspend_time) 85 logging.info('Resumed back') 86 87 message = screen_test.check_external_display_connected( 88 expected_connector) 89 if not message: 90 message = screen_test.test_screen_with_image( 91 test_resolution, test_mirrored) 92 if message: 93 raise error.TestFail(message) 94