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 import time 7 8 from autotest_lib.client.common_lib import error 9 from autotest_lib.server.cros.faft.firmware_test import FirmwareTest 10 11 12 class firmware_DevScreenTimeout(FirmwareTest): 13 """ 14 Servo based developer firmware screen timeout test. 15 16 When booting in developer mode, the firmware shows a screen to warn user 17 the disk image is not secured. If a user press Ctrl-D or a timeout reaches, 18 it will boot to developer mode. This test is to verify the timeout period. 19 20 This test tries to boot the system in developer mode twice. 21 The first one will repeatly press Ctrl-D on booting in order to reduce 22 the time on developer warning screen. The second one will do nothing and 23 wait the developer screen timeout. The time difference of these two boots 24 is close to the developer screen timeout. 25 """ 26 version = 1 27 28 # We accept 5s timeout margin as we need 5s to ensure client is offline. 29 # If the margin is too small and firmware initialization is too fast, 30 # the test will fail incorrectly. 31 TIMEOUT_MARGIN = 5 32 33 fw_time_record = {} 34 35 def ctrl_d_repeatedly(self): 36 """Press Ctrl-D repeatedly. We want to be aggressive and obtain a 37 low firmware boot time when developer mode is enabled, so spam the 38 AP console with ctrl-D every half second until the firmware_screen 39 delay has been reached. 40 """ 41 for _ in range(self.faft_config.firmware_screen * 2): 42 self.servo.ctrl_d() 43 time.sleep(0.5) 44 45 def record_fw_boot_time(self, tag): 46 """Record the current firmware boot time with the tag. 47 48 Args: 49 tag: A tag about this boot. 50 51 Raises: 52 error.TestError: If the firmware-boot-time file does not exist. 53 """ 54 [fw_time] = self.faft_client.system.run_shell_command_get_output( 55 'cat /tmp/firmware-boot-time') 56 logging.info('Got firmware boot time: %s', fw_time) 57 if fw_time: 58 self.fw_time_record[tag] = float(fw_time) 59 else: 60 raise error.TestError('Failed to get the firmware boot time.') 61 62 def check_timeout_period(self): 63 """Check the firmware screen timeout period matches our spec. 64 65 Raises: 66 error.TestFail: If the timeout period does not match our spec. 67 """ 68 # Record the boot time of firmware screen timeout. 69 self.record_fw_boot_time('timeout_boot') 70 got_timeout = (self.fw_time_record['timeout_boot'] - 71 self.fw_time_record['ctrl_d_boot']) 72 logging.info('Estimated developer firmware timeout: %s', got_timeout) 73 74 if (abs(got_timeout - self.faft_config.dev_screen_timeout) > 75 self.TIMEOUT_MARGIN): 76 raise error.TestFail( 77 'The developer firmware timeout does not match our spec: ' 78 'expected %.2f +/- %.2f but got %.2f.' % 79 (self.faft_config.dev_screen_timeout, self.TIMEOUT_MARGIN, 80 got_timeout)) 81 82 def initialize(self, host, cmdline_args): 83 super(firmware_DevScreenTimeout, self).initialize(host, cmdline_args) 84 # This test is run on developer mode only. 85 self.switcher.setup_mode('dev') 86 self.setup_usbkey(usbkey=False) 87 88 def run_once(self): 89 if self.faft_config.fw_bypasser_type != 'ctrl_d_bypasser': 90 raise error.TestNAError("This test is only valid on devices with " 91 "screens.") 92 93 logging.info("Always expected developer mode firmware A boot.") 94 self.check_state((self.checkers.crossystem_checker, { 95 'devsw_boot': '1', 96 'mainfw_act': 'A', 97 'mainfw_type': 'developer', 98 })) 99 100 # To add an extra reboot before the measurement 101 # to avoid TPM reset too long 102 self.switcher.simple_reboot() 103 self.switcher.wait_for_client() 104 logging.info("Reboot and press Ctrl-D repeatedly.") 105 self.switcher.simple_reboot() 106 self.ctrl_d_repeatedly() 107 self.switcher.wait_for_client() 108 109 logging.info("Record the firmware boot time without waiting " 110 "firmware screen; on next reboot, do nothing and wait the " 111 "screen timeout.") 112 self.record_fw_boot_time('ctrl_d_boot') 113 self.switcher.simple_reboot() 114 self.switcher.wait_for_client() 115 116 logging.info("Check the firmware screen timeout matches our spec.") 117 self.check_timeout_period() 118