[tip: timers/core] time/kunit: Add time64_to_tm() case beyond 32-bit day count
From: tip-bot2 for Karl Mehltretter
Date: Tue Sep 29 2026 - 15:24:03 EST
The following commit has been merged into the timers/core branch of tip:
Commit-ID: 3945c4a3ea151f777b4b098ebeecd2f85c20244f
Gitweb: https://git.kernel.org/tip/3945c4a3ea151f777b4b098ebeecd2f85c20244f
Author: Karl Mehltretter <kmehltretter@xxxxxxxxx>
AuthorDate: Fri, 25 Sep 2026 18:57:02 +02:00
Committer: Thomas Gleixner <tglx@xxxxxxxxxx>
CommitterDate: Tue, 29 Sep 2026 21:18:42 +02:00
time/kunit: Add time64_to_tm() case beyond 32-bit day count
The existing date range test covers +/-80,000 years around the epoch,
far below the day count at which a 32-bit long wraps (2^31 days,
roughly 5.88 million years).
Add a case at exactly 2^31 days after the epoch. Without the preceding
fix a 32-bit kernel returns tm_year=-5879541 and wrong month, day,
day-of-year and weekday; with it the result matches 64-bit kernels.
Signed-off-by: Karl Mehltretter <kmehltretter@xxxxxxxxx>
Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxx>
Assisted-by: LLM
Reviewed-by: Thomas Weißschuh <thomas.weissschuh@xxxxxxxxxxxxx>
Link: https://patch.msgid.link/20260925165702.51677-3-kmehltretter@xxxxxxxxx
---
kernel/time/time_test.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/kernel/time/time_test.c b/kernel/time/time_test.c
index 1b99180..8b71876 100644
--- a/kernel/time/time_test.c
+++ b/kernel/time/time_test.c
@@ -87,8 +87,24 @@ static void time64_to_tm_test_date_range(struct kunit *test)
}
}
+static void time64_to_tm_test_wide_day_count(struct kunit *test)
+{
+ /* 2^31 days: the first count that does not fit in a 32-bit long. */
+ time64_t timestamp = (1LL << 31) * 86400;
+ struct tm result;
+
+ time64_to_tm(timestamp, 0, &result);
+
+ KUNIT_EXPECT_EQ(test, result.tm_year, 5879680);
+ KUNIT_EXPECT_EQ(test, result.tm_mon, 6);
+ KUNIT_EXPECT_EQ(test, result.tm_mday, 12);
+ KUNIT_EXPECT_EQ(test, result.tm_yday, 193);
+ KUNIT_EXPECT_EQ(test, result.tm_wday, 6);
+}
+
static struct kunit_case time_test_cases[] = {
KUNIT_CASE_SLOW(time64_to_tm_test_date_range),
+ KUNIT_CASE(time64_to_tm_test_wide_day_count),
{}
};