[CRIU] [PATCH cr 02/11] zdtm: add a new test case to check that all
data can be restored
Andrey Vagin
avagin at openvz.org
Thu Apr 5 12:02:06 EDT 2012
* create pipe
* write a maximum amount of data
* suspend/resume
* check that all data have been restored
Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
test/zdtm.sh | 1 +
test/zdtm/live/static/Makefile | 1 +
test/zdtm/live/static/pipe01.c | 132 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 134 insertions(+), 0 deletions(-)
diff --git a/test/zdtm.sh b/test/zdtm.sh
index 2c35100..75b3576 100644
--- a/test/zdtm.sh
+++ b/test/zdtm.sh
@@ -4,6 +4,7 @@ ZP="zdtm/live"
TEST_LIST="
static/pipe00
+static/pipe01
static/busyloop00
static/cwd00
static/env00
diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
index c75b038..3b36a2c 100644
--- a/test/zdtm/live/static/Makefile
+++ b/test/zdtm/live/static/Makefile
@@ -27,6 +27,7 @@ TST_NOFILE = \
shm \
ptrace_sig \
pipe00 \
+ pipe01 \
pthread00 \
vdso00 \
utsname \
diff --git a/test/zdtm/live/static/pipe01.c b/test/zdtm/live/static/pipe01.c
new file mode 100644
index 0000000..db3f424
--- /dev/null
+++ b/test/zdtm/live/static/pipe01.c
@@ -0,0 +1,132 @@
+#include <unistd.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <string.h>
+#include <fcntl.h>
+#include <sys/wait.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <linux/limits.h>
+
+#include "zdtmtst.h"
+
+const char *test_doc = "Test that all data can be restored";
+const char *test_author = "Andrey Vagin <avagin at parallels.com>";
+
+#define TEST_STRING "Hello world"
+
+int main(int argc, char ** argv)
+{
+ int pfd[2], pfd_dup[2], pfd_rop[2];
+ char path[PATH_MAX];
+ int ret;
+ uint8_t buf[4096];
+ uint32_t crc;
+ int flags, size = 0;
+
+ test_init(argc, argv);
+
+ crc = ~0;
+ datagen(buf, sizeof(buf), &crc);
+
+ ret = pipe(pfd);
+ if (ret) {
+ err("pipe() failed: %m");
+ return 1;
+ }
+
+ pfd_dup[0] = dup(pfd[0]);
+ pfd_dup[1] = dup(pfd[1]);
+
+ snprintf(path, PATH_MAX, "/proc/self/fd/%d", pfd[0]);
+ pfd_rop[0] = open(path, O_RDONLY);
+ snprintf(path, PATH_MAX, "/proc/self/fd/%d", pfd[1]);
+ pfd_rop[1] = open(path, O_WRONLY);
+
+ if (pfd_rop[0] == -1 || pfd_rop[1] == -1 ||
+ pfd_dup[0] == -1 || pfd_dup[1] == -1) {
+ err("dup() failed");
+ return 1;
+ }
+
+ flags = fcntl(pfd[1], F_GETFL, 0);
+ if (flags == -1) {
+ err("fcntl() failed");
+ return 1;
+ }
+
+ ret = fcntl(pfd[1], F_SETFL, flags | O_NONBLOCK);
+ if (ret == -1) {
+ err("fcntl() failed");
+ return 1;
+ }
+
+ while (1) {
+ ret = write(pfd[1], buf, sizeof(buf));
+ if (ret == -1) {
+ if (errno == EAGAIN)
+ break;
+ err("write() failed: %m");
+ goto err;
+ }
+
+ size += ret;
+ }
+
+ test_daemon();
+
+ test_waitsig();
+
+ flags = fcntl(pfd[1], F_GETFL, 0);
+ if (!(flags & O_NONBLOCK)) {
+ err("O_NONBLOCK is absent");
+ goto err;
+ }
+
+ flags = fcntl(pfd_dup[1], F_GETFL, 0);
+ if (!(flags & O_NONBLOCK)) {
+ err("O_NONBLOCK is absent");
+ goto err;
+ }
+
+ flags = fcntl(pfd_rop[1], F_GETFL, 0);
+ if (flags & O_NONBLOCK) {
+ err("O_NONBLOCK appeared");
+ goto err;
+ }
+
+ if (close(pfd[1]) == -1) {
+ err("close() failed");
+ goto err;
+ }
+
+ close(pfd_dup[1]);
+ close(pfd_rop[1]);
+
+ while (1) {
+ ret = read(pfd[0], buf, sizeof(buf));
+ if (ret == 0)
+ break;
+ if (ret == -1) {
+ goto err;
+ err("read() failed: %m");
+ }
+ size -= ret;
+
+ crc = ~0;
+ ret = datachk(buf, sizeof(buf), &crc);
+ if (ret) {
+ fail("CRC mismatch\n");
+ goto err;
+ }
+ }
+
+ if (size)
+ goto err;
+
+ pass();
+ return 0;
+err:
+ fail();
+ return 1;
+}
--
1.7.1
More information about the CRIU
mailing list