Skip to content

Commit 4e6a231

Browse files
t-8chThomas Gleixner
authored andcommitted
selftests: vDSO: vdso_test_abi: Add test for clock_getres_time64()
Some architectures will start to implement this function. Make sure it works correctly. Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de> Signed-off-by: Thomas Gleixner <tglx@kernel.org> Link: https://patch.msgid.link/20251223-vdso-compat-time32-v1-4-97ea7a06a543@linutronix.de
1 parent 1dcd127 commit 4e6a231

1 file changed

Lines changed: 52 additions & 1 deletion

File tree

tools/testing/selftests/vDSO/vdso_test_abi.c

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ typedef long (*vdso_gettimeofday_t)(struct timeval *tv, struct timezone *tz);
3636
typedef long (*vdso_clock_gettime_t)(clockid_t clk_id, struct timespec *ts);
3737
typedef long (*vdso_clock_gettime64_t)(clockid_t clk_id, struct vdso_timespec64 *ts);
3838
typedef long (*vdso_clock_getres_t)(clockid_t clk_id, struct timespec *ts);
39+
typedef long (*vdso_clock_getres_time64_t)(clockid_t clk_id, struct vdso_timespec64 *ts);
3940
typedef time_t (*vdso_time_t)(time_t *t);
4041

4142
static const char * const vdso_clock_name[] = {
@@ -196,6 +197,55 @@ static void vdso_test_clock_getres(clockid_t clk_id)
196197
}
197198
}
198199

200+
#ifdef __NR_clock_getres_time64
201+
static void vdso_test_clock_getres_time64(clockid_t clk_id)
202+
{
203+
int clock_getres_fail = 0;
204+
205+
/* Find clock_getres. */
206+
vdso_clock_getres_time64_t vdso_clock_getres_time64 =
207+
(vdso_clock_getres_time64_t)vdso_sym(version, name[7]);
208+
209+
if (!vdso_clock_getres_time64) {
210+
ksft_print_msg("Couldn't find %s\n", name[7]);
211+
ksft_test_result_skip("%s %s\n", name[7],
212+
vdso_clock_name[clk_id]);
213+
return;
214+
}
215+
216+
struct vdso_timespec64 ts, sys_ts;
217+
long ret = VDSO_CALL(vdso_clock_getres_time64, 2, clk_id, &ts);
218+
219+
if (ret == 0) {
220+
ksft_print_msg("The vdso resolution is %lld %lld\n",
221+
(long long)ts.tv_sec, (long long)ts.tv_nsec);
222+
} else {
223+
clock_getres_fail++;
224+
}
225+
226+
ret = syscall(__NR_clock_getres_time64, clk_id, &sys_ts);
227+
228+
ksft_print_msg("The syscall resolution is %lld %lld\n",
229+
(long long)sys_ts.tv_sec, (long long)sys_ts.tv_nsec);
230+
231+
if ((sys_ts.tv_sec != ts.tv_sec) || (sys_ts.tv_nsec != ts.tv_nsec))
232+
clock_getres_fail++;
233+
234+
if (clock_getres_fail > 0) {
235+
ksft_test_result_fail("%s %s\n", name[7],
236+
vdso_clock_name[clk_id]);
237+
} else {
238+
ksft_test_result_pass("%s %s\n", name[7],
239+
vdso_clock_name[clk_id]);
240+
}
241+
}
242+
#else /* !__NR_clock_getres_time64 */
243+
static void vdso_test_clock_getres_time64(clockid_t clk_id)
244+
{
245+
ksft_test_result_skip("%s %s\n", name[7], vdso_clock_name[clk_id]);
246+
}
247+
#endif /* __NR_clock_getres_time64 */
248+
199249
/*
200250
* This function calls vdso_test_clock_gettime and vdso_test_clock_getres
201251
* with different values for clock_id.
@@ -208,9 +258,10 @@ static inline void vdso_test_clock(clockid_t clock_id)
208258
vdso_test_clock_gettime64(clock_id);
209259

210260
vdso_test_clock_getres(clock_id);
261+
vdso_test_clock_getres_time64(clock_id);
211262
}
212263

213-
#define VDSO_TEST_PLAN 29
264+
#define VDSO_TEST_PLAN 38
214265

215266
int main(int argc, char **argv)
216267
{

0 commit comments

Comments
 (0)