[CRIU] [PATCH 4/4] zdtm/maps01: extend maps01

Andrey Vagin avagin at openvz.org
Tue Oct 14 01:42:45 PDT 2014


It's bad idea to have only one target object.
In addition I add a shared region to the second process,
which is not mapped in the first.

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 test/zdtm/live/static/maps01.c | 49 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 48 insertions(+), 1 deletion(-)

diff --git a/test/zdtm/live/static/maps01.c b/test/zdtm/live/static/maps01.c
index 22340a7..6deaf87 100644
--- a/test/zdtm/live/static/maps01.c
+++ b/test/zdtm/live/static/maps01.c
@@ -1,3 +1,4 @@
+#define _GNU_SOURCE
 #include <errno.h>
 #include <fcntl.h>
 #include <unistd.h>
@@ -21,7 +22,7 @@ const char *test_author	= "Andrew Vagin <avagin at openvz.org";
 
 int main(int argc, char ** argv)
 {
-	void *m, *m2;
+	void *m, *m2, *p, *p2;
 	char path[PATH_MAX];
 	uint32_t crc;
 	pid_t pid = -1;
@@ -35,14 +36,39 @@ int main(int argc, char ** argv)
 	if (m == MAP_FAILED)
 		goto err;
 
+	p = mmap(NULL, MEM_SIZE, PROT_WRITE | PROT_READ,
+				MAP_SHARED | MAP_ANONYMOUS, -1, 0);
+
+	if (p == MAP_FAILED)
+		goto err;
+
+	p2 = mmap(NULL, MEM_OFFSET, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+	if (p2 == MAP_FAILED)
+		goto err;
+
 	pid = test_fork();
 	if (pid < 0) {
 		goto err;
 	} else if (pid == 0) {
+		void *p3;
+
+		p3 = mmap(NULL, MEM_OFFSET3, PROT_READ | PROT_WRITE,
+					MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+		if (p3 == MAP_FAILED)
+			goto err;
+
 		crc = ~0;
 		datagen(m + MEM_OFFSET, PAGE_SIZE, &crc);
 		crc = ~0;
 		datagen(m + MEM_OFFSET2, PAGE_SIZE, &crc);
+		crc = ~0;
+		datagen(p + MEM_OFFSET + MEM_OFFSET3, PAGE_SIZE, &crc);
+		crc = ~0;
+		datagen(p + MEM_OFFSET + 2 * MEM_OFFSET3, PAGE_SIZE, &crc);
+		crc = ~0;
+		datagen(p + MEM_OFFSET3, PAGE_SIZE, &crc);
+		crc = ~0;
+		datagen(p3, PAGE_SIZE, &crc);
 
 		test_waitsig();
 
@@ -58,9 +84,26 @@ int main(int argc, char ** argv)
 		status = datachk(m + PAGE_SIZE, PAGE_SIZE, &crc);
 		if (status)
 			return 1;
+		crc = ~0;
+		status = datachk(p + MEM_OFFSET + 2 * MEM_OFFSET3, PAGE_SIZE, &crc);
+		if (status)
+			return 1;
+		crc = ~0;
+		status = datachk(p + MEM_OFFSET3, PAGE_SIZE, &crc);
+		if (status)
+			return 1;
+		crc = ~0;
+		status = datachk(p3, PAGE_SIZE, &crc);
+		if (status)
+			return 1;
 		return 0;
 	}
 
+	munmap(p, MEM_OFFSET);
+	p2 = mremap(p + MEM_OFFSET, MEM_OFFSET, MEM_OFFSET, MREMAP_FIXED | MREMAP_MAYMOVE, p2);
+	if (p2 == MAP_FAILED)
+		goto err;
+
 	snprintf(path, PATH_MAX, "/proc/self/map_files/%lx-%lx",
 						(unsigned long) m,
 						(unsigned long) m + MEM_SIZE);
@@ -106,6 +149,10 @@ int main(int argc, char ** argv)
 	if (datachk(m2, PAGE_SIZE, &crc))
 		goto err;
 
+	crc = ~0;
+	if (datachk(p2 + MEM_OFFSET3, PAGE_SIZE, &crc))
+		goto err;
+
 	pass();
 
 	return 0;
-- 
1.9.3



More information about the CRIU mailing list