From e8959f369396ce49975e8a3ee26db14586d46ec4 Mon Sep 17 00:00:00 2001 From: Mathieu Maret Date: Wed, 19 Aug 2020 13:58:52 +0200 Subject: [PATCH] Add test on wq with timeout --- tests/test.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/tests/test.c b/tests/test.c index ade140e..fd76f81 100644 --- a/tests/test.c +++ b/tests/test.c @@ -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");