Tom Wai-Hong Tam | 109f63c | 2011-12-08 14:58:27 +0800 | [diff] [blame] | 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 |
Yusuf Mohsinally | e580a01 | 2014-05-18 19:23:12 -0700 | [diff] [blame] | 9 | from autotest_lib.server.cros.faft.firmware_test import FirmwareTest |
Tom Wai-Hong Tam | 109f63c | 2011-12-08 14:58:27 +0800 | [diff] [blame] | 10 | |
| 11 | |
Yusuf Mohsinally | e580a01 | 2014-05-18 19:23:12 -0700 | [diff] [blame] | 12 | class firmware_DevScreenTimeout(FirmwareTest): |
Tom Wai-Hong Tam | 109f63c | 2011-12-08 14:58:27 +0800 | [diff] [blame] | 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 | |
Vic Yang | 96713a9 | 2012-09-10 14:19:39 +0800 | [diff] [blame] | 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 |
Tom Wai-Hong Tam | 109f63c | 2011-12-08 14:58:27 +0800 | [diff] [blame] | 32 | |
| 33 | fw_time_record = {} |
| 34 | |
Tom Wai-Hong Tam | 109f63c | 2011-12-08 14:58:27 +0800 | [diff] [blame] | 35 | def ctrl_d_repeatedly(self): |
David Hendricks | 848e891 | 2015-08-24 16:47:29 -0700 | [diff] [blame] | 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): |
Tom Wai-Hong Tam | 408c995 | 2015-04-30 00:37:36 +0800 | [diff] [blame] | 42 | self.servo.ctrl_d() |
David Hendricks | 848e891 | 2015-08-24 16:47:29 -0700 | [diff] [blame] | 43 | time.sleep(0.5) |
Tom Wai-Hong Tam | 109f63c | 2011-12-08 14:58:27 +0800 | [diff] [blame] | 44 | |
Tom Wai-Hong Tam | 109f63c | 2011-12-08 14:58:27 +0800 | [diff] [blame] | 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 | """ |
Chun-ting Chang | d43aa9b | 2012-11-16 10:12:05 +0800 | [diff] [blame] | 54 | [fw_time] = self.faft_client.system.run_shell_command_get_output( |
Tom Wai-Hong Tam | 109f63c | 2011-12-08 14:58:27 +0800 | [diff] [blame] | 55 | 'cat /tmp/firmware-boot-time') |
Vic Yang | 47d42ba | 2012-10-31 11:07:39 +0800 | [diff] [blame] | 56 | logging.info('Got firmware boot time: %s', fw_time) |
Tom Wai-Hong Tam | 109f63c | 2011-12-08 14:58:27 +0800 | [diff] [blame] | 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 | |
Tom Wai-Hong Tam | 109f63c | 2011-12-08 14:58:27 +0800 | [diff] [blame] | 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']) |
Vic Yang | 47d42ba | 2012-10-31 11:07:39 +0800 | [diff] [blame] | 72 | logging.info('Estimated developer firmware timeout: %s', got_timeout) |
Tom Wai-Hong Tam | 109f63c | 2011-12-08 14:58:27 +0800 | [diff] [blame] | 73 | |
Yusuf Mohsinally | a39f970 | 2013-08-15 16:09:51 -0700 | [diff] [blame] | 74 | if (abs(got_timeout - self.faft_config.dev_screen_timeout) > |
Tom Wai-Hong Tam | 4173876 | 2012-10-29 14:32:39 +0800 | [diff] [blame] | 75 | self.TIMEOUT_MARGIN): |
Tom Wai-Hong Tam | 109f63c | 2011-12-08 14:58:27 +0800 | [diff] [blame] | 76 | raise error.TestFail( |
Yusuf Mohsinally | e580a01 | 2014-05-18 19:23:12 -0700 | [diff] [blame] | 77 | 'The developer firmware timeout does not match our spec: ' |
Tom Wai-Hong Tam | 109f63c | 2011-12-08 14:58:27 +0800 | [diff] [blame] | 78 | 'expected %.2f +/- %.2f but got %.2f.' % |
Yusuf Mohsinally | a39f970 | 2013-08-15 16:09:51 -0700 | [diff] [blame] | 79 | (self.faft_config.dev_screen_timeout, self.TIMEOUT_MARGIN, |
Tom Wai-Hong Tam | 4173876 | 2012-10-29 14:32:39 +0800 | [diff] [blame] | 80 | got_timeout)) |
Tom Wai-Hong Tam | 109f63c | 2011-12-08 14:58:27 +0800 | [diff] [blame] | 81 | |
Yusuf Mohsinally | 1f115ae | 2013-11-06 17:31:16 -0800 | [diff] [blame] | 82 | def initialize(self, host, cmdline_args): |
| 83 | super(firmware_DevScreenTimeout, self).initialize(host, cmdline_args) |
Tom Wai-Hong Tam | 109f63c | 2011-12-08 14:58:27 +0800 | [diff] [blame] | 84 | # This test is run on developer mode only. |
Tom Wai-Hong Tam | 0cc9a4f | 2015-05-02 05:12:39 +0800 | [diff] [blame] | 85 | self.switcher.setup_mode('dev') |
Tom Wai-Hong Tam | 893bcc0 | 2012-11-02 16:13:34 +0800 | [diff] [blame] | 86 | self.setup_usbkey(usbkey=False) |
Tom Wai-Hong Tam | 109f63c | 2011-12-08 14:58:27 +0800 | [diff] [blame] | 87 | |
Vic Yang | b09a041 | 2012-11-06 15:18:22 +0800 | [diff] [blame] | 88 | def run_once(self): |
Daisuke Nojiri | 76bed2f | 2015-10-29 08:58:45 -0700 | [diff] [blame] | 89 | if self.faft_config.fw_bypasser_type != 'ctrl_d_bypasser': |
Tom Wai-Hong Tam | ab52742 | 2015-05-22 07:03:28 +0800 | [diff] [blame] | 90 | raise error.TestNAError("This test is only valid on devices with " |
| 91 | "screens.") |
| 92 | |
Yusuf Mohsinally | e580a01 | 2014-05-18 19:23:12 -0700 | [diff] [blame] | 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 | |
Peggy Chuang | fdcef7b | 2018-02-26 17:45:43 +0800 | [diff] [blame] | 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() |
Yusuf Mohsinally | e580a01 | 2014-05-18 19:23:12 -0700 | [diff] [blame] | 104 | logging.info("Reboot and press Ctrl-D repeatedly.") |
Shelley Chen | 5ca7148 | 2016-12-14 16:48:25 -0800 | [diff] [blame] | 105 | self.switcher.simple_reboot() |
Yusuf Mohsinally | e580a01 | 2014-05-18 19:23:12 -0700 | [diff] [blame] | 106 | self.ctrl_d_repeatedly() |
Tom Wai-Hong Tam | 19bfb6e | 2015-08-20 06:05:36 +0800 | [diff] [blame] | 107 | self.switcher.wait_for_client() |
Yusuf Mohsinally | e580a01 | 2014-05-18 19:23:12 -0700 | [diff] [blame] | 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') |
Shelley Chen | 5ca7148 | 2016-12-14 16:48:25 -0800 | [diff] [blame] | 113 | self.switcher.simple_reboot() |
Tom Wai-Hong Tam | 19bfb6e | 2015-08-20 06:05:36 +0800 | [diff] [blame] | 114 | self.switcher.wait_for_client() |
Yusuf Mohsinally | e580a01 | 2014-05-18 19:23:12 -0700 | [diff] [blame] | 115 | |
| 116 | logging.info("Check the firmware screen timeout matches our spec.") |
| 117 | self.check_timeout_period() |