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.weisssc...@linutronix.de>
---
 tools/testing/selftests/vDSO/vdso_test_abi.c | 37 +++++++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/vDSO/vdso_test_abi.c 
b/tools/testing/selftests/vDSO/vdso_test_abi.c
index 
c25f09998b82d797d690228e6ff026150b28934b..238d609a457a281d802734b40d6a2c35ba7f6d72
 100644
--- a/tools/testing/selftests/vDSO/vdso_test_abi.c
+++ b/tools/testing/selftests/vDSO/vdso_test_abi.c
@@ -26,8 +26,15 @@
 static const char *version;
 static const char **name;
 
+/* The same as struct __kernel_timespec */
+struct vdso_timespec64 {
+       uint64_t tv_sec;
+       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_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);
 
@@ -70,6 +77,33 @@ static void vdso_test_gettimeofday(void)
        }
 }
 
+static void vdso_test_clock_gettime64(clockid_t clk_id)
+{
+       /* Find clock_gettime64. */
+       vdso_clock_gettime64_t vdso_clock_gettime64 =
+               (vdso_clock_gettime64_t)vdso_sym(version, name[5]);
+
+       if (!vdso_clock_gettime64) {
+               ksft_print_msg("Couldn't find %s\n", name[5]);
+               ksft_test_result_skip("%s %s\n", name[5],
+                                     vdso_clock_name[clk_id]);
+               return;
+       }
+
+       struct vdso_timespec64 ts;
+       long ret = VDSO_CALL(vdso_clock_gettime64, 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_test_result_pass("%s %s\n", name[5],
+                                     vdso_clock_name[clk_id]);
+       } else {
+               ksft_test_result_fail("%s %s\n", name[5],
+                                     vdso_clock_name[clk_id]);
+       }
+}
+
 static void vdso_test_clock_gettime(clockid_t clk_id)
 {
        /* Find clock_gettime. */
@@ -171,11 +205,12 @@ static inline void vdso_test_clock(clockid_t clock_id)
        ksft_print_msg("clock_id: %s\n", vdso_clock_name[clock_id]);
 
        vdso_test_clock_gettime(clock_id);
+       vdso_test_clock_gettime64(clock_id);
 
        vdso_test_clock_getres(clock_id);
 }
 
-#define VDSO_TEST_PLAN 20
+#define VDSO_TEST_PLAN 29
 
 int main(int argc, char **argv)
 {

-- 
2.50.1


Reply via email to