aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authornodist <kevin.comas.git@gmail.com>2026-10-17 19:44:26 -0400
committernodist <kevin.comas.git@gmail.com>2026-10-17 19:44:26 -0400
commitbaa6f9cdea938c06435635f906b128f7940a59ec (patch)
tree289432ee715aad5e072c47154f572cbf7be16859 /test
parent801aeb9172136ca93a4603fcf8dcf8e19a1522fe (diff)
add io_uring open_read_close testHEADmain
Diffstat (limited to 'test')
-rw-r--r--test/io.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/test/io.c b/test/io.c
index 2df3144..8a269fa 100644
--- a/test/io.c
+++ b/test/io.c
@@ -18,3 +18,34 @@ KPL_TEST(statx) {
free(task);
kpl_io_uring_free(&io_uring);
}
+
+#define TEST_TO_READ 5
+
+static const char *test_linix_compare = "Linux";
+
+KPL_TEST(open_read_close) {
+ kpl_io_uring io_uring = {};
+ KPL_ASSERT(kpl_io_uring_init(&io_uring, KPL_IO_URING_QUEUE_SIZE_POW2_MIN) == 0, "should return 0 for success");
+ char buffer[TEST_TO_READ + 1] = {};
+ kpl_object_task *task = calloc(1, sizeof(kpl_object_task) + sizeof(kpl_class) * 1);
+ task->io_res = 1;
+ KPL_ASSERT(kpl_io_uring_openat(&io_uring, task, AT_FDCWD, linux_version, O_RDONLY, 0),
+ "should add open operation");
+ KPL_ASSERT(kpl_io_uring_submit(&io_uring) == 1, "should submit one io operation");
+ KPL_ASSERT(task == kpl_io_uring_get_completed(&io_uring), "should return a task");
+ KPL_ASSERT(task->io_res > 0, "io_res should have open fd");
+ int32_t fd = task->io_res;
+ task->io_res = 1;
+ KPL_ASSERT(kpl_io_uring_read(&io_uring, task, fd, &buffer, TEST_TO_READ, 0), "should add read operation");
+ KPL_ASSERT(kpl_io_uring_submit(&io_uring) == 1, "should submit one io operation");
+ KPL_ASSERT(task == kpl_io_uring_get_completed(&io_uring), "should return a task");
+ KPL_ASSERT(task->io_res == TEST_TO_READ, "io_res should equal the number of bytes read");
+ KPL_ASSERT(strcmp(test_linix_compare, buffer) == 0, "should have Linux string in buffer");
+ task->io_res = 1;
+ KPL_ASSERT(kpl_io_uring_close(&io_uring, task, fd), "should add close operation");
+ KPL_ASSERT(kpl_io_uring_submit(&io_uring) == 1, "should submit one io operation");
+ KPL_ASSERT(task == kpl_io_uring_get_completed(&io_uring), "should return a task");
+ KPL_ASSERT(task->io_res == 0, "io_res should have close success");
+ free(task);
+ kpl_io_uring_free(&io_uring);
+}