diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/README | 2 | ||||
| -rw-r--r-- | test/identifier.c | 1 | ||||
| -rw-r--r-- | test/io.c | 40 |
3 files changed, 24 insertions, 19 deletions
diff --git a/test/README b/test/README index 4ef67e0..5a0e197 100644 --- a/test/README +++ b/test/README @@ -22,7 +22,7 @@ Both macros can only be used inside a KPL_TEST function Asserting: -KPL_ASSSERT(condition, "Fail Message"); +KPL_ASSERT(condition, "Fail Message"); --- diff --git a/test/identifier.c b/test/identifier.c index bd50795..abbcdac 100644 --- a/test/identifier.c +++ b/test/identifier.c @@ -20,4 +20,5 @@ KPL_TEST(identifier_compare) { KPL_ASSERT(kpl_identifier_compare(&identifier_a, &identifier_b) == 0, "should be 0"); int32_t compare_value = strcmp(string_b, string_c); KPL_ASSERT(kpl_identifier_compare(&identifier_b, &identifier_c) == compare_value, "should equal strcmp"); + KPL_ASSERT(kpl_identifier_equal(&identifier_a, &identifier_b), "should be equal"); } @@ -4,21 +4,23 @@ static const char *linux_version = "/proc/version"; KPL_TEST(statx) { - 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"); + kpl_env env = {}; + kpl_thread thread = { .env = &env }; + kpl_io_uring *io_uring = &thread.io_uring; + KPL_ASSERT(kpl_io_uring_init(&thread.io_uring, KPL_IO_URING_QUEUE_SIZE_POW2_MIN) == 0, "should return 0 for success"); struct statx statx_object = {}; kpl_object_task *task = calloc(1, sizeof(kpl_object_task) + sizeof(kpl_class) * 1); task->io_res = 1; - KPL_ASSERT(kpl_io_uring_statx(&io_uring, task, AT_FDCWD, linux_version, 0, STATX_ALL, &statx_object), + KPL_ASSERT(kpl_io_uring_statx(io_uring, task, AT_FDCWD, linux_version, 0, STATX_ALL, &statx_object), "should add statx operation"); KPL_ASSERT(task->object_flags & KPL_OBJECT_FLAGS_IO_PENDING , "task should have io pending flag"); - 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(kpl_io_uring_submit(&thread) == 1, "should submit one io operation"); + KPL_ASSERT(task == kpl_io_uring_get_completed(&thread), "should return a task"); KPL_ASSERT(!(task->object_flags & KPL_OBJECT_FLAGS_IO_PENDING) , "task should not have io pending flag"); KPL_ASSERT(task->io_res == 0, "io_res should have success stax return"); KPL_ASSERT(statx_object.stx_nlink > 0, "should have one or more hard link(s)"); free(task); - kpl_io_uring_free(&io_uring); + kpl_io_uring_free(io_uring); } #define TEST_TO_READ 5 @@ -26,28 +28,30 @@ KPL_TEST(statx) { 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"); + kpl_env env = {}; + kpl_thread thread = { .env = &env }; + kpl_io_uring *io_uring = &thread.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), + 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(kpl_io_uring_submit(&thread) == 1, "should submit one io operation"); + KPL_ASSERT(task == kpl_io_uring_get_completed(&thread), "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(kpl_io_uring_read(io_uring, task, fd, &buffer, TEST_TO_READ, 0), "should add read operation"); + KPL_ASSERT(kpl_io_uring_submit(&thread) == 1, "should submit one io operation"); + KPL_ASSERT(task == kpl_io_uring_get_completed(&thread), "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(kpl_io_uring_close(io_uring, task, fd), "should add close operation"); + KPL_ASSERT(kpl_io_uring_submit(&thread) == 1, "should submit one io operation"); + KPL_ASSERT(task == kpl_io_uring_get_completed(&thread), "should return a task"); KPL_ASSERT(task->io_res == 0, "io_res should have close success"); free(task); - kpl_io_uring_free(&io_uring); + kpl_io_uring_free(io_uring); } |
