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