Skip to content

Commit a4864a3

Browse files
George G. Davisshuahkh
authored andcommitted
selftests: watchdog: Add optional file argument
Some systems have multiple watchdog devices where the first device registered is assigned to the /dev/watchdog device file. In order to test other watchdog devices, add an optional file argument for selecting non-default watchdog devices for testing. Tested-by: Eugeniu Rosca <[email protected]> Signed-off-by: George G. Davis <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent 8828229 commit a4864a3

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
int fd;
2121
const char v = 'V';
22-
static const char sopts[] = "bdehp:t:Tn:NL";
22+
static const char sopts[] = "bdehp:t:Tn:NLf:";
2323
static const struct option lopts[] = {
2424
{"bootstatus", no_argument, NULL, 'b'},
2525
{"disable", no_argument, NULL, 'd'},
@@ -31,6 +31,7 @@ static const struct option lopts[] = {
3131
{"pretimeout", required_argument, NULL, 'n'},
3232
{"getpretimeout", no_argument, NULL, 'N'},
3333
{"gettimeleft", no_argument, NULL, 'L'},
34+
{"file", required_argument, NULL, 'f'},
3435
{NULL, no_argument, NULL, 0x0}
3536
};
3637

@@ -69,6 +70,8 @@ static void term(int sig)
6970
static void usage(char *progname)
7071
{
7172
printf("Usage: %s [options]\n", progname);
73+
printf(" -f, --file Open watchdog device file\n");
74+
printf(" Default is /dev/watchdog\n");
7275
printf(" -b, --bootstatus Get last boot status (Watchdog/POR)\n");
7376
printf(" -d, --disable Turn off the watchdog timer\n");
7477
printf(" -e, --enable Turn on the watchdog timer\n");
@@ -92,14 +95,20 @@ int main(int argc, char *argv[])
9295
int ret;
9396
int c;
9497
int oneshot = 0;
98+
char *file = "/dev/watchdog";
9599

96100
setbuf(stdout, NULL);
97101

98-
fd = open("/dev/watchdog", O_WRONLY);
102+
while ((c = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) {
103+
if (c == 'f')
104+
file = optarg;
105+
}
106+
107+
fd = open(file, O_WRONLY);
99108

100109
if (fd == -1) {
101110
if (errno == ENOENT)
102-
printf("Watchdog device not enabled.\n");
111+
printf("Watchdog device (%s) not found.\n", file);
103112
else if (errno == EACCES)
104113
printf("Run watchdog as root.\n");
105114
else
@@ -108,6 +117,8 @@ int main(int argc, char *argv[])
108117
exit(-1);
109118
}
110119

120+
optind = 0;
121+
111122
while ((c = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) {
112123
switch (c) {
113124
case 'b':
@@ -190,6 +201,9 @@ int main(int argc, char *argv[])
190201
else
191202
printf("WDIOC_GETTIMELEFT error '%s'\n", strerror(errno));
192203
break;
204+
case 'f':
205+
/* Handled above */
206+
break;
193207

194208
default:
195209
usage(argv[0]);

0 commit comments

Comments
 (0)