1 # Copyright (c) 2012 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 import logging 6 import os 7 import re 8 9 from autotest_lib.client.bin import test, utils 10 from autotest_lib.client.common_lib import error 11 from autotest_lib.client.cros import service_stopper 12 from autotest_lib.client.cros.graphics import graphics_utils 13 14 15 class graphics_SanAngeles(test.test): 16 """ 17 Benchmark OpenGL object rendering. 18 """ 19 version = 2 20 preserve_srcdir = True 21 GSC = None 22 23 def setup(self): 24 os.chdir(self.srcdir) 25 utils.make('clean') 26 utils.make('all') 27 28 def initialize(self): 29 self.GSC = graphics_utils.GraphicsStateChecker() 30 if utils.is_freon(): 31 # If UI is running, we must stop it and restore later. 32 self._services = service_stopper.ServiceStopper(['ui']) 33 self._services.stop_services() 34 35 def cleanup(self): 36 if utils.is_freon() and self._services: 37 self._services.restore_services() 38 if self.GSC: 39 keyvals = self.GSC.get_memory_keyvals() 40 for key, val in keyvals.iteritems(): 41 self.output_perf_value(description=key, value=val, 42 units='bytes', higher_is_better=False) 43 self.GSC.finalize() 44 self.write_perf_keyval(keyvals) 45 46 def run_once(self): 47 cmd_gl = os.path.join(self.srcdir, 'SanOGL') 48 cmd_gles = os.path.join(self.srcdir, 'SanOGLES') 49 cmd_gles_s = os.path.join(self.srcdir, 'SanOGLES_S') 50 if os.path.isfile(cmd_gl): 51 cmd = cmd_gl 52 elif os.path.isfile(cmd_gles): 53 cmd = cmd_gles 54 elif os.path.isfile(cmd_gles_s): 55 cmd = cmd_gles_s 56 else: 57 raise error.TestFail('Failed to locate SanAngeles executable: ' 58 '%s, %s or %s. Test setup error.' 59 % (cmd_gl, cmd_gles, cmd_gles_s)) 60 61 cmd += ' ' + utils.graphics_platform() 62 cmd = graphics_utils.xcommand(cmd) 63 result = utils.run(cmd, 64 stderr_is_expected=False, 65 stdout_tee=utils.TEE_TO_LOGS, 66 stderr_tee=utils.TEE_TO_LOGS, 67 ignore_status=True) 68 69 report = re.findall(r'frame_rate = ([0-9.]+)', result.stdout) 70 if not report: 71 raise error.TestFail('Could not find frame_rate in stdout (' + 72 result.stdout + ') ' + result.stderr) 73 74 frame_rate = float(report[0]) 75 logging.info('frame_rate = %.1f', frame_rate) 76 self.write_perf_keyval( 77 {'frames_per_sec_rate_san_angeles': frame_rate}) 78 self.output_perf_value(description='fps', value=frame_rate, 79 units='fps', higher_is_better=True) 80 if 'error' in result.stderr.lower(): 81 raise error.TestFail('Error on stderr while running SanAngeles: ' + 82 result.stderr + ' (' + report[0] + ')') 83