Commit e0939577 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

zdtm: Add fifo-rowo-pair test case

I need a special test case where fake
fifo will be created by us to restore
the former.
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent ea1ce8e4
......@@ -43,6 +43,7 @@ static/unlink_fstat02
static/eventfs00
static/inotify00
static/unbound_sock
static/fifo-rowo-pair
"
# Duplicate list with pidns/ prefix
TEST_LIST=$TEST_LIST$(echo $TEST_LIST | tr ' ' '\n' | sed 's#^#pidns/#')
......
......@@ -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 `< $<`
......
#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@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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment