From 7ae2d7a5f0b56aeb0a7eb9b0aa7a95f05526c1ae Mon Sep 17 00:00:00 2001 From: stefan Date: Wed, 11 Aug 2010 18:52:43 +0000 Subject: [PATCH] - move test cases in a seperate file git-svn-id: http://svn.lfbs.rwth-aachen.de/svn/scc/trunk/MetalSVM@79 315a16e6-25f9-4109-90ae-ca3045a26c18 --- kernel/Makefile | 2 +- kernel/main.c | 111 ++------------------------------------- kernel/tests.c | 134 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 138 insertions(+), 109 deletions(-) create mode 100644 kernel/tests.c diff --git a/kernel/Makefile b/kernel/Makefile index b349d388..52cc06c4 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -1,4 +1,4 @@ -C_source = main.c tasks.c processor.c +C_source = main.c tasks.c processor.c tests.c OBJS += $(patsubst %.c, %.o, $(filter %.c, $(C_source))) ALLOBJS += $(patsubst %.c, %.o, $(filter %.c, $(C_source))) diff --git a/kernel/main.c b/kernel/main.c index 0760696c..c63f9578 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -23,10 +23,8 @@ #include #include #include -#include -#include -#include #include +#include #include #ifdef CONFIG_PCI #include @@ -42,100 +40,10 @@ //#include #endif -static sem_t consuming, producing; -static mailbox_int32_t mbox; -static int val = 0; - +extern int test_init(void); extern const void kernel_start; extern const void kernel_end; -int STDCALL consumer(void* arg) -{ - int i, m = 0; - - for(i=0; i<5; i++) { - sem_wait(&consuming); - kprintf("Consumer got %d\n", val); - val = 0; - sem_post(&producing); - } - - for(i=0; i<5; i++) { - mailbox_int32_fetch(&mbox, &m); - kprintf("Got mail %d\n", m); - } - - return 0; -} - -int STDCALL producer(void* arg) -{ - int i; - int mail[5] = {1, 2, 3, 4, 5}; - - for(i=0; i<5; i++) { - sem_wait(&producing); - kprintf("Produce value: current val %d\n", val); - val = 42; - sem_post(&consuming); - } - - for(i=0; i<5; i++) { - //kprintf("Send mail %d\n", mail[i]); - mailbox_int32_post(&mbox, mail[i]); - } - - return 0; -} - -int STDCALL foo(void* arg) -{ - int i; - - if (!arg) - return 0; - - for(i=0; i<5; i++) { - kputs((char*) arg); - sleep(1); - } - - return 42; -} - -int STDCALL join_test(void* arg) -{ - tid_t id; - int ret, result = -1234; - - ret = create_kernel_task(&id, foo, "Hello from foo2\n"); - kprintf("Wait for task %u: ret = %d\n", id, ret); - ret = join_task(id, &result); - kprintf("Task %u finished: ret = %d, result = %d\n", id, ret, result); - - return 0; -} - -int STDCALL userfoo(void* arg) -{ - int i; - - if (!arg) - return 0; - - for (i = 0; i < 5; i++) { - SYSCALL1(__NR_write, arg); - } - - // demo of a general protection fault - //kprintf("test user\n"); - - /* task exit */ - SYSCALL1(__NR_exit, 0); - - return 0; -} - #ifdef CONFIG_LWIP int STDCALL lwip_task(void* arg) { @@ -185,7 +93,6 @@ int STDCALL lwip_task(void* arg) int main(void) { - tid_t id1, id2, id3, id4, id5; #ifdef CONFIG_LWIP tid_t lwip_id; #endif @@ -193,7 +100,6 @@ int main(void) kprintf("Here is MetalSVM %s\n", METALSVM_VERSION); system_init(); - while(1); irq_init(); timer_init(); #ifdef CONFIG_KEYBOARD @@ -206,9 +112,6 @@ int main(void) irq_enable(); kprintf("Kernel starts at %p and ends at %p\n", &kernel_start, &kernel_end); - - while(1) - ; detect_cpu_frequency(); kprintf("Processor frequency: %d MHz\n", get_cpu_frequency()/1000000); @@ -221,21 +124,13 @@ int main(void) timer_set_frequency(TIMER_FREQ); - sem_init(&producing, 1); - sem_init(&consuming, 0); - mailbox_int32_init(&mbox); - sleep(5); + test_init(); #ifdef CONFIG_LWIP //create_kernel_task(&lwip_id, lwip_task, NULL); #endif - create_kernel_task(&id1, foo, "Hello from foo1\n"); - create_kernel_task(&id2, join_test, NULL); - create_kernel_task(&id3, producer, NULL); - create_kernel_task(&id4, consumer, NULL); - create_user_task(&id5, userfoo, "Hello from user process foo\n", 0); current_task->status = TASK_IDLE; reschedule(); diff --git a/kernel/tests.c b/kernel/tests.c new file mode 100644 index 00000000..a4bc23cd --- /dev/null +++ b/kernel/tests.c @@ -0,0 +1,134 @@ +/* + * Copyright 2010 Stefan Lankes, Chair for Operating Systems, + * RWTH Aachen University + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * This file is part of MetalSVM. + */ + +#include +#include +#include +#include +#include +#include +#include + +static sem_t consuming, producing; +static mailbox_int32_t mbox; +static int val = 0; + +static int STDCALL consumer(void* arg) +{ + int i, m = 0; + + for(i=0; i<5; i++) { + sem_wait(&consuming); + kprintf("Consumer got %d\n", val); + val = 0; + sem_post(&producing); + } + + for(i=0; i<5; i++) { + mailbox_int32_fetch(&mbox, &m); + kprintf("Got mail %d\n", m); + } + + return 0; +} + +static int STDCALL producer(void* arg) +{ + int i; + int mail[5] = {1, 2, 3, 4, 5}; + + for(i=0; i<5; i++) { + sem_wait(&producing); + kprintf("Produce value: current val %d\n", val); + val = 42; + sem_post(&consuming); + } + + for(i=0; i<5; i++) { + //kprintf("Send mail %d\n", mail[i]); + mailbox_int32_post(&mbox, mail[i]); + } + + return 0; +} + +static int STDCALL foo(void* arg) +{ + int i; + + if (!arg) + return 0; + + for(i=0; i<5; i++) { + kputs((char*) arg); + sleep(1); + } + + return 42; +} + +static int STDCALL join_test(void* arg) +{ + tid_t id; + int ret, result = -1234; + + ret = create_kernel_task(&id, foo, "Hello from foo2\n"); + kprintf("Wait for task %u: ret = %d\n", id, ret); + ret = join_task(id, &result); + kprintf("Task %u finished: ret = %d, result = %d\n", id, ret, result); + + return 0; +} + +static int STDCALL userfoo(void* arg) +{ + int i; + + if (!arg) + return 0; + + for (i = 0; i < 5; i++) { + SYSCALL1(__NR_write, arg); + } + + // demo of a general protection fault + //kprintf("test user\n"); + + /* task exit */ + SYSCALL1(__NR_exit, 0); + + return 0; +} + +int test_init(void) +{ + tid_t id1, id2, id3, id4, id5; + + sem_init(&producing, 1); + sem_init(&consuming, 0); + mailbox_int32_init(&mbox); + + create_kernel_task(&id1, foo, "Hello from foo1\n"); + create_kernel_task(&id2, join_test, NULL); + create_kernel_task(&id3, producer, NULL); + create_kernel_task(&id4, consumer, NULL); + create_user_task(&id5, userfoo, "Hello from user process foo\n", 0); + + return 0; +}