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

zdtm: Add fifo ghost file test

Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Acked-by: 's avatarAndrey Wagin <avagin@gmail.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent e0939577
...@@ -44,6 +44,7 @@ static/eventfs00 ...@@ -44,6 +44,7 @@ static/eventfs00
static/inotify00 static/inotify00
static/unbound_sock static/unbound_sock
static/fifo-rowo-pair static/fifo-rowo-pair
static/fifo-ghost
" "
# Duplicate list with pidns/ prefix # Duplicate list with pidns/ prefix
TEST_LIST=$TEST_LIST$(echo $TEST_LIST | tr ' ' '\n' | sed 's#^#pidns/#') TEST_LIST=$TEST_LIST$(echo $TEST_LIST | tr ' ' '\n' | sed 's#^#pidns/#')
......
...@@ -69,6 +69,7 @@ TST_FILE = \ ...@@ -69,6 +69,7 @@ TST_FILE = \
unlink_largefile \ unlink_largefile \
mtime_mmap \ mtime_mmap \
fifo \ fifo \
fifo-ghost \
fifo_ro \ fifo_ro \
fifo_wronly \ fifo_wronly \
unlink_fifo \ unlink_fifo \
......
#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@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;
}
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