diff --git a/readme.txt b/readme.txt index ab7e2f881..8740e4a35 100644 --- a/readme.txt +++ b/readme.txt @@ -60,6 +60,7 @@ *** 2.1.0 *** - FIX: Fixed assertion in adcStop() (bug 3015109)(backported in 2.0.0). +- OPT: Simplified the test suite code, now it is smaller (backported in 2.0.0). *** 1.5.9 *** - FIX: Fixed STM8 baud rate setup error (bug 3010990). diff --git a/test/test.c b/test/test.c index 0d52d479b..3a5c93edc 100644 --- a/test/test.c +++ b/test/test.c @@ -110,7 +110,7 @@ void test_printn(uint32_t n) { * * @param[in] msgp the message */ -void test_print(char *msgp) { +void test_print(const char *msgp) { while (*msgp) chIOPut(chp, *msgp++); @@ -121,7 +121,7 @@ void test_print(char *msgp) { * * @param[in] msgp the message */ -void test_println(char *msgp) { +void test_println(const char *msgp) { test_print(msgp); chIOPut(chp, '\r'); @@ -353,7 +353,7 @@ msg_t TestThread(void *p) { test_print("."); test_printn(j + 1); test_print(" ("); - test_print(patterns[i][j]->gettest()); + test_print(patterns[i][j]->name); test_println(")"); #if DELAY_BETWEEN_TESTS > 0 chThdSleepMilliseconds(DELAY_BETWEEN_TESTS); diff --git a/test/test.h b/test/test.h index bcdc2e3a0..2ab27847e 100644 --- a/test/test.h +++ b/test/test.h @@ -60,7 +60,7 @@ * @brief Structure representing a test case. */ struct testcase { - char *(*gettest)(void); /**< @brief Test case name get function. */ + const char *name; /**< @brief Test case name. */ void (*setup)(void); /**< @brief Test case preparation function. */ void (*teardown)(void); /**< @brief Test case clean up function. */ void (*execute)(void); /**< @brief Test case execution function. */ @@ -84,8 +84,8 @@ extern "C" { #endif msg_t TestThread(void *p); void test_printn(uint32_t n); - void test_print(char *msgp); - void test_println(char *msgp); + void test_print(const char *msgp); + void test_println(const char *msgp); void test_emit_token(char token); bool_t _test_fail(unsigned point); bool_t _test_assert(unsigned point, bool_t condition); diff --git a/test/testbmk.c b/test/testbmk.c index 9e0d687e2..a67c09af1 100644 --- a/test/testbmk.c +++ b/test/testbmk.c @@ -102,11 +102,6 @@ static unsigned int msg_loop_test(Thread *tp) { * printed in the output log. */ -static char *bmk1_gettest(void) { - - return "Benchmark, messages #1"; -} - static void bmk1_execute(void) { uint32_t n; @@ -121,7 +116,7 @@ static void bmk1_execute(void) { } const struct testcase testbmk1 = { - bmk1_gettest, + "Benchmark, messages #1", NULL, NULL, bmk1_execute @@ -136,11 +131,6 @@ const struct testcase testbmk1 = { * printed in the output log. */ -static char *bmk2_gettest(void) { - - return "Benchmark, messages #2"; -} - static void bmk2_execute(void) { uint32_t n; @@ -155,7 +145,7 @@ static void bmk2_execute(void) { } const struct testcase testbmk2 = { - bmk2_gettest, + "Benchmark, messages #2", NULL, NULL, bmk2_execute @@ -176,11 +166,6 @@ static msg_t thread2(void *p) { * printed in the output log. */ -static char *bmk3_gettest(void) { - - return "Benchmark, messages #3"; -} - static void bmk3_execute(void) { uint32_t n; @@ -199,7 +184,7 @@ static void bmk3_execute(void) { } const struct testcase testbmk3 = { - bmk3_gettest, + "Benchmark, messages #3", NULL, NULL, bmk3_execute @@ -215,11 +200,6 @@ const struct testcase testbmk3 = { * iterations after a second of continuous operations. */ -static char *bmk4_gettest(void) { - - return "Benchmark, context switch"; -} - msg_t thread4(void *p) { msg_t msg; Thread *self = chThdSelf(); @@ -265,7 +245,7 @@ static void bmk4_execute(void) { } const struct testcase testbmk4 = { - bmk4_gettest, + "Benchmark, context switch", NULL, NULL, bmk4_execute @@ -282,11 +262,6 @@ const struct testcase testbmk4 = { * a second of continuous operations. */ -static char *bmk5_gettest(void) { - - return "Benchmark, threads, full cycle"; -} - static void bmk5_execute(void) { uint32_t n = 0; @@ -307,7 +282,7 @@ static void bmk5_execute(void) { } const struct testcase testbmk5 = { - bmk5_gettest, + "Benchmark, threads, full cycle", NULL, NULL, bmk5_execute @@ -326,11 +301,6 @@ const struct testcase testbmk5 = { * a second of continuous operations. */ -static char *bmk6_gettest(void) { - - return "Benchmark, threads, create only"; -} - static void bmk6_execute(void) { uint32_t n = 0; @@ -351,7 +321,7 @@ static void bmk6_execute(void) { } const struct testcase testbmk6 = { - bmk6_gettest, + "Benchmark, threads, create only", NULL, NULL, bmk6_execute @@ -376,11 +346,6 @@ static msg_t thread3(void *p) { return 0; } -static char *bmk7_gettest(void) { - - return "Benchmark, mass reschedule, 5 threads"; -} - static void bmk7_setup(void) { chSemInit(&sem1, 0); @@ -417,7 +382,7 @@ static void bmk7_execute(void) { } const struct testcase testbmk7 = { - bmk7_gettest, + "Benchmark, mass reschedule, 5 threads", bmk7_setup, NULL, bmk7_execute @@ -448,11 +413,6 @@ static msg_t thread8(void *p) { return 0; } -static char *bmk8_gettest(void) { - - return "Benchmark, round robin context switching"; -} - static void bmk8_execute(void) { uint32_t n; @@ -475,7 +435,7 @@ static void bmk8_execute(void) { } const struct testcase testbmk8 = { - bmk8_gettest, + "Benchmark, round robin context switching", NULL, NULL, bmk8_execute @@ -491,11 +451,6 @@ const struct testcase testbmk8 = { * a second of continuous operations. */ -static char *bmk9_gettest(void) { - - return "Benchmark, I/O Queues throughput"; -} - static void bmk9_execute(void) { uint32_t n; static uint8_t ib[16]; @@ -525,7 +480,7 @@ static void bmk9_execute(void) { } const struct testcase testbmk9 = { - bmk9_gettest, + "Benchmark, I/O Queues throughput", NULL, NULL, bmk9_execute @@ -540,11 +495,6 @@ const struct testcase testbmk9 = { * a second of continuous operations. */ -static char *bmk10_gettest(void) { - - return "Benchmark, virtual timers set/reset"; -} - static void tmo(void *param) {(void)param;} static void bmk10_execute(void) { @@ -571,7 +521,7 @@ static void bmk10_execute(void) { } const struct testcase testbmk10 = { - bmk10_gettest, + "Benchmark, virtual timers set/reset", NULL, NULL, bmk10_execute @@ -587,11 +537,6 @@ const struct testcase testbmk10 = { * a second of continuous operations. */ -static char *bmk11_gettest(void) { - - return "Benchmark, semaphores wait/signal"; -} - static void bmk11_setup(void) { chSemInit(&sem1, 1); @@ -622,7 +567,7 @@ static void bmk11_execute(void) { } const struct testcase testbmk11 = { - bmk11_gettest, + "Benchmark, semaphores wait/signal", bmk11_setup, NULL, bmk11_execute @@ -639,11 +584,6 @@ const struct testcase testbmk11 = { * a second of continuous operations. */ -static char *bmk12_gettest(void) { - - return "Benchmark, mutexes lock/unlock"; -} - static void bmk12_setup(void) { chMtxInit(&mtx1); @@ -674,7 +614,7 @@ static void bmk12_execute(void) { } const struct testcase testbmk12 = { - bmk12_gettest, + "Benchmark, mutexes lock/unlock", bmk12_setup, NULL, bmk12_execute @@ -688,11 +628,6 @@ const struct testcase testbmk12 = { * The memory size of the various kernel objects is printed. */ -static char *bmk13_gettest(void) { - - return "Benchmark, RAM footprint"; -} - static void bmk13_execute(void) { test_print("--- System: "); @@ -740,7 +675,7 @@ static void bmk13_execute(void) { } const struct testcase testbmk13 = { - bmk13_gettest, + "Benchmark, RAM footprint", NULL, NULL, bmk13_execute diff --git a/test/testdyn.c b/test/testdyn.c index 345076828..4bd4ed06c 100644 --- a/test/testdyn.c +++ b/test/testdyn.c @@ -78,11 +78,6 @@ static msg_t thread(void *p) { } #if CH_USE_HEAP -static char *dyn1_gettest(void) { - - return "Dynamic APIs, threads creation from heap"; -} - static void dyn1_setup(void) { chHeapInit(&heap1, test.buffer, sizeof(union test_buffers)); @@ -123,7 +118,7 @@ static void dyn1_execute(void) { } const struct testcase testdyn1 = { - dyn1_gettest, + "Dynamic APIs, threads creation from heap", dyn1_setup, NULL, dyn1_execute @@ -141,11 +136,6 @@ const struct testcase testdyn1 = { * one to fail. */ -static char *dyn2_gettest(void) { - - return "Dynamic APIs, threads creation from memory pool"; -} - static void dyn2_setup(void) { chPoolInit(&mp1, THD_WA_SIZE(THREADS_STACK_SIZE), NULL); @@ -184,7 +174,7 @@ static void dyn2_execute(void) { } const struct testcase testdyn2 = { - dyn2_gettest, + "Dynamic APIs, threads creation from memory pool", dyn2_setup, NULL, dyn2_execute @@ -212,11 +202,6 @@ static unsigned regscan(void) { return i; } -static char *dyn3_gettest(void) { - - return "Dynamic APIs, registry and references"; -} - static void dyn3_setup(void) { chHeapInit(&heap1, test.buffer, sizeof(union test_buffers)); @@ -256,7 +241,7 @@ static void dyn3_execute(void) { } const struct testcase testdyn3 = { - dyn3_gettest, + "Dynamic APIs, registry and references", dyn3_setup, NULL, dyn3_execute diff --git a/test/testevt.c b/test/testevt.c index 52ffc5ccd..7e3f4a405 100644 --- a/test/testevt.c +++ b/test/testevt.c @@ -75,11 +75,6 @@ static EVENTSOURCE_DECL(es2); * the associated event handlers are invoked in LSb-first order. */ -static char *evt1_gettest(void) { - - return "Events, registration and dispatch"; -} - static void evt1_setup(void) { chEvtClear(ALL_EVENTS); @@ -113,7 +108,7 @@ static void evt1_execute(void) { } const struct testcase testevt1 = { - evt1_gettest, + "Events, registration and dispatch", evt1_setup, NULL, evt1_execute @@ -133,11 +128,6 @@ const struct testcase testevt1 = { * the expected time and that there are no stuck event flags. */ -static char *evt2_gettest(void) { - - return "Events, wait and broadcast"; -} - static void evt2_setup(void) { chEvtClear(ALL_EVENTS); @@ -235,7 +225,7 @@ static void evt2_execute(void) { } const struct testcase testevt2 = { - evt2_gettest, + "Events, wait and broadcast", evt2_setup, NULL, evt2_execute @@ -257,11 +247,6 @@ const struct testcase testevt2 = { * After each test phase the test verifies that there are no stuck event flags. */ -static char *evt3_gettest(void) { - - return "Events, timeouts"; -} - static void evt3_setup(void) { chEvtClear(ALL_EVENTS); @@ -288,7 +273,7 @@ static void evt3_execute(void) { } const struct testcase testevt3 = { - evt3_gettest, + "Events, timeouts", evt3_setup, NULL, evt3_execute diff --git a/test/testheap.c b/test/testheap.c index eb81f77ed..698a01861 100644 --- a/test/testheap.c +++ b/test/testheap.c @@ -64,11 +64,6 @@ static MemoryHeap test_heap; * sequence. */ -static char *heap1_gettest(void) { - - return "Heap, allocation and fragmentation test"; -} - static void heap1_setup(void) { chHeapInit(&test_heap, test.buffer, sizeof(union test_buffers)); @@ -148,7 +143,7 @@ static void heap1_execute(void) { } const struct testcase testheap1 = { - heap1_gettest, + "Heap, allocation and fragmentation test", heap1_setup, NULL, heap1_execute diff --git a/test/testmbox.c b/test/testmbox.c index b3fa57470..7926f3d06 100644 --- a/test/testmbox.c +++ b/test/testmbox.c @@ -71,11 +71,6 @@ static MAILBOX_DECL(mb1, test.wa.T0, MB_SIZE); * The test expects to find a consistent mailbox status after each operation. */ -static char *mbox1_gettest(void) { - - return "Mailboxes, queuing and timeouts"; -} - static void mbox1_setup(void) { chMBInit(&mb1, (msg_t *)test.wa.T0, MB_SIZE); @@ -161,7 +156,7 @@ static void mbox1_execute(void) { } const struct testcase testmbox1 = { - mbox1_gettest, + "Mailboxes, queuing and timeouts", mbox1_setup, NULL, mbox1_execute diff --git a/test/testmsg.c b/test/testmsg.c index 3757f1de9..5db9614bb 100644 --- a/test/testmsg.c +++ b/test/testmsg.c @@ -59,11 +59,6 @@ * not find a fifth message waiting. */ -static char *msg1_gettest(void) { - - return "Messages, loop"; -} - static msg_t thread(void *p) { chMsgSend(p, 'A'); @@ -107,7 +102,7 @@ static void msg1_execute(void) { } const struct testcase testmsg1 = { - msg1_gettest, + "Messages, loop", NULL, NULL, msg1_execute diff --git a/test/testmtx.c b/test/testmtx.c index f1d7b6d2a..7337b1f14 100644 --- a/test/testmtx.c +++ b/test/testmtx.c @@ -83,10 +83,6 @@ static CONDVAR_DECL(c1); * The test expects the threads to perform their operations in increasing * priority order regardless of the initial order. */ -static char *mtx1_gettest(void) { - - return "Mutexes, priority enqueuing test"; -} static void mtx1_setup(void) { @@ -117,7 +113,7 @@ static void mtx1_execute(void) { } const struct testcase testmtx1 = { - mtx1_gettest, + "Mutexes, priority enqueuing test", mtx1_setup, NULL, mtx1_execute @@ -155,11 +151,6 @@ const struct testcase testmtx1 = { * @endcode */ -static char *mtx2_gettest(void) { - - return "Mutexes, priority inheritance, simple case"; -} - static void mtx2_setup(void) { chMtxInit(&m1); @@ -213,7 +204,7 @@ static void mtx2_execute(void) { } const struct testcase testmtx2 = { - mtx2_gettest, + "Mutexes, priority inheritance, simple case", mtx2_setup, NULL, mtx2_execute @@ -249,10 +240,6 @@ const struct testcase testmtx2 = { * ^ - Priority transition (boost or return). * @endcode */ -static char *mtx3_gettest(void) { - - return "Mutexes, priority inheritance, complex case"; -} static void mtx3_setup(void) { @@ -337,7 +324,7 @@ static void mtx3_execute(void) { } const struct testcase testmtx3 = { - mtx3_gettest, + "Mutexes, priority inheritance, complex case", mtx3_setup, NULL, mtx3_execute @@ -353,10 +340,6 @@ const struct testcase testmtx3 = { * The test expects that the priority changes caused by the priority * inheritance algorithm happen at the right moment and with the right values. */ -static char *mtx4_gettest(void) { - - return "Mutexes, priority return"; -} static void mtx4_setup(void) { @@ -429,7 +412,7 @@ static void mtx4_execute(void) { } const struct testcase testmtx4 = { - mtx4_gettest, + "Mutexes, priority return", mtx4_setup, NULL, mtx4_execute @@ -444,10 +427,6 @@ const struct testcase testmtx4 = { * The test expects that the internal mutex status is consistent after each * operation. */ -static char *mtx5_gettest(void) { - - return "Mutexes, status"; -} static void mtx5_setup(void) { @@ -476,7 +455,7 @@ static void mtx5_execute(void) { } const struct testcase testmtx5 = { - mtx5_gettest, + "Mutexes, status", mtx5_setup, NULL, mtx5_execute @@ -493,10 +472,6 @@ const struct testcase testmtx5 = { * The test expects the threads to reach their goal in increasing priority * order regardless of the initial order. */ -static char *mtx6_gettest(void) { - - return "CondVar, signal test"; -} static void mtx6_setup(void) { @@ -534,7 +509,7 @@ static void mtx6_execute(void) { } const struct testcase testmtx6 = { - mtx6_gettest, + "CondVar, signal test", mtx6_setup, NULL, mtx6_execute @@ -549,10 +524,6 @@ const struct testcase testmtx6 = { * The test expects the threads to reach their goal in increasing priority * order regardless of the initial order. */ -static char *mtx7_gettest(void) { - - return "CondVar, broadcast test"; -} static void mtx7_setup(void) { @@ -575,7 +546,7 @@ static void mtx7_execute(void) { } const struct testcase testmtx7 = { - mtx7_gettest, + "CondVar, broadcast test", mtx7_setup, NULL, mtx7_execute @@ -589,10 +560,6 @@ const struct testcase testmtx7 = { * conditional variable queue. It tests this very specific situation in order * to complete the code coverage. */ -static char *mtx8_gettest(void) { - - return "CondVar, boost test"; -} static void mtx8_setup(void) { @@ -637,7 +604,7 @@ static void mtx8_execute(void) { } const struct testcase testmtx8 = { - mtx8_gettest, + "CondVar, boost test", mtx8_setup, NULL, mtx8_execute diff --git a/test/testpools.c b/test/testpools.c index fdd637768..2ed0e6b35 100644 --- a/test/testpools.c +++ b/test/testpools.c @@ -66,11 +66,6 @@ static void *null_provider(size_t size) { return NULL; } -static char *pools1_gettest(void) { - - return "Memory Pools, queue/dequeue"; -} - static void pools1_setup(void) { chPoolInit(&mp1, THD_WA_SIZE(THREADS_STACK_SIZE), NULL); @@ -96,7 +91,7 @@ static void pools1_execute(void) { } const struct testcase testpools1 = { - pools1_gettest, + "Memory Pools, queue/dequeue", pools1_setup, NULL, pools1_execute diff --git a/test/testqueues.c b/test/testqueues.c index 8247cbd07..149c2a3c3 100644 --- a/test/testqueues.c +++ b/test/testqueues.c @@ -76,11 +76,6 @@ static OUTPUTQUEUE_DECL(oq, test.wa.T1, TEST_QUEUES_SIZE, notify); * consistent through the whole test. */ -static char *queues1_gettest(void) { - - return "Queues, input queues"; -} - static void queues1_setup(void) { chIQInit(&iq, wa[0], TEST_QUEUES_SIZE, notify); @@ -135,7 +130,7 @@ static void queues1_execute(void) { } const struct testcase testqueues1 = { - queues1_gettest, + "Queues, input queues", queues1_setup, NULL, queues1_execute @@ -149,10 +144,6 @@ const struct testcase testqueues1 = { * @p OutputQueue object including timeouts. The queue state must remain * consistent through the whole test. */ -static char *queues2_gettest(void) { - - return "Queues, output queues"; -} static void queues2_setup(void) { @@ -199,7 +190,7 @@ static void queues2_execute(void) { } const struct testcase testqueues2 = { - queues2_gettest, + "Queues, output queues", queues2_setup, NULL, queues2_execute diff --git a/test/testsem.c b/test/testsem.c index dd9db66cd..58d4e5e35 100644 --- a/test/testsem.c +++ b/test/testsem.c @@ -70,10 +70,6 @@ static SEMAPHORE_DECL(sem1, 0); * priority order depending on the CH_USE_SEMAPHORES_PRIORITY configuration * setting. */ -static char *sem1_gettest(void) { - - return "Semaphores, enqueuing"; -} static void sem1_setup(void) { @@ -107,6 +103,13 @@ static void sem1_execute(void) { #endif } +const struct testcase testsem1 = { + "Semaphores, enqueuing", + sem1_setup, + NULL, + sem1_execute +}; + /** * @page test_sem_002 Timeout test * @@ -117,17 +120,6 @@ static void sem1_execute(void) { * in each of the above scenario and that the semaphore structure status is * correct after each operation. */ -const struct testcase testsem1 = { - sem1_gettest, - sem1_setup, - NULL, - sem1_execute -}; - -static char *sem2_gettest(void) { - - return "Semaphores, timeout"; -} static void sem2_setup(void) { @@ -186,7 +178,7 @@ static void sem2_execute(void) { } const struct testcase testsem2 = { - sem2_gettest, + "Semaphores, timeout", sem2_setup, NULL, sem2_execute @@ -205,11 +197,6 @@ const struct testcase testsem2 = { * correct after each operation. */ -static char *sem3_gettest(void) { - - return "Semaphores, atomic signal-wait"; -} - static void sem3_setup(void) { chSemInit(&sem1, 0); @@ -236,7 +223,7 @@ static void sem3_execute(void) { } const struct testcase testsem3 = { - sem3_gettest, + "Semaphores, atomic signal-wait", sem3_setup, NULL, sem3_execute diff --git a/test/testthd.c b/test/testthd.c index c2150a9c1..232ea7008 100644 --- a/test/testthd.c +++ b/test/testthd.c @@ -66,11 +66,6 @@ static msg_t thread(void *p) { return 0; } -static char *thd1_gettest(void) { - - return "Threads, enqueuing test #1"; -} - static void thd1_execute(void) { threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriority()-5, thread, "E"); @@ -83,7 +78,7 @@ static void thd1_execute(void) { } const struct testcase testthd1 = { - thd1_gettest, + "Threads, enqueuing test #1", NULL, NULL, thd1_execute @@ -99,11 +94,6 @@ const struct testcase testthd1 = { * priority order regardless of the initial order. */ -static char *thd2_gettest(void) { - - return "Threads, enqueuing test #2"; -} - static void thd2_execute(void) { threads[1] = chThdCreateStatic(wa[1], WA_SIZE, chThdGetPriority()-4, thread, "D"); @@ -116,7 +106,7 @@ static void thd2_execute(void) { } const struct testcase testthd2 = { - thd2_gettest, + "Threads, enqueuing test #2", NULL, NULL, thd2_execute @@ -132,11 +122,6 @@ const struct testcase testthd2 = { * also tested under priority inheritance boosted priority state. */ -static char *thd3_gettest(void) { - - return "Threads, priority change"; -} - static void thd3_execute(void) { tprio_t prio, p1; @@ -186,7 +171,7 @@ static void thd3_execute(void) { } const struct testcase testthd3 = { - thd3_gettest, + "Threads, priority change", NULL, NULL, thd3_execute @@ -200,11 +185,6 @@ const struct testcase testthd3 = { * to wake up at the exact expected time. */ -static char *thd4_gettest(void) { - - return "Threads, delays"; -} - static void thd4_execute(void) { systime_t time; @@ -232,7 +212,7 @@ static void thd4_execute(void) { } const struct testcase testthd4 = { - thd4_gettest, + "Threads, delays", NULL, NULL, thd4_execute