Home | History | Annotate | Download | only in firmware_RecoveryButton
      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_RecoveryButton(FirmwareTest):
     12     """
     13     Servo based recovery button 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 emulates
     17     recovery button pressed and reboots. It then triggers recovery mode by
     18     unplugging and plugging in the USB disk and checks success of it.
     19     """
     20     version = 1
     21 
     22     def ensure_normal_boot(self):
     23         """Ensure normal mode boot this time.
     24 
     25         If not, it may be a test failure during step 2, try to recover to
     26         normal mode by setting no recovery mode and rebooting the machine.
     27         """
     28         if not self.checkers.crossystem_checker(
     29                 {'mainfw_type': ('normal', 'developer')}):
     30             self.servo.disable_recovery_mode()
     31             self.switcher.mode_aware_reboot()
     32 
     33     def initialize(self, host, cmdline_args, dev_mode=False, ec_wp=None):
     34         super(firmware_RecoveryButton, 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=False)
     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_RecoveryButton, self).cleanup()
     45 
     46     def run_once(self, dev_mode=False):
     47         is_jetstream = (self.faft_config.mode_switcher_type ==
     48                         'jetstream_switcher')
     49         logging.info("Switch to recovery mode and reboot.")
     50         self.check_state((self.checkers.crossystem_checker, {
     51                     'mainfw_type': 'developer' if dev_mode else 'normal',
     52                     }))
     53         self.switcher.reboot_to_mode(to_mode='rec',
     54                                      from_mode='dev' if dev_mode else 'normal')
     55 
     56         logging.info("Expected recovery boot and reboot.")
     57         self.check_state((self.checkers.crossystem_checker, {
     58                     'mainfw_type': 'recovery',
     59                     'recovery_reason': vboot.RECOVERY_REASON['RO_MANUAL'],
     60                     }))
     61         self.switcher.mode_aware_reboot()
     62 
     63         logging.info("Expected normal/dev boot.")
     64         self.check_state((self.checkers.crossystem_checker, {
     65                     'mainfw_type': 'developer' if dev_mode and not is_jetstream
     66                                     else 'normal',
     67                     }))
     68