• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 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"""This is a client side WebGL performance test.
5
6http://hg.mozilla.org/users/bjacob_mozilla.com/webgl-perf-tests/raw-file/3729e8afac99/index.html
7
8From the sources:
9Keep in mind that these tests are not realistic workloads. These are not
10benchmarks aiming to compare browser or GPU performance. These are only useful
11to catch performance regressions in a given browser and system.
12"""
13
14import logging
15import os
16
17from autotest_lib.client.bin import test
18from autotest_lib.client.bin import utils
19from autotest_lib.client.common_lib import error
20from autotest_lib.client.common_lib.cros import chrome
21from autotest_lib.client.cros.graphics import graphics_utils
22
23
24class graphics_WebGLPerformance(graphics_utils.GraphicsTest):
25    """WebGL performance graphics test."""
26    version = 1
27    _test_duration_secs = 0
28    perf_keyval = {}
29
30    def setup(self):
31        self.job.setup_dep(['webgl_perf'])
32        self.job.setup_dep(['graphics'])
33
34    def initialize(self):
35        super(graphics_WebGLPerformance, self).initialize()
36
37    def cleanup(self):
38        super(graphics_WebGLPerformance, self).cleanup()
39
40    def run_performance_test(self, browser, test_url):
41        """Runs the performance test from the given url.
42
43        @param browser: The Browser object to run the test with.
44        @param test_url: The URL to the performance test site.
45        """
46        if not utils.wait_for_idle_cpu(60.0, 0.1):
47            if not utils.wait_for_idle_cpu(20.0, 0.2):
48                raise error.TestFail('Failed: Could not get idle CPU.')
49
50        # Kick off test.
51        tab = browser.tabs.New()
52        tab.Navigate(test_url)
53        tab.Activate()
54        tab.WaitForDocumentReadyStateToBeComplete()
55
56        # Wait for test completion.
57        tab.WaitForJavaScriptCondition('time_ms_geom_mean > 0.0',
58                                       timeout=self._test_duration_secs)
59
60        # Get the geometric mean of individual runtimes.
61        time_ms_geom_mean = tab.EvaluateJavaScript('time_ms_geom_mean')
62        logging.info('WebGLPerformance: time_ms_geom_mean = %f',
63                     time_ms_geom_mean)
64
65        # Output numbers for plotting by harness.
66        keyvals = {}
67        keyvals['time_ms_geom_mean'] = time_ms_geom_mean
68        self.write_perf_keyval(keyvals)
69        self.output_perf_value(
70            description='time_geom_mean',
71            value=time_ms_geom_mean,
72            units='ms',
73            higher_is_better=False,
74            graph='time_geom_mean')
75        # Add extra value to the graph distinguishing different boards.
76        variant = utils.get_board_with_frequency_and_memory()
77        desc = 'time_geom_mean-%s' % variant
78        self.output_perf_value(
79            description=desc,
80            value=time_ms_geom_mean,
81            units='ms',
82            higher_is_better=False,
83            graph='time_geom_mean')
84
85        # Get a copy of the test report.
86        test_report = tab.EvaluateJavaScript('test_report')
87        results_path = os.path.join(
88            self.bindir,
89            '../../results/default/graphics_WebGLPerformance/test_report.html')
90        f = open(results_path, 'w+')
91        f.write(test_report)
92        f.close()
93
94        tab.Close()
95
96    @graphics_utils.GraphicsTest.failure_report_decorator('graphics_WebGLPerformance')
97    def run_once(self, test_duration_secs=2700, fullscreen=True):
98        """Finds a brower with telemetry, and run the test.
99
100        @param test_duration_secs: The test duration in seconds.
101        @param fullscreen: Whether to run the test in fullscreen.
102        """
103        # To avoid 0ms on fast machines like samus the workload was increased.
104        # Unfortunately that makes running on slow machines impractical without
105        # deviating from upstream too much.
106        if utils.get_gpu_family() == 'pinetrail':
107            # TODO(ihf): return a TestPass(message) once available.
108            logging.warning('Test is too slow to run regularly.')
109            return
110
111        self._test_duration_secs = test_duration_secs
112        ext_paths = []
113        if fullscreen:
114            ext_paths.append(
115                os.path.join(self.autodir, 'deps', 'graphics',
116                             'graphics_test_extension'))
117
118        with chrome.Chrome(logged_in=False,
119                           extension_paths=ext_paths,
120                           init_network_controller=True) as cr:
121            websrc_dir = os.path.join(self.autodir, 'deps', 'webgl_perf', 'src')
122            if not cr.browser.platform.SetHTTPServerDirectories(websrc_dir):
123                raise error.TestFail('Failed: Unable to start HTTP server')
124            test_url = cr.browser.platform.http_server.UrlOf(
125                os.path.join(websrc_dir, 'index.html'))
126            self.run_performance_test(cr.browser, test_url)
127