[CRIU] [PATCH 21/21] zdtm: Add fifo-rowo-pair test case

Cyrill Gorcunov gorcunov at openvz.org
Wed Jun 6 18:22:01 EDT 2012


I need a special test case where fake
fifo will be created by us to restore
the former.

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

diff --git a/test/zdtm.sh b/test/zdtm.sh
index eb84a26..058c99f 100644
--- a/test/zdtm.sh
+++ b/test/zdtm.sh
@@ -45,6 +45,7 @@ static/unlink_fstat00
 static/unlink_fstat02
 static/eventfs00
 static/inotify00
+static/fifo-rowo-pair
 "
 
 UTS_TEST_LIST="
diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
index a399741..de13d39 100644
--- a/test/zdtm/live/static/Makefile
+++ b/test/zdtm/live/static/Makefile
@@ -68,6 +68,7 @@ TST_FILE	=				\
 		unlink_fifo			\
 		unlink_fifo_wronly		\
 		file_shared			\
+		fifo-rowo-pair			\
 
 TST_DIR		=				\
 		cwd00				\
diff --git a/test/zdtm/live/static/fifo-rowo-pair.c b/test/zdtm/live/static/fifo-rowo-pair.c
new file mode 100644
index 0000000..df1d82b
--- /dev/null
+++ b/test/zdtm/live/static/fifo-rowo-pair.c
@@ -0,0 +1,108 @@
+#define _GNU_SOURCE
+#include <unistd.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <string.h>
+#include <utime.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/mman.h>
+
+#include <time.h>
+
+#include "zdtmtst.h"
+
+const char *test_doc	= "Test for fifo ro/wo with "
+			  "fake fifo needed on crtools side";
+const char *test_author	= "Cyrill Gorcunov <gorcunov at openvz.org>";
+
+char *filename;
+TEST_OPTION(filename, string, "fifo name", 1);
+
+int main(int argc, char **argv)
+{
+	task_waiter_t t;
+	pid_t pid;
+	int fd, v;
+	int status;
+
+	test_init(argc, argv);
+
+	if (mknod(filename, S_IFIFO | 0700, 0)) {
+		err("can't make fifo \"%s\": %m\n", filename);
+		exit(1);
+	}
+
+	task_waiter_init(&t);
+
+	pid = test_fork();
+	if (pid == 0) {
+		fd = open(filename, O_WRONLY);
+		if (fd < 0) {
+			err("can't open %s: %m\n", filename);
+			exit(1);
+		}
+
+		task_waiter_complete(&t);
+		task_waiter_update(&t);
+
+		v = 00100;
+		if (write(fd, &v, sizeof(v)) != sizeof(v)) {
+			err("write failed: %m\n");
+			exit(1);
+		}
+
+		/* Don't exit until explicitly asked */
+		task_waiter_wait(&t);
+
+		exit(0);
+	} else if (pid < 0) {
+		err("test_fork failed: %m\n");
+		exit(1);
+	}
+
+	fd = open(filename, O_RDONLY);
+	if (fd < 0) {
+		err("can't open %s: %m\n", filename);
+		exit(1);
+	}
+
+	/* Wait until data appear in kernel fifo buffer */
+	task_waiter_wait(&t);
+
+	test_daemon();
+	test_waitsig();
+
+	if (read(fd, &v, sizeof(v)) != sizeof(v)) {
+		err("read failed: %m\n");
+		exit(1);
+	}
+
+	task_waiter_complete(&t);
+	task_waiter_update(&t);
+
+	if (v != 00100) {
+		fail("read data mismatch\n");
+		exit(1);
+	}
+
+	waitpid(pid, &status, P_ALL);
+
+	if (unlink(filename) < 0) {
+		err("can't unlink %s: %m", filename);
+		exit(1);
+	}
+
+	errno = (status >> 8) & 0x7f;
+	if (errno) {
+		fail("Child exited with error %m");
+		exit(errno);
+	}
+
+	pass();
+	return 0;
+}
-- 
1.7.7.6



More information about the CRIU mailing list