blob: 23084f2212791fe6d376447042c52467a0b8af15 [file] [log] [blame]
Randy Dunlap56fb9e52006-05-21 20:58:10 -07001/*
2 * Watchdog Driver Test Program
3 */
4
5#include <stdio.h>
6#include <stdlib.h>
7#include <string.h>
8#include <unistd.h>
9#include <fcntl.h>
10#include <sys/ioctl.h>
11#include <linux/types.h>
12#include <linux/watchdog.h>
13
14int fd;
15
16/*
17 * This function simply sends an IOCTL to the driver, which in turn ticks
18 * the PC Watchdog card to reset its internal timer so it doesn't trigger
19 * a computer reset.
20 */
Ladinu Chandrasingheb7ed6982009-09-22 16:43:42 -070021static void keep_alive(void)
Randy Dunlap56fb9e52006-05-21 20:58:10 -070022{
23 int dummy;
24
25 ioctl(fd, WDIOC_KEEPALIVE, &dummy);
26}
27
28/*
29 * The main program. Run the program with "-d" to disable the card,
30 * or "-e" to enable the card.
31 */
32int main(int argc, char *argv[])
33{
James Hogandfc33382010-04-05 11:31:29 +010034 int flags;
35
Randy Dunlap56fb9e52006-05-21 20:58:10 -070036 fd = open("/dev/watchdog", O_WRONLY);
37
38 if (fd == -1) {
39 fprintf(stderr, "Watchdog device not enabled.\n");
40 fflush(stderr);
41 exit(-1);
42 }
43
44 if (argc > 1) {
45 if (!strncasecmp(argv[1], "-d", 2)) {
James Hogandfc33382010-04-05 11:31:29 +010046 flags = WDIOS_DISABLECARD;
47 ioctl(fd, WDIOC_SETOPTIONS, &flags);
Randy Dunlap56fb9e52006-05-21 20:58:10 -070048 fprintf(stderr, "Watchdog card disabled.\n");
49 fflush(stderr);
Devendra Naga3c2a6182012-05-14 23:42:02 +053050 goto end;
Randy Dunlap56fb9e52006-05-21 20:58:10 -070051 } else if (!strncasecmp(argv[1], "-e", 2)) {
James Hogandfc33382010-04-05 11:31:29 +010052 flags = WDIOS_ENABLECARD;
53 ioctl(fd, WDIOC_SETOPTIONS, &flags);
Randy Dunlap56fb9e52006-05-21 20:58:10 -070054 fprintf(stderr, "Watchdog card enabled.\n");
55 fflush(stderr);
Devendra Naga3c2a6182012-05-14 23:42:02 +053056 goto end;
Randy Dunlap56fb9e52006-05-21 20:58:10 -070057 } else {
58 fprintf(stderr, "-d to disable, -e to enable.\n");
59 fprintf(stderr, "run by itself to tick the card.\n");
60 fflush(stderr);
Devendra Naga3c2a6182012-05-14 23:42:02 +053061 goto end;
Randy Dunlap56fb9e52006-05-21 20:58:10 -070062 }
63 } else {
64 fprintf(stderr, "Watchdog Ticking Away!\n");
65 fflush(stderr);
66 }
67
68 while(1) {
69 keep_alive();
70 sleep(1);
71 }
Devendra Naga3c2a6182012-05-14 23:42:02 +053072end:
73 close(fd);
74 return 0;
Randy Dunlap56fb9e52006-05-21 20:58:10 -070075}