Commit 3ed37580 authored by Kirill Tkhai's avatar Kirill Tkhai Committed by Pavel Emelyanov

zdtm: Add aio01 test

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: 's avatarKirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent b6386369
......@@ -135,6 +135,7 @@ TST_NOFILE = \
remap_dead_pid \
remap_dead_pid_root \
aio00 \
aio01 \
fd \
apparmor \
seccomp_strict \
......
#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@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;
}
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