helpers: add io_uring_create_file() helper
cleanup: add io_uring_create_file() helper,
and replace create_file() with io_uring_calloc() in tests.
Signed-off-by: Zhiqiang Liu <[email protected]>
diff --git a/test/helpers.c b/test/helpers.c
index af6d936..c5a82fa 100644
--- a/test/helpers.c
+++ b/test/helpers.c
@@ -4,6 +4,10 @@
*/
#include <stdlib.h>
#include <assert.h>
+#include <string.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <unistd.h>
#include "helpers.h"
@@ -41,4 +45,25 @@
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);
+}