1# Copyright 2015 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 6import time 7 8from autotest_lib.client.common_lib import utils 9from autotest_lib.server.cros import vboot_constants as vboot 10from autotest_lib.server.cros.faft.firmware_test import FirmwareTest 11from autotest_lib.server.cros.faft.firmware_test import ConnectionError 12 13 14class firmware_ConsecutiveBoot(FirmwareTest): 15 """ 16 Servo based consecutive boot test via power button to turn on DUT and 17 /sbin/shutdown command to turn off DUT. 18 19 This test is intended to be run with many iterations to ensure that the DUT 20 does boot into Chrome OS and then does power off later. 21 22 The iteration should be specified by the parameter -a "faft_iterations=10". 23 """ 24 version = 1 25 # Number of power button press to boot before declare test fail. 26 POWER_ON_RETRY = 3 27 28 29 def initialize(self, host, cmdline_args, dev_mode=False): 30 # Parse arguments from command line 31 dict_args = utils.args_to_dict(cmdline_args) 32 self.faft_iterations = int(dict_args.get('faft_iterations', 1)) 33 self.faft_waitup_time = int(dict_args.get('faft_waitup_time', 0)) 34 self.faft_localrun = int(dict_args.get('faft_localrun', 0)) 35 super(firmware_ConsecutiveBoot, self).initialize(host, cmdline_args) 36 self.switcher.setup_mode('dev' if dev_mode else 'normal') 37 if dev_mode: 38 self.clear_set_gbb_flags(0, vboot.GBB_FLAG_DEV_SCREEN_SHORT_DELAY) 39 self.setup_usbkey(usbkey=False) 40 41 def wait_for_client_aux(self): 42 """Use test specific timeout to wait for system to come up, 43 otherwise use default (180s). 44 """ 45 logging.info('wait_for_client %d start.', self.faft_waitup_time) 46 if self.faft_waitup_time: 47 self.switcher.wait_for_client(self.faft_waitup_time) 48 else: 49 self.switcher.wait_for_client() 50 51 def shutdown_power_on(self): 52 """ 53 Use /sbin/shutdown to turn off device follow by power button press to 54 turn on device. Do not want to call full_power_off_and_on since we 55 are testing firmware and mainly want to focus on power on sequence. 56 """ 57 boot_id = self.get_bootid() 58 59 # Call shutdown instead of long press the power key, since we're 60 # testing the firmware, not the power manager and button handling. 61 logging.info("Sending /sbin/shutdown -P now") 62 self.run_shutdown_cmd() 63 logging.info('Wait for client to go offline') 64 self.switcher.wait_for_client_offline(timeout=100, orig_boot_id=boot_id) 65 if self.check_ec_capability(['x86'], suppress_warning=True): 66 self.check_shutdown_power_state( 67 self.POWER_STATE_G3, pwr_retries=13, orig_boot_id=boot_id) 68 69 # Retry in case power_short_press was not registered. 70 for i in xrange(self.POWER_ON_RETRY): 71 logging.info("sleep %d, tap power key to boot.", 72 self.faft_config.powerup_ready) 73 time.sleep(self.faft_config.powerup_ready) 74 self.servo.power_key(self.faft_config.hold_pwr_button_poweron) 75 try: 76 self.wait_for_client_aux() 77 except ConnectionError: 78 logging.error('wait_for_client exception %d.', i) 79 else: 80 logging.info('wait_for_client online done %d.', i) 81 return 82 raise ConnectionError() 83 84 def cleanup(self): 85 try: 86 # Restore the GBB flag in developer mode test. 87 self.clear_set_gbb_flags(vboot.GBB_FLAG_DEV_SCREEN_SHORT_DELAY, 0) 88 except Exception as e: 89 logging.error("Caught exception: %s", str(e)) 90 super(firmware_ConsecutiveBoot, self).cleanup() 91 92 def run_once(self, host, dev_mode=False): 93 """Runs a single iteration of the test.""" 94 for i in xrange(self.faft_iterations): 95 logging.info('======== Running FAFT ITERATION %d/%s ========', 96 i+1, self.faft_iterations) 97 logging.info("Expected boot fine, full power off DUT and on.") 98 self.check_state((self.checkers.crossystem_checker, { 99 'mainfw_type': 'developer' if dev_mode else 'normal', 100 })) 101 self.shutdown_power_on() 102 103 logging.info("Expected boot fine.") 104 self.check_state((self.checkers.crossystem_checker, { 105 'mainfw_type': 'developer' if dev_mode else 'normal', 106 })) 107