X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;ds=sidebyside;f=bertos%2Fkern%2Fsem_test.c;h=d042ab3b8cc67d620f66ee70275860cc87e13f18;hb=c863f160d11502e2c452d567df1f8642ba2694c3;hp=354277fcbd0f4e9c0a6cbc41d17f3e21fff8a555;hpb=c64879e277eb12f6e22fee612274d3783424c58f;p=bertos.git diff --git a/bertos/kern/sem_test.c b/bertos/kern/sem_test.c index 354277fc..d042ab3b 100644 --- a/bertos/kern/sem_test.c +++ b/bertos/kern/sem_test.c @@ -32,10 +32,16 @@ * \brief Semaphore test. * * \version $Id$ - * + * * \author Daniele Basile - * \author Stefano Fedrigo - * + * \author Stefano Fedrigo + * + * $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_sem.h $cfgdir/ + * $test$: echo "#undef CONFIG_KERN_SEMAPHORES" >> $cfgdir/cfg_sem.h + * $test$: echo "#define CONFIG_KERN_SEMAPHORES 1" >> $cfgdir/cfg_sem.h */ #include @@ -50,7 +56,7 @@ // Global settings for the test. #define MAX_GLOBAL_COUNT 1024 #define TEST_TIME_OUT_MS 6000 -#define DELAY 5 +#define DELAY 5 // Settings for the test process. //Process 1 @@ -83,8 +89,8 @@ unsigned int global_count = 0; /* * These macros generate the code needed to create the test process functions. - */ -#define PROC_TEST(num) static void proc_test##num(void) \ + */ +#define PROC_TEST(num) static void proc_semTest##num(void) \ { \ unsigned int local_count = 0; \ \ @@ -103,8 +109,8 @@ unsigned int global_count = 0; } \ } \ -#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 PROC_TEST_STACK(num) static cpu_stack_t proc_sem_test##num##_stack[1024 / sizeof(cpu_stack_t)]; +#define PROC_TEST_INIT(num) proc_new(proc_semTest##num, NULL, sizeof(proc_sem_test##num##_stack), proc_sem_test##num##_stack); // Define process PROC_TEST(1) @@ -134,7 +140,7 @@ int sem_testRun(void) ticks_t start_time = timer_clock(); kprintf("Run semaphore test..\n"); - + //Init the process tests PROC_TEST_INIT(1) PROC_TEST_INIT(2) @@ -145,16 +151,16 @@ int sem_testRun(void) PROC_TEST_INIT(7) PROC_TEST_INIT(8) kputs("> Main: Processes created\n"); - + /* - * Wait until all process finishing, if some going wrong we return - * error after time_out_ms ms. - */ + * Wait until all processes exit, if something goes wrong we return an + * error after timeout_ms. + */ while((timer_clock() - start_time) < ms_to_ticks(TEST_TIME_OUT_MS)) { if (sem_attempt(&sem)) { - kputs("> Main: Check if test is finish..\n"); + kputs("> Main: Check if test has finished..\n"); if(global_count == MAX_GLOBAL_COUNT) { kputs("> Main: Test Finished..Ok!\n"); @@ -165,7 +171,7 @@ int sem_testRun(void) } proc_yield(); } - + kputs("Semaphore Test fail..\n"); return -1; } @@ -177,7 +183,7 @@ int sem_testSetup(void) kprintf("Init Semaphore.."); sem_init(&sem); kprintf("Done.\n"); - + #if CONFIG_KERN_PREEMPT kprintf("Init Interrupt (preempt mode).."); irq_init(); @@ -187,11 +193,11 @@ int sem_testSetup(void) kprintf("Init Timer.."); timer_init(); kprintf("Done.\n"); - + kprintf("Init Process.."); proc_init(); kprintf("Done.\n"); - + return 0; } @@ -201,4 +207,4 @@ int sem_testTearDown(void) return 0; } -TEST_MAIN(sem); \ No newline at end of file +TEST_MAIN(sem);