• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2017 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.client.common_lib import utils
10from autotest_lib.server import autotest
11from autotest_lib.server.cros.faft.firmware_test import FirmwareTest
12
13
14class firmware_ConsecutiveLidSwitch(FirmwareTest):
15    """
16    Servo based consecutive lid switch test.
17
18    This test is intended to be run with many iterations to ensure that closing
19    DUT lid triggers suspend and opening lid wakes it up.
20
21    The iteration should be specified by the parameter -a "faft_iterations=10".
22
23    Checking the boot_id ensures DUT won't reboot unexpectedly.
24    """
25    version = 1
26
27
28    def initialize(self, host, cmdline_args):
29        # Parse arguments from command line
30        dict_args = utils.args_to_dict(cmdline_args)
31        self.faft_iterations = int(dict_args.get('faft_iterations', 1))
32        super(firmware_ConsecutiveLidSwitch, self).initialize(host,
33                                                              cmdline_args)
34        self.setup_usbkey(usbkey=False)
35
36
37    def cleanup(self):
38        # Restore the lid_open switch in case the test failed in the middle.
39        try:
40            self.servo.set('lid_open', 'yes')
41        except Exception as e:
42            logging.error("Caught exception: %s", str(e))
43        super(firmware_ConsecutiveLidSwitch, self).cleanup()
44
45
46    def run_once(self, host):
47        # Login as a normal user and stay there. Closing lid at the login
48        # screen may shut the machine down, that also verifies the lid switch
49        # but take more time. Once logged in, closing lid triggers suspend.
50        autotest_client = autotest.Autotest(host)
51        autotest_client.run_test("desktopui_SimpleLogin",
52                                 exit_without_logout=True)
53
54        original_boot_id = host.get_boot_id()
55
56        for i in xrange(self.faft_iterations):
57            logging.info('======== Running FAFT ITERATION %d/%d ========',
58                         i + 1, self.faft_iterations)
59
60            logging.info("Close lid to suspend.")
61            self.servo.set('lid_open', 'no')
62            logging.info("Expected going to suspend. Waiting DUT offline...")
63            self.switcher.wait_for_client_offline()
64            time.sleep(self.LID_DELAY)
65
66            logging.info("Wake DUT by lid switch.")
67            self.servo.set('lid_open', 'yes')
68            logging.info("Expected going to resume. Waiting DUT online...")
69            self.switcher.wait_for_client()
70            time.sleep(self.LID_DELAY)
71
72            boot_id = host.get_boot_id()
73            if boot_id != original_boot_id:
74                raise error.TestFail('Different boot_id. Unexpected reboot.')
75