Skip to contentSkip to conversation

selftests: watchdog: Add optional file argument

PATCH Superseded George G. Davis 2 participants 4 messages Aug 29, 2019 Kselftest

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 tools/testing/selftests/watchdog/watchdog-test.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
tools/testing/selftests/watchdog/watchdog-test.c +15 -2
index c2333c78cf04..ebeb684552b9 100644
@@ -19,7 +19,7 @@
 
 int fd;
 const char v = 'V';
-static const char sopts[] = "bdehp:t:Tn:NL";
+static const char sopts[] = "bdehp:t:Tn:NLf:";
 static const struct option lopts[] = {
 	{"bootstatus",          no_argument, NULL, 'b'},
 	{"disable",             no_argument, NULL, 'd'},
@@ -31,6 +31,7 @@ static const struct option lopts[] = {
 	{"pretimeout",    required_argument, NULL, 'n'},
 	{"getpretimeout",       no_argument, NULL, 'N'},
 	{"gettimeleft",		no_argument, NULL, 'L'},
+	{"file",          required_argument, NULL, 'f'},
 	{NULL,                  no_argument, NULL, 0x0}
 };
 
@@ -69,6 +70,7 @@ static void term(int sig)
 static void usage(char *progname)
 {
 	printf("Usage: %s [options]\n", progname);
+	printf(" -f, --file          Open watchdog device file (default is /dev/watchdog)\n");
 	printf(" -b, --bootstatus    Get last boot status (Watchdog/POR)\n");
 	printf(" -d, --disable       Turn off the watchdog timer\n");
 	printf(" -e, --enable        Turn on the watchdog timer\n");
@@ -92,10 +94,16 @@ int main(int argc, char *argv[])
 	int ret;
 	int c;
 	int oneshot = 0;
+	char *file = "/dev/watchdog";
 
 	setbuf(stdout, NULL);
 
-	fd = open("/dev/watchdog", O_WRONLY);
+	while ((c = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) {
+		if (c == 'f')
+			file = optarg;
+	}
+
+	fd = open(file, O_WRONLY);
 
 	if (fd == -1) {
 		if (errno == ENOENT)
@@ -108,6 +116,8 @@ int main(int argc, char *argv[])
 		exit(-1);
 	}
 
+	optind = 0;
+
 	while ((c = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) {
 		switch (c) {
 		case 'b':
@@ -190,6 +200,9 @@ int main(int argc, char *argv[])
 			else
 				printf("WDIOC_GETTIMELEFT error '%s'\n", strerror(errno));
 			break;
+		case 'f':
+			/* Handled above */
+			break;
 
 		default:
 			usage(argv[0]);
Signature · 1 line
2.7.4
#1 lore raw

Hi George,

Quoted 2 lines · George G. Davis

Some systems have multiple watchdog devices where the first device registered is assigned to the /dev/watchdog device file.

Confirmed on R-Car H3-Salvator-X:

root@rcar-gen3:~# ls -al /dev/watchdog*
crw-------    1 root     root       10, 130 Aug 21 09:38 /dev/watchdog
crw-------    1 root     root      247,   0 Aug 21 09:38 /dev/watchdog0

[..]

tools/testing/selftests/watchdog/watchdog-test.c int main(int argc, char *argv[]) · line 106

Quoted 7 lines
tools/testing/selftests/watchdog/watchdog-test.c +6 -1
-	fd = open("/dev/watchdog", O_WRONLY);
+	while ((c = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) {
+		if (c == 'f')
+			file = optarg;
+	}
+
+	fd = open(file, O_WRONLY);

Would it be possible to improve below not so helpful and slightly misleading printout:

$ ./watchdog-test -d -t 10 -p 5 -e -f /dev/watch
Watchdog device not enabled.

Thanks!

Signature · 2 lines
Best Regards,
Eugeniu.
#2 lore raw
Quoted 11 lines · Eugeniu Rosca

Hi George,

Quoted 2 lines · George G. Davis

Some systems have multiple watchdog devices where the first device registered is assigned to the /dev/watchdog device file.

Confirmed on R-Car H3-Salvator-X:

root@rcar-gen3:~# ls -al /dev/watchdog*
crw-------    1 root     root       10, 130 Aug 21 09:38 /dev/watchdog
crw-------    1 root     root      247,   0 Aug 21 09:38 /dev/watchdog0

Based on [1], I think this patch is actually helpful when there is at least a /dev/watchdog1 in the system. Particularly on R-Car3, this happens when enabling softdog in addition to the standard RWDT:

root@rcar-gen3:~# ls -al /dev/watchdog*
crw-------    1 root     root       10, 130 Aug 21 09:38 /dev/watchdog
crw-------    1 root     root      247,   0 Aug 21 09:38 /dev/watchdog0
crw-------    1 root     root      247,   1 Aug 21 09:38 /dev/watchdog1

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/watchdog/watchdog-kernel-api.rst?h=v5.3-rc6#n71
----8<----
id 0 is special. It has both a
/dev/watchdog0 cdev (dynamic major, minor 0) as well as the old
/dev/watchdog miscdev.
----8<----

Signature · 2 lines
Best Regards,
Eugeniu.
#3 lore raw
In reply to Eugeniu Rosca

Hello Eugeniu,

Quoted 11 lines · Eugeniu Rosca

Hi George,

Quoted 2 lines · George G. Davis

Some systems have multiple watchdog devices where the first device registered is assigned to the /dev/watchdog device file.

Confirmed on R-Car H3-Salvator-X:

root@rcar-gen3:~# ls -al /dev/watchdog*
crw-------    1 root     root       10, 130 Aug 21 09:38 /dev/watchdog
crw-------    1 root     root      247,   0 Aug 21 09:38 /dev/watchdog0

What you see there is the typical case where there is only one watchdog in the system, /dev/watchdog0, which is registered as the default watchdog via /dev/watchdog. If you have another watchdog enabled, e.g. softdog, you will see:

root@h3ulcb:~# ls -l /dev/watchdog*
crw-------    1 root     root       10, 130 Mar 28 20:37 /dev/watchdog
crw-------    1 root     root      247,   0 Mar 28 20:37 /dev/watchdog0
crw-------    1 root     root      247,   1 Mar 28 20:37 /dev/watchdog1

In the above case, watchdog0 is aliased to watchdog but you may prefer to test the non-default watchdog1 instead (rather than changing your kernel config if one or more are built-in, preventing testing of the non-default watchdog).

Quoted 13 lines

[..]

Review

Quoted 7 lines
(quoted diff) +6 -1
-	fd = open("/dev/watchdog", O_WRONLY);
+	while ((c = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) {
+		if (c == 'f')
+			file = optarg;
+	}
+
+	fd = open(file, O_WRONLY);

Would it be possible to improve below not so helpful and slightly misleading printout:

Quoted 2 lines
$ ./watchdog-test -d -t 10 -p 5 -e -f /dev/watch
Watchdog device not enabled.

Oops, right, thanks for that report.

I'll add the following in the next update:

tools/testing/selftests/watchdog/watchdog-test.c +1 -1
index ebeb684552b9..9f17cae61007 100644
@@ -107,7 +107,7 @@ int main(int argc, char *argv[])
 
 	if (fd == -1) {
 		if (errno == ENOENT)
-			printf("Watchdog device not enabled.\n");
+			printf("Watchdog device (%s) not found.\n", file);
 		else if (errno == EACCES)
 			printf("Run watchdog as root.\n");
 		else

Thanks!

Signature · 2 lines
Regards,
George