[PATCH v3 6/6] test: wdt: add a test for max_timeout_ms

Juuso Rinta <[email protected]>
Newsgroups org.u-boot-project.lists.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 | 47 +++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 43 insertions(+), 4 deletions(-)

diff --git a/test/dm/wdt.c b/test/dm/wdt.c
index bef29591d5a..2e9d641d6bb 100644
--- a/test/dm/wdt.c
+++ b/test/dm/wdt.c
@@ -3,7 +3,9 @@
  * Copyright 2017 Google, Inc
  */
 
+#include <console.h>
 #include <dm.h>
+#include <div64.h>
 #include <time.h>
 #include <wdt.h>
 #include <asm/gpio.h>
@@ -21,29 +23,57 @@ static int dm_test_wdt_base(struct unit_test_state *uts)
 {
 	struct sandbox_state *state = state_get_current();
 	struct udevice *dev;
-	const u64 timeout = 42;
+	struct wdt_uc_plat *plat;
+	const u64 timeout = 4000;
 
 	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);
+	ut_assert_nextline("WDT:   Started %s with servicing every 50ms (%ds timeout)",
+			   dev->name, (u32)lldiv(timeout, 1000));
+	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 with servicing every 50ms (%ds timeout, requested %ds)",
+		dev->name, SANDBOX_WDT_MAX_TIMEOUT_MS / 1000,
+		(SANDBOX_WDT_MAX_TIMEOUT_MS + 1000) / 1000);
+	ut_assert_console_end();
+
+	/* Clamped, subsecond rounding ignored in the print */
+	console_record_reset();
+	ut_assertok(wdt_start(dev, SANDBOX_WDT_MAX_TIMEOUT_MS + 100, 0));
+	ut_asserteq(SANDBOX_WDT_MAX_TIMEOUT_MS, state->wdt.counter);
+	ut_assert_nextline("WDT:   Started %s with servicing every 50ms (%ds timeout)",
+			   dev->name, SANDBOX_WDT_MAX_TIMEOUT_MS / 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,7 +83,8 @@ 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;
-	const u64 timeout = 42;
+	struct wdt_uc_plat *plat;
+	const u64 timeout = 4000;
 	const int offset = 8;
 	int val;
 
@@ -61,9 +92,17 @@ static int dm_test_wdt_gpio_toggle(struct unit_test_state *uts)
 					      "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));
+	ut_assert_nextline("WDT:   Started %s with servicing every 25ms (%ds timeout)",
+			   wdt->name, (u32)lldiv(timeout, 1000));
+	ut_assert_console_end();
 
 	val = sandbox_gpio_get_value(gpio, offset);
 	ut_assertok(wdt_reset(wdt));
@@ -75,7 +114,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.