Add test on wq with timeout

This commit is contained in:
Mathieu Maret 2020-08-19 13:58:52 +02:00
parent 5b933a82d3
commit e8959f3693

View File

@ -9,6 +9,7 @@
#include "serial.h"
#include "stack.h"
#include "synchro.h"
#include "time.h"
void testPhymem(void)
{
@ -234,14 +235,19 @@ static void kthread2(void *strIn)
}
}
void sleepThread(void *arg){
static int initialJiffies = 0;
void sleepThread(void *arg)
{
(void)arg;
int secSleep = 0;
while (secSleep < 5){
printf("Sleeping loop %d\n", secSleep);
int secSleep = 0;
initialJiffies = jiffies;
while (secSleep < 5) {
// printf("Sleeping loop %d\n", secSleep);
secSleep++;
kthreadMsleep(1000);
}
unsigned long ellapsedTime = jiffies_to_msecs(jiffies - initialJiffies);
assertmsg(ellapsedTime >= 5000 && ellapsedTime < 5100, "ellapsedTime %d\n", ellapsedTime);
kthreadMsleep(0);
printf("I should never be showed\n");
assert(1);
@ -249,11 +255,12 @@ void sleepThread(void *arg){
struct mutex mutexTest;
void mutThread(void *arg){
void mutThread(void *arg)
{
(void)arg;
printf("%s started\n", (char *)arg);
int test = 5;
while(test > 0){
while (test > 0) {
mutexLock(&mutexTest);
printf("%s sleep\n", (char *)arg);
kthreadMsleep(1000);
@ -262,6 +269,14 @@ void mutThread(void *arg){
test--;
}
}
static int haveTimeout = 0;
void wqThread(void *arg)
{
(void)arg;
DECLARE_WAITQUEUE(test);
assert(waitTimeout(&test, 1000) == 1);
haveTimeout = 1;
}
void testKthread()
{
@ -270,6 +285,9 @@ void testKthread()
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("wq timeout", wqThread, NULL);
kthreadMsleep(2000);
assert(haveTimeout);
kthreadCreate("sleep", sleepThread, NULL);
kthreadMsleep(5000);
kthreadCreate("mtest1", mutThread, "mut1");