blob: f04bbf499b778795d22901c8bf882d1358483b45 [file] [log] [blame]
Tom Wai-Hong Tam109f63c2011-12-08 14:58:27 +08001# 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
5import logging
6import time
7
8from autotest_lib.client.common_lib import error
Yusuf Mohsinallye580a012014-05-18 19:23:12 -07009from autotest_lib.server.cros.faft.firmware_test import FirmwareTest
Tom Wai-Hong Tam109f63c2011-12-08 14:58:27 +080010
11
Yusuf Mohsinallye580a012014-05-18 19:23:12 -070012class firmware_DevScreenTimeout(FirmwareTest):
Tom Wai-Hong Tam109f63c2011-12-08 14:58:27 +080013 """
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 Yang96713a92012-09-10 14:19:39 +080028 # 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 Tam109f63c2011-12-08 14:58:27 +080032
33 fw_time_record = {}
34
Tom Wai-Hong Tam109f63c2011-12-08 14:58:27 +080035 def ctrl_d_repeatedly(self):
David Hendricks848e8912015-08-24 16:47:29 -070036 """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 Tam408c9952015-04-30 00:37:36 +080042 self.servo.ctrl_d()
David Hendricks848e8912015-08-24 16:47:29 -070043 time.sleep(0.5)
Tom Wai-Hong Tam109f63c2011-12-08 14:58:27 +080044
Tom Wai-Hong Tam109f63c2011-12-08 14:58:27 +080045 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 Changd43aa9b2012-11-16 10:12:05 +080054 [fw_time] = self.faft_client.system.run_shell_command_get_output(
Tom Wai-Hong Tam109f63c2011-12-08 14:58:27 +080055 'cat /tmp/firmware-boot-time')
Vic Yang47d42ba2012-10-31 11:07:39 +080056 logging.info('Got firmware boot time: %s', fw_time)
Tom Wai-Hong Tam109f63c2011-12-08 14:58:27 +080057 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 Tam109f63c2011-12-08 14:58:27 +080062 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 Yang47d42ba2012-10-31 11:07:39 +080072 logging.info('Estimated developer firmware timeout: %s', got_timeout)
Tom Wai-Hong Tam109f63c2011-12-08 14:58:27 +080073
Yusuf Mohsinallya39f9702013-08-15 16:09:51 -070074 if (abs(got_timeout - self.faft_config.dev_screen_timeout) >
Tom Wai-Hong Tam41738762012-10-29 14:32:39 +080075 self.TIMEOUT_MARGIN):
Tom Wai-Hong Tam109f63c2011-12-08 14:58:27 +080076 raise error.TestFail(
Yusuf Mohsinallye580a012014-05-18 19:23:12 -070077 'The developer firmware timeout does not match our spec: '
Tom Wai-Hong Tam109f63c2011-12-08 14:58:27 +080078 'expected %.2f +/- %.2f but got %.2f.' %
Yusuf Mohsinallya39f9702013-08-15 16:09:51 -070079 (self.faft_config.dev_screen_timeout, self.TIMEOUT_MARGIN,
Tom Wai-Hong Tam41738762012-10-29 14:32:39 +080080 got_timeout))
Tom Wai-Hong Tam109f63c2011-12-08 14:58:27 +080081
Yusuf Mohsinally1f115ae2013-11-06 17:31:16 -080082 def initialize(self, host, cmdline_args):
83 super(firmware_DevScreenTimeout, self).initialize(host, cmdline_args)
Tom Wai-Hong Tam109f63c2011-12-08 14:58:27 +080084 # This test is run on developer mode only.
Tom Wai-Hong Tam0cc9a4f2015-05-02 05:12:39 +080085 self.switcher.setup_mode('dev')
Tom Wai-Hong Tam893bcc02012-11-02 16:13:34 +080086 self.setup_usbkey(usbkey=False)
Tom Wai-Hong Tam109f63c2011-12-08 14:58:27 +080087
Vic Yangb09a0412012-11-06 15:18:22 +080088 def run_once(self):
Daisuke Nojiri76bed2f2015-10-29 08:58:45 -070089 if self.faft_config.fw_bypasser_type != 'ctrl_d_bypasser':
Tom Wai-Hong Tamab527422015-05-22 07:03:28 +080090 raise error.TestNAError("This test is only valid on devices with "
91 "screens.")
92
Yusuf Mohsinallye580a012014-05-18 19:23:12 -070093 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 Chuangfdcef7b2018-02-26 17:45:43 +0800100 # 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 Mohsinallye580a012014-05-18 19:23:12 -0700104 logging.info("Reboot and press Ctrl-D repeatedly.")
Shelley Chen5ca71482016-12-14 16:48:25 -0800105 self.switcher.simple_reboot()
Yusuf Mohsinallye580a012014-05-18 19:23:12 -0700106 self.ctrl_d_repeatedly()
Tom Wai-Hong Tam19bfb6e2015-08-20 06:05:36 +0800107 self.switcher.wait_for_client()
Yusuf Mohsinallye580a012014-05-18 19:23:12 -0700108
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 Chen5ca71482016-12-14 16:48:25 -0800113 self.switcher.simple_reboot()
Tom Wai-Hong Tam19bfb6e2015-08-20 06:05:36 +0800114 self.switcher.wait_for_client()
Yusuf Mohsinallye580a012014-05-18 19:23:12 -0700115
116 logging.info("Check the firmware screen timeout matches our spec.")
117 self.check_timeout_period()