Skip to content

Commit 7262aa7

Browse files
t-8chKAGA-KOKO
authored andcommitted
selftests: vDSO: vdso_test_abi: Add tests for clock_gettime64()
To be y2038-safe, 32-bit userspace needs to explicitly call the 64-bit safe time APIs. For this the 32-bit vDSOs contains a clock_gettime() variant which always uses 64-bit time types. Also test this vDSO function. Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Link: https://lore.kernel.org/all/20250812-vdso-tests-fixes-v2-7-90f499dd35f8@linutronix.de
1 parent 7b87dbf commit 7262aa7

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

tools/testing/selftests/vDSO/vdso_test_abi.c

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,15 @@
2626
static const char *version;
2727
static const char **name;
2828

29+
/* The same as struct __kernel_timespec */
30+
struct vdso_timespec64 {
31+
uint64_t tv_sec;
32+
uint64_t tv_nsec;
33+
};
34+
2935
typedef long (*vdso_gettimeofday_t)(struct timeval *tv, struct timezone *tz);
3036
typedef long (*vdso_clock_gettime_t)(clockid_t clk_id, struct timespec *ts);
37+
typedef long (*vdso_clock_gettime64_t)(clockid_t clk_id, struct vdso_timespec64 *ts);
3138
typedef long (*vdso_clock_getres_t)(clockid_t clk_id, struct timespec *ts);
3239
typedef time_t (*vdso_time_t)(time_t *t);
3340

@@ -70,6 +77,33 @@ static void vdso_test_gettimeofday(void)
7077
}
7178
}
7279

80+
static void vdso_test_clock_gettime64(clockid_t clk_id)
81+
{
82+
/* Find clock_gettime64. */
83+
vdso_clock_gettime64_t vdso_clock_gettime64 =
84+
(vdso_clock_gettime64_t)vdso_sym(version, name[5]);
85+
86+
if (!vdso_clock_gettime64) {
87+
ksft_print_msg("Couldn't find %s\n", name[5]);
88+
ksft_test_result_skip("%s %s\n", name[5],
89+
vdso_clock_name[clk_id]);
90+
return;
91+
}
92+
93+
struct vdso_timespec64 ts;
94+
long ret = VDSO_CALL(vdso_clock_gettime64, 2, clk_id, &ts);
95+
96+
if (ret == 0) {
97+
ksft_print_msg("The time is %lld.%06lld\n",
98+
(long long)ts.tv_sec, (long long)ts.tv_nsec);
99+
ksft_test_result_pass("%s %s\n", name[5],
100+
vdso_clock_name[clk_id]);
101+
} else {
102+
ksft_test_result_fail("%s %s\n", name[5],
103+
vdso_clock_name[clk_id]);
104+
}
105+
}
106+
73107
static void vdso_test_clock_gettime(clockid_t clk_id)
74108
{
75109
/* Find clock_gettime. */
@@ -171,11 +205,12 @@ static inline void vdso_test_clock(clockid_t clock_id)
171205
ksft_print_msg("clock_id: %s\n", vdso_clock_name[clock_id]);
172206

173207
vdso_test_clock_gettime(clock_id);
208+
vdso_test_clock_gettime64(clock_id);
174209

175210
vdso_test_clock_getres(clock_id);
176211
}
177212

178-
#define VDSO_TEST_PLAN 20
213+
#define VDSO_TEST_PLAN 29
179214

180215
int main(int argc, char **argv)
181216
{

0 commit comments

Comments
 (0)