X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fkern%2Fproc_test.c;h=4bad9a24d1eef14cefbac249b01ad7a21a5a44ea;hb=5198d7ad08c6225bde49be486ae1ee395f1eefd0;hp=e06e984f660aef3581416d1c60758e47d75fefe9;hpb=e18f335ab6b31fb2a2a0950c8d4ce5a4173af062;p=bertos.git diff --git a/bertos/kern/proc_test.c b/bertos/kern/proc_test.c index e06e984f..4bad9a24 100644 --- a/bertos/kern/proc_test.c +++ b/bertos/kern/proc_test.c @@ -34,6 +34,16 @@ * * \version $Id$ * \author Daniele Basile + * + * $test$: cp bertos/cfg/cfg_proc.h $cfgdir/ + * $test$: echo "#undef CONFIG_KERN" >> $cfgdir/cfg_proc.h + * $test$: echo "#define CONFIG_KERN 1" >> $cfgdir/cfg_proc.h + * $test$: cp bertos/cfg/cfg_monitor.h $cfgdir/ + * $test$: echo "#undef CONFIG_KERN_MONITOR" >> $cfgdir/cfg_monitor.h + * $test$: echo "#define CONFIG_KERN_MONITOR 1" >> $cfgdir/cfg_monitor.h + * $test$: cp bertos/cfg/cfg_signal.h $cfgdir/ + * $test$: echo "#undef CONFIG_KERN_SIGNALS" >> $cfgdir/cfg_signal.h + * $test$: echo "#define CONFIG_KERN_SIGNALS 1" >> $cfgdir/cfg_signal.h */ #include @@ -43,33 +53,81 @@ #include #include -/* - * Proc scheduling test subthread 1 - */ -static void proc_test1(void) -{ - for (int i = 0; i < 30; ++i) - { - kputs("> test1\n"); - timer_delay(50); - proc_yield(); - } -} + +// Global settings for the test. +#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 2 + * These macros generate the code needed to create the test process functions. */ -static void proc_test2(void) -{ - for (int i = 0; i < 30; ++i) - { - kputs("> test2\n"); - timer_delay(75); - } -} - -static cpu_stack_t proc_test1_stack[CONFIG_KERN_MINSTACKSIZE / sizeof(cpu_stack_t)]; -static cpu_stack_t proc_test2_stack[CONFIG_KERN_MINSTACKSIZE / sizeof(cpu_stack_t)]; +#define PROC_TEST(num) static void proc_test##num(void) \ +{ \ + 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) /** @@ -77,59 +135,69 @@ static cpu_stack_t proc_test2_stack[CONFIG_KERN_MINSTACKSIZE / sizeof(cpu_stack_ */ int proc_testRun(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"); + 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("> main\n"); + kputs("> Main\n"); timer_delay(93); monitor_report(); - proc_yield(); } - return 0; + + 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("> Main: process test finished..ok!\n"); + return 0; + } + + kputs("> Main: process test..fail!\n"); + return -1; } -#if UNIT_TEST int proc_testSetup(void) { kdbg_init(); #if CONFIG_KERN_PREEMPT + kprintf("Init Interrupt (preempt mode).."); irq_init(); + kprintf("Done.\n"); #endif + kprintf("Init Timer.."); timer_init(); + kprintf("Done.\n"); + kprintf("Init Process.."); proc_init(); + kprintf("Done.\n"); + return 0; } int proc_testTearDown(void) { + kputs("TearDown Process test.\n"); return 0; } -#include -#include -#include -#include -#include -#if CONFIG_KERN_PREEMPT - #include - #include -#else - #include - // FIXME: we need to link with the switch asm code too! -#endif -#include -#include -#include -#include -#include - TEST_MAIN(proc); - -#endif // _TEST