xref: /aosp_15_r20/external/autotest/server/site_tests/firmware_ECPowerG3/firmware_ECPowerG3.py (revision 9c5db1993ded3edbeafc8092d69fe5de2ee02df7)
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
6
7from autotest_lib.client.common_lib import error
8from autotest_lib.server.cros.faft.firmware_test import FirmwareTest
9
10
11class firmware_ECPowerG3(FirmwareTest):
12    """
13    Servo based EC X86 power G3 drop test.
14    """
15    version = 1
16
17    # Time out range for waiting system drop into G3.
18    G3_RETRIES = 13
19
20    # Record failure event
21    _failed = False
22
23    def initialize(self, host, cmdline_args):
24        super(firmware_ECPowerG3, self).initialize(host, cmdline_args)
25        # Don't bother if there is no Chrome EC.
26        if not self.check_ec_capability():
27            raise error.TestNAError("Nothing needs to be tested on this device")
28        # Only run in normal mode
29        self.switcher.setup_mode('normal')
30        self.ec.send_command("chan 0")
31
32    def cleanup(self):
33        try:
34            self.ec.send_command("chan 0xffffffff")
35        except Exception as e:
36            logging.error("Caught exception: %s", str(e))
37        super(firmware_ECPowerG3, self).cleanup()
38
39    def check_G3(self):
40        """Shutdown the system and check if X86 drop into G3 correctly."""
41        self.run_shutdown_cmd()
42        if not self.wait_power_state(self.POWER_STATE_G3, self.G3_RETRIES):
43            logging.error("EC fails to drop into G3")
44            self._failed = True
45        self.servo.power_short_press()
46
47    def check_failure(self):
48        """Check whether any failure has occurred."""
49        return not self._failed
50
51    def run_once(self):
52        """Execute the main body of the test.
53        """
54        if not self.check_ec_capability(['x86']):
55            raise error.TestNAError("Nothing needs to be tested on this device")
56
57        logging.info("Power off and check if system drop into G3 correctly.")
58        self.switcher.mode_aware_reboot('custom', self.check_G3)
59
60        logging.info("Check if failure occurred.")
61        self.check_state(self.check_failure)
62