Home | History | Annotate | Download | only in power_PSROccupancyTest
      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 
      6 import os.path
      7 import time
      8 
      9 from autotest_lib.client.common_lib import error
     10 from autotest_lib.client.common_lib.cros import chrome
     11 from autotest_lib.client.bin import test, utils
     12 from autotest_lib.client.cros.graphics import graphics_utils
     13 
     14 
     15 class power_PSROccupancyTest(test.test):
     16     """
     17     Tests that PSR is entered on a static content.
     18 
     19     The purpose of this test is to verify that display enters the PSR state when
     20     the content being displayed is static. It also verifies that the display
     21     stays in PSR state for as long as the display is static. It first enables
     22     PSR if not enabled and makes the displayed content static. It then waits for
     23     some time, after which it checks whether the display was in PSR state for
     24     close to (<wait time> - <vblankoffdelay>).
     25     """
     26     version = 1
     27 
     28 
     29     def _is_psr_enabled(self):
     30         enable_psr_file_path = '/sys/module/i915/parameters/enable_psr'
     31         if not os.path.exists(enable_psr_file_path):
     32             raise error.TestFail('sysfs entry for "enable_psr" is missing.')
     33         return int(utils.read_file(enable_psr_file_path)) == 1
     34 
     35 
     36     def _get_perf_count(self):
     37         debugfs_file_path = '/sys/kernel/debug/dri/0/i915_edp_psr_status'
     38         if not os.path.exists(debugfs_file_path):
     39             raise error.TestFail('debugfs entry for PSR status is missing.')
     40         psr_status = utils.read_file(debugfs_file_path).splitlines()
     41         if len(psr_status) != 4:
     42             raise error.TestFail(
     43                     'Incorrect number of lines in %s.' % debugfs_file_path)
     44         perf_count_chunks = psr_status[3].split()
     45         if len(perf_count_chunks) != 2:
     46             raise error.TestFail('Unknown format in %s.' % debugfs_file_path)
     47         return int(perf_count_chunks[1])
     48 
     49 
     50     def _get_vblank_timeout(self):
     51         return int(utils.read_file('/sys/module/drm/parameters/vblankoffdelay'))
     52 
     53 
     54     def run_once(self):
     55         if utils.get_board() not in ['samus', 'gandof']:
     56             raise error.TestNAError(
     57                     'Trying to run PSR tests on unsupported board.')
     58         psr_enabled = self._is_psr_enabled()
     59         if (not psr_enabled and
     60             graphics_utils.call_xrandr('--output eDP1 --set psr on')):
     61             error.TestFail('Unable to enable PSR via xrandr.')
     62         # Start chrome in full screen mode so that there is no blinking cursor
     63         # or ticking clock on the screen.
     64         with chrome.Chrome(logged_in=False, extra_browser_args=['--kiosk']):
     65             # Sample the PSR performance count from debugfs and wait for 20s.
     66             # At the end of 20s, re-sample the PSR performance count. The time
     67             # spent in PSR should be close to (20s - <vblankoffdelay>).
     68             sleep_time_milliseconds = 20 * 1000
     69             min_occupancy = 0.9 * (sleep_time_milliseconds -
     70                                    self._get_vblank_timeout())
     71             perf_count_old = self._get_perf_count()
     72             time.sleep(sleep_time_milliseconds / 1000)
     73             perf_count_new = self._get_perf_count()
     74             occupancy_time = perf_count_new - perf_count_old
     75             if occupancy_time < min_occupancy:
     76                 raise error.TestFail(
     77                         'PSR occupancy time %dms less than expected.' %
     78                         occupancy_time)
     79             # Disable PSR if it was not enabled to begin with.
     80             if (not psr_enabled and
     81                 graphics_utils.call_xrandr('--output eDP1 --set psr off')):
     82                 raise error.TestWarn('Unable to disable PSR via xrandr.')
     83