[CRIU] [PATCH 4/7] zdtm: Add fifo-rowo-pair test case
Cyrill Gorcunov
gorcunov at openvz.org
Thu Jun 28 11:59:27 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 | 4 +
test/zdtm/live/static/fifo-rowo-pair.c | 150 ++++++++++++++++++++++++++++++++
3 files changed, 155 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 85dba69..eef6021 100644
--- a/test/zdtm.sh
+++ b/test/zdtm.sh
@@ -42,6 +42,7 @@ static/unlink_fstat00
static/unlink_fstat02
static/eventfs00
static/inotify00
+static/fifo-rowo-pair
"
# 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 135bb23..11f34fb 100644
--- a/test/zdtm/live/static/Makefile
+++ b/test/zdtm/live/static/Makefile
@@ -87,6 +87,7 @@ TST = \
$(TST_FILE) \
$(TST_DIR) \
env00 \
+ fifo-rowo-pair \
umask00 \
cmdlinenv00 \
@@ -130,6 +131,9 @@ env00.pid: env00
umask00.pid: umask00
$(<D)/$(<F) --pidfile=$@ --outfile=$<.out --mask=0345
+fifo-rowo-pair.pid: fifo-rowo-pair
+ $(<D)/$(<F) --pidfile=$@ --outfile=$<.out --name_master=$<.master.test --name_slave=$<.slave.test
+
%.out: %.pid %
-kill -TERM `< $<`
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..17265a2
--- /dev/null
+++ b/test/zdtm/live/static/fifo-rowo-pair.c
@@ -0,0 +1,150 @@
+#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 *name_master;
+TEST_OPTION(name_master, string, "master fifo name", 1);
+
+char *name_slave;
+TEST_OPTION(name_slave, string, "slave fifo name", 1);
+
+int main(int argc, char **argv)
+{
+ task_waiter_t t;
+ pid_t pid;
+ int fd_master, fd_slave;
+ int v, status;
+
+ test_init(argc, argv);
+
+ if (mknod(name_master, S_IFIFO | 0700, 0)) {
+ err("can't make fifo \"%s\": %m\n", name_master);
+ exit(1);
+ }
+
+ if (mknod(name_slave, S_IFIFO | 0700, 0)) {
+ err("can't make fifo \"%s\": %m\n", name_slave);
+ exit(1);
+ }
+
+ fd_slave = open(name_slave, O_RDWR);
+ if (fd_slave < 0) {
+ err("can't open %s: %m\n", name_slave);
+ exit(1);
+ }
+
+ task_waiter_init(&t);
+
+ pid = test_fork();
+ if (pid == 0) {
+ int new_slave;
+
+ fd_master = open(name_master, O_WRONLY);
+ if (fd_master < 0) {
+ err("can't open %s: %m\n", name_master);
+ exit(1);
+ }
+
+ new_slave = dup2(fd_slave, 64);
+ if (new_slave < 0) {
+ err("can't dup %s: %m\n", name_slave);
+ exit(1);
+ }
+
+ close(fd_slave);
+
+ task_waiter_complete_current(&t);
+
+ v = 00100;
+ if (write(new_slave, &v, sizeof(v)) != sizeof(v)) {
+ err("write failed: %m\n");
+ exit(1);
+ }
+
+ v = 00100;
+ if (write(fd_master, &v, sizeof(v)) != sizeof(v)) {
+ err("write failed: %m\n");
+ exit(1);
+ }
+
+ /* Don't exit until explicitly asked */
+ task_waiter_wait4(&t, getppid());
+
+ exit(0);
+ } else if (pid < 0) {
+ err("test_fork failed: %m\n");
+ exit(1);
+ }
+
+ fd_master = open(name_master, O_RDONLY);
+ if (fd_master < 0) {
+ err("can't open %s: %m\n", name_master);
+ exit(1);
+ }
+
+ /* Wait until data appear in kernel fifo buffer */
+ task_waiter_wait4(&t, pid);
+
+ test_daemon();
+ test_waitsig();
+
+ if (read(fd_master, &v, sizeof(v)) != sizeof(v)) {
+ err("read failed: %m\n");
+ exit(1);
+ }
+
+ task_waiter_complete_current(&t);
+
+ if (v != 00100) {
+ fail("read data mismatch\n");
+ exit(1);
+ }
+
+ if (read(fd_slave, &v, sizeof(v)) != sizeof(v)) {
+ err("read failed: %m\n");
+ exit(1);
+ }
+ if (v != 00100) {
+ fail("read data mismatch\n");
+ exit(1);
+ }
+
+ waitpid(pid, &status, P_ALL);
+
+ if (unlink(name_master) < 0) {
+ err("can't unlink %s: %m", name_master);
+ exit(1);
+ }
+
+ if (unlink(name_slave) < 0) {
+ err("can't unlink %s: %m", name_slave);
+ 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