[PATCH] selftests: net: fix format warnings on 32-bit architectures

From: Sasha Levin

Date: Tue Nov 03 2026 - 11:43:50 EST


On 32-bit architectures ssize_t is an int, tv_sec is a long long with a
64-bit time_t, and uint64_t is not a size_t, so ipsec, txtimestamp and
the tcp_ao library warn when printing them with %ld, %lu and %zu:

txtimestamp.c:191:42: warning: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type '__time64_t' {aka 'long long int'} [-Wformat=]

Print ssize_t with %zd, tv_sec as long long, and the net namespace
cookies with PRIu64 as the rest of ftrace-tcp.c already does. 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@xxxxxxxxxx>
---
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.

tools/testing/selftests/net/ipsec.c | 2 +-
tools/testing/selftests/net/tcp_ao/lib/ftrace-tcp.c | 2 +-
tools/testing/selftests/net/txtimestamp.c | 9 +++++----
3 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/tools/testing/selftests/net/ipsec.c b/tools/testing/selftests/net/ipsec.c
index 89c32c354c008..ba8c36a93f176 100644
--- a/tools/testing/selftests/net/ipsec.c
+++ b/tools/testing/selftests/net/ipsec.c
@@ -2030,7 +2030,7 @@ static int __write_desc(int test_desc_fd, struct xfrm_desc *desc)
if (ret == sizeof(*desc))
return 0;

- pr_err("Writing test's desc failed %ld", ret);
+ pr_err("Writing test's desc failed %zd", ret);

return -1;
}
diff --git a/tools/testing/selftests/net/tcp_ao/lib/ftrace-tcp.c b/tools/testing/selftests/net/tcp_ao/lib/ftrace-tcp.c
index 27403f8750547..cd93ff8965dda 100644
--- a/tools/testing/selftests/net/tcp_ao/lib/ftrace-tcp.c
+++ b/tools/testing/selftests/net/tcp_ao/lib/ftrace-tcp.c
@@ -504,7 +504,7 @@ static int setup_tcp_trace_events(struct test_ftracer *tracer)
size_t i;
int ret;

- filter = test_sprintf("net_cookie == %zu || net_cookie == %zu",
+ filter = test_sprintf("net_cookie == %" PRIu64 " || net_cookie == %" PRIu64,
ns_cookie1, ns_cookie2);
if (!filter)
return -ENOMEM;
diff --git a/tools/testing/selftests/net/txtimestamp.c b/tools/testing/selftests/net/txtimestamp.c
index f7bdf30b78d9f..be1452d73b303 100644
--- a/tools/testing/selftests/net/txtimestamp.c
+++ b/tools/testing/selftests/net/txtimestamp.c
@@ -188,12 +188,13 @@ static void __print_timestamp(const char *name, struct timespec *cur,
return;

if (cfg_print_nsec)
- fprintf(stderr, " %s: %lu s %lu ns (seq=%u, len=%u)",
- name, cur->tv_sec, cur->tv_nsec,
+ fprintf(stderr, " %s: %lld s %ld ns (seq=%u, len=%u)",
+ name, (long long)cur->tv_sec, (long)cur->tv_nsec,
key, payload_len);
else
- fprintf(stderr, " %s: %lu s %lu us (seq=%u, len=%u)",
- name, cur->tv_sec, cur->tv_nsec / NSEC_PER_USEC,
+ fprintf(stderr, " %s: %lld s %ld us (seq=%u, len=%u)",
+ name, (long long)cur->tv_sec,
+ (long)(cur->tv_nsec / NSEC_PER_USEC),
key, payload_len);

if (cur != &ts_usr) {
--
2.53.0