• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Lint as: python2, python3
2# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6import logging
7import os
8import re
9
10from autotest_lib.client.bin import test, utils
11from autotest_lib.client.common_lib import error
12from autotest_lib.client.cros import service_stopper
13from autotest_lib.client.cros.graphics import graphics_utils
14
15
16class graphics_SanAngeles(graphics_utils.GraphicsTest):
17    """
18    Benchmark OpenGL object rendering.
19    """
20    version = 2
21    preserve_srcdir = True
22
23    def setup(self):
24        os.chdir(self.srcdir)
25        utils.make('clean')
26        utils.make('all')
27
28    def initialize(self):
29        super(graphics_SanAngeles, self).initialize()
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        super(graphics_SanAngeles, self).cleanup()
38
39    @graphics_utils.GraphicsTest.failure_report_decorator('graphics_SanAngeles')
40    def run_once(self):
41        cmd_gl = os.path.join(self.srcdir, 'SanOGL')
42        cmd_gles = os.path.join(self.srcdir, 'SanOGLES')
43        cmd_gles_s = os.path.join(self.srcdir, 'SanOGLES_S')
44        if os.path.isfile(cmd_gl):
45            cmd = cmd_gl
46        elif os.path.isfile(cmd_gles):
47            cmd = cmd_gles
48        elif os.path.isfile(cmd_gles_s):
49            cmd = cmd_gles_s
50        else:
51            raise error.TestFail(
52                'Failed: Could not locate SanAngeles executable: '
53                '%s, %s or %s.  Test setup error.' %
54                (cmd_gl, cmd_gles, cmd_gles_s))
55
56        cmd += ' ' + utils.graphics_platform()
57        result = utils.run(cmd,
58                           stderr_is_expected=False,
59                           stdout_tee=utils.TEE_TO_LOGS,
60                           stderr_tee=utils.TEE_TO_LOGS,
61                           ignore_status=True)
62
63        report = re.findall(r'frame_rate = ([0-9.]+)', result.stdout)
64        if not report:
65            raise error.TestFail('Failed: Could not find frame_rate in stdout ('
66                                 + result.stdout + ') ' + result.stderr)
67
68        frame_rate = float(report[0])
69        logging.info('frame_rate = %.1f', frame_rate)
70        self.write_perf_keyval({'frames_per_sec_rate_san_angeles': frame_rate})
71        self.output_perf_value(
72            description='fps',
73            value=frame_rate,
74            units='fps',
75            higher_is_better=True)
76        if 'error' in result.stderr.lower():
77            raise error.TestFail('Failed: stderr while running SanAngeles: ' +
78                                 result.stderr + ' (' + report[0] + ')')
79