]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-watchdog.c
Merge pull request #17549 from yuwata/tiny-fixes
[thirdparty/systemd.git] / src / test / test-watchdog.c
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3 #include <string.h>
4 #include <unistd.h>
5
6 #include "log.h"
7 #include "tests.h"
8 #include "watchdog.h"
9
10 int main(int argc, char *argv[]) {
11 usec_t t;
12 unsigned i, count;
13 int r;
14 bool slow;
15
16 test_setup_logging(LOG_DEBUG);
17
18 slow = slow_tests_enabled();
19
20 t = slow ? 10 * USEC_PER_SEC : 1 * USEC_PER_SEC;
21 count = slow ? 5 : 3;
22
23 r = watchdog_set_timeout(&t);
24 if (r < 0)
25 log_warning_errno(r, "Failed to open watchdog: %m");
26 if (r == -EPERM)
27 t = 0;
28
29 for (i = 0; i < count; i++) {
30 log_info("Pinging...");
31 r = watchdog_ping();
32 if (r < 0)
33 log_warning_errno(r, "Failed to ping watchdog: %m");
34
35 usleep(t/2);
36 }
37
38 watchdog_close(true);
39 return 0;
40 }