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""" 6This is a client side WebGL clear test that measures how many frames-per-second 7(FPS) can be achieved (possibly limited by vsync) with glClear only. It can be 8useful to gauge that most WebGL applications won't likely achieve anything 9higher than the FPS output of this test, assuming all else equal. It may also 10be useful to various types of graphics developers as a sanity check. However, 11your mileage may vary and we make no claims with respect to any particular 12platform or application. 13 14This test is expected to run 30 seconds by default. Any run that reports a FPS 15value and finishes is a PASS. An acceptable FPS value is subjective and 16platform, driver and/or project dependent... interpretation of the FPS results 17are left up to the interested parties. 18""" 19 20import logging 21import os 22import time 23from autotest_lib.client.bin import test 24from autotest_lib.client.common_lib import error 25from autotest_lib.client.common_lib.cros import chrome 26from autotest_lib.client.cros.graphics import graphics_utils 27 28 29class graphics_WebGLClear(test.test): 30 """WebGL clear graphics test.""" 31 version = 1 32 GSC = None 33 perf_keyval = {} 34 test_duration_secs = 30 35 36 def setup(self): 37 self.job.setup_dep(['webgl_clear']) 38 39 def initialize(self): 40 self.GSC = graphics_utils.GraphicsStateChecker() 41 self.perf_keyval = {} 42 43 def cleanup(self): 44 if self.GSC: 45 keyvals = self.GSC.get_memory_keyvals() 46 for key, val in keyvals.iteritems(): 47 self.output_perf_value(description=key, 48 value=val, 49 units='bytes', 50 higher_is_better=False) 51 self.GSC.finalize() 52 self.write_perf_keyval(keyvals) 53 54 def run_clear_test(self, browser, test_url): 55 """Runs the clear test from the given url. 56 57 @param browser: The Browser object to run the test with. 58 @param test_url: The URL to the clear test suite. 59 """ 60 tab = browser.tabs.New() 61 tab.Navigate(test_url) 62 tab.Activate() 63 tab.WaitForDocumentReadyStateToBeComplete() 64 time.sleep(self.test_duration_secs) 65 avg_fps = tab.EvaluateJavaScript('g_fpsTimer.averageFPS;') 66 self.perf_keyval['avg_fps'] = avg_fps 67 self.output_perf_value(description='avg_fps', 68 value=avg_fps, 69 units='fps', 70 higher_is_better=True) 71 logging.info('Average FPS = %f', avg_fps) 72 73 tab.Close() 74 75 def run_once(self, test_duration_secs=30): 76 """Finds a brower with telemetry, and run the test. 77 78 @param test_duration_secs: The test duration in seconds to run the test 79 for. 80 """ 81 self.test_duration_secs = test_duration_secs 82 83 # For this to have any noticable effect, SwapbuffersWait needs to be false 84 # in xorg.conf. 85 browser_args = '--disable-gpu-vsync' 86 87 with chrome.Chrome(logged_in=False, 88 extra_browser_args=browser_args) as cr: 89 clearsrc = os.path.join(self.autodir, 'deps', 'webgl_clear', 'src') 90 if not cr.browser.platform.SetHTTPServerDirectories(clearsrc): 91 raise error.TestError('Unable to start HTTP server') 92 test_url = cr.browser.platform.http_server.UrlOf(os.path.join( 93 clearsrc, 'WebGLClear.html')) 94 self.run_clear_test(cr.browser, test_url) 95 96 self.write_perf_keyval(self.perf_keyval) 97