1# Copyright (c) 2012 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.faft.firmware_test import FirmwareTest
10
11
12class firmware_ECWakeSource(FirmwareTest):
13    """
14    Servo based EC wake source test.
15    """
16    version = 1
17
18    # Delay for waiting client to shut down
19    SHUTDOWN_DELAY = 10
20
21    def initialize(self, host, cmdline_args):
22        super(firmware_ECWakeSource, self).initialize(host, cmdline_args)
23        # Only run in normal mode
24        self.switcher.setup_mode('normal')
25
26    def hibernate_and_wake_by_power_button(self):
27        """Shutdown to G2/S5, then hibernate EC. Finally, wake by power button."""
28        self.faft_client.system.run_shell_command("shutdown -H now")
29        time.sleep(self.SHUTDOWN_DELAY)
30        self.switcher.wait_for_client_offline()
31        self.ec.send_command("hibernate 1000")
32        time.sleep(self.WAKE_DELAY)
33        self.servo.power_short_press()
34
35    def run_once(self):
36        # TODO(victoryang): make this test run on both x86 and arm
37        if not self.check_ec_capability(['x86', 'lid']):
38            raise error.TestNAError("Nothing needs to be tested on this device")
39
40        logging.info("Suspend and wake by power button.")
41        self.suspend()
42        self.switcher.wait_for_client_offline()
43        self.servo.power_normal_press()
44        self.switcher.wait_for_client()
45
46        logging.info("Suspend and wake by lid switch.")
47        self.suspend()
48        self.switcher.wait_for_client_offline()
49        self.servo.set('lid_open', 'no')
50        time.sleep(self.LID_DELAY)
51        self.servo.set('lid_open', 'yes')
52        self.switcher.wait_for_client()
53
54        logging.info("EC hibernate and wake by power button.")
55        self.hibernate_and_wake_by_power_button()
56        self.switcher.wait_for_client()
57