From bdf186e13258abd9c5fb932d84a7ea1e15c7d933 Mon Sep 17 00:00:00 2001 From: Prefetch Date: Tue, 18 Jul 2023 17:31:21 +0200 Subject: This test was basically a duplicate, remove it --- Makefile | 3 +-- tests/test01.c | 22 +++++++++++++++------ tests/test02.c | 62 ---------------------------------------------------------- 3 files changed, 17 insertions(+), 70 deletions(-) delete mode 100644 tests/test02.c diff --git a/Makefile b/Makefile index edef168..00f1816 100644 --- a/Makefile +++ b/Makefile @@ -7,9 +7,8 @@ lib/%.o: lib/%.asm tests/%.run: tests/%.c liblinen.so linen.h gcc -L . -llinen -I . -o $@ $< -tests: tests/test01.run tests/test02.run +tests: tests/test01.run LD_LIBRARY_PATH=. ./tests/test01.run - LD_LIBRARY_PATH=. ./tests/test02.run .PHONY: clean clean: diff --git a/tests/test01.c b/tests/test01.c index 198dac7..4c7919c 100644 --- a/tests/test01.c +++ b/tests/test01.c @@ -1,9 +1,9 @@ -#include "linen.h" - #include #include -#include #include +#include + +#include "linen.h" #define NUM_THREADS 10 @@ -26,7 +26,8 @@ void* f(void* arg) { void main() { - printf("\x1B[1mTEST 01: threads print after random delay:\x1B[0m\n"); + printf("\x1B[1mTEST 01: threads print after random delay " + "while getting joined consecutively:\x1B[0m\n"); /* Thread handles and arguments */ linen_thread_t ts[NUM_THREADS]; @@ -47,6 +48,15 @@ void main() { } } - /* Wait for threads to finish */ - usleep(1200000); + /* Wait for each thread to finish in order, and print its argument. + * The first message only prints once thread #0 is done, and so on. */ + for (int i = 0; i < NUM_THREADS; i++) { + useconds_t* pd; + int r = linen_thread_finish(ts[i], (void**)&pd); + if (r) { + printf(" Failed to join thread #%d with error %d\n", i, r); + } else { + printf(" Thread #%d slept for %dms\n", i, *pd / 1000); + } + } } diff --git a/tests/test02.c b/tests/test02.c deleted file mode 100644 index 1cd0c1a..0000000 --- a/tests/test02.c +++ /dev/null @@ -1,62 +0,0 @@ -#include -#include -#include -#include - -#include "linen.h" - - -#define NUM_THREADS 10 - - -/* Argument for thread function */ -typedef struct { - useconds_t delay; - int id; -} f_arg_t; - - -/* Function for threads to run */ -void* f(void* arg) { - f_arg_t* a = (f_arg_t*)arg; - usleep(a->delay); - printf(" Hello from thread #%d!\n", a->id); - return (void*)&(a->delay); -} - - -void main() { - printf("\x1B[1mTEST 02: threads print after random delay " - "while getting joined consecutively:\x1B[0m\n"); - - /* Thread handles and arguments */ - linen_thread_t ts[NUM_THREADS]; - f_arg_t args[NUM_THREADS]; - - /* Set arguments */ - srand(time(NULL)); - for (int i = 0; i < NUM_THREADS; i++) { - args[i].delay = (useconds_t)rand() % 1000000; - args[i].id = i; - } - - /* Spawn threads */ - for (int i = 0; i < NUM_THREADS; i++) { - int r = linen_thread_create(&ts[i], f, (void*)&args[i]); - if (r) { - printf(" Failed to spawn thread #%d with error %d\n", i, r); - } - } - - /* Wait for each thread to finish in order, and print its argument. - * The first message only prints once thread #0 is done, and so on. */ - for (int i = 0; i < NUM_THREADS; i++) { - useconds_t* pd; - int r = linen_thread_finish(ts[i], (void**)&pd); - if (r) { - printf(" Failed to join thread #%d with error %d\n", i, r); - } else { - printf(" Thread #%d slept for %dms\n", i, *pd / 1000); - } - } -} -- cgit v1.2.3