test: add mutex test
This commit is contained in:
parent
0f200d1911
commit
36734ae6e6
29
tests/test.c
29
tests/test.c
@ -8,6 +8,7 @@
|
|||||||
#include "paging.h"
|
#include "paging.h"
|
||||||
#include "serial.h"
|
#include "serial.h"
|
||||||
#include "stack.h"
|
#include "stack.h"
|
||||||
|
#include "synchro.h"
|
||||||
|
|
||||||
void testPhymem(void)
|
void testPhymem(void)
|
||||||
{
|
{
|
||||||
@ -236,20 +237,44 @@ static void kthread2(void *strIn)
|
|||||||
void sleepThread(void *arg){
|
void sleepThread(void *arg){
|
||||||
(void)arg;
|
(void)arg;
|
||||||
int secSleep = 0;
|
int secSleep = 0;
|
||||||
while (1){
|
while (secSleep < 5){
|
||||||
printf("Sleeping loop %d\n", secSleep);
|
printf("Sleeping loop %d\n", secSleep);
|
||||||
secSleep++;
|
secSleep++;
|
||||||
kthreadMsleep(1000);
|
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()
|
void testKthread()
|
||||||
{
|
{
|
||||||
|
mutexInit(&mutexTest);
|
||||||
// It is not expected to have necessarily "Hello world\n" properly written
|
// 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("Test2", (cpu_kstate_function_arg1_t *)kthread2, (void *)"el ol\n");
|
||||||
|
kthreadCreate("Test1", (cpu_kstate_function_arg1_t *)kthread1, (void *)"Hlowrd\n");
|
||||||
kthreadMsleep(1000);
|
kthreadMsleep(1000);
|
||||||
kthreadCreate("sleep", sleepThread, NULL);
|
kthreadCreate("sleep", sleepThread, NULL);
|
||||||
|
kthreadMsleep(5000);
|
||||||
|
kthreadCreate("mtest1", mutThread, "mut1");
|
||||||
|
kthreadCreate("mtest2", mutThread, "mut2");
|
||||||
|
kthreadCreate("mtest3", mutThread, "mut3");
|
||||||
}
|
}
|
||||||
|
|
||||||
void run_test(void)
|
void run_test(void)
|
||||||
|
Loading…
Reference in New Issue
Block a user