From fcae1afdb51063bedd4c0f13b08f23352eee4a26 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Thu, 17 Mar 2016 11:24:12 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@9130 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- test/nil/configuration.xml | 321 +++++++++++++++++++++++++++++-- test/nil/source/test/test_sequence_004.c | 293 +++++++++++++++++++++++++++- 2 files changed, 592 insertions(+), 22 deletions(-) (limited to 'test/nil') diff --git a/test/nil/configuration.xml b/test/nil/configuration.xml index e5cc2c075..c8dcc54cc 100644 --- a/test/nil/configuration.xml +++ b/test/nil/configuration.xml @@ -563,19 +563,19 @@ test_assert((eventmask_t)0 == events, "wrong events mask");]]> This sequence tests the ChibiOS/NIL functionalities related to mailboxes. - - Mailbox non-blocking tests. + Mailbox normal API, non-blocking tests. - The mailbox API is tested without triggering blocking conditions. + The mailbox normal API is tested without triggering blocking conditions. CH_CFG_USE_MAILBOXES @@ -588,7 +588,8 @@ static MAILBOX_DECL(mb1, mb_buffer, MB_SIZE);]]> - + @@ -605,22 +606,312 @@ static MAILBOX_DECL(mb1, mb_buffer, MB_SIZE);]]> - Testing forward and backward queuing, checking for no errors. + Resetting the mailbox, conditions are checked, no errors expected. + + + + + + + + + + + Filling the mailbox using chMBPost() and chMBPostAhead() once, no errors expected. + + + + + + + + + + + Testing intermediate conditions. Data pointers must be aligned, semaphore counters are checked. + + + + + + + + + + + Emptying the mailbox using chMBFetch(), no errors expected. + + + + + + + + + + + Posting and then fetching one more message, no errors expected. + + + + + + + + + + + Testing final conditions. Data pointers must be aligned to buffer start, semaphore counters are checked. + + + + + + + + + + + + + Mailbox I-Class API, non-blocking tests. + + + The mailbox I-Class API is tested without triggering blocking conditions. + + + CH_CFG_USE_MAILBOXES + + + + + + + + + + + + + + + + Testing the mailbox size. + + + + + + + + + + + Resetting the mailbox, conditions are checked, no errors expected. + + + + + + + + + + + Filling the mailbox using chMBPostI() and chMBPostAheadI() once, no errors expected. - + + + Testing intermediate conditions. Data pointers must be aligned, semaphore counters are checked. + + + + + + + + + + + Emptying the mailbox using chMBFetchI(), no errors expected. + + + + + + + + + + + Posting and then fetching one more message, no errors expected. + + + + + + + + + + + Testing final conditions. Data pointers must be aligned to buffer start, semaphore counters are checked. + + + + + + + + + + + + + Mailbox timeouts. + + + The mailbox API is tested for timeouts. + + + CH_CFG_USE_MAILBOXES + + + + + + + + + + + + + + + + Filling the mailbox. + + + + + + + + + + + Testing chMBPost(), chMBPostI(), chMBPostAhead() and chMBPostAheadI() timeout. + + + + + + + + + + + Resetting the mailbox. + + + + + + + + + + + Testing chMBFetch() and chMBFetchI() timeout. + + + + + + + + diff --git a/test/nil/source/test/test_sequence_004.c b/test/nil/source/test/test_sequence_004.c index 6e1f3a834..4ee372d21 100644 --- a/test/nil/source/test/test_sequence_004.c +++ b/test/nil/source/test/test_sequence_004.c @@ -29,6 +29,8 @@ * *

Test Cases

* - @subpage test_004_001 + * - @subpage test_004_002 + * - @subpage test_004_003 * . */ @@ -48,10 +50,11 @@ static MAILBOX_DECL(mb1, mb_buffer, MB_SIZE); #if CH_CFG_USE_MAILBOXES || defined(__DOXYGEN__) /** - * @page test_004_001 Mailbox non-blocking tests + * @page test_004_001 Mailbox normal API, non-blocking tests * *

Description

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

Conditions

* This test is only executed if the following preprocessor condition @@ -61,7 +64,15 @@ static MAILBOX_DECL(mb1, mb_buffer, MB_SIZE); * *

Test Steps

* - Testing the mailbox size. - * - Testing forward and backward queuing, checking for no errors. + * - Resetting the mailbox, conditions are checked, no errors expected. + * - Filling the mailbox using chMBPost() and chMBPostAhead() once, no + * errors expected. + * - Testing intermediate conditions. Data pointers must be aligned, + * semaphore counters are checked. + * - Emptying the mailbox using chMBFetch(), no errors expected. + * - Posting and then fetching one more message, no errors expected. + * - Testing final conditions. Data pointers must be aligned to buffer + * start, semaphore counters are checked. * . */ @@ -74,7 +85,8 @@ static void test_004_001_teardown(void) { } static void test_004_001_execute(void) { - msg_t msg1; + msg_t msg1, msg2; + unsigned i; /* Testing the mailbox size.*/ test_set_step(1); @@ -82,11 +94,21 @@ static void test_004_001_execute(void) { test_assert_lock(chMBGetFreeCountI(&mb1) == MB_SIZE, "wrong size"); } - /* Testing forward and backward queuing, checking for no errors.*/ + /* Resetting the mailbox, conditions are checked, no errors + expected.*/ test_set_step(2); { - unsigned i; + chMBReset(&mb1); + test_assert_lock(chMBGetFreeCountI(&mb1) == MB_SIZE, "not empty"); + test_assert_lock(chMBGetUsedCountI(&mb1) == 0, "still full"); + test_assert_lock(mb1.buffer == mb1.wrptr, "write pointer not aligned to base"); + test_assert_lock(mb1.buffer == mb1.rdptr, "read pointer not aligned to base"); + } + /* Filling the mailbox using chMBPost() and chMBPostAhead() once, no + errors expected.*/ + test_set_step(3); + { for (i = 0; i < MB_SIZE - 1; i++) { msg1 = chMBPost(&mb1, 'B' + i, TIME_INFINITE); test_assert(msg1 == MSG_OK, "wrong wake-up message"); @@ -94,16 +116,267 @@ static void test_004_001_execute(void) { msg1 = chMBPostAhead(&mb1, 'A', TIME_INFINITE); test_assert(msg1 == MSG_OK, "wrong wake-up message"); } + + /* Testing intermediate conditions. Data pointers must be aligned, + semaphore counters are checked.*/ + test_set_step(4); + { + test_assert_lock(chMBGetFreeCountI(&mb1) == 0, "still empty"); + test_assert_lock(chMBGetUsedCountI(&mb1) == MB_SIZE, "not full"); + test_assert_lock(mb1.rdptr == mb1.wrptr, "pointers not aligned"); + } + + /* Emptying the mailbox using chMBFetch(), no errors expected.*/ + test_set_step(5); + { + for (i = 0; i < MB_SIZE; i++) { + msg1 = chMBFetch(&mb1, &msg2, TIME_INFINITE); + test_assert(msg1 == MSG_OK, "wrong wake-up message"); + test_emit_token(msg2); + } + test_assert_sequence("ABCDE", "wrong get sequence"); + } + + /* Posting and then fetching one more message, no errors expected.*/ + test_set_step(6); + { + msg1 = chMBPost(&mb1, 'B' + i, TIME_INFINITE); + test_assert(msg1 == MSG_OK, "wrong wake-up message"); + msg1 = chMBFetch(&mb1, &msg2, TIME_INFINITE); + test_assert(msg1 == MSG_OK, "wrong wake-up message"); + } + + /* Testing final conditions. Data pointers must be aligned to buffer + start, semaphore counters are checked.*/ + test_set_step(7); + { + test_assert_lock(chMBGetFreeCountI(&mb1) == 0, "still empty"); + test_assert_lock(chMBGetUsedCountI(&mb1) == MB_SIZE, "not full"); + test_assert(mb1.buffer == mb1.wrptr, "write pointer not aligned to base"); + test_assert(mb1.buffer == mb1.rdptr, "read pointer not aligned to base"); + } } static const testcase_t test_004_001 = { - "Mailbox non-blocking tests", + "Mailbox normal API, non-blocking tests", test_004_001_setup, test_004_001_teardown, test_004_001_execute }; #endif /* CH_CFG_USE_MAILBOXES */ +#if CH_CFG_USE_MAILBOXES || defined(__DOXYGEN__) +/** + * @page test_004_002 Mailbox I-Class API, non-blocking tests + * + *

Description

+ * The mailbox I-Class 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. + * - Resetting the mailbox, conditions are checked, no errors expected. + * - Filling the mailbox using chMBPostI() and chMBPostAheadI() once, + * no errors expected. + * - Testing intermediate conditions. Data pointers must be aligned, + * semaphore counters are checked. + * - Emptying the mailbox using chMBFetchI(), no errors expected. + * - Posting and then fetching one more message, no errors expected. + * - Testing final conditions. Data pointers must be aligned to buffer + * start, semaphore counters are checked. + * . + */ + +static void test_004_002_setup(void) { + chMBObjectInit(&mb1, mb_buffer, MB_SIZE); +} + +static void test_004_002_teardown(void) { + chMBReset(&mb1); +} + +static void test_004_002_execute(void) { + msg_t msg1, msg2; + unsigned i; + + /* Testing the mailbox size.*/ + test_set_step(1); + { + test_assert_lock(chMBGetFreeCountI(&mb1) == MB_SIZE, "wrong size"); + } + + /* Resetting the mailbox, conditions are checked, no errors + expected.*/ + test_set_step(2); + { + chSysLock(); + chMBResetI(&mb1); + chSysUnlock(); + test_assert_lock(chMBGetFreeCountI(&mb1) == MB_SIZE, "not empty"); + test_assert_lock(chMBGetUsedCountI(&mb1) == 0, "still full"); + test_assert_lock(mb1.buffer == mb1.wrptr, "write pointer not aligned to base"); + test_assert_lock(mb1.buffer == mb1.rdptr, "read pointer not aligned to base"); + } + + /* Filling the mailbox using chMBPostI() and chMBPostAheadI() once, + no errors expected.*/ + test_set_step(3); + { + for (i = 0; i < MB_SIZE - 1; i++) { + chSysLock(); + msg1 = chMBPostI(&mb1, 'B' + i); + chSysUnlock(); + test_assert(msg1 == MSG_OK, "wrong wake-up message"); + } + chSysLock(); + msg1 = chMBPostAheadI(&mb1, 'A'); + chSysUnlock(); + test_assert(msg1 == MSG_OK, "wrong wake-up message"); + } + + /* Testing intermediate conditions. Data pointers must be aligned, + semaphore counters are checked.*/ + test_set_step(4); + { + test_assert_lock(chMBGetFreeCountI(&mb1) == 0, "still empty"); + test_assert_lock(chMBGetUsedCountI(&mb1) == MB_SIZE, "not full"); + test_assert_lock(mb1.rdptr == mb1.wrptr, "pointers not aligned"); + } + + /* Emptying the mailbox using chMBFetchI(), no errors expected.*/ + test_set_step(5); + { + for (i = 0; i < MB_SIZE; i++) { + chSysLock(); + msg1 = chMBFetchI(&mb1, &msg2); + chSysUnlock(); + test_assert(msg1 == MSG_OK, "wrong wake-up message"); + test_emit_token(msg2); + } + test_assert_sequence("ABCDE", "wrong get sequence"); + } + + /* Posting and then fetching one more message, no errors expected.*/ + test_set_step(6); + { + msg1 = chMBPost(&mb1, 'B' + i, TIME_INFINITE); + test_assert(msg1 == MSG_OK, "wrong wake-up message"); + msg1 = chMBFetch(&mb1, &msg2, TIME_INFINITE); + test_assert(msg1 == MSG_OK, "wrong wake-up message"); + } + + /* Testing final conditions. Data pointers must be aligned to buffer + start, semaphore counters are checked.*/ + test_set_step(7); + { + test_assert_lock(chMBGetFreeCountI(&mb1) == 0, "still empty"); + test_assert_lock(chMBGetUsedCountI(&mb1) == MB_SIZE, "not full"); + test_assert(mb1.buffer == mb1.wrptr, "write pointer not aligned to base"); + test_assert(mb1.buffer == mb1.rdptr, "read pointer not aligned to base"); + } +} + +static const testcase_t test_004_002 = { + "Mailbox I-Class API, non-blocking tests", + test_004_002_setup, + test_004_002_teardown, + test_004_002_execute +}; +#endif /* CH_CFG_USE_MAILBOXES */ + +#if CH_CFG_USE_MAILBOXES || defined(__DOXYGEN__) +/** + * @page test_004_003 Mailbox timeouts + * + *

Description

+ * The mailbox API is tested for timeouts. + * + *

Conditions

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

Test Steps

+ * - Filling the mailbox. + * - Testing chMBPost(), chMBPostI(), chMBPostAhead() and + * chMBPostAheadI() timeout. + * - Resetting the mailbox. + * - Testing chMBFetch() and chMBFetchI() timeout. + * . + */ + +static void test_004_003_setup(void) { + chMBObjectInit(&mb1, mb_buffer, MB_SIZE); +} + +static void test_004_003_teardown(void) { + chMBReset(&mb1); +} + +static void test_004_003_execute(void) { + msg_t msg1, msg2; + unsigned i; + + /* Filling the mailbox.*/ + test_set_step(1); + { + for (i = 0; i < MB_SIZE; i++) { + msg1 = chMBPost(&mb1, 'B' + i, TIME_INFINITE); + test_assert(msg1 == MSG_OK, "wrong wake-up message"); + } + } + + /* Testing chMBPost(), chMBPostI(), chMBPostAhead() and + chMBPostAheadI() timeout.*/ + test_set_step(2); + { + msg1 = chMBPost(&mb1, 'X', 1); + test_assert(msg1 == MSG_TIMEOUT, "wrong wake-up message"); + chSysLock(); + msg1 = chMBPostI(&mb1, 'X'); + chSysUnlock(); + test_assert(msg1 == MSG_TIMEOUT, "wrong wake-up message"); + msg1 = chMBPostAhead(&mb1, 'X', 1); + test_assert(msg1 == MSG_TIMEOUT, "wrong wake-up message"); + chSysLock(); + msg1 = chMBPostAheadI(&mb1, 'X'); + chSysUnlock(); + test_assert(msg1 == MSG_TIMEOUT, "wrong wake-up message"); + } + + /* Resetting the mailbox.*/ + test_set_step(3); + { + chMBReset(&mb1); + } + + /* Testing chMBFetch() and chMBFetchI() timeout.*/ + test_set_step(4); + { + msg1 = chMBFetch(&mb1, &msg2, 1); + test_assert(msg1 == MSG_TIMEOUT, "wrong wake-up message"); + chSysLock(); + msg1 = chMBFetchI(&mb1, &msg2); + chSysUnlock(); + test_assert(msg1 == MSG_TIMEOUT, "wrong wake-up message"); + } +} + +static const testcase_t test_004_003 = { + "Mailbox timeouts", + test_004_003_setup, + test_004_003_teardown, + test_004_003_execute +}; +#endif /* CH_CFG_USE_MAILBOXES */ + /**************************************************************************** * Exported data. ****************************************************************************/ @@ -114,6 +387,12 @@ static const testcase_t test_004_001 = { const testcase_t * const test_sequence_004[] = { #if CH_CFG_USE_MAILBOXES || defined(__DOXYGEN__) &test_004_001, +#endif +#if CH_CFG_USE_MAILBOXES || defined(__DOXYGEN__) + &test_004_002, +#endif +#if CH_CFG_USE_MAILBOXES || defined(__DOXYGEN__) + &test_004_003, #endif NULL }; -- cgit v1.2.3