[Piglit] [PATCH 04/12] util: add piglit_time_is_monotonic helper

Emil Velikov emil.l.velikov at gmail.com
Sat Nov 22 14:40:26 PST 2014


Rather than assuming that piglit_get_microseconds() returns -1 when
there is no monotonic timer, add explicit function to check.

Use it where needed, and break the above assumption.

Signed-off-by: Emil Velikov <emil.l.velikov at gmail.com>
---
 tests/spec/glx_oml_sync_control/timing.c |  2 +-
 tests/util/piglit-util.c                 | 13 +++++++++++++
 tests/util/piglit-util.h                 |  9 +++++++++
 3 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/tests/spec/glx_oml_sync_control/timing.c b/tests/spec/glx_oml_sync_control/timing.c
index a03e75e..7fbcf44 100644
--- a/tests/spec/glx_oml_sync_control/timing.c
+++ b/tests/spec/glx_oml_sync_control/timing.c
@@ -210,7 +210,7 @@ draw(Display *dpy)
 					(new_ust - last_ust) / delta_msc);
 
 			if (last_timestamp >= 0) {
-				if (new_timestamp < 0) {
+				if (!piglit_time_is_monotonic()) {
 					fprintf(stderr,
 						"no monotonic clock\n");
 					piglit_merge_result(&result,
diff --git a/tests/util/piglit-util.c b/tests/util/piglit-util.c
index c87678f..aa423d2 100644
--- a/tests/util/piglit-util.c
+++ b/tests/util/piglit-util.c
@@ -646,6 +646,19 @@ write_null:
 	return size_written;
 }
 
+bool
+piglit_time_is_monotonic(void)
+{
+#ifdef PIGLIT_HAS_POSIX_CLOCK_MONOTONIC
+	struct timespec t;
+	int r = clock_gettime(CLOCK_MONOTONIC, &t);
+
+	return r == 0 || (r == -1 && errno != EINVAL);
+#else
+	return false;
+#endif
+}
+
 int64_t
 piglit_get_microseconds(void)
 {
diff --git a/tests/util/piglit-util.h b/tests/util/piglit-util.h
index 320dfde..3a02334 100755
--- a/tests/util/piglit-util.h
+++ b/tests/util/piglit-util.h
@@ -238,6 +238,15 @@ size_t
 piglit_join_paths(char buf[], size_t buf_size, int n, ...);
 
 /**
+ * \brief Whether piglit_time_get* return monotonically increasing time.
+ *
+ * Can be used to determine how accurate/reliable the time returned by the
+ * function(s) is.
+ */
+bool
+piglit_time_is_monotonic();
+
+/**
  * \brief Get a monotonically increasing time in microseconds
  *
  * This time can be used for relative time measurements.
-- 
2.1.3



More information about the Piglit mailing list