1 /* watchdog-test framework
2 * Copyright (C) 2014 Red Hat Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include <sys/ioctl.h>
25 #include <linux/watchdog.h>
27 #define WATCHDOG_DEVICE "/dev/watchdog"
28 #define WATCHDOG_TIMEOUT 30
38 setvbuf (stdout, NULL, _IONBF, 0);
41 printf ("Welcome to the watchdog test framework.\n");
42 printf ("You should read the README file and run this in the guest.\n");
43 printf ("DO NOT RUN IT IN THE HOST!\n");
45 printf ("The test is as follows:\n");
46 printf ("(1) I will set up the watchdog with a %d second timeout.\n",
48 printf ("(2) I will ping the watchdog for %d seconds. During this time\n"
49 " the guest should run normally.\n",
50 WATCHDOG_TIMEOUT * 2);
51 printf ("(3) I will stop pinging the watchdog and just count up. If the\n"
52 " virtual watchdog device is set correctly, then the watchdog\n"
53 " action (eg. reboot) should happen around the %d second mark.\n",
56 printf ("Do you want to start the test? Type \"yes\" without quotes:\n");
58 if (fgets (input, sizeof input, stdin) == NULL ||
59 strcmp (input, "yes") != 0) {
60 printf ("Exiting the program.\n");
65 printf ("Setting up the watchdog (%s) with a %d second timeout.\n",
66 WATCHDOG_DEVICE, WATCHDOG_TIMEOUT);
69 fd = open (WATCHDOG_DEVICE, O_WRONLY);
71 perror (WATCHDOG_DEVICE);
75 timeout = WATCHDOG_TIMEOUT;
76 if (ioctl (fd, WDIOC_SETTIMEOUT, &timeout) == -1) {
77 perror ("ioctl: WDIOC_SETTIMEOUT: error setting timeout");
81 if (ioctl (fd, WDIOC_GETTIMEOUT, &timeout) == -1)
82 perror ("ioctl: WDIOC_GETTIMEOUT");
84 printf ("Timeout is set to %d seconds.\n");
85 if (timeout != WATCHDOG_TIMEOUT)
86 printf ("Note: some watchdog devices don't support setting exact timeout values.\n");
90 printf ("Pinging the watchdog for %d seconds ...\n", WATCHDOG_TIMEOUT*2);
96 if (t - start_t > WATCHDOG_TIMEOUT * 2)
98 printf ("%d... ", (int) (t - start_t));
104 if (ioctl (fd, WDIOC_KEEPALIVE, 0) == -1)
105 perror ("ioctl: WDIOC_KEEPALIVE");
110 printf ("Stopping pings.\n");
111 printf ("The watchdog action should happen at around %d mark.\n");
117 printf ("%d... ", (int) (t - start_t));