From 4b6e936c8a66da4fc25f35914b0e9b9e66a31359 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Thu, 17 Mar 2016 10:00:40 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@9129 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/nil/include/ch.h | 27 +++++ test/nil/.cproject | 1 + test/nil/configuration.xml | 165 ++++++++++++++++++++++--------- test/nil/source/test/test_root.c | 2 + test/nil/source/test/test_root.h | 1 + test/nil/source/test/test_sequence_002.c | 30 ++++++ test/nil/source/test/test_sequence_003.c | 10 ++ test/nil/source/test/test_sequence_004.c | 119 ++++++++++++++++++++++ test/nil/source/test/test_sequence_004.h | 17 ++++ test/nil/test.mk | 3 +- 10 files changed, 328 insertions(+), 47 deletions(-) create mode 100644 test/nil/source/test/test_sequence_004.c create mode 100644 test/nil/source/test/test_sequence_004.h diff --git a/os/nil/include/ch.h b/os/nil/include/ch.h index 419822471..507128186 100644 --- a/os/nil/include/ch.h +++ b/os/nil/include/ch.h @@ -854,6 +854,33 @@ struct nil_system { #define US2RTC(freq, usec) (rtcnt_t)((((freq) + 999999UL) / 1000000UL) * (usec)) /** @} */ +/** + * @name Semaphores macros + * @{ + */ +/** + * @brief Data part of a static semaphore initializer. + * @details This macro should be used when statically initializing a semaphore + * that is part of a bigger structure. + * + * @param[in] name the name of the semaphore variable + * @param[in] n the counter initial value, this value must be + * non-negative + */ +#define _SEMAPHORE_DATA(name, n) {n} + +/** + * @brief Static semaphore initializer. + * @details Statically initialized semaphores require no explicit + * initialization using @p chSemInit(). + * + * @param[in] name the name of the semaphore variable + * @param[in] n the counter initial value, this value must be + * non-negative + */ +#define SEMAPHORE_DECL(name, n) semaphore_t name = _SEMAPHORE_DATA(name, n) +/** @} */ + /** * @name Macro Functions * @{ diff --git a/test/nil/.cproject b/test/nil/.cproject index dbe6b4f10..d3500207c 100644 --- a/test/nil/.cproject +++ b/test/nil/.cproject @@ -37,6 +37,7 @@ + diff --git a/test/nil/configuration.xml b/test/nil/configuration.xml index 55003af45..e5cc2c075 100644 --- a/test/nil/configuration.xml +++ b/test/nil/configuration.xml @@ -65,7 +65,7 @@ THD_FUNCTION(test_support, arg) { Internal Tests - Threads Functionality + Threads Functionality. This sequence tests the ChibiOS/NIL functionalities related to threading. @@ -217,7 +217,7 @@ test_assert_time_window(time + 100, Internal Tests - Semaphores + Semaphores. This sequence tests the ChibiOS/NIL functionalities related to counter semaphores. @@ -236,7 +236,7 @@ static semaphore_t sem1;]]> Wait, Signal and Reset primitives are tested. The testing thread does not trigger a state change. - + CH_CFG_USE_SEMAPHORES @@ -299,7 +299,7 @@ test_assert_lock(chSemGetCounterI(&sem1) == 2, "wrong counter value");]]>Wait, Signal and Reset primitives are tested. The testing thread triggers a state change. - + CH_CFG_USE_SEMAPHORES @@ -353,7 +353,7 @@ test_assert(MSG_RESET == msg, "wrong returned message");]]> Timeout on semaphores is tested. - + CH_CFG_USE_SEMAPHORES @@ -363,7 +363,7 @@ test_assert(MSG_RESET == msg, "wrong returned message");]]> - @@ -376,12 +376,12 @@ msg_t msg;]]> - @@ -393,12 +393,12 @@ test_assert(MSG_TIMEOUT == msg, "wrong timeout message");]]> - @@ -438,7 +438,7 @@ test_assert(MSG_TIMEOUT == msg, "wrong timeout message");]]> - @@ -451,10 +451,10 @@ msg_t msg;]]> - @@ -466,14 +466,14 @@ test_assert(MSG_OK == msg,"wrong returned message");]]> - @@ -487,7 +487,7 @@ test_assert(MSG_TIMEOUT == msg, "wrong returned message");]]> Event flags functionality is tested. - + CH_CFG_USE_EVENTS @@ -497,7 +497,7 @@ test_assert(MSG_TIMEOUT == msg, "wrong returned message");]]> - @@ -510,10 +510,10 @@ eventmask_t events;]]> - @@ -525,10 +525,10 @@ test_assert((eventmask_t)0x55 == events, "wrong events mask");]]> - epmask = 0; -events = chEvtWaitAnyTimeout(ALL_EVENTS, MS2ST(1000)); -test_assert((eventmask_t)0 != events, "timed out"); + epmask = 0; +events = chEvtWaitAnyTimeout(ALL_EVENTS, MS2ST(1000)); +test_assert((eventmask_t)0 != events, "timed out"); test_assert((eventmask_t)0x55 == events, "wrong events mask");]]> @@ -540,11 +540,11 @@ test_assert((eventmask_t)0x55 == events, "wrong events mask");]]> - @@ -552,6 +552,79 @@ test_assert((eventmask_t)0 == events, "wrong events mask");]]> + + + Internal Tests + + + Mailboxes. + + + This sequence tests the ChibiOS/NIL functionalities related to mailboxes. + + + + + + + + Mailbox non-blocking tests. + + + The mailbox API is tested without triggering blocking conditions. + + + CH_CFG_USE_MAILBOXES + + + + + + + + + + + + + + + + Testing the mailbox size. + + + + + + + + + + + Testing forward and backward queuing, checking for no errors. + + + + + + + + + + + + diff --git a/test/nil/source/test/test_root.c b/test/nil/source/test/test_root.c index 23306dba6..1d42a6d44 100644 --- a/test/nil/source/test/test_root.c +++ b/test/nil/source/test/test_root.c @@ -24,6 +24,7 @@ * - @subpage test_sequence_001 * - @subpage test_sequence_002 * - @subpage test_sequence_003 + * - @subpage test_sequence_004 * . */ @@ -50,6 +51,7 @@ const testcase_t * const *test_suite[] = { test_sequence_001, test_sequence_002, test_sequence_003, + test_sequence_004, NULL }; diff --git a/test/nil/source/test/test_root.h b/test/nil/source/test/test_root.h index aade0f83d..10daddeef 100644 --- a/test/nil/source/test/test_root.h +++ b/test/nil/source/test/test_root.h @@ -28,6 +28,7 @@ #include "test_sequence_001.h" #include "test_sequence_002.h" #include "test_sequence_003.h" +#include "test_sequence_004.h" /*===========================================================================*/ /* External declarations. */ diff --git a/test/nil/source/test/test_sequence_002.c b/test/nil/source/test/test_sequence_002.c index 94c530125..bd626683b 100644 --- a/test/nil/source/test/test_sequence_002.c +++ b/test/nil/source/test/test_sequence_002.c @@ -46,6 +46,7 @@ static semaphore_t sem1; * Test cases. ****************************************************************************/ +#if CH_CFG_USE_SEMAPHORES || defined(__DOXYGEN__) /** * @page test_002_001 Semaphore primitives, no state change * @@ -53,6 +54,12 @@ static semaphore_t sem1; * Wait, Signal and Reset primitives are tested. The testing thread * does not trigger a state change. * + *

Conditions

+ * This test is only executed if the following preprocessor condition + * evaluates to true: + * - CH_CFG_USE_SEMAPHORES + * . + * *

Test Steps

* - The function chSemWait() is invoked, after return the counter and * the returned message are tested. @@ -107,7 +114,9 @@ static const testcase_t test_002_001 = { test_002_001_teardown, test_002_001_execute }; +#endif /* CH_CFG_USE_SEMAPHORES */ +#if CH_CFG_USE_SEMAPHORES || defined(__DOXYGEN__) /** * @page test_002_002 Semaphore primitives, with state change * @@ -115,6 +124,12 @@ static const testcase_t test_002_001 = { * Wait, Signal and Reset primitives are tested. The testing thread * triggers a state change. * + *

Conditions

+ * This test is only executed if the following preprocessor condition + * evaluates to true: + * - CH_CFG_USE_SEMAPHORES + * . + * *

Test Steps

* - The function chSemWait() is invoked, after return the counter and * the returned message are tested. The semaphore is signaled by @@ -166,13 +181,21 @@ static const testcase_t test_002_002 = { test_002_002_teardown, test_002_002_execute }; +#endif /* CH_CFG_USE_SEMAPHORES */ +#if CH_CFG_USE_SEMAPHORES || defined(__DOXYGEN__) /** * @page test_002_003 Semaphores timeout * *

Description

* Timeout on semaphores is tested. * + *

Conditions

+ * This test is only executed if the following preprocessor condition + * evaluates to true: + * - CH_CFG_USE_SEMAPHORES + * . + * *

Test Steps

* - The function chSemWaitTimeout() is invoked a first time, after * return the system time, the counter and the returned message are @@ -228,6 +251,7 @@ static const testcase_t test_002_003 = { test_002_003_teardown, test_002_003_execute }; +#endif /* CH_CFG_USE_SEMAPHORES */ /**************************************************************************** * Exported data. @@ -237,8 +261,14 @@ static const testcase_t test_002_003 = { * @brief Semaphores. */ const testcase_t * const test_sequence_002[] = { +#if CH_CFG_USE_SEMAPHORES || defined(__DOXYGEN__) &test_002_001, +#endif +#if CH_CFG_USE_SEMAPHORES || defined(__DOXYGEN__) &test_002_002, +#endif +#if CH_CFG_USE_SEMAPHORES || defined(__DOXYGEN__) &test_002_003, +#endif NULL }; diff --git a/test/nil/source/test/test_sequence_003.c b/test/nil/source/test/test_sequence_003.c index 3d4e501d7..b58bd3b69 100644 --- a/test/nil/source/test/test_sequence_003.c +++ b/test/nil/source/test/test_sequence_003.c @@ -104,12 +104,19 @@ static const testcase_t test_003_001 = { test_003_001_execute }; +#if CH_CFG_USE_EVENTS || defined(__DOXYGEN__) /** * @page test_003_002 Events Flags functionality * *

Description

* Event flags functionality is tested. * + *

Conditions

+ * This test is only executed if the following preprocessor condition + * evaluates to true: + * - CH_CFG_USE_EVENTS + * . + * *

Test Steps

* - A set of event flags are set on the current thread then the * function chEvtWaitAnyTimeout() is invoked, the function is @@ -171,6 +178,7 @@ static const testcase_t test_003_002 = { NULL, test_003_002_execute }; +#endif /* CH_CFG_USE_EVENTS */ /**************************************************************************** * Exported data. @@ -181,6 +189,8 @@ static const testcase_t test_003_002 = { */ const testcase_t * const test_sequence_003[] = { &test_003_001, +#if CH_CFG_USE_EVENTS || defined(__DOXYGEN__) &test_003_002, +#endif NULL }; diff --git a/test/nil/source/test/test_sequence_004.c b/test/nil/source/test/test_sequence_004.c new file mode 100644 index 000000000..6e1f3a834 --- /dev/null +++ b/test/nil/source/test/test_sequence_004.c @@ -0,0 +1,119 @@ +/* + ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +#include "hal.h" +#include "ch_test.h" +#include "test_root.h" + +/** + * @page test_sequence_004 Mailboxes + * + * File: @ref test_sequence_004.c + * + *

Description

+ * This sequence tests the ChibiOS/NIL functionalities related to + * mailboxes. + * + *

Test Cases

+ * - @subpage test_004_001 + * . + */ + +/**************************************************************************** + * Shared code. + ****************************************************************************/ + +#define ALLOWED_DELAY MS2ST(5) +#define MB_SIZE 4 + +static msg_t mb_buffer[MB_SIZE]; +static MAILBOX_DECL(mb1, mb_buffer, MB_SIZE); + +/**************************************************************************** + * Test cases. + ****************************************************************************/ + +#if CH_CFG_USE_MAILBOXES || defined(__DOXYGEN__) +/** + * @page test_004_001 Mailbox non-blocking tests + * + *

Description

+ * The mailbox API is tested without triggering blocking conditions. + * + *

Conditions

+ * This test is only executed if the following preprocessor condition + * evaluates to true: + * - CH_CFG_USE_MAILBOXES + * . + * + *

Test Steps

+ * - Testing the mailbox size. + * - Testing forward and backward queuing, checking for no errors. + * . + */ + +static void test_004_001_setup(void) { + chMBObjectInit(&mb1, mb_buffer, MB_SIZE); +} + +static void test_004_001_teardown(void) { + chMBReset(&mb1); +} + +static void test_004_001_execute(void) { + msg_t msg1; + + /* Testing the mailbox size.*/ + test_set_step(1); + { + test_assert_lock(chMBGetFreeCountI(&mb1) == MB_SIZE, "wrong size"); + } + + /* Testing forward and backward queuing, checking for no errors.*/ + test_set_step(2); + { + unsigned i; + + for (i = 0; i < MB_SIZE - 1; i++) { + msg1 = chMBPost(&mb1, 'B' + i, TIME_INFINITE); + test_assert(msg1 == MSG_OK, "wrong wake-up message"); + } + msg1 = chMBPostAhead(&mb1, 'A', TIME_INFINITE); + test_assert(msg1 == MSG_OK, "wrong wake-up message"); + } +} + +static const testcase_t test_004_001 = { + "Mailbox non-blocking tests", + test_004_001_setup, + test_004_001_teardown, + test_004_001_execute +}; +#endif /* CH_CFG_USE_MAILBOXES */ + +/**************************************************************************** + * Exported data. + ****************************************************************************/ + +/** + * @brief Mailboxes. + */ +const testcase_t * const test_sequence_004[] = { +#if CH_CFG_USE_MAILBOXES || defined(__DOXYGEN__) + &test_004_001, +#endif + NULL +}; diff --git a/test/nil/source/test/test_sequence_004.h b/test/nil/source/test/test_sequence_004.h new file mode 100644 index 000000000..3ecaa4259 --- /dev/null +++ b/test/nil/source/test/test_sequence_004.h @@ -0,0 +1,17 @@ +/* + ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +extern const testcase_t * const test_sequence_004[]; diff --git a/test/nil/test.mk b/test/nil/test.mk index 8a221d403..2fc7b8b9e 100644 --- a/test/nil/test.mk +++ b/test/nil/test.mk @@ -3,7 +3,8 @@ TESTSRC = ${CHIBIOS}/test/lib/ch_test.c \ ${CHIBIOS}/test/nil/source/test/test_root.c \ ${CHIBIOS}/test/nil/source/test/test_sequence_001.c \ ${CHIBIOS}/test/nil/source/test/test_sequence_002.c \ - ${CHIBIOS}/test/nil/source/test/test_sequence_003.c + ${CHIBIOS}/test/nil/source/test/test_sequence_003.c \ + ${CHIBIOS}/test/nil/source/test/test_sequence_004.c # Required include directories TESTINC = ${CHIBIOS}/test/lib \ -- cgit v1.2.3