diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/config.c | 16 | ||||
| -rw-r--r-- | test/queue.c | 55 |
2 files changed, 68 insertions, 3 deletions
diff --git a/test/config.c b/test/config.c index a8fd1ad..a871243 100644 --- a/test/config.c +++ b/test/config.c @@ -20,14 +20,14 @@ KPL_TEST(config_change_module_extension) { KPL_ASSERT(strcmp(config.module_extension, ".l") == 0, "Invalid new module extension"); } -KPL_TEST(config_io_queue_pow) { +KPL_TEST(config_io_queue_pow2) { kpl_config config; const int32_t argc = 3; - const char *argv[] = { "./kpl", "--io-queue-pow=14", "./file.kpl" }; + const char *argv[] = { "./kpl", "--io-queue-pow2=14", "./file.kpl" }; kpl_config_init(&config); int32_t code = kpl_config_parse_args(&config, argc, argv); KPL_ASSERT(code == KPL_EXIT_CODE_SUCCESS, "Invalid exit code"); - KPL_ASSERT(config.io.queue_pow == 14, "Invalid io queue power of two"); + KPL_ASSERT(config.io.queue_pow2 == 14, "Invalid io queue power of two"); } KPL_TEST(config_thread_count) { @@ -39,3 +39,13 @@ KPL_TEST(config_thread_count) { KPL_ASSERT(code == KPL_EXIT_CODE_SUCCESS, "Invalid exit code"); KPL_ASSERT(config.thread.count == 1, "Invalid thread count"); } + +KPL_TEST(config_memory_pool_pow2) { + kpl_config config; + const int32_t argc = 3; + const char *argv[] = { "./kpl", "--memory-pool-pow2=6,7", "./file.kpl" }; + kpl_config_init(&config); + int32_t code = kpl_config_parse_args(&config, argc, argv); + KPL_ASSERT(code == KPL_EXIT_CODE_SUCCESS, "Invalid exit code"); + KPL_ASSERT(config.thread.ring_pool_entries_pow2[6] == 7, "Invalid entries pow2"); +} diff --git a/test/queue.c b/test/queue.c new file mode 100644 index 0000000..9886225 --- /dev/null +++ b/test/queue.c @@ -0,0 +1,55 @@ + +#include "kpl_test.h" + +typedef struct { + _Atomic int32_t increments; + bool pop_error; + kpl_task_queue task_queue; + pthread_t pthread; +} kpl_task_queue_thread_test; + +#define TASK_QUEUE_THREAD_COUNT 3 + +#define TASK_QUEUE_PER_THREAD_INCREMENTS 10 + +static const int32_t kpl_task_queue_total_increments = TASK_QUEUE_THREAD_COUNT * TASK_QUEUE_PER_THREAD_INCREMENTS; + +static kpl_task_queue_thread_test task_queue_threads[TASK_QUEUE_THREAD_COUNT] = {}; + +static void *queue_task_queue_thread_fn(void *arg) { + const int32_t thread_id = (int32_t) (intptr_t) arg; + for (int32_t round = 0; round < TASK_QUEUE_PER_THREAD_INCREMENTS; round++) { + for (int32_t id = 0; id < TASK_QUEUE_THREAD_COUNT; id++) { + kpl_task *task = calloc(1, sizeof(kpl_task)); + kpl_task_queue_add(&task_queue_threads[id].task_queue, task); + } + kpl_task *task = kpl_task_queue_next(&task_queue_threads[thread_id].task_queue); + if (task) { + task_queue_threads[thread_id].increments++; + free(task); + } else { + task_queue_threads[thread_id].pop_error = true; + break; + } + } + return NULL; +} + +KPL_TEST(queue_task_queue_threads) { + for (int32_t id = 0; id < TASK_QUEUE_THREAD_COUNT; id++) + kpl_task_queue_init(&task_queue_threads[id].task_queue); + for (int32_t id = 0; id < TASK_QUEUE_THREAD_COUNT; id++) + pthread_create(&task_queue_threads[id].pthread, NULL, queue_task_queue_thread_fn, (void*) (intptr_t) id); + for (int32_t id = 0; id < TASK_QUEUE_THREAD_COUNT; id++) + pthread_join(task_queue_threads[id].pthread, NULL); + for (int32_t id = 0; id < TASK_QUEUE_THREAD_COUNT; id++) { + kpl_task *task = NULL; + while ((task = kpl_task_queue_next(&task_queue_threads[id].task_queue))) { + task_queue_threads[id].increments++; + free(task); + } + KPL_ASSERT(!task_queue_threads[id].pop_error, "Task queue pop failed"); + KPL_ASSERT(task_queue_threads[id].increments == kpl_task_queue_total_increments, + "Invalid number of increments"); + } +} |
