[CRIU] [PATCH cr 15/16] zdtm: cow00 checks that parent's data are not available from a child

Andrey Vagin avagin at openvz.org
Tue Oct 23 06:02:27 EDT 2012


A parent writes a new data after forking a child, so this data should
not be avaliable from child.

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 test/zdtm/live/static/cow00.c |   37 +++++++++++++++++++++++++++++--------
 1 files changed, 29 insertions(+), 8 deletions(-)

diff --git a/test/zdtm/live/static/cow00.c b/test/zdtm/live/static/cow00.c
index 2782c2d..04b6c53 100644
--- a/test/zdtm/live/static/cow00.c
+++ b/test/zdtm/live/static/cow00.c
@@ -13,6 +13,9 @@
 const char *test_doc	= "Check that cow memory are restored";
 const char *test_author	= "Andrey Vagin <avagin at parallels.com";
 
+#define MAP_SIZE	(PAGE_SIZE * 2)
+#define NONCOW_OFFSET	PAGE_SIZE
+
 static int is_cow(void *addr, pid_t p1, pid_t p2)
 {
 	char buf[PATH_MAX];
@@ -65,13 +68,13 @@ static int is_cow(void *addr, pid_t p1, pid_t p2)
 
 int main(int argc, char ** argv)
 {
-	void *addr;
+	char *addr;
 	pid_t pid;
-	int ret = 1;
+	int ret = 1, status = -1;
 
 	test_init(argc, argv);
 
-	addr = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+	addr = mmap(NULL, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
 	if (addr == MAP_FAILED) {
 		err("Can't allocate memory\n");
 		return 1;
@@ -85,6 +88,13 @@ int main(int argc, char ** argv)
 		return 1;
 	} else if (pid == 0) {
 		test_waitsig();
+
+		if (addr[NONCOW_OFFSET]) {
+			fail("%p contains non-zero symbol %c",
+				addr + NONCOW_OFFSET, addr[NONCOW_OFFSET]);
+			return 1;
+		}
+
 		return 0;
 	}
 
@@ -95,19 +105,30 @@ int main(int argc, char ** argv)
 		goto out;
 	}
 
+	/* These data should not be available for children */
+	addr[NONCOW_OFFSET] = 'p';
+
 	test_daemon();
 
 	test_waitsig();
 
-	if (is_cow(addr, pid, getpid()) == 1)
-		pass();
-	else
+	if (is_cow(addr, pid, getpid()) == 0) {
 		fail("A page is not shared");
+		goto out;
+	}
 
 	ret = 0;
 out:
 	kill(pid, SIGTERM);
-	wait(NULL);
+	wait(&status);
+
+	if (status) {
+		err("The child exited with code %d", status);
+		ret = 1;
+	}
+
+	if (ret == 0)
+		pass();
 
-	return ret;
+	return ret || status ? 1 : 0;
 }
-- 
1.7.1



More information about the CRIU mailing list