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