[CRIU] [PATCH 2/2] zdtm: Add maps02 test

Cyrill Gorcunov gorcunov at openvz.org
Thu May 10 13:07:05 EDT 2012


In a sake of nonlinear mapping.

Still the test is out of normal test-flow
since it's "always fail" case (because we
don't support nonlinear mapping yet, but
this test code might be needed in future.
After all I've been using it for testing
proc-parsing procesure).

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 test/zdtm/live/static/Makefile |    1 +
 test/zdtm/live/static/maps02.c |   58 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 59 insertions(+), 0 deletions(-)
 create mode 100644 test/zdtm/live/static/maps02.c

diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
index 5cf9445..53cc10e 100644
--- a/test/zdtm/live/static/Makefile
+++ b/test/zdtm/live/static/Makefile
@@ -44,6 +44,7 @@ TST_NOFILE	=				\
 		file_fown			\
 		eventfs00			\
 		inotify00			\
+		maps02				\
 #		jobctl00			\
 
 TST_FILE	=				\
diff --git a/test/zdtm/live/static/maps02.c b/test/zdtm/live/static/maps02.c
new file mode 100644
index 0000000..1657e28
--- /dev/null
+++ b/test/zdtm/live/static/maps02.c
@@ -0,0 +1,58 @@
+#define _GNU_SOURCE         /* See feature_test_macros(7) */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <string.h>
+#include <setjmp.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+#include "zdtmtst.h"
+
+const char *test_doc	= "Create non-linear mapping\n";
+const char *test_author	= "Cyrill Gorcunov <gorcunov at openvz.org>";
+
+#define MAPS_LEN	0x4000
+
+int main(int argc, char ** argv)
+{
+	const char fname[] = "maps02-test";
+	void *map;
+	int fd, i;
+	long data;
+
+	test_init(argc, argv);
+
+	fd = open(fname, O_RDWR | O_CREAT | O_TRUNC);
+	if (fd < 0) {
+		fail("Can't open %s\n", fname);
+		exit(1);
+	}
+
+	for (i = 0; i < MAPS_LEN / sizeof(long); i++)
+		write(fd, &data, sizeof(data));
+
+	map = mmap(NULL, MAPS_LEN, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, -1, 0);
+	if (map == MAP_FAILED) {
+		fail("Can't map %s\n", fname);
+		exit(1);
+	}
+
+	for (i = 0; i < MAPS_LEN / sizeof(long) - 1; i++) {
+		((long *)map)[i] = i;
+	}
+
+	if (remap_file_pages(map + 0x1000, 0x1000, 0, 0, 0)) {
+		fail("Can't remap file pages %s\n", fname);
+		exit(1);
+	}
+
+	test_daemon();
+	test_waitsig();
+
+	pass();
+	return 0;
+}
-- 
1.7.7.6



More information about the CRIU mailing list