aboutsummaryrefslogtreecommitdiff
path: root/test/helpers.c
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-07-07 05:12:36 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-07-07 05:12:36 +0000
commit04d90211ecab6b0ddadadcf6c182f4607b9b72a8 (patch)
treeebe9c872e416346e4b333e5062da32401c8e0a73 /test/helpers.c
parentd53db6851ea17b2d219d084e1afc683b8b62b105 (diff)
parent1d27ff1934c5c4292dc00fba7f7f8ae411ed42f5 (diff)
downloadliburing-android14-mainline-uwb-release.tar.gz
Change-Id: Ic34ca4f84d38b3a9593603ab4791da9a91806588
Diffstat (limited to 'test/helpers.c')
-rw-r--r--test/helpers.c33
1 files changed, 31 insertions, 2 deletions
diff --git a/test/helpers.c b/test/helpers.c
index 930d82a..491822e 100644
--- a/test/helpers.c
+++ b/test/helpers.c
@@ -49,14 +49,14 @@ void *t_calloc(size_t nmemb, size_t size)
/*
* Helper for creating file and write @size byte buf with 0xaa value in the file.
*/
-void t_create_file(const char *file, size_t size)
+static void __t_create_file(const char *file, size_t size, char pattern)
{
ssize_t ret;
char *buf;
int fd;
buf = t_malloc(size);
- memset(buf, 0xaa, size);
+ memset(buf, pattern, size);
fd = open(file, O_WRONLY | O_CREAT, 0644);
assert(fd >= 0);
@@ -68,6 +68,16 @@ void t_create_file(const char *file, size_t size)
assert(ret == size);
}
+void t_create_file(const char *file, size_t size)
+{
+ __t_create_file(file, size, 0xaa);
+}
+
+void t_create_file_pattern(const char *file, size_t size, char pattern)
+{
+ __t_create_file(file, size, pattern);
+}
+
/*
* Helper for creating @buf_num number of iovec
* with @buf_size bytes buffer of each iovec.
@@ -114,3 +124,22 @@ enum t_setup_ret t_create_ring(int depth, struct io_uring *ring,
p.flags = flags;
return t_create_ring_params(depth, ring, &p);
}
+
+enum t_setup_ret t_register_buffers(struct io_uring *ring,
+ const struct iovec *iovecs,
+ unsigned nr_iovecs)
+{
+ int ret;
+
+ ret = io_uring_register_buffers(ring, iovecs, nr_iovecs);
+ if (!ret)
+ return T_SETUP_OK;
+
+ if ((ret == -EPERM || ret == -ENOMEM) && geteuid()) {
+ fprintf(stdout, "too large non-root buffer registration, skip\n");
+ return T_SETUP_SKIP;
+ }
+
+ fprintf(stderr, "buffer register failed: %s\n", strerror(-ret));
+ return ret;
+}