Skip to content

Commit 0be54f6

Browse files
committed
Add test_linux_watchdog: Test if the watchdog resets the device
Signed-off-by: Chris Fiege <[email protected]>
1 parent 28cd0b8 commit 0be54f6

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

tests/test_linux_hardware.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import json
22

3+
from pexpect import TIMEOUT
4+
35

46
def test_linux_i2c_bus_0_eeprom(shell):
57
"""
@@ -80,3 +82,35 @@ def test_sensors(shell, record_property):
8082
assert "cpu_thermal-virtual-0" in data
8183
record_property("cpu_thermal-virtual-0", data["cpu_thermal-virtual-0"]["temp1"]["temp1_input"])
8284
assert 10 <= data["cpu_thermal-virtual-0"]["temp1"]["temp1_input"] <= 70
85+
86+
87+
def test_linux_watchdog(strategy):
88+
"""
89+
Check if the system reboots, if we stop feeding the watchdog.
90+
91+
The watchdog is handled by systemd, so stopping systemd should reboot the DUT.
92+
"""
93+
94+
try:
95+
strategy.target.deactivate(strategy.shell)
96+
97+
# systemd should be feeding the watchdog. let's kill systemd and wait for the watchdog to reset the DUT.
98+
strategy.console.write(b"kill -11 1\n") # This command will not return, so we can not use shell.run()
99+
100+
# Wait for barebox to boot. Reset reason must be "Watchdog"
101+
index, _, _, _ = strategy.console.expect(
102+
["STM32 RCC reset reason WDG", TIMEOUT],
103+
timeout=30,
104+
)
105+
if index != 0:
106+
raise Exception("Device failed to reboot in time.")
107+
strategy.target.activate(strategy.barebox)
108+
strategy.barebox.run_check("global linux.bootargs.loglevel=loglevel=6")
109+
strategy.barebox.boot("")
110+
strategy.barebox.await_boot()
111+
strategy.target.activate(strategy.shell)
112+
except Exception as e:
113+
# With any exception happening in this test we must assume that the device state is tainted.
114+
# Let's switch it off, so the strategy can reboot the device into a clean state
115+
strategy.transition(Status.off)
116+
raise e

0 commit comments

Comments
 (0)