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