[CRIU] Re: [PATCH 1/3] zdtm: Add fifo-rowo-pair test case
Cyrill Gorcunov
gorcunov at openvz.org
Sun Jul 1 09:38:53 EDT 2012
On Sun, Jul 01, 2012 at 04:51:15PM +0400, Andrey Wagin wrote:
> 2012/6/27 Cyrill Gorcunov <gorcunov at openvz.org>:
> > I need a special test case where fake
> > fifo will be created by us to restore
> > the former.
>
> Need more details about what and why this test case does
Andrew, something like below?
Cyrill
-------------- next part --------------
>From a96e56a8601b4dff19b6abc88ba5417bd298bf06 Mon Sep 17 00:00:00 2001
From: Cyrill Gorcunov <gorcunov at openvz.org>
Date: Thu, 7 Jun 2012 02:14:54 +0400
Subject: [PATCH] zdtm: Add fifo-rowo-pair test case v2
I need a special test case where fake
fifo will be created by us to restore
the former.
In particular I need O_WRONLY fifo in
children to be able to simulate a fifo
which waits for connection where our
tool should be able to handle such situation
by using fake fifo end.
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 | 162 ++++++++++++++++++++++++++++++++
3 files changed, 167 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..464728c
--- /dev/null
+++ b/test/zdtm/live/static/fifo-rowo-pair.c
@@ -0,0 +1,162 @@
+#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);
+
+#define TEST_VALUE 00100
+
+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 = TEST_VALUE;
+ if (write(new_slave, &v, sizeof(v)) != sizeof(v)) {
+ err("write failed: %m\n");
+ exit(1);
+ }
+
+ v = TEST_VALUE;
+ 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);
+ goto out_kill;
+ }
+
+ /* 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");
+ goto out_kill;
+ }
+
+ task_waiter_complete_current(&t);
+
+ if (v != TEST_VALUE) {
+ fail("read data mismatch\n");
+ goto out_wait;
+ }
+
+ if (read(fd_slave, &v, sizeof(v)) != sizeof(v)) {
+ err("read failed: %m\n");
+ goto out_wait;
+ }
+ if (v != TEST_VALUE) {
+ fail("read data mismatch\n");
+ goto out_wait;
+ }
+
+ waitpid(pid, &status, P_ALL);
+ if (!WIFEXITED(status))
+ kill(pid, SIGKILL);
+
+ 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 = WEXITSTATUS(status);
+ if (errno) {
+ fail("Child exited with error %m");
+ exit(errno);
+ }
+
+ pass();
+ return 0;
+
+out_kill:
+ kill(pid, SIGKILL);
+out_wait:
+ waitpid(pid, &status, P_ALL);
+ if (!WIFEXITED(status))
+ kill(pid, SIGKILL);
+ return 1;
+}
--
1.7.7.6
More information about the CRIU
mailing list