summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/watchdog
diff options
context:
space:
mode:
authorShuah Khan <skhan@linuxfoundation.org>2022-10-21 00:18:28 +0300
committerShuah Khan <skhan@linuxfoundation.org>2022-10-26 06:15:10 +0300
commit66d1dce0ecb2a15ec2e1ec2d9c25bf13d9004d57 (patch)
tree560ca7097ada18df761ce37fb6fb581fd1e73c6c /tools/testing/selftests/watchdog
parentde3ee3f63400a23954e7c1ad1cb8c20f29ab6fe3 (diff)
downloadlinux-66d1dce0ecb2a15ec2e1ec2d9c25bf13d9004d57.tar.xz
selftests/watchdog: change to print reset reason info.
The test prints reset reason when WDIOC_GETBOOTSTATUS returns a 0 flag value and all other cases simply say watchdog. Parse the flag values returned by WDIOC_GETBOOTSTATUS and print corresponding reset reason for each WDIOF_* boot status. Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
Diffstat (limited to 'tools/testing/selftests/watchdog')
-rw-r--r--tools/testing/selftests/watchdog/watchdog-test.c58
1 files changed, 55 insertions, 3 deletions
diff --git a/tools/testing/selftests/watchdog/watchdog-test.c b/tools/testing/selftests/watchdog/watchdog-test.c
index f45e510500c0..09baf5e0e703 100644
--- a/tools/testing/selftests/watchdog/watchdog-test.c
+++ b/tools/testing/selftests/watchdog/watchdog-test.c
@@ -1,6 +1,17 @@
// SPDX-License-Identifier: GPL-2.0
/*
- * Watchdog Driver Test Program
+* Watchdog Driver Test Program
+* - Tests all ioctls except WDIOC_GETTEMP
+* - Tests Magic Close - CONFIG_WATCHDOG_NOWAYOUT
+* - 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.
+*
+* Reference: Documentation/watchdog/watchdog-api.rst
*/
#include <errno.h>
@@ -91,6 +102,44 @@ static void usage(char *progname)
printf("Example: %s -t 12 -T -n 7 -N\n", progname);
}
+struct wdiof_status {
+ int flag;
+ const char *status_str;
+};
+
+#define WDIOF_NUM_BOOTSTATUS 7
+
+static const struct wdiof_status wdiof_bootstatus[WDIOF_NUM_BOOTSTATUS] = {
+ {WDIOF_OVERHEAT, "Reset due to CPU overheat"},
+ {WDIOF_FANFAULT, "Fan failed"},
+ {WDIOF_EXTERN1, "External relay 1"},
+ {WDIOF_EXTERN2, "External relay 2"},
+ {WDIOF_POWERUNDER, "Power bad/power fault"},
+ {WDIOF_CARDRESET, "Card previously reset the CPU"},
+ {WDIOF_POWEROVER, "Power over voltage"},
+};
+
+static void print_boot_status(int flags)
+{
+ int wdiof = 0;
+
+ if (flags == WDIOF_UNKNOWN) {
+ printf("Unknown flag error from WDIOC_GETBOOTSTATUS\n");
+ return;
+ }
+
+ if (flags == 0) {
+ printf("Last boot is caused by: Power-On-Reset\n");
+ return;
+ }
+
+ for (wdiof = 0; wdiof < WDIOF_NUM_BOOTSTATUS; wdiof++) {
+ if (flags & wdiof_bootstatus[wdiof].flag)
+ printf("Last boot is caused by: %s\n",
+ wdiof_bootstatus[wdiof].status_str);
+ }
+}
+
int main(int argc, char *argv[])
{
int flags;
@@ -140,8 +189,7 @@ int main(int argc, char *argv[])
oneshot = 1;
ret = ioctl(fd, WDIOC_GETBOOTSTATUS, &flags);
if (!ret)
- printf("Last boot is caused by: %s.\n", (flags != 0) ?
- "Watchdog" : "Power-On-Reset");
+ print_boot_status(flags);
else
printf("WDIOC_GETBOOTSTATUS error '%s'\n", strerror(errno));
break;
@@ -249,6 +297,10 @@ int main(int argc, char *argv[])
sleep(ping_rate);
}
end:
+ /*
+ * Send specific magic character 'V' just in case Magic Close is
+ * enabled to ensure watchdog gets disabled on close.
+ */
ret = write(fd, &v, 1);
if (ret < 0)
printf("Stopping watchdog ticks failed (%d)...\n", errno);