Skip to content

Commit 1dbdcc8

Browse files
Timur TabiShuah Khan
authored andcommitted
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>
1 parent 83896c6 commit 1dbdcc8

File tree

1 file changed

+34
-27
lines changed

1 file changed

+34
-27
lines changed

tools/testing/selftests/watchdog/watchdog-test.c

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ const char v = 'V';
2424
static void keep_alive(void)
2525
{
2626
int dummy;
27+
int ret;
2728

28-
printf(".");
29-
ioctl(fd, WDIOC_KEEPALIVE, &dummy);
29+
ret = ioctl(fd, WDIOC_KEEPALIVE, &dummy);
30+
if (!ret)
31+
printf(".");
3032
}
3133

3234
/*
@@ -51,6 +53,7 @@ int main(int argc, char *argv[])
5153
int flags;
5254
unsigned int ping_rate = 1;
5355
int ret;
56+
int i;
5457

5558
setbuf(stdout, NULL);
5659

@@ -61,31 +64,35 @@ int main(int argc, char *argv[])
6164
exit(-1);
6265
}
6366

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-
}
67+
for (i = 1; i < argc; i++) {
68+
if (!strncasecmp(argv[i], "-d", 2)) {
69+
flags = WDIOS_DISABLECARD;
70+
ret = ioctl(fd, WDIOC_SETOPTIONS, &flags);
71+
if (!ret)
72+
printf("Watchdog card disabled.\n");
73+
} else if (!strncasecmp(argv[i], "-e", 2)) {
74+
flags = WDIOS_ENABLECARD;
75+
ret = ioctl(fd, WDIOC_SETOPTIONS, &flags);
76+
if (!ret)
77+
printf("Watchdog card enabled.\n");
78+
} else if (!strncasecmp(argv[i], "-t", 2) && argv[2]) {
79+
flags = atoi(argv[i + 1]);
80+
ret = ioctl(fd, WDIOC_SETTIMEOUT, &flags);
81+
if (!ret)
82+
printf("Watchdog timeout set to %u seconds.\n", flags);
83+
i++;
84+
} else if (!strncasecmp(argv[i], "-p", 2) && argv[2]) {
85+
ping_rate = strtoul(argv[i + 1], NULL, 0);
86+
printf("Watchdog ping rate set to %u seconds.\n", ping_rate);
87+
i++;
88+
} else {
89+
printf("-d to disable, -e to enable, -t <n> to set "
90+
"the timeout,\n-p <n> to set the ping rate, and ");
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+
}
8996
}
9097

9198
printf("Watchdog Ticking Away!\n");

0 commit comments

Comments
 (0)