xref: /aosp_15_r20/external/autotest/server/site_tests/firmware_ECWatchdog/firmware_ECWatchdog.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
6import time
7
8from autotest_lib.client.common_lib import error
9from autotest_lib.server.cros.faft.firmware_test import FirmwareTest
10
11class firmware_ECWatchdog(FirmwareTest):
12    """
13    Servo based EC watchdog test.
14    """
15    version = 1
16
17
18    # Delay of spin-wait in ms. Nuvoton boards set the hardware watchdog to
19    # 3187.5ms and also sets a timer to 2200ms. Set the timeout long enough to
20    # exceed the hardware watchdog timer because the timer isn't 100% reliable.
21    # If there are other platforms that use a longer watchdog timeout, this
22    # may need to be adjusted.
23    WATCHDOG_DELAY = 3700  # 3187.5ms + 500ms safety margin, rounded up.
24
25    # Delay of EC power on.
26    EC_BOOT_DELAY = 1000
27
28
29    def initialize(self, host, cmdline_args):
30        super(firmware_ECWatchdog, self).initialize(host, cmdline_args)
31        # Only run in normal mode
32        self.switcher.setup_mode('normal')
33
34
35    def reboot_by_watchdog(self):
36        """
37        Trigger a watchdog reset.
38        """
39        self.faft_client.system.run_shell_command("sync")
40        self.ec.send_command("waitms %d" % self.WATCHDOG_DELAY)
41        time.sleep((self.WATCHDOG_DELAY + self.EC_BOOT_DELAY) / 1000.0)
42        self.check_lid_and_power_on()
43
44
45    def run_once(self):
46        """Runs a single iteration of the test."""
47        if not self.check_ec_capability():
48            raise error.TestNAError("Nothing needs to be tested on this device")
49
50        logging.info("Trigger a watchdog reset and power on system again.")
51        self.switcher.mode_aware_reboot('custom', self.reboot_by_watchdog)
52