summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZhiqiang Liu <liuzhiqiang26@huawei.com>2021-02-23 14:43:57 +0800
committerZhiqiang Liu <liuzhiqiang26@huawei.com>2021-02-23 14:43:57 +0800
commitb7b089a671b9d4f2d453bf6f3ca106c5bb9d5d70 (patch)
tree2808798661ddc1b049bdf4c6b532cd99b92a5575
parent93bec4c6e5cad8ba4230a3fa5fcb99cc9b77e41a (diff)
downloadliburing-b7b089a671b9d4f2d453bf6f3ca106c5bb9d5d70.tar.gz
liburing-b7b089a671b9d4f2d453bf6f3ca106c5bb9d5d70.tar.bz2
helpers: add io_uring_calloc helper
add io_uring_calloc() helper, and replace all calloc() with io_uring_calloc() in all tests. Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
-rw-r--r--test/accept.c2
-rw-r--r--test/d4ae271dfaae-test.c2
-rw-r--r--test/file-register.c4
-rw-r--r--test/file-update.c2
-rw-r--r--test/helpers.c14
-rw-r--r--test/helpers.h7
-rw-r--r--test/probe.c3
-rw-r--r--test/read-write.c2
-rw-r--r--test/splice.c9
9 files changed, 32 insertions, 13 deletions
diff --git a/test/accept.c b/test/accept.c
index b1a5a71..a0a8ae6 100644
--- a/test/accept.c
+++ b/test/accept.c
@@ -247,7 +247,7 @@ static int test_accept_many(unsigned nr, unsigned usecs)
ret = io_uring_queue_init(2 * nr, &m_io_uring, 0);
assert(ret >= 0);
- fds = calloc(nr, sizeof(int));
+ fds = io_uring_calloc(nr, sizeof(int));
for (i = 0; i < nr; i++)
fds[i] = start_accept_listen(NULL, i);
diff --git a/test/d4ae271dfaae-test.c b/test/d4ae271dfaae-test.c
index 3b69482..98b43cc 100644
--- a/test/d4ae271dfaae-test.c
+++ b/test/d4ae271dfaae-test.c
@@ -76,7 +76,7 @@ int main(int argc, char *argv[])
goto out;
}
- iovecs = calloc(10, sizeof(struct iovec));
+ iovecs = io_uring_calloc(10, sizeof(struct iovec));
for (i = 0; i < 10; i++) {
io_uring_posix_memalign(&buf, 4096, 4096);
iovecs[i].iov_base = buf;
diff --git a/test/file-register.c b/test/file-register.c
index a7e9a21..2e08eca 100644
--- a/test/file-register.c
+++ b/test/file-register.c
@@ -39,7 +39,7 @@ static int *open_files(int nr_files, int extra, int add)
int *files;
int i;
- files = calloc(nr_files + extra, sizeof(int));
+ files = io_uring_calloc(nr_files + extra, sizeof(int));
for (i = 0; i < nr_files; i++) {
if (!add)
@@ -232,7 +232,7 @@ static int test_removals(struct io_uring *ring)
goto err;
}
- fds = calloc(10, sizeof(int));
+ fds = io_uring_calloc(10, sizeof(int));
for (i = 0; i < 10; i++)
fds[i] = -1;
diff --git a/test/file-update.c b/test/file-update.c
index bf7746b..341005c 100644
--- a/test/file-update.c
+++ b/test/file-update.c
@@ -37,7 +37,7 @@ static int *open_files(int nr_files, int extra, int add)
int *files;
int i;
- files = calloc(nr_files + extra, sizeof(int));
+ files = io_uring_calloc(nr_files + extra, sizeof(int));
for (i = 0; i < nr_files; i++) {
if (!add)
diff --git a/test/helpers.c b/test/helpers.c
index 83ed3e5..af6d936 100644
--- a/test/helpers.c
+++ b/test/helpers.c
@@ -28,3 +28,17 @@ void io_uring_posix_memalign(void **memptr, size_t alignment, size_t size)
ret = posix_memalign(memptr, alignment, size);
assert(!ret);
}
+
+/*
+ * Helper for allocating space for an array of nmemb elements
+ * with size bytes for each element.
+ */
+void *io_uring_calloc(size_t nmemb, size_t size)
+{
+ void *ret;
+ ret = calloc(nmemb, size);
+ assert(ret);
+ return ret;
+}
+
+
diff --git a/test/helpers.h b/test/helpers.h
index ba8c4fd..dc192d4 100644
--- a/test/helpers.h
+++ b/test/helpers.h
@@ -20,6 +20,13 @@ void *io_uring_malloc(size_t size);
*/
void io_uring_posix_memalign(void **memptr, size_t alignment, size_t size);
+
+/*
+ * Helper for allocating space for an array of nmemb elements
+ * with size bytes for each element.
+ */
+void *io_uring_calloc(size_t nmemb, size_t size);
+
#ifdef __cplusplus
}
#endif
diff --git a/test/probe.c b/test/probe.c
index 1961176..0881240 100644
--- a/test/probe.c
+++ b/test/probe.c
@@ -9,6 +9,7 @@
#include <string.h>
#include <fcntl.h>
+#include "helpers.h"
#include "liburing.h"
static int no_probe;
@@ -67,7 +68,7 @@ static int test_probe(struct io_uring *ring)
int ret;
len = sizeof(*p) + 256 * sizeof(struct io_uring_probe_op);
- p = calloc(1, len);
+ p = io_uring_calloc(1, len);
ret = io_uring_register_probe(ring, p, 0);
if (ret == -EINVAL) {
fprintf(stdout, "Probe not supported, skipping\n");
diff --git a/test/read-write.c b/test/read-write.c
index 25fda8a..cb15c26 100644
--- a/test/read-write.c
+++ b/test/read-write.c
@@ -364,7 +364,7 @@ static int has_nonvec_read(void)
exit(ret);
}
- p = calloc(1, sizeof(*p) + 256 * sizeof(struct io_uring_probe_op));
+ p = io_uring_calloc(1, sizeof(*p) + 256 * sizeof(struct io_uring_probe_op));
ret = io_uring_register_probe(&ring, p, 256);
/* if we don't have PROBE_REGISTER, we don't have OP_READ/WRITE */
if (ret == -EINVAL) {
diff --git a/test/splice.c b/test/splice.c
index 6442caf..0834aa3 100644
--- a/test/splice.c
+++ b/test/splice.c
@@ -6,6 +6,7 @@
#include <fcntl.h>
#include <sys/mman.h>
+#include "helpers.h"
#include "liburing.h"
#define BUF_SIZE (16 * 4096)
@@ -86,12 +87,8 @@ static int init_splice_ctx(struct test_ctx *ctx)
{
int ret, rnd_fd;
- ctx->buf_in = calloc(BUF_SIZE, 1);
- if (!ctx->buf_in)
- return 1;
- ctx->buf_out = calloc(BUF_SIZE, 1);
- if (!ctx->buf_out)
- return 1;
+ ctx->buf_in = io_uring_calloc(BUF_SIZE, 1);
+ ctx->buf_out = io_uring_calloc(BUF_SIZE, 1);
ctx->fd_in = create_file(".splice-test-in");
if (ctx->fd_in < 0) {