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 5import logging, time 6 7from autotest_lib.client.common_lib import error 8from autotest_lib.client.common_lib import utils 9from autotest_lib.server.cros.faft.firmware_test import FirmwareTest 10 11# platform_S3Cycle test timing constants 12BEFORE_SUSPEND_WAIT_TIME_SECONDS = 10 13BEFORE_RESUME_WAIT_TIME_SECONDS = 2 14SUSPEND_WAIT_TIME_SECONDS = 5 15LIDOPEN_WAIT_TIME_SECONDS = 2 16POWER_STATE_RETRY_COUNT = 10 17 18class 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 cmd = 'echo mem > /sys/power/state' 49 block = False 50 self.faft_client.system.run_shell_command(cmd, block) 51 time.sleep(SUSPEND_WAIT_TIME_SECONDS); 52 # check S3 state transition 53 if not self.wait_power_state('S3', POWER_STATE_RETRY_COUNT): 54 raise error.TestFail('Platform failed to reach S3 state.') 55 56 def perform_resume(self, resume_source): 57 """ 58 Perform resume with selected resume source and check state transition. 59 @param resume_source(string):resume source option. 60 """ 61 logging.info('== S3 resume and check the state transition ==') 62 time.sleep(BEFORE_RESUME_WAIT_TIME_SECONDS); 63 if resume_source == 'powerbtn': 64 self.ec.send_command('powerbtn') 65 elif resume_source == 'lid': 66 self.ec.send_command('lidclose') 67 time.sleep(LIDOPEN_WAIT_TIME_SECONDS); 68 self.ec.send_command('lidopen') 69 elif resume_source == 'kbpress': 70 self.ec.key_press('<enter>') 71 else: 72 raise error.TestFail('Invalid resume source.') 73 # check S0 state transition 74 if not self.wait_power_state('S0', POWER_STATE_RETRY_COUNT): 75 raise error.TestFail('Platform failed to reach S0 state.') 76 77 def run_once(self): 78 """Main test logic""" 79 if not self.faft_config.chrome_ec or not self.check_ec_capability(): 80 raise error.TestNAError('Chrome EC is not supported on this device.') 81 82 for i in xrange(self.faft_iterations): 83 logging.info('== Running FAFT ITERATION %d/%s ==',i+1, self.faft_iterations) 84 logging.info('S3 suspend/resume back and check state transition.') 85 self.switcher.mode_aware_reboot('custom', self.perform_s3_cycle) 86 87 def cleanup(self): 88 self.ec.set_uart_regexp('None') 89 # Test may failed before resume, wake the system. 90 self.ec.send_command('powerbtn') 91 # Perform a warm reboot as part of the cleanup. 92 self._client.reboot() 93 super(platform_S3Cycle, self).cleanup() 94