aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests
diff options
context:
space:
mode:
authorShuah Khan <shuahkh@osg.samsung.com>2016-09-13 15:03:35 -0400
committerShuah Khan <shuahkh@osg.samsung.com>2016-09-20 11:58:34 -0400
commit02a35aad8a3e0b2bde1986053cefc2fcd63aee5d (patch)
treea06f839bc7e20151e1efef5765c7db5d1000e8e7 /tools/testing/selftests
parentb6ebbac51bedf9e98e837688bc838f400196da5e (diff)
selftests: move watchdog tests from Documentation/watchdog
Remove watchdog-test from Makefile to move the test to selftests. Add Makefile and .gitignore for watchdog-test. watchdog-test will not be run as part of selftests suite and will not be included in install targets. It can be built separately for now. Acked-by: Jonathan Corbet <corbet@lwn.net> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
Diffstat (limited to 'tools/testing/selftests')
-rw-r--r--tools/testing/selftests/watchdog/.gitignore1
-rw-r--r--tools/testing/selftests/watchdog/Makefile8
-rw-r--r--tools/testing/selftests/watchdog/watchdog-test.c105
3 files changed, 114 insertions, 0 deletions
diff --git a/tools/testing/selftests/watchdog/.gitignore b/tools/testing/selftests/watchdog/.gitignore
new file mode 100644
index 000000000000..5aac51575c7e
--- /dev/null
+++ b/tools/testing/selftests/watchdog/.gitignore
@@ -0,0 +1 @@
watchdog-test
diff --git a/tools/testing/selftests/watchdog/Makefile b/tools/testing/selftests/watchdog/Makefile
new file mode 100644
index 000000000000..f863c664e3d1
--- /dev/null
+++ b/tools/testing/selftests/watchdog/Makefile
@@ -0,0 +1,8 @@
1TEST_PROGS := watchdog-test
2
3all: $(TEST_PROGS)
4
5include ../lib.mk
6
7clean:
8 rm -fr $(TEST_PROGS)
diff --git a/tools/testing/selftests/watchdog/watchdog-test.c b/tools/testing/selftests/watchdog/watchdog-test.c
new file mode 100644
index 000000000000..6983d05097e2
--- /dev/null
+++ b/tools/testing/selftests/watchdog/watchdog-test.c
@@ -0,0 +1,105 @@
1/*
2 * Watchdog Driver Test Program
3 */
4
5#include <errno.h>
6#include <stdio.h>
7#include <stdlib.h>
8#include <string.h>
9#include <unistd.h>
10#include <fcntl.h>
11#include <signal.h>
12#include <sys/ioctl.h>
13#include <linux/types.h>
14#include <linux/watchdog.h>
15
16int fd;
17const char v = 'V';
18
19/*
20 * This function simply sends an IOCTL to the driver, which in turn ticks
21 * the PC Watchdog card to reset its internal timer so it doesn't trigger
22 * a computer reset.
23 */
24static void keep_alive(void)
25{
26 int dummy;
27
28 printf(".");
29 ioctl(fd, WDIOC_KEEPALIVE, &dummy);
30}
31
32/*
33 * The main program. Run the program with "-d" to disable the card,
34 * or "-e" to enable the card.
35 */
36
37static void term(int sig)
38{
39 int ret = write(fd, &v, 1);
40
41 close(fd);
42 if (ret < 0)
43 printf("\nStopping watchdog ticks failed (%d)...\n", errno);
44 else
45 printf("\nStopping watchdog ticks...\n");
46 exit(0);
47}
48
49int main(int argc, char *argv[])
50{
51 int flags;
52 unsigned int ping_rate = 1;
53 int ret;
54
55 setbuf(stdout, NULL);
56
57 fd = open("/dev/watchdog", O_WRONLY);
58
59 if (fd == -1) {
60 printf("Watchdog device not enabled.\n");
61 exit(-1);
62 }
63
64 if (argc > 1) {
65 if (!strncasecmp(argv[1], "-d", 2)) {
66 flags = WDIOS_DISABLECARD;
67 ioctl(fd, WDIOC_SETOPTIONS, &flags);
68 printf("Watchdog card disabled.\n");
69 goto end;
70 } else if (!strncasecmp(argv[1], "-e", 2)) {
71 flags = WDIOS_ENABLECARD;
72 ioctl(fd, WDIOC_SETOPTIONS, &flags);
73 printf("Watchdog card enabled.\n");
74 goto end;
75 } else if (!strncasecmp(argv[1], "-t", 2) && argv[2]) {
76 flags = atoi(argv[2]);
77 ioctl(fd, WDIOC_SETTIMEOUT, &flags);
78 printf("Watchdog timeout set to %u seconds.\n", flags);
79 goto end;
80 } else if (!strncasecmp(argv[1], "-p", 2) && argv[2]) {
81 ping_rate = strtoul(argv[2], NULL, 0);
82 printf("Watchdog ping rate set to %u seconds.\n", ping_rate);
83 } else {
84 printf("-d to disable, -e to enable, -t <n> to set " \
85 "the timeout,\n-p <n> to set the ping rate, and \n");
86 printf("run by itself to tick the card.\n");
87 goto end;
88 }
89 }
90
91 printf("Watchdog Ticking Away!\n");
92
93 signal(SIGINT, term);
94
95 while(1) {
96 keep_alive();
97 sleep(ping_rate);
98 }
99end:
100 ret = write(fd, &v, 1);
101 if (ret < 0)
102 printf("Stopping watchdog ticks failed (%d)...\n", errno);
103 close(fd);
104 return 0;
105}