summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAlexandros Frantzis <alexandros.frantzis@collabora.com>2017-12-13 13:27:54 +0200
committerPekka Paalanen <pekka.paalanen@collabora.co.uk>2017-12-18 11:27:43 +0200
commit10d708d2688f26c17b3f009fcc681174d9877166 (patch)
tree53f4a6d0798d904dd9fcb1973645eb9df6fd704d /tests
parent787fa611de1b7c4144b7491260c513a5ec0a4728 (diff)
shared: Add timespec_to_proto helper function
Add helper function to convert from struct timespec values to tv_sec_hi, tv_sec_lo, tv_nsec triplets used for sending high-resolution timestamp data over the wayland protocol. Replace existing conversion code with the helper function. Signed-off-by: Alexandros Frantzis <alexandros.frantzis@collabora.com> Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Diffstat (limited to 'tests')
-rw-r--r--tests/timespec-test.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/timespec-test.c b/tests/timespec-test.c
index a4d8dcfb..54230f89 100644
--- a/tests/timespec-test.c
+++ b/tests/timespec-test.c
@@ -79,6 +79,35 @@ ZUC_TEST(timespec_test, timespec_to_msec)
ZUC_ASSERT_EQ(timespec_to_msec(&a), (4000ULL) + 4);
}
+ZUC_TEST(timespec_test, timespec_to_proto)
+{
+ struct timespec a;
+ uint32_t tv_sec_hi;
+ uint32_t tv_sec_lo;
+ uint32_t tv_nsec;
+
+ a.tv_sec = 0;
+ a.tv_nsec = 0;
+ timespec_to_proto(&a, &tv_sec_hi, &tv_sec_lo, &tv_nsec);
+ ZUC_ASSERT_EQ(0, tv_sec_hi);
+ ZUC_ASSERT_EQ(0, tv_sec_lo);
+ ZUC_ASSERT_EQ(0, tv_nsec);
+
+ a.tv_sec = 1234;
+ a.tv_nsec = NSEC_PER_SEC - 1;
+ timespec_to_proto(&a, &tv_sec_hi, &tv_sec_lo, &tv_nsec);
+ ZUC_ASSERT_EQ(0, tv_sec_hi);
+ ZUC_ASSERT_EQ(1234, tv_sec_lo);
+ ZUC_ASSERT_EQ(NSEC_PER_SEC - 1, tv_nsec);
+
+ a.tv_sec = (time_t)0x7000123470005678LL;
+ a.tv_nsec = 1;
+ timespec_to_proto(&a, &tv_sec_hi, &tv_sec_lo, &tv_nsec);
+ ZUC_ASSERT_EQ((uint64_t)a.tv_sec >> 32, tv_sec_hi);
+ ZUC_ASSERT_EQ(0x70005678, tv_sec_lo);
+ ZUC_ASSERT_EQ(1, tv_nsec);
+}
+
ZUC_TEST(timespec_test, millihz_to_nsec)
{
ZUC_ASSERT_EQ(millihz_to_nsec(60000), 16666666);