[PATCH 2/4] time: test: Avoid unnecessary divisions in time64_to_tm() test

From: Thomas Weißschuh (Schneider Electric)

Date: Thu Sep 03 2026 - 04:25:43 EST


The time64_to_tm_test_date_range() test case is slow.
One big part of this slowness is the division done in the test loop to
calculate the current day from the current seconds. As each test loop
advances the time by one day, that division can be avoided.

Remove the division and instead increment the 'days' variable directly.

This brings the test's runtime from 30 seconds down to 15 seconds in an
emulated 32-bit ARM machine.

Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@xxxxxxxxxxxxx>
---
kernel/time/time_test.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/time/time_test.c b/kernel/time/time_test.c
index 1b99180da288..70b20c5c7336 100644
--- a/kernel/time/time_test.c
+++ b/kernel/time/time_test.c
@@ -69,12 +69,12 @@ static void time64_to_tm_test_date_range(struct kunit *test)
time64_t secs;
s64 days;

- for (secs = -total_secs; secs <= total_secs; secs += 86400) {
+ for (secs = -total_secs, days = div_s64(secs, 86400);
+ secs <= total_secs;
+ secs += 86400, days++) {

time64_to_tm(secs, 0, &result);

- days = div_s64(secs, 86400);
-
#define FAIL_MSG "%05ld/%02d/%02d (%2d) : %lld", \
year, month, mdday, yday, days


--
2.55.0