Skip to content

Commit

Permalink
selftests/watchdog: add support for WDIOC_GETSTATUS
Browse files Browse the repository at this point in the history
Add support for calling WDIOC_GETSTATUS and printing supported
features and status.

Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
  • Loading branch information
shuahkh committed Oct 26, 2022
1 parent 66d1dce commit ac7e8d3
Showing 1 changed file with 41 additions and 3 deletions.
44 changes: 41 additions & 3 deletions tools/testing/selftests/watchdog/watchdog-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
* - Could be tested against softdog driver on systems that
* don't have watchdog hardware.
* - TODO:
* - WDIOC_GETSTATUS is called when WDIOC_GETBOOTSTATUS is called.
* - Enhance the logic to call WDIOC_GETSTATUS and test return values.
* - Enhance coverage of ioctl return values - flags and status.
* - Enhance test to add coverage for WDIOC_GETTEMP.
*
Expand All @@ -30,13 +28,14 @@

int fd;
const char v = 'V';
static const char sopts[] = "bdehp:t:Tn:NLf:i";
static const char sopts[] = "bdehp:st:Tn:NLf:i";
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'},
{"pingrate", required_argument, NULL, 'p'},
{"status", no_argument, NULL, 's'},
{"timeout", required_argument, NULL, 't'},
{"gettimeout", no_argument, NULL, 'T'},
{"pretimeout", required_argument, NULL, 'n'},
Expand Down Expand Up @@ -85,6 +84,7 @@ static void usage(char *progname)
printf(" -f, --file\t\tOpen watchdog device file\n");
printf("\t\t\tDefault is /dev/watchdog\n");
printf(" -i, --info\t\tShow watchdog_info\n");
printf(" -s, --status\t\tGet status & supported features\n");
printf(" -b, --bootstatus\tGet last boot status (Watchdog/POR)\n");
printf(" -d, --disable\t\tTurn off the watchdog timer\n");
printf(" -e, --enable\t\tTurn on the watchdog timer\n");
Expand All @@ -107,6 +107,35 @@ struct wdiof_status {
const char *status_str;
};

#define WDIOF_NUM_STATUS 8

static const struct wdiof_status wdiof_status[WDIOF_NUM_STATUS] = {
{WDIOF_SETTIMEOUT, "Set timeout (in seconds)"},
{WDIOF_MAGICCLOSE, "Supports magic close char"},
{WDIOF_PRETIMEOUT, "Pretimeout (in seconds), get/set"},
{WDIOF_ALARMONLY, "Watchdog triggers a management or other external alarm not a reboot"},
{WDIOF_KEEPALIVEPING, "Keep alive ping reply"},
{WDIOS_DISABLECARD, "Turn off the watchdog timer"},
{WDIOS_ENABLECARD, "Turn on the watchdog timer"},
{WDIOS_TEMPPANIC, "Kernel panic on temperature trip"},
};

static void print_status(int flags)
{
int wdiof = 0;

if (flags == WDIOS_UNKNOWN) {
printf("Unknown status error from WDIOC_GETSTATUS\n");
return;
}

for (wdiof = 0; wdiof < WDIOF_NUM_STATUS; wdiof++) {
if (flags & wdiof_status[wdiof].flag)
printf("Support/Status: %s\n",
wdiof_status[wdiof].status_str);
}
}

#define WDIOF_NUM_BOOTSTATUS 7

static const struct wdiof_status wdiof_bootstatus[WDIOF_NUM_BOOTSTATUS] = {
Expand Down Expand Up @@ -219,6 +248,15 @@ int main(int argc, char *argv[])
ping_rate = DEFAULT_PING_RATE;
printf("Watchdog ping rate set to %u seconds.\n", ping_rate);
break;
case 's':
flags = 0;
oneshot = 1;
ret = ioctl(fd, WDIOC_GETSTATUS, &flags);
if (!ret)
print_status(flags);
else
printf("WDIOC_GETSTATUS error '%s'\n", strerror(errno));
break;
case 't':
flags = strtoul(optarg, NULL, 0);
ret = ioctl(fd, WDIOC_SETTIMEOUT, &flags);
Expand Down

0 comments on commit ac7e8d3

Please sign in to comment.