[CRIU] [PATCH] test: combine remap_dead_pid{,_root} tests

Dmitry Safonov dsafonov at virtuozzo.com
Mon Nov 14 10:36:44 PST 2016


1. Dropped check for (fd < 0) - there is check after open() in the
test, just two lines upper or so.
2. Combined two test to share common code: they differ only by proc
path to open in a dead process.

Cc: Tycho Andersen <tycho.andersen at canonical.com>
Signed-off-by: Dmitry Safonov <dsafonov at virtuozzo.com>
---
 test/zdtm/static/Makefile              |  1 +
 test/zdtm/static/remap_dead_pid.c      | 13 +++---
 test/zdtm/static/remap_dead_pid_root.c | 73 +---------------------------------
 3 files changed, 9 insertions(+), 78 deletions(-)
 mode change 100644 => 120000 test/zdtm/static/remap_dead_pid_root.c

diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile
index f8a922b10025..6d8cd755fe22 100644
--- a/test/zdtm/static/Makefile
+++ b/test/zdtm/static/Makefile
@@ -390,6 +390,7 @@ shm:			override CFLAGS += -DNEW_IPC_NS
 msgque:			override CFLAGS += -DNEW_IPC_NS
 sem:			override CFLAGS += -DNEW_IPC_NS
 posix_timers:		override LDLIBS += -lrt -pthread
+remap_dead_pid_root:	override CFLAGS += -DREMAP_PID_ROOT
 socket-tcp6: override CFLAGS += -D ZDTM_IPV6
 socket-tcpbuf6: override CFLAGS += -D ZDTM_IPV6
 socket-tcpbuf-local: override CFLAGS += -D ZDTM_TCP_LOCAL
diff --git a/test/zdtm/static/remap_dead_pid.c b/test/zdtm/static/remap_dead_pid.c
index 00fe3fd16359..b46fd2b0b741 100644
--- a/test/zdtm/static/remap_dead_pid.c
+++ b/test/zdtm/static/remap_dead_pid.c
@@ -14,6 +14,12 @@
 #define CLONE_NEWNS     0x00020000
 #endif
 
+#ifdef REMAP_PID_ROOT
+const char *proc_path = "/proc/%d";
+#else
+const char *proc_path = "/proc/%d/mountinfo";
+#endif
+
 const char *test_doc	= "Check that dead pid's /proc entries are remapped correctly";
 const char *test_author	= "Tycho Andersen <tycho.andersen at canonical.com>";
 
@@ -40,7 +46,7 @@ int main(int argc, char **argv)
 		char path[PATH_MAX];
 		pid_t result;
 
-		sprintf(path, "/proc/%d/mountinfo", pid);
+		sprintf(path, proc_path, pid);
 		fd = open(path, O_RDONLY);
 		if (fd < 0) {
 			fail("failed to open fd");
@@ -55,11 +61,6 @@ int main(int argc, char **argv)
 			return -1;
 		}
 
-		if (fd < 0) {
-			fail("failed opening %s", path);
-			return -1;
-		}
-
 		test_daemon();
 		test_waitsig();
 
diff --git a/test/zdtm/static/remap_dead_pid_root.c b/test/zdtm/static/remap_dead_pid_root.c
deleted file mode 100644
index 2a3141216b0f..000000000000
--- a/test/zdtm/static/remap_dead_pid_root.c
+++ /dev/null
@@ -1,72 +0,0 @@
-#define _GNU_SOURCE
-#include <string.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <signal.h>
-#include <stdio.h>
-#include <limits.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-
-#include "zdtmtst.h"
-
-#ifndef CLONE_NEWNS
-#define CLONE_NEWNS     0x00020000
-#endif
-
-const char *test_doc	= "Check that dead pid's /proc entries are remapped correctly";
-const char *test_author	= "Tycho Andersen <tycho.andersen at canonical.com>";
-
-int main(int argc, char **argv)
-{
-	pid_t pid;
-
-	test_init(argc, argv);
-
-	pid = fork();
-	if (pid < 0) {
-		fail("fork() failed");
-		return -1;
-	}
-
-	if (pid == 0) {
-		test_msg("child is %d\n", pid);
-		/* Child process just sleeps until it is killed. All we need
-		 * here is a process to open the mountinfo of. */
-		while(1)
-			sleep(10);
-	} else {
-		int fd, ret;
-		char path[PATH_MAX];
-		pid_t result;
-
-		sprintf(path, "/proc/%d", pid);
-		fd = open(path, O_RDONLY);
-		if (fd < 0) {
-			fail("failed to open fd");
-			return -1;
-		}
-
-		/* no matter what, we should kill the child */
-		kill(pid, SIGKILL);
-		result = waitpid(pid, NULL, 0);
-		if (result < 0) {
-			fail("failed waitpid()");
-			return -1;
-		}
-
-		test_daemon();
-		test_waitsig();
-
-		ret = fcntl(fd, F_GETFD);
-		close(fd);
-
-		if (ret) {
-			fail("bad fd after restore");
-			return -1;
-		}
-	}
-
-	pass();
-	return 0;
-}
diff --git a/test/zdtm/static/remap_dead_pid_root.c b/test/zdtm/static/remap_dead_pid_root.c
new file mode 120000
index 000000000000..3739fc74bea6
--- /dev/null
+++ b/test/zdtm/static/remap_dead_pid_root.c
@@ -0,0 +1 @@
+remap_dead_pid.c
\ No newline at end of file
-- 
2.10.2



More information about the CRIU mailing list