[CRIU] [PATCH 8/8] zdtm: Add test for cwd and opened ghost directory

Pavel Emelyanov xemul at parallels.com
Thu Jul 3 08:08:44 PDT 2014


Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
 test/zdtm.sh                   |  1 +
 test/zdtm/.gitignore           |  1 +
 test/zdtm/live/static/Makefile |  1 +
 test/zdtm/live/static/cwd02.c  | 92 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 95 insertions(+)
 create mode 100644 test/zdtm/live/static/cwd02.c

diff --git a/test/zdtm.sh b/test/zdtm.sh
index 3603519..2212176 100755
--- a/test/zdtm.sh
+++ b/test/zdtm.sh
@@ -18,6 +18,7 @@ static/pipe02
 static/busyloop00
 static/cwd00
 static/cwd01
+static/cwd02
 static/env00
 static/maps00
 static/maps01
diff --git a/test/zdtm/.gitignore b/test/zdtm/.gitignore
index 7b88d9a..9d914ea 100644
--- a/test/zdtm/.gitignore
+++ b/test/zdtm/.gitignore
@@ -15,6 +15,7 @@
 /live/static/criu-rtc.pb-c.h
 /live/static/cwd00
 /live/static/cwd01
+/live/static/cwd02
 /live/static/deleted_dev
 /live/static/deleted_unix_sock
 /live/static/dumpable01
diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
index d4aeec2..34982bc 100644
--- a/test/zdtm/live/static/Makefile
+++ b/test/zdtm/live/static/Makefile
@@ -154,6 +154,7 @@ TST_FILE	=				\
 TST_DIR		=				\
 		cwd00				\
 		cwd01				\
+		cwd02				\
 		overmount_dev			\
 		overmount_file			\
 		overmount_fifo			\
diff --git a/test/zdtm/live/static/cwd02.c b/test/zdtm/live/static/cwd02.c
new file mode 100644
index 0000000..e7747f4
--- /dev/null
+++ b/test/zdtm/live/static/cwd02.c
@@ -0,0 +1,92 @@
+#include <errno.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+#include <string.h>
+#include <sys/wait.h>
+#include <fcntl.h>
+
+#include "zdtmtst.h"
+
+const char *test_doc	= "Check that removed and opened cwd are kept";
+const char *test_author	= "Pavel Emelianov <xemul at parallels.com>";
+
+char *dirname;
+TEST_OPTION(dirname, string, "directory name", 1);
+
+int main(int argc, char **argv)
+{
+	char cwd0[256];
+	int fd, pid, p[2], aux;
+	struct stat std, stf;
+
+	test_init(argc, argv);
+
+	pipe(p);
+	pid = fork();
+	if (pid == 0) {
+		close(p[1]);
+		read(p[0], &aux, sizeof(aux));
+		aux = rmdir(dirname);
+		exit(aux ? 1 : 0);
+	}
+
+	if (!getcwd(cwd0, sizeof(cwd0))) {
+		err("can't get cwd: %m\n");
+		exit(1);
+	}
+
+	if (mkdir(dirname, 0700)) {
+		err("can't make directory %s: %m\n", dirname);
+		exit(1);
+	}
+
+	if ((fd = open(dirname, O_DIRECTORY)) < 0) {
+		err("can't open dir %s: %m\n", dirname);
+		goto cleanup;
+	}
+
+	if (chdir(dirname)) {
+		err("can't change directory to %s: %m\n", dirname);
+		goto cleanup;
+	}
+
+	close(p[1]);
+	close(p[0]);
+	waitpid(pid, &aux, 0);
+	if (!WIFEXITED(aux) || WEXITSTATUS(aux) != 0) {
+		err("can't remove dir\n");
+		goto cleanup;
+	}
+
+	test_daemon();
+	test_waitsig();
+
+	if (fstat(fd, &stf) < 0) {
+		fail("dir fd closed\n");
+		goto cleanup;
+	}
+
+	if (stat("/proc/self/cwd", &std) < 0) {
+		fail("cwd is not OK\n");
+		goto cleanup;
+	}
+
+	if (stf.st_ino != std.st_ino ||
+			stf.st_dev != stf.st_dev) {
+		fail("cwd and opened fd are not the same\n");
+		goto cleanup;
+	}
+
+	pass();
+
+cleanup:
+	/* return to the initial dir before writing out results */
+	if (chdir(cwd0)) {
+		err("can't change directory to %s: %m\n", cwd0);
+		exit(1);
+	}
+
+	rmdir(dirname);
+	return 0;
+}
-- 
1.8.3.1




More information about the CRIU mailing list