Home | History | Annotate | Download | only in graphics_WebGLClear
      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 """
      6 This 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
      8 useful to gauge that most WebGL applications won't likely achieve anything
      9 higher than the FPS output of this test, assuming all else equal.  It may also
     10 be useful to various types of graphics developers as a sanity check.  However,
     11 your mileage may vary and we make no claims with respect to any particular
     12 platform or application.
     13 
     14 This test is expected to run 30 seconds by default.  Any run that reports a FPS
     15 value and finishes is a PASS.  An acceptable FPS value is subjective and
     16 platform, driver and/or project dependent... interpretation of the FPS results
     17 are left up to the interested parties.
     18 """
     19 
     20 import logging
     21 import os
     22 import time
     23 from autotest_lib.client.bin import test
     24 from autotest_lib.client.common_lib import error
     25 from autotest_lib.client.common_lib.cros import chrome
     26 from autotest_lib.client.cros.graphics import graphics_utils
     27 
     28 
     29 class 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