Merge branch 'add-memalign-helper' of https://github.com/ZhiqiangLiu26/liburing
* 'add-memalign-helper' of https://github.com/ZhiqiangLiu26/liburing:
helpers: add io_uring_create_buffers() helper
helpers: add io_uring_create_file() helper
helpers: add io_uring_calloc helper
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 @@
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/cq-overflow.c b/test/cq-overflow.c
index 0303966..f116678 100644
--- a/test/cq-overflow.c
+++ b/test/cq-overflow.c
@@ -19,38 +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;
-}
-
-static int create_file(const char *file)
-{
- ssize_t ret;
- char *buf;
- int fd;
-
- buf = io_uring_malloc(FILE_SIZE);
- memset(buf, 0xaa, FILE_SIZE);
-
- fd = open(file, O_WRONLY | O_CREAT, 0644);
- if (fd < 0) {
- perror("open file");
- return 1;
- }
- ret = write(fd, buf, FILE_SIZE);
- close(fd);
- return ret != FILE_SIZE;
-}
-
#define ENTRIES 8
static int test_io(const char *file, unsigned long usecs, unsigned *drops, int fault)
@@ -492,14 +460,9 @@
return ret;
}
- if (create_file(".basic-rw")) {
- fprintf(stderr, "file creation failed\n");
- goto err;
- }
- if (create_buffers()) {
- fprintf(stderr, "file creation failed\n");
- goto err;
- }
+ io_uring_create_file(".basic-rw", FILE_SIZE);
+
+ vecs = io_uring_create_buffers(BUFFERS, BS);
iters = 0;
usecs = 1000;
diff --git a/test/d4ae271dfaae-test.c b/test/d4ae271dfaae-test.c
index 3b69482..06ec268 100644
--- a/test/d4ae271dfaae-test.c
+++ b/test/d4ae271dfaae-test.c
@@ -16,26 +16,6 @@
#define FILE_SIZE (128 * 1024)
-static int create_file(const char *file)
-{
- ssize_t ret;
- char *buf;
- int fd;
-
- buf = io_uring_malloc(FILE_SIZE);
- memset(buf, 0xaa, FILE_SIZE);
-
- fd = open(file, O_WRONLY | O_CREAT, 0644);
- if (fd < 0) {
- perror("open file");
- return 1;
- }
- ret = write(fd, buf, FILE_SIZE);
- fsync(fd);
- close(fd);
- return ret != FILE_SIZE;
-}
-
int main(int argc, char *argv[])
{
struct io_uring ring;
@@ -64,10 +44,7 @@
fname = argv[1];
} else {
fname = ".sqpoll.tmp";
- if (create_file(fname)) {
- fprintf(stderr, "file creation failed\n");
- goto out;
- }
+ io_uring_create_file(fname, FILE_SIZE);
}
fd = open(fname, O_RDONLY | O_DIRECT);
@@ -76,7 +53,7 @@
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/fadvise.c b/test/fadvise.c
index 6bf58ef..69dc985 100644
--- a/test/fadvise.c
+++ b/test/fadvise.c
@@ -42,26 +42,6 @@
return utime_since(tv, &end);
}
-static int create_file(const char *file)
-{
- ssize_t ret;
- char *buf;
- int fd;
-
- buf = io_uring_malloc(FILE_SIZE);
- memset(buf, 0xaa, FILE_SIZE);
-
- fd = open(file, O_WRONLY | O_CREAT, 0644);
- if (fd < 0) {
- perror("open file");
- return 1;
- }
- ret = write(fd, buf, FILE_SIZE);
- fsync(fd);
- close(fd);
- return ret != FILE_SIZE;
-}
-
static int do_fadvise(struct io_uring *ring, int fd, off_t offset, off_t len,
int advice)
{
@@ -184,10 +164,7 @@
fname = argv[1];
} else {
fname = ".fadvise.tmp";
- if (create_file(".fadvise.tmp")) {
- fprintf(stderr, "file creation failed\n");
- goto err;
- }
+ io_uring_create_file(fname, FILE_SIZE);
}
if (io_uring_queue_init(8, &ring, 0)) {
fprintf(stderr, "ring creation failed\n");
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 @@
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 @@
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 @@
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/fsync.c b/test/fsync.c
index 1cd4f8d..5aa5a83 100644
--- a/test/fsync.c
+++ b/test/fsync.c
@@ -138,35 +138,13 @@
#define FILE_SIZE 1024
-static int create_file(const char *file)
-{
- ssize_t ret;
- char *buf;
- int fd;
-
- buf = io_uring_malloc(FILE_SIZE);
- memset(buf, 0xaa, FILE_SIZE);
-
- fd = open(file, O_WRONLY | O_CREAT, 0644);
- if (fd < 0) {
- perror("open file");
- return 1;
- }
- ret = write(fd, buf, FILE_SIZE);
- close(fd);
- return ret != FILE_SIZE;
-}
-
static int test_sync_file_range(struct io_uring *ring)
{
int ret, fd, save_errno;
struct io_uring_sqe *sqe;
struct io_uring_cqe *cqe;
- if (create_file(".sync_file_range")) {
- fprintf(stderr, "file creation failed\n");
- return 1;
- }
+ io_uring_create_file(".sync_file_range", FILE_SIZE);
fd = open(".sync_file_range", O_RDWR);
save_errno = errno;
diff --git a/test/helpers.c b/test/helpers.c
index 83ed3e5..2350c11 100644
--- a/test/helpers.c
+++ b/test/helpers.c
@@ -4,8 +4,13 @@
*/
#include <stdlib.h>
#include <assert.h>
+#include <string.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <unistd.h>
#include "helpers.h"
+#include "liburing.h"
/*
* Helper for allocating memory in tests.
@@ -28,3 +33,56 @@
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;
+}
+
+/*
+ * Helper for creating file and write @size byte buf with 0xaa value in the file.
+ */
+void io_uring_create_file(const char *file, size_t size)
+{
+ ssize_t ret;
+ char *buf;
+ int fd;
+
+ buf = io_uring_malloc(size);
+ memset(buf, 0xaa, size);
+
+ fd = open(file, O_WRONLY | O_CREAT, 0644);
+ assert(fd >= 0);
+
+ ret = write(fd, buf, size);
+ fsync(fd);
+ close(fd);
+ free(buf);
+ 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 ba8c4fd..e6190ac 100644
--- a/test/helpers.h
+++ b/test/helpers.h
@@ -20,6 +20,24 @@
*/
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);
+
+
+/*
+ * Helper for creating file and write @size byte buf with 0xaa value in the file.
+ */
+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 4dfcef0..1deb430 100644
--- a/test/io-cancel.c
+++ b/test/io-cancel.c
@@ -20,38 +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 int create_file(const char *file)
-{
- ssize_t ret;
- char *buf;
- int fd;
-
- buf = io_uring_malloc(FILE_SIZE);
- memset(buf, 0xaa, FILE_SIZE);
-
- fd = open(file, O_WRONLY | O_CREAT, 0644);
- if (fd < 0) {
- perror("open file");
- return 1;
- }
- ret = write(fd, buf, FILE_SIZE);
- close(fd);
- return ret != FILE_SIZE;
-}
-
static unsigned long long utime_since(const struct timeval *s,
const struct timeval *e)
{
@@ -235,14 +203,9 @@
if (argc > 1)
return 0;
- if (create_file(".basic-rw")) {
- fprintf(stderr, "file creation failed\n");
- goto err;
- }
- if (create_buffers()) {
- fprintf(stderr, "file creation failed\n");
- goto err;
- }
+ io_uring_create_file(".basic-rw", FILE_SIZE);
+
+ 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 9a27dac..4ddc646 100644
--- a/test/iopoll.c
+++ b/test/iopoll.c
@@ -24,38 +24,6 @@
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 create_file(const char *file)
-{
- ssize_t ret;
- char *buf;
- int fd;
-
- buf = io_uring_malloc(FILE_SIZE);
- memset(buf, 0xaa, FILE_SIZE);
-
- fd = open(file, O_WRONLY | O_CREAT, 0644);
- if (fd < 0) {
- perror("open file");
- return 1;
- }
- ret = write(fd, buf, FILE_SIZE);
- close(fd);
- return ret != FILE_SIZE;
-}
-
static int provide_buffers(struct io_uring *ring)
{
struct io_uring_sqe *sqe;
@@ -366,16 +334,10 @@
fname = argv[1];
} else {
fname = ".iopoll-rw";
- if (create_file(".iopoll-rw")) {
- fprintf(stderr, "file creation failed\n");
- goto err;
- }
+ 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/madvise.c b/test/madvise.c
index 2a10779..c06465f 100644
--- a/test/madvise.c
+++ b/test/madvise.c
@@ -44,26 +44,6 @@
return utime_since(tv, &end);
}
-static int create_file(const char *file)
-{
- ssize_t ret;
- char *buf;
- int fd;
-
- buf = io_uring_malloc(FILE_SIZE);
- memset(buf, 0xaa, FILE_SIZE);
-
- fd = open(file, O_WRONLY | O_CREAT, 0644);
- if (fd < 0) {
- perror("open file");
- return 1;
- }
- ret = write(fd, buf, FILE_SIZE);
- fsync(fd);
- close(fd);
- return ret != FILE_SIZE;
-}
-
static int do_madvise(struct io_uring *ring, void *addr, off_t len, int advice)
{
struct io_uring_sqe *sqe;
@@ -179,10 +159,7 @@
fname = argv[1];
} else {
fname = ".madvise.tmp";
- if (create_file(".madvise.tmp")) {
- fprintf(stderr, "file creation failed\n");
- goto err;
- }
+ io_uring_create_file(fname, FILE_SIZE);
}
if (io_uring_queue_init(8, &ring, 0)) {
diff --git a/test/open-close.c b/test/open-close.c
index 59c6d3a..6d44c6a 100644
--- a/test/open-close.c
+++ b/test/open-close.c
@@ -13,25 +13,6 @@
#include "helpers.h"
#include "liburing.h"
-static int create_file(const char *file, size_t size)
-{
- ssize_t ret;
- char *buf;
- int fd;
-
- buf = io_uring_malloc(size);
- memset(buf, 0xaa, size);
-
- fd = open(file, O_WRONLY | O_CREAT, 0644);
- if (fd < 0) {
- perror("open file");
- return 1;
- }
- ret = write(fd, buf, size);
- close(fd);
- return ret != size;
-}
-
static int test_close(struct io_uring *ring, int fd, int is_ring_fd)
{
struct io_uring_cqe *cqe;
@@ -119,14 +100,10 @@
do_unlink = 1;
}
- if (create_file(path, 4096)) {
- fprintf(stderr, "file create failed\n");
- return 1;
- }
- if (do_unlink && create_file(path_rel, 4096)) {
- fprintf(stderr, "file create failed\n");
- return 1;
- }
+ io_uring_create_file(path, 4096);
+
+ if (do_unlink)
+ io_uring_create_file(path_rel, 4096);
ret = test_openat(&ring, path, -1);
if (ret < 0) {
diff --git a/test/openat2.c b/test/openat2.c
index 7994804..750a2b4 100644
--- a/test/openat2.c
+++ b/test/openat2.c
@@ -13,25 +13,6 @@
#include "helpers.h"
#include "liburing.h"
-static int create_file(const char *file, size_t size)
-{
- ssize_t ret;
- char *buf;
- int fd;
-
- buf = io_uring_malloc(size);
- memset(buf, 0xaa, size);
-
- fd = open(file, O_WRONLY | O_CREAT, 0644);
- if (fd < 0) {
- perror("open file");
- return 1;
- }
- ret = write(fd, buf, size);
- close(fd);
- return ret != size;
-}
-
static int test_openat2(struct io_uring *ring, const char *path, int dfd)
{
struct io_uring_cqe *cqe;
@@ -88,14 +69,10 @@
do_unlink = 1;
}
- if (create_file(path, 4096)) {
- fprintf(stderr, "file create failed\n");
- return 1;
- }
- if (do_unlink && create_file(path_rel, 4096)) {
- fprintf(stderr, "file create failed\n");
- return 1;
- }
+ io_uring_create_file(path, 4096);
+
+ if (do_unlink)
+ io_uring_create_file(path_rel, 4096);
ret = test_openat2(&ring, path, -1);
if (ret < 0) {
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 @@
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..4a331d5 100644
--- a/test/read-write.c
+++ b/test/read-write.c
@@ -25,19 +25,6 @@
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;
@@ -55,25 +42,6 @@
return 0;
}
-static int create_file(const char *file)
-{
- ssize_t ret;
- char *buf;
- int fd;
-
- buf = io_uring_malloc(FILE_SIZE);
- memset(buf, 0xaa, FILE_SIZE);
-
- fd = open(file, O_WRONLY | O_CREAT, 0644);
- if (fd < 0) {
- perror("open file");
- return 1;
- }
- ret = write(fd, buf, FILE_SIZE);
- close(fd);
- return ret != FILE_SIZE;
-}
-
static int __test_io(const char *file, struct io_uring *ring, int write,
int buffered, int sqthread, int fixed, int nonvec,
int buf_select, int seq, int exp_len)
@@ -364,7 +332,7 @@
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) {
@@ -784,16 +752,10 @@
fname = argv[1];
} else {
fname = ".basic-rw";
- if (create_file(fname)) {
- fprintf(stderr, "file creation failed\n");
- goto err;
- }
+ 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/short-read.c b/test/short-read.c
index 4d84937..c839799 100644
--- a/test/short-read.c
+++ b/test/short-read.c
@@ -15,25 +15,6 @@
#define BUF_SIZE 4096
#define FILE_SIZE 1024
-static int create_file(const char *file)
-{
- ssize_t ret;
- char *buf;
- int fd;
-
- buf = io_uring_malloc(FILE_SIZE);
- memset(buf, 0xaa, FILE_SIZE);
-
- fd = open(file, O_WRONLY | O_CREAT, 0644);
- if (fd < 0) {
- perror("open file");
- return 1;
- }
- ret = write(fd, buf, FILE_SIZE);
- close(fd);
- return ret != FILE_SIZE;
-}
-
int main(int argc, char *argv[])
{
int ret, fd, save_errno;
@@ -48,10 +29,7 @@
vec.iov_base = io_uring_malloc(BUF_SIZE);
vec.iov_len = BUF_SIZE;
- if (create_file(".short-read")) {
- fprintf(stderr, "file creation failed\n");
- return 1;
- }
+ io_uring_create_file(".short-read", FILE_SIZE);
fd = open(".short-read", O_RDONLY);
save_errno = errno;
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 @@
{
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) {
diff --git a/test/sq-poll-dup.c b/test/sq-poll-dup.c
index cda0b5f..a6e50f0 100644
--- a/test/sq-poll-dup.c
+++ b/test/sq-poll-dup.c
@@ -26,38 +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 create_file(const char *file)
-{
- ssize_t ret;
- char *buf;
- int fd;
-
- buf = io_uring_malloc(FILE_SIZE);
- memset(buf, 0xaa, FILE_SIZE);
-
- fd = open(file, O_WRONLY | O_CREAT, 0644);
- if (fd < 0) {
- perror("open file");
- return 1;
- }
- ret = write(fd, buf, FILE_SIZE);
- close(fd);
- return ret != FILE_SIZE;
-}
-
static int wait_io(struct io_uring *ring, int nr_ios)
{
struct io_uring_cqe *cqe;
@@ -193,16 +161,10 @@
fname = argv[1];
} else {
fname = ".basic-rw";
- if (create_file(fname)) {
- fprintf(stderr, "file creation failed\n");
- goto err;
- }
+ 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 f74278e..4f1192d 100644
--- a/test/sq-poll-share.c
+++ b/test/sq-poll-share.c
@@ -24,38 +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 create_file(const char *file)
-{
- ssize_t ret;
- char *buf;
- int fd;
-
- buf = io_uring_malloc(FILE_SIZE);
- memset(buf, 0xaa, FILE_SIZE);
-
- fd = open(file, O_WRONLY | O_CREAT, 0644);
- if (fd < 0) {
- perror("open file");
- return 1;
- }
- ret = write(fd, buf, FILE_SIZE);
- close(fd);
- return ret != FILE_SIZE;
-}
-
static int wait_io(struct io_uring *ring, int nr_ios)
{
struct io_uring_cqe *cqe;
@@ -115,16 +83,10 @@
fname = argv[1];
} else {
fname = ".basic-rw";
- if (create_file(fname)) {
- fprintf(stderr, "file creation failed\n");
- goto err;
- }
+ 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/statx.c b/test/statx.c
index abbc4cb..bd8b5a3 100644
--- a/test/statx.c
+++ b/test/statx.c
@@ -31,25 +31,6 @@
}
#endif
-static int create_file(const char *file, size_t size)
-{
- ssize_t ret;
- char *buf;
- int fd;
-
- buf = io_uring_malloc(size);
- memset(buf, 0xaa, size);
-
- fd = open(file, O_WRONLY | O_CREAT, 0644);
- if (fd < 0) {
- perror("open file");
- return 1;
- }
- ret = write(fd, buf, size);
- close(fd);
- return ret != size;
-}
-
static int statx_syscall_supported(void)
{
return errno == ENOSYS ? 0 : -1;
@@ -162,10 +143,7 @@
fname = argv[1];
} else {
fname = "/tmp/.statx";
- if (create_file(fname, 4096)) {
- fprintf(stderr, "file create failed\n");
- return 1;
- }
+ io_uring_create_file(fname, 4096);
}
ret = test_statx(&ring, fname);
diff --git a/test/submit-reuse.c b/test/submit-reuse.c
index 35109fb..3c09d8d 100644
--- a/test/submit-reuse.c
+++ b/test/submit-reuse.c
@@ -38,26 +38,6 @@
return NULL;
}
-static int create_file(const char *file)
-{
- ssize_t ret;
- char *buf;
- int fd;
-
- buf = io_uring_malloc(FILE_SIZE);
- memset(buf, 0xaa, FILE_SIZE);
-
- fd = open(file, O_WRONLY | O_CREAT, 0644);
- if (fd < 0) {
- perror("open file");
- return 1;
- }
- ret = write(fd, buf, FILE_SIZE);
- fsync(fd);
- close(fd);
- return ret != FILE_SIZE;
-}
-
static char str1[STR_SIZE];
static char str2[STR_SIZE];
@@ -177,14 +157,10 @@
return 0;
}
- if (do_unlink && create_file(fname1)) {
- fprintf(stderr, "file creation failed\n");
- goto err;
- }
- if (create_file(".reuse.2")) {
- fprintf(stderr, "file creation failed\n");
- goto err;
- }
+ if (do_unlink)
+ io_uring_create_file(fname1, FILE_SIZE);
+
+ io_uring_create_file(".reuse.2", FILE_SIZE);
fd1 = open(fname1, O_RDONLY);
if (fd1 < 0) {
diff --git a/test/thread-exit.c b/test/thread-exit.c
index 2f15aa7..dc9bfaf 100644
--- a/test/thread-exit.c
+++ b/test/thread-exit.c
@@ -20,26 +20,6 @@
#define NR_IOS 8
#define WSIZE 512
-static int create_file(const char *file, size_t size)
-{
- ssize_t ret;
- char *buf;
- int fd;
-
- buf = io_uring_malloc(size);
- memset(buf, 0xaa, size);
-
- fd = open(file, O_WRONLY | O_CREAT, 0644);
- if (fd < 0) {
- perror("open file");
- return 1;
- }
- ret = write(fd, buf, size);
- close(fd);
- free(buf);
- return ret != size;
-}
-
struct d {
int fd;
struct io_uring *ring;
@@ -108,10 +88,8 @@
do_unlink = 1;
}
- if (do_unlink && create_file(fname, 4096)) {
- fprintf(stderr, "file create failed\n");
- return 1;
- }
+ if (do_unlink)
+ io_uring_create_file(fname, 4096);
fd = open(fname, O_WRONLY);
if (fd < 0) {