mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] selftests: vDSO: print tv_sec as long long in vdso_test_getrandom
@ 2026-11-03 15:55 Sasha Levin
  2026-11-03 16:24 ` Jason A. Donenfeld
  0 siblings, 1 reply; 2+ messages in thread
From: Sasha Levin @ 2026-11-03 15:55 UTC (permalink / raw)
  To: Andy Lutomirski, Thomas Gleixner, Vincenzo Frascino
  Cc: Jason A . Donenfeld, Thomas Weißschuh, Shuah Khan,
	linux-kselftest, linux-kernel

On 32-bit architectures with a 64-bit time_t, such as armhf in Debian
13, tv_sec is a long long, and printing it with %lu warns:

  vdso_test_getrandom.c:184:40: warning: format '%lu' expects argument of type 'long unsigned int', but argument 3 has type '__time64_t' {aka 'long long int'} [-Wformat=]

Cast it to long long and print it with %lld. While at it, print tv_nsec,
a long, with %ld instead of %lu, and cast it to long, as it is a long
long on x32.

Signed-off-by: Sasha Levin <sashal@kernel.org>
---
Found with a 32-bit build of the selftests with a 64-bit time_t (gcc 16
and clang 21 with -m32 -D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64);
KernelCI's 32-bit arm builds show the same warnings. The changed files
build without format warnings there now, and the x86_64 builds don't
change. The other selftests get the same kind of fix in separate
patches.

 .../selftests/vDSO/vdso_test_getrandom.c       | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/tools/testing/selftests/vDSO/vdso_test_getrandom.c b/tools/testing/selftests/vDSO/vdso_test_getrandom.c
index ef402001e8988..504b84d4cc53e 100644
--- a/tools/testing/selftests/vDSO/vdso_test_getrandom.c
+++ b/tools/testing/selftests/vDSO/vdso_test_getrandom.c
@@ -181,19 +181,22 @@ static void bench_single(void)
 	test_vdso_getrandom(NULL);
 	clock_gettime(CLOCK_MONOTONIC, &end);
 	timespecsub(&end, &start, &diff);
-	printf("   vdso: %u times in %lu.%09lu seconds\n", TRIALS, diff.tv_sec, diff.tv_nsec);
+	printf("   vdso: %u times in %lld.%09ld seconds\n", TRIALS,
+	       (long long)diff.tv_sec, (long)diff.tv_nsec);
 
 	clock_gettime(CLOCK_MONOTONIC, &start);
 	test_libc_getrandom(NULL);
 	clock_gettime(CLOCK_MONOTONIC, &end);
 	timespecsub(&end, &start, &diff);
-	printf("   libc: %u times in %lu.%09lu seconds\n", TRIALS, diff.tv_sec, diff.tv_nsec);
+	printf("   libc: %u times in %lld.%09ld seconds\n", TRIALS,
+	       (long long)diff.tv_sec, (long)diff.tv_nsec);
 
 	clock_gettime(CLOCK_MONOTONIC, &start);
 	test_syscall_getrandom(NULL);
 	clock_gettime(CLOCK_MONOTONIC, &end);
 	timespecsub(&end, &start, &diff);
-	printf("syscall: %u times in %lu.%09lu seconds\n", TRIALS, diff.tv_sec, diff.tv_nsec);
+	printf("syscall: %u times in %lld.%09ld seconds\n", TRIALS,
+	       (long long)diff.tv_sec, (long)diff.tv_nsec);
 }
 
 static void bench_multi(void)
@@ -208,7 +211,8 @@ static void bench_multi(void)
 		pthread_join(threads[i], NULL);
 	clock_gettime(CLOCK_MONOTONIC, &end);
 	timespecsub(&end, &start, &diff);
-	printf("   vdso: %u x %u times in %lu.%09lu seconds\n", TRIALS, THREADS, diff.tv_sec, diff.tv_nsec);
+	printf("   vdso: %u x %u times in %lld.%09ld seconds\n", TRIALS, THREADS,
+	       (long long)diff.tv_sec, (long)diff.tv_nsec);
 
 	clock_gettime(CLOCK_MONOTONIC, &start);
 	for (size_t i = 0; i < THREADS; ++i)
@@ -217,7 +221,8 @@ static void bench_multi(void)
 		pthread_join(threads[i], NULL);
 	clock_gettime(CLOCK_MONOTONIC, &end);
 	timespecsub(&end, &start, &diff);
-	printf("   libc: %u x %u times in %lu.%09lu seconds\n", TRIALS, THREADS, diff.tv_sec, diff.tv_nsec);
+	printf("   libc: %u x %u times in %lld.%09ld seconds\n", TRIALS, THREADS,
+	       (long long)diff.tv_sec, (long)diff.tv_nsec);
 
 	clock_gettime(CLOCK_MONOTONIC, &start);
 	for (size_t i = 0; i < THREADS; ++i)
@@ -226,7 +231,8 @@ static void bench_multi(void)
 		pthread_join(threads[i], NULL);
 	clock_gettime(CLOCK_MONOTONIC, &end);
 	timespecsub(&end, &start, &diff);
-	printf("   syscall: %u x %u times in %lu.%09lu seconds\n", TRIALS, THREADS, diff.tv_sec, diff.tv_nsec);
+	printf("   syscall: %u x %u times in %lld.%09ld seconds\n", TRIALS, THREADS,
+	       (long long)diff.tv_sec, (long)diff.tv_nsec);
 }
 
 static void fill(void)
-- 
2.53.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] selftests: vDSO: print tv_sec as long long in vdso_test_getrandom
  2026-11-03 15:55 [PATCH] selftests: vDSO: print tv_sec as long long in vdso_test_getrandom Sasha Levin
@ 2026-11-03 16:24 ` Jason A. Donenfeld
  0 siblings, 0 replies; 2+ messages in thread
From: Jason A. Donenfeld @ 2026-11-03 16:24 UTC (permalink / raw)
  To: Sasha Levin
  Cc: Andy Lutomirski, Thomas Gleixner, Vincenzo Frascino,
	Thomas Weißschuh, Shuah Khan, linux-kselftest, linux-kernel

Thanks. I can take this through my random tree, unless the vDSO people want it.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-03 16:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-03 15:55 [PATCH] selftests: vDSO: print tv_sec as long long in vdso_test_getrandom Sasha Levin
2026-11-03 16:24 ` Jason A. Donenfeld

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®