[PATCH RESEND v2 5/5] test: wdt: add a test for max_timeout_ms

Juuso Rinta via U-Boot <[email protected]>
Newsgroups gmane.comp.boot-loaders.u-boot.general,gmane.comp.boot-loaders.u-boot
Message-ID <[email protected]>
Add a DM test for the case where wdt_start() is called with
a timeout_ms value greater than the (emulated) hardware-supported
limit.

Add console-print asserts for both the clamped and unclamped cases,
as well as for the per-device uclass-plat data max_timeout_ms field.

Add matching tests for the GPIO driver, which does not set the
max_timeout_ms value.

Signed-off-by: Juuso Rinta <[email protected]>
---
 test/dm/wdt.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 47 insertions(+), 2 deletions(-)

diff --git a/test/dm/wdt.c b/test/dm/wdt.c
index bef29591d5a..d86620b25ab 100644
--- a/test/dm/wdt.c
+++ b/test/dm/wdt.c
@@ -3,6 +3,7 @@
  * Copyright 2017 Google, Inc
  */
 
+#include <console.h>
 #include <dm.h>
 #include <time.h>
 #include <wdt.h>
@@ -16,34 +17,68 @@
 #include <u-boot/schedule.h>
 #include <watchdog.h>
 
+static void format_wdt_servicing_str(char *str, size_t len, struct udevice *dev)
+{
+	if (IS_ENABLED(CONFIG_WATCHDOG)) {
+		u32 reset_period = dev_read_u32_default(dev, "hw_margin_ms",
+							4000) / 4;
+
+		snprintf(str, len, " with servicing every %ums ",
+			 reset_period);
+	} else {
+		snprintf(str, len, " without servicing ");
+	}
+}
+
 /* Test that watchdog driver functions are called */
 static int dm_test_wdt_base(struct unit_test_state *uts)
 {
 	struct sandbox_state *state = state_get_current();
 	struct udevice *dev;
+	struct wdt_uc_plat *plat;
 	const u64 timeout = 42;
+	char svc[40];
 
 	ut_assertok(uclass_get_device_by_driver(UCLASS_WDT,
 						DM_DRIVER_GET(wdt_sandbox), &dev));
 	ut_assertnonnull(dev);
+
+	/* Sandbox driver sets max_timeout_ms during probe */
+	plat = dev_get_uclass_plat(dev);
+	ut_asserteq(SANDBOX_WDT_MAX_TIMEOUT_MS, plat->max_timeout_ms);
+
 	ut_asserteq(0, state->wdt.counter);
 	ut_asserteq(false, state->wdt.running);
 
+	/* Unclamped timeout path */
+	console_record_reset();
 	ut_assertok(wdt_start(dev, timeout, 0));
 	ut_asserteq(timeout, state->wdt.counter);
 	ut_asserteq(true, state->wdt.running);
+	format_wdt_servicing_str(svc, sizeof(svc), dev);
+	ut_assert_nextline("WDT:   Started %s%s(0s timeout)", dev->name, svc);
+	ut_assert_console_end();
 
 	uint reset_count = state->wdt.reset_count;
 	ut_assertok(wdt_reset(dev));
 	ut_asserteq(reset_count + 1, state->wdt.reset_count);
 	ut_asserteq(true, state->wdt.running);
 
+	/* Clamped timeout path */
+	console_record_reset();
+	ut_assertok(wdt_start(dev, SANDBOX_WDT_MAX_TIMEOUT_MS + 1000, 0));
+	ut_asserteq(SANDBOX_WDT_MAX_TIMEOUT_MS, state->wdt.counter);
+	ut_assert_nextline("WDT:   Started %s%s(%ds timeout, requested %ds)",
+			   dev->name, svc, SANDBOX_WDT_MAX_TIMEOUT_MS / 1000,
+			   (SANDBOX_WDT_MAX_TIMEOUT_MS + 1000) / 1000);
+	ut_assert_console_end();
+
 	ut_assertok(wdt_stop(dev));
 	ut_asserteq(false, state->wdt.running);
 
 	return 0;
 }
-DM_TEST(dm_test_wdt_base, UTF_SCAN_PDATA | UTF_SCAN_FDT);
+DM_TEST(dm_test_wdt_base, UTF_SCAN_PDATA | UTF_SCAN_FDT | UTF_CONSOLE);
 
 static int dm_test_wdt_gpio_toggle(struct unit_test_state *uts)
 {
@@ -53,17 +88,27 @@ static int dm_test_wdt_gpio_toggle(struct unit_test_state *uts)
 	 * driver behaves as expected when using the 'toggle' algorithm.
 	 */
 	struct udevice *wdt, *gpio;
+	struct wdt_uc_plat *plat;
 	const u64 timeout = 42;
 	const int offset = 8;
 	int val;
+	char svc[40];
 
 	ut_assertok(uclass_get_device_by_name(UCLASS_WDT,
 					      "wdt-gpio-toggle", &wdt));
 	ut_assertnonnull(wdt);
 
+	/* GPIO driver does not set max_timeout_ms */
+	plat = dev_get_uclass_plat(wdt);
+	ut_asserteq(0, plat->max_timeout_ms);
+
 	ut_assertok(uclass_get_device_by_name(UCLASS_GPIO, "base-gpios", &gpio));
 	ut_assertnonnull(gpio);
+	console_record_reset();
 	ut_assertok(wdt_start(wdt, timeout, 0));
+	format_wdt_servicing_str(svc, sizeof(svc), wdt);
+	ut_assert_nextline("WDT:   Started %s%s(0s timeout)", wdt->name, svc);
+	ut_assert_console_end();
 
 	val = sandbox_gpio_get_value(gpio, offset);
 	ut_assertok(wdt_reset(wdt));
@@ -75,7 +120,7 @@ static int dm_test_wdt_gpio_toggle(struct unit_test_state *uts)
 
 	return 0;
 }
-DM_TEST(dm_test_wdt_gpio_toggle, UTF_SCAN_FDT);
+DM_TEST(dm_test_wdt_gpio_toggle, UTF_SCAN_FDT | UTF_CONSOLE);
 
 static int dm_test_wdt_gpio_level(struct unit_test_state *uts)
 {

-- 
2.39.2
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.