[CRIU] [PATCH v5 5/5] zdtm: Add aio01 test

Kirill Tkhai ktkhai at virtuozzo.com
Wed Mar 23 06:01:51 PDT 2016


Description:

1)Create io context, submit several io operations and
get events of some of them.

2)Sleep on signal.

3)Check tail, head and nr events restored correct.

4)Emit one more io operation.

5)Check tail has moved one number forward (i.e. synchronize
in-kernel and userspace tails if they were different).

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 test/zdtm/static/Makefile |    1 
 test/zdtm/static/aio01.c  |  114 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 115 insertions(+)
 create mode 100644 test/zdtm/static/aio01.c

diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile
index 7817e00..d4a2978 100644
--- a/test/zdtm/static/Makefile
+++ b/test/zdtm/static/Makefile
@@ -135,6 +135,7 @@ TST_NOFILE	=				\
 		remap_dead_pid			\
 		remap_dead_pid_root			\
 		aio00				\
+		aio01				\
 		fd				\
 		apparmor				\
 		seccomp_strict			\
diff --git a/test/zdtm/static/aio01.c b/test/zdtm/static/aio01.c
new file mode 100644
index 0000000..193f562
--- /dev/null
+++ b/test/zdtm/static/aio01.c
@@ -0,0 +1,114 @@
+#include <linux/aio_abi.h>
+#include <sys/syscall.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <aio.h>
+
+#include "zdtmtst.h"
+
+const char *test_doc	= "Check head and tail restore correct";
+const char *test_author	= "Kirill Tkhai <ktkhai at virtuozzo.com>";
+
+struct aio_ring {
+	unsigned	id;     /* kernel internal index number */
+	unsigned	nr;     /* number of io_events */
+	unsigned	head;   /* Written to by userland or under ring_lock
+				 * mutex by aio_read_events_ring(). */
+	unsigned	tail;
+	unsigned	magic;
+	unsigned	compat_features;
+	unsigned	incompat_features;
+	unsigned	header_length;	/* size of aio_ring */
+	struct io_event	io_events[0];
+}; /* 128 bytes + ring size */
+
+int main(int argc, char **argv)
+{
+	struct iocb iocb, *iocbp = &iocb;
+	volatile struct aio_ring *ring;
+	unsigned long ctx = 0;
+	struct io_event event;
+	unsigned tail[2], head[2];
+	unsigned nr[2];
+	int i, fd, ret;
+	char buf[1];
+
+	test_init(argc, argv);
+
+	memset(&iocb, 0, sizeof(iocb));
+
+	if (syscall(__NR_io_setup, 64, &ctx) < 0) {
+		pr_perror("Can't setup io ctx");
+		return 1;
+	}
+
+	fd = open("/dev/null", O_WRONLY);
+	if (fd < 0) {
+		pr_perror("Can't open /dev/null");
+		return 1;
+	}
+
+	iocb.aio_fildes = fd;
+	iocb.aio_buf = (unsigned long)buf;
+	iocb.aio_nbytes = 1;
+	iocb.aio_lio_opcode = IOCB_CMD_PWRITE;
+
+	ring = (struct aio_ring *)ctx;
+	nr[0] = ring->nr;
+
+	for (i = 0; i < nr[0] + 2; i++) {
+		if (syscall(__NR_io_submit, ctx, 1, &iocbp) != 1) {
+			fail("Can't submit aio");
+			return 1;
+		}
+
+		if (!(i % 2))
+			continue;
+
+		ret = syscall(__NR_io_getevents, ctx, 0, 1, &event, NULL);
+		if (ret != 1) {
+			fail("Can't get event");
+			return 1;
+		}
+	}
+
+	tail[0] = *((volatile unsigned *)&ring->tail);
+	head[0] = *((volatile unsigned *)&ring->head);
+
+	test_msg("tail=%u, head=%u, nr=%u\n", tail[0], head[0], nr[0]);
+
+	test_daemon();
+	test_waitsig();
+
+	tail[1] = *((volatile unsigned *)&ring->tail);
+	head[1] = *((volatile unsigned *)&ring->head);
+	nr[1] = *((volatile unsigned *)&ring->nr);
+
+	test_msg("tail=%u, head=%u, nr=%u\n", tail[1], head[1], nr[1]);
+
+	if (tail[0] != tail[1] || head[0] != head[1] || nr[0] != nr[1]) {
+		fail("missmatch");
+		return 1;
+	}
+
+	if (syscall(__NR_io_submit, ctx, 1, &iocbp) != 1) {
+		fail("Can't submit aio");
+		return 1;
+	}
+
+	tail[1] = *((volatile unsigned *)&ring->tail);
+	head[1] = *((volatile unsigned *)&ring->head);
+	nr[1] = *((volatile unsigned *)&ring->nr);
+
+	test_msg("tail=%u, head=%u, nr=%u\n", tail[1], head[1], nr[1]);
+
+	if (tail[1] == tail[0] + 1 && head[1] == head[0] && nr[1] == nr[0])
+		pass();
+	else
+		fail("mismatch");
+	return 0;
+}



More information about the CRIU mailing list