feat: add new test

This commit is contained in:
Nemo D'ACREMONT 2025-05-07 08:31:17 +02:00
parent 1505a4d8ef
commit 6d97e0ee60
No known key found for this signature in database
GPG Key ID: 85F245EC3BB1E022
4 changed files with 48 additions and 3 deletions

View File

@ -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})

View File

@ -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}

44
tst/13-join-switch.c Normal file
View File

@ -0,0 +1,44 @@
#include <stdio.h>
#include <assert.h>
#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;
}

View File

@ -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()