From 6d97e0ee605af89b478f558270b1cdc45145d089 Mon Sep 17 00:00:00 2001 From: Nemo D'ACREMONT Date: Wed, 7 May 2025 08:31:17 +0200 Subject: [PATCH] feat: add new test --- Makefile | 2 +- fetch_tests.sh | 2 +- tst/13-join-switch.c | 44 +++++++++++++++++++++++++++++++++++++++ tst/32-switch-many-join.c | 3 ++- 4 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 tst/13-join-switch.c diff --git a/Makefile b/Makefile index 3d4e74d..f353dc8 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ install_dir?=install # Comment out the bins that doesn't need to be compiled bbins+=$(wildcard ${tst_dir}/*.c) bins=$(filter-out ${tst_dir}/51-fibonacci.c ${tst_dir}/71-preemption.c, ${bbins}) -all_bins=01-main 02-switch 03-equity 11-join 12-join-main 21-create-many 22-create-many-recursive 23-create-many-once 31-switch-many 32-switch-many-join 33-switch-many-cascade 51-fibonacci 52-dac-sum 61-mutex 62-mutex 63-mutex-equity 64-mutex-join 71-preemption 81-deadlock +all_bins=01-main 02-switch 03-equity 11-join 12-join-main 13-join-switch 21-create-many 22-create-many-recursive 23-create-many-once 31-switch-many 32-switch-many-join 33-switch-many-cascade 51-fibonacci 52-dac-sum 61-mutex 62-mutex 63-mutex-equity 64-mutex-join 71-preemption 81-deadlock bins_target=$(patsubst %.c,${build_dir}/%,${bins}) install_bins_targets=$(patsubst ${tst_dir}/%.c,${install_dir}/bin/%,${bins}) diff --git a/fetch_tests.sh b/fetch_tests.sh index 9b1d968..edbd30e 100755 --- a/fetch_tests.sh +++ b/fetch_tests.sh @@ -1,7 +1,7 @@ #!/bin/sh tst_dir=tst -filenames="01-main 02-switch 03-equity 11-join 12-join-main 21-create-many 22-create-many-recursive 23-create-many-once 31-switch-many 32-switch-many-join 33-switch-many-cascade 51-fibonacci 61-mutex 62-mutex 63-mutex-equity 64-mutex-join 71-preemption 81-deadlock" +filenames="01-main 02-switch 03-equity 11-join 12-join-main 13-join-switch 21-create-many 22-create-many-recursive 23-create-many-once 31-switch-many 32-switch-many-join 33-switch-many-cascade 51-fibonacci 61-mutex 62-mutex 63-mutex-equity 64-mutex-join 71-preemption 81-deadlock" mkdir -p "${tst_dir}" for filename in ${filenames} diff --git a/tst/13-join-switch.c b/tst/13-join-switch.c new file mode 100644 index 0000000..51b1a5b --- /dev/null +++ b/tst/13-join-switch.c @@ -0,0 +1,44 @@ +#include +#include +#include "thread.h" + +/* test du join d'un thread qui fait plein de yield(). + * + * le programme doit retourner correctement. + * valgrind doit être content. + * + * support nécessaire: + * - thread_create() + * - thread_exit() + * - thread_join() avec récupération valeur de retour, avec thread_exit() + * sur un thread qui yield() plusieurs fois vers celui qui joine. + */ + +static void * thfunc(void *dummy __attribute__((unused))) +{ + unsigned i; + for(i=0; i<10; i++) { + printf(" le fils yield\n"); + thread_yield(); + } + thread_exit((void*)0xdeadbeef); + return NULL; /* unreachable, shut up the compiler */ +} + +int main() +{ + thread_t th; + int err; + void *res = NULL; + + err = thread_create(&th, thfunc, NULL); + assert(!err); + + printf("le main joine...\n"); + err = thread_join(th, &res); + assert(!err); + assert(res == (void*) 0xdeadbeef); + + printf("join OK\n"); + return 0; +} diff --git a/tst/32-switch-many-join.c b/tst/32-switch-many-join.c index deffb36..a8d3ecf 100644 --- a/tst/32-switch-many-join.c +++ b/tst/32-switch-many-join.c @@ -7,7 +7,8 @@ /* test de plein de switch pendant que N-1 threads sont bloqués dans join * - * La durée du programme doit etre proportionnelle au nombre de threads et de yields donnés en argument + * La durée du programme doit etre proportionnelle au nombre de yields + * mais ne pas varier avec le nombre de threads donné en argument. * * support nécessaire: * - thread_create()