Skip to contentSkip to conversation

selftests: watchdog: Add optional file argument

PATCH Superseded George G. Davis 3 participants 7 messages Aug 30, 2019 Kselftest

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 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.

---
v1:
- https://lkml.org/lkml/2019/8/29/16
v2:
- Update printf for ENOENT case based on report from Eugeniu Rosca

---
 tools/testing/selftests/watchdog/watchdog-test.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
tools/testing/selftests/watchdog/watchdog-test.c +16 -3
index c2333c78cf04..9f17cae61007 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,14 +94,20 @@ 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)
-			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
@@ -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
Reviewed-by on v2 1/1
#1 lore raw

Hi George,

Quoted 5 lines · George G. Davis

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.

Quoted 7 lines

---
v1:
- https://lkml.org/lkml/2019/8/29/16
v2:
- Update printf for ENOENT case based on report from Eugeniu Rosca

Below interdiff [1] matches my expectations. Thanks!

[1] interdiff <(git show patch_v1) <(git show patch_v2)

tools/testing/selftests/watchdog/watchdog-test.c +1 -1
diff -u b/tools/testing/selftests/watchdog/watchdog-test.c b/tools/testing/selftests/watchdog/watchdog-test.c
@@ -107,7 +107,7 @@
 
 	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
Signature · 2 lines
Best Regards,
Eugeniu.
#2 lore raw

Hello Eugeniu,

Quoted 7 lines · Eugeniu Rosca

Hi George,

Quoted 2 lines · George G. Davis

v2:
- Update printf for ENOENT case based on report from Eugeniu Rosca

Below interdiff [1] matches my expectations. Thanks!

Thanks for confirming.

Signature · 2 lines
Regards,
George
maintainer
#3 lore raw
In reply to George G. Davis
Quoted 38 lines · George G. Davis

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.

---
v1:
- https://lkml.org/lkml/2019/8/29/16
v2:
- Update printf for ENOENT case based on report from Eugeniu Rosca

---
  tools/testing/selftests/watchdog/watchdog-test.c | 19 ++++++++++++++++---
  1 file changed, 16 insertions(+), 3 deletions(-)
tools/testing/selftests/watchdog/watchdog-test.c +2 -1
index c2333c78cf04..9f17cae61007 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}
  };
 

tools/testing/selftests/watchdog/watchdog-test.c static void term(int sig) · line 73

Quoted 4 lines
tools/testing/selftests/watchdog/watchdog-test.c +1 -0
@@ -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");

Can you split this line into two printf's. Checkpatch doesn't like it.

printf(" -f, --file Open watchdog device file\n");
A second one below for default.

On a separate note, I wish this usage block uses \t instead of spacing things out.

thanks,
-- Shuah

#4 lore raw
Quoted 11 lines · shuah

tools/testing/selftests/watchdog/watchdog-test.c static void term(int sig) · line 73

Quoted 6 lines · George G. Davis
tools/testing/selftests/watchdog/watchdog-test.c +1 -0
@@ -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");

Can you split this line into two printf's. Checkpatch doesn't like it.

Quoted 2 lines

printf(" -f, --file Open watchdog device file\n");
A second one below for default.

Sure, I'll add the following interdiff in v3:

tools/testing/selftests/watchdog/watchdog-test.c +2 -1
index 9f17cae61007..6a68b486dd61 100644
@@ -70,7 +70,8 @@ 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(" -f, --file          Open watchdog device file\n");
+	printf("                     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");
Quoted 2 lines

On a separate note, I wish this usage block uses \t instead of spacing things out.

I noticed that most of those lines are hard spaced with only one using tabs. To remain consistent with existing CodingStyle, I used hard spaces.

Thanks!

Signature · 2 lines
Regards,
George
maintainer
#5 lore raw
Quoted 22 lines · George G. Davis
Quoted 11 lines · shuah

tools/testing/selftests/watchdog/watchdog-test.c static void term(int sig) · line 73

Quoted 6 lines · George G. Davis
tools/testing/selftests/watchdog/watchdog-test.c +1 -0
@@ -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");

Can you split this line into two printf's. Checkpatch doesn't like it.

Quoted 2 lines

printf(" -f, --file Open watchdog device file\n");
A second one below for default.

Sure, I'll add the following interdiff in v3:

tools/testing/selftests/watchdog/watchdog-test.c +0 -0
index 9f17cae61007..6a68b486dd61 100644

tools/testing/selftests/watchdog/watchdog-test.c static void term(int sig) · line 74

Quoted 6 lines
tools/testing/selftests/watchdog/watchdog-test.c +2 -1
@@ -70,7 +70,8 @@ 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(" -f, --file          Open watchdog device file\n");
+	printf("                     Default is /dev/watchdog\n");

Thanks. This is what I am looking for. Please send v3 with thsi change.

Quoted 10 lines
tools/testing/selftests/watchdog/watchdog-test.c +0 -0
  	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");
Quoted 3 lines

On a separate note, I wish this usage block uses \t instead of spacing things out.

I noticed that most of those lines are hard spaced with only one using tabs. To remain consistent with existing CodingStyle, I used hard spaces.

yes. My comment about using "\t" can be done later and if you would like to send for that patch, I will be happy to take it.

thanks,
-- Shuah

#6 lore raw
Quoted 8 lines · shuah
Quoted 5 lines · George G. Davis
Quoted 3 lines · shuah

Can you split this line into two printf's. Checkpatch doesn't like it.

Sure, I'll add the following interdiff in v3:

Thanks. This is what I am looking for. Please send v3 with thsi change.

Done.

Quoted 9 lines
Quoted 6 lines
Quoted 2 lines

On a separate note, I wish this usage block uses \t instead of spacing things out.

I noticed that most of those lines are hard spaced with only one using tabs. To remain consistent with existing CodingStyle, I used hard spaces.

yes. My comment about using "\t" can be done later and if you would like to send for that patch, I will be happy to take it.

I'll send that along in a separate thread.

Thanks!

Signature · 2 lines
Regards,
George