• Eugeniu Rosca's avatar
    selftests: watchdog: get boot reason via WDIOC_GETBOOTSTATUS · a3d6d79f
    Eugeniu Rosca authored
    Some watchdog drivers implement WDIOF_CARDRESET feature. As example,
    see commit b6ef36d2 ("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: default avatarEugeniu Rosca <erosca@de.adit-jv.com>
    Signed-off-by: default avatarShuah Khan <shuahkh@osg.samsung.com>
    a3d6d79f
watchdog-test.c 3.75 KB