Skip to contentSkip to conversation

dm: rtc: Avoid a race in the rtc_reset test

PATCH In review Simon Glass 3 participants 9 messages Jul 31, 2022 – Aug 2, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dm: rtc: Avoid a race in the rtc_reset test

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.

---

 test/dm/rtc.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
test/dm/rtc.c +8 -3
index c7f9f8f0ce7..403bf5c640a 100644
@@ -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;
 }
Signature · 1 line
2.37.1.455.g008518b4e5-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 19 lines · Simon Glass

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.

---

  test/dm/rtc.c | 11 ++++++++---
  1 file changed, 8 insertions(+), 3 deletions(-)
test/dm/rtc.c +0 -0
index c7f9f8f0ce7..403bf5c640a 100644

test/dm/rtc.c static int dm_test_rtc_reset(struct unit_test_state *uts) · line 248

Quoted 5 lines
test/dm/rtc.c +1 -1
@@ -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);

This is an unrelated change. It would be preferable to describe it in the commit message.

Quoted 6 lines
test/dm/rtc.c +0 -1
  	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 */

test/dm/rtc.c static int dm_test_rtc_reset(struct unit_test_state *uts) · line 262

Quoted 10 lines
test/dm/rtc.c +7 -1
+	/*
+	 * 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);

If the operating system uses daylight saving time, this may still fail (very rarely).

How about using gmtime() instead of localtime()? But that would be a separate patch.

Quoted 3 lines
test/dm/rtc.c +0 -0
  	return 0;
  }
#2 lore raw

Hi Heinrich,

Quoted 47 lines · Heinrich Schuchardt
Quoted 19 lines · Simon Glass

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.

---

  test/dm/rtc.c | 11 ++++++++---
  1 file changed, 8 insertions(+), 3 deletions(-)
test/dm/rtc.c +0 -0
index c7f9f8f0ce7..403bf5c640a 100644

test/dm/rtc.c static int dm_test_rtc_reset(struct unit_test_state *uts) · line 248

Quoted 5 lines
test/dm/rtc.c +1 -1
@@ -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);

This is an unrelated change. It would be preferable to describe it in the commit message.

Quoted 6 lines
test/dm/rtc.c +0 -1
      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 */

test/dm/rtc.c static int dm_test_rtc_reset(struct unit_test_state *uts) · line 262

Quoted 10 lines
test/dm/rtc.c +7 -1
+     /*
+      * 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);
Quoted 5 lines

If the operating system uses daylight saving time, this may still fail (very rarely).

How about using gmtime() instead of localtime()? But that would be a separate patch.

I'm not sure how to do this, as U-Boot expects local time. Of course we could enhance the rtc API to support both (and use gmtime for the test).

I've got an idea how to deal with daylight savings, and an alternative approach for this patch, so will send a series.

Quoted 7 lines
Quoted 3 lines
test/dm/rtc.c +0 -0
      return 0;
  }

Regards,
Simon

#3 lore raw
Quoted 50 lines · Simon Glass

Hi Heinrich,

Quoted 47 lines · Heinrich Schuchardt
Quoted 19 lines · Simon Glass

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.

---

   test/dm/rtc.c | 11 ++++++++---
   1 file changed, 8 insertions(+), 3 deletions(-)
test/dm/rtc.c +0 -0
index c7f9f8f0ce7..403bf5c640a 100644

test/dm/rtc.c static int dm_test_rtc_reset(struct unit_test_state *uts) · line 248

Quoted 5 lines
test/dm/rtc.c +1 -1
@@ -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);

This is an unrelated change. It would be preferable to describe it in the commit message.

Quoted 16 lines
test/dm/rtc.c +7 -2
       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);
Quoted 8 lines
Quoted 5 lines

If the operating system uses daylight saving time, this may still fail (very rarely).

How about using gmtime() instead of localtime()? But that would be a separate patch.

I'm not sure how to do this, as U-Boot expects local time. Of course we could enhance the rtc API to support both (and use gmtime for the

What makes you think that U-Boot expects local time? U-Boot has no notion of time zones. Linux systems tend to use UTC on the RTC. Why should sandbox_defconfig deviate?

$ sudo hwclock --show -v
hwclock from util-linux 2.38
System Time: 1659365754.792540
Trying to open: /dev/rtc0
Using the rtc interface to the clock.
Assuming hardware clock is kept in UTC time.

If you dual boot into Windows, you should better adjust Windows to use UTC.

Best regards

Heinrich

Quoted 15 lines

test).

I've got an idea how to deal with daylight savings, and an alternative approach for this patch, so will send a series.

Quoted 7 lines
Quoted 3 lines
test/dm/rtc.c +0 -0
       return 0;
   }

Regards,
Simon

#4 lore raw

Hi Heinrich,

Quoted 65 lines · Heinrich Schuchardt
Quoted 50 lines · Simon Glass

Hi Heinrich,

Quoted 47 lines · Heinrich Schuchardt
Quoted 19 lines · Simon Glass

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.

---

   test/dm/rtc.c | 11 ++++++++---
   1 file changed, 8 insertions(+), 3 deletions(-)
test/dm/rtc.c +0 -0
index c7f9f8f0ce7..403bf5c640a 100644

test/dm/rtc.c static int dm_test_rtc_reset(struct unit_test_state *uts) · line 248

Quoted 5 lines
test/dm/rtc.c +1 -1
@@ -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);

This is an unrelated change. It would be preferable to describe it in the commit message.

Quoted 16 lines
test/dm/rtc.c +7 -2
       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);
Quoted 8 lines
Quoted 5 lines

If the operating system uses daylight saving time, this may still fail (very rarely).

How about using gmtime() instead of localtime()? But that would be a separate patch.

I'm not sure how to do this, as U-Boot expects local time. Of course we could enhance the rtc API to support both (and use gmtime for the

What makes you think that U-Boot expects local time? U-Boot has no notion of time zones. Linux systems tend to use UTC on the RTC. Why should sandbox_defconfig deviate?

Quoted 6 lines
$ sudo hwclock --show -v
hwclock from util-linux 2.38
System Time: 1659365754.792540
Trying to open: /dev/rtc0
Using the rtc interface to the clock.
Assuming hardware clock is kept in UTC time.

Well the thing is, we want to show local times in U-Boot. As I mentioned, we could expand the API to allow control over that, e.g. to show local times but use UTC in tests?

Quoted 2 lines

If you dual boot into Windows, you should better adjust Windows to use UTC.

I'm not the world's most dedicated Windows user.

Regards,
Simon

Quoted 21 lines

Best regards

Heinrich

Quoted 15 lines

test).

I've got an idea how to deal with daylight savings, and an alternative approach for this patch, so will send a series.

Quoted 7 lines
Quoted 3 lines
test/dm/rtc.c +0 -0
       return 0;
   }

Regards,
Simon

#5 lore raw
Quoted 68 lines · Simon Glass

Hi Heinrich,

Quoted 65 lines · Heinrich Schuchardt
Quoted 50 lines · Simon Glass

Hi Heinrich,

Quoted 47 lines · Heinrich Schuchardt
Quoted 19 lines · Simon Glass

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.

---

   test/dm/rtc.c | 11 ++++++++---
   1 file changed, 8 insertions(+), 3 deletions(-)
test/dm/rtc.c +0 -0
index c7f9f8f0ce7..403bf5c640a 100644

test/dm/rtc.c static int dm_test_rtc_reset(struct unit_test_state *uts) · line 248

Quoted 5 lines
test/dm/rtc.c +1 -1
@@ -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);

This is an unrelated change. It would be preferable to describe it in the commit message.

Quoted 16 lines
test/dm/rtc.c +7 -2
       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);
Quoted 8 lines
Quoted 5 lines

If the operating system uses daylight saving time, this may still fail (very rarely).

How about using gmtime() instead of localtime()? But that would be a separate patch.

I'm not sure how to do this, as U-Boot expects local time. Of course we could enhance the rtc API to support both (and use gmtime for the

What makes you think that U-Boot expects local time? U-Boot has no notion of time zones. Linux systems tend to use UTC on the RTC. Why should sandbox_defconfig deviate?

Quoted 8 lines
Quoted 6 lines
$ sudo hwclock --show -v
hwclock from util-linux 2.38
System Time: 1659365754.792540
Trying to open: /dev/rtc0
Using the rtc interface to the clock.
Assuming hardware clock is kept in UTC time.

Well the thing is, we want to show local times in U-Boot.

Who's "we"?

I'm with Heinrich. I'd much rather U-Boot showed the time actually stored in the RTC, and if we emulate an RTC, that RTC should emulate what a real RTC does, namely store UTC. If you're worried about that that might confuse somebody, there's no harm adding " UTC" or "+00" or whatever to the output-for-humans (wherever that is).

Especially when doing anything else causes weird and still-fragile hacks to be sprinkled throughout the testing code (that DST hack is ugly, and the "only twice a year" isn't accurate, because something on the host may also change /etc/localtime at any time).

Rasmus

PS: I loved working in Iceland. Apart from the beautiful nature, their timezone is UTC+0 all year round, so all questions of UTC vs localtime vs DST were moot :)

#6 lore raw

Hi Rasmus,

Quoted 77 lines · Rasmus Villemoes
Quoted 75 lines · Simon Glass

Hi Heinrich,

Quoted 71 lines · Heinrich Schuchardt
Quoted 50 lines · Simon Glass

Hi Heinrich,

Quoted 47 lines · Heinrich Schuchardt
Quoted 19 lines · Simon Glass

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.

---

   test/dm/rtc.c | 11 ++++++++---
   1 file changed, 8 insertions(+), 3 deletions(-)
test/dm/rtc.c +0 -0
index c7f9f8f0ce7..403bf5c640a 100644

test/dm/rtc.c static int dm_test_rtc_reset(struct unit_test_state *uts) · line 248

Quoted 5 lines
test/dm/rtc.c +1 -1
@@ -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);

This is an unrelated change. It would be preferable to describe it in the commit message.

Quoted 16 lines
test/dm/rtc.c +7 -2
       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);
Quoted 8 lines
Quoted 5 lines

If the operating system uses daylight saving time, this may still fail (very rarely).

How about using gmtime() instead of localtime()? But that would be a separate patch.

I'm not sure how to do this, as U-Boot expects local time. Of course we could enhance the rtc API to support both (and use gmtime for the

What makes you think that U-Boot expects local time? U-Boot has no notion of time zones. Linux systems tend to use UTC on the RTC. Why should sandbox_defconfig deviate?

$ sudo hwclock --show -v
hwclock from util-linux 2.38
System Time: 1659365754.792540
Trying to open: /dev/rtc0
Using the rtc interface to the clock.
Assuming hardware clock is kept in UTC time.
Quoted 3 lines
Quoted 1 line

Well the thing is, we want to show local times in U-Boot.

Who's "we"?

Me, at least. E.g. the 'date' command on sandbox shows the current local time.

Quoted 11 lines

I'm with Heinrich. I'd much rather U-Boot showed the time actually stored in the RTC, and if we emulate an RTC, that RTC should emulate what a real RTC does, namely store UTC. If you're worried about that that might confuse somebody, there's no harm adding " UTC" or "+00" or whatever to the output-for-humans (wherever that is).

Especially when doing anything else causes weird and still-fragile hacks to be sprinkled throughout the testing code (that DST hack is ugly, and the "only twice a year" isn't accurate, because something on the host may also change /etc/localtime at any time).

OK, we have an is_dst but not many drivers actually set it, Anyway, it doesn't specify the offset. So if we wanted to support a DST offset we would have to add that to the API.

The patches in this series deal with the 'second' problem. They happen to also deal with the DST issue mentioned by Heinrich in v1.

So one option is just to remove any mention of DST, since the code changes are the same for the 'second' problem as the DST problem.

For changing sandbox to use gmtime, we could add the concept of a timezone offset to U-Boot, along with an option to the 'date' command to allow GMT or local time. Then we could change sandbox to internally use gmtime(). Would that be useful?

As I said, it doesn't really affect the code, as I see it, but I could certainly drop the DST comments if that helps.

Quoted 6 lines

Rasmus

PS: I loved working in Iceland. Apart from the beautiful nature, their timezone is UTC+0 all year round, so all questions of UTC vs localtime vs DST were moot :)

From what I understand in the 1800s every town/city had its own time based on the position of the sun, so things were even worse!

I'm not sure I like DST, actually. Perhaps I should move to Arizona?

Regards,
Simon

#7 lore raw
In reply to Simon Glass
Quoted 68 lines · Simon Glass

Hi Heinrich,

Quoted 65 lines · Heinrich Schuchardt
Quoted 50 lines · Simon Glass

Hi Heinrich,

Quoted 47 lines · Heinrich Schuchardt
Quoted 19 lines · Simon Glass

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.

---

    test/dm/rtc.c | 11 ++++++++---
    1 file changed, 8 insertions(+), 3 deletions(-)
test/dm/rtc.c +0 -0
index c7f9f8f0ce7..403bf5c640a 100644

test/dm/rtc.c static int dm_test_rtc_reset(struct unit_test_state *uts) · line 248

Quoted 5 lines
test/dm/rtc.c +1 -1
@@ -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);

This is an unrelated change. It would be preferable to describe it in the commit message.

Quoted 16 lines
test/dm/rtc.c +7 -2
        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);
Quoted 8 lines
Quoted 5 lines

If the operating system uses daylight saving time, this may still fail (very rarely).

How about using gmtime() instead of localtime()? But that would be a separate patch.

I'm not sure how to do this, as U-Boot expects local time. Of course we could enhance the rtc API to support both (and use gmtime for the

What makes you think that U-Boot expects local time? U-Boot has no notion of time zones. Linux systems tend to use UTC on the RTC. Why should sandbox_defconfig deviate?

Quoted 8 lines
Quoted 6 lines
$ sudo hwclock --show -v
hwclock from util-linux 2.38
System Time: 1659365754.792540
Trying to open: /dev/rtc0
Using the rtc interface to the clock.
Assuming hardware clock is kept in UTC time.

Well the thing is, we want to show local times in U-Boot. As I

U-Boot neither knows the time zone of the user nor the time zone of the RTC not does it hold the time zone definitions needed to manage daylight saving time.

The idea of showing local time is doomed.

Typically the RTC will be using UTC and not local time. The sandbox should do the same.

Best regards

Heinrich

Quoted 33 lines

mentioned, we could expand the API to allow control over that, e.g. to show local times but use UTC in tests?

Quoted 2 lines

If you dual boot into Windows, you should better adjust Windows to use UTC.

I'm not the world's most dedicated Windows user.

Regards,
Simon

Quoted 21 lines

Best regards

Heinrich

Quoted 15 lines

test).

I've got an idea how to deal with daylight savings, and an alternative approach for this patch, so will send a series.

Quoted 7 lines
Quoted 3 lines
test/dm/rtc.c +0 -0
        return 0;
    }

Regards,
Simon

#8 lore raw

Hi Heinrich,

Quoted 77 lines · Heinrich Schuchardt
Quoted 75 lines · Simon Glass

Hi Heinrich,

Quoted 71 lines · Heinrich Schuchardt
Quoted 50 lines · Simon Glass

Hi Heinrich,

Quoted 47 lines · Heinrich Schuchardt
Quoted 19 lines · Simon Glass

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.

---

    test/dm/rtc.c | 11 ++++++++---
    1 file changed, 8 insertions(+), 3 deletions(-)
test/dm/rtc.c +0 -0
index c7f9f8f0ce7..403bf5c640a 100644

test/dm/rtc.c static int dm_test_rtc_reset(struct unit_test_state *uts) · line 248

Quoted 5 lines
test/dm/rtc.c +1 -1
@@ -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);

This is an unrelated change. It would be preferable to describe it in the commit message.

Quoted 16 lines
test/dm/rtc.c +7 -2
        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);
Quoted 8 lines
Quoted 5 lines

If the operating system uses daylight saving time, this may still fail (very rarely).

How about using gmtime() instead of localtime()? But that would be a separate patch.

I'm not sure how to do this, as U-Boot expects local time. Of course we could enhance the rtc API to support both (and use gmtime for the

What makes you think that U-Boot expects local time? U-Boot has no notion of time zones. Linux systems tend to use UTC on the RTC. Why should sandbox_defconfig deviate?

$ sudo hwclock --show -v
hwclock from util-linux 2.38
System Time: 1659365754.792540
Trying to open: /dev/rtc0
Using the rtc interface to the clock.
Assuming hardware clock is kept in UTC time.
Quoted 5 lines
Quoted 1 line

Well the thing is, we want to show local times in U-Boot. As I

U-Boot neither knows the time zone of the user nor the time zone of the RTC not does it hold the time zone definitions needed to manage daylight saving time.

Right, that's what I'm wondering, whether we should add that.

Quoted 5 lines

The idea of showing local time is doomed.

Typically the RTC will be using UTC and not local time. The sandbox should do the same.

We'll have to disagree on that one. I find GM time just such a pain.

Let's review the series on its merits, then. I can drop or rephase the comments if that helps.

This whole thing came about because you brought up the potential for a test failure when the time zone changes. Let's just ignore that problem as it is very rare, as you said.

Regards,
Simon

Quoted 39 lines

Best regards

Heinrich

Quoted 33 lines

mentioned, we could expand the API to allow control over that, e.g. to show local times but use UTC in tests?

Quoted 2 lines

If you dual boot into Windows, you should better adjust Windows to use UTC.

I'm not the world's most dedicated Windows user.

Regards,
Simon

Quoted 21 lines

Best regards

Heinrich

Quoted 15 lines

test).

I've got an idea how to deal with daylight savings, and an alternative approach for this patch, so will send a series.

Quoted 7 lines
Quoted 3 lines
test/dm/rtc.c +0 -0
        return 0;
    }

Regards,
Simon