public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] Enhance watchdog API test coverage
@ 2022-10-21 22:18 Shuah Khan
  2022-10-21 22:18 ` [PATCH 1/4] selftests/watchdog: change to print reset reason info Shuah Khan
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Shuah Khan @ 2022-10-21 22:18 UTC (permalink / raw)
  To: skhan, shuah; +Cc: linux-kselftest, linux-kernel

Enace watchdog test to improve watchdog API coverage of iocls and
return values.

Shuah Khan (4):
  selftests/watchdog: change to print reset reason info.
  selftests/watchdog: add support for WDIOC_GETSTATUS
  selftests/watchdog: print watchdog_info option strings
  selftests/watchdog: add test for WDIOC_GETTEMP

 .../selftests/watchdog/watchdog-test.c        | 104 +++++++++++++++++-
 1 file changed, 99 insertions(+), 5 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/4] selftests/watchdog: change to print reset reason info.
  2022-10-21 22:18 [PATCH 0/4] Enhance watchdog API test coverage Shuah Khan
@ 2022-10-21 22:18 ` Shuah Khan
  2022-10-21 22:18 ` [PATCH 2/4] selftests/watchdog: add support for WDIOC_GETSTATUS Shuah Khan
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Shuah Khan @ 2022-10-21 22:18 UTC (permalink / raw)
  To: skhan, shuah; +Cc: linux-kselftest, linux-kernel

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>
---
 .../selftests/watchdog/watchdog-test.c        | 58 ++++++++++++++++++-
 1 file 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..5db9ad8b543c 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 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.
+*
+* 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);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/4] selftests/watchdog: add support for WDIOC_GETSTATUS
  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
  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
  3 siblings, 0 replies; 5+ messages in thread
From: Shuah Khan @ 2022-10-21 22:18 UTC (permalink / raw)
  To: skhan, shuah; +Cc: linux-kselftest, linux-kernel

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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/4] selftests/watchdog: print watchdog_info option strings
  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 ` [PATCH 2/4] selftests/watchdog: add support for WDIOC_GETSTATUS Shuah Khan
@ 2022-10-21 22:18 ` Shuah Khan
  2022-10-21 22:18 ` [PATCH 4/4] selftests/watchdog: add test for WDIOC_GETTEMP Shuah Khan
  3 siblings, 0 replies; 5+ messages in thread
From: Shuah Khan @ 2022-10-21 22:18 UTC (permalink / raw)
  To: skhan, shuah; +Cc: linux-kselftest, linux-kernel

Change show watchdog_info output to print option strings instead
of hex values to make it user friendly and human readable.

Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
---
 tools/testing/selftests/watchdog/watchdog-test.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/tools/testing/selftests/watchdog/watchdog-test.c b/tools/testing/selftests/watchdog/watchdog-test.c
index e6af6e327eb3..03103eaa946c 100644
--- a/tools/testing/selftests/watchdog/watchdog-test.c
+++ b/tools/testing/selftests/watchdog/watchdog-test.c
@@ -6,7 +6,6 @@
 * - Could be tested against softdog driver on systems that
 *   don't have watchdog hadrware.
 * - TODO:
-* - Enhance coverage of ioctl return values - flags and status.
 * - Enhance test to add coverage for WDIOC_GETTEMP.
 *
 * Reference: Documentation/watchdog/watchdog-api.rst
@@ -314,7 +313,7 @@ int main(int argc, char *argv[])
 			printf(" identity:\t\t%s\n", info.identity);
 			printf(" firmware_version:\t%u\n",
 			       info.firmware_version);
-			printf(" options:\t\t%08x\n", info.options);
+			print_status(info.options);
 			break;
 
 		default:
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 4/4] selftests/watchdog: add test for WDIOC_GETTEMP
  2022-10-21 22:18 [PATCH 0/4] Enhance watchdog API test coverage Shuah Khan
                   ` (2 preceding siblings ...)
  2022-10-21 22:18 ` [PATCH 3/4] selftests/watchdog: print watchdog_info option strings Shuah Khan
@ 2022-10-21 22:18 ` Shuah Khan
  3 siblings, 0 replies; 5+ messages in thread
From: Shuah Khan @ 2022-10-21 22:18 UTC (permalink / raw)
  To: skhan, shuah; +Cc: linux-kselftest, linux-kernel

Add test for WDIOC_GETTEMP and this ioctl might not be supported by some
devices and if it is this test will print the following message:

Inappropriate ioctl for device

Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
---
 tools/testing/selftests/watchdog/watchdog-test.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/watchdog/watchdog-test.c b/tools/testing/selftests/watchdog/watchdog-test.c
index 03103eaa946c..5ec0384b7f02 100644
--- a/tools/testing/selftests/watchdog/watchdog-test.c
+++ b/tools/testing/selftests/watchdog/watchdog-test.c
@@ -1,12 +1,10 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
 * Watchdog Driver Test Program
-* - Tests all ioctls except WDIOC_GETTEMP
+* - Tests all ioctls
 * - Tests Magic Close - CONFIG_WATCHDOG_NOWAYOUT
 * - Could be tested against softdog driver on systems that
 *   don't have watchdog hadrware.
-* - TODO:
-* - Enhance test to add coverage for WDIOC_GETTEMP.
 *
 * Reference: Documentation/watchdog/watchdog-api.rst
  */
@@ -177,6 +175,7 @@ int main(int argc, char *argv[])
 	int oneshot = 0;
 	char *file = "/dev/watchdog";
 	struct watchdog_info info;
+	int temperature;
 
 	setbuf(stdout, NULL);
 
@@ -255,6 +254,12 @@ int main(int argc, char *argv[])
 				print_status(flags);
 			else
 				printf("WDIOC_GETSTATUS error '%s'\n", strerror(errno));
+			ret = ioctl(fd, WDIOC_GETTEMP, &temperature);
+			if (ret)
+				printf("WDIOC_GETTEMP: '%s'\n", strerror(errno));
+			else
+				printf("Temeprature: %d\n", temperature);
+
 			break;
 		case 't':
 			flags = strtoul(optarg, NULL, 0);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-10-21 22:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH 2/4] selftests/watchdog: add support for WDIOC_GETSTATUS Shuah Khan
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox