• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2013 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
6
7from autotest_lib.client.common_lib import error
8from autotest_lib.server.cros import vboot_constants as vboot
9from autotest_lib.server.cros.faft.firmware_test import ConnectionError
10from autotest_lib.server.cros.faft.firmware_test import FirmwareTest
11
12
13class firmware_LegacyRecovery(FirmwareTest):
14    """
15    Servo based test to Verify recovery request at Remove Screen.
16
17    This test requires a USB disk plugged-in, which contains a Chrome OS test
18    image (built by "build_image --test"). It recovery boots to the USB image
19    and sets recovery_request=1 and do a reboot. A failure is expected.
20    """
21    version = 1
22
23    def initialize(self, host, cmdline_args):
24        super(firmware_LegacyRecovery, self).initialize(host, cmdline_args)
25        self.setup_usbkey(usbkey=True, host=False)
26        self.switcher.setup_mode('normal')
27
28    def cleanup(self):
29        super(firmware_LegacyRecovery, self).cleanup()
30
31    def run_once(self):
32        logging.info("Turn on the recovery boot. Enable recovery request "
33                     "and perform a reboot.")
34        self.check_state((self.checkers.crossystem_checker, {
35                           'devsw_boot': '0',
36                           'mainfw_type': 'normal',
37                           }))
38        self.faft_client.system.request_recovery_boot()
39        self.switcher.mode_aware_reboot(wait_for_dut_up=False)
40        self.switcher.bypass_rec_mode()
41        try:
42            self.switcher.wait_for_client()
43        except ConnectionError:
44            raise error.TestError('Failed to boot the USB image.')
45        self.faft_client.system.run_shell_command(
46                                   'crossystem recovery_request=1')
47
48        logging.info("Wait to ensure no recovery boot at remove screen "
49                     "and a boot failure is expected. "
50                     "Unplug and plug USB, try to boot it again.")
51        self.check_state((self.checkers.crossystem_checker, {
52                           'mainfw_type': 'recovery',
53                           }))
54        self.switcher.mode_aware_reboot(wait_for_dut_up=False)
55        logging.info('Wait to ensure DUT doesnt Boot on USB at Remove screen.')
56        try:
57            self.switcher.wait_for_client()
58            raise error.TestFail('Unexpected USB boot at Remove Screen.')
59        except ConnectionError:
60            logging.info('Done, Waited till timeout and no USB boot occured.')
61        self.switcher.bypass_rec_mode()
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['LEGACY'],
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