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 5 import logging 6 import time 7 8 from autotest_lib.client.common_lib import error 9 from autotest_lib.server.cros.faft.firmware_test import FirmwareTest 10 11 12 class 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 23 SHORT_SHUTDOWN_CONFIRMATION_PERIOD = 0.1 24 25 def wait_fw_screen_and_close_lid(self): 26 """Wait for firmware warning screen and close lid.""" 27 time.sleep(self.faft_config.firmware_screen) 28 self.servo.lid_close() 29 30 def wait_longer_fw_screen_and_close_lid(self): 31 """Wait for firmware screen without timeout and close lid.""" 32 time.sleep(self.faft_config.firmware_screen) 33 self.wait_fw_screen_and_close_lid() 34 35 def wait_second_screen_and_close_lid(self): 36 """Wait and trigger TO_NORM or RECOVERY INSERT screen and close lid.""" 37 self.switcher.trigger_dev_to_rec() 38 self.wait_longer_fw_screen_and_close_lid() 39 40 def wait_yuck_screen_and_close_lid(self): 41 """Wait and trigger yuck screen and clod lid.""" 42 # Insert a corrupted USB stick. A yuck screen is expected. 43 self.servo.switch_usbkey('dut') 44 time.sleep(self.faft_config.usb_plug) 45 self.wait_longer_fw_screen_and_close_lid() 46 47 def initialize(self, host, cmdline_args): 48 super(firmware_FwScreenCloseLid, self).initialize(host, cmdline_args) 49 if self.faft_config.has_lid: 50 self.assert_test_image_in_usb_disk() 51 self.switcher.setup_mode('dev') 52 self.servo.switch_usbkey('host') 53 usb_dev = self.servo.probe_host_usb_dev() 54 # Corrupt the kernel of USB stick. It is needed for triggering a 55 # yuck screen later. 56 self.corrupt_usb_kernel(usb_dev) 57 58 def cleanup(self): 59 if self.faft_config.has_lid: 60 self.servo.switch_usbkey('host') 61 usb_dev = self.servo.probe_host_usb_dev() 62 # Restore kernel of USB stick which is corrupted on setup phase. 63 self.restore_usb_kernel(usb_dev) 64 super(firmware_FwScreenCloseLid, self).cleanup() 65 66 def run_once(self): 67 if not self.faft_config.has_lid: 68 logging.info('This test does nothing on devices without lid.') 69 return 70 71 if self.faft_config.fw_bypasser_type != 'ctrl_d_bypasser': 72 raise error.TestNAError("This test is only valid on devices with " 73 "screens.") 74 75 if self.faft_config.chrome_ec and not self.check_ec_capability(['lid']): 76 raise error.TestNAError("TEST IT MANUALLY! ChromeEC can't control " 77 "lid on the device %s" % 78 self.faft_config.platform) 79 80 logging.info("Expected dev mode and reboot. " 81 "When the next DEVELOPER SCREEN shown, close lid " 82 "to make DUT shutdown.") 83 self.check_state((self.checkers.crossystem_checker, { 84 'devsw_boot': '1', 85 'mainfw_type': 'developer', 86 })) 87 self.switcher.mode_aware_reboot(wait_for_dut_up=False) 88 self.run_shutdown_process(self.wait_fw_screen_and_close_lid, 89 pre_power_action=self.servo.lid_open, 90 run_power_action=False, 91 post_power_action=self.switcher.bypass_dev_mode) 92 self.switcher.wait_for_client() 93 94 logging.info("Reboot. When the developer screen shown, press " 95 "enter key to trigger either TO_NORM screen (new) or " 96 "RECOVERY INSERT screen (old). Then close lid to " 97 "make DUT shutdown.") 98 self.check_state((self.checkers.crossystem_checker, { 99 'devsw_boot': '1', 100 'mainfw_type': 'developer', 101 })) 102 self.switcher.mode_aware_reboot(wait_for_dut_up=False) 103 self.run_shutdown_process(self.wait_second_screen_and_close_lid, 104 pre_power_action=self.servo.lid_open, 105 run_power_action=False, 106 post_power_action=self.switcher.bypass_dev_mode, 107 shutdown_timeout=self.SHORT_SHUTDOWN_CONFIRMATION_PERIOD) 108 self.switcher.wait_for_client() 109 110 logging.info("Request recovery boot. When the RECOVERY INSERT " 111 "screen shows, close lid to make DUT shutdown.") 112 self.check_state((self.checkers.crossystem_checker, { 113 'devsw_boot': '1', 114 'mainfw_type': 'developer', 115 })) 116 self.faft_client.system.request_recovery_boot() 117 self.switcher.mode_aware_reboot(wait_for_dut_up=False) 118 self.run_shutdown_process(self.wait_longer_fw_screen_and_close_lid, 119 pre_power_action=self.servo.lid_open, 120 run_power_action=False, 121 post_power_action=self.switcher.bypass_dev_mode, 122 shutdown_timeout=self.SHORT_SHUTDOWN_CONFIRMATION_PERIOD) 123 self.switcher.wait_for_client() 124 125 logging.info("Request recovery boot again. When the recovery " 126 "insert screen shows, insert a corrupted USB and trigger " 127 "a YUCK SCREEN. Then 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.mode_aware_reboot(wait_for_dut_up=False) 134 self.run_shutdown_process(self.wait_yuck_screen_and_close_lid, 135 pre_power_action=self.servo.lid_open, 136 run_power_action=False, 137 post_power_action=self.switcher.bypass_dev_mode, 138 shutdown_timeout=self.SHORT_SHUTDOWN_CONFIRMATION_PERIOD) 139 self.switcher.wait_for_client() 140 141 logging.info("Switch back to normal mode.") 142 self.check_state((self.checkers.crossystem_checker, { 143 'devsw_boot': '1', 144 'mainfw_type': 'developer', 145 })) 146 self.switcher.reboot_to_mode(to_mode='normal') 147 148 logging.info("Expected normal mode and request recovery boot. " 149 "Because an USB stick is inserted, a RECOVERY REMOVE " 150 "screen shows. Close lid to make DUT shutdown.") 151 self.check_state((self.checkers.crossystem_checker, { 152 'devsw_boot': '0', 153 'mainfw_type': 'normal', 154 })) 155 self.faft_client.system.request_recovery_boot() 156 self.switcher.mode_aware_reboot(wait_for_dut_up=False) 157 self.run_shutdown_process(self.wait_longer_fw_screen_and_close_lid, 158 pre_power_action=self.servo.lid_open, 159 run_power_action=False, 160 shutdown_timeout=self.SHORT_SHUTDOWN_CONFIRMATION_PERIOD) 161 self.switcher.wait_for_client() 162 self.check_state((self.checkers.crossystem_checker, { 163 'devsw_boot': '0', 164 'mainfw_type': 'normal', 165 })) 166