[CRIU] [PATCH cr 2/8] zdtm: check pid name space

Andrey Vagin avagin at openvz.org
Wed May 16 04:32:35 EDT 2012


Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 test/zdtm/live/static/pid_namespace.c |   65 +++++++++++++++++++++++++++++++++
 1 files changed, 65 insertions(+), 0 deletions(-)
 create mode 100644 test/zdtm/live/static/pid_namespace.c

diff --git a/test/zdtm/live/static/pid_namespace.c b/test/zdtm/live/static/pid_namespace.c
new file mode 100644
index 0000000..1e6f7ce
--- /dev/null
+++ b/test/zdtm/live/static/pid_namespace.c
@@ -0,0 +1,65 @@
+#include <sys/wait.h>
+#include <sched.h>
+#include <unistd.h>
+#include <sys/syscall.h>
+
+#include "zdtmtst.h"
+
+const char *test_doc	= "Check that pid ns context migrated successfully";
+const char *test_author	= "Andrey Vagin <avagin at openvz.org>";
+
+static int test_fn(int argc, char **argv)
+{
+	pid_t pid = syscall(__NR_getpid), tmp, cpid;
+	int status;
+
+	test_ns_daemon();
+	cpid = test_fork();
+
+	if (cpid < 0) {
+		err("fork failed");
+		return 1;
+	} else if (cpid == 0) {
+		pid = syscall(__NR_getpid);
+
+		test_waitsig();
+
+		tmp = syscall(__NR_getpid);
+		if (pid != tmp) {
+			fail("%d != %d\n", pid, tmp);
+			return 1;
+		}
+
+		return 0;
+	}
+
+	test_waitsig();
+
+	kill(cpid, SIGTERM);
+	tmp = syscall(__NR_getpid);
+	if (pid != tmp) {
+		fail("%d != %d\n", pid, tmp);
+		return 1;
+	}
+
+	tmp = waitpid(cpid, &status, 0);
+	if (tmp == -1) {
+		err("wait failed");
+		return 1;
+	}
+
+	if (!WIFEXITED(status) || WEXITSTATUS(status)) {
+		fail("child failed with status %x", status);
+		return 1;
+	}
+
+	pass();
+	return 0;
+}
+
+int main(int argc, char **argv)
+{
+	test_init_ns(argc, argv, CLONE_NEWPID, test_fn);
+
+	return 0;
+}
-- 
1.7.1



More information about the CRIU mailing list