]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/test/test-watchdog.c
Merge pull request #10293 from poettering/cryptsetup-fixes
[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
e96d6be7 6#include "log.h"
0cf29baa 7#include "tests.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 15
6d7c4033 16 test_setup_logging(LOG_DEBUG);
e96d6be7 17
0cf29baa 18 slow = slow_tests_enabled();
da1e72f4
ZJS
19
20 t = slow ? 10 * USEC_PER_SEC : 1 * USEC_PER_SEC;
21 count = slow ? 5 : 3;
22
e96d6be7
LP
23 r = watchdog_set_timeout(&t);
24 if (r < 0)
da927ba9 25 log_warning_errno(r, "Failed to open watchdog: %m");
da1e72f4
ZJS
26 if (r == -EPERM)
27 t = 0;
e96d6be7 28
da1e72f4 29 for (i = 0; i < count; i++) {
e96d6be7
LP
30 log_info("Pinging...");
31 r = watchdog_ping();
32 if (r < 0)
da927ba9 33 log_warning_errno(r, "Failed to ping watchdog: %m");
e96d6be7
LP
34
35 usleep(t/2);
36 }
37
38 watchdog_close(true);
39 return 0;
40}