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