aboutsummaryrefslogtreecommitdiff
path: root/test/read-write.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/read-write.c')
-rw-r--r--test/read-write.c67
1 files changed, 29 insertions, 38 deletions
diff --git a/test/read-write.c b/test/read-write.c
index d0a77fa..3951a64 100644
--- a/test/read-write.c
+++ b/test/read-write.c
@@ -9,15 +9,15 @@
#include <string.h>
#include <fcntl.h>
#include <sys/types.h>
-#include <sys/poll.h>
+#include <poll.h>
#include <sys/eventfd.h>
#include <sys/resource.h>
#include "helpers.h"
#include "liburing.h"
-#define FILE_SIZE (128 * 1024)
-#define BS 4096
+#define FILE_SIZE (256 * 1024)
+#define BS 8192
#define BUFFERS (FILE_SIZE / BS)
static struct iovec *vecs;
@@ -49,7 +49,7 @@ static int __test_io(const char *file, struct io_uring *ring, int write,
struct io_uring_sqe *sqe;
struct io_uring_cqe *cqe;
int open_flags;
- int i, fd, ret;
+ int i, fd = -1, ret;
off_t offset;
#ifdef VERBOSE
@@ -57,13 +57,6 @@ static int __test_io(const char *file, struct io_uring *ring, int write,
buffered, sqthread,
fixed, nonvec);
#endif
- if (sqthread && geteuid()) {
-#ifdef VERBOSE
- fprintf(stdout, "SKIPPED (not root)\n");
-#endif
- return 0;
- }
-
if (write)
open_flags = O_WRONLY;
else
@@ -71,19 +64,22 @@ static int __test_io(const char *file, struct io_uring *ring, int write,
if (!buffered)
open_flags |= O_DIRECT;
+ if (fixed) {
+ ret = t_register_buffers(ring, vecs, BUFFERS);
+ if (ret == T_SETUP_SKIP)
+ return 0;
+ if (ret != T_SETUP_OK) {
+ fprintf(stderr, "buffer reg failed: %d\n", ret);
+ goto err;
+ }
+ }
+
fd = open(file, open_flags);
if (fd < 0) {
perror("file open");
goto err;
}
- if (fixed) {
- ret = io_uring_register_buffers(ring, vecs, BUFFERS);
- if (ret) {
- fprintf(stderr, "buffer reg failed: %d\n", ret);
- goto err;
- }
- }
if (sqthread) {
ret = io_uring_register_files(ring, &fd, 1);
if (ret) {
@@ -235,30 +231,21 @@ static int test_io(const char *file, int write, int buffered, int sqthread,
int fixed, int nonvec, int exp_len)
{
struct io_uring ring;
- int ret, ring_flags;
+ int ret, ring_flags = 0;
- if (sqthread) {
- if (geteuid()) {
- if (!warned) {
- fprintf(stderr, "SQPOLL requires root, skipping\n");
- warned = 1;
- }
- return 0;
- }
+ if (sqthread)
ring_flags = IORING_SETUP_SQPOLL;
- } else {
- ring_flags = 0;
- }
- ret = io_uring_queue_init(64, &ring, ring_flags);
- if (ret) {
+ ret = t_create_ring(64, &ring, ring_flags);
+ if (ret == T_SETUP_SKIP)
+ return 0;
+ if (ret != T_SETUP_OK) {
fprintf(stderr, "ring create failed: %d\n", ret);
return 1;
}
ret = __test_io(file, &ring, write, buffered, sqthread, fixed, nonvec,
0, 0, exp_len);
-
io_uring_queue_exit(&ring);
return ret;
}
@@ -493,7 +480,7 @@ static int test_buf_select(const char *filename, int nonvec)
fprintf(stdout, "Buffer select not supported, skipping\n");
return 0;
}
- free(p);
+ io_uring_free_probe(p);
/*
* Write out data with known pattern
@@ -671,8 +658,8 @@ static int test_write_efbig(void)
return 1;
}
rlim = old_rlim;
- rlim.rlim_cur = 64 * 1024;
- rlim.rlim_max = 64 * 1024;
+ rlim.rlim_cur = 128 * 1024;
+ rlim.rlim_max = 128 * 1024;
if (setrlimit(RLIMIT_FSIZE, &rlim) < 0) {
perror("setrlimit");
return 1;
@@ -683,6 +670,7 @@ static int test_write_efbig(void)
perror("file open");
goto err;
}
+ unlink(".efbig");
ret = io_uring_queue_init(32, &ring, 0);
if (ret) {
@@ -739,19 +727,22 @@ static int test_write_efbig(void)
err:
if (fd != -1)
close(fd);
- unlink(".efbig");
return 1;
}
int main(int argc, char *argv[])
{
int i, ret, nr;
+ char buf[256];
char *fname;
if (argc > 1) {
fname = argv[1];
} else {
- fname = ".basic-rw";
+ srand((unsigned)time(NULL));
+ snprintf(buf, sizeof(buf), ".basic-rw-%u-%u",
+ (unsigned)rand(), (unsigned)getpid());
+ fname = buf;
t_create_file(fname, FILE_SIZE);
}