Home | History | Annotate | Download | only in platform_S3Cycle
      1 # Copyright 2016 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.common_lib import error
      8 from autotest_lib.client.common_lib import utils
      9 from autotest_lib.server.cros.faft.firmware_test import FirmwareTest
     10 
     11 # platform_S3Cycle test timing constants
     12 BEFORE_SUSPEND_WAIT_TIME_SECONDS = 10
     13 BEFORE_RESUME_WAIT_TIME_SECONDS = 2
     14 SUSPEND_WAIT_TIME_SECONDS = 5
     15 LIDOPEN_WAIT_TIME_SECONDS = 2
     16 POWER_STATE_RETRY_COUNT = 10
     17 
     18 class platform_S3Cycle(FirmwareTest):
     19     '''
     20     Servo based S3 cycle test.
     21     '''
     22     version = 1
     23 
     24     def initialize(self, host, cmdline_args):
     25         dict_args = utils.args_to_dict(cmdline_args)
     26         self.faft_iterations = int(dict_args.get('faft_iterations', 1))
     27         super(platform_S3Cycle, self).initialize(host, cmdline_args)
     28         self.switcher.setup_mode('normal')
     29 
     30     def perform_s3_cycle(self):
     31         """
     32         Perform S3 suspend/resume cycle and check state transition.
     33         """
     34         resume_sources = ['powerbtn', 'lid', 'kbpress']
     35         for resume_source in resume_sources:
     36             time.sleep(BEFORE_SUSPEND_WAIT_TIME_SECONDS);
     37             self.perform_suspend()
     38             self.perform_resume(resume_source)
     39 
     40     def perform_suspend(self):
     41         """
     42         Perform suspend to mem and check state transition.
     43         """
     44         logging.info('== S3 suspend and check the state transition ==')
     45         # check S0 state transition
     46         if not self.wait_power_state('S0', POWER_STATE_RETRY_COUNT):
     47             raise error.TestFail('Platform failed to reach S0 state.')
     48         self.faft_client.system.run_shell_command('echo mem > /sys/power/state &')
     49         time.sleep(SUSPEND_WAIT_TIME_SECONDS);
     50         # check S3 state transition
     51         if not self.wait_power_state('S3', POWER_STATE_RETRY_COUNT):
     52             raise error.TestFail('Platform failed to reach S3 state.')
     53 
     54     def perform_resume(self, resume_source):
     55         """
     56         Perform resume with selected resume source and check state transition.
     57         @param resume_source(string):resume source option.
     58         """
     59         logging.info('== S3 resume and check the state transition ==')
     60         time.sleep(BEFORE_RESUME_WAIT_TIME_SECONDS);
     61         if resume_source == 'powerbtn':
     62             self.ec.send_command('powerbtn')
     63         elif resume_source == 'lid':
     64             self.ec.send_command('lidclose')
     65             time.sleep(LIDOPEN_WAIT_TIME_SECONDS);
     66             self.ec.send_command('lidopen')
     67         elif resume_source == 'kbpress':
     68             self.ec.key_press('<enter>')
     69         else:
     70             raise error.TestFail('Invalid resume source.')
     71         # check S0 state transition
     72         if not self.wait_power_state('S0', POWER_STATE_RETRY_COUNT):
     73             raise error.TestFail('Platform failed to reach S0 state.')
     74 
     75     def run_once(self):
     76         if not self.faft_config.chrome_ec or not self.check_ec_capability():
     77             raise error.TestNAError('Chrome EC is not supported on this device.')
     78 
     79         for i in xrange(self.faft_iterations):
     80             logging.info('== Running FAFT ITERATION %d/%s ==',i+1, self.faft_iterations)
     81             logging.info('S3 suspend/resume back and check state transition.')
     82             self.switcher.mode_aware_reboot('custom', self.perform_s3_cycle)
     83 
     84     def cleanup(self):
     85         self.ec.set_uart_regexp('None')
     86         # Test may failed before resume, wake the system.
     87         self.ec.send_command('powerbtn')
     88         # Perform a warm reboot as part of the cleanup.
     89         self._client.reboot()
     90         super(platform_S3Cycle, self).cleanup()
     91