On Tue, Aug 26, 2025 at 09:11:10PM -0500, Andrew Hamilton wrote:
> Add tests outside the date range possible with 32-bit time
> calculation. Also add a few more nominal date/time test values
> to the 32-bit "tests" array. Add min / max tests for years 0001
> and 9999.
>
> Signed-off-by: Vladimir Serbinenko <phco...@gmail.com>
> Signed-off-by: Andrew Hamilton <adham...@gmail.com>
> ---
>  tests/date_unit_test.c | 75 +++++++++++++++++++++++++++++++++++++-----
>  1 file changed, 66 insertions(+), 9 deletions(-)
>
> diff --git a/tests/date_unit_test.c b/tests/date_unit_test.c
> index 99774f199..d3bf5a712 100644
> --- a/tests/date_unit_test.c
> +++ b/tests/date_unit_test.c
> @@ -25,12 +25,13 @@
>  #include <grub/test.h>
>
>  static void
> -date_test (grub_int32_t v)
> +date_test (grub_int64_t v)
>  {
>    struct grub_datetime dt;
>    time_t t = v;
>    struct tm *g;
>    int w;
> +  grub_int64_t back = 0;
>
>    g = gmtime (&t);
>
> @@ -38,28 +39,56 @@ date_test (grub_int32_t v)
>
>    w = grub_get_weekday (&dt);
>
> -  grub_test_assert (g->tm_sec == dt.second, "time %d bad second: %d vs %d", 
> v,
> +  grub_datetime2unixtime (&dt, &back);
> +
> +  grub_test_assert (g->tm_sec == dt.second, "time %lld bad second: %d vs 
> %d", (long long) v,
>                   g->tm_sec, dt.second);
> -  grub_test_assert (g->tm_min == dt.minute, "time %d bad minute: %d vs %d", 
> v,
> +  grub_test_assert (g->tm_min == dt.minute, "time %lld bad minute: %d vs 
> %d", (long long) v,
>                   g->tm_min, dt.minute);
> -  grub_test_assert (g->tm_hour == dt.hour, "time %d bad hour: %d vs %d", v,
> +  grub_test_assert (g->tm_hour == dt.hour, "time %lld bad hour: %d vs %d", 
> (long long) v,
>                   g->tm_hour, dt.hour);
> -  grub_test_assert (g->tm_mday == dt.day, "time %d bad day: %d vs %d", v,
> +  grub_test_assert (g->tm_mday == dt.day, "time %lld bad day: %d vs %d", 
> (long long) v,
>                   g->tm_mday, dt.day);
> -  grub_test_assert (g->tm_mon + 1 == dt.month, "time %d bad month: %d vs 
> %d", v,
> +  grub_test_assert (g->tm_mon + 1 == dt.month, "time %lld bad month: %d vs 
> %d",(long long) v,
>                   g->tm_mon + 1, dt.month);
>    grub_test_assert (g->tm_year + 1900 == dt.year,
> -                 "time %d bad year: %d vs %d", v,
> +                   "time %lld bad year: %d vs %d", (long long) v,
>                   g->tm_year + 1900, dt.year);
> -  grub_test_assert (g->tm_wday == w, "time %d bad week day: %d vs %d", v,
> +  grub_test_assert (g->tm_wday == w, "time %lld bad week day: %d vs %d", 
> (long long) v,
>                   g->tm_wday, w);
> +  grub_test_assert (back == v, "time %lld bad back transform: %lld", (long 
> long) v,
> +                   (long long) back);
>  }
>
>  static void
>  date_test_iter (void)
>  {
> -  grub_int32_t tests[] = { -1, 0, +1, -2133156255, GRUB_INT32_MIN,
> +  /*
> +   * Test several interesting UNIX timestamps in 32-bit time:
> +   *   1.             -1: 1969-12-31 23:59:59 - Just before EPOCH
> +   *   2.              0: 1970-01-01 00:00:00 - EPOCH
> +   *   3.             +1: 1970-01-01 00:00:01 - Just after EPOCH
> +   *   4.      978224552: 2000-12-31 01:02:32 - Leap year, prior to Feb

s/prior/after/?

> +   *   5.    -2133156255: 1902-05-28 16:35:45 - Nominal value
> +   *   6.    -2110094321: 1903-02-19 14:41:19 - Nominal value
> +   *   7. GRUB_INT32_MIN: 1901-12-13 20:45:52 - 32-bit Min value
> +   *   8. GRUB_INT32_MAX: 2038-01-19 03:14:07 - 32-bit Max value
> +   */
> +  grub_int32_t tests[] = { -1, 0, +1, 978224552, -2133156255, -2110094321, 
> GRUB_INT32_MIN,
>                          GRUB_INT32_MAX };

Otherwise LGTM...

When you fix the issue above you can add my RB...

Daniel

_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to