selftests: watchdog: get boot reason via WDIOC_GETBOOTSTATUS
Some watchdog drivers implement WDIOF_CARDRESET feature. As example,
see commit b6ef36d2c1
("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@de.adit-jv.com>
Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
This commit is contained in:
parent
f8f92c072e
commit
a3d6d79f11
|
@ -18,8 +18,9 @@
|
||||||
|
|
||||||
int fd;
|
int fd;
|
||||||
const char v = 'V';
|
const char v = 'V';
|
||||||
static const char sopts[] = "dehp:t:";
|
static const char sopts[] = "bdehp:t:";
|
||||||
static const struct option lopts[] = {
|
static const struct option lopts[] = {
|
||||||
|
{"bootstatus", no_argument, NULL, 'b'},
|
||||||
{"disable", no_argument, NULL, 'd'},
|
{"disable", no_argument, NULL, 'd'},
|
||||||
{"enable", no_argument, NULL, 'e'},
|
{"enable", no_argument, NULL, 'e'},
|
||||||
{"help", no_argument, NULL, 'h'},
|
{"help", no_argument, NULL, 'h'},
|
||||||
|
@ -63,6 +64,7 @@ static void term(int sig)
|
||||||
static void usage(char *progname)
|
static void usage(char *progname)
|
||||||
{
|
{
|
||||||
printf("Usage: %s [options]\n", 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(" -d, --disable Turn off the watchdog timer\n");
|
||||||
printf(" -e, --enable Turn on the watchdog timer\n");
|
printf(" -e, --enable Turn on the watchdog timer\n");
|
||||||
printf(" -h, --help Print the help message\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;
|
unsigned int ping_rate = DEFAULT_PING_RATE;
|
||||||
int ret;
|
int ret;
|
||||||
int c;
|
int c;
|
||||||
|
int oneshot = 0;
|
||||||
|
|
||||||
setbuf(stdout, NULL);
|
setbuf(stdout, NULL);
|
||||||
|
|
||||||
|
@ -91,6 +94,16 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
while ((c = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) {
|
while ((c = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) {
|
||||||
switch (c) {
|
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':
|
case 'd':
|
||||||
flags = WDIOS_DISABLECARD;
|
flags = WDIOS_DISABLECARD;
|
||||||
ret = ioctl(fd, WDIOC_SETOPTIONS, &flags);
|
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");
|
printf("Watchdog Ticking Away!\n");
|
||||||
|
|
||||||
signal(SIGINT, term);
|
signal(SIGINT, term);
|
||||||
|
|
Loading…
Reference in a new issue