diff mbox series

[2/2] selftests: watchdog: Add command line option to show watchdog_info

Message ID 20190907085833.21167-2-erosca@de.adit-jv.com (mailing list archive)
State Mainlined
Commit ce3a677802121e038d2f062e90f96f84e7351da0
Headers show
Series [1/2] selftests: watchdog: Validate optional file argument | expand

Commit Message

Eugeniu Rosca Sept. 7, 2019, 8:58 a.m. UTC
From: "George G. Davis" <george_davis@mentor.com>

A side of affect of commit "selftests: watchdog: Add optional file
argument" is that arbitrary files may be opened for watchdog testing, e.g.
/dev/null. To prevent watchdog-test from operating on non-watchdog device
files, commit "selftests: watchdog: Validate optional file argument" was
added to validate that a file is indeed a watchdog device via an
ioctl(WDIOC_GETSUPPORT) call. Since the watchdog_info is available as a
result of the ioctl(WDIOC_GETSUPPORT) call, add a command line option to
show the watchdog_info.

Suggested-by: Eugeniu Rosca <erosca@de.adit-jv.com>
Signed-off-by: George G. Davis <george_davis@mentor.com>
Signed-off-by: Eugeniu Rosca <erosca@de.adit-jv.com>
---
v1: Applied/tested on commit ce54eab71e210f ("kunit: fix failure to build without printk") of 
    https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git/log/?h=next

 tools/testing/selftests/watchdog/watchdog-test.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

Comments

Shuah Sept. 16, 2019, 1:26 p.m. UTC | #1
On 9/7/19 2:58 AM, Eugeniu Rosca wrote:
> From: "George G. Davis" <george_davis@mentor.com>
> 
> A side of affect of commit "selftests: watchdog: Add optional file
> argument" is that arbitrary files may be opened for watchdog testing, e.g.
> /dev/null. To prevent watchdog-test from operating on non-watchdog device
> files, commit "selftests: watchdog: Validate optional file argument" was
> added to validate that a file is indeed a watchdog device via an
> ioctl(WDIOC_GETSUPPORT) call. Since the watchdog_info is available as a
> result of the ioctl(WDIOC_GETSUPPORT) call, add a command line option to
> show the watchdog_info.
> 
> Suggested-by: Eugeniu Rosca <erosca@de.adit-jv.com>
> Signed-off-by: George G. Davis <george_davis@mentor.com>
> Signed-off-by: Eugeniu Rosca <erosca@de.adit-jv.com>
> ---
> v1: Applied/tested on commit ce54eab71e210f ("kunit: fix failure to build without printk") of
>      https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git/log/?h=next
> 
>   tools/testing/selftests/watchdog/watchdog-test.c | 16 +++++++++++++++-
>   1 file changed, 15 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/watchdog/watchdog-test.c b/tools/testing/selftests/watchdog/watchdog-test.c
> index 6ed822dc2222..f45e510500c0 100644
> --- a/tools/testing/selftests/watchdog/watchdog-test.c
> +++ b/tools/testing/selftests/watchdog/watchdog-test.c
> @@ -19,7 +19,7 @@
>   
>   int fd;
>   const char v = 'V';
> -static const char sopts[] = "bdehp:t:Tn:NLf:";
> +static const char sopts[] = "bdehp:t:Tn:NLf:i";
>   static const struct option lopts[] = {
>   	{"bootstatus",          no_argument, NULL, 'b'},
>   	{"disable",             no_argument, NULL, 'd'},
> @@ -32,6 +32,7 @@ static const struct option lopts[] = {
>   	{"getpretimeout",       no_argument, NULL, 'N'},
>   	{"gettimeleft",		no_argument, NULL, 'L'},
>   	{"file",          required_argument, NULL, 'f'},
> +	{"info",		no_argument, NULL, 'i'},
>   	{NULL,                  no_argument, NULL, 0x0}
>   };
>   
> @@ -72,6 +73,7 @@ static void usage(char *progname)
>   	printf("Usage: %s [options]\n", progname);
>   	printf(" -f, --file\t\tOpen watchdog device file\n");
>   	printf("\t\t\tDefault is /dev/watchdog\n");
> +	printf(" -i, --info\t\tShow watchdog_info\n");
>   	printf(" -b, --bootstatus\tGet last boot status (Watchdog/POR)\n");
>   	printf(" -d, --disable\t\tTurn off the watchdog timer\n");
>   	printf(" -e, --enable\t\tTurn on the watchdog timer\n");
> @@ -216,6 +218,18 @@ int main(int argc, char *argv[])
>   		case 'f':
>   			/* Handled above */
>   			break;
> +		case 'i':
> +			/*
> +			 * watchdog_info was obtained as part of file open
> +			 * validation. So we just show it here.
> +			 */
> +			oneshot = 1;
> +			printf("watchdog_info:\n");
> +			printf(" identity:\t\t%s\n", info.identity);
> +			printf(" firmware_version:\t%u\n",
> +			       info.firmware_version);
> +			printf(" options:\t\t%08x\n", info.options);
> +			break;
>   
>   		default:
>   			usage(argv[0]);
> 

I would like to see these combined. Please don't add another argument.
Combine patch and 1&2.

thanks,
-- Shuah
George G. Davis Sept. 16, 2019, 1:55 p.m. UTC | #2
Hello,

On Mon, Sep 16, 2019 at 07:26:41AM -0600, shuah wrote:
> On 9/7/19 2:58 AM, Eugeniu Rosca wrote:
> >diff --git a/tools/testing/selftests/watchdog/watchdog-test.c b/tools/testing/selftests/watchdog/watchdog-test.c
> >index 6ed822dc2222..f45e510500c0 100644
> >--- a/tools/testing/selftests/watchdog/watchdog-test.c
> >+++ b/tools/testing/selftests/watchdog/watchdog-test.c
> >@@ -19,7 +19,7 @@
> >  int fd;
> >  const char v = 'V';
> >-static const char sopts[] = "bdehp:t:Tn:NLf:";
> >+static const char sopts[] = "bdehp:t:Tn:NLf:i";
> >  static const struct option lopts[] = {
> >  	{"bootstatus",          no_argument, NULL, 'b'},
> >  	{"disable",             no_argument, NULL, 'd'},
> >@@ -32,6 +32,7 @@ static const struct option lopts[] = {
> >  	{"getpretimeout",       no_argument, NULL, 'N'},
> >  	{"gettimeleft",		no_argument, NULL, 'L'},
> >  	{"file",          required_argument, NULL, 'f'},
> >+	{"info",		no_argument, NULL, 'i'},
> >  	{NULL,                  no_argument, NULL, 0x0}
> >  };
> >@@ -72,6 +73,7 @@ static void usage(char *progname)
> >  	printf("Usage: %s [options]\n", progname);
> >  	printf(" -f, --file\t\tOpen watchdog device file\n");
> >  	printf("\t\t\tDefault is /dev/watchdog\n");
> >+	printf(" -i, --info\t\tShow watchdog_info\n");
> >  	printf(" -b, --bootstatus\tGet last boot status (Watchdog/POR)\n");
> >  	printf(" -d, --disable\t\tTurn off the watchdog timer\n");
> >  	printf(" -e, --enable\t\tTurn on the watchdog timer\n");
> >@@ -216,6 +218,18 @@ int main(int argc, char *argv[])
> >  		case 'f':
> >  			/* Handled above */
> >  			break;
> >+		case 'i':
> >+			/*
> >+			 * watchdog_info was obtained as part of file open
> >+			 * validation. So we just show it here.
> >+			 */
> >+			oneshot = 1;
> >+			printf("watchdog_info:\n");
> >+			printf(" identity:\t\t%s\n", info.identity);
> >+			printf(" firmware_version:\t%u\n",
> >+			       info.firmware_version);
> >+			printf(" options:\t\t%08x\n", info.options);
> >+			break;
> >  		default:
> >  			usage(argv[0]);
> >
> 
> I would like to see these combined.

Ok.

> Please don't add another argument.

I'm not clear on your request here. Do you want to drop the addition
of optional --info|-i command line option and always display the
watchdog_info?

If yes, perhaps Eugeniu may mention what he has already mentioned to me earlier
that "it's very useful to see the watchdog identity" but "some users might
perceive the console output a bit busy if the Watchdog identity: <WDT name>
message is always on" so perhaps it is "more user-friendly to still call the
WDIOC_GETSUPPORT ioctl to sanitize the device file, but to only print the
Watchdog identity: message when the user passes e.g. a new -i, --identity
parameter".


> Combine patch and 1&2.

I'll do that but I'm not entirely clear on your "Please don't add another
argument" request.

> 
> thanks,
> -- Shuah
Eugeniu Rosca Sept. 16, 2019, 1:57 p.m. UTC | #3
Hi Shuah,
CC George

On Mon, Sep 16, 2019 at 07:26:41AM -0600, shuah wrote:
[..]
> >   		case 'f':
> >   			/* Handled above */
> >   			break;
> > +		case 'i':
> > +			/*
> > +			 * watchdog_info was obtained as part of file open
> > +			 * validation. So we just show it here.
> > +			 */
> > +			oneshot = 1;
> > +			printf("watchdog_info:\n");
> > +			printf(" identity:\t\t%s\n", info.identity);
> > +			printf(" firmware_version:\t%u\n",
> > +			       info.firmware_version);
> > +			printf(" options:\t\t%08x\n", info.options);
> > +			break;
> >   		default:
> >   			usage(argv[0]);
> > 
> 
> I would like to see these combined. Please don't add another argument.
> Combine patch and 1&2.

With all my appreciation for your comment, why do you think it is better
to get rid of the new argument? I don't think it is user-friendly to
always report the watchdog_info to the user. Just look at outputs [1-2]
and imagine that the watchdog_info part would pop up unconditionally.
It looks too busy to me.

[1] watchdog-test -b -i
Last boot is caused by: Power-On-Reset.
watchdog_info:
 identity:              Renesas WDT Watchdog
 firmware_version:      0
 options:               000081a0

[2] watchdog-test -i --help    
watchdog_info:
 identity:              Renesas WDT Watchdog
 firmware_version:      0
 options:               000081a0
Usage: ./watchdog-test [options]
 -f, --file             Open watchdog device file
                        Default is /dev/watchdog
 -i, --info             Show watchdog_info
 -b, --bootstatus       Get last boot status (Watchdog/POR)
 -d, --disable          Turn off the watchdog timer
 -e, --enable           Turn on the watchdog timer
 -h, --help             Print the help message
 -p, --pingrate=P       Set ping rate to P seconds (default 1)
 -t, --timeout=T        Set timeout to T seconds
 -T, --gettimeout       Get the timeout
 -n, --pretimeout=T     Set the pretimeout to T seconds
 -N, --getpretimeout    Get the pretimeout
 -L, --gettimeleft      Get the time left until timer expires

Parameters are parsed left-to-right in real-time.
Example: ./watchdog-test -d -t 10 -p 5 -e
Example: ./watchdog-test -t 12 -T -n 7 -N
Shuah Sept. 16, 2019, 4:05 p.m. UTC | #4
On 9/16/19 7:57 AM, Eugeniu Rosca wrote:
> Hi Shuah,
> CC George
> 
> On Mon, Sep 16, 2019 at 07:26:41AM -0600, shuah wrote:
> [..]
>>>    		case 'f':
>>>    			/* Handled above */
>>>    			break;
>>> +		case 'i':
>>> +			/*
>>> +			 * watchdog_info was obtained as part of file open
>>> +			 * validation. So we just show it here.
>>> +			 */
>>> +			oneshot = 1;
>>> +			printf("watchdog_info:\n");
>>> +			printf(" identity:\t\t%s\n", info.identity);
>>> +			printf(" firmware_version:\t%u\n",
>>> +			       info.firmware_version);
>>> +			printf(" options:\t\t%08x\n", info.options);
>>> +			break;
>>>    		default:
>>>    			usage(argv[0]);
>>>
>>
>> I would like to see these combined. Please don't add another argument.
>> Combine patch and 1&2.
> 
> With all my appreciation for your comment, why do you think it is better
> to get rid of the new argument? I don't think it is user-friendly to
> always report the watchdog_info to the user. Just look at outputs [1-2]
> and imagine that the watchdog_info part would pop up unconditionally.
> It looks too busy to me.

Yes it does look busy. I am okay with adding a second options
based on what you both said.

I don't like the commit log.

Unfortunately this thread no longer contains the commit log.

I would like to see the commit log without any references to side
effects. It make it rather confusing.

"A side of affect of commit "selftests: watchdog: Add optional file
argument" is that arbitrary files may be opened for watchdog testing, e.g.
/dev/null. To prevent watchdog-test from operating on non-watchdog device
files, commit "selftests: watchdog: Validate optional file argument" was
added to validate that a file is indeed a watchdog device via an
ioctl(WDIOC_GETSUPPORT) call. Since the watchdog_info is available as a
result of the ioctl(WDIOC_GETSUPPORT) call, add a command line option to
show the watchdog_info."

I would drop all references to that.

thanks,
-- Shuah
George G. Davis Sept. 16, 2019, 4:15 p.m. UTC | #5
Hello Shuah,

On Mon, Sep 16, 2019 at 10:05:17AM -0600, shuah wrote:
> On 9/16/19 7:57 AM, Eugeniu Rosca wrote:
> >Hi Shuah,
> >CC George
> >
> >On Mon, Sep 16, 2019 at 07:26:41AM -0600, shuah wrote:
> >[..]
> >>>   		case 'f':
> >>>   			/* Handled above */
> >>>   			break;
> >>>+		case 'i':
> >>>+			/*
> >>>+			 * watchdog_info was obtained as part of file open
> >>>+			 * validation. So we just show it here.
> >>>+			 */
> >>>+			oneshot = 1;
> >>>+			printf("watchdog_info:\n");
> >>>+			printf(" identity:\t\t%s\n", info.identity);
> >>>+			printf(" firmware_version:\t%u\n",
> >>>+			       info.firmware_version);
> >>>+			printf(" options:\t\t%08x\n", info.options);
> >>>+			break;
> >>>   		default:
> >>>   			usage(argv[0]);
> >>>
> >>
> >>I would like to see these combined. Please don't add another argument.
> >>Combine patch and 1&2.
> >
> >With all my appreciation for your comment, why do you think it is better
> >to get rid of the new argument? I don't think it is user-friendly to
> >always report the watchdog_info to the user. Just look at outputs [1-2]
> >and imagine that the watchdog_info part would pop up unconditionally.
> >It looks too busy to me.
> 
> Yes it does look busy. I am okay with adding a second options
> based on what you both said.
> 
> I don't like the commit log.

Agreed, I didn't like it either - it was rather a draft.

> 
> Unfortunately this thread no longer contains the commit log.
> 
> I would like to see the commit log without any references to side
> effects. It make it rather confusing.
> 
> "A side of affect of commit "selftests: watchdog: Add optional file
> argument" is that arbitrary files may be opened for watchdog testing, e.g.
> /dev/null. To prevent watchdog-test from operating on non-watchdog device
> files, commit "selftests: watchdog: Validate optional file argument" was
> added to validate that a file is indeed a watchdog device via an
> ioctl(WDIOC_GETSUPPORT) call. Since the watchdog_info is available as a
> result of the ioctl(WDIOC_GETSUPPORT) call, add a command line option to
> show the watchdog_info."
> 
> I would drop all references to that.

How about the following commit message for the squash commit for [1] and [2]?:

"
selftests: watchdog: Validate optional file argument

As reported by Eugeniu Rosca, a side of affect of commit c3f2490d6e92
("selftests: watchdog: Add optional file argument") is that arbitrary files
may be opened for watchdog testing, e.g.

./watchdog-test  -f /dev/zero
Watchdog Ticking Away!

To prevent watchdog-test from operating on non-watchdog device files,
validate that a file is indeed a watchdog device via an
ioctl(WDIOC_GETSUPPORT) call.

While we're at it, since the watchdog_info is available as a result of the
ioctl(WDIOC_GETSUPPORT) call, add a command line option to optionally show
the watchdog_info.
"

Thanks!


> 
> thanks,
> -- Shuah
Eugeniu Rosca Sept. 17, 2019, 6:53 p.m. UTC | #6
(For LKML readability) Superseded by:
 - https://patchwork.kernel.org/patch/11149289/
   ("[v3,2/2] selftests: watchdog: Add command line option to show watchdog_info")
diff mbox series

Patch

diff --git a/tools/testing/selftests/watchdog/watchdog-test.c b/tools/testing/selftests/watchdog/watchdog-test.c
index 6ed822dc2222..f45e510500c0 100644
--- a/tools/testing/selftests/watchdog/watchdog-test.c
+++ b/tools/testing/selftests/watchdog/watchdog-test.c
@@ -19,7 +19,7 @@ 
 
 int fd;
 const char v = 'V';
-static const char sopts[] = "bdehp:t:Tn:NLf:";
+static const char sopts[] = "bdehp:t:Tn:NLf:i";
 static const struct option lopts[] = {
 	{"bootstatus",          no_argument, NULL, 'b'},
 	{"disable",             no_argument, NULL, 'd'},
@@ -32,6 +32,7 @@  static const struct option lopts[] = {
 	{"getpretimeout",       no_argument, NULL, 'N'},
 	{"gettimeleft",		no_argument, NULL, 'L'},
 	{"file",          required_argument, NULL, 'f'},
+	{"info",		no_argument, NULL, 'i'},
 	{NULL,                  no_argument, NULL, 0x0}
 };
 
@@ -72,6 +73,7 @@  static void usage(char *progname)
 	printf("Usage: %s [options]\n", progname);
 	printf(" -f, --file\t\tOpen watchdog device file\n");
 	printf("\t\t\tDefault is /dev/watchdog\n");
+	printf(" -i, --info\t\tShow watchdog_info\n");
 	printf(" -b, --bootstatus\tGet last boot status (Watchdog/POR)\n");
 	printf(" -d, --disable\t\tTurn off the watchdog timer\n");
 	printf(" -e, --enable\t\tTurn on the watchdog timer\n");
@@ -216,6 +218,18 @@  int main(int argc, char *argv[])
 		case 'f':
 			/* Handled above */
 			break;
+		case 'i':
+			/*
+			 * watchdog_info was obtained as part of file open
+			 * validation. So we just show it here.
+			 */
+			oneshot = 1;
+			printf("watchdog_info:\n");
+			printf(" identity:\t\t%s\n", info.identity);
+			printf(" firmware_version:\t%u\n",
+			       info.firmware_version);
+			printf(" options:\t\t%08x\n", info.options);
+			break;
 
 		default:
 			usage(argv[0]);