diff --git a/tests/test.c b/tests/test.c index c1cdd27..ade140e 100644 --- a/tests/test.c +++ b/tests/test.c @@ -8,6 +8,7 @@ #include "paging.h" #include "serial.h" #include "stack.h" +#include "synchro.h" void testPhymem(void) { @@ -236,20 +237,44 @@ static void kthread2(void *strIn) void sleepThread(void *arg){ (void)arg; int secSleep = 0; - while (1){ + while (secSleep < 5){ printf("Sleeping loop %d\n", secSleep); secSleep++; kthreadMsleep(1000); } + kthreadMsleep(0); + printf("I should never be showed\n"); + assert(1); +} + +struct mutex mutexTest; + +void mutThread(void *arg){ + (void)arg; + printf("%s started\n", (char *)arg); + int test = 5; + while(test > 0){ + mutexLock(&mutexTest); + printf("%s sleep\n", (char *)arg); + kthreadMsleep(1000); + printf("%s up\n", (char *)arg); + mutexUnlock(&mutexTest); + test--; + } } void testKthread() { + mutexInit(&mutexTest); // It is not expected to have necessarily "Hello world\n" properly written - kthreadCreate("Test1", (cpu_kstate_function_arg1_t *)kthread1, (void *)"Hlowrd\n"); kthreadCreate("Test2", (cpu_kstate_function_arg1_t *)kthread2, (void *)"el ol\n"); + kthreadCreate("Test1", (cpu_kstate_function_arg1_t *)kthread1, (void *)"Hlowrd\n"); kthreadMsleep(1000); kthreadCreate("sleep", sleepThread, NULL); + kthreadMsleep(5000); + kthreadCreate("mtest1", mutThread, "mut1"); + kthreadCreate("mtest2", mutThread, "mut2"); + kthreadCreate("mtest3", mutThread, "mut3"); } void run_test(void)