Home | History | Annotate | Download | only in firmware_UserRequestRecovery
      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 
      7 from autotest_lib.server.cros import vboot_constants as vboot
      8 from autotest_lib.server.cros.faft.firmware_test import FirmwareTest
      9 
     10 
     11 class firmware_UserRequestRecovery(FirmwareTest):
     12     """
     13     Servo based user request recovery boot test.
     14 
     15     This test requires a USB disk plugged-in, which contains a Chrome OS test
     16     image (built by "build_image --test"). On runtime, this test first requests
     17     a recovery mode on next boot by setting the crossystem recovery_request
     18     flag. It then triggers recovery mode by unplugging and plugging in the USB
     19     disk and checks success of it.
     20     """
     21     version = 1
     22 
     23     def ensure_normal_boot(self):
     24         """Ensure normal mode boot this time.
     25 
     26         If not, it may be a test failure during step 2, try to recover to
     27         normal mode by simply rebooting the machine.
     28         """
     29         if not self.checkers.crossystem_checker(
     30                 {'mainfw_type': ('normal', 'developer')}):
     31             self.switcher.mode_aware_reboot()
     32 
     33     def initialize(self, host, cmdline_args, dev_mode=False, ec_wp=None):
     34         super(firmware_UserRequestRecovery, self).initialize(host, cmdline_args,
     35                                                              ec_wp=ec_wp)
     36         self.switcher.setup_mode('dev' if dev_mode else 'normal')
     37         self.setup_usbkey(usbkey=True, host=True)
     38 
     39     def cleanup(self):
     40         try:
     41             self.ensure_normal_boot()
     42         except Exception as e:
     43             logging.error("Caught exception: %s", str(e))
     44         super(firmware_UserRequestRecovery, self).cleanup()
     45 
     46     def run_once(self, dev_mode=False):
     47         logging.info("Request recovery boot.")
     48         self.check_state((self.checkers.crossystem_checker, {
     49                            'mainfw_type': 'developer' if dev_mode else 'normal',
     50                            }))
     51         # Execute on DUT: crossystem recovery_request=193
     52         self.faft_client.system.request_recovery_boot()
     53         # Execute from desktop:
     54         #   dut-control warm_reset:on sleep:0.5000 warm_reset:off
     55         self.switcher.simple_reboot()
     56 
     57         # DUT should be waiting for USB after reboot.
     58         # Connect servo USB to DUT and DUT should boot from USB.
     59         # dut-control usb_mux_sel1:dut_sees_usbkey
     60         # bypass_rec_mode will issue power_state:rec if host did not response in
     61         # delay_reboot_to_ping seconds, which may reset recovery_reason and
     62         # fail this tests.
     63         self.switcher.bypass_rec_mode()
     64         self.switcher.wait_for_client()
     65 
     66         logging.info("Expected recovery boot, request recovery again.")
     67         self.check_state((self.checkers.crossystem_checker, {
     68                            'mainfw_type': 'recovery',
     69                            'recovery_reason' : vboot.RECOVERY_REASON['US_TEST'],
     70                            }))
     71 
     72         self.faft_client.system.request_recovery_boot()
     73         self.switcher.simple_reboot()
     74         self.switcher.bypass_rec_mode()
     75         self.switcher.wait_for_client()
     76 
     77         logging.info("Expected recovery boot.")
     78         self.check_state((self.checkers.crossystem_checker, {
     79                            'mainfw_type': 'recovery',
     80                            'recovery_reason' : vboot.RECOVERY_REASON['US_TEST'],
     81                            }))
     82         self.switcher.mode_aware_reboot()
     83 
     84         logging.info("Expected normal boot.")
     85         self.check_state((self.checkers.crossystem_checker, {
     86                            'mainfw_type': 'developer' if dev_mode else 'normal',
     87                            }))
     88