summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZhiqiang Liu <liuzhiqiang26@huawei.com>2021-02-23 11:42:07 +0800
committerZhiqiang Liu <liuzhiqiang26@huawei.com>2021-02-23 11:57:53 +0800
commit93bec4c6e5cad8ba4230a3fa5fcb99cc9b77e41a (patch)
tree0f8fb8b26f7f996f5756fbebb01f0e2bc0d72ee0
parentcdd38178038dce9a97d6ffc1c0f0453650948536 (diff)
downloadliburing-93bec4c6e5cad8ba4230a3fa5fcb99cc9b77e41a.tar.gz
liburing-93bec4c6e5cad8ba4230a3fa5fcb99cc9b77e41a.tar.bz2
helpers: add io_uring_posix_memalign helper
add io_uring_posix_memalign helper, and replace all posix_memalign() with io_uring_posix_memalign() in all tests. Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
-rw-r--r--test/500f9fbadef8-test.c6
-rw-r--r--test/cq-overflow.c3
-rw-r--r--test/d4ae271dfaae-test.c3
-rw-r--r--test/helpers.c11
-rw-r--r--test/helpers.h6
-rw-r--r--test/io-cancel.c3
-rw-r--r--test/iopoll.c3
-rw-r--r--test/read-write.c3
-rw-r--r--test/sq-poll-dup.c3
-rw-r--r--test/sq-poll-share.c3
-rw-r--r--test/stdout.c11
11 files changed, 29 insertions, 26 deletions
diff --git a/test/500f9fbadef8-test.c b/test/500f9fbadef8-test.c
index 9ebff43..51081c5 100644
--- a/test/500f9fbadef8-test.c
+++ b/test/500f9fbadef8-test.c
@@ -10,6 +10,7 @@
#include <string.h>
#include <fcntl.h>
+#include "helpers.h"
#include "liburing.h"
#define BLOCKS 4096
@@ -28,10 +29,7 @@ int main(int argc, char *argv[])
if (argc > 1)
return 0;
- if (posix_memalign(&iov.iov_base, 4096, 4096)) {
- fprintf(stderr, "memalign failed\n");
- return 1;
- }
+ io_uring_posix_memalign(&iov.iov_base, 4096, 4096);
iov.iov_len = 4096;
ret = io_uring_queue_init(1, &ring, IORING_SETUP_IOPOLL);
diff --git a/test/cq-overflow.c b/test/cq-overflow.c
index e5ccee4..0303966 100644
--- a/test/cq-overflow.c
+++ b/test/cq-overflow.c
@@ -25,8 +25,7 @@ static int create_buffers(void)
vecs = io_uring_malloc(BUFFERS * sizeof(struct iovec));
for (i = 0; i < BUFFERS; i++) {
- if (posix_memalign(&vecs[i].iov_base, BS, BS))
- return 1;
+ io_uring_posix_memalign(&vecs[i].iov_base, BS, BS);
vecs[i].iov_len = BS;
}
diff --git a/test/d4ae271dfaae-test.c b/test/d4ae271dfaae-test.c
index b4c48fc..3b69482 100644
--- a/test/d4ae271dfaae-test.c
+++ b/test/d4ae271dfaae-test.c
@@ -78,8 +78,7 @@ int main(int argc, char *argv[])
iovecs = calloc(10, sizeof(struct iovec));
for (i = 0; i < 10; i++) {
- if (posix_memalign(&buf, 4096, 4096))
- goto out;
+ io_uring_posix_memalign(&buf, 4096, 4096);
iovecs[i].iov_base = buf;
iovecs[i].iov_len = 4096;
}
diff --git a/test/helpers.c b/test/helpers.c
index 7acf184..83ed3e5 100644
--- a/test/helpers.c
+++ b/test/helpers.c
@@ -17,3 +17,14 @@ void *io_uring_malloc(size_t size)
assert(ret);
return ret;
}
+
+
+/*
+ * Helper for allocating size bytes aligned on a boundary.
+ */
+void io_uring_posix_memalign(void **memptr, size_t alignment, size_t size)
+{
+ int ret;
+ ret = posix_memalign(memptr, alignment, size);
+ assert(!ret);
+}
diff --git a/test/helpers.h b/test/helpers.h
index 6a268c1..ba8c4fd 100644
--- a/test/helpers.h
+++ b/test/helpers.h
@@ -14,6 +14,12 @@ extern "C" {
*/
void *io_uring_malloc(size_t size);
+
+/*
+ * Helper for allocating size bytes aligned on a boundary.
+ */
+void io_uring_posix_memalign(void **memptr, size_t alignment, size_t size);
+
#ifdef __cplusplus
}
#endif
diff --git a/test/io-cancel.c b/test/io-cancel.c
index aeaa0ff..4dfcef0 100644
--- a/test/io-cancel.c
+++ b/test/io-cancel.c
@@ -26,8 +26,7 @@ static int create_buffers(void)
vecs = io_uring_malloc(BUFFERS * sizeof(struct iovec));
for (i = 0; i < BUFFERS; i++) {
- if (posix_memalign(&vecs[i].iov_base, BS, BS))
- return 1;
+ io_uring_posix_memalign(&vecs[i].iov_base, BS, BS);
vecs[i].iov_len = BS;
}
diff --git a/test/iopoll.c b/test/iopoll.c
index 2f47b3e..9a27dac 100644
--- a/test/iopoll.c
+++ b/test/iopoll.c
@@ -30,8 +30,7 @@ static int create_buffers(void)
vecs = io_uring_malloc(BUFFERS * sizeof(struct iovec));
for (i = 0; i < BUFFERS; i++) {
- if (posix_memalign(&vecs[i].iov_base, BS, BS))
- return 1;
+ io_uring_posix_memalign(&vecs[i].iov_base, BS, BS);
vecs[i].iov_len = BS;
}
diff --git a/test/read-write.c b/test/read-write.c
index 484a840..25fda8a 100644
--- a/test/read-write.c
+++ b/test/read-write.c
@@ -31,8 +31,7 @@ static int create_buffers(void)
vecs = io_uring_malloc(BUFFERS * sizeof(struct iovec));
for (i = 0; i < BUFFERS; i++) {
- if (posix_memalign(&vecs[i].iov_base, BS, BS))
- return 1;
+ io_uring_posix_memalign(&vecs[i].iov_base, BS, BS);
vecs[i].iov_len = BS;
}
diff --git a/test/sq-poll-dup.c b/test/sq-poll-dup.c
index 73bb285..cda0b5f 100644
--- a/test/sq-poll-dup.c
+++ b/test/sq-poll-dup.c
@@ -32,8 +32,7 @@ static int create_buffers(void)
vecs = io_uring_malloc(BUFFERS * sizeof(struct iovec));
for (i = 0; i < BUFFERS; i++) {
- if (posix_memalign(&vecs[i].iov_base, BS, BS))
- return 1;
+ io_uring_posix_memalign(&vecs[i].iov_base, BS, BS);
vecs[i].iov_len = BS;
}
diff --git a/test/sq-poll-share.c b/test/sq-poll-share.c
index 393178b..f74278e 100644
--- a/test/sq-poll-share.c
+++ b/test/sq-poll-share.c
@@ -30,8 +30,7 @@ static int create_buffers(void)
vecs = io_uring_malloc(BUFFERS * sizeof(struct iovec));
for (i = 0; i < BUFFERS; i++) {
- if (posix_memalign(&vecs[i].iov_base, BS, BS))
- return 1;
+ io_uring_posix_memalign(&vecs[i].iov_base, BS, BS);
vecs[i].iov_len = BS;
}
diff --git a/test/stdout.c b/test/stdout.c
index 25585dc..6380e1b 100644
--- a/test/stdout.c
+++ b/test/stdout.c
@@ -9,6 +9,7 @@
#include <string.h>
#include <fcntl.h>
+#include "helpers.h"
#include "liburing.h"
static int test_pipe_io_fixed(struct io_uring *ring)
@@ -20,10 +21,7 @@ static int test_pipe_io_fixed(struct io_uring *ring)
char buffer[128];
int i, ret, fds[2];
- if (posix_memalign(&vecs[0].iov_base, 4096, 4096)) {
- fprintf(stderr, "Failed to alloc mem\n");
- return 1;
- }
+ io_uring_posix_memalign(&vecs[0].iov_base, 4096, 4096);
memcpy(vecs[0].iov_base, str, strlen(str));
vecs[0].iov_len = strlen(str);
@@ -104,10 +102,7 @@ static int test_stdout_io_fixed(struct io_uring *ring)
struct iovec vecs;
int ret;
- if (posix_memalign(&vecs.iov_base, 4096, 4096)) {
- fprintf(stderr, "Failed to alloc mem\n");
- return 1;
- }
+ io_uring_posix_memalign(&vecs.iov_base, 4096, 4096);
memcpy(vecs.iov_base, str, strlen(str));
vecs.iov_len = strlen(str);