dm: rtc: Avoid a race in the rtc_reset test
authorSimon Glass <sjg@chromium.org>
Mon, 1 Aug 2022 13:58:46 +0000 (07:58 -0600)
committerTom Rini <trini@konsulko.com>
Fri, 2 Sep 2022 20:21:44 +0000 (16:21 -0400)
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.

Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
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

index a834975..e23905b 100644 (file)
@@ -251,10 +251,15 @@ static int dm_test_rtc_reset(struct unit_test_state *uts)
 
        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;
 }