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