X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fkern%2Fproc_test.c;h=0553881b78a0cbaee898ed67a544309d34da3681;hb=6f173abf128765ef8e4f71b0cd1619e2d2691cfb;hp=38a6b16c66fe5083b9b41e1ce8c2ab95179a354a;hpb=87302355709b6d5ac0592024b84207ba86baa82e;p=bertos.git diff --git a/bertos/kern/proc_test.c b/bertos/kern/proc_test.c index 38a6b16c..0553881b 100644 --- a/bertos/kern/proc_test.c +++ b/bertos/kern/proc_test.c @@ -26,103 +26,172 @@ * invalidate any other reasons why the executable file might be covered by * the GNU General Public License. * - * Copyright 2005 Develer S.r.l. (http://www.develer.com/) + * Copyright 2008 Develer S.r.l. (http://www.develer.com/) * --> * * * \brief Test kernel process. * * \version $Id$ - * * \author Daniele Basile */ #include +#include +#include + #include #include + +// Global settings for the test. +#define MAX_GLOBAL_COUNT 1024 +#define TEST_TIME_OUT_MS 6000 +#define DELAY 5 + +// Settings for the test process. +//Process 1 +#define INC_PROC_T1 1 +#define DELAY_PROC_T1 INC_PROC_T1*DELAY +//Process 2 +#define INC_PROC_T2 3 +#define DELAY_PROC_T2 INC_PROC_T2*DELAY +//Process 3 +#define INC_PROC_T3 5 +#define DELAY_PROC_T3 INC_PROC_T3*DELAY +//Process 4 +#define INC_PROC_T4 7 +#define DELAY_PROC_T4 INC_PROC_T4*DELAY +//Process 5 +#define INC_PROC_T5 11 +#define DELAY_PROC_T5 INC_PROC_T5*DELAY +//Process 6 +#define INC_PROC_T6 13 +#define DELAY_PROC_T6 INC_PROC_T6*DELAY +//Process 7 +#define INC_PROC_T7 17 +#define DELAY_PROC_T7 INC_PROC_T7*DELAY +//Process 8 +#define INC_PROC_T8 19 +#define DELAY_PROC_T8 INC_PROC_T8*DELAY + +//Global count for each process. +unsigned int t1_count = 0; +unsigned int t2_count = 0; +unsigned int t3_count = 0; +unsigned int t4_count = 0; +unsigned int t5_count = 0; +unsigned int t6_count = 0; +unsigned int t7_count = 0; +unsigned int t8_count = 0; + /* - * Proc scheduling test subthread 1 + * These macros generate the code needed to create the test process functions. + */ +#define PROC_TEST(num) static void proc_test##num(void) \ +{ \ + unsigned int local_count = 0; \ + \ + for (int i = 0; i < INC_PROC_T##num; ++i) \ + { \ + t##num##_count++; \ + kprintf("> Process[%d]: count[%d]\n", num, t##num##_count); \ + timer_delay(DELAY_PROC_T##num); \ + } \ +} \ + +#define PROC_TEST_STACK(num) static cpu_stack_t proc_test##num##_stack[CONFIG_KERN_MINSTACKSIZE / sizeof(cpu_stack_t)]; +#define PROC_TEST_INIT(num) proc_new(proc_test##num, NULL, sizeof(proc_test##num##_stack), proc_test##num##_stack); + +// Define process +PROC_TEST(1) +PROC_TEST(2) +PROC_TEST(3) +PROC_TEST(4) +PROC_TEST(5) +PROC_TEST(6) +PROC_TEST(7) +PROC_TEST(8) + +// Define process stacks for test. +PROC_TEST_STACK(1) +PROC_TEST_STACK(2) +PROC_TEST_STACK(3) +PROC_TEST_STACK(4) +PROC_TEST_STACK(5) +PROC_TEST_STACK(6) +PROC_TEST_STACK(7) +PROC_TEST_STACK(8) + + +/** + * Process scheduling test */ -static void proc_test1(void) +int proc_testRun(void) { + kprintf("Run Process test..\n"); + + //Init the process tests + PROC_TEST_INIT(1) + PROC_TEST_INIT(2) + PROC_TEST_INIT(3) + PROC_TEST_INIT(4) + PROC_TEST_INIT(5) + PROC_TEST_INIT(6) + PROC_TEST_INIT(7) + PROC_TEST_INIT(8) + kputs("> Main: Processes created\n"); + for (int i = 0; i < 30; ++i) { - kputs("> test1\n"); - timer_delay(50); - proc_switch(); + kputs("> Main\n"); + timer_delay(93); + monitor_report(); } -} -/* - * Proc scheduling test subthread 2 - */ -static void proc_test2(void) -{ - for (int i = 0; i < 30; ++i) + if( t1_count == INC_PROC_T1 && + t2_count == INC_PROC_T2 && + t3_count == INC_PROC_T3 && + t4_count == INC_PROC_T4 && + t5_count == INC_PROC_T5 && + t6_count == INC_PROC_T6 && + t7_count == INC_PROC_T7 && + t8_count == INC_PROC_T8) { - kputs("> test2\n"); - timer_delay(75); - proc_switch(); + kputs("> Main: process test finished..ok!\n"); + return 0; } -} -static cpustack_t proc_test1_stack[CONFIG_PROC_DEFSTACKSIZE / sizeof(cpustack_t)]; -static cpustack_t proc_test2_stack[CONFIG_PROC_DEFSTACKSIZE / sizeof(cpustack_t)]; + kputs("> Main: process test..fail!\n"); + return -1; +} int proc_testSetup(void) { kdbg_init(); - proc_init(); - IRQ_ENABLE; + + #if CONFIG_KERN_PREEMPT + kprintf("Init Interrupt (preempt mode).."); + irq_init(); + kprintf("Done.\n"); + #endif + + kprintf("Init Timer.."); timer_init(); - return 0; -} + kprintf("Done.\n"); + + kprintf("Init Process.."); + proc_init(); + kprintf("Done.\n"); -int proc_testTearDown(void) -{ return 0; } -/** - * Process scheduling test - */ -int proc_testRun(void) +int proc_testTearDown(void) { - proc_new(proc_test1, NULL, sizeof(proc_test1_stack), proc_test1_stack); - proc_new(proc_test2, NULL, sizeof(proc_test2_stack), proc_test2_stack); - kputs("Processes created\n"); - - //kputs("stack1:\n"); - //kdump(proc_test_stack1 + sizeof(proc_test_stack1) - 64, 64); - - //kputs("stack2:\n"); - //kdump(proc_test_stack2 + sizeof(proc_test_stack2) - 64, 64); - - for (int i = 0; i < 30; ++i) - { - kputs("> main\n"); - timer_delay(93); - proc_switch(); - } + kputs("TearDown Process test.\n"); return 0; } -#warning Fix test to comply to new policy. -#if 0 -/* - * FIXME: to be compiled as a single file - * the kernel module needs the assembly switch function - * and the idle() that lay in a emulator cpp file. - * How can we fix this? - */ -#include TEST_ONLY(drv/kdebug.c) -#include TEST_ONLY(kern/coop.c) -#include TEST_ONLY(kern/proc.c) -#include TEST_ONLY(drv/timer.c) -#include TEST_ONLY(mware/formatwr.c) -#include TEST_ONLY(mware/hex.c) -#include TEST_ONLY(os/hptime.c) TEST_MAIN(proc); -#endif