From 5de1c54b61c2414ae2220b9e0e303ed22a79fe3d Mon Sep 17 00:00:00 2001 From: Mathieu Maret Date: Mon, 6 Jul 2020 17:21:49 +0200 Subject: [PATCH] Move sleep Thread to test --- core/main.c | 11 ----------- tests/test.c | 19 +++++++++++++++---- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/core/main.c b/core/main.c index cab937b..6362790 100644 --- a/core/main.c +++ b/core/main.c @@ -32,16 +32,6 @@ void idleThread(void *arg) } } -void sleepThread(void *arg){ - (void)arg; - int secSleep = 0; - while (1){ - printf("Sleeping loop %d\n", secSleep); - secSleep++; - kthreadMsleep(1000); - } -} - // Multiboot information available here : // https://www.gnu.org/software/grub/manual/multiboot/multiboot.html#kernel_002ec // https://www.gnu.org/software/grub/manual/multiboot/html_node/Boot-information-format.html#Boot%20information%20format @@ -127,7 +117,6 @@ void kmain(unsigned long magic, unsigned long addr) allocSetup(); kthreadSetup(_stack_bottom, (_stack_top - _stack_bottom + 1)); kthreadCreate("idle ", idleThread, NULL); - kthreadCreate("sleep", sleepThread, NULL); irqSetRoutine(IRQ_TIMER, pit_handler); #ifdef RUN_TEST run_test(); diff --git a/tests/test.c b/tests/test.c index 681bb09..c1cdd27 100644 --- a/tests/test.c +++ b/tests/test.c @@ -218,9 +218,8 @@ void testCoroutine() static void kthread1(void *strIn) { char *str = (char *)strIn; - printf("\nkth1: %s\n", (char *)strIn); for (; *str != '\n'; str++) { - printf("kth1_: %c\n", *str); + printf("kth1: %c\n", *str); kthreadYield(); } } @@ -228,17 +227,29 @@ static void kthread1(void *strIn) static void kthread2(void *strIn) { char *str = (char *)strIn; - printf("\nkth2: %s\n", (char *)strIn); for (; *str != '\n'; str++) { - printf("kth2_: %c\n", *str); + printf("kth2: %c\n", *str); kthreadYield(); } } +void sleepThread(void *arg){ + (void)arg; + int secSleep = 0; + while (1){ + printf("Sleeping loop %d\n", secSleep); + secSleep++; + kthreadMsleep(1000); + } +} + void testKthread() { + // 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"); + kthreadMsleep(1000); + kthreadCreate("sleep", sleepThread, NULL); } void run_test(void)