• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2018 The Chromium 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
5import logging
6import os
7
8from autotest_lib.client.bin import utils
9from autotest_lib.client.common_lib import error
10from autotest_lib.client.cros import chrome_binary_test
11from autotest_lib.client.cros.graphics import graphics_utils
12from autotest_lib.client.common_lib.cros import chrome
13from autotest_lib.client.cros import constants
14from autotest_lib.client.cros.multimedia import display_facade_native
15from autotest_lib.client.cros.multimedia import facade_resource
16
17EXTRA_BROWSER_ARGS = ['--enable-experimental-web-platform-features']
18
19class graphics_HwOverlays(graphics_utils.GraphicsTest,
20                          chrome_binary_test.ChromeBinaryTest):
21    """Runs a given html and measures stuff."""
22    version = 1
23
24    # The tests are essentially composed of a preamble and an epilog, in between
25    # which we count the amount of overlays. Each of those essentially waits
26    # until either a total number of items is drawn, or there's a timeout.
27    PREAMBLE_TOTAL_NUMBER_OF_DRAW_PASSES = 5
28    PREAMBLE_TIMEOUT_SECONDS = 10
29    EPILOG_TOTAL_NUMBER_OF_DRAW_PASSES = 10
30    EPILOG_TIMEOUT_SECONDS = 10
31
32    POLLING_INTERVAL_SECONDS = 1
33
34    def initialize(self):
35        super(graphics_HwOverlays, self).initialize()
36
37    def cleanup(self):
38        super(graphics_HwOverlays, self).cleanup()
39
40    def set_rotation_to_zero(self, cr):
41        # Set rotation to 0 (portrait) otherwise tablet platforms might not get
42        # overlays.
43        facade = facade_resource.FacadeResource(cr)
44
45        display_facade = display_facade_native.DisplayFacadeNative(facade)
46        internal_display_id = display_facade.get_internal_display_id()
47
48        logging.info("Internal display ID is %s", internal_display_id)
49        display_facade.set_display_rotation(internal_display_id, rotation=0)
50
51    def run_once(self, html_file, data_file_url = None):
52        if not graphics_utils.is_drm_atomic_supported():
53            logging.info('Skipping test: platform does not support DRM atomic')
54            return
55
56        if graphics_utils.get_max_num_available_drm_planes() <= 2:
57            logging.info('Skipping test: platform supports 2 or less planes')
58            return
59
60        logging.info('Starting test, navigating to %s', html_file)
61
62        with chrome.Chrome(extra_browser_args=EXTRA_BROWSER_ARGS,
63                           extension_paths=[constants.DISPLAY_TEST_EXTENSION],
64                           autotest_ext=True,
65                           init_network_controller=True) as cr:
66            self.set_rotation_to_zero(cr)
67
68            cr.browser.platform.SetHTTPServerDirectories(self.bindir)
69
70            tab = cr.browser.tabs[0]
71            tab.Navigate(cr.browser.platform.http_server.UrlOf(
72                    os.path.join(self.bindir, html_file)))
73            tab.WaitForDocumentReadyStateToBeComplete()
74
75            if data_file_url:
76                tab.EvaluateJavaScript('load_data_url("%s")' % data_file_url)
77
78            # Draw something; this also triggers JS parsing and execution.
79            tab.EvaluateJavaScript('draw_pass()')
80
81            # Wait until a few passes have been drawn, then read the amount of
82            # overlays.
83            utils.poll_for_condition(
84                    lambda: tab.EvaluateJavaScript('get_draw_passes_count()') >
85                            self.PREAMBLE_TOTAL_NUMBER_OF_DRAW_PASSES,
86                    exception=error.TestFail('JS is not drawing (preamble)'),
87                    timeout=self.PREAMBLE_TIMEOUT_SECONDS,
88                    sleep_interval=self.POLLING_INTERVAL_SECONDS)
89
90            num_overlays = 0;
91            try:
92                num_overlays = graphics_utils.get_num_hardware_overlays()
93                logging.debug('Found %s overlays', num_overlays)
94            except Exception as e:
95                logging.error(e)
96                raise error.TestFail('Error: %s' % str(e))
97
98            utils.poll_for_condition(
99                    lambda: tab.EvaluateJavaScript('get_draw_passes_count()') >
100                            self.EPILOG_TOTAL_NUMBER_OF_DRAW_PASSES,
101                    exception=error.TestFail('JS is not drawing (epilog)'),
102                    timeout=self.EPILOG_TIMEOUT_SECONDS,
103                    sleep_interval=self.POLLING_INTERVAL_SECONDS)
104
105            if (num_overlays <= 1):
106                raise error.TestFail('%s failed, number of overlays is %d' %
107                        (html_file, num_overlays))
108