1 # Copyright (c) 2012 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.faft.firmware_test import FirmwareTest 9 10 11 class firmware_DevBootUSB(FirmwareTest): 12 """ 13 Servo based Ctrl-U developer USB 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 switches 17 DUT to developer mode. When dev_boot_usb=0, pressing Ctrl-U on developer 18 screen should not boot the USB disk. When dev_boot_usb=1, pressing Ctrl-U 19 should boot the USB disk. 20 """ 21 version = 1 22 23 def initialize(self, host, cmdline_args, ec_wp=None): 24 super(firmware_DevBootUSB, self).initialize(host, cmdline_args, 25 ec_wp=ec_wp) 26 self.switcher.setup_mode('dev') 27 self.setup_usbkey(usbkey=True, host=False) 28 29 self.original_dev_boot_usb = self.faft_client.system.get_dev_boot_usb() 30 logging.info('Original dev_boot_usb value: %s', 31 str(self.original_dev_boot_usb)) 32 33 def cleanup(self): 34 try: 35 self.ensure_dev_internal_boot(self.original_dev_boot_usb) 36 except Exception as e: 37 logging.error("Caught exception: %s", str(e)) 38 super(firmware_DevBootUSB, self).cleanup() 39 40 def run_once(self): 41 if (self.faft_config.has_keyboard and 42 not self.check_ec_capability(['keyboard'])): 43 raise error.TestNAError("TEST IT MANUALLY! This test can't be " 44 "automated on non-Chrome-EC devices.") 45 46 logging.info("Expected developer mode, set dev_boot_usb to 0.") 47 self.check_state((self.checkers.dev_boot_usb_checker, False)) 48 self.faft_client.system.set_dev_boot_usb(0) 49 self.switcher.mode_aware_reboot() 50 51 logging.info("Expected internal disk boot, set dev_boot_usb to 1.") 52 self.check_state((self.checkers.dev_boot_usb_checker, 53 False, 54 "Not internal disk boot, dev_boot_usb misbehaved")) 55 self.faft_client.system.set_dev_boot_usb(1) 56 self.switcher.simple_reboot() 57 self.switcher.bypass_dev_boot_usb() 58 self.switcher.wait_for_client() 59 60 logging.info("Expected USB boot, set dev_boot_usb to the original.") 61 self.check_state((self.checkers.dev_boot_usb_checker, (True, True), 62 'Device not booted from USB image properly.')) 63 self.faft_client.system.set_dev_boot_usb(self.original_dev_boot_usb) 64 self.switcher.mode_aware_reboot() 65 66 logging.info("Check and done.") 67 self.check_state((self.checkers.dev_boot_usb_checker, False)) 68