]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-watchdog.c
Merge pull request #8417 from brauner/2018-03-09/add_bind_mount_fallback_to_private_d...
[thirdparty/systemd.git] / src / test / test-watchdog.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 /***
3 This file is part of systemd.
4
5 Copyright 2012 Lennart Poettering
6 ***/
7
8 #include <string.h>
9 #include <unistd.h>
10
11 #include "env-util.h"
12 #include "log.h"
13 #include "watchdog.h"
14
15 int main(int argc, char *argv[]) {
16 usec_t t;
17 unsigned i, count;
18 int r;
19 bool slow;
20
21 log_set_max_level(LOG_DEBUG);
22 log_parse_environment();
23
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
30 r = watchdog_set_timeout(&t);
31 if (r < 0)
32 log_warning_errno(r, "Failed to open watchdog: %m");
33 if (r == -EPERM)
34 t = 0;
35
36 for (i = 0; i < count; i++) {
37 log_info("Pinging...");
38 r = watchdog_ping();
39 if (r < 0)
40 log_warning_errno(r, "Failed to ping watchdog: %m");
41
42 usleep(t/2);
43 }
44
45 watchdog_close(true);
46 return 0;
47 }