Home | History | Annotate | Download | only in firmware_InvalidUSB
      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.client.common_lib import error
      8 from autotest_lib.server.cros import vboot_constants as vboot
      9 from autotest_lib.server.cros.faft.firmware_test import ConnectionError
     10 from autotest_lib.server.cros.faft.firmware_test import FirmwareTest
     11 
     12 
     13 class firmware_InvalidUSB(FirmwareTest):
     14     """
     15     Servo based booting an invalid USB image test.
     16 
     17     This test requires a USB disk plugged-in, which contains a Chrome OS test
     18     image (built by "build_image --test"). On runtime, this test corrupts the
     19     USB image and tries to boot into it. A failure is expected. It then
     20     restores the USB image and boots into it again.
     21     """
     22     version = 1
     23 
     24     def restore_usb(self):
     25         """Restore the USB image. USB plugs/unplugs happen in this method."""
     26         self.servo.switch_usbkey('host')
     27         usb_dev = self.servo.probe_host_usb_dev()
     28         self.restore_usb_kernel(usb_dev)
     29 
     30     def initialize(self, host, cmdline_args):
     31         super(firmware_InvalidUSB, self).initialize(host, cmdline_args)
     32         self.servo.switch_usbkey('host')
     33         usb_dev = self.servo.probe_host_usb_dev()
     34         self.assert_test_image_in_usb_disk(usb_dev)
     35         self.corrupt_usb_kernel(usb_dev)
     36         self.switcher.setup_mode('normal')
     37         self.servo.switch_usbkey('dut')
     38 
     39     def cleanup(self):
     40         self.restore_usb()
     41         super(firmware_InvalidUSB, self).cleanup()
     42 
     43     def run_once(self):
     44         logging.info("Turn on the recovery boot. Remove and insert the"
     45                      "corrupted USB stick, a boot failure is expected."
     46                      "Restore the USB image and boot it again.")
     47         self.check_state((self.checkers.crossystem_checker, {
     48                           'devsw_boot': '0',
     49                           'mainfw_type': 'normal',
     50                           }))
     51         self.switcher.reboot_to_mode(to_mode='rec', wait_for_dut_up=False)
     52         logging.info('Wait to ensure the USB image is unable to boot...')
     53         try:
     54             self.switcher.wait_for_client()
     55             raise error.TestFail('Should not boot from the invalid USB image.')
     56         except ConnectionError:
     57             logging.info(
     58                 'The USB image is surely unable to boot. Restore it and try...')
     59 
     60         self.restore_usb()
     61         self.servo.switch_usbkey('dut')
     62         self.switcher.wait_for_client()
     63 
     64         logging.info("Expected to boot the restored USB image and reboot.")
     65         self.check_state((self.checkers.crossystem_checker, {
     66                           'mainfw_type': 'recovery',
     67                           'recovery_reason': vboot.RECOVERY_REASON['RO_MANUAL'],
     68                           }))
     69         self.switcher.mode_aware_reboot()
     70 
     71         logging.info("Expected to normal boot and done.")
     72         self.check_state((self.checkers.crossystem_checker, {
     73                           'devsw_boot': '0',
     74                           'mainfw_type': 'normal',
     75                           }))
     76