From dd85cc143d987851bc7cc995cf6109136a16b930 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 16 Feb 2009 18:22:49 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@773 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- readme.txt | 3 ++ test/test.c | 107 ++++++++++++++++++++++--------------------------------- test/test.h | 9 ++++- test/testbmk.c | 49 ++++++++++++++++--------- test/testbmk.h | 4 +-- test/testcond.c | 22 ++++++++---- test/testcond.h | 3 +- test/testdyn.c | 30 +++++++++------- test/testdyn.h | 2 +- test/testevt.c | 15 +++++--- test/testevt.h | 2 +- test/testheap.c | 20 ++++++----- test/testheap.h | 2 +- test/testmsg.c | 24 ++++++++----- test/testmsg.h | 2 +- test/testmtx.c | 27 +++++++------- test/testmtx.h | 2 +- test/testpools.c | 15 +++++--- test/testpools.h | 2 +- test/testrdy.c | 29 +++++++-------- test/testrdy.h | 2 +- test/testsem.c | 26 +++++++++----- test/testsem.h | 2 +- todo.txt | 6 ++-- 24 files changed, 227 insertions(+), 178 deletions(-) diff --git a/readme.txt b/readme.txt index 51ddc1db1..10612524c 100644 --- a/readme.txt +++ b/readme.txt @@ -80,6 +80,9 @@ Win32-MinGW - ChibiOS/RT simulator and demo into a WIN32 process, - FIX: Fixed a small problem in the chcore.c template file. - NEW: Mode flexible debug configuration options, removed the old CH_USE_DEBUG and CH_USE_TRACE. +- Improvements to the test suite, added a new level of indirection that allows + to make tests depend on the configuration options without have to put #ifs + into the test main module. *** 1.1.0unstable *** - FIX: Modified the default value for the STM32 HSI setup it was 1, it should diff --git a/test/test.c b/test/test.c index 5300bce88..9574a0f0e 100644 --- a/test/test.c +++ b/test/test.c @@ -32,50 +32,19 @@ #include "testbmk.h" /* - * Array of all the test cases. + * Array of all the test patterns. */ -static const struct testcase *tests[] = { - &testrdy1, - &testrdy2, -#if CH_USE_SEMAPHORES - &testsem1, - &testsem2, -#endif -#if CH_USE_MUTEXES - &testmtx1, - &testmtx2, - &testmtx3, -#if CH_USE_CONDVARS - &testcond1, - &testcond2, -#endif -#endif -#if CH_USE_MESSAGES - &testmsg1, -#endif -#if CH_USE_EVENTS - &testevt1, -#endif -#if CH_USE_HEAP - &testheap1, -#endif -#if CH_USE_MEMPOOLS - &testpools1, -#endif -#if CH_USE_DYNAMIC && CH_USE_HEAP - &testdyn1, -#endif -#if CH_USE_DYNAMIC && CH_USE_MEMPOOLS - &testdyn2, -#endif - &testbmk1, - &testbmk2, - &testbmk3, - &testbmk4, - &testbmk5, - &testbmk6, - &testbmk7, - &testbmk8, +static const struct testcase **patterns[] = { + patternrdy, + patternsem, + patternmtx, + patterncond, + patternmsg, + patternevt, + patternheap, + patternpools, + patterndyn, + patternbmk, NULL }; @@ -248,13 +217,15 @@ static void execute_test(const struct testcase *tcp) { for (i = 0; i < MAX_THREADS; i++) threads[i] = NULL; - tcp->setup(); + if (tcp->setup != NULL) + tcp->setup(); tcp->execute(); - tcp->teardown(); + if (tcp->teardown != NULL) + tcp->teardown(); } msg_t TestThread(void *p) { - int i; + int i, j; comp = p; test_println(""); @@ -265,29 +236,35 @@ msg_t TestThread(void *p) { global_fail = FALSE; i = 0; - while (tests[i]) { + while (patterns[i]) { #if DELAY_BETWEEN_TESTS > 0 - chThdSleepMilliseconds(DELAY_BETWEEN_TESTS); + chThdSleepMilliseconds(DELAY_BETWEEN_TESTS); #endif - test_println("---------------------------------------------------------------------------"); - test_print("--- Test Case "); - test_printn(i + 1); - test_print(" ("); - test_print(tests[i]->gettest()); - test_println(")"); - execute_test(tests[i]); - if (local_fail) { - test_print("--- Result: FAIL ("); - if (failmsg) - test_print(failmsg); - else { - test_print("sequence error: "); - print_tokens(); - } + j = 0; + while (patterns[i][j]) { + test_println("---------------------------------------------------------------------------"); + test_print("--- Test Case "); + test_printn(i + 1); + test_print("."); + test_printn(j + 1); + test_print(" ("); + test_print(patterns[i][j]->gettest()); test_println(")"); + execute_test(patterns[i][j]); + if (local_fail) { + test_print("--- Result: FAIL ("); + if (failmsg) + test_print(failmsg); + else { + test_print("sequence error: "); + print_tokens(); + } + test_println(")"); + } + else + test_println("--- Result: SUCCESS"); + j++; } - else - test_println("--- Result: SUCCESS"); i++; } test_println("---------------------------------------------------------------------------"); diff --git a/test/test.h b/test/test.h index 4c6de614a..a0acbd1f7 100644 --- a/test/test.h +++ b/test/test.h @@ -20,9 +20,16 @@ #ifndef _TEST_H_ #define _TEST_H_ +#ifndef DELAY_BETWEEN_TESTS +#define DELAY_BETWEEN_TESTS 200 +#endif + +#ifndef TEST_NO_BENCHMARKS +#define TEST_NO_BENCHMARKS FALSE +#endif + #define MAX_THREADS 5 #define MAX_TOKENS 16 -#define DELAY_BETWEEN_TESTS 200 #if defined(CH_ARCHITECTURE_AVR) || defined(CH_ARCHITECTURE_MSP430) #define THREADS_STACK_SIZE 48 diff --git a/test/testbmk.c b/test/testbmk.c index 3fe32df00..f6dc58f20 100644 --- a/test/testbmk.c +++ b/test/testbmk.c @@ -23,8 +23,6 @@ static Semaphore sem1; -static void empty(void) {} - static msg_t thread1(void *p) { msg_t msg; @@ -72,8 +70,8 @@ static void bmk1_execute(void) { const struct testcase testbmk1 = { bmk1_gettest, - empty, - empty, + NULL, + NULL, bmk1_execute }; @@ -98,8 +96,8 @@ static void bmk2_execute(void) { const struct testcase testbmk2 = { bmk2_gettest, - empty, - empty, + NULL, + NULL, bmk2_execute }; @@ -133,8 +131,8 @@ static void bmk3_execute(void) { const struct testcase testbmk3 = { bmk3_gettest, - empty, - empty, + NULL, + NULL, bmk3_execute }; @@ -164,8 +162,8 @@ static void bmk4_execute(void) { const struct testcase testbmk4 = { bmk4_gettest, - empty, - empty, + NULL, + NULL, bmk4_execute }; @@ -195,8 +193,8 @@ static void bmk5_execute(void) { const struct testcase testbmk5 = { bmk5_gettest, - empty, - empty, + NULL, + NULL, bmk5_execute }; @@ -250,7 +248,7 @@ static void bmk6_execute(void) { const struct testcase testbmk6 = { bmk6_gettest, bmk6_setup, - empty, + NULL, bmk6_execute }; @@ -288,8 +286,8 @@ static void bmk7_execute(void) { const struct testcase testbmk7 = { bmk7_gettest, - empty, - empty, + NULL, + NULL, bmk7_execute }; @@ -325,7 +323,24 @@ static void bmk8_execute(void) { const struct testcase testbmk8 = { bmk8_gettest, - empty, - empty, + NULL, + NULL, bmk8_execute }; + +/* + * Test sequence for benchmarks pattern. + */ +const struct testcase *patternbmk[] = { +#if TEST_NO_BENCHMARKS + &testbmk1, + &testbmk2, + &testbmk3, + &testbmk4, + &testbmk5, + &testbmk6, + &testbmk7, + &testbmk8, +#endif + NULL +}; diff --git a/test/testbmk.h b/test/testbmk.h index afa3381e4..f5e269f31 100644 --- a/test/testbmk.h +++ b/test/testbmk.h @@ -20,8 +20,6 @@ #ifndef _TESTBMK_H_ #define _TESTBMK_H_ -extern const struct testcase testbmk1, testbmk2, testbmk3, - testbmk4, testbmk5, testbmk6, - testbmk7, testbmk8; +extern const struct testcase *patternbmk[]; #endif /* _TESTBMK_H_ */ diff --git a/test/testcond.c b/test/testcond.c index f6f390044..2771b5202 100644 --- a/test/testcond.c +++ b/test/testcond.c @@ -37,9 +37,6 @@ static void cond1_setup(void) { chMtxInit(&m1); } -static void cond1_teardown(void) { -} - static msg_t thread1(void *p) { chMtxLock(&m1); @@ -71,7 +68,7 @@ static void cond1_execute(void) { const struct testcase testcond1 = { cond1_gettest, cond1_setup, - cond1_teardown, + NULL, cond1_execute }; @@ -97,9 +94,20 @@ static void cond2_execute(void) { const struct testcase testcond2 = { cond2_gettest, - cond1_setup, - cond1_teardown, + NULL, + NULL, cond2_execute }; -#endif /* defined(CH_USE_CONDVARS) && defined(CH_USE_MUTEXES) */ +#endif /* CH_USE_CONDVARS && CH_USE_MUTEXES */ + +/* + * Test sequence for condvars pattern. + */ +const struct testcase *patterncond[] = { +#if CH_USE_CONDVARS && CH_USE_MUTEXES + &testcond1, + &testcond2, +#endif + NULL +}; diff --git a/test/testcond.h b/test/testcond.h index 8e6f286b1..b07aa804e 100644 --- a/test/testcond.h +++ b/test/testcond.h @@ -20,7 +20,6 @@ #ifndef _TESTCOND_H_ #define _TESTCOND_H_ -extern const struct testcase testcond1; -extern const struct testcase testcond2; +extern const struct testcase *patterncond[]; #endif /* _TESTCOND_H_ */ diff --git a/test/testdyn.c b/test/testdyn.c index f59cdaa14..07b07594c 100644 --- a/test/testdyn.c +++ b/test/testdyn.c @@ -35,12 +35,6 @@ static char *dyn1_gettest(void) { return "Dynamic APIs, threads creation from heap"; } -static void dyn1_setup(void) { -} - -static void dyn1_teardown(void) { -} - static void dyn1_execute(void) { size_t n, sz; tprio_t prio = chThdGetPriority(); @@ -72,8 +66,8 @@ static void dyn1_execute(void) { const struct testcase testdyn1 = { dyn1_gettest, - dyn1_setup, - dyn1_teardown, + NULL, + NULL, dyn1_execute }; #endif /* CH_USE_HEAP */ @@ -91,9 +85,6 @@ static void dyn2_setup(void) { chPoolInit(&mp1, THD_WA_SIZE(THREADS_STACK_SIZE)); } -static void dyn2_teardown(void) { -} - static void dyn2_execute(void) { int i; tprio_t prio = chThdGetPriority(); @@ -129,9 +120,24 @@ static void dyn2_execute(void) { const struct testcase testdyn2 = { dyn2_gettest, dyn2_setup, - dyn2_teardown, + NULL, dyn2_execute }; #endif /* CH_USE_MEMPOOLS */ #endif /* CH_USE_DYNAMIC */ + +/* + * Test sequence for dynamic APIs pattern. + */ +const struct testcase *patterndyn[] = { +#if CH_USE_DYNAMIC +#if CH_USE_HEAP + &testdyn1, +#endif +#if CH_USE_MEMPOOLS + &testdyn2, +#endif +#endif + NULL +}; diff --git a/test/testdyn.h b/test/testdyn.h index bb2a396bb..d209c9f71 100644 --- a/test/testdyn.h +++ b/test/testdyn.h @@ -20,6 +20,6 @@ #ifndef _TESTDYN_H_ #define _TESTDYN_H_ -extern const struct testcase testdyn1, testdyn2; +extern const struct testcase *patterndyn[]; #endif /* _TESTDYN_H_ */ diff --git a/test/testevt.c b/test/testevt.c index 706953dd6..89c5cf114 100644 --- a/test/testevt.c +++ b/test/testevt.c @@ -37,9 +37,6 @@ static void evt1_setup(void) { chEvtClear(ALL_EVENTS); } -static void evt1_teardown(void) { -} - static msg_t thread(void *p) { chEvtBroadcast(&es1); @@ -97,8 +94,18 @@ static void evt1_execute(void) { const struct testcase testevt1 = { evt1_gettest, evt1_setup, - evt1_teardown, + NULL, evt1_execute }; #endif /* CH_USE_EVENTS */ + +/* + * Test sequence for events pattern. + */ +const struct testcase *patternevt[] = { +#if CH_USE_EVENTS + &testevt1, +#endif + NULL +}; diff --git a/test/testevt.h b/test/testevt.h index 5c66d5924..477b7083e 100644 --- a/test/testevt.h +++ b/test/testevt.h @@ -20,6 +20,6 @@ #ifndef _TESTEVT_H_ #define _TESTEVT_H_ -extern const struct testcase testevt1; +extern const struct testcase *patternevt[]; #endif /* _TESTEVT_H_ */ diff --git a/test/testheap.c b/test/testheap.c index e9907baba..841c084e8 100644 --- a/test/testheap.c +++ b/test/testheap.c @@ -30,12 +30,6 @@ static char *heap1_gettest(void) { return "Heap, allocation and fragmentation test"; } -static void heap1_setup(void) { -} - -static void heap1_teardown(void) { -} - static void heap1_execute(void) { void *p1, *p2, *p3; size_t n, sz; @@ -75,9 +69,19 @@ static void heap1_execute(void) { const struct testcase testheap1 = { heap1_gettest, - heap1_setup, - heap1_teardown, + NULL, + NULL, heap1_execute }; #endif /* CH_USE_HEAP */ + +/* + * Test sequence for heap pattern. + */ +const struct testcase *patternheap[] = { +#if CH_USE_HEAP + &testheap1, +#endif + NULL +}; diff --git a/test/testheap.h b/test/testheap.h index 4fc6d17ce..a310dc40c 100644 --- a/test/testheap.h +++ b/test/testheap.h @@ -20,6 +20,6 @@ #ifndef _TESTHEAP_H_ #define _TESTHEAP_H_ -extern const struct testcase testheap1; +extern const struct testcase *patternheap[]; #endif /* _TESTHEAP_H_ */ diff --git a/test/testmsg.c b/test/testmsg.c index 735375a16..8af1c29e3 100644 --- a/test/testmsg.c +++ b/test/testmsg.c @@ -21,17 +21,13 @@ #include "test.h" +#if CH_USE_MESSAGES + static char *msg1_gettest(void) { return "Messages, dispatch test"; } -static void msg1_setup(void) { -} - -static void msg1_teardown(void) { -} - static msg_t thread(void *p) { msg_t msg; int i; @@ -59,7 +55,19 @@ static void msg1_execute(void) { const struct testcase testmsg1 = { msg1_gettest, - msg1_setup, - msg1_teardown, + NULL, + NULL, msg1_execute }; + +#endif /* CH_USE_MESSAGES */ + +/* + * Test sequence for messages pattern. + */ +const struct testcase *patternmsg[] = { +#if CH_USE_MESSAGES + &testmsg1, +#endif + NULL +}; diff --git a/test/testmsg.h b/test/testmsg.h index 8c9631bb7..c3cadcafa 100644 --- a/test/testmsg.h +++ b/test/testmsg.h @@ -20,6 +20,6 @@ #ifndef _TESTMSG_H_ #define _TESTMSG_H_ -extern const struct testcase testmsg1; +extern const struct testcase *patternmsg[]; #endif /* _TESTMSG_H_ */ diff --git a/test/testmtx.c b/test/testmtx.c index 7675f3f7c..6bef57041 100644 --- a/test/testmtx.c +++ b/test/testmtx.c @@ -37,9 +37,6 @@ static void mtx1_setup(void) { chMtxInit(&m1); } -static void mtx1_teardown(void) { -} - static msg_t thread1(void *p) { chMtxLock(&m1); @@ -66,7 +63,7 @@ static void mtx1_execute(void) { const struct testcase testmtx1 = { mtx1_gettest, mtx1_setup, - mtx1_teardown, + NULL, mtx1_execute }; @@ -80,9 +77,6 @@ static void mtx2_setup(void) { chMtxInit(&m1); } -static void mtx2_teardown(void) { -} - static msg_t thread2(void *p) { chThdSleepMilliseconds(10); @@ -127,7 +121,7 @@ static void mtx2_execute(void) { const struct testcase testmtx2 = { mtx2_gettest, mtx2_setup, - mtx2_teardown, + NULL, mtx2_execute }; @@ -142,9 +136,6 @@ static void mtx3_setup(void) { chMtxInit(&m2); } -static void mtx3_teardown(void) { -} - static msg_t thread5(void *p) { chMtxLock(&m1); @@ -218,8 +209,20 @@ static void mtx3_execute(void) { const struct testcase testmtx3 = { mtx3_gettest, mtx3_setup, - mtx3_teardown, + NULL, mtx3_execute }; #endif /* CH_USE_MUTEXES */ + +/* + * Test sequence for mutexes pattern. + */ +const struct testcase *patternmtx[] = { +#if CH_USE_MUTEXES + &testmtx1, + &testmtx2, + &testmtx3, +#endif + NULL +}; diff --git a/test/testmtx.h b/test/testmtx.h index 068fbc7b8..59c49605b 100644 --- a/test/testmtx.h +++ b/test/testmtx.h @@ -20,6 +20,6 @@ #ifndef _TESTMTX_H_ #define _TESTMTX_H_ -extern const struct testcase testmtx1, testmtx2, testmtx3; +extern const struct testcase *patternmtx[]; #endif /* _TESTMTX_H_ */ diff --git a/test/testpools.c b/test/testpools.c index 2165c39d1..fae7402c3 100644 --- a/test/testpools.c +++ b/test/testpools.c @@ -35,9 +35,6 @@ static void pools1_setup(void) { chPoolInit(&mp1, THD_WA_SIZE(THREADS_STACK_SIZE)); } -static void pools1_teardown(void) { -} - static void pools1_execute(void) { int i; @@ -56,8 +53,18 @@ static void pools1_execute(void) { const struct testcase testpools1 = { pools1_gettest, pools1_setup, - pools1_teardown, + NULL, pools1_execute }; #endif /* CH_USE_MEMPOOLS */ + +/* + * Test sequence for pools pattern. + */ +const struct testcase *patternpools[] = { +#if CH_USE_MEMPOOLS + &testpools1, +#endif + NULL +}; diff --git a/test/testpools.h b/test/testpools.h index 413d1eb76..920e64da2 100644 --- a/test/testpools.h +++ b/test/testpools.h @@ -20,6 +20,6 @@ #ifndef _TESTPOOLS_H_ #define _TESTPOOLS_H_ -extern const struct testcase testpools1; +extern const struct testcase *patternpools[]; #endif /* _TESTPOOLS_H_ */ diff --git a/test/testrdy.c b/test/testrdy.c index a9b52701e..b085fde02 100644 --- a/test/testrdy.c +++ b/test/testrdy.c @@ -32,12 +32,6 @@ static char *rdy1_gettest(void) { return "Ready List, priority enqueuing test #1"; } -static void rdy1_setup(void) { -} - -static void rdy1_teardown(void) { -} - static void rdy1_execute(void) { threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriority()-5, thread, "E"); @@ -51,8 +45,8 @@ static void rdy1_execute(void) { const struct testcase testrdy1 = { rdy1_gettest, - rdy1_setup, - rdy1_teardown, + NULL, + NULL, rdy1_execute }; @@ -61,12 +55,6 @@ static char *rdy2_gettest(void) { return "Ready List, priority enqueuing test #2"; } -static void rdy2_setup(void) { -} - -static void rdy2_teardown(void) { -} - static void rdy2_execute(void) { threads[1] = chThdCreateStatic(wa[1], WA_SIZE, chThdGetPriority()-4, thread, "D"); @@ -80,7 +68,16 @@ static void rdy2_execute(void) { const struct testcase testrdy2 = { rdy2_gettest, - rdy2_setup, - rdy2_teardown, + NULL, + NULL, rdy2_execute }; + +/* + * Test sequence for ready list pattern. + */ +const struct testcase *patternrdy[] = { + &testrdy1, + &testrdy2, + NULL +}; diff --git a/test/testrdy.h b/test/testrdy.h index 68719351f..3be545b1b 100644 --- a/test/testrdy.h +++ b/test/testrdy.h @@ -20,6 +20,6 @@ #ifndef _TESTRDY_H_ #define _TESTRDY_H_ -extern const struct testcase testrdy1, testrdy2; +extern const struct testcase *patternrdy[]; #endif /* _TESTRDY_H_ */ diff --git a/test/testsem.c b/test/testsem.c index c16bb0e68..c582d9531 100644 --- a/test/testsem.c +++ b/test/testsem.c @@ -37,9 +37,6 @@ static void sem1_setup(void) { chSemInit(&sem1, 0); } -static void sem1_teardown(void) { -} - static msg_t thread(void *p) { chSemWait(&sem1); @@ -66,10 +63,11 @@ static void sem1_execute(void) { const struct testcase testsem1 = { sem1_gettest, sem1_setup, - sem1_teardown, + NULL, sem1_execute }; +#if CH_USE_SEMAPHORES_TIMEOUT static char *sem2_gettest(void) { return "Semaphores, timeout test"; @@ -80,9 +78,6 @@ static void sem2_setup(void) { chSemInit(&sem1, 0); } -static void sem2_teardown(void) { -} - static void sem2_execute(void) { int i; systime_t target_time; @@ -101,8 +96,21 @@ static void sem2_execute(void) { const struct testcase testsem2 = { sem2_gettest, sem2_setup, - sem2_teardown, + NULL, sem2_execute }; - +#endif /* CH_USE_SEMAPHORES_TIMEOUT */ #endif /* CH_USE_SEMAPHORES */ + +/* + * Test sequence for semaphores pattern. + */ +const struct testcase *patternsem[] = { +#if CH_USE_SEMAPHORES + &testsem1, +#if CH_USE_SEMAPHORES_TIMEOUT + &testsem2, +#endif +#endif + NULL +}; diff --git a/test/testsem.h b/test/testsem.h index 8bb6b17bf..3bb19d0d9 100644 --- a/test/testsem.h +++ b/test/testsem.h @@ -20,6 +20,6 @@ #ifndef _TESTSEM_H_ #define _TESTSEM_H_ -extern const struct testcase testsem1, testsem2; +extern const struct testcase *patternsem[]; #endif /* _TESTSEM_H_ */ diff --git a/todo.txt b/todo.txt index af61fd29c..4f9288f59 100644 --- a/todo.txt +++ b/todo.txt @@ -5,12 +5,14 @@ After 1.0.0: * chSysLock() and chSysUnlock() with counter (option). * OSEK-style chSysSuspendAll()/chSysResumeAll()/chSysEnable()/chSysDisable(), implemented this as the new Suspended and Disabled states in 1.1. -X lwIP TCP/IP stack integration. +X lwIP TCP/IP stack integration and demo. - "Wide Queues" or Mailboxes, lwIP requires them. -- FatFS library integration and demo. +X FatFS library integration and demo. * Multiple debug switches. - Stack guard pages. - Threads profiling option. + - Objects registry. + Problem: fixed size? it goes against project policy. * Idle loop hook macro. * Switch the configuration options to TRUE/FALSE rather than def/undef. - Threads Pools manager in the library. -- cgit v1.2.3