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

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

 



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 (default 1)
 -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 9b34b319fc91..a1391be2dc1e 100644
--- a/tools/testing/selftests/watchdog/watchdog-test.c
+++ b/tools/testing/selftests/watchdog/watchdog-test.c
@@ -18,8 +18,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'},
@@ -63,6 +64,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");
@@ -79,6 +81,7 @@ int main(int argc, char *argv[])
 	unsigned int ping_rate = DEFAULT_PING_RATE;
 	int ret;
 	int c;
+	int oneshot = 0;
 
 	setbuf(stdout, NULL);
 
@@ -91,6 +94,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("WDIOC_GETBOOTSTATUS errno '%s'\n", strerror(errno));
+			break;
 		case 'd':
 			flags = WDIOS_DISABLECARD;
 			ret = ioctl(fd, WDIOC_SETOPTIONS, &flags);
@@ -127,6 +140,9 @@ int main(int argc, char *argv[])
 		}
 	}
 
+	if (oneshot)
+		goto end;
+
 	printf("Watchdog Ticking Away!\n");
 
 	signal(SIGINT, term);
-- 
2.13.0

--
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