[CRIU] [PATCH] uptime_grow test

Evgeny Antyshev eantyshev at parallels.com
Tue Jun 19 05:22:29 EDT 2012


we query system timer CLOCK_MONOTONIC continuously
and fail in case it stepped backwards
---
 test/zdtm/live/static/Makefile      |    2 +
 test/zdtm/live/static/uptime_grow.c |   46 +++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+), 0 deletions(-)
 create mode 100644 test/zdtm/live/static/uptime_grow.c

diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
index a399741..5492d05 100644
--- a/test/zdtm/live/static/Makefile
+++ b/test/zdtm/live/static/Makefile
@@ -46,6 +46,7 @@ TST_NOFILE	=				\
 		file_fown			\
 		eventfs00			\
 		inotify00			\
+		uptime_grow			\
 #		jobctl00			\
 
 TST_FILE	=				\
@@ -157,6 +158,7 @@ futex:			override LDFLAGS += -pthread
 jobctl00:		override LDLIBS += -lutil
 socket_listen:		override LDLIBS += -lrt
 socket_aio:		override LDLIBS += -lrt
+uptime_grow:	override LDLIBS += -lrt
 unlink_largefile:	override CFLAGS += -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE
 inotify_system_nodel:	override CFLAGS += -DNODEL
 pthread00:		override LDLIBS += -pthread
diff --git a/test/zdtm/live/static/uptime_grow.c b/test/zdtm/live/static/uptime_grow.c
new file mode 100644
index 0000000..ca2b4ef
--- /dev/null
+++ b/test/zdtm/live/static/uptime_grow.c
@@ -0,0 +1,46 @@
+#include "zdtmtst.h"
+
+const char *test_doc    = "test to ensure that monotonic clock doesn't decrease";
+const char *test_author = "Evgeny Antysev <eantyshev at parallels.com>";
+
+#include <stdio.h>
+#include <time.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <string.h>
+#include <errno.h>
+#include <stdlib.h>
+
+#define NEWER(t1,t2) (t1.tv_sec > t2.tv_sec || t1.tv_nsec > t2.tv_nsec)
+
+int main(int argc, char **argv)
+{
+	struct timespec tm_old, tm;
+	double diff_nsec;
+	test_init(argc, argv);
+
+	if (0 != clock_gettime(CLOCK_MONOTONIC, &tm_old)) {
+		err("clock_gettime failed: %m\n");
+		exit(1);
+	}
+
+	test_daemon();
+
+	while (test_go()) {
+		if (0 != clock_gettime(CLOCK_MONOTONIC, &tm)) {
+			err("clock_gettime failed: %m\n");
+			exit(1);
+		}
+		if (!NEWER(tm, tm_old)) {
+			diff_nsec = (tm_old.tv_sec - tm.tv_sec) * 1.0E9 +\
+				(tm_old.tv_nsec - tm.tv_nsec);
+			fail("clock step backward for %e nsec\n", diff_nsec);
+			exit(1);
+		}
+		memcpy(&tm_old, &tm, sizeof(struct timespec));
+	}
+	pass();
+	return 0;
+}
-- 
1.6.5.1.1367.gcd48



More information about the CRIU mailing list