Re: [PATCH v3 6/6] selftests: watchdog: get boot reason via WDIOC_GETBOOTSTATUS

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 06/03/2017 02:15 PM, Eugeniu Rosca wrote:
> Some watchdog drivers implement WDIOF_CARDRESET feature. As example,
> see commit b6ef36d2c1e3 ("watchdog: qcom: Report reboot reason").
> This option allows reporting to userspace the cause of the last boot
> (POR/watchdog reset), being helpful in e.g. automated test-cases.
> 
> Add support for WDIOC_GETBOOTSTATUS in the test code, to be able to:
> - check if watchdog drivers properly implement WDIOF_CARDRESET.
> - check the last boot status, if WDIOF_CARDRESET is implemented.
> 
> Make the `-b, --bootstatus` option one-shot. That means, skip the
> keepalive mechanism if `-b` is provided on the command line, as we
> are only interested in the boot status information.
> 
> Tested on Rcar-H3 Salvator-X board:
> 
> ********************** Cold boot finished
> salvator-x:/home/root# ./watchdog-test -h
> Usage: ./watchdog-test [options]
>  -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
>  -t, --timeout=T     Set timeout to T seconds
> 
> Parameters are parsed left-to-right in real-time.
> Example: ./watchdog-test -d -t 10 -p 5 -e
> salvator-x:/home/root#
> salvator-x:/home/root# ./watchdog-test -b
> Last boot is caused by: Power-On-Reset.
> salvator-x:/home/root#
> salvator-x:/home/root# ./watchdog-test -d -t 1 -p 2 -e
> Watchdog card disabled.
> Watchdog timeout set to 1 seconds.
> Watchdog ping rate set to 2 seconds.
> Watchdog card enabled.
> Watchdog Ticking Away!
> ********************** Reboot due to watchdog trigger finished
> salvator-x:/home/root# ./watchdog-test -b
> Last boot is caused by: Watchdog.
> salvator-x:/home/root#
> salvator-x:/home/root# reboot
> ********************** Reboot due to user action finished
> salvator-x:/home/root# ./watchdog-test -b
> Last boot is caused by: Power-On-Reset.
> salvator-x:/home/root#
> 
> Signed-off-by: Eugeniu Rosca <erosca@xxxxxxxxxxxxxx>
> ---
>  tools/testing/selftests/watchdog/watchdog-test.c | 18 +++++++++++++++++-
>  1 file changed, 17 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/watchdog/watchdog-test.c b/tools/testing/selftests/watchdog/watchdog-test.c
> index c768b51a044e..baab8cd00697 100644
> --- a/tools/testing/selftests/watchdog/watchdog-test.c
> +++ b/tools/testing/selftests/watchdog/watchdog-test.c
> @@ -16,8 +16,9 @@
>  
>  int fd;
>  const char v = 'V';
> -static const char sopts[] = "dehp:t:";
> +static const char sopts[] = "bdehp:t:";
>  static const struct option lopts[] = {
> +	{"bootstatus",          no_argument, NULL, 'b'},
>  	{"disable",             no_argument, NULL, 'd'},
>  	{"enable",              no_argument, NULL, 'e'},
>  	{"help",                no_argument, NULL, 'h'},
> @@ -61,6 +62,7 @@ static void term(int sig)
>  static void usage(char *progname)
>  {
>  	printf("Usage: %s [options]\n", progname);
> +	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");
>  	printf(" -h, --help          Print the help message\n");
> @@ -77,6 +79,7 @@ int main(int argc, char *argv[])
>  	unsigned int ping_rate = 1;
>  	int ret;
>  	int c;
> +	int oneshot = 0;
>  
>  	setbuf(stdout, NULL);
>  
> @@ -89,6 +92,16 @@ int main(int argc, char *argv[])
>  
>  	while ((c = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) {
>  		switch (c) {
> +		case 'b':
> +			flags = 0;
> +			oneshot = 1;
> +			ret = ioctl(fd, WDIOC_GETBOOTSTATUS, &flags);
> +			if (!ret)
> +				printf("Last boot is caused by: %s.\n", (flags != 0) ?
> +					"Watchdog" : "Power-On-Reset");
> +			else
> +				printf("Failed to get boot status.\n");

Please include ioctl ret value in the error message.

> +			break;
>  		case 'd':
>  			flags = WDIOS_DISABLECARD;
>  			ret = ioctl(fd, WDIOC_SETOPTIONS, &flags);
> @@ -125,6 +138,9 @@ int main(int argc, char *argv[])
>  		}
>  	}
>  
> +	if (oneshot)
> +		goto end;
> +
>  	printf("Watchdog Ticking Away!\n");
>  
>  	signal(SIGINT, term);
> 

thanks,
-- Shuah
--
To unsubscribe from this list: send the line "unsubscribe linux-kselftest" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux