[CRIU] [PATCH 9/9] zdtm: Test for manual (for now) testing

Pavel Emelyanov xemul at parallels.com
Thu Apr 11 09:51:40 EDT 2013


This guy touches a random page once per second and backs-up
what was touched. At the end it checks whether everything is
OK. It can be used to test how snapshots work -- take several
snapshots with several seconds pauses in betweem and restore
form the last.

Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
 test/zdtm/live/static/Makefile    |  1 +
 test/zdtm/live/static/mem-touch.c | 62 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 63 insertions(+)
 create mode 100644 test/zdtm/live/static/mem-touch.c

diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
index 345ccc8..69fd6ff 100644
--- a/test/zdtm/live/static/Makefile
+++ b/test/zdtm/live/static/Makefile
@@ -92,6 +92,7 @@ TST_NOFILE	=				\
 		posix_timers			\
 		sigpending			\
 		sk-netlink			\
+		mem-touch			\
 #		jobctl00			\
 
 TST_FILE	=				\
diff --git a/test/zdtm/live/static/mem-touch.c b/test/zdtm/live/static/mem-touch.c
new file mode 100644
index 0000000..c1e3ab2
--- /dev/null
+++ b/test/zdtm/live/static/mem-touch.c
@@ -0,0 +1,62 @@
+#include <unistd.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <sys/mman.h>
+
+#include "zdtmtst.h"
+
+const char *test_doc	= "Check changing memory";
+const char *test_author	= "Pavel Emelyanov <xemul at parallels.com>";
+
+#define MEM_PAGES	16
+#define PAGE_SIZE	4096
+
+int main(int argc, char **argv)
+{
+	void *mem;
+	int i, fail = 0;
+	unsigned rover = 1;
+	unsigned backup[MEM_PAGES] = {};
+
+	srand(time(NULL));
+
+	test_init(argc, argv);
+
+	mem = mmap(NULL, MEM_PAGES * PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, 0, 0);
+	if (mem == MAP_FAILED)
+		return 1;
+
+	test_msg("mem %p backup %p\n", mem, backup);
+
+	test_daemon();
+	while (test_go()) {
+		unsigned pfn;
+
+		pfn = random() % MEM_PAGES;
+		*(unsigned *)(mem + pfn * PAGE_SIZE) = rover;
+		backup[pfn] = rover;
+		test_msg("t %u %u\n", pfn, rover);
+		rover++;
+		sleep(1);
+	}
+	test_waitsig();
+
+	test_msg("final rover %u\n", rover);
+	for (i = 0; i < MEM_PAGES; i++)
+		if (backup[i] != *(unsigned *)(mem + i * PAGE_SIZE)) {
+			test_msg("Page %u differs want %u has %u\n", i,
+					backup[i], *(unsigned *)(mem + i * PAGE_SIZE));
+			fail = 1;
+		} else
+			test_msg("Page %u matches %u\n", i, backup[i]);
+
+	if (fail)
+		fail("Memory corruption\n");
+	else
+		pass();
+
+	return 0;
+}
+
-- 
1.7.11.7


More information about the CRIU mailing list