From b9933c2089f5f0cd93738ae9081c45fcf3df54b7 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 11 Aug 2011 17:51:37 +0000 Subject: Implemented system state checker debug option, remove the option CH_USE_NESTED_LOCKS. Documentation improvements and fixes. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3221 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- test/coverage/chconf.h | 61 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 20 deletions(-) (limited to 'test') diff --git a/test/coverage/chconf.h b/test/coverage/chconf.h index d063fa93f..d3bc3b430 100644 --- a/test/coverage/chconf.h +++ b/test/coverage/chconf.h @@ -33,7 +33,10 @@ #define _CHCONF_H_ /*===========================================================================*/ -/* Kernel parameters. */ +/** + * @name Kernel parameters and options + * @{ + */ /*===========================================================================*/ /** @@ -60,21 +63,6 @@ #define CH_TIME_QUANTUM 20 #endif -/** - * @brief Nested locks. - * @details If enabled then the use of nested @p chSysLock() / @p chSysUnlock() - * operations is allowed.
- * For performance and code size reasons the recommended setting - * is to leave this option disabled.
- * You may use this option if you need to merge ChibiOS/RT with - * external libraries that require nested lock/unlock operations. - * - * @note The default is @p FALSE. - */ -#if !defined(CH_USE_NESTED_LOCKS) || defined(__DOXYGEN__) -#define CH_USE_NESTED_LOCKS TRUE -#endif - /** * @brief Managed RAM size. * @details Size of the RAM area to be managed by the OS. If set to zero @@ -107,8 +95,13 @@ #define CH_NO_IDLE_THREAD FALSE #endif +/** @} */ + /*===========================================================================*/ -/* Performance options. */ +/** + * @name Performance options + * @{ + */ /*===========================================================================*/ /** @@ -123,8 +116,13 @@ #define CH_OPTIMIZE_SPEED FALSE #endif +/** @} */ + /*===========================================================================*/ -/* Subsystem options. */ +/** + * @name Subsystem options + * @{ + */ /*===========================================================================*/ /** @@ -346,10 +344,26 @@ #define CH_USE_DYNAMIC TRUE #endif +/** @} */ + /*===========================================================================*/ -/* Debug options. */ +/** + * @name Debug options + * @{ + */ /*===========================================================================*/ +/** + * @brief Debug option, system state check. + * @details If enabled the correct call protocol for system APIs is checked + * at runtime. + * + * @note The default is @p FALSE. + */ +#if !defined(CH_DBG_SYSTEM_STATE_CHECK) || defined(__DOXYGEN__) +#define CH_DBG_SYSTEM_STATE_CHECK FALSE +#endif + /** * @brief Debug option, parameters checks. * @details If enabled then the checks on the API functions input @@ -423,8 +437,13 @@ #define CH_DBG_THREADS_PROFILING TRUE #endif +/** @} */ + /*===========================================================================*/ -/* Kernel hooks. */ +/** + * @name Kernel hooks + * @{ + */ /*===========================================================================*/ /** @@ -495,6 +514,8 @@ } #endif +/** @} */ + /*===========================================================================*/ /* Port-specific settings (override port settings defaulted in chcore.h). */ /*===========================================================================*/ -- cgit v1.2.3 From 43752ee8d132fc57028a9ff15156c5bfcd81c013 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 12 Aug 2011 11:10:19 +0000 Subject: Extended state check to all kernel I-class and s-class APIs, corrected some test cases where call protocol rules were not strictly observerd. No the whole test suite pass with the state checker enabled. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3223 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- test/test.h | 16 ++++++++++++++++ test/testbmk.c | 2 ++ test/testmbox.c | 34 ++++++++++++++++++++++++---------- test/testqueues.c | 52 ++++++++++++++++++++++++++++++++++------------------ test/testsem.c | 2 ++ 5 files changed, 78 insertions(+), 28 deletions(-) (limited to 'test') diff --git a/test/test.h b/test/test.h index 31806fddb..b1fd311e6 100644 --- a/test/test.h +++ b/test/test.h @@ -126,6 +126,22 @@ extern "C" { return; \ } +/** + * @brief Test assertion with lock. + * + * @param[in] point numeric assertion identifier + * @param[in] condition a boolean expression that must be verified to be true + * @param[in] msg failure message + */ +#define test_assert_lock(point, condition, msg) { \ + chSysLock(); \ + if (_test_assert(point, condition)) { \ + chSysUnlock(); \ + return; \ + } \ + chSysUnlock(); \ +} + /** * @brief Test sequence assertion. * diff --git a/test/testbmk.c b/test/testbmk.c index 54da81fd8..4958ddf8b 100644 --- a/test/testbmk.c +++ b/test/testbmk.c @@ -465,10 +465,12 @@ static void bmk9_execute(void) { test_wait_tick(); test_start_timer(1000); do { + chSysLock(); chIQPutI(&iq, 0); chIQPutI(&iq, 1); chIQPutI(&iq, 2); chIQPutI(&iq, 3); + chSysUnlock(); (void)chIQGet(&iq); (void)chIQGet(&iq); (void)chIQGet(&iq); diff --git a/test/testmbox.c b/test/testmbox.c index 8797536c6..86b9febb4 100644 --- a/test/testmbox.c +++ b/test/testmbox.c @@ -101,19 +101,23 @@ static void mbox1_execute(void) { */ msg1 = chMBPost(&mb1, 'X', 1); test_assert(4, msg1 == RDY_TIMEOUT, "wrong wake-up message"); + chSysLock(); msg1 = chMBPostI(&mb1, 'X'); + chSysUnlock(); test_assert(5, msg1 == RDY_TIMEOUT, "wrong wake-up message"); msg1 = chMBPostAhead(&mb1, 'X', 1); test_assert(6, msg1 == RDY_TIMEOUT, "wrong wake-up message"); + chSysLock(); msg1 = chMBPostAheadI(&mb1, 'X'); + chSysUnlock(); test_assert(7, msg1 == RDY_TIMEOUT, "wrong wake-up message"); /* * Testing final conditions. */ - test_assert(8, chMBGetFreeCountI(&mb1) == 0, "still empty"); - test_assert(9, chMBGetUsedCountI(&mb1) == MB_SIZE, "not full"); - test_assert(10, mb1.mb_rdptr == mb1.mb_wrptr, "pointers not aligned"); + test_assert_lock(8, chMBGetFreeCountI(&mb1) == 0, "still empty"); + test_assert_lock(9, chMBGetUsedCountI(&mb1) == MB_SIZE, "not full"); + test_assert_lock(10, mb1.mb_rdptr == mb1.mb_wrptr, "pointers not aligned"); /* * Testing dequeuing. @@ -140,19 +144,22 @@ static void mbox1_execute(void) { */ msg1 = chMBFetch(&mb1, &msg2, 1); test_assert(17, msg1 == RDY_TIMEOUT, "wrong wake-up message"); + chSysLock(); msg1 = chMBFetchI(&mb1, &msg2); + chSysUnlock(); test_assert(18, msg1 == RDY_TIMEOUT, "wrong wake-up message"); /* * Testing final conditions. */ - test_assert(19, chMBGetFreeCountI(&mb1) == MB_SIZE, "not empty"); - test_assert(20, chMBGetUsedCountI(&mb1) == 0, "still full"); - test_assert(21, mb1.mb_rdptr == mb1.mb_wrptr, "pointers not aligned"); + test_assert_lock(19, chMBGetFreeCountI(&mb1) == MB_SIZE, "not empty"); + test_assert_lock(20, chMBGetUsedCountI(&mb1) == 0, "still full"); + test_assert_lock(21, mb1.mb_rdptr == mb1.mb_wrptr, "pointers not aligned"); /* * Testing I-Class. */ + chSysLock() msg1 = chMBPostI(&mb1, 'A'); test_assert(22, msg1 == RDY_OK, "wrong wake-up message"); msg1 = chMBPostI(&mb1, 'B'); @@ -162,16 +169,20 @@ static void mbox1_execute(void) { msg1 = chMBPostI(&mb1, 'D'); test_assert(25, msg1 == RDY_OK, "wrong wake-up message"); msg1 = chMBPostI(&mb1, 'E'); + chSysUnlock() test_assert(26, msg1 == RDY_OK, "wrong wake-up message"); test_assert(27, mb1.mb_rdptr == mb1.mb_wrptr, "pointers not aligned"); for (i = 0; i < MB_SIZE; i++) { + chSysLock(); msg1 = chMBFetchI(&mb1, &msg2); + chSysUnlock(); test_assert(28, msg1 == RDY_OK, "wrong wake-up message"); test_emit_token(msg2); } test_assert_sequence(29, "ABCDE"); test_assert(30, mb1.mb_rdptr == mb1.mb_wrptr, "pointers not aligned"); + chSysLock(); msg1 = chMBPostAheadI(&mb1, 'E'); test_assert(31, msg1 == RDY_OK, "wrong wake-up message"); msg1 = chMBPostAheadI(&mb1, 'D'); @@ -181,10 +192,13 @@ static void mbox1_execute(void) { msg1 = chMBPostAheadI(&mb1, 'B'); test_assert(34, msg1 == RDY_OK, "wrong wake-up message"); msg1 = chMBPostAheadI(&mb1, 'A'); + chSysUnlock(); test_assert(35, msg1 == RDY_OK, "wrong wake-up message"); test_assert(36, mb1.mb_rdptr == mb1.mb_wrptr, "pointers not aligned"); for (i = 0; i < MB_SIZE; i++) { + chSysLock(); msg1 = chMBFetchI(&mb1, &msg2); + chSysUnlock(); test_assert(37, msg1 == RDY_OK, "wrong wake-up message"); test_emit_token(msg2); } @@ -199,10 +213,10 @@ static void mbox1_execute(void) { /* * Re-testing final conditions. */ - test_assert(40, chMBGetFreeCountI(&mb1) == MB_SIZE, "not empty"); - test_assert(41, chMBGetUsedCountI(&mb1) == 0, "still full"); - test_assert(42, mb1.mb_buffer == mb1.mb_wrptr, "write pointer not aligned to base"); - test_assert(43, mb1.mb_buffer == mb1.mb_rdptr, "read pointer not aligned to base"); + test_assert_lock(40, chMBGetFreeCountI(&mb1) == MB_SIZE, "not empty"); + test_assert_lock(41, chMBGetUsedCountI(&mb1) == 0, "still full"); + test_assert_lock(42, mb1.mb_buffer == mb1.mb_wrptr, "write pointer not aligned to base"); + test_assert_lock(43, mb1.mb_buffer == mb1.mb_rdptr, "read pointer not aligned to base"); } ROMCONST struct testcase testmbox1 = { diff --git a/test/testqueues.c b/test/testqueues.c index 55945761d..456598fa4 100644 --- a/test/testqueues.c +++ b/test/testqueues.c @@ -96,46 +96,54 @@ static void queues1_execute(void) { size_t n; /* Initial empty state */ - test_assert(1, chIQIsEmptyI(&iq), "not empty"); + test_assert_lock(1, chIQIsEmptyI(&iq), "not empty"); /* Queue filling */ + chSysLock(); for (i = 0; i < TEST_QUEUES_SIZE; i++) chIQPutI(&iq, 'A' + i); - test_assert(2, chIQIsFullI(&iq), "still has space"); - test_assert(3, chIQPutI(&iq, 0) == Q_FULL, "failed to report Q_FULL"); + chSysUnlock(); + test_assert_lock(2, chIQIsFullI(&iq), "still has space"); + test_assert_lock(3, chIQPutI(&iq, 0) == Q_FULL, "failed to report Q_FULL"); /* Queue emptying */ for (i = 0; i < TEST_QUEUES_SIZE; i++) test_emit_token(chIQGet(&iq)); - test_assert(4, chIQIsEmptyI(&iq), "still full"); + test_assert_lock(4, chIQIsEmptyI(&iq), "still full"); test_assert_sequence(5, "ABCD"); /* Queue filling again */ + chSysLock(); for (i = 0; i < TEST_QUEUES_SIZE; i++) chIQPutI(&iq, 'A' + i); + chSysUnlock(); /* Reading the whole thing */ n = chIQReadTimeout(&iq, wa[1], TEST_QUEUES_SIZE * 2, TIME_IMMEDIATE); test_assert(6, n == TEST_QUEUES_SIZE, "wrong returned size"); - test_assert(7, chIQIsEmptyI(&iq), "still full"); + test_assert_lock(7, chIQIsEmptyI(&iq), "still full"); /* Queue filling again */ + chSysLock(); for (i = 0; i < TEST_QUEUES_SIZE; i++) chIQPutI(&iq, 'A' + i); + chSysUnlock(); /* Partial reads */ n = chIQReadTimeout(&iq, wa[1], TEST_QUEUES_SIZE / 2, TIME_IMMEDIATE); test_assert(8, n == TEST_QUEUES_SIZE / 2, "wrong returned size"); n = chIQReadTimeout(&iq, wa[1], TEST_QUEUES_SIZE / 2, TIME_IMMEDIATE); test_assert(9, n == TEST_QUEUES_SIZE / 2, "wrong returned size"); - test_assert(10, chIQIsEmptyI(&iq), "still full"); + test_assert_lock(10, chIQIsEmptyI(&iq), "still full"); /* Testing reset */ + chSysLock(); chIQPutI(&iq, 0); chIQResetI(&iq); - test_assert(11, chIQGetFullI(&iq) == 0, "still full"); + chSysUnlock(); + test_assert_lock(11, chIQGetFullI(&iq) == 0, "still full"); threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriority()+1, thread1, NULL); - test_assert(12, chIQGetFullI(&iq) == 0, "not empty"); + test_assert_lock(12, chIQGetFullI(&iq) == 0, "not empty"); test_wait_threads(); /* Timeout */ @@ -175,38 +183,46 @@ static void queues2_execute(void) { size_t n; /* Initial empty state */ - test_assert(1, chOQIsEmptyI(&oq), "not empty"); + test_assert_lock(1, chOQIsEmptyI(&oq), "not empty"); /* Queue filling */ for (i = 0; i < TEST_QUEUES_SIZE; i++) chOQPut(&oq, 'A' + i); - test_assert(2, chOQIsFullI(&oq), "still has space"); + test_assert_lock(2, chOQIsFullI(&oq), "still has space"); /* Queue emptying */ - for (i = 0; i < TEST_QUEUES_SIZE; i++) - test_emit_token(chOQGetI(&oq)); - test_assert(3, chOQIsEmptyI(&oq), "still full"); + for (i = 0; i < TEST_QUEUES_SIZE; i++) { + char c; + + chSysLock(); + c = chOQGetI(&oq); + chSysUnlock(); + test_emit_token(c); + } + test_assert_lock(3, chOQIsEmptyI(&oq), "still full"); test_assert_sequence(4, "ABCD"); - test_assert(5, chOQGetI(&oq) == Q_EMPTY, "failed to report Q_EMPTY"); + test_assert_lock(5, chOQGetI(&oq) == Q_EMPTY, "failed to report Q_EMPTY"); /* Writing the whole thing */ n = chOQWriteTimeout(&oq, wa[1], TEST_QUEUES_SIZE * 2, TIME_IMMEDIATE); test_assert(6, n == TEST_QUEUES_SIZE, "wrong returned size"); - test_assert(7, chOQIsFullI(&oq), "not full"); + test_assert_lock(7, chOQIsFullI(&oq), "not full"); threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriority()+1, thread2, NULL); - test_assert(8, chOQGetFullI(&oq) == TEST_QUEUES_SIZE, "not empty"); + test_assert_lock(8, chOQGetFullI(&oq) == TEST_QUEUES_SIZE, "not empty"); test_wait_threads(); /* Testing reset */ + chSysLock(); chOQResetI(&oq); - test_assert(9, chOQGetFullI(&oq) == 0, "still full"); + chSysUnlock(); + test_assert_lock(9, chOQGetFullI(&oq) == 0, "still full"); /* Partial writes */ n = chOQWriteTimeout(&oq, wa[1], TEST_QUEUES_SIZE / 2, TIME_IMMEDIATE); test_assert(10, n == TEST_QUEUES_SIZE / 2, "wrong returned size"); n = chOQWriteTimeout(&oq, wa[1], TEST_QUEUES_SIZE / 2, TIME_IMMEDIATE); test_assert(11, n == TEST_QUEUES_SIZE / 2, "wrong returned size"); - test_assert(12, chOQIsFullI(&oq), "not full"); + test_assert_lock(12, chOQIsFullI(&oq), "not full"); /* Timeout */ test_assert(13, chOQPutTimeout(&oq, 0, 10) == Q_TIMEOUT, "wrong timeout return"); diff --git a/test/testsem.c b/test/testsem.c index 6a6a622ef..d5c9072a7 100644 --- a/test/testsem.c +++ b/test/testsem.c @@ -104,7 +104,9 @@ static void sem1_execute(void) { test_assert_sequence(1, "ABCDE"); #endif threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriority()+5, thread1, "A"); + chSysLock(); chSemAddCounterI(&sem1, 2); + chSysUnlock(); test_wait_threads(); test_assert(2, chSemGetCounterI(&sem1) == 1, "invalid counter"); } -- cgit v1.2.3 From 5cee2c08d787d1b14c62d5595b72644a773fe443 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 13 Aug 2011 15:40:57 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3226 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- test/coverage/chconf.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'test') diff --git a/test/coverage/chconf.h b/test/coverage/chconf.h index d3bc3b430..0859452de 100644 --- a/test/coverage/chconf.h +++ b/test/coverage/chconf.h @@ -482,6 +482,16 @@ } #endif +/** + * @brief Context switch hook. + * @details This hook is invoked just before switching between threads. + */ +#if !defined(THREAD_CONTEXT_SWITCH_HOOK) || defined(__DOXYGEN__) +#define THREAD_CONTEXT_SWITCH_HOOK(ntp, otp) { \ + /* System halt code here.*/ \ +} +#endif + /** * @brief Idle Loop hook. * @details This hook is continuously invoked by the idle thread loop. @@ -503,6 +513,7 @@ } #endif + /** * @brief System halt hook. * @details This hook is invoked in case to a system halting error before -- cgit v1.2.3