summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZhiqiang Liu <liuzhiqiang26@huawei.com>2021-02-23 20:25:54 +0800
committerZhiqiang Liu <liuzhiqiang26@huawei.com>2021-02-23 20:34:54 +0800
commitb6e4a0aba34a7d9a0656ad04a2265a5854ef85f4 (patch)
tree28639614f5daf9653a60c3d61f45700415d9276c
parentfa7ba190db8eb4bbbad9118a80b782c20bbbc6ca (diff)
downloadliburing-b6e4a0aba34a7d9a0656ad04a2265a5854ef85f4.tar.gz
liburing-b6e4a0aba34a7d9a0656ad04a2265a5854ef85f4.tar.bz2
helpers: add io_uring_create_buffers() helper
add io_uring_create_buffers() helper, and replace create_buffers() with io_uring_create_buffers() helper. Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
-rw-r--r--test/cq-overflow.c18
-rw-r--r--test/helpers.c19
-rw-r--r--test/helpers.h5
-rw-r--r--test/io-cancel.c18
-rw-r--r--test/iopoll.c18
-rw-r--r--test/read-write.c18
-rw-r--r--test/sq-poll-dup.c18
-rw-r--r--test/sq-poll-share.c18
8 files changed, 30 insertions, 102 deletions
diff --git a/test/cq-overflow.c b/test/cq-overflow.c
index a22da6b..f116678 100644
--- a/test/cq-overflow.c
+++ b/test/cq-overflow.c
@@ -19,19 +19,6 @@
static struct iovec *vecs;
-static int create_buffers(void)
-{
- int i;
-
- vecs = io_uring_malloc(BUFFERS * sizeof(struct iovec));
- for (i = 0; i < BUFFERS; i++) {
- io_uring_posix_memalign(&vecs[i].iov_base, BS, BS);
- vecs[i].iov_len = BS;
- }
-
- return 0;
-}
-
#define ENTRIES 8
static int test_io(const char *file, unsigned long usecs, unsigned *drops, int fault)
@@ -475,10 +462,7 @@ int main(int argc, char *argv[])
io_uring_create_file(".basic-rw", FILE_SIZE);
- if (create_buffers()) {
- fprintf(stderr, "file creation failed\n");
- goto err;
- }
+ vecs = io_uring_create_buffers(BUFFERS, BS);
iters = 0;
usecs = 1000;
diff --git a/test/helpers.c b/test/helpers.c
index c5a82fa..2350c11 100644
--- a/test/helpers.c
+++ b/test/helpers.c
@@ -10,6 +10,7 @@
#include <unistd.h>
#include "helpers.h"
+#include "liburing.h"
/*
* Helper for allocating memory in tests.
@@ -67,3 +68,21 @@ void io_uring_create_file(const char *file, size_t size)
assert(ret == size);
}
+
+/*
+ * Helper for creating @buf_num number of iovec
+ * with @buf_size bytes buffer of each iovec.
+ */
+struct iovec *io_uring_create_buffers(size_t buf_num, size_t buf_size)
+{
+ struct iovec *vecs;
+ int i;
+
+ vecs = io_uring_malloc(buf_num * sizeof(struct iovec));
+ for (i = 0; i < buf_num; i++) {
+ io_uring_posix_memalign(&vecs[i].iov_base, buf_size, buf_size);
+ vecs[i].iov_len = buf_size;
+ }
+ return vecs;
+}
+
diff --git a/test/helpers.h b/test/helpers.h
index 4cc357f..e6190ac 100644
--- a/test/helpers.h
+++ b/test/helpers.h
@@ -33,6 +33,11 @@ void *io_uring_calloc(size_t nmemb, size_t size);
*/
void io_uring_create_file(const char *file, size_t size);
+/*
+ * Helper for creating @buf_num number of iovec
+ * with @buf_size bytes buffer of each iovec.
+ */
+struct iovec *io_uring_create_buffers(size_t buf_num, size_t buf_size);
#ifdef __cplusplus
}
#endif
diff --git a/test/io-cancel.c b/test/io-cancel.c
index 25bac7a..1deb430 100644
--- a/test/io-cancel.c
+++ b/test/io-cancel.c
@@ -20,19 +20,6 @@
static struct iovec *vecs;
-static int create_buffers(void)
-{
- int i;
-
- vecs = io_uring_malloc(BUFFERS * sizeof(struct iovec));
- for (i = 0; i < BUFFERS; i++) {
- io_uring_posix_memalign(&vecs[i].iov_base, BS, BS);
- vecs[i].iov_len = BS;
- }
-
- return 0;
-}
-
static unsigned long long utime_since(const struct timeval *s,
const struct timeval *e)
{
@@ -218,10 +205,7 @@ int main(int argc, char *argv[])
io_uring_create_file(".basic-rw", FILE_SIZE);
- if (create_buffers()) {
- fprintf(stderr, "file creation failed\n");
- goto err;
- }
+ vecs = io_uring_create_buffers(BUFFERS, BS);
for (i = 0; i < 4; i++) {
int v1 = (i & 1) != 0;
diff --git a/test/iopoll.c b/test/iopoll.c
index b1dafd0..4ddc646 100644
--- a/test/iopoll.c
+++ b/test/iopoll.c
@@ -24,19 +24,6 @@ static struct iovec *vecs;
static int no_buf_select;
static int no_iopoll;
-static int create_buffers(void)
-{
- int i;
-
- vecs = io_uring_malloc(BUFFERS * sizeof(struct iovec));
- for (i = 0; i < BUFFERS; i++) {
- io_uring_posix_memalign(&vecs[i].iov_base, BS, BS);
- vecs[i].iov_len = BS;
- }
-
- return 0;
-}
-
static int provide_buffers(struct io_uring *ring)
{
struct io_uring_sqe *sqe;
@@ -350,10 +337,7 @@ int main(int argc, char *argv[])
io_uring_create_file(fname, FILE_SIZE);
}
- if (create_buffers()) {
- fprintf(stderr, "file creation failed\n");
- goto err;
- }
+ vecs = io_uring_create_buffers(BUFFERS, BS);
nr = 16;
if (no_buf_select)
diff --git a/test/read-write.c b/test/read-write.c
index bd6df37..4a331d5 100644
--- a/test/read-write.c
+++ b/test/read-write.c
@@ -25,19 +25,6 @@ static int no_read;
static int no_buf_select;
static int warned;
-static int create_buffers(void)
-{
- int i;
-
- vecs = io_uring_malloc(BUFFERS * sizeof(struct iovec));
- for (i = 0; i < BUFFERS; i++) {
- io_uring_posix_memalign(&vecs[i].iov_base, BS, BS);
- vecs[i].iov_len = BS;
- }
-
- return 0;
-}
-
static int create_nonaligned_buffers(void)
{
int i;
@@ -768,10 +755,7 @@ int main(int argc, char *argv[])
io_uring_create_file(fname, FILE_SIZE);
}
- if (create_buffers()) {
- fprintf(stderr, "file creation failed\n");
- goto err;
- }
+ vecs = io_uring_create_buffers(BUFFERS, BS);
/* if we don't have nonvec read, skip testing that */
nr = has_nonvec_read() ? 32 : 16;
diff --git a/test/sq-poll-dup.c b/test/sq-poll-dup.c
index 18dae3f..a6e50f0 100644
--- a/test/sq-poll-dup.c
+++ b/test/sq-poll-dup.c
@@ -26,19 +26,6 @@
static struct iovec *vecs;
static struct io_uring rings[NR_RINGS];
-static int create_buffers(void)
-{
- int i;
-
- vecs = io_uring_malloc(BUFFERS * sizeof(struct iovec));
- for (i = 0; i < BUFFERS; i++) {
- io_uring_posix_memalign(&vecs[i].iov_base, BS, BS);
- vecs[i].iov_len = BS;
- }
-
- return 0;
-}
-
static int wait_io(struct io_uring *ring, int nr_ios)
{
struct io_uring_cqe *cqe;
@@ -177,10 +164,7 @@ int main(int argc, char *argv[])
io_uring_create_file(fname, FILE_SIZE);
}
- if (create_buffers()) {
- fprintf(stderr, "file creation failed\n");
- goto err;
- }
+ vecs = io_uring_create_buffers(BUFFERS, BS);
fd = open(fname, O_RDONLY | O_DIRECT);
if (fd < 0) {
diff --git a/test/sq-poll-share.c b/test/sq-poll-share.c
index d2e82a0..4f1192d 100644
--- a/test/sq-poll-share.c
+++ b/test/sq-poll-share.c
@@ -24,19 +24,6 @@
static struct iovec *vecs;
-static int create_buffers(void)
-{
- int i;
-
- vecs = io_uring_malloc(BUFFERS * sizeof(struct iovec));
- for (i = 0; i < BUFFERS; i++) {
- io_uring_posix_memalign(&vecs[i].iov_base, BS, BS);
- vecs[i].iov_len = BS;
- }
-
- return 0;
-}
-
static int wait_io(struct io_uring *ring, int nr_ios)
{
struct io_uring_cqe *cqe;
@@ -99,10 +86,7 @@ int main(int argc, char *argv[])
io_uring_create_file(fname, FILE_SIZE);
}
- if (create_buffers()) {
- fprintf(stderr, "file creation failed\n");
- goto err;
- }
+ vecs = io_uring_create_buffers(BUFFERS, BS);
fd = open(fname, O_RDONLY | O_DIRECT);
if (fd < 0) {