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