• 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 to enable HDCP and verify screen."""
6
7import logging
8import time
9
10from autotest_lib.client.bin import utils
11from autotest_lib.client.common_lib import error
12from autotest_lib.client.cros.chameleon import chameleon_port_finder
13from autotest_lib.client.cros.chameleon import chameleon_screen_test
14from autotest_lib.server import test
15from autotest_lib.server.cros.multimedia import remote_facade_factory
16
17
18class display_HDCPScreen(test.test):
19    """Server side test to enable HDCP and verify screen.
20
21    This test forces CrOS to enable HDCP and compares screens between CrOS
22    and Chameleon.
23    """
24    version = 1
25
26    TEST_CONFIGS = [
27        # (enable_chameleon, request_cros, expected_cros_state,
28        #  expected_chameleon_state)
29        (True, 'Desired', 'Enabled', True),
30        (False, 'Desired', 'Desired', False),
31        # TODO: Investigate the case below which was disabled as it failed.
32        # Check http://crbug.com/447493
33        #(True, 'Undesired', 'Undesired', False),
34        (False, 'Undesired', 'Undesired', False),
35    ]
36
37    DURATION_UNPLUG_FOR_HDCP = 1
38    TIMEOUT_HDCP_SWITCH = 10
39
40    def run_once(self, host, test_mirrored=False):
41        if host.get_architecture() != 'arm':
42            raise error.TestNAError('HDCP is not supported on a non-ARM device')
43
44        factory = remote_facade_factory.RemoteFacadeFactory(host)
45        display_facade = factory.create_display_facade()
46        chameleon_board = host.chameleon
47
48        chameleon_board.setup_and_reset(self.outputdir)
49        finder = chameleon_port_finder.ChameleonVideoInputFinder(
50                chameleon_board, display_facade)
51
52        errors = []
53        for chameleon_port in finder.iterate_all_ports():
54            screen_test = chameleon_screen_test.ChameleonScreenTest(
55                    chameleon_port, display_facade, self.outputdir)
56
57            logging.info('See the display on Chameleon: port %d (%s)',
58                         chameleon_port.get_connector_id(),
59                         chameleon_port.get_connector_type())
60
61            logging.info('Set mirrored: %s', test_mirrored)
62            display_facade.set_mirrored(test_mirrored)
63
64            resolution = display_facade.get_external_resolution()
65            logging.info('Detected resolution on CrOS: %r', resolution)
66
67            original_cros_state = display_facade.get_content_protection()
68            was_chameleon_enabled = (
69                    chameleon_port.is_content_protection_enabled())
70            try:
71                for (enable_chameleon, request_cros, expected_cros_state,
72                     expected_chameleon_state) in self.TEST_CONFIGS:
73                    # Do unplug and plug to emulate switching to a different
74                    # display with a different content protection state.
75                    chameleon_port.unplug()
76                    logging.info('Set Chameleon HDCP: %r', enable_chameleon)
77                    chameleon_port.set_content_protection(enable_chameleon)
78                    time.sleep(self.DURATION_UNPLUG_FOR_HDCP)
79                    chameleon_port.plug()
80                    chameleon_port.wait_video_input_stable()
81
82                    logging.info('Request CrOS HDCP: %s', request_cros)
83                    display_facade.set_content_protection(request_cros)
84
85                    state = utils.wait_for_value(
86                            display_facade.get_content_protection, 'Enabled',
87                            timeout_sec=self.TIMEOUT_HDCP_SWITCH)
88                    logging.info('Got CrOS state: %s', state)
89                    if state != expected_cros_state:
90                        error_message = ('Failed to enable HDCP, state: %r' %
91                                         state)
92                        logging.error(error_message)
93                        errors.append(error_message)
94
95                    encrypted = chameleon_port.is_video_input_encrypted()
96                    logging.info('Got Chameleon state: %r', encrypted)
97                    if encrypted != expected_chameleon_state:
98                        error_message = ('Chameleon found HDCP in wrong state: '
99                                         'expected %r but got %r' %
100                                         (expected_chameleon_state, encrypted))
101                        logging.error(error_message)
102                        errors.append(error_message)
103
104                    logging.info('Test screen under HDCP %s...',
105                                 'enabled' if encrypted else 'disabled')
106                    screen_test.test_screen_with_image(
107                            resolution, test_mirrored, errors)
108            finally:
109                display_facade.set_content_protection(original_cros_state)
110                chameleon_port.set_content_protection(was_chameleon_enabled)
111
112        if errors:
113            raise error.TestFail('; '.join(set(errors)))
114