1# Copyright (c) 2011 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 error 9from autotest_lib.server.cros.faft.firmware_test import FirmwareTest 10 11 12class firmware_FwScreenCloseLid(FirmwareTest): 13 """ 14 Servo based lid close triggered shutdown test during firmware screens. 15 16 This test requires a USB disk plugged-in, which contains a Chrome OS test 17 image (built by "build_image --test"). On runtime, this test triggers 18 firmware screens (developer, remove, insert, yuck, to_norm screens), 19 and then closes the lid in order to power the machine down. 20 """ 21 version = 1 22 NEEDS_SERVO_USB = True 23 24 SHORT_SHUTDOWN_CONFIRMATION_PERIOD = 0.1 25 26 def wait_fw_screen_and_close_lid(self): 27 """Wait for firmware warning screen and close lid.""" 28 time.sleep(self.faft_config.firmware_screen) 29 self.servo.lid_close() 30 31 def wait_longer_fw_screen_and_close_lid(self): 32 """Wait for firmware screen without timeout and close lid.""" 33 time.sleep(self.faft_config.firmware_screen) 34 self.wait_fw_screen_and_close_lid() 35 36 def wait_second_screen_and_close_lid(self): 37 """Wait and trigger TO_NORM or RECOVERY INSERT screen and close lid.""" 38 self.switcher.trigger_dev_to_rec() 39 self.wait_longer_fw_screen_and_close_lid() 40 41 def wait_yuck_screen_and_close_lid(self): 42 """Wait and trigger yuck screen and clod lid.""" 43 # Insert a corrupted USB stick. A yuck screen is expected. 44 self.servo.switch_usbkey('dut') 45 time.sleep(self.faft_config.usb_plug) 46 self.wait_longer_fw_screen_and_close_lid() 47 48 def initialize(self, host, cmdline_args): 49 """Initialize the test""" 50 super(firmware_FwScreenCloseLid, self).initialize(host, cmdline_args) 51 if self.faft_config.has_lid: 52 self.switcher.setup_mode('dev') 53 self.setup_usbkey(True, host=True) 54 usb_dev = self.servo.probe_host_usb_dev() 55 # Corrupt the kernel of USB stick. It is needed for triggering a 56 # yuck screen later. 57 self.corrupt_usb_kernel(usb_dev) 58 59 def cleanup(self): 60 """Cleanup the test""" 61 try: 62 if self.faft_config.has_lid: 63 self.servo.switch_usbkey('host') 64 usb_dev = self.servo.probe_host_usb_dev() 65 # Restore kernel of USB stick which is corrupted on setup phase. 66 self.restore_usb_kernel(usb_dev) 67 except Exception as e: 68 logging.error("Caught exception: %s", str(e)) 69 super(firmware_FwScreenCloseLid, self).cleanup() 70 71 def run_once(self): 72 """Main test logic""" 73 if not self.faft_config.has_lid: 74 logging.info('This test does nothing on devices without lid.') 75 return 76 77 # Some platforms may not turn on with just lid open 78 power_action = False 79 if not self.faft_config.lid_wake_from_power_off: 80 power_action = True 81 82 if self.faft_config.mode_switcher_type not in ( 83 'keyboard_dev_switcher', 'tablet_detachable_switcher', 84 'menu_switcher'): 85 raise error.TestNAError("This test is only valid on devices with " 86 "screens.") 87 88 if self.faft_config.chrome_ec and not self.check_ec_capability(['lid' 89 ]): 90 raise error.TestNAError( 91 "TEST IT MANUALLY! ChromeEC can't control " 92 "lid on the device %s" % self.faft_config.platform) 93 94 logging.info("Expected dev mode and reboot. " 95 "When the next DEVELOPER SCREEN shown, close lid " 96 "to make DUT shutdown.") 97 self.check_state((self.checkers.crossystem_checker, { 98 'devsw_boot': '1', 99 'mainfw_type': 'developer', 100 })) 101 self.switcher.simple_reboot() 102 self.run_shutdown_process( 103 self.wait_fw_screen_and_close_lid, 104 pre_power_action=self.servo.lid_open, 105 run_power_action=power_action, 106 post_power_action=self.switcher.bypass_dev_mode) 107 self.switcher.wait_for_client() 108 109 logging.info("Reboot. When the developer screen shown, press " 110 "enter key to trigger either TO_NORM screen (new) or " 111 "RECOVERY INSERT screen (old). Then close lid to " 112 "make DUT shutdown.") 113 self.check_state((self.checkers.crossystem_checker, { 114 'devsw_boot': '1', 115 'mainfw_type': 'developer', 116 })) 117 self.switcher.simple_reboot() 118 self.run_shutdown_process( 119 self.wait_second_screen_and_close_lid, 120 pre_power_action=self.servo.lid_open, 121 run_power_action=power_action, 122 post_power_action=self.switcher.bypass_dev_mode, 123 shutdown_timeout=self.SHORT_SHUTDOWN_CONFIRMATION_PERIOD) 124 self.switcher.wait_for_client() 125 126 logging.info("Request recovery boot. When the RECOVERY INSERT " 127 "screen shows, close lid to make DUT shutdown.") 128 self.check_state((self.checkers.crossystem_checker, { 129 'devsw_boot': '1', 130 'mainfw_type': 'developer', 131 })) 132 self.faft_client.system.request_recovery_boot() 133 self.switcher.simple_reboot() 134 self.run_shutdown_process( 135 self.wait_longer_fw_screen_and_close_lid, 136 pre_power_action=self.servo.lid_open, 137 run_power_action=power_action, 138 post_power_action=self.switcher.bypass_dev_mode, 139 shutdown_timeout=self.SHORT_SHUTDOWN_CONFIRMATION_PERIOD) 140 self.switcher.wait_for_client() 141 142 logging.info("Request recovery boot again. When the recovery " 143 "insert screen shows, insert a corrupted USB and trigger " 144 "a YUCK SCREEN. Then close lid to make DUT shutdown.") 145 self.check_state((self.checkers.crossystem_checker, { 146 'devsw_boot': '1', 147 'mainfw_type': 'developer', 148 })) 149 self.faft_client.system.request_recovery_boot() 150 self.switcher.simple_reboot() 151 self.run_shutdown_process( 152 self.wait_yuck_screen_and_close_lid, 153 pre_power_action=self.servo.lid_open, 154 run_power_action=power_action, 155 post_power_action=self.switcher.bypass_dev_mode, 156 shutdown_timeout=self.SHORT_SHUTDOWN_CONFIRMATION_PERIOD) 157 self.switcher.wait_for_client() 158 159 logging.info("Switch back to normal mode.") 160 self.check_state((self.checkers.crossystem_checker, { 161 'devsw_boot': '1', 162 'mainfw_type': 'developer', 163 })) 164 self.switcher.reboot_to_mode(to_mode='normal') 165 166 logging.info("Expected normal mode and request recovery boot. " 167 "Because an USB stick is inserted, a RECOVERY REMOVE " 168 "screen shows. Close lid to make DUT shutdown.") 169 self.check_state((self.checkers.crossystem_checker, { 170 'devsw_boot': '0', 171 'mainfw_type': 'normal', 172 })) 173 self.faft_client.system.request_recovery_boot() 174 self.switcher.simple_reboot() 175 self.run_shutdown_process( 176 self.wait_longer_fw_screen_and_close_lid, 177 pre_power_action=self.servo.lid_open, 178 run_power_action=power_action, 179 shutdown_timeout=self.SHORT_SHUTDOWN_CONFIRMATION_PERIOD) 180 self.switcher.wait_for_client() 181 self.check_state((self.checkers.crossystem_checker, { 182 'devsw_boot': '0', 183 'mainfw_type': 'normal', 184 })) 185