Home | History | Annotate | Download | only in power_SuspendToIdle
      1 # Copyright (c) 2018 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
      6 
      7 from contextlib import contextmanager
      8 
      9 from autotest_lib.client.bin import test
     10 from autotest_lib.client.bin import utils
     11 from autotest_lib.client.common_lib import error
     12 from autotest_lib.client.cros.power import power_suspend
     13 from autotest_lib.client.cros.power import power_status
     14 from autotest_lib.client.cros.power import power_utils
     15 
     16 
     17 class power_SuspendToIdle(test.test):
     18     """class for power_SuspendToIdle test."""
     19     version = 1
     20 
     21     @contextmanager
     22     def _log_error_message(self):
     23         """Suppress exception and log the message."""
     24         try:
     25             yield
     26         except Exception as e:
     27             self._error_count += 1
     28             self._error_message.append(str(e))
     29 
     30     def run_once(self, force_suspend_to_idle=False):
     31         """Main test method.
     32         """
     33         if utils.get_cpu_arch() != 'x86_64':
     34             raise error.TestNAError('This test only supports x86_64 CPU.')
     35 
     36         if power_utils.get_sleep_state() != 'freeze':
     37             if not force_suspend_to_idle:
     38                 raise error.TestNAError(
     39                     'System default config is not suspend to idle.')
     40             else:
     41                 logging.info('System default config is suspend to ram. '
     42                              'Force suspend to idle')
     43 
     44         self._error_count = 0
     45         self._error_message = []
     46         dmc_firmware_stats = None
     47         s0ix_residency_stats = None
     48         cpu_packages_stats = None
     49         rc6_residency_stats = None
     50 
     51         with self._log_error_message():
     52             dmc_firmware_stats = power_status.DMCFirmwareStats()
     53             if not dmc_firmware_stats.check_fw_loaded():
     54                 raise error.TestFail('DMC firmware not loaded.')
     55 
     56         with self._log_error_message():
     57             pch_powergating_stats = power_status.PCHPowergatingStats()
     58             pch_powergating_stats.read_pch_powergating_info()
     59             if not pch_powergating_stats.check_s0ix_requirement():
     60                 raise error.TestFail('PCH powergating check failed.')
     61 
     62         with self._log_error_message():
     63             s0ix_residency_stats = power_status.S0ixResidencyStats()
     64 
     65         with self._log_error_message():
     66             cpu_packages_stats = power_status.CPUPackageStats()
     67 
     68         with self._log_error_message():
     69             rc6_residency_stats = power_status.RC6ResidencyStats()
     70 
     71         with self._log_error_message():
     72             suspender = power_suspend.Suspender(self.resultsdir,
     73                                                 suspend_state='freeze')
     74             suspender.suspend()
     75 
     76         with self._log_error_message():
     77             if (dmc_firmware_stats and
     78                 dmc_firmware_stats.is_dc6_supported() and
     79                 dmc_firmware_stats.get_accumulated_dc6_entry() <= 0):
     80                 raise error.TestFail('DC6 entry check failed.')
     81 
     82         with self._log_error_message():
     83             if (s0ix_residency_stats and
     84                 s0ix_residency_stats.get_accumulated_residency_secs() <= 0):
     85                 raise error.TestFail('S0ix residency check failed.')
     86 
     87         with self._log_error_message():
     88             if (cpu_packages_stats and
     89                 cpu_packages_stats.refresh().get('C10', 0) <= 0):
     90                 raise error.TestFail('C10 state check failed.')
     91 
     92         with self._log_error_message():
     93             if (rc6_residency_stats and
     94                 rc6_residency_stats.get_accumulated_residency_secs() <= 0):
     95                 raise error.TestFail('RC6 residency check failed.')
     96 
     97         if self._error_count > 0:
     98             raise error.TestFail('Found %d errors: ' % self._error_count,
     99                                  ', '.join(self._error_message))
    100