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 import autotest 10from autotest_lib.server.cros.faft.firmware_test import FirmwareTest 11 12 13class firmware_ECWakeSource(FirmwareTest): 14 """ 15 Servo based EC wake source test. 16 """ 17 version = 1 18 19 def initialize(self, host, cmdline_args): 20 super(firmware_ECWakeSource, self).initialize(host, cmdline_args) 21 # Only run in normal mode 22 self.switcher.setup_mode('normal') 23 24 def cleanup(self): 25 # Restore the lid_open switch in case the test failed in the middle. 26 self.servo.set('lid_open', 'yes') 27 super(firmware_ECWakeSource, self).cleanup() 28 29 def hibernate_and_wake_by_power_button(self): 30 """Shutdown to G2/S5, then hibernate EC. Finally, wake by power button.""" 31 self.faft_client.system.run_shell_command("shutdown -H now") 32 self.switcher.wait_for_client_offline() 33 self.ec.send_command("hibernate 1000") 34 time.sleep(self.WAKE_DELAY) 35 self.servo.power_short_press() 36 37 def run_once(self, host): 38 """Runs a single iteration of the test.""" 39 # TODO(victoryang): make this test run on both x86 and arm 40 if not self.check_ec_capability(['x86', 'lid']): 41 raise error.TestNAError("Nothing needs to be tested on this device") 42 43 # Login as a normal user and stay there, such that closing lid triggers 44 # suspend, instead of shutdown. 45 autotest_client = autotest.Autotest(host) 46 autotest_client.run_test("desktopui_SimpleLogin", 47 exit_without_logout=True) 48 49 original_boot_id = host.get_boot_id() 50 51 logging.info("Suspend and wake by power button.") 52 self.suspend() 53 self.switcher.wait_for_client_offline() 54 self.servo.power_normal_press() 55 self.switcher.wait_for_client() 56 57 logging.info("Suspend and wake by lid switch.") 58 self.suspend() 59 self.switcher.wait_for_client_offline() 60 self.servo.set('lid_open', 'no') 61 time.sleep(self.LID_DELAY) 62 self.servo.set('lid_open', 'yes') 63 self.switcher.wait_for_client() 64 65 logging.info("Close lid to suspend and wake by lid switch.") 66 self.servo.set('lid_open', 'no') 67 # Expect going to suspend, not pingable 68 self.switcher.wait_for_client_offline() 69 time.sleep(self.LID_DELAY) 70 self.servo.set('lid_open', 'yes') 71 self.switcher.wait_for_client() 72 73 boot_id = host.get_boot_id() 74 if boot_id != original_boot_id: 75 raise error.TestFail('Different boot_id. Unexpected reboot.') 76 77 if self.servo.main_device_is_ccd(): 78 logging.info("Using CCD, ignore waking by power button.") 79 else: 80 logging.info("EC hibernate and wake by power button.") 81 self.hibernate_and_wake_by_power_button() 82 self.switcher.wait_for_client() 83