From: Shuah Khan <skhan@linuxfoundation.org>
To: skhan@linuxfoundation.org, shuah@kernel.org
Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 2/4] selftests/watchdog: add support for WDIOC_GETSTATUS
Date: Fri, 21 Oct 2022 16:18:17 -0600 [thread overview]
Message-ID: <de434449f962c396f0dfd8c170461f894d62dd70.1666390362.git.skhan@linuxfoundation.org> (raw)
In-Reply-To: <cover.1666390362.git.skhan@linuxfoundation.org>
Add support for calling WDIOC_GETSTATUS and printing supported
features and status.
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
---
.../selftests/watchdog/watchdog-test.c | 44 +++++++++++++++++--
1 file changed, 41 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/watchdog/watchdog-test.c b/tools/testing/selftests/watchdog/watchdog-test.c
index 5db9ad8b543c..e6af6e327eb3 100644
--- a/tools/testing/selftests/watchdog/watchdog-test.c
+++ b/tools/testing/selftests/watchdog/watchdog-test.c
@@ -6,8 +6,6 @@
* - Could be tested against softdog driver on systems that
* don't have watchdog hadrware.
* - 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.
*
@@ -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'},
@@ -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");
@@ -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] = {
@@ -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);
--
2.34.1
next prev parent reply other threads:[~2022-10-21 22:18 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-21 22:18 [PATCH 0/4] Enhance watchdog API test coverage Shuah Khan
2022-10-21 22:18 ` [PATCH 1/4] selftests/watchdog: change to print reset reason info Shuah Khan
2022-10-21 22:18 ` Shuah Khan [this message]
2022-10-21 22:18 ` [PATCH 3/4] selftests/watchdog: print watchdog_info option strings Shuah Khan
2022-10-21 22:18 ` [PATCH 4/4] selftests/watchdog: add test for WDIOC_GETTEMP Shuah Khan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=de434449f962c396f0dfd8c170461f894d62dd70.1666390362.git.skhan@linuxfoundation.org \
--to=skhan@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=shuah@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®