• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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(graphics_utils.GraphicsTest):
16    """
17    Benchmark OpenGL object rendering.
18    """
19    version = 2
20    preserve_srcdir = True
21
22    def setup(self):
23        os.chdir(self.srcdir)
24        utils.make('clean')
25        utils.make('all')
26
27    def initialize(self):
28        super(graphics_SanAngeles, self).initialize()
29        # If UI is running, we must stop it and restore later.
30        self._services = service_stopper.ServiceStopper(['ui'])
31        self._services.stop_services()
32
33    def cleanup(self):
34        if self._services:
35            self._services.restore_services()
36        super(graphics_SanAngeles, self).cleanup()
37
38    @graphics_utils.GraphicsTest.failure_report_decorator('graphics_SanAngeles')
39    def run_once(self):
40        cmd_gl = os.path.join(self.srcdir, 'SanOGL')
41        cmd_gles = os.path.join(self.srcdir, 'SanOGLES')
42        cmd_gles_s = os.path.join(self.srcdir, 'SanOGLES_S')
43        if os.path.isfile(cmd_gl):
44            cmd = cmd_gl
45        elif os.path.isfile(cmd_gles):
46            cmd = cmd_gles
47        elif os.path.isfile(cmd_gles_s):
48            cmd = cmd_gles_s
49        else:
50            raise error.TestFail(
51                'Failed: Could not locate SanAngeles executable: '
52                '%s, %s or %s.  Test setup error.' %
53                (cmd_gl, cmd_gles, cmd_gles_s))
54
55        cmd += ' ' + utils.graphics_platform()
56        result = utils.run(cmd,
57                           stderr_is_expected=False,
58                           stdout_tee=utils.TEE_TO_LOGS,
59                           stderr_tee=utils.TEE_TO_LOGS,
60                           ignore_status=True)
61
62        report = re.findall(r'frame_rate = ([0-9.]+)', result.stdout)
63        if not report:
64            raise error.TestFail('Failed: Could not find frame_rate in stdout ('
65                                 + result.stdout + ') ' + result.stderr)
66
67        frame_rate = float(report[0])
68        logging.info('frame_rate = %.1f', frame_rate)
69        self.write_perf_keyval({'frames_per_sec_rate_san_angeles': frame_rate})
70        self.output_perf_value(
71            description='fps',
72            value=frame_rate,
73            units='fps',
74            higher_is_better=True)
75        if 'error' in result.stderr.lower():
76            raise error.TestFail('Failed: stderr while running SanAngeles: ' +
77                                 result.stderr + ' (' + report[0] + ')')
78