selftests: vDSO: print tv_sec as long long in vdso_test_getrandom
Subsystems (2)
PATCH 1/1 selftests: vDSO: print tv_sec as long long in vdso_test_getrandom
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.
---
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(-)
tools/testing/selftests/vDSO/vdso_test_getrandom.c +12 -6
@@ -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 )
Signature · 1 line
2.53.0
Thanks. I can take this through my random tree, unless the vDSO people want it.