summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDaniel Stone <daniels@collabora.com>2017-03-01 11:34:03 +0000
committerPekka Paalanen <pekka.paalanen@collabora.co.uk>2017-03-13 14:20:06 +0200
commit839b63546d2e69e3bf863d0de701817524e5c1d1 (patch)
tree28c99402b393be6462829e1cea6dd248623853c3 /tests
parent37ad7e3bae090c8791dc638bfc3f952fb5c12acf (diff)
timespec: Add timespec subtraction helpers
Add helpers to subtract two timespecs, then return the difference in either milliseconds or nanoseconds. These will be used to compare timestamps during the repaint cycle. Signed-off-by: Daniel Stone <daniels@collabora.com> Suggested-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk> Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Diffstat (limited to 'tests')
-rw-r--r--tests/timespec-test.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/timespec-test.c b/tests/timespec-test.c
index 712d1acd..a5039110 100644
--- a/tests/timespec-test.c
+++ b/tests/timespec-test.c
@@ -142,3 +142,25 @@ ZUC_TEST(timespec_test, timespec_add_msec)
ZUC_ASSERT_EQ(1002, r.tv_sec);
ZUC_ASSERT_EQ(2000001, r.tv_nsec);
}
+
+ZUC_TEST(timespec_test, timespec_sub_to_nsec)
+{
+ struct timespec a, b;
+
+ a.tv_sec = 1000;
+ a.tv_nsec = 1;
+ b.tv_sec = 1;
+ b.tv_nsec = 2;
+ ZUC_ASSERT_EQ((999L * NSEC_PER_SEC) - 1, timespec_sub_to_nsec(&a, &b));
+}
+
+ZUC_TEST(timespec_test, timespec_sub_to_msec)
+{
+ struct timespec a, b;
+
+ a.tv_sec = 1000;
+ a.tv_nsec = 2000000L;
+ b.tv_sec = 2;
+ b.tv_nsec = 1000000L;
+ ZUC_ASSERT_EQ((998 * 1000) + 1, timespec_sub_to_msec(&a, &b));
+}