Commit 1dbdcc81 authored by Timur Tabi's avatar Timur Tabi Committed by Shuah Khan

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: default avatarTimur Tabi <timur@codeaurora.org>
Reviewed-by: default avatarGuenter Roeck <linux@roeck-us.net>
Signed-off-by: default avatarShuah Khan <shuahkh@osg.samsung.com>
parent 83896c68
...@@ -24,9 +24,11 @@ const char v = 'V'; ...@@ -24,9 +24,11 @@ const char v = 'V';
static void keep_alive(void) static void keep_alive(void)
{ {
int dummy; int dummy;
int ret;
ret = ioctl(fd, WDIOC_KEEPALIVE, &dummy);
if (!ret)
printf("."); printf(".");
ioctl(fd, WDIOC_KEEPALIVE, &dummy);
} }
/* /*
...@@ -51,6 +53,7 @@ int main(int argc, char *argv[]) ...@@ -51,6 +53,7 @@ int main(int argc, char *argv[])
int flags; int flags;
unsigned int ping_rate = 1; unsigned int ping_rate = 1;
int ret; int ret;
int i;
setbuf(stdout, NULL); setbuf(stdout, NULL);
...@@ -61,29 +64,33 @@ int main(int argc, char *argv[]) ...@@ -61,29 +64,33 @@ int main(int argc, char *argv[])
exit(-1); exit(-1);
} }
if (argc > 1) { for (i = 1; i < argc; i++) {
if (!strncasecmp(argv[1], "-d", 2)) { if (!strncasecmp(argv[i], "-d", 2)) {
flags = WDIOS_DISABLECARD; flags = WDIOS_DISABLECARD;
ioctl(fd, WDIOC_SETOPTIONS, &flags); ret = ioctl(fd, WDIOC_SETOPTIONS, &flags);
if (!ret)
printf("Watchdog card disabled.\n"); printf("Watchdog card disabled.\n");
goto end; } else if (!strncasecmp(argv[i], "-e", 2)) {
} else if (!strncasecmp(argv[1], "-e", 2)) {
flags = WDIOS_ENABLECARD; flags = WDIOS_ENABLECARD;
ioctl(fd, WDIOC_SETOPTIONS, &flags); ret = ioctl(fd, WDIOC_SETOPTIONS, &flags);
if (!ret)
printf("Watchdog card enabled.\n"); printf("Watchdog card enabled.\n");
goto end; } else if (!strncasecmp(argv[i], "-t", 2) && argv[2]) {
} else if (!strncasecmp(argv[1], "-t", 2) && argv[2]) { flags = atoi(argv[i + 1]);
flags = atoi(argv[2]); ret = ioctl(fd, WDIOC_SETTIMEOUT, &flags);
ioctl(fd, WDIOC_SETTIMEOUT, &flags); if (!ret)
printf("Watchdog timeout set to %u seconds.\n", flags); printf("Watchdog timeout set to %u seconds.\n", flags);
goto end; i++;
} else if (!strncasecmp(argv[1], "-p", 2) && argv[2]) { } else if (!strncasecmp(argv[i], "-p", 2) && argv[2]) {
ping_rate = strtoul(argv[2], NULL, 0); ping_rate = strtoul(argv[i + 1], NULL, 0);
printf("Watchdog ping rate set to %u seconds.\n", ping_rate); printf("Watchdog ping rate set to %u seconds.\n", ping_rate);
i++;
} else { } else {
printf("-d to disable, -e to enable, -t <n> to set " \ printf("-d to disable, -e to enable, -t <n> to set "
"the timeout,\n-p <n> to set the ping rate, and \n"); "the timeout,\n-p <n> to set the ping rate, and ");
printf("run by itself to tick the card.\n"); printf("run by itself to tick the card.\n");
printf("Parameters are parsed left-to-right in real-time.\n");
printf("Example: %s -d -t 10 -p 5 -e\n", argv[0]);
goto end; goto end;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment