[CRIU] [PATCH 5/5] zdtm: paketized pipe test introduced
Stanislav Kinsburskiy
skinsbursky at virtuozzo.com
Tue Dec 15 02:58:09 PST 2015
Signed-off-by: Stanislav Kinsburskiy <skinsbursky at virtuozzo.com>
---
test/zdtm/live/static/Makefile | 1
test/zdtm/live/static/pipe03.c | 89 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 90 insertions(+)
create mode 100644 test/zdtm/live/static/pipe03.c
diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
index a6995c6..6a7f823 100644
--- a/test/zdtm/live/static/Makefile
+++ b/test/zdtm/live/static/Makefile
@@ -50,6 +50,7 @@ TST_NOFILE = \
pipe00 \
pipe01 \
pipe02 \
+ pipe03 \
pthread00 \
pthread01 \
pthread02 \
diff --git a/test/zdtm/live/static/pipe03.c b/test/zdtm/live/static/pipe03.c
new file mode 100644
index 0000000..a5353f0
--- /dev/null
+++ b/test/zdtm/live/static/pipe03.c
@@ -0,0 +1,89 @@
+#include <linux/limits.h>
+#define _GNU_SOURCE /* See feature_test_macros(7) */
+#include <fcntl.h> /* Obtain O_* constant definitions */
+#include <unistd.h>
+
+#include "zdtmtst.h"
+
+const char *test_doc = "Test migration of paketized pipe";
+const char *test_author = "Stanislav Kinsburskiy <skinsbursky at odin.com>";
+
+int main(int argc, char ** argv)
+{
+ int p[2];
+ ssize_t res;
+ char *messages[] = {
+ "This ",
+ "is ",
+ "a ",
+ "test ",
+ "message ",
+ "for ",
+ "paketized ",
+ "pipe.",
+ NULL,
+ }, **m;
+ char buf[PIPE_BUF];
+
+ test_init(argc, argv);
+
+ if (pipe2(p, O_DIRECT | O_NONBLOCK))
+ return 1;
+
+ m = messages;
+ do {
+ if (write(p[1], *m, strlen(*m) + 1) != strlen(*m) + 1) {
+ pr_perror("write failed");
+ return 1;
+ }
+ } while (*(++m));
+
+ test_daemon();
+
+ test_waitsig();
+
+ m = messages;
+ do {
+ res = read(p[0], buf, PIPE_BUF);
+ if (res < 0) {
+ pr_perror("read failed");
+ goto fail;
+ }
+ if (res != strlen(*m) + 1) {
+ pr_err("Read more that expected: %d instead of %d\n",
+ res, strlen(*m) + 1);
+ pr_err("Read : \"%s\"\n", buf);
+ pr_err("Expected: \"%s\"\n", *m);
+ goto fail;
+ }
+ if (strcmp(*m, buf)) {
+ pr_err("Packet doesn't match: \"%s\" "
+ "(instead of \"%s\")\n",
+ buf, *m);
+ goto fail;
+ }
+ } while (*(++m));
+
+ /* All the sent packets have arrived.
+ * Let's check, that there are no more in the queue */
+ res = read(p[0], buf, PIPE_BUF);
+ if (res != -1) {
+ pr_err("Unexpected packet in the pipe:");
+ fail();
+ pr_err("Packet content: \"%s\"\n", buf);
+ return 1;
+ }
+ if (errno != EAGAIN) {
+ pr_err("Read failed, but errno is wrong: %d (%s)\n", errno,
+ strerror(errno));
+ goto fail;
+ }
+
+ pass();
+
+ return 0;
+
+fail:
+ fail();
+ return 1;
+}
More information about the CRIU
mailing list