diff options
author | Simon Glass <sjg@chromium.org> | 2022-08-01 07:58:47 -0600 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2022-09-02 16:21:44 -0400 |
commit | fc7ceae0d5b7a017c3fed88a8bfe2eb3d24058a9 (patch) | |
tree | 830386de44f8a0e434c4972faefffc728bded7a4 /test/dm | |
parent | c4d7247a389ae2770ddcdada5143401068a696c0 (diff) | |
download | u-boot-fc7ceae0d5b7a017c3fed88a8bfe2eb3d24058a9.zip u-boot-fc7ceae0d5b7a017c3fed88a8bfe2eb3d24058a9.tar.gz u-boot-fc7ceae0d5b7a017c3fed88a8bfe2eb3d24058a9.tar.bz2 |
dm: rtc: Try to avoid a race in rtc_set_get test
It seems that the time can change in between getting it and reading the
offset. Check for this and try again if this happens.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'test/dm')
-rw-r--r-- | test/dm/rtc.c | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/test/dm/rtc.c b/test/dm/rtc.c index e23905b..50086ff 100644 --- a/test/dm/rtc.c +++ b/test/dm/rtc.c @@ -60,16 +60,27 @@ static int dm_test_rtc_set_get(struct unit_test_state *uts) { struct rtc_time now, time, cmp; struct udevice *dev, *emul; - long offset, old_offset, old_base_time; + long offset, check_offset, old_offset, old_base_time; + int i; ut_assertok(uclass_get_device(UCLASS_RTC, 0, &dev)); - ut_assertok(dm_rtc_get(dev, &now)); ut_assertok(i2c_emul_find(dev, &emul)); ut_assertnonnull(emul); - /* Tell the RTC to go into manual mode */ - old_offset = sandbox_i2c_rtc_set_offset(emul, false, 0); + /* Get the offset, putting the RTC into manual mode */ + i = 0; + do { + check_offset = sandbox_i2c_rtc_set_offset(emul, false, 0); + ut_assertok(dm_rtc_get(dev, &now)); + + /* Tell the RTC to go into manual mode */ + old_offset = sandbox_i2c_rtc_set_offset(emul, false, 0); + + /* If the times changed in that period, read it again */ + } while (++i < 2 && check_offset != old_offset); + ut_asserteq(check_offset, old_offset); + old_base_time = sandbox_i2c_rtc_get_set_base_time(emul, -1); memset(&time, '\0', sizeof(time)); @@ -127,7 +138,8 @@ static int dm_test_rtc_set_get(struct unit_test_state *uts) ut_asserteq(now.tm_sec + 1, cmp.tm_sec); } - old_offset = sandbox_i2c_rtc_set_offset(emul, true, 0); + /* return RTC to normal mode */ + sandbox_i2c_rtc_set_offset(emul, true, 0); return 0; } |