From 65507ee3bb5d8e650e7376c4a57860c3e7069364 Mon Sep 17 00:00:00 2001
From: Anders Roxell <anders.roxell@linaro.org>
Date: Sat, 15 Nov 2025 18:28:24 +0100
Subject: [PATCH 4/5] selftests: vdso: Convert vdso_test_abi.c to use kernel
 time types

Convert vDSO ABI tests to use kernel-specific time types instead of libc
types to properly test the kernel vDSO interface directly.

Add the necessary kernel headers (asm/posix_types.h, linux/types.h,
linux/time_types.h, errno.h) and convert all type references:
- struct timeval/timespec -> __kernel_old_timeval/__kernel_old_timespec
- time_t -> __kernel_old_time_t

Update format specifiers to match kernel types (%ld instead of %lld for
old kernel types which are long, not long long) and adjust casts
accordingly.

This ensures the tests directly exercise the kernel vDSO functions
without going through libc wrappers, providing more accurate testing of
the kernel implementation.

Signed-off-by: Anders Roxell <anders.roxell@linaro.org>
---
 tools/testing/selftests/vDSO/vdso_test_abi.c | 41 +++++++++++---------
 1 file changed, 22 insertions(+), 19 deletions(-)

diff --git a/tools/testing/selftests/vDSO/vdso_test_abi.c b/tools/testing/selftests/vDSO/vdso_test_abi.c
index 819e0593f955..c7b056c9838b 100644
--- a/tools/testing/selftests/vDSO/vdso_test_abi.c
+++ b/tools/testing/selftests/vDSO/vdso_test_abi.c
@@ -12,6 +12,7 @@
 #include <elf.h>
 #include <stdio.h>
 #include <time.h>
+#include <errno.h>
 #include <sys/auxv.h>
 #include <sys/time.h>
 #define _GNU_SOURCE
@@ -22,6 +23,9 @@
 #include "vdso_config.h"
 #include "vdso_call.h"
 #include "parse_vdso.h"
+#include <asm/posix_types.h>
+#include <linux/types.h>
+#include <linux/time_types.h>
 
 static const char *version;
 static const char **name;
@@ -32,11 +36,11 @@ struct vdso_timespec64 {
 	uint64_t tv_nsec;
 };
 
-typedef long (*vdso_gettimeofday_t)(struct timeval *tv, struct timezone *tz);
-typedef long (*vdso_clock_gettime_t)(clockid_t clk_id, struct timespec *ts);
+typedef long (*vdso_gettimeofday_t)(struct __kernel_old_timeval *tv, struct timezone *tz);
+typedef long (*vdso_clock_gettime_t)(clockid_t clk_id, struct __kernel_old_timespec *ts);
 typedef long (*vdso_clock_gettime64_t)(clockid_t clk_id, struct vdso_timespec64 *ts);
-typedef long (*vdso_clock_getres_t)(clockid_t clk_id, struct timespec *ts);
-typedef time_t (*vdso_time_t)(time_t *t);
+typedef long (*vdso_clock_getres_t)(clockid_t clk_id, struct __kernel_old_timespec *ts);
+typedef __kernel_old_time_t (*vdso_time_t)(__kernel_old_time_t *t);
 
 static const char * const vdso_clock_name[] = {
 	[CLOCK_REALTIME]		= "CLOCK_REALTIME",
@@ -65,12 +69,12 @@ static void vdso_test_gettimeofday(void)
 		return;
 	}
 
-	struct timeval tv;
+	struct __kernel_old_timeval tv;
 	long ret = VDSO_CALL(vdso_gettimeofday, 2, &tv, 0);
 
 	if (ret == 0) {
-		ksft_print_msg("The time is %lld.%06lld\n",
-			       (long long)tv.tv_sec, (long long)tv.tv_usec);
+		ksft_print_msg("The time is %ld.%06ld\n",
+			       (long)tv.tv_sec, (long)tv.tv_usec);
 		ksft_test_result_pass("%s\n", name[0]);
 	} else {
 		ksft_test_result_fail("%s\n", name[0]);
@@ -117,12 +121,12 @@ static void vdso_test_clock_gettime(clockid_t clk_id)
 		return;
 	}
 
-	struct timespec ts;
+	struct __kernel_old_timespec ts;
 	long ret = VDSO_CALL(vdso_clock_gettime, 2, clk_id, &ts);
 
 	if (ret == 0) {
-		ksft_print_msg("The time is %lld.%06lld\n",
-			       (long long)ts.tv_sec, (long long)ts.tv_nsec);
+		ksft_print_msg("The time is %ld.%06ld\n",
+			       ts.tv_sec, ts.tv_nsec);
 		ksft_test_result_pass("%s %s\n", name[1],
 				      vdso_clock_name[clk_id]);
 	} else {
@@ -143,11 +147,11 @@ static void vdso_test_time(void)
 		return;
 	}
 
-	long ret = VDSO_CALL(vdso_time, 1, NULL);
+	__kernel_old_time_t ret = VDSO_CALL(vdso_time, 1, NULL);
 
 	if (ret > 0) {
-		ksft_print_msg("The time in hours since January 1, 1970 is %lld\n",
-				(long long)(ret / 3600));
+		ksft_print_msg("The time in hours since January 1, 1970 is %ld\n",
+				(ret / 3600));
 		ksft_test_result_pass("%s\n", name[2]);
 	} else {
 		ksft_test_result_fail("%s\n", name[2]);
@@ -169,20 +173,20 @@ static void vdso_test_clock_getres(clockid_t clk_id)
 		return;
 	}
 
-	struct timespec ts, sys_ts;
+	struct __kernel_old_timespec ts, sys_ts;
 	long ret = VDSO_CALL(vdso_clock_getres, 2, clk_id, &ts);
 
 	if (ret == 0) {
-		ksft_print_msg("The vdso resolution is %lld %lld\n",
-			       (long long)ts.tv_sec, (long long)ts.tv_nsec);
+		ksft_print_msg("The vdso resolution is %ld %ld\n",
+			       (long)ts.tv_sec, (long)ts.tv_nsec);
 	} else {
 		clock_getres_fail++;
 	}
 
 	ret = syscall(SYS_clock_getres, clk_id, &sys_ts);
 
-	ksft_print_msg("The syscall resolution is %lld %lld\n",
-			(long long)sys_ts.tv_sec, (long long)sys_ts.tv_nsec);
+	ksft_print_msg("The clock_getres resolution is %ld %ld\n",
+			sys_ts.tv_sec, sys_ts.tv_nsec);
 
 	if ((sys_ts.tv_sec != ts.tv_sec) || (sys_ts.tv_nsec != ts.tv_nsec))
 		clock_getres_fail++;
@@ -246,7 +250,6 @@ static inline void vdso_test_clock(clockid_t clock_id)
 	/* Test vDSO functions directly */
 	vdso_test_clock_gettime(clock_id);
 	vdso_test_clock_gettime64(clock_id);
-
 	vdso_test_clock_getres(clock_id);
 
 	/* Test libc wrappers */
-- 
2.51.0

