All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] dm: rtc: Avoid a race in the rtc_reset test
@ 2022-07-31 18:27 Simon Glass
  2022-08-01  8:11 ` Heinrich Schuchardt
  0 siblings, 1 reply; 9+ messages in thread
From: Simon Glass @ 2022-07-31 18:27 UTC (permalink / raw)
  To: U-Boot Mailing List
  Cc: Heinrich Schuchardt, Tom Rini, Simon Glass, Bin Meng,
	Rasmus Villemoes, Marek Vasut, Pavel Herrmann

Since resetting the RTC on sandbox causes it to read the base time from
the system, we cannot rely on this being unchanged since it was last read.
Allow for a one-second delay.

Fixes: https://source.denx.de/u-boot/u-boot/-/issues/4
Reported-by: Bin Meng <bmeng.cn@gmail.com>
Reported-by: Tom Rini <trini@konsulko.com>
Suggested-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Signed-off-by: Simon Glass <sjg@chromium.org>
---

 test/dm/rtc.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/test/dm/rtc.c b/test/dm/rtc.c
index c7f9f8f0ce7..403bf5c640a 100644
--- a/test/dm/rtc.c
+++ b/test/dm/rtc.c
@@ -245,16 +245,21 @@ static int dm_test_rtc_reset(struct unit_test_state *uts)
 	ut_assertok(dm_rtc_get(dev, &now));
 
 	ut_assertok(i2c_emul_find(dev, &emul));
-	ut_assert(emul != NULL);
+	ut_assertnonnull(emul);
 
 	old_base_time = sandbox_i2c_rtc_get_set_base_time(emul, 0);
 
 	ut_asserteq(0, sandbox_i2c_rtc_get_set_base_time(emul, -1));
 
-	/* Resetting the RTC should put he base time back to normal */
+	/*
+	 * Resetting the RTC should put the base time back to normal. Allow for
+	 * a one-second adjustment in case the time flips over while this
+	 * test process is pre-empted, since reset_time() in i2c_rtc_emul.c
+	 * reads the time from the OS.
+	 */
 	ut_assertok(dm_rtc_reset(dev));
 	base_time = sandbox_i2c_rtc_get_set_base_time(emul, -1);
-	ut_asserteq(old_base_time, base_time);
+	ut_assert(base_time - old_base_time <= 1);
 
 	return 0;
 }
-- 
2.37.1.455.g008518b4e5-goog


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

end of thread, other threads:[~2022-08-02 14:02 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-31 18:27 [PATCH] dm: rtc: Avoid a race in the rtc_reset test Simon Glass
2022-08-01  8:11 ` Heinrich Schuchardt
2022-08-01 13:59   ` Simon Glass
2022-08-01 14:58     ` Heinrich Schuchardt
2022-08-01 19:13       ` Simon Glass
2022-08-02  7:08         ` Rasmus Villemoes
2022-08-02 12:41           ` Simon Glass
2022-08-02 13:51         ` Heinrich Schuchardt
2022-08-02 14:01           ` Simon Glass

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.