1# Copyright (c) 2012 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 6from threading import Timer 7 8from autotest_lib.client.common_lib import common 9from autotest_lib.client.common_lib import error 10from autotest_lib.server.cros.faft.firmware_test import FirmwareTest 11 12 13class firmware_FAFTSetup(FirmwareTest): 14 """This test checks the following FAFT hardware requirement: 15 - Warm reset 16 - Cold reset 17 - Recovery boot with USB stick 18 - USB stick is plugged into Servo board, not DUT 19 - Keyboard simulation 20 - No terminal opened on EC console 21 """ 22 version = 1 23 NEEDS_SERVO_USB = True 24 25 # Delay to ensure client is ready to read the key press. 26 KEY_PRESS_DELAY = 2 27 28 def console_checker(self): 29 """Verify EC console is available if using Chrome EC.""" 30 if not self.check_ec_capability(suppress_warning=True): 31 # Not Chrome EC. Nothing to check. 32 return True 33 try: 34 if self.ec.get_version(): 35 return True 36 except: # pylint: disable=W0702 37 pass 38 39 logging.error("Cannot talk to EC console.") 40 logging.error( 41 "Please check there is no terminal opened on EC console.") 42 raise error.TestFail("Failed EC console check.") 43 44 def base_keyboard_checker(self, press_action): 45 """Press key and check from DUT. 46 47 Args: 48 press_action: A callable that would press the keys when called. 49 """ 50 result = True 51 # Stop UI so that key presses don't go to Chrome. 52 self.faft_client.system.run_shell_command("stop ui") 53 54 # Press the keys 55 Timer(self.KEY_PRESS_DELAY, press_action).start() 56 57 # Invoke client side script to monitor keystrokes 58 if not self.faft_client.system.check_keys([28, 29, 32]): 59 result = False 60 61 # Turn UI back on 62 self.faft_client.system.run_shell_command("start ui") 63 return result 64 65 def keyboard_checker(self): 66 """Press 'd', Ctrl, ENTER by servo and check from DUT.""" 67 68 def keypress(): 69 """Press 'd', Ctrl, ENTER""" 70 self.servo.ctrl_d() 71 self.servo.enter_key() 72 73 return self.base_keyboard_checker(keypress) 74 75 def run_once(self): 76 """Main test logic""" 77 logging.info("Check EC console is available and test warm reboot") 78 self.console_checker() 79 self.switcher.mode_aware_reboot() 80 81 logging.info("Check test image is on USB stick and run recovery boot") 82 self.setup_usbkey(usbkey=True, host=False) 83 self.switcher.reboot_to_mode(to_mode='rec') 84 85 self.check_state((self.checkers.crossystem_checker, { 86 'mainfw_type': 'recovery' 87 })) 88 89 logging.info("Check cold boot") 90 self.switcher.mode_aware_reboot(reboot_type='cold') 91 92 if self.faft_config.mode_switcher_type in ( 93 'menu_switcher', 94 'keyboard_dev_switcher'): 95 logging.info("Check keyboard simulation") 96 self.check_state(self.keyboard_checker) 97 else: 98 logging.info("Skip keyboard simulation on an embedded device") 99