Mesa (main): util: Add unittest for timespec_get

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Jun 9 18:00:21 UTC 2022


Module: Mesa
Branch: main
Commit: 0ef513699d39972081409352320af6cea5977203
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=0ef513699d39972081409352320af6cea5977203

Author: Yonggang Luo <luoyonggang at gmail.com>
Date:   Thu Mar 31 02:00:04 2022 +0800

util: Add unittest for timespec_get

Signed-off-by: Yonggang Luo <luoyonggang at gmail.com>
Reviewed-by: Jason Ekstrand <jason.ekstrand at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15497>

---

 src/util/tests/timespec_test.cpp | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/src/util/tests/timespec_test.cpp b/src/util/tests/timespec_test.cpp
index d8bf60215eb..9edfa3b237c 100644
--- a/src/util/tests/timespec_test.cpp
+++ b/src/util/tests/timespec_test.cpp
@@ -25,6 +25,7 @@
 
 #include <gtest/gtest.h>
 
+#include "c11/time.h"
 #include "util/timespec.h"
 
 #include <limits>
@@ -317,3 +318,16 @@ TEST(timespec_test, timespec_eq)
    EXPECT_FALSE(timespec_eq(&a, &b));
    EXPECT_FALSE(timespec_eq(&b, &a));
 }
+
+TEST(timespec_test, timespec_get)
+{
+   struct timespec a;
+   struct timespec b;
+   time_t t;
+   timespec_get(&a, TIME_UTC);
+   time(&t);
+   timespec_get(&b, TIME_UTC);
+   /* `t + 1` and `t - 1` are used intentionally for avoid flakes */
+   EXPECT_LE(a.tv_sec, t + 1);
+   EXPECT_LE(t - 1, b.tv_sec);
+}



More information about the mesa-commit mailing list