[CRIU] [PATCH 3/3] zdtm: Add fifo ghost file test

Cyrill Gorcunov gorcunov at openvz.org
Wed Jun 27 10:28:37 EDT 2012


Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 test/zdtm.sh                       |    1 +
 test/zdtm/live/static/Makefile     |    1 +
 test/zdtm/live/static/fifo-ghost.c |   81 ++++++++++++++++++++++++++++++++++++
 3 files changed, 83 insertions(+), 0 deletions(-)
 create mode 100644 test/zdtm/live/static/fifo-ghost.c

diff --git a/test/zdtm.sh b/test/zdtm.sh
index 2b74b41..6964ff1 100644
--- a/test/zdtm.sh
+++ b/test/zdtm.sh
@@ -44,6 +44,7 @@ static/unlink_fstat02
 static/eventfs00
 static/inotify00
 static/fifo-rowo-pair
+static/fifo-ghost
 "
 # Duplicate list with pidns/ prefix
 TEST_LIST=$TEST_LIST$(echo $TEST_LIST | tr ' ' '\n' | sed 's#^#pidns/#')
diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
index 8a002c3..cb24dbd 100644
--- a/test/zdtm/live/static/Makefile
+++ b/test/zdtm/live/static/Makefile
@@ -69,6 +69,7 @@ TST_FILE	=				\
 		unlink_largefile		\
 		mtime_mmap			\
 		fifo				\
+		fifo-ghost			\
 		fifo_ro				\
 		fifo_wronly			\
 		unlink_fifo			\
diff --git a/test/zdtm/live/static/fifo-ghost.c b/test/zdtm/live/static/fifo-ghost.c
new file mode 100644
index 0000000..93fcf4f
--- /dev/null
+++ b/test/zdtm/live/static/fifo-ghost.c
@@ -0,0 +1,81 @@
+#include <errno.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/mount.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include "zdtmtst.h"
+
+const char *test_doc	= "Check that a ghost fifo with data restored";
+const char *test_author	= "Cyrill Gorcunov <gorcunov at openvz.org>";
+
+char *filename;
+TEST_OPTION(filename, string, "file name", 1);
+
+int main(int argc, char **argv)
+{
+	int fd;
+	int fd_ro;
+	mode_t mode = S_IFIFO | 0700;
+	uint8_t buf[256];
+	uint32_t crc;
+	int ret;
+
+	test_init(argc, argv);
+
+	if (mknod(filename, mode, 0)) {
+		err("can't make fifo \"%s\": %m\n", filename);
+		exit(1);
+	}
+
+	fd = open(filename, O_RDWR);
+	if (fd < 0) {
+		err("can't open %s: %m\n", filename);
+		return 1;
+	}
+
+	fd_ro = open(filename, O_RDONLY);
+	if (fd_ro < 0) {
+		err("can't open %s: %m\n", filename);
+		return 1;
+	}
+
+	crc = ~0;
+	datagen(buf, sizeof(buf), &crc);
+	ret = write(fd, buf, sizeof(buf));
+	if (ret != sizeof(buf)) {
+		err("write() failed\n");
+		return 1;
+	}
+
+	if (unlink(filename) < 0) {
+		fail("can't unlink %s: %m", filename);
+		return 1;
+	}
+
+	close(fd);
+
+	test_daemon();
+	test_waitsig();
+
+	ret = read(fd_ro, buf, sizeof(buf));
+	if (ret != sizeof(buf)) {
+		err("read() failed\n");
+		return 1;
+	}
+
+	crc = ~0;
+	if (datachk(buf, sizeof(buf), &crc)) {
+		fail("data corrupted\n");
+		return 1;
+	}
+
+	if (close(fd_ro) < 0) {
+		fail("can't close %s: %m", filename);
+		return 1;
+	}
+
+	pass();
+	return 0;
+}
-- 
1.7.7.6



More information about the CRIU mailing list