xref: /aosp_15_r20/external/autotest/client/site_tests/graphics_PerfControl/graphics_PerfControl.py (revision 9c5db1993ded3edbeafc8092d69fe5de2ee02df7)
1# Lint as: python2, python3
2# Copyright (c) 2014 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, time
7
8from autotest_lib.client.bin import test, utils
9from autotest_lib.client.common_lib import error
10from autotest_lib.client.cros import perf
11from autotest_lib.client.cros import service_stopper
12from autotest_lib.client.cros.graphics import graphics_utils
13
14
15class graphics_PerfControl(graphics_utils.GraphicsTest):
16  version = 1
17
18  # None-init vars used by cleanup() here, in case setup() fails
19  _services = None
20
21  def initialize(self):
22    super(graphics_PerfControl, self).initialize()
23    self._services = service_stopper.ServiceStopper(['ui'])
24
25  def cleanup(self):
26    if self._services:
27      self._services.restore_services()
28    super(graphics_PerfControl, self).cleanup()
29
30  @graphics_utils.GraphicsTest.failure_report_decorator('graphics_PerfControl')
31  def run_once(self):
32    logging.info(utils.get_board_with_frequency_and_memory())
33
34    # If UI is running, we must stop it and restore later.
35    self._services.stop_services()
36
37    # Wrap the test run inside of a PerfControl instance to make machine
38    # behavior more consistent.
39    with perf.PerfControl() as pc:
40      if not pc.verify_is_valid():
41        raise error.TestFail('Failed: %s' % pc.get_error_reason())
42      # Do nothing for a short while so the PerfControl thread is collecting
43      # real data.
44      time.sleep(10)
45
46      if not pc.verify_is_valid():
47        raise error.TestFail('Failed: %s' % pc.get_error_reason())
48