From 08f0e14155bb8bd3b42bfa7aec602485b6570844 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Date: Tue, 4 Oct 2022 13:03:41 +0200 Subject: [PATCH] Add two nOS-V RT extra tests --- test/rt/nosv/CMakeLists.txt | 2 ++ test/rt/nosv/several-tasks.c | 50 ++++++++++++++++++++++++++++++ test/rt/nosv/waitfor.c | 59 ++++++++++++++++++++++++++++++++++++ 3 files changed, 111 insertions(+) create mode 100644 test/rt/nosv/several-tasks.c create mode 100644 test/rt/nosv/waitfor.c diff --git a/test/rt/nosv/CMakeLists.txt b/test/rt/nosv/CMakeLists.txt index 2faae06..e8c5707 100644 --- a/test/rt/nosv/CMakeLists.txt +++ b/test/rt/nosv/CMakeLists.txt @@ -24,3 +24,5 @@ function(nosv_test) endfunction() nosv_test(attach.c) +nosv_test(waitfor.c) +nosv_test(several-tasks.c) diff --git a/test/rt/nosv/several-tasks.c b/test/rt/nosv/several-tasks.c new file mode 100644 index 0000000..32740db --- /dev/null +++ b/test/rt/nosv/several-tasks.c @@ -0,0 +1,50 @@ +/* Copyright (c) 2022 Barcelona Supercomputing Center (BSC) + * SPDX-License-Identifier: GPL-3.0-or-later */ + +#define _DEFAULT_SOURCE + +#include +#include +#include + +#include "common.h" + +#define NTASKS 200 +atomic_int ncompleted = 0; + +nosv_task_t tasks[NTASKS]; + +static void +task_body(nosv_task_t task) +{ + UNUSED(task); + usleep(500); + atomic_fetch_add(&ncompleted, 1); +} + +int +main(void) +{ + nosv_init(); + + nosv_task_type_t task_type; + nosv_type_init(&task_type, task_body, NULL, NULL, "task", NULL, NULL, 0); + + for (int i = 0; i < NTASKS; i++) + nosv_create(&tasks[i], task_type, 0, 0); + + for (int i = 0; i < NTASKS; i++) + nosv_submit(tasks[i], 0); + + while (atomic_load(&ncompleted) != NTASKS) + usleep(1000); + + for (int i = 0; i < NTASKS; i++) + nosv_destroy(tasks[i], 0); + + nosv_type_destroy(task_type, 0); + + nosv_shutdown(); + + return 0; +} diff --git a/test/rt/nosv/waitfor.c b/test/rt/nosv/waitfor.c new file mode 100644 index 0000000..e5520eb --- /dev/null +++ b/test/rt/nosv/waitfor.c @@ -0,0 +1,59 @@ +/* Copyright (c) 2022 Barcelona Supercomputing Center (BSC) + * SPDX-License-Identifier: GPL-3.0-or-later */ + +#define _DEFAULT_SOURCE + +#include +#include +#include +#include + +#include "common.h" + +#define NTASKS 200 +atomic_int ncompleted = 0; + +nosv_task_t tasks[NTASKS]; + +static void +task_body(nosv_task_t task) +{ + UNUSED(task); + const uint64_t time_ns = 5000ULL * 1000ULL; + uint64_t actual_ns = 0; + nosv_waitfor(time_ns, &actual_ns); +} + +static void +task_done(nosv_task_t task) +{ + UNUSED(task); + atomic_fetch_add(&ncompleted, 1); +} + +int +main(void) +{ + nosv_init(); + + nosv_task_type_t task_type; + nosv_type_init(&task_type, task_body, NULL, task_done, "task", NULL, NULL, 0); + + for (int i = 0; i < NTASKS; i++) + nosv_create(&tasks[i], task_type, 0, 0); + + for (int i = 0; i < NTASKS; i++) + nosv_submit(tasks[i], 0); + + while (atomic_load(&ncompleted) != NTASKS) + usleep(1000); + + for (int i = 0; i < NTASKS; i++) + nosv_destroy(tasks[i], 0); + + nosv_type_destroy(task_type, 0); + + nosv_shutdown(); + + return 0; +}