]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/test/test-watchdog.c
tree-wide: remove Lennart's copyright lines
[thirdparty/systemd.git] / src / test / test-watchdog.c
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
e96d6be7 2
dccca82b 3#include <string.h>
e96d6be7 4#include <unistd.h>
e96d6be7 5
da1e72f4 6#include "env-util.h"
e96d6be7 7#include "log.h"
cf0fbc49 8#include "watchdog.h"
e96d6be7
LP
9
10int main(int argc, char *argv[]) {
da1e72f4
ZJS
11 usec_t t;
12 unsigned i, count;
e96d6be7 13 int r;
da1e72f4 14 bool slow;
e96d6be7
LP
15
16 log_set_max_level(LOG_DEBUG);
17 log_parse_environment();
18
da1e72f4
ZJS
19 r = getenv_bool("SYSTEMD_SLOW_TESTS");
20 slow = r >= 0 ? r : SYSTEMD_SLOW_TESTS_DEFAULT;
21
22 t = slow ? 10 * USEC_PER_SEC : 1 * USEC_PER_SEC;
23 count = slow ? 5 : 3;
24
e96d6be7
LP
25 r = watchdog_set_timeout(&t);
26 if (r < 0)
da927ba9 27 log_warning_errno(r, "Failed to open watchdog: %m");
da1e72f4
ZJS
28 if (r == -EPERM)
29 t = 0;
e96d6be7 30
da1e72f4 31 for (i = 0; i < count; i++) {
e96d6be7
LP
32 log_info("Pinging...");
33 r = watchdog_ping();
34 if (r < 0)
da927ba9 35 log_warning_errno(r, "Failed to ping watchdog: %m");
e96d6be7
LP
36
37 usleep(t/2);
38 }
39
40 watchdog_close(true);
41 return 0;
42}