[CRIU] Re: [PATCH cr 3/3] zdtm: remove extra code from file_fown

Cyrill Gorcunov gorcunov at openvz.org
Wed May 30 06:35:59 EDT 2012


On Wed, May 30, 2012 at 12:44:16PM +0400, Pavel Emelyanov wrote:
> All applied.
> 
> Cyrill, Andrey says that fowner testcase doesn't pass after this patch.
> Why and how can we fix it?

The attached patch should fix it.

	Cyrill
-------------- next part --------------
>From caa929dddb7970ff11b4e6ba22bcf430ef3ff2d3 Mon Sep 17 00:00:00 2001
From: Cyrill Gorcunov <gorcunov at openvz.org>
Date: Wed, 30 May 2012 14:34:58 +0400
Subject: [PATCH] zdtm: Update file_fown test case

 - make sure syscalls finished with success
 - put sync points where needed

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 test/zdtm/live/static/file_fown.c |  111 ++++++++++++++++++++++++++++---------
 1 files changed, 84 insertions(+), 27 deletions(-)

diff --git a/test/zdtm/live/static/file_fown.c b/test/zdtm/live/static/file_fown.c
index e138a0a..af58a3f 100644
--- a/test/zdtm/live/static/file_fown.c
+++ b/test/zdtm/live/static/file_fown.c
@@ -33,6 +33,58 @@ static int received_io;
 
 #define SK_DATA "packet"
 
+#define WAIT_FOR(n)						\
+	do {							\
+		while (MAP_SYNC(map) != n)			\
+			sleep(1);				\
+	} while (0)
+
+#define panic(op)						\
+	do {							\
+		fail("%s failed\n", #op);			\
+		exit(1);					\
+	} while (0)
+
+#define __assert_zop_noret(op, ...)				\
+	do {							\
+		if (op( __VA_ARGS__ ))				\
+			panic(op);				\
+	} while (0)
+
+#define __assert_cmp_noret(op, type, var, cmp, ...)		\
+	do {							\
+		type var = op( __VA_ARGS__ );			\
+		if (cmp)					\
+			panic(op);				\
+	} while (0)
+
+#define __assert_cmp_intr_noret(op, type, var, cmp, ...)	\
+	do {							\
+		type var = op( __VA_ARGS__ );			\
+		int attempt = 10;				\
+		while ((cmp)) {					\
+			attempt--;				\
+			if (!attempt-- || errno != EAGAIN)	\
+				panic(op);			\
+			var = op( __VA_ARGS__ );		\
+		}						\
+	} while (0)
+
+#define assert_fcntl(...)					\
+	__assert_zop_noret(fcntl, __VA_ARGS__)
+
+#define assert_read(fd, ptr, size)				\
+	__assert_cmp_noret(read, ssize_t, __r, __r != size, fd, ptr, size)
+
+#define assert_write(fd, ptr, size)				\
+	__assert_cmp_noret(write, ssize_t, __r, __r != size, fd, ptr, size)
+
+#define assert_read_intr(fd, ptr, size)				\
+	__assert_cmp_intr_noret(read, ssize_t, __r, __r != size, fd, ptr, size)
+
+#define assert_write_intr(fd, ptr, size)			\
+	__assert_cmp_intr_noret(write, ssize_t, __r, __r != size, fd, ptr, size)
+
 static void signal_handler_io(int status)
 {
 	received_io++;
@@ -50,18 +102,18 @@ int main(int argc, char ** argv)
 	uid_t suid;
 
 	int ssk_pair[2];
-	char buf[64];
+	char buf[64] = { };
 
 	test_init(argc, argv);
 
 	if (getresuid(&ruid, &euid, &suid)) {
-		fail("getresuid failed");
+		fail("getresuid failed\n");
 		exit(1);
 	}
 
 	map = mmap(NULL, 1024, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
 	if (map == MAP_FAILED) {
-		fail("Can't map");
+		fail("Can't map\n");
 		exit(1);
 	}
 
@@ -78,31 +130,34 @@ int main(int argc, char ** argv)
 	memset(&saio, 0, sizeof(saio));
 	saio.sa_handler = (sig_t)signal_handler_io;
 	saio.sa_flags = SA_RESTART;
-	sigaction(SIGIO, &saio, 0);
+	if (sigaction(SIGIO, &saio, 0)) {
+		fail("sigaction failed\n");
+		exit(1);
+	}
 
 	if (setresuid(-1, 1, -1)) {
-		fail("setresuid failed");
+		fail("setresuid failed\n");
 		exit(1);
 	}
 
-	fcntl(pipes[0], F_SETOWN, getpid());
-	fcntl(pipes[1], F_SETOWN, getpid());
+	assert_fcntl(pipes[0], F_SETOWN, getpid());
+	assert_fcntl(pipes[1], F_SETOWN, getpid());
 
 	test_msg("main owner pipes[0]: %d\n", fcntl(pipes[0], F_GETOWN));
 
-	fcntl(pipes[0], F_SETSIG, SIGIO);
-	fcntl(pipes[1], F_SETSIG, SIGIO);
+	assert_fcntl(pipes[0], F_SETSIG, SIGIO);
+	assert_fcntl(pipes[1], F_SETSIG, SIGIO);
 
-	fcntl(pipes[0], F_SETFL, fcntl(pipes[0], F_GETFL) | O_NONBLOCK | O_ASYNC);
-	fcntl(pipes[1], F_SETFL, fcntl(pipes[1], F_GETFL) | O_NONBLOCK | O_ASYNC);
+	assert_fcntl(pipes[0], F_SETFL, fcntl(pipes[0], F_GETFL) | O_NONBLOCK | O_ASYNC);
+	assert_fcntl(pipes[1], F_SETFL, fcntl(pipes[1], F_GETFL) | O_NONBLOCK | O_ASYNC);
 
-	fcntl(ssk_pair[0], F_SETOWN, getpid());
-	fcntl(ssk_pair[0], F_SETSIG, SIGIO);
-	fcntl(ssk_pair[0], F_SETFL, fcntl(ssk_pair[0], F_GETFL) | O_NONBLOCK | O_ASYNC);
+	assert_fcntl(ssk_pair[0], F_SETOWN, getpid());
+	assert_fcntl(ssk_pair[0], F_SETSIG, SIGIO);
+	assert_fcntl(ssk_pair[0], F_SETFL, fcntl(ssk_pair[0], F_GETFL) | O_NONBLOCK | O_ASYNC);
 	test_msg("main owner ssk_pair[0]: %d\n", fcntl(ssk_pair[0], F_GETOWN));
 
 	if (setresuid(-1, euid, -1)) {
-		fail("setresuid failed");
+		fail("setresuid failed\n");
 		exit(1);
 	}
 
@@ -118,18 +173,19 @@ int main(int argc, char ** argv)
 
 	if (pid == 0) {
 		int v = 1;
-		MAP_SYNC(map) = 1;
 
-		while (MAP_SYNC(map) != 3)
-			sleep(1);
+		assert_write(pipes[1], &v, sizeof(v));
+		assert_read(pipes[0], &v, sizeof(v));
+		assert_fcntl(pipes[1], F_SETOWN, getpid());
 
-		fcntl(pipes[1], F_SETOWN, getpid());
+		MAP_SYNC(map) = 1;
+		WAIT_FOR(3);
 
-		write(pipes[1], &v, sizeof(v));
-		read(pipes[0], &v, sizeof(v));
+		assert_write_intr(pipes[1], &v, sizeof(v));
+		assert_read_intr(pipes[0], &v, sizeof(v));
 
-		write(ssk_pair[0], SK_DATA, sizeof(SK_DATA));
-		read(ssk_pair[1], &buf, sizeof(buf));
+		assert_write_intr(ssk_pair[0], SK_DATA, sizeof(SK_DATA));
+		assert_read_intr(ssk_pair[1], &buf, sizeof(SK_DATA));
 		if (strcmp(buf, SK_DATA)) {
 			fail("data corrupted\n");
 			exit(1);
@@ -143,15 +199,16 @@ int main(int argc, char ** argv)
 		exit(0);
 	}
 
-	while (MAP_SYNC(map) != 1)
-		sleep(1);
+	WAIT_FOR(1);
 
 	test_daemon();
 	test_waitsig();
 
 	MAP_SYNC(map) = 3;
-
-	waitpid(pid, &status, P_ALL);
+	if (waitpid(pid, &status, P_ALL) == -1) {
+		fail("waitpid failed\n");
+		exit(1);
+	}
 
 	if (received_io < 1		||
 	    MAP_PID_PIPE0(map) != ppid	||
-- 
1.7.7.6



More information about the CRIU mailing list