• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2015 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
9from autotest_lib.server.cros import vboot_constants as vboot
10from autotest_lib.server.cros.faft.firmware_test import FirmwareTest
11from autotest_lib.server.cros.faft.utils import mode_switcher
12
13class firmware_ECLidShutdown(FirmwareTest):
14    """
15    Testing GBB_FLAG_DISABLE_LID_SHUTDOWN flag
16    """
17    version = 1
18
19    # Delay between closing and opening the lid
20    LID_DELAY = 2
21    # time to wait before checking if DUT booted into OS mode
22    BOOTUP_TIME = 30
23    # # times to check if DUT in expected power state
24    # This accomodates if DUT needs to transition into certain states.
25    PWR_RETRIES = 13
26
27    def initialize(self, host, cmdline_args):
28        super(firmware_ECLidShutdown, self).initialize(host, cmdline_args)
29        self.setup_usbkey(usbkey=False)
30
31    def cleanup(self):
32        """If DUT not pingable, may be still stuck in recovery mode.
33        Reboot it.  Also, reset GBB_FLAGS and make sure that lid set
34        to open (in case of error).
35        """
36        # reset ec_uart_regexp to prevent timeouts in case there was
37        # an error before we could reset it
38        self._reset_ec_regexp()
39        if self.servo.get('lid_open') == 'no':
40            self.servo.set('lid_open', 'yes')
41        self.clear_set_gbb_flags(vboot.GBB_FLAG_DISABLE_LID_SHUTDOWN,
42                                 0)
43        try:
44            self.switcher.wait_for_client()
45        except ConnectionError:
46            logging.error("ERROR: client not in OS mode.  Rebooting ...")
47            # reboot back to OS mode
48            self.switcher.mode_aware_reboot(reboot_type='cold',
49                                            sync_before_boot=False)
50        super(firmware_ECLidShutdown, self).cleanup()
51
52    def _reset_ec_regexp(self):
53        """Reset ec_uart_regexp field
54
55        Needs to be done for the ec_uart_regexp otherwise
56        dut-control command will time out due to no match.
57        """
58        self.servo.set('ec_uart_regexp', 'None')
59
60    def verify_lid_shutdown(self):
61        """
62        Make sure that firmware boots into OS with lid closed
63        """
64        self.clear_set_gbb_flags(vboot.GBB_FLAG_DISABLE_LID_SHUTDOWN,
65                                 0)
66        # reboot into recovery mode and wait a bit for it to actually get there
67        self.faft_client.system.request_recovery_boot()
68        self.switcher.simple_reboot()
69        time.sleep(self.faft_config.firmware_screen)
70
71        # close/open lid
72        self.servo.set('lid_open', 'no')
73        time.sleep(self.LID_DELAY)
74        if not self.wait_power_state("G3", self.PWR_RETRIES):
75            logging.error("ERROR: EC does not shut down")
76            return False
77        self.servo.set('lid_open', 'yes')
78
79        # ping DUT - should boot into OS now
80        self._reset_ec_regexp()
81        self.switcher.wait_for_client()
82
83        return True
84
85    def check_disable_lid_shutdown(self):
86        """
87        Set flag to disable shutdown of DUT when lid closed.  Then check
88        if DUT shuts down during recovery mode screen.
89        """
90        # enable shutdown flag
91        self.clear_set_gbb_flags(0,
92                                 vboot.GBB_FLAG_DISABLE_LID_SHUTDOWN)
93        # reboot into recovery mode and wait a bit for it to get there
94        self.faft_client.system.request_recovery_boot()
95        self.switcher.simple_reboot()
96        time.sleep(self.faft_config.firmware_screen)
97
98        # close/open the lid
99        self.servo.set('lid_open', 'no')
100        time.sleep(self.LID_DELAY)
101        if not self.wait_power_state("S0", self.PWR_RETRIES):
102            logging.error("ERROR: EC shuts down")
103            return False
104        self.servo.set('lid_open', 'yes')
105
106        # this should be more than enough time for system to boot up
107        # if it was going to.
108        time.sleep(self.BOOTUP_TIME)
109
110        # should still be offline
111        self.switcher.wait_for_client_offline()
112
113        # reboot back to OS mode
114        self.switcher.mode_aware_reboot(reboot_type='cold',
115                                        sync_before_boot=False)
116
117        # disable flag
118        self._reset_ec_regexp()
119        return True
120
121
122    def run_once(self):
123        if not self.check_ec_capability(['lid']):
124            raise error.TestNAError("This device needs a lid to run this test")
125
126        logging.info("Verify DUT with DISABLE_LID_SHUTDOWN disabled")
127        self.check_state(self.verify_lid_shutdown)
128
129        logging.info("Verify DUT with DISABLE_LID_SHUTDOWN enabled")
130        self.check_state(self.check_disable_lid_shutdown)
131
132