1# Copyright (c) 2013 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 6 7from autotest_lib.client.common_lib import error 8from autotest_lib.server.cros import vboot_constants as vboot 9from autotest_lib.server.cros.faft.firmware_test import ConnectionError 10from autotest_lib.server.cros.faft.firmware_test import FirmwareTest 11 12 13class firmware_LegacyRecovery(FirmwareTest): 14 """ 15 Servo based test to Verify recovery request at Remove Screen. 16 17 This test requires a USB disk plugged-in, which contains a ChromeOS test 18 image (built by "build_image --test"). It recovery boots to the USB image 19 and sets recovery_request=1 and do a reboot. A failure is expected. 20 """ 21 version = 1 22 NEEDS_SERVO_USB = True 23 24 def initialize(self, host, cmdline_args): 25 super(firmware_LegacyRecovery, self).initialize(host, cmdline_args) 26 self.setup_usbkey(usbkey=True, host=False) 27 self.switcher.setup_mode('normal') 28 29 def cleanup(self): 30 super(firmware_LegacyRecovery, self).cleanup() 31 32 def run_once(self): 33 """Runs a single iteration of the test.""" 34 logging.info("Turn on the recovery boot. Enable recovery request " 35 "and perform a reboot.") 36 self.check_state((self.checkers.crossystem_checker, { 37 'devsw_boot': '0', 38 'mainfw_type': 'normal', 39 })) 40 self.faft_client.system.request_recovery_boot() 41 self.switcher.simple_reboot() 42 self.switcher.bypass_rec_mode() 43 try: 44 self.switcher.wait_for_client() 45 except ConnectionError: 46 raise error.TestError('Failed to boot the USB image.') 47 self.faft_client.system.run_shell_command( 48 'crossystem recovery_request=1') 49 50 logging.info("Wait to ensure no recovery boot at remove screen " 51 "and a boot failure is expected. " 52 "Unplug and plug USB, try to boot it again.") 53 self.check_state((self.checkers.crossystem_checker, { 54 'mainfw_type': 'recovery', 55 })) 56 self.switcher.mode_aware_reboot(wait_for_dut_up=False) 57 logging.info('Wait to ensure DUT doesnt Boot on USB at Remove screen.') 58 try: 59 self.switcher.wait_for_client(timeout=self.faft_config.usb_image_boot_timeout) 60 raise error.TestFail('Unexpected USB boot at Remove Screen.') 61 except ConnectionError: 62 logging.info('Done, Waited till timeout and no USB boot occured.') 63 self.switcher.bypass_rec_mode() 64 self.switcher.wait_for_client() 65 66 logging.info("Expected to boot the restored USB image and reboot.") 67 self.check_state((self.checkers.crossystem_checker, { 68 'mainfw_type': 'recovery', 69 'recovery_reason': vboot.RECOVERY_REASON['LEGACY'], 70 })) 71 self.switcher.mode_aware_reboot() 72 73 logging.info("Expected to normal boot and done.") 74 self.check_state((self.checkers.crossystem_checker, { 75 'devsw_boot': '0', 76 'mainfw_type': 'normal', 77 })) 78