From 822e754cafdc5a32c80c97ca015cd6f9008329c3 Mon Sep 17 00:00:00 2001 From: Andrew Opalach Date: Tue, 24 Dec 2024 14:38:53 -0500 Subject: Rename, cleanup and pass on readability Signed-off-by: Andrew Opalach --- tests/fs_event_local.c | 27 ++++++++++++++++----------- tests/loop_sleep.c | 40 ++++++++++++++++++++-------------------- tests/meson.build | 7 +++++++ tests/stdin_lines.c | 26 +++++++++++++------------- tests/timer_loop.c | 40 ++++++++++++++++++++-------------------- tests/timer_thread.c | 22 +++++++++++----------- 6 files changed, 87 insertions(+), 75 deletions(-) create mode 100644 tests/meson.build (limited to 'tests') diff --git a/tests/fs_event_local.c b/tests/fs_event_local.c index 2e1e41d..25cd545 100644 --- a/tests/fs_event_local.c +++ b/tests/fs_event_local.c @@ -1,30 +1,35 @@ -#include -#include -#include +#include +#include +#include +#include static str *TEST_FILE_PATH = al_str_c("./test.txt"); -static struct aki_event_loop loop; -static struct aki_fs_event fs; +static struct nn_event_loop loop; +static struct nn_fs_event fs; static void fs_event_callback(void *userdata, struct inotify_event *event) { (void)userdata; (void)event; al_printf("WRITE CLOSE\n"); - aki_fs_event_stop(&fs); + nn_fs_event_stop(&fs); } s32 main(void) { - if (!aki_common_init()) return EXIT_FAILURE; + if (!nn_common_init()) return EXIT_FAILURE; - aki_event_loop_init(&loop); + nn_event_loop_init(&loop); - aki_fs_event_init(&fs, TEST_FILE_PATH, AKI_CLOSE_WRITE, fs_event_callback, NULL); - if (!aki_fs_event_start(&fs, &loop)) return EXIT_FAILURE; + if (!nn_file_exists(TEST_FILE_PATH)) + nn_file_create(TEST_FILE_PATH); - aki_event_loop_run(&loop); + nn_fs_event_init(&fs, TEST_FILE_PATH, NNWT_CLOSE_WRITE, fs_event_callback, NULL); + if (!nn_fs_event_start(&fs, &loop)) + return EXIT_FAILURE; + + nn_event_loop_run(&loop); return EXIT_SUCCESS; } diff --git a/tests/loop_sleep.c b/tests/loop_sleep.c index 4823bae..0fe16fd 100644 --- a/tests/loop_sleep.c +++ b/tests/loop_sleep.c @@ -1,47 +1,47 @@ -#include -#include -#include +#include +#include +#include -static struct aki_event_loop loop; -static struct aki_timer timer; +static struct nn_event_loop loop; +static struct nn_timer timer; -static void timer_callback2(void *userdata, struct aki_timer *timer) +static void timer_callback2(void *userdata, struct nn_timer *timer) { (void)userdata; al_printf("4\n"); - aki_timer_stop(timer); - aki_event_loop_sleep(&loop, AKI_TS_FROM_USEC(600000)); + nn_timer_stop(timer); + nn_event_loop_sleep(&loop, NNWT_TS_FROM_USEC(600000)); al_printf("5\n"); } -static void timer_callback(void *userdata, struct aki_timer *timer) +static void timer_callback(void *userdata, struct nn_timer *timer) { (void)userdata; al_printf("1\n"); - aki_event_loop_sleep(&loop, AKI_TS_FROM_USEC(100000)); + nn_event_loop_sleep(&loop, NNWT_TS_FROM_USEC(100000)); al_printf("2\n"); timer->callback = timer_callback2; - aki_timer_again(timer); - aki_event_loop_sleep(&loop, AKI_TS_FROM_USEC(800000)); + nn_timer_again(timer); + nn_event_loop_sleep(&loop, NNWT_TS_FROM_USEC(800000)); al_printf("3\n"); - aki_event_loop_sleep(&loop, AKI_TS_FROM_USEC(2000000)); + nn_event_loop_sleep(&loop, NNWT_TS_FROM_USEC(2000000)); al_printf("6\n"); } s32 main(void) { - if (!aki_common_init()) return EXIT_FAILURE; + if (!nn_common_init()) return EXIT_FAILURE; - aki_event_loop_init(&loop); + nn_event_loop_init(&loop); - aki_timer_init(&timer, &loop, timer_callback, NULL); - aki_timer_set_repeat(&timer, AKI_TS_FROM_USEC(1000000)); - aki_timer_again(&timer); + nn_timer_init(&timer, &loop, timer_callback, NULL); + nn_timer_set_repeat(&timer, NNWT_TS_FROM_USEC(1000000)); + nn_timer_again(&timer); - aki_event_loop_sleep(&loop, AKI_TS_FROM_USEC(6000000)); + nn_event_loop_sleep(&loop, NNWT_TS_FROM_USEC(6000000)); al_printf("7\n"); - aki_event_loop_run(&loop); + nn_event_loop_run(&loop); return EXIT_SUCCESS; } diff --git a/tests/meson.build b/tests/meson.build new file mode 100644 index 0000000..de795eb --- /dev/null +++ b/tests/meson.build @@ -0,0 +1,7 @@ +executable('timer_thread', ['timer_thread.c'], dependencies: naunet) +executable('timer_loop', ['timer_loop.c'], dependencies: naunet) +executable('loop_sleep', ['loop_sleep.c'], dependencies: naunet) +if not is_windows + executable('stdin_lines', ['stdin_lines.c'], dependencies: naunet) + executable('fs_event', ['fs_event_local.c'], dependencies: naunet) +endif diff --git a/tests/stdin_lines.c b/tests/stdin_lines.c index cf0f941..9656a78 100644 --- a/tests/stdin_lines.c +++ b/tests/stdin_lines.c @@ -1,31 +1,31 @@ -#include -#include +#include +#include -static struct aki_event_loop loop; -static struct aki_line_processor pro; +static struct nn_event_loop loop; +static struct nn_line_processor pro; static u8 line_callback(void *userdata, str *line) { (void)userdata; al_printf("%.*s\n", AL_STR_PRINTF(line)); - if (al_str_eq(line, al_str_c("quit"))) return AKI_LINE_PROCESSOR_STOP; - return AKI_LINE_PROCESSOR_CONTINUE; + if (al_str_eq(line, al_str_c("quit"))) return NNWT_LINE_PROCESSOR_STOP; + return NNWT_LINE_PROCESSOR_CONTINUE; } s32 main(void) { - if (!aki_common_init()) return EXIT_FAILURE; + if (!nn_common_init()) return EXIT_FAILURE; - aki_event_loop_init(&loop); + nn_event_loop_init(&loop); pro.callback = line_callback; pro.userdata = NULL; - aki_line_processor_init(&pro, al_str_c("\n")); - aki_line_processor_open_fd(&pro, STDIN_FILENO); - aki_line_processor_run(&pro, &loop); + nn_line_processor_init(&pro, al_str_c("\n")); + nn_line_processor_open_fd(&pro, STDIN_FILENO); + nn_line_processor_run(&pro, &loop); - aki_event_loop_run(&loop); - aki_event_loop_destroy(&loop); + nn_event_loop_run(&loop); + nn_event_loop_destroy(&loop); return EXIT_SUCCESS; } diff --git a/tests/timer_loop.c b/tests/timer_loop.c index 3c403f9..ece849e 100644 --- a/tests/timer_loop.c +++ b/tests/timer_loop.c @@ -1,39 +1,39 @@ -#include -#include -#include +#include +#include +#include #define DELAY 100000L -#define REPEAT 21 +#define REPEAT 21u -static struct aki_event_loop loop; -static struct aki_timer timer; +static struct nn_event_loop loop; +static struct nn_timer timer; static f64 start; -static u32 iter = 0; +static u32 iter = 0u; -static void timer_callback(void *userdata, struct aki_timer *timer) +static void timer_callback(void *userdata, struct nn_timer *timer) { (void)userdata; - u64 diff = (aki_get_tick() - start) * 1000000Lu; - aki_timer_set_repeat(timer, AKI_TS_FROM_USEC(DELAY + ((s64)(iter * DELAY) - diff))); - al_printf("[%2u] %lfs\n", iter, diff / 1000000.0); - if (++iter == REPEAT) aki_timer_stop(timer); - else aki_timer_again(timer); + u64 diff = (nn_get_tick() - start) * 1000000Lu; + nn_timer_set_repeat(timer, NNWT_TS_FROM_USEC(DELAY + ((s64)(iter * DELAY) - diff))); + al_printf("[%2u (%llu)] %lfs\n", iter, nn_get_timestamp(), diff / 1000000.0); + if (++iter == REPEAT) nn_timer_stop(timer); + else nn_timer_again(timer); } s32 main(void) { - if (!aki_common_init()) return EXIT_FAILURE; + if (!nn_common_init()) return EXIT_FAILURE; - aki_event_loop_init(&loop); + nn_event_loop_init(&loop); - aki_timer_init(&timer, &loop, timer_callback, NULL); - aki_timer_set_repeat(&timer, AKI_TS_FROM_USEC(DELAY)); - start = aki_get_tick(); + nn_timer_init(&timer, &loop, timer_callback, NULL); + nn_timer_set_repeat(&timer, NNWT_TS_FROM_USEC(DELAY)); + start = nn_get_tick(); timer_callback(NULL, &timer); - aki_event_loop_run(&loop); - aki_event_loop_destroy(&loop); + nn_event_loop_run(&loop); + nn_event_loop_destroy(&loop); return EXIT_SUCCESS; } diff --git a/tests/timer_thread.c b/tests/timer_thread.c index 2949cf7..f6627dc 100644 --- a/tests/timer_thread.c +++ b/tests/timer_thread.c @@ -1,30 +1,30 @@ -#include -#include +#include +#include #define DELAY 100000L #define REPEAT 21u -static struct aki_thread thread; +static struct nn_thread thread; -static aki_thread_result AKI_THREADCALL test_thread(void *userdata) +static nn_thread_result NNWT_THREADCALL test_thread(void *userdata) { (void)userdata; u64 diff; - f64 start = aki_get_tick(); + f64 start = nn_get_tick(); for (u32 i = 0; i < REPEAT; i++) { - diff = (aki_get_tick() - start) * 1000000Lu; - aki_thread_sleep(AKI_TS_FROM_USEC(DELAY + ((s64)(i * DELAY) - diff))); - al_printf("[%2u (%llu)] %lfs\n", i, aki_get_timestamp(), diff / 1000000.0); + diff = (nn_get_tick() - start) * 1000000Lu; + nn_thread_sleep(NNWT_TS_FROM_USEC(DELAY + ((s64)(i * DELAY) - diff))); + al_printf("[%2u (%llu)] %lfs\n", i, nn_get_timestamp(), diff / 1000000.0); } return 0; } s32 main(void) { - if (!aki_common_init()) return EXIT_FAILURE; + if (!nn_common_init()) return EXIT_FAILURE; - aki_thread_create(&thread, test_thread, NULL); - aki_thread_join(&thread); + nn_thread_create(&thread, test_thread, NULL); + nn_thread_join(&thread); return EXIT_SUCCESS; } -- cgit v1.2.3-101-g0448