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