| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
|
| 3 |
#include "log.h" |
| 4 |
#include "tests.h" |
| 5 |
#include "time-util.h" |
| 6 |
#include "watchdog.h" |
| 7 |
|
| 8 |
int main(int argc, char *argv[]) { |
| 9 |
int r; |
| 10 |
|
| 11 |
test_setup_logging(LOG_DEBUG); |
| 12 |
|
| 13 |
bool slow = slow_tests_enabled(); |
| 14 |
|
| 15 |
usec_t timeout = slow ? 10 * USEC_PER_SEC : 2 * USEC_PER_SEC; |
| 16 |
unsigned count = slow ? 5 : 3; |
| 17 |
|
| 18 |
log_info("Initializing watchdog with timeout of %s", FORMAT_TIMESPAN(timeout, USEC_PER_SEC)); |
| 19 |
r = watchdog_setup(timeout); |
| 20 |
if (r < 0) |
| 21 |
log_warning_errno(r, "Failed to open watchdog: %m"); |
| 22 |
|
| 23 |
for (unsigned i = 0; i < count; i++) { |
| 24 |
timeout = watchdog_runtime_wait(/* divisor= */ 2); |
| 25 |
log_info("Sleeping %s…", FORMAT_TIMESPAN(timeout, USEC_PER_SEC)); |
| 26 |
usleep_safe(timeout); |
| 27 |
log_info("Pinging..."); |
| 28 |
r = watchdog_ping(); |
| 29 |
if (r < 0) |
| 30 |
log_warning_errno(r, "Failed to ping watchdog: %m"); |
| 31 |
} |
| 32 |
|
| 33 |
watchdog_close(/* disarm= */ true); |
| 34 |
return 0; |
| 35 |
} |