2006-05-21 20:58:10 -07:00
/*
* Watchdog Driver Test Program
*/
2016-07-19 17:41:22 +02:00
# include <errno.h>
2006-05-21 20:58:10 -07:00
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <unistd.h>
# include <fcntl.h>
2012-05-17 15:07:48 +05:30
# include <signal.h>
2017-07-01 14:57:26 +02:00
# include <getopt.h>
2006-05-21 20:58:10 -07:00
# include <sys/ioctl.h>
# include <linux/types.h>
# include <linux/watchdog.h>
2017-07-01 14:57:29 +02:00
# define DEFAULT_PING_RATE 1
2006-05-21 20:58:10 -07:00
int fd ;
2016-06-21 18:00:15 -05:00
const char v = ' V ' ;
selftests: watchdog: get boot reason via WDIOC_GETBOOTSTATUS
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@de.adit-jv.com>
Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
2017-07-01 14:57:30 +02:00
static const char sopts [ ] = " bdehp:t: " ;
2017-07-01 14:57:26 +02:00
static const struct option lopts [ ] = {
selftests: watchdog: get boot reason via WDIOC_GETBOOTSTATUS
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@de.adit-jv.com>
Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
2017-07-01 14:57:30 +02:00
{ " bootstatus " , no_argument , NULL , ' b ' } ,
2017-07-01 14:57:26 +02:00
{ " disable " , no_argument , NULL , ' d ' } ,
{ " enable " , no_argument , NULL , ' e ' } ,
{ " help " , no_argument , NULL , ' h ' } ,
{ " pingrate " , required_argument , NULL , ' p ' } ,
{ " timeout " , required_argument , NULL , ' t ' } ,
{ NULL , no_argument , NULL , 0x0 }
} ;
2006-05-21 20:58:10 -07:00
/*
* This function simply sends an IOCTL to the driver , which in turn ticks
* the PC Watchdog card to reset its internal timer so it doesn ' t trigger
* a computer reset .
*/
2009-09-22 16:43:42 -07:00
static void keep_alive ( void )
2006-05-21 20:58:10 -07:00
{
2017-07-01 14:57:25 +02:00
int dummy ;
int ret ;
2006-05-21 20:58:10 -07:00
2017-07-01 14:57:25 +02:00
ret = ioctl ( fd , WDIOC_KEEPALIVE , & dummy ) ;
if ( ! ret )
printf ( " . " ) ;
2006-05-21 20:58:10 -07:00
}
/*
* The main program . Run the program with " -d " to disable the card ,
* or " -e " to enable the card .
*/
2012-05-17 15:07:48 +05:30
2012-07-23 10:46:11 -07:00
static void term ( int sig )
2012-05-17 15:07:48 +05:30
{
2017-07-01 14:57:25 +02:00
int ret = write ( fd , & v , 1 ) ;
2016-07-19 17:41:22 +02:00
2017-07-01 14:57:25 +02:00
close ( fd ) ;
if ( ret < 0 )
printf ( " \n Stopping watchdog ticks failed (%d)... \n " , errno ) ;
else
printf ( " \n Stopping watchdog ticks... \n " ) ;
exit ( 0 ) ;
2012-05-17 15:07:48 +05:30
}
2017-07-01 14:57:26 +02:00
static void usage ( char * progname )
{
printf ( " Usage: %s [options] \n " , progname ) ;
selftests: watchdog: get boot reason via WDIOC_GETBOOTSTATUS
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@de.adit-jv.com>
Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
2017-07-01 14:57:30 +02:00
printf ( " -b, --bootstatus Get last boot status (Watchdog/POR) \n " ) ;
2017-07-01 14:57:26 +02:00
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 " ) ;
2017-07-01 14:57:29 +02:00
printf ( " -p, --pingrate=P Set ping rate to P seconds (default %d) \n " , DEFAULT_PING_RATE ) ;
2017-07-01 14:57:26 +02:00
printf ( " -t, --timeout=T Set timeout to T seconds \n " ) ;
printf ( " \n " ) ;
printf ( " Parameters are parsed left-to-right in real-time. \n " ) ;
printf ( " Example: %s -d -t 10 -p 5 -e \n " , progname ) ;
}
2006-05-21 20:58:10 -07:00
int main ( int argc , char * argv [ ] )
{
2017-07-01 14:57:25 +02:00
int flags ;
2017-07-01 14:57:29 +02:00
unsigned int ping_rate = DEFAULT_PING_RATE ;
2017-07-01 14:57:25 +02:00
int ret ;
2017-07-01 14:57:26 +02:00
int c ;
selftests: watchdog: get boot reason via WDIOC_GETBOOTSTATUS
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@de.adit-jv.com>
Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
2017-07-01 14:57:30 +02:00
int oneshot = 0 ;
2010-04-05 11:31:29 +01:00
2017-07-01 14:57:25 +02:00
setbuf ( stdout , NULL ) ;
2016-06-21 18:00:14 -05:00
2017-07-01 14:57:25 +02:00
fd = open ( " /dev/watchdog " , O_WRONLY ) ;
2006-05-21 20:58:10 -07:00
2017-07-01 14:57:25 +02:00
if ( fd = = - 1 ) {
printf ( " Watchdog device not enabled. \n " ) ;
exit ( - 1 ) ;
}
2006-05-21 20:58:10 -07:00
2017-07-01 14:57:26 +02:00
while ( ( c = getopt_long ( argc , argv , sopts , lopts , NULL ) ) ! = - 1 ) {
switch ( c ) {
selftests: watchdog: get boot reason via WDIOC_GETBOOTSTATUS
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@de.adit-jv.com>
Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
2017-07-01 14:57:30 +02:00
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 ;
2017-07-01 14:57:26 +02:00
case ' d ' :
2017-07-01 14:57:25 +02:00
flags = WDIOS_DISABLECARD ;
ret = ioctl ( fd , WDIOC_SETOPTIONS , & flags ) ;
if ( ! ret )
printf ( " Watchdog card disabled. \n " ) ;
2017-07-01 14:57:28 +02:00
else
printf ( " WDIOS_DISABLECARD errno '%s' \n " , strerror ( errno ) ) ;
2017-07-01 14:57:26 +02:00
break ;
case ' e ' :
2017-07-01 14:57:25 +02:00
flags = WDIOS_ENABLECARD ;
ret = ioctl ( fd , WDIOC_SETOPTIONS , & flags ) ;
if ( ! ret )
printf ( " Watchdog card enabled. \n " ) ;
2017-07-01 14:57:28 +02:00
else
printf ( " WDIOS_ENABLECARD errno '%s' \n " , strerror ( errno ) ) ;
2017-07-01 14:57:26 +02:00
break ;
case ' p ' :
ping_rate = strtoul ( optarg , NULL , 0 ) ;
2017-07-01 14:57:29 +02:00
if ( ! ping_rate )
ping_rate = DEFAULT_PING_RATE ;
2017-07-01 14:57:26 +02:00
printf ( " Watchdog ping rate set to %u seconds. \n " , ping_rate ) ;
break ;
case ' t ' :
2017-07-01 14:57:27 +02:00
flags = strtoul ( optarg , NULL , 0 ) ;
2017-07-01 14:57:25 +02:00
ret = ioctl ( fd , WDIOC_SETTIMEOUT , & flags ) ;
if ( ! ret )
printf ( " Watchdog timeout set to %u seconds. \n " , flags ) ;
2017-07-01 14:57:28 +02:00
else
printf ( " WDIOC_SETTIMEOUT errno '%s' \n " , strerror ( errno ) ) ;
2017-07-01 14:57:26 +02:00
break ;
default :
usage ( argv [ 0 ] ) ;
2017-07-01 14:57:25 +02:00
goto end ;
}
}
2006-05-21 20:58:10 -07:00
selftests: watchdog: get boot reason via WDIOC_GETBOOTSTATUS
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@de.adit-jv.com>
Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
2017-07-01 14:57:30 +02:00
if ( oneshot )
goto end ;
2017-07-01 14:57:25 +02:00
printf ( " Watchdog Ticking Away! \n " ) ;
2015-06-29 11:46:17 -05:00
2017-07-01 14:57:25 +02:00
signal ( SIGINT , term ) ;
2012-05-17 15:07:48 +05:30
2017-07-01 14:57:25 +02:00
while ( 1 ) {
keep_alive ( ) ;
sleep ( ping_rate ) ;
}
2012-05-14 23:42:02 +05:30
end :
2017-07-01 14:57:25 +02:00
ret = write ( fd , & v , 1 ) ;
if ( ret < 0 )
printf ( " Stopping watchdog ticks failed (%d)... \n " , errno ) ;
close ( fd ) ;
return 0 ;
2006-05-21 20:58:10 -07:00
}