From 6d6284c9e6d1e3d1f0083c153ee21235771e1014 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Wed, 24 Feb 2016 14:44:50 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@8941 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- test/rt/test.c | 13 +++++++++++++ test/rt/test.h | 1 + test/rt/test.mk | 1 + test/rt/testbmk.c | 43 +++++++++++++++++++------------------------ test/rt/testdyn.c | 15 +++++++++------ 5 files changed, 43 insertions(+), 30 deletions(-) (limited to 'test') diff --git a/test/rt/test.c b/test/rt/test.c index fcba9607d..f4a08eeea 100644 --- a/test/rt/test.c +++ b/test/rt/test.c @@ -35,6 +35,7 @@ #include "testevt.h" #include "testheap.h" #include "testpools.h" +#include "testdyn.h" #include "testqueues.h" #include "testbmk.h" @@ -51,6 +52,7 @@ static ROMCONST struct testcase * ROMCONST *patterns[] = { patternevt, patternheap, patternpools, + patterndyn, patternqueues, patternbmk, NULL @@ -191,6 +193,17 @@ bool _test_assert_time_window(unsigned point, systime_t start, systime_t end) { * Threads utils. */ +/** + * @brief Sets a termination request in all the test-spawned threads. + */ +void test_terminate_threads(void) { + int i; + + for (i = 0; i < MAX_THREADS; i++) + if (threads[i]) + chThdTerminate(threads[i]); +} + /** * @brief Waits for the completion of all the test-spawned threads. */ diff --git a/test/rt/test.h b/test/rt/test.h index eb1f35c54..da080db2d 100644 --- a/test/rt/test.h +++ b/test/rt/test.h @@ -90,6 +90,7 @@ extern "C" { bool _test_assert(unsigned point, bool condition); bool _test_assert_sequence(unsigned point, char *expected); bool _test_assert_time_window(unsigned point, systime_t start, systime_t end); + void test_terminate_threads(void); void test_wait_threads(void); systime_t test_wait_tick(void); void test_start_timer(unsigned ms); diff --git a/test/rt/test.mk b/test/rt/test.mk index 1a3b368bb..03de3c89a 100644 --- a/test/rt/test.mk +++ b/test/rt/test.mk @@ -8,6 +8,7 @@ TESTSRC = ${CHIBIOS}/test/rt/test.c \ ${CHIBIOS}/test/rt/testevt.c \ ${CHIBIOS}/test/rt/testheap.c \ ${CHIBIOS}/test/rt/testpools.c \ + ${CHIBIOS}/test/rt/testdyn.c \ ${CHIBIOS}/test/rt/testqueues.c \ ${CHIBIOS}/test/rt/testsys.c \ ${CHIBIOS}/test/rt/testbmk.c diff --git a/test/rt/testbmk.c b/test/rt/testbmk.c index 639ba2b7b..1bffbc4df 100644 --- a/test/rt/testbmk.c +++ b/test/rt/testbmk.c @@ -344,7 +344,8 @@ ROMCONST struct testcase testbmk6 = { static THD_FUNCTION(thread3, p) { - while (!*(bool *)p) + (void)p; + while (!chThdShouldTerminateX()) chSemWait(&sem1); } @@ -355,13 +356,12 @@ static void bmk7_setup(void) { static void bmk7_execute(void) { uint32_t n; - bool terminate = false; - threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriorityX()+5, thread3, &terminate); - threads[1] = chThdCreateStatic(wa[1], WA_SIZE, chThdGetPriorityX()+4, thread3, &terminate); - threads[2] = chThdCreateStatic(wa[2], WA_SIZE, chThdGetPriorityX()+3, thread3, &terminate); - threads[3] = chThdCreateStatic(wa[3], WA_SIZE, chThdGetPriorityX()+2, thread3, &terminate); - threads[4] = chThdCreateStatic(wa[4], WA_SIZE, chThdGetPriorityX()+1, thread3, &terminate); + threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriorityX()+5, thread3, NULL); + threads[1] = chThdCreateStatic(wa[1], WA_SIZE, chThdGetPriorityX()+4, thread3, NULL); + threads[2] = chThdCreateStatic(wa[2], WA_SIZE, chThdGetPriorityX()+3, thread3, NULL); + threads[3] = chThdCreateStatic(wa[3], WA_SIZE, chThdGetPriorityX()+2, thread3, NULL); + threads[4] = chThdCreateStatic(wa[4], WA_SIZE, chThdGetPriorityX()+1, thread3, NULL); n = 0; test_wait_tick(); @@ -373,7 +373,7 @@ static void bmk7_execute(void) { _sim_check_for_interrupts(); #endif } while (!test_timer_done); - terminate = true; + test_terminate_threads(); chSemReset(&sem1, 0); test_wait_threads(); @@ -401,44 +401,39 @@ ROMCONST struct testcase testbmk7 = { * The performance is calculated by measuring the number of iterations after * a second of continuous operations. */ -typedef struct { - bool terminate; - uint32_t n; -} params_t; static THD_FUNCTION(thread8, p) { - params_t *pp = (params_t *)p; do { chThdYield(); chThdYield(); chThdYield(); chThdYield(); - pp->n += 4; + (*(uint32_t *)p) += 4; #if defined(SIMULATOR) _sim_check_for_interrupts(); #endif - } while (!pp->terminate); + } while(!chThdShouldTerminateX()); } static void bmk8_execute(void) { - params_t params = {false, 0}; + uint32_t n; - params.n = 0; + n = 0; test_wait_tick(); - threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriorityX()-1, thread8, (void *)¶ms); - threads[1] = chThdCreateStatic(wa[1], WA_SIZE, chThdGetPriorityX()-1, thread8, (void *)¶ms); - threads[2] = chThdCreateStatic(wa[2], WA_SIZE, chThdGetPriorityX()-1, thread8, (void *)¶ms); - threads[3] = chThdCreateStatic(wa[3], WA_SIZE, chThdGetPriorityX()-1, thread8, (void *)¶ms); - threads[4] = chThdCreateStatic(wa[4], WA_SIZE, chThdGetPriorityX()-1, thread8, (void *)¶ms); + threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriorityX()-1, thread8, (void *)&n); + threads[1] = chThdCreateStatic(wa[1], WA_SIZE, chThdGetPriorityX()-1, thread8, (void *)&n); + threads[2] = chThdCreateStatic(wa[2], WA_SIZE, chThdGetPriorityX()-1, thread8, (void *)&n); + threads[3] = chThdCreateStatic(wa[3], WA_SIZE, chThdGetPriorityX()-1, thread8, (void *)&n); + threads[4] = chThdCreateStatic(wa[4], WA_SIZE, chThdGetPriorityX()-1, thread8, (void *)&n); chThdSleepSeconds(1); - params.terminate = true; + test_terminate_threads(); test_wait_threads(); test_print("--- Score : "); - test_printn(params.n); + test_printn(n); test_println(" ctxswc/S"); } diff --git a/test/rt/testdyn.c b/test/rt/testdyn.c index 9e8932c10..25304a376 100644 --- a/test/rt/testdyn.c +++ b/test/rt/testdyn.c @@ -87,13 +87,16 @@ static void dyn1_execute(void) { /* Starting threads from the heap. */ threads[0] = chThdCreateFromHeap(&heap1, THD_WORKING_AREA_SIZE(THREADS_STACK_SIZE), + "dyn1", prio-1, thread, "A"); threads[1] = chThdCreateFromHeap(&heap1, THD_WORKING_AREA_SIZE(THREADS_STACK_SIZE), + "dyn2", prio-2, thread, "B"); /* Large working area in order to make the thread creation fail.*/ threads[2] = chThdCreateFromHeap(&heap1, THD_WORKING_AREA_SIZE(THREADS_STACK_SIZE * 16), + "dyn3", prio-3, thread, "C"); test_assert(1, (threads[0] != NULL) && @@ -145,11 +148,11 @@ static void dyn2_execute(void) { chPoolFree(&mp1, wa[i]); /* Starting threads from the memory pool. */ - threads[0] = chThdCreateFromMemoryPool(&mp1, prio-1, thread, "A"); - threads[1] = chThdCreateFromMemoryPool(&mp1, prio-2, thread, "B"); - threads[2] = chThdCreateFromMemoryPool(&mp1, prio-3, thread, "C"); - threads[3] = chThdCreateFromMemoryPool(&mp1, prio-4, thread, "D"); - threads[4] = chThdCreateFromMemoryPool(&mp1, prio-5, thread, "E"); + threads[0] = chThdCreateFromMemoryPool(&mp1, "dyn1", prio-1, thread, "A"); + threads[1] = chThdCreateFromMemoryPool(&mp1, "dyn2", prio-2, thread, "B"); + threads[2] = chThdCreateFromMemoryPool(&mp1, "dyn3", prio-3, thread, "C"); + threads[3] = chThdCreateFromMemoryPool(&mp1, "dyn4", prio-4, thread, "D"); + threads[4] = chThdCreateFromMemoryPool(&mp1, "dyn5", prio-5, thread, "E"); test_assert(1, (threads[0] != NULL) && (threads[1] != NULL) && @@ -207,7 +210,7 @@ static void dyn3_execute(void) { tprio_t prio = chThdGetPriorityX(); /* Testing references increase/decrease and final detach.*/ - tp = chThdCreateFromHeap(&heap1, WA_SIZE, prio-1, thread, "A"); + tp = chThdCreateFromHeap(&heap1, WA_SIZE, "dyn1", prio-1, thread, "A"); test_assert(1, tp->refs == 1, "wrong initial reference counter"); chThdAddRef(tp); test_assert(2, tp->refs == 2, "references increase failure"); -- cgit v1.2.3