Upcoming changes will shuffle around the timespec and timeval types.
To keep ts_leq() and tv_leq() working with all of those types, transform
them into macros.

Also drop ts64_leq() as it can now be replaced by the regular ts_leq().

Signed-off-by: Thomas Weißschuh <[email protected]>
---
 .../testing/selftests/vDSO/vdso_test_correctness.c | 47 ++++++++++------------
 1 file changed, 22 insertions(+), 25 deletions(-)

diff --git a/tools/testing/selftests/vDSO/vdso_test_correctness.c 
b/tools/testing/selftests/vDSO/vdso_test_correctness.c
index 
66cd1d4c19872e78c0e608f5e0fb5215cf902b50..5a127fc93e7368cbe8d9fb4a4482a6a735ffd46c
 100644
--- a/tools/testing/selftests/vDSO/vdso_test_correctness.c
+++ b/tools/testing/selftests/vDSO/vdso_test_correctness.c
@@ -213,30 +213,27 @@ static void test_getcpu(void)
        }
 }
 
-static bool ts_leq(const struct timespec *a, const struct timespec *b)
-{
-       if (a->tv_sec != b->tv_sec)
-               return a->tv_sec < b->tv_sec;
-       else
-               return a->tv_nsec <= b->tv_nsec;
-}
-
-static bool ts64_leq(const struct __kernel_timespec *a,
-                    const struct __kernel_timespec *b)
-{
-       if (a->tv_sec != b->tv_sec)
-               return a->tv_sec < b->tv_sec;
-       else
-               return a->tv_nsec <= b->tv_nsec;
-}
-
-static bool tv_leq(const struct timeval *a, const struct timeval *b)
-{
-       if (a->tv_sec != b->tv_sec)
-               return a->tv_sec < b->tv_sec;
-       else
-               return a->tv_usec <= b->tv_usec;
-}
+#define ts_leq(_a, _b) ({                              \
+       bool _ret;                                      \
+                                                       \
+       if ((_a)->tv_sec != (_b)->tv_sec)               \
+               _ret = (_a)->tv_sec < (_b)->tv_sec;     \
+       else                                            \
+               _ret = (_a)->tv_nsec <= (_b)->tv_nsec;  \
+                                                       \
+       _ret;                                           \
+})
+
+#define tv_leq(_a, _b) ({                              \
+       bool _ret;                                      \
+                                                       \
+       if ((_a)->tv_sec != (_b)->tv_sec)               \
+               _ret = (_a)->tv_sec < (_b)->tv_sec;     \
+       else                                            \
+               _ret = (_a)->tv_usec <= (_b)->tv_usec;  \
+                                                       \
+       _ret;                                           \
+})
 
 static char const * const clocknames[] = {
        [0] = "CLOCK_REALTIME",
@@ -352,7 +349,7 @@ static void test_one_clock_gettime64(int clock, const char 
*name)
               (unsigned long long)vdso.tv_sec, vdso.tv_nsec,
               (unsigned long long)end.tv_sec, end.tv_nsec);
 
-       if (!ts64_leq(&start, &vdso) || !ts64_leq(&vdso, &end)) {
+       if (!ts_leq(&start, &vdso) || !ts_leq(&vdso, &end)) {
                printf("[FAIL]\tTimes are out of sequence\n");
                nerrs++;
                return;

-- 
2.51.0


Reply via email to