Fix wrong libevdev clock test
authorDavid Herrmann <dh.herrmann@gmail.com>
Mon, 28 Oct 2013 16:16:43 +0000 (17:16 +0100)
committerPeter Hutterer <peter.hutterer@who-t.net>
Thu, 31 Oct 2013 01:23:13 +0000 (11:23 +1000)
We can rely on CLOCK_MONOTONIC and CLOCK_REALTIME to be different at any
time. However, this does not apply to the ms/us/ns parts of the current
time. Both may be in sync regarding the current micro-seconds state. So
remove the wrong clock us-comparison.

I was able to trigger this on my machine. Chances that both are in sync
are very low so I assume my RTC only provides low granularity and thus
both clocks are sync during boot for higher granularity.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
test/test-libevdev-init.c

index 7d4376d196b37c47c08232c11e4518224f08324e..bf0b87437c6f414a39895584d948202ae0e96bed 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <config.h>
 #include <errno.h>
+#include <inttypes.h>
 #include <unistd.h>
 #include <time.h>
 #include <sys/types.h>
@@ -304,6 +305,7 @@ START_TEST(test_clock_id_events)
        struct input_event ev1, ev2;
        struct timespec t1_real, t2_real;
        struct timespec t1_mono, t2_mono;
+       int64_t t1, t2;
 
        rc = test_create_device(&uidev, &dev,
                                EV_SYN, SYN_REPORT,
@@ -342,8 +344,9 @@ START_TEST(test_clock_id_events)
        ck_assert_int_eq(ev1.code, ev2.code);
        ck_assert_int_eq(ev1.value, ev2.value);
 
-       ck_assert_int_ne(ev1.time.tv_sec, ev2.time.tv_sec);
-       ck_assert_int_ne(ev1.time.tv_usec, ev2.time.tv_usec);
+       t1 = ev1.time.tv_sec * 1000000LL + ev1.time.tv_usec;
+       t2 = ev2.time.tv_sec * 1000000LL + ev2.time.tv_usec;
+       ck_assert_int_ne(t1, t2);
 
        ck_assert_int_ge(ev1.time.tv_sec, t1_real.tv_sec);
        ck_assert_int_ge(ev1.time.tv_usec, t1_real.tv_nsec/1000);