From f140302b0b3e9f7c84fede1120e3bb15c2c4322a Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 13 Apr 2009 08:15:51 +0000 Subject: 97.92% code coverage for threads. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@899 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- test/test.c | 4 +- test/test.mk | 2 +- test/testrdy.c | 83 --------------------------------- test/testrdy.h | 25 ---------- test/testthd.c | 145 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/testthd.h | 25 ++++++++++ 6 files changed, 173 insertions(+), 111 deletions(-) delete mode 100644 test/testrdy.c delete mode 100644 test/testrdy.h create mode 100644 test/testthd.c create mode 100644 test/testthd.h diff --git a/test/test.c b/test/test.c index 5cc11f542..73fbe7381 100644 --- a/test/test.c +++ b/test/test.c @@ -20,7 +20,7 @@ #include #include "test.h" -#include "testrdy.h" +#include "testthd.h" #include "testsem.h" #include "testmtx.h" #include "testmsg.h" @@ -35,7 +35,7 @@ * Array of all the test patterns. */ static const struct testcase **patterns[] = { - patternrdy, + patternthd, patternsem, patternmtx, patternmsg, diff --git a/test/test.mk b/test/test.mk index 9f423de64..ee5128ac2 100644 --- a/test/test.mk +++ b/test/test.mk @@ -1,5 +1,5 @@ # List of all the ChibiOS/RT test files. -TESTSRC = ../../test/test.c ../../test/testrdy.c ../../test/testsem.c \ +TESTSRC = ../../test/test.c ../../test/testthd.c ../../test/testsem.c \ ../../test/testmtx.c ../../test/testmsg.c ../../test/testmbox.c \ ../../test/testevt.c ../../test/testheap.c ../../test/testpools.c \ ../../test/testdyn.c ../../test/testbmk.c diff --git a/test/testrdy.c b/test/testrdy.c deleted file mode 100644 index d35b783c4..000000000 --- a/test/testrdy.c +++ /dev/null @@ -1,83 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. - - This file is part of ChibiOS/RT. - - ChibiOS/RT is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - ChibiOS/RT is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include - -#include "test.h" - -static msg_t thread(void *p) { - - test_emit_token(*(char *)p); - return 0; -} - -static char *rdy1_gettest(void) { - - return "Ready List, priority enqueuing test #1"; -} - -static void rdy1_execute(void) { - - threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriority()-5, thread, "E"); - threads[1] = chThdCreateStatic(wa[1], WA_SIZE, chThdGetPriority()-4, thread, "D"); - threads[2] = chThdCreateStatic(wa[2], WA_SIZE, chThdGetPriority()-3, thread, "C"); - threads[3] = chThdCreateStatic(wa[3], WA_SIZE, chThdGetPriority()-2, thread, "B"); - threads[4] = chThdCreateStatic(wa[4], WA_SIZE, chThdGetPriority()-1, thread, "A"); - test_wait_threads(); - test_assert_sequence("ABCDE"); -} - -const struct testcase testrdy1 = { - rdy1_gettest, - NULL, - NULL, - rdy1_execute -}; - -static char *rdy2_gettest(void) { - - return "Ready List, priority enqueuing test #2"; -} - -static void rdy2_execute(void) { - - threads[1] = chThdCreateStatic(wa[1], WA_SIZE, chThdGetPriority()-4, thread, "D"); - threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriority()-5, thread, "E"); - threads[4] = chThdCreateStatic(wa[4], WA_SIZE, chThdGetPriority()-1, thread, "A"); - threads[3] = chThdCreateStatic(wa[3], WA_SIZE, chThdGetPriority()-2, thread, "B"); - threads[2] = chThdCreateStatic(wa[2], WA_SIZE, chThdGetPriority()-3, thread, "C"); - test_wait_threads(); - test_assert_sequence("ABCDE"); -} - -const struct testcase testrdy2 = { - rdy2_gettest, - NULL, - NULL, - rdy2_execute -}; - -/* - * Test sequence for ready list pattern. - */ -const struct testcase * const patternrdy[] = { - &testrdy1, - &testrdy2, - NULL -}; diff --git a/test/testrdy.h b/test/testrdy.h deleted file mode 100644 index 3be545b1b..000000000 --- a/test/testrdy.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. - - This file is part of ChibiOS/RT. - - ChibiOS/RT is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - ChibiOS/RT is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef _TESTRDY_H_ -#define _TESTRDY_H_ - -extern const struct testcase *patternrdy[]; - -#endif /* _TESTRDY_H_ */ diff --git a/test/testthd.c b/test/testthd.c new file mode 100644 index 000000000..92f0bfe9f --- /dev/null +++ b/test/testthd.c @@ -0,0 +1,145 @@ +/* + ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include + +#include "test.h" + +static msg_t thread(void *p) { + + test_emit_token(*(char *)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"); + threads[1] = chThdCreateStatic(wa[1], WA_SIZE, chThdGetPriority()-4, thread, "D"); + threads[2] = chThdCreateStatic(wa[2], WA_SIZE, chThdGetPriority()-3, thread, "C"); + threads[3] = chThdCreateStatic(wa[3], WA_SIZE, chThdGetPriority()-2, thread, "B"); + threads[4] = chThdCreateStatic(wa[4], WA_SIZE, chThdGetPriority()-1, thread, "A"); + test_wait_threads(); + test_assert_sequence("ABCDE"); +} + +const struct testcase testthd1 = { + thd1_gettest, + NULL, + NULL, + thd1_execute +}; + +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"); + threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriority()-5, thread, "E"); + threads[4] = chThdCreateStatic(wa[4], WA_SIZE, chThdGetPriority()-1, thread, "A"); + threads[3] = chThdCreateStatic(wa[3], WA_SIZE, chThdGetPriority()-2, thread, "B"); + threads[2] = chThdCreateStatic(wa[2], WA_SIZE, chThdGetPriority()-3, thread, "C"); + test_wait_threads(); + test_assert_sequence("ABCDE"); +} + +const struct testcase testthd2 = { + thd2_gettest, + NULL, + NULL, + thd2_execute +}; + +static char *thd3_gettest(void) { + + return "Threads, priority change"; +} + +static void thd3_execute(void) { + tprio_t prio, p1; + + prio = chThdGetPriority(); + p1 = chThdSetPriority(prio + 1); + test_assert(p1 == prio, "#1"); + test_assert(chThdGetPriority() == prio + 1, "#2"); + p1 = chThdSetPriority(p1); + test_assert(p1 == prio + 1, "#3"); + test_assert(chThdGetPriority() == prio, "#4"); +} + +const struct testcase testthd3 = { + thd3_gettest, + NULL, + NULL, + thd3_execute +}; + +static char *thd4_gettest(void) { + + return "Threads, delays"; +} + +static void thd4_execute(void) { + systime_t time; + + /* Timeouts in microseconds.*/ + time = chTimeNow(); + chThdSleepMicroseconds(100000); + test_assert(chTimeIsWithin(time + US2ST(100000), time + US2ST(100000) + 1), "#1"); + + /* Timeouts in milliseconds.*/ + time = chTimeNow(); + chThdSleepMilliseconds(100); + test_assert(chTimeIsWithin(time + MS2ST(100), time + MS2ST(100) + 1), "#2"); + + /* Timeouts in seconds.*/ + time = chTimeNow(); + chThdSleepSeconds(1); + test_assert(chTimeIsWithin(time + S2ST(1), time + S2ST(1) + 1), "#3"); + + /* Absolute timelines.*/ + time = chTimeNow() + MS2ST(100); + chThdSleepUntil(time); + test_assert(chTimeIsWithin(time, time + 1), "#4"); +} + +const struct testcase testthd4 = { + thd4_gettest, + NULL, + NULL, + thd4_execute +}; + +/* + * Test sequence for ready list pattern. + */ +const struct testcase * const patternthd[] = { + &testthd1, + &testthd2, + &testthd3, + &testthd4, + NULL +}; diff --git a/test/testthd.h b/test/testthd.h new file mode 100644 index 000000000..936795e56 --- /dev/null +++ b/test/testthd.h @@ -0,0 +1,25 @@ +/* + ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef _TESTRDY_H_ +#define _TESTRDY_H_ + +extern const struct testcase *patternthd[]; + +#endif /* _TESTRDY_H_ */ -- cgit v1.2.3