Add test on wq with timeout
This commit is contained in:
parent
5b933a82d3
commit
e8959f3693
24
tests/test.c
24
tests/test.c
@ -9,6 +9,7 @@
|
|||||||
#include "serial.h"
|
#include "serial.h"
|
||||||
#include "stack.h"
|
#include "stack.h"
|
||||||
#include "synchro.h"
|
#include "synchro.h"
|
||||||
|
#include "time.h"
|
||||||
|
|
||||||
void testPhymem(void)
|
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;
|
(void)arg;
|
||||||
int secSleep = 0;
|
int secSleep = 0;
|
||||||
|
initialJiffies = jiffies;
|
||||||
while (secSleep < 5) {
|
while (secSleep < 5) {
|
||||||
printf("Sleeping loop %d\n", secSleep);
|
// printf("Sleeping loop %d\n", secSleep);
|
||||||
secSleep++;
|
secSleep++;
|
||||||
kthreadMsleep(1000);
|
kthreadMsleep(1000);
|
||||||
}
|
}
|
||||||
|
unsigned long ellapsedTime = jiffies_to_msecs(jiffies - initialJiffies);
|
||||||
|
assertmsg(ellapsedTime >= 5000 && ellapsedTime < 5100, "ellapsedTime %d\n", ellapsedTime);
|
||||||
kthreadMsleep(0);
|
kthreadMsleep(0);
|
||||||
printf("I should never be showed\n");
|
printf("I should never be showed\n");
|
||||||
assert(1);
|
assert(1);
|
||||||
@ -249,7 +255,8 @@ void sleepThread(void *arg){
|
|||||||
|
|
||||||
struct mutex mutexTest;
|
struct mutex mutexTest;
|
||||||
|
|
||||||
void mutThread(void *arg){
|
void mutThread(void *arg)
|
||||||
|
{
|
||||||
(void)arg;
|
(void)arg;
|
||||||
printf("%s started\n", (char *)arg);
|
printf("%s started\n", (char *)arg);
|
||||||
int test = 5;
|
int test = 5;
|
||||||
@ -262,6 +269,14 @@ void mutThread(void *arg){
|
|||||||
test--;
|
test--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
static int haveTimeout = 0;
|
||||||
|
void wqThread(void *arg)
|
||||||
|
{
|
||||||
|
(void)arg;
|
||||||
|
DECLARE_WAITQUEUE(test);
|
||||||
|
assert(waitTimeout(&test, 1000) == 1);
|
||||||
|
haveTimeout = 1;
|
||||||
|
}
|
||||||
|
|
||||||
void testKthread()
|
void testKthread()
|
||||||
{
|
{
|
||||||
@ -270,6 +285,9 @@ void testKthread()
|
|||||||
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");
|
kthreadCreate("Test1", (cpu_kstate_function_arg1_t *)kthread1, (void *)"Hlowrd\n");
|
||||||
kthreadMsleep(1000);
|
kthreadMsleep(1000);
|
||||||
|
kthreadCreate("wq timeout", wqThread, NULL);
|
||||||
|
kthreadMsleep(2000);
|
||||||
|
assert(haveTimeout);
|
||||||
kthreadCreate("sleep", sleepThread, NULL);
|
kthreadCreate("sleep", sleepThread, NULL);
|
||||||
kthreadMsleep(5000);
|
kthreadMsleep(5000);
|
||||||
kthreadCreate("mtest1", mutThread, "mut1");
|
kthreadCreate("mtest1", mutThread, "mut1");
|
||||||
|
Loading…
Reference in New Issue
Block a user