aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorTimur Tabi <timur@codeaurora.org>2017-05-01 15:23:04 -0400
committerShuah Khan <shuahkh@osg.samsung.com>2017-05-02 12:48:24 -0400
commit1dbdcc810928a2c1acdd0bbfce9495f63610a0d1 (patch)
tree419b5df1eaed107760cf7eae51d4dc71b0d618c9 /tools
parent83896c68fd32895ba4ff685c4df9d1e794dfb4fe (diff)
selftests: watchdog: accept multiple params on command line
Watchdog drivers are not required to retain programming information, such as timeouts, after the watchdog device is closed. Therefore, the watchdog test should be able to perform multiple actions after opening the watchdog device. For example, to set the timeout to 10s and ping every 5s: watchdog-test -t 10 -p 5 -e Also, display the periodic decimal point only if the keep-alive call succeeds. Signed-off-by: Timur Tabi <timur@codeaurora.org> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/testing/selftests/watchdog/watchdog-test.c61
1 files changed, 34 insertions, 27 deletions
diff --git a/tools/testing/selftests/watchdog/watchdog-test.c b/tools/testing/selftests/watchdog/watchdog-test.c
index 6983d05097e2..a74c9d739d07 100644
--- a/tools/testing/selftests/watchdog/watchdog-test.c
+++ b/tools/testing/selftests/watchdog/watchdog-test.c
@@ -24,9 +24,11 @@ const char v = 'V';
24static void keep_alive(void) 24static void keep_alive(void)
25{ 25{
26 int dummy; 26 int dummy;
27 int ret;
27 28
28 printf("."); 29 ret = ioctl(fd, WDIOC_KEEPALIVE, &dummy);
29 ioctl(fd, WDIOC_KEEPALIVE, &dummy); 30 if (!ret)
31 printf(".");
30} 32}
31 33
32/* 34/*
@@ -51,6 +53,7 @@ int main(int argc, char *argv[])
51 int flags; 53 int flags;
52 unsigned int ping_rate = 1; 54 unsigned int ping_rate = 1;
53 int ret; 55 int ret;
56 int i;
54 57
55 setbuf(stdout, NULL); 58 setbuf(stdout, NULL);
56 59
@@ -61,31 +64,35 @@ int main(int argc, char *argv[])
61 exit(-1); 64 exit(-1);
62 } 65 }
63 66
64 if (argc > 1) { 67 for (i = 1; i < argc; i++) {
65 if (!strncasecmp(argv[1], "-d", 2)) { 68 if (!strncasecmp(argv[i], "-d", 2)) {
66 flags = WDIOS_DISABLECARD; 69 flags = WDIOS_DISABLECARD;
67 ioctl(fd, WDIOC_SETOPTIONS, &flags); 70 ret = ioctl(fd, WDIOC_SETOPTIONS, &flags);
68 printf("Watchdog card disabled.\n"); 71 if (!ret)
69 goto end; 72 printf("Watchdog card disabled.\n");
70 } else if (!strncasecmp(argv[1], "-e", 2)) { 73 } else if (!strncasecmp(argv[i], "-e", 2)) {
71 flags = WDIOS_ENABLECARD; 74 flags = WDIOS_ENABLECARD;
72 ioctl(fd, WDIOC_SETOPTIONS, &flags); 75 ret = ioctl(fd, WDIOC_SETOPTIONS, &flags);
73 printf("Watchdog card enabled.\n"); 76 if (!ret)
74 goto end; 77 printf("Watchdog card enabled.\n");
75 } else if (!strncasecmp(argv[1], "-t", 2) && argv[2]) { 78 } else if (!strncasecmp(argv[i], "-t", 2) && argv[2]) {
76 flags = atoi(argv[2]); 79 flags = atoi(argv[i + 1]);
77 ioctl(fd, WDIOC_SETTIMEOUT, &flags); 80 ret = ioctl(fd, WDIOC_SETTIMEOUT, &flags);
78 printf("Watchdog timeout set to %u seconds.\n", flags); 81 if (!ret)
79 goto end; 82 printf("Watchdog timeout set to %u seconds.\n", flags);
80 } else if (!strncasecmp(argv[1], "-p", 2) && argv[2]) { 83 i++;
81 ping_rate = strtoul(argv[2], NULL, 0); 84 } else if (!strncasecmp(argv[i], "-p", 2) && argv[2]) {
82 printf("Watchdog ping rate set to %u seconds.\n", ping_rate); 85 ping_rate = strtoul(argv[i + 1], NULL, 0);
83 } else { 86 printf("Watchdog ping rate set to %u seconds.\n", ping_rate);
84 printf("-d to disable, -e to enable, -t <n> to set " \ 87 i++;
85 "the timeout,\n-p <n> to set the ping rate, and \n"); 88 } else {
86 printf("run by itself to tick the card.\n"); 89 printf("-d to disable, -e to enable, -t <n> to set "
87 goto end; 90 "the timeout,\n-p <n> to set the ping rate, and ");
88 } 91 printf("run by itself to tick the card.\n");
92 printf("Parameters are parsed left-to-right in real-time.\n");
93 printf("Example: %s -d -t 10 -p 5 -e\n", argv[0]);
94 goto end;
95 }
89 } 96 }
90 97
91 printf("Watchdog Ticking Away!\n"); 98 printf("Watchdog Ticking Away!\n");