git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@10841 35acf78f-673a-0410-8e92-d51de3d6d3f4

This commit is contained in:
Giovanni Di Sirio 2017-10-17 07:46:38 +00:00
parent a202724fea
commit ba2ff06045
26 changed files with 1556 additions and 4785 deletions

View File

@ -103,7 +103,9 @@ include $(CHIBIOS)/os/hal/osal/rt/osal.mk
include $(CHIBIOS)/os/rt/rt.mk
include $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/port_v7m.mk
# Other files (optional).
include $(CHIBIOS)/test/rt/test.mk
include $(CHIBIOS)/test/lib/test.mk
include $(CHIBIOS)/test/rt/rt_test.mk
include $(CHIBIOS)/test/oslib/oslib_test.mk
# Define linker script file here
LDSCRIPT= $(STARTUPLD)/STM32F746xG.ld

View File

@ -17,6 +17,7 @@
#include "ch.h"
#include "hal.h"
#include "rt_test_root.h"
#include "oslib_test_root.h"
/*
* This is a periodic thread that does absolutely nothing except flashing
@ -71,8 +72,10 @@ int main(void) {
* sleeping in a loop and check the button state.
*/
while (true) {
if (palReadLine(LINE_BUTTON_USER))
if (palReadLine(LINE_BUTTON_USER)) {
test_execute((BaseSequentialStream *)&SD1, &rt_test_suite);
test_execute((BaseSequentialStream *)&SD1, &oslib_test_suite);
}
chThdSleepMilliseconds(2000);
}
}

View File

@ -229,11 +229,13 @@ msg_t test_execute(BaseSequentialStream *stream, const testsuite_t *tsp) {
test_chp = stream;
test_println("");
#if defined(TEST_SUITE_NAME)
test_println("*** " TEST_SUITE_NAME);
#else
test_println("*** ChibiOS test suite");
#endif
if (tsp->name != NULL) {
test_print("*** ");
test_println(tsp->name);
}
else {
test_println("*** Test Suite");
}
test_println("***");
test_print("*** Compiled: ");
test_println(__DATE__ " - " __TIME__);

View File

@ -35,584 +35,13 @@
<value>oslib_</value>
</code_prefix>
<global_definitions>
<value><![CDATA[#define TEST_SUITE_NAME "ChibiOS OS Library Test Suite"
/*
* Allowed delay in timeout checks.
*/
#define ALLOWED_DELAY TIME_MS2I(2)
/*
* Maximum number of test threads.
*/
#define MAX_THREADS 5
/*
* Stack size of test threads.
*/
#if defined(CH_ARCHITECTURE_AVR) || defined(CH_ARCHITECTURE_MSP430)
#define THREADS_STACK_SIZE 48
#elif defined(CH_ARCHITECTURE_STM8)
#define THREADS_STACK_SIZE 64
#elif defined(CH_ARCHITECTURE_SIMIA32)
#define THREADS_STACK_SIZE 512
#else
#define THREADS_STACK_SIZE 128
#endif
/*
* Working Area size of test threads.
*/
#define WA_SIZE MEM_ALIGN_NEXT(THD_WORKING_AREA_SIZE(THREADS_STACK_SIZE), \
PORT_WORKING_AREA_ALIGN)
#define TEST_REPORT_HOOK_HEADER test_print_port_info();
extern uint8_t test_buffer[WA_SIZE * 5];
extern thread_t *threads[MAX_THREADS];
extern void * ROMCONST wa[5];
void test_print_port_info(void);
void test_terminate_threads(void);
void test_wait_threads(void);
systime_t test_wait_tick(void);]]></value>
<value />
</global_definitions>
<global_code>
<value><![CDATA[void test_print_port_info(void) {
#ifdef PORT_COMPILER_NAME
test_print("*** Compiler: ");
test_println(PORT_COMPILER_NAME);
#endif
test_print("*** Architecture: ");
test_println(PORT_ARCHITECTURE_NAME);
#ifdef PORT_CORE_VARIANT_NAME
test_print("*** Core Variant: ");
test_println(PORT_CORE_VARIANT_NAME);
#endif
#ifdef PORT_INFO
test_print("*** Port Info: ");
test_println(PORT_INFO);
#endif
}
/*
* Global test buffer holding 5 working areas.
*/
ALIGNED_VAR(PORT_WORKING_AREA_ALIGN) uint8_t test_buffer[WA_SIZE * 5];
/*
* Pointers to the spawned threads.
*/
thread_t *threads[MAX_THREADS];
/*
* Pointers to the working areas.
*/
void * ROMCONST wa[5] = {test_buffer + (WA_SIZE * 0),
test_buffer + (WA_SIZE * 1),
test_buffer + (WA_SIZE * 2),
test_buffer + (WA_SIZE * 3),
test_buffer + (WA_SIZE * 4)};
/*
* Sets a termination request in all the test-spawned threads.
*/
void test_terminate_threads(void) {
unsigned i;
for (i = 0; i < MAX_THREADS; i++)
if (threads[i])
chThdTerminate(threads[i]);
}
/*
* Waits for the completion of all the test-spawned threads.
*/
void test_wait_threads(void) {
unsigned i;
for (i = 0; i < MAX_THREADS; i++)
if (threads[i] != NULL) {
chThdWait(threads[i]);
threads[i] = NULL;
}
}
/*
* Delays execution until next system time tick.
*/
systime_t test_wait_tick(void) {
chThdSleep(1);
return chVTGetSystemTime();
}]]></value>
<value />
</global_code>
</global_data_and_code>
<sequences>
<sequence>
<type index="0">
<value>Internal Tests</value>
</type>
<brief>
<value>Binary Semaphores.</value>
</brief>
<description>
<value>This sequence tests the ChibiOS library functionalities related to binary semaphores.</value>
</description>
<condition>
<value>CH_CFG_USE_SEMAPHORES</value>
</condition>
<shared_code>
<value><![CDATA[#include "ch.h"
static semaphore_t sem1;
static THD_FUNCTION(thread1, p) {
chSemWait(&sem1);
test_emit_token(*(char *)p);
}
static THD_FUNCTION(thread2, p) {
(void)p;
chThdSleepMilliseconds(50);
chSysLock();
chSemSignalI(&sem1); /* For coverage reasons */
chSchRescheduleS();
chSysUnlock();
}
static THD_FUNCTION(thread3, p) {
(void)p;
chSemWait(&sem1);
chSemSignal(&sem1);
}
static THD_FUNCTION(thread4, p) {
chBSemSignal((binary_semaphore_t *)p);
}]]></value>
</shared_code>
<cases>
<case>
<brief>
<value>Semaphore primitives, no state change.</value>
</brief>
<description>
<value>Wait, Signal and Reset primitives are tested. The testing thread does not trigger a state change.</value>
</description>
<condition>
<value />
</condition>
<various_code>
<setup_code>
<value><![CDATA[chSemObjectInit(&sem1, 1);]]></value>
</setup_code>
<teardown_code>
<value><![CDATA[chSemReset(&sem1, 0);]]></value>
</teardown_code>
<local_variables>
<value />
</local_variables>
</various_code>
<steps>
<step>
<description>
<value>The function chSemWait() is invoked, after return the counter and the returned message are tested.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[msg_t msg;
msg = chSemWait(&sem1);
test_assert_lock(chSemGetCounterI(&sem1) == 0, "wrong counter value");
test_assert(MSG_OK == msg, "wrong returned message");]]></value>
</code>
</step>
<step>
<description>
<value>The function chSemSignal() is invoked, after return the counter is tested.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[chSemSignal(&sem1);
test_assert_lock(chSemGetCounterI(&sem1) == 1, "wrong counter value");]]></value>
</code>
</step>
<step>
<description>
<value>The function chSemReset() is invoked, after return the counter is tested.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[chSemReset(&sem1, 2);
test_assert_lock(chSemGetCounterI(&sem1) == 2, "wrong counter value");]]></value>
</code>
</step>
</steps>
</case>
<case>
<brief>
<value>Semaphore enqueuing test.</value>
</brief>
<description>
<value>Five threads with randomized priorities are enqueued to a semaphore then awakened one at time. The test expects that the threads reach their goal in FIFO order or priority order depending on the @p CH_CFG_USE_SEMAPHORES_PRIORITY configuration setting.</value>
</description>
<condition>
<value />
</condition>
<various_code>
<setup_code>
<value><![CDATA[chSemObjectInit(&sem1, 0);]]></value>
</setup_code>
<teardown_code>
<value />
</teardown_code>
<local_variables>
<value />
</local_variables>
</various_code>
<steps>
<step>
<description>
<value>Five threads are created with mixed priority levels (not increasing nor decreasing). Threads enqueue on a semaphore initialized to zero.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriorityX()+5, thread1, "A");
threads[1] = chThdCreateStatic(wa[1], WA_SIZE, chThdGetPriorityX()+1, thread1, "B");
threads[2] = chThdCreateStatic(wa[2], WA_SIZE, chThdGetPriorityX()+3, thread1, "C");
threads[3] = chThdCreateStatic(wa[3], WA_SIZE, chThdGetPriorityX()+4, thread1, "D");
threads[4] = chThdCreateStatic(wa[4], WA_SIZE, chThdGetPriorityX()+2, thread1, "E");]]></value>
</code>
</step>
<step>
<description>
<value>The semaphore is signaled 5 times. The thread activation sequence is tested.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[chSemSignal(&sem1);
chSemSignal(&sem1);
chSemSignal(&sem1);
chSemSignal(&sem1);
chSemSignal(&sem1);
test_wait_threads();
#if CH_CFG_USE_SEMAPHORES_PRIORITY
test_assert_sequence("ADCEB", "invalid sequence");
#else
test_assert_sequence("ABCDE", "invalid sequence");
#endif]]></value>
</code>
</step>
</steps>
</case>
<case>
<brief>
<value>Semaphore timeout test.</value>
</brief>
<description>
<value>The three possible semaphore waiting modes (do not wait, wait with timeout, wait without timeout) are explored. The test expects that the semaphore wait function returns the correct value in each of the above scenario and that the semaphore structure status is correct after each operation.</value>
</description>
<condition>
<value />
</condition>
<various_code>
<setup_code>
<value><![CDATA[chSemObjectInit(&sem1, 0);]]></value>
</setup_code>
<teardown_code>
<value />
</teardown_code>
<local_variables>
<value><![CDATA[unsigned i;
systime_t target_time;
msg_t msg;]]></value>
</local_variables>
</various_code>
<steps>
<step>
<description>
<value>Testing special case TIME_IMMEDIATE.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[msg = chSemWaitTimeout(&sem1, TIME_IMMEDIATE);
test_assert(msg == MSG_TIMEOUT, "wrong wake-up message");
test_assert(queue_isempty(&sem1.queue), "queue not empty");
test_assert(sem1.cnt == 0, "counter not zero");]]></value>
</code>
</step>
<step>
<description>
<value>Testing non-timeout condition.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriorityX() - 1,
thread2, 0);
msg = chSemWaitTimeout(&sem1, TIME_MS2I(500));
test_wait_threads();
test_assert(msg == MSG_OK, "wrong wake-up message");
test_assert(queue_isempty(&sem1.queue), "queue not empty");
test_assert(sem1.cnt == 0, "counter not zero");]]></value>
</code>
</step>
<step>
<description>
<value>Testing timeout condition.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[target_time = test_wait_tick() + TIME_MS2I(5 * 50);
for (i = 0; i < 5; i++) {
test_emit_token('A' + i);
msg = chSemWaitTimeout(&sem1, TIME_MS2I(50));
test_assert(msg == MSG_TIMEOUT, "wrong wake-up message");
test_assert(queue_isempty(&sem1.queue), "queue not empty");
test_assert(sem1.cnt == 0, "counter not zero");
}
test_assert_sequence("ABCDE", "invalid sequence");
test_assert_time_window(target_time, target_time + ALLOWED_DELAY,
"out of time window");]]></value>
</code>
</step>
</steps>
</case>
<case>
<brief>
<value>Testing chSemAddCounterI() functionality.</value>
</brief>
<description>
<value>The functon is tested by waking up a thread then the semaphore counter value is tested.</value>
</description>
<condition>
<value />
</condition>
<various_code>
<setup_code>
<value><![CDATA[chSemObjectInit(&sem1, 0);]]></value>
</setup_code>
<teardown_code>
<value />
</teardown_code>
<local_variables>
<value />
</local_variables>
</various_code>
<steps>
<step>
<description>
<value>A thread is created, it goes to wait on the semaphore.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriorityX()+1, thread1, "A");]]></value>
</code>
</step>
<step>
<description>
<value>The semaphore counter is increased by two, it is then tested to be one, the thread must have completed.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[chSysLock();
chSemAddCounterI(&sem1, 2);
chSchRescheduleS();
chSysUnlock();
test_wait_threads();
test_assert_lock(chSemGetCounterI(&sem1) == 1, "invalid counter");
test_assert_sequence("A", "invalid sequence");]]></value>
</code>
</step>
</steps>
</case>
<case>
<brief>
<value>Testing chSemWaitSignal() functionality.</value>
</brief>
<description>
<value>This test case explicitly addresses the @p chSemWaitSignal() function. A thread is created that performs a wait and a signal operations. The tester thread is awakened from an atomic wait/signal operation. The test expects that the semaphore wait function returns the correct value in each of the above scenario and that the semaphore structure status is correct after each operation.</value>
</description>
<condition>
<value />
</condition>
<various_code>
<setup_code>
<value><![CDATA[chSemObjectInit(&sem1, 0);]]></value>
</setup_code>
<teardown_code>
<value><![CDATA[test_wait_threads();]]></value>
</teardown_code>
<local_variables>
<value />
</local_variables>
</various_code>
<steps>
<step>
<description>
<value>An higher priority thread is created that performs non-atomical wait and signal operations on a semaphore.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriorityX()+1, thread3, 0);]]></value>
</code>
</step>
<step>
<description>
<value>The function chSemSignalWait() is invoked by specifying the same semaphore for the wait and signal phases. The counter value must be one on exit.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[chSemSignalWait(&sem1, &sem1);
test_assert(queue_isempty(&sem1.queue), "queue not empty");
test_assert(sem1.cnt == 0, "counter not zero");]]></value>
</code>
</step>
<step>
<description>
<value>The function chSemSignalWait() is invoked again by specifying the same semaphore for the wait and signal phases. The counter value must be one on exit.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[chSemSignalWait(&sem1, &sem1);
test_assert(queue_isempty(&sem1.queue), "queue not empty");
test_assert(sem1.cnt == 0, "counter not zero");]]></value>
</code>
</step>
</steps>
</case>
<case>
<brief>
<value>Testing Binary Semaphores special case.</value>
</brief>
<description>
<value>This test case tests the binary semaphores functionality. The test both checks the binary semaphore status and the expected status of the underlying counting semaphore.</value>
</description>
<condition>
<value />
</condition>
<various_code>
<setup_code>
<value />
</setup_code>
<teardown_code>
<value><![CDATA[test_wait_threads();]]></value>
</teardown_code>
<local_variables>
<value><![CDATA[binary_semaphore_t bsem;
msg_t msg;]]></value>
</local_variables>
</various_code>
<steps>
<step>
<description>
<value>Creating a binary semaphore in "taken" state, the state is checked.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[chBSemObjectInit(&bsem, true);
test_assert_lock(chBSemGetStateI(&bsem) == true, "not taken");]]></value>
</code>
</step>
<step>
<description>
<value>Resetting the binary semaphore in "taken" state, the state must not change.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[chBSemReset(&bsem, true);
test_assert_lock(chBSemGetStateI(&bsem) == true, "not taken");]]></value>
</code>
</step>
<step>
<description>
<value>Starting a signaler thread at a lower priority.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[threads[0] = chThdCreateStatic(wa[0], WA_SIZE,
chThdGetPriorityX()-1, thread4, &bsem);]]></value>
</code>
</step>
<step>
<description>
<value>Waiting for the binary semaphore to be signaled, the semaphore is expected to be taken.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[msg = chBSemWait(&bsem);
test_assert_lock(chBSemGetStateI(&bsem) == true, "not taken");
test_assert(msg == MSG_OK, "unexpected message");]]></value>
</code>
</step>
<step>
<description>
<value>Signaling the binary semaphore, checking the binary semaphore state to be "not taken" and the underlying counter semaphore counter to be one.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[chBSemSignal(&bsem);
test_assert_lock(chBSemGetStateI(&bsem) ==false, "still taken");
test_assert_lock(chSemGetCounterI(&bsem.sem) == 1, "unexpected counter");]]></value>
</code>
</step>
<step>
<description>
<value>Signaling the binary semaphore again, the internal state must not change from "not taken".</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[chBSemSignal(&bsem);
test_assert_lock(chBSemGetStateI(&bsem) == false, "taken");
test_assert_lock(chSemGetCounterI(&bsem.sem) == 1, "unexpected counter");]]></value>
</code>
</step>
</steps>
</case>
</cases>
</sequence>
<sequence>
<type index="0">
<value>Internal Tests</value>
@ -1282,7 +711,8 @@ test_assert(chPoolAlloc(&mp1) == NULL, "provider returned memory");]]></value>
<value><![CDATA[#define ALLOC_SIZE 16
#define HEAP_SIZE (ALLOC_SIZE * 8)
memory_heap_t test_heap;]]></value>
static memory_heap_t test_heap;
static uint8_t test_heap_buffer[HEAP_SIZE];]]></value>
</shared_code>
<cases>
<case>
@ -1297,7 +727,7 @@ memory_heap_t test_heap;]]></value>
</condition>
<various_code>
<setup_code>
<value><![CDATA[chHeapObjectInit(&test_heap, test_buffer, sizeof(test_buffer));]]></value>
<value><![CDATA[chHeapObjectInit(&test_heap, test_heap_buffer, sizeof(test_heap_buffer));]]></value>
</setup_code>
<teardown_code>
<value />
@ -1327,7 +757,7 @@ size_t n, sz;]]></value>
<value />
</tags>
<code>
<value><![CDATA[p1 = chHeapAlloc(&test_heap, sizeof test_buffer * 2);
<value><![CDATA[p1 = chHeapAlloc(&test_heap, sizeof test_heap_buffer * 2);
test_assert(p1 == NULL, "allocation not failed");]]></value>
</code>
</step>

View File

@ -2,8 +2,7 @@
TESTSRC += ${CHIBIOS}/test/oslib/source/test/oslib_test_root.c \
${CHIBIOS}/test/oslib/source/test/oslib_test_sequence_001.c \
${CHIBIOS}/test/oslib/source/test/oslib_test_sequence_002.c \
${CHIBIOS}/test/oslib/source/test/oslib_test_sequence_003.c \
${CHIBIOS}/test/oslib/source/test/oslib_test_sequence_004.c
${CHIBIOS}/test/oslib/source/test/oslib_test_sequence_003.c
# Required include directories
TESTINC += ${CHIBIOS}/test/oslib/source/test

View File

@ -24,7 +24,6 @@
* - @subpage oslib_test_sequence_001
* - @subpage oslib_test_sequence_002
* - @subpage oslib_test_sequence_003
* - @subpage oslib_test_sequence_004
* .
*/
@ -46,17 +45,14 @@
* @brief Array of test sequences.
*/
const testsequence_t * const oslib_test_suite_array[] = {
#if (CH_CFG_USE_SEMAPHORES) || defined(__DOXYGEN__)
#if (CH_CFG_USE_MAILBOXES) || defined(__DOXYGEN__)
&oslib_test_sequence_001,
#endif
#if (CH_CFG_USE_MAILBOXES) || defined(__DOXYGEN__)
#if (CH_CFG_USE_MEMPOOLS) || defined(__DOXYGEN__)
&oslib_test_sequence_002,
#endif
#if (CH_CFG_USE_MEMPOOLS) || defined(__DOXYGEN__)
&oslib_test_sequence_003,
#endif
#if (CH_CFG_USE_HEAP) || defined(__DOXYGEN__)
&oslib_test_sequence_004,
&oslib_test_sequence_003,
#endif
NULL
};
@ -73,74 +69,4 @@ const testsuite_t oslib_test_suite = {
/* Shared code. */
/*===========================================================================*/
void test_print_port_info(void) {
#ifdef PORT_COMPILER_NAME
test_print("*** Compiler: ");
test_println(PORT_COMPILER_NAME);
#endif
test_print("*** Architecture: ");
test_println(PORT_ARCHITECTURE_NAME);
#ifdef PORT_CORE_VARIANT_NAME
test_print("*** Core Variant: ");
test_println(PORT_CORE_VARIANT_NAME);
#endif
#ifdef PORT_INFO
test_print("*** Port Info: ");
test_println(PORT_INFO);
#endif
}
/*
* Global test buffer holding 5 working areas.
*/
ALIGNED_VAR(PORT_WORKING_AREA_ALIGN) uint8_t test_buffer[WA_SIZE * 5];
/*
* Pointers to the spawned threads.
*/
thread_t *threads[MAX_THREADS];
/*
* Pointers to the working areas.
*/
void * ROMCONST wa[5] = {test_buffer + (WA_SIZE * 0),
test_buffer + (WA_SIZE * 1),
test_buffer + (WA_SIZE * 2),
test_buffer + (WA_SIZE * 3),
test_buffer + (WA_SIZE * 4)};
/*
* Sets a termination request in all the test-spawned threads.
*/
void test_terminate_threads(void) {
unsigned i;
for (i = 0; i < MAX_THREADS; i++)
if (threads[i])
chThdTerminate(threads[i]);
}
/*
* Waits for the completion of all the test-spawned threads.
*/
void test_wait_threads(void) {
unsigned i;
for (i = 0; i < MAX_THREADS; i++)
if (threads[i] != NULL) {
chThdWait(threads[i]);
threads[i] = NULL;
}
}
/*
* Delays execution until next system time tick.
*/
systime_t test_wait_tick(void) {
chThdSleep(1);
return chVTGetSystemTime();
}
#endif /* !defined(__DOXYGEN__) */

View File

@ -27,7 +27,6 @@
#include "oslib_test_sequence_001.h"
#include "oslib_test_sequence_002.h"
#include "oslib_test_sequence_003.h"
#include "oslib_test_sequence_004.h"
#if !defined(__DOXYGEN__)
@ -48,48 +47,6 @@ extern "C" {
/* Shared definitions. */
/*===========================================================================*/
#define TEST_SUITE_NAME "ChibiOS/RT Test Suite"
/*
* Allowed delay in timeout checks.
*/
#define ALLOWED_DELAY TIME_MS2I(2)
/*
* Maximum number of test threads.
*/
#define MAX_THREADS 5
/*
* Stack size of test threads.
*/
#if defined(CH_ARCHITECTURE_AVR) || defined(CH_ARCHITECTURE_MSP430)
#define THREADS_STACK_SIZE 48
#elif defined(CH_ARCHITECTURE_STM8)
#define THREADS_STACK_SIZE 64
#elif defined(CH_ARCHITECTURE_SIMIA32)
#define THREADS_STACK_SIZE 512
#else
#define THREADS_STACK_SIZE 128
#endif
/*
* Working Area size of test threads.
*/
#define WA_SIZE MEM_ALIGN_NEXT(THD_WORKING_AREA_SIZE(THREADS_STACK_SIZE), \
PORT_WORKING_AREA_ALIGN)
#define TEST_REPORT_HOOK_HEADER test_print_port_info();
extern uint8_t test_buffer[WA_SIZE * 5];
extern thread_t *threads[MAX_THREADS];
extern void * ROMCONST wa[5];
void test_print_port_info(void);
void test_terminate_threads(void);
void test_wait_threads(void);
systime_t test_wait_tick(void);
#endif /* !defined(__DOXYGEN__) */
#endif /* OSLIB_TEST_ROOT_H */

View File

@ -21,472 +21,376 @@
* @file oslib_test_sequence_001.c
* @brief Test Sequence 001 code.
*
* @page oslib_test_sequence_001 [1] Binary Semaphores
* @page oslib_test_sequence_001 [1] Mailboxes
*
* File: @ref oslib_test_sequence_001.c
*
* <h2>Description</h2>
* This sequence tests the ChibiOS library functionalities related to
* binary semaphores.
* This sequence tests the ChibiOS libraryfunctionalities related to
* mailboxes.
*
* <h2>Conditions</h2>
* This sequence is only executed if the following preprocessor condition
* evaluates to true:
* - CH_CFG_USE_SEMAPHORES
* - CH_CFG_USE_MAILBOXES
* .
*
* <h2>Test Cases</h2>
* - @subpage oslib_test_001_001
* - @subpage oslib_test_001_002
* - @subpage oslib_test_001_003
* - @subpage oslib_test_001_004
* - @subpage oslib_test_001_005
* - @subpage oslib_test_001_006
* .
*/
#if (CH_CFG_USE_SEMAPHORES) || defined(__DOXYGEN__)
#if (CH_CFG_USE_MAILBOXES) || defined(__DOXYGEN__)
/****************************************************************************
* Shared code.
****************************************************************************/
#include "ch.h"
#define MB_SIZE 4
static semaphore_t sem1;
static THD_FUNCTION(thread1, p) {
chSemWait(&sem1);
test_emit_token(*(char *)p);
}
static THD_FUNCTION(thread2, p) {
(void)p;
chThdSleepMilliseconds(50);
chSysLock();
chSemSignalI(&sem1); /* For coverage reasons */
chSchRescheduleS();
chSysUnlock();
}
static THD_FUNCTION(thread3, p) {
(void)p;
chSemWait(&sem1);
chSemSignal(&sem1);
}
static THD_FUNCTION(thread4, p) {
chBSemSignal((binary_semaphore_t *)p);
}
static msg_t mb_buffer[MB_SIZE];
static MAILBOX_DECL(mb1, mb_buffer, MB_SIZE);
/****************************************************************************
* Test cases.
****************************************************************************/
/**
* @page oslib_test_001_001 [1.1] Semaphore primitives, no state change
* @page oslib_test_001_001 [1.1] Mailbox normal API, non-blocking tests
*
* <h2>Description</h2>
* Wait, Signal and Reset primitives are tested. The testing thread
* does not trigger a state change.
* The mailbox normal API is tested without triggering blocking
* conditions.
*
* <h2>Test Steps</h2>
* - [1.1.1] The function chSemWait() is invoked, after return the
* counter and the returned message are tested.
* - [1.1.2] The function chSemSignal() is invoked, after return the
* counter is tested.
* - [1.1.3] The function chSemReset() is invoked, after return the
* counter is tested.
* - [1.1.1] Testing the mailbox size.
* - [1.1.2] Resetting the mailbox, conditions are checked, no errors
* expected.
* - [1.1.3] Testing the behavior of API when the mailbox is in reset
* state then return in active state.
* - [1.1.4] Filling the mailbox using chMBPostTimeout() and
* chMBPostAheadTimeout() once, no errors expected.
* - [1.1.5] Testing intermediate conditions. Data pointers must be
* aligned, semaphore counters are checked.
* - [1.1.6] Emptying the mailbox using chMBFetchTimeout(), no errors
* expected.
* - [1.1.7] Posting and then fetching one more message, no errors
* expected.
* - [1.1.8] Testing final conditions. Data pointers must be aligned to
* buffer start, semaphore counters are checked.
* .
*/
static void oslib_test_001_001_setup(void) {
chSemObjectInit(&sem1, 1);
chMBObjectInit(&mb1, mb_buffer, MB_SIZE);
}
static void oslib_test_001_001_teardown(void) {
chSemReset(&sem1, 0);
chMBReset(&mb1);
}
static void oslib_test_001_001_execute(void) {
msg_t msg1, msg2;
unsigned i;
/* [1.1.1] The function chSemWait() is invoked, after return the
counter and the returned message are tested.*/
/* [1.1.1] Testing the mailbox size.*/
test_set_step(1);
{
msg_t msg;
msg = chSemWait(&sem1);
test_assert_lock(chSemGetCounterI(&sem1) == 0, "wrong counter value");
test_assert(MSG_OK == msg, "wrong returned message");
test_assert_lock(chMBGetFreeCountI(&mb1) == MB_SIZE, "wrong size");
}
/* [1.1.2] The function chSemSignal() is invoked, after return the
counter is tested.*/
/* [1.1.2] Resetting the mailbox, conditions are checked, no errors
expected.*/
test_set_step(2);
{
chSemSignal(&sem1);
test_assert_lock(chSemGetCounterI(&sem1) == 1, "wrong counter value");
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");
}
/* [1.1.3] The function chSemReset() is invoked, after return the
counter is tested.*/
/* [1.1.3] Testing the behavior of API when the mailbox is in reset
state then return in active state.*/
test_set_step(3);
{
chSemReset(&sem1, 2);
test_assert_lock(chSemGetCounterI(&sem1) == 2, "wrong counter value");
msg1 = chMBPostTimeout(&mb1, (msg_t)0, TIME_INFINITE);
test_assert(msg1 == MSG_RESET, "not in reset state");
msg1 = chMBPostAheadTimeout(&mb1, (msg_t)0, TIME_INFINITE);
test_assert(msg1 == MSG_RESET, "not in reset state");
msg1 = chMBFetchTimeout(&mb1, &msg2, TIME_INFINITE);
test_assert(msg1 == MSG_RESET, "not in reset state");
chMBResumeX(&mb1);
}
/* [1.1.4] Filling the mailbox using chMBPostTimeout() and
chMBPostAheadTimeout() once, no errors expected.*/
test_set_step(4);
{
for (i = 0; i < MB_SIZE - 1; i++) {
msg1 = chMBPostTimeout(&mb1, 'B' + i, TIME_INFINITE);
test_assert(msg1 == MSG_OK, "wrong wake-up message");
}
msg1 = chMBPostAheadTimeout(&mb1, 'A', TIME_INFINITE);
test_assert(msg1 == MSG_OK, "wrong wake-up message");
}
/* [1.1.5] Testing intermediate conditions. Data pointers must be
aligned, semaphore counters are checked.*/
test_set_step(5);
{
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");
}
/* [1.1.6] Emptying the mailbox using chMBFetchTimeout(), no errors
expected.*/
test_set_step(6);
{
for (i = 0; i < MB_SIZE; i++) {
msg1 = chMBFetchTimeout(&mb1, &msg2, TIME_INFINITE);
test_assert(msg1 == MSG_OK, "wrong wake-up message");
test_emit_token(msg2);
}
test_assert_sequence("ABCD", "wrong get sequence");
}
/* [1.1.7] Posting and then fetching one more message, no errors
expected.*/
test_set_step(7);
{
msg1 = chMBPostTimeout(&mb1, 'B' + i, TIME_INFINITE);
test_assert(msg1 == MSG_OK, "wrong wake-up message");
msg1 = chMBFetchTimeout(&mb1, &msg2, TIME_INFINITE);
test_assert(msg1 == MSG_OK, "wrong wake-up message");
}
/* [1.1.8] Testing final conditions. Data pointers must be aligned to
buffer start, semaphore counters are checked.*/
test_set_step(8);
{
test_assert_lock(chMBGetFreeCountI(&mb1) == MB_SIZE, "not empty");
test_assert_lock(chMBGetUsedCountI(&mb1) == 0, "still 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 oslib_test_001_001 = {
"Semaphore primitives, no state change",
"Mailbox normal API, non-blocking tests",
oslib_test_001_001_setup,
oslib_test_001_001_teardown,
oslib_test_001_001_execute
};
/**
* @page oslib_test_001_002 [1.2] Semaphore enqueuing test
* @page oslib_test_001_002 [1.2] Mailbox I-Class API, non-blocking tests
*
* <h2>Description</h2>
* Five threads with randomized priorities are enqueued to a semaphore
* then awakened one at time. The test expects that the threads reach
* their goal in FIFO order or priority order depending on the @p
* CH_CFG_USE_SEMAPHORES_PRIORITY configuration setting.
* The mailbox I-Class API is tested without triggering blocking
* conditions.
*
* <h2>Test Steps</h2>
* - [1.2.1] Five threads are created with mixed priority levels (not
* increasing nor decreasing). Threads enqueue on a semaphore
* initialized to zero.
* - [1.2.2] The semaphore is signaled 5 times. The thread activation
* sequence is tested.
* - [1.2.1] Testing the mailbox size.
* - [1.2.2] Resetting the mailbox, conditions are checked, no errors
* expected. The mailbox is then returned in active state.
* - [1.2.3] Filling the mailbox using chMBPostI() and chMBPostAheadI()
* once, no errors expected.
* - [1.2.4] Testing intermediate conditions. Data pointers must be
* aligned, semaphore counters are checked.
* - [1.2.5] Emptying the mailbox using chMBFetchI(), no errors
* expected.
* - [1.2.6] Posting and then fetching one more message, no errors
* expected.
* - [1.2.7] Testing final conditions. Data pointers must be aligned to
* buffer start, semaphore counters are checked.
* .
*/
static void oslib_test_001_002_setup(void) {
chSemObjectInit(&sem1, 0);
chMBObjectInit(&mb1, mb_buffer, MB_SIZE);
}
static void oslib_test_001_002_teardown(void) {
chMBReset(&mb1);
}
static void oslib_test_001_002_execute(void) {
msg_t msg1, msg2;
unsigned i;
/* [1.2.1] Five threads are created with mixed priority levels (not
increasing nor decreasing). Threads enqueue on a semaphore
initialized to zero.*/
/* [1.2.1] Testing the mailbox size.*/
test_set_step(1);
{
threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriorityX()+5, thread1, "A");
threads[1] = chThdCreateStatic(wa[1], WA_SIZE, chThdGetPriorityX()+1, thread1, "B");
threads[2] = chThdCreateStatic(wa[2], WA_SIZE, chThdGetPriorityX()+3, thread1, "C");
threads[3] = chThdCreateStatic(wa[3], WA_SIZE, chThdGetPriorityX()+4, thread1, "D");
threads[4] = chThdCreateStatic(wa[4], WA_SIZE, chThdGetPriorityX()+2, thread1, "E");
test_assert_lock(chMBGetFreeCountI(&mb1) == MB_SIZE, "wrong size");
}
/* [1.2.2] The semaphore is signaled 5 times. The thread activation
sequence is tested.*/
/* [1.2.2] Resetting the mailbox, conditions are checked, no errors
expected. The mailbox is then returned in active state.*/
test_set_step(2);
{
chSemSignal(&sem1);
chSemSignal(&sem1);
chSemSignal(&sem1);
chSemSignal(&sem1);
chSemSignal(&sem1);
test_wait_threads();
#if CH_CFG_USE_SEMAPHORES_PRIORITY
test_assert_sequence("ADCEB", "invalid sequence");
#else
test_assert_sequence("ABCDE", "invalid sequence");
#endif
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");
chMBResumeX(&mb1);
}
/* [1.2.3] 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");
}
/* [1.2.4] 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");
}
/* [1.2.5] 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("ABCD", "wrong get sequence");
}
/* [1.2.6] Posting and then fetching one more message, no errors
expected.*/
test_set_step(6);
{
msg1 = chMBPostTimeout(&mb1, 'B' + i, TIME_INFINITE);
test_assert(msg1 == MSG_OK, "wrong wake-up message");
msg1 = chMBFetchTimeout(&mb1, &msg2, TIME_INFINITE);
test_assert(msg1 == MSG_OK, "wrong wake-up message");
}
/* [1.2.7] Testing final conditions. Data pointers must be aligned to
buffer start, semaphore counters are checked.*/
test_set_step(7);
{
test_assert_lock(chMBGetFreeCountI(&mb1) == MB_SIZE, "not empty");
test_assert_lock(chMBGetUsedCountI(&mb1) == 0, "still 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 oslib_test_001_002 = {
"Semaphore enqueuing test",
"Mailbox I-Class API, non-blocking tests",
oslib_test_001_002_setup,
NULL,
oslib_test_001_002_teardown,
oslib_test_001_002_execute
};
/**
* @page oslib_test_001_003 [1.3] Semaphore timeout test
* @page oslib_test_001_003 [1.3] Mailbox timeouts
*
* <h2>Description</h2>
* The three possible semaphore waiting modes (do not wait, wait with
* timeout, wait without timeout) are explored. The test expects that
* the semaphore wait function returns the correct value in each of the
* above scenario and that the semaphore structure status is correct
* after each operation.
* The mailbox API is tested for timeouts.
*
* <h2>Test Steps</h2>
* - [1.3.1] Testing special case TIME_IMMEDIATE.
* - [1.3.2] Testing non-timeout condition.
* - [1.3.3] Testing timeout condition.
* - [1.3.1] Filling the mailbox.
* - [1.3.2] Testing chMBPostTimeout(), chMBPostI(),
* chMBPostAheadTimeout() and chMBPostAheadI() timeout.
* - [1.3.3] Resetting the mailbox. The mailbox is then returned in
* active state.
* - [1.3.4] Testing chMBFetchTimeout() and chMBFetchI() timeout.
* .
*/
static void oslib_test_001_003_setup(void) {
chSemObjectInit(&sem1, 0);
chMBObjectInit(&mb1, mb_buffer, MB_SIZE);
}
static void oslib_test_001_003_teardown(void) {
chMBReset(&mb1);
}
static void oslib_test_001_003_execute(void) {
msg_t msg1, msg2;
unsigned i;
systime_t target_time;
msg_t msg;
/* [1.3.1] Testing special case TIME_IMMEDIATE.*/
/* [1.3.1] Filling the mailbox.*/
test_set_step(1);
{
msg = chSemWaitTimeout(&sem1, TIME_IMMEDIATE);
test_assert(msg == MSG_TIMEOUT, "wrong wake-up message");
test_assert(queue_isempty(&sem1.queue), "queue not empty");
test_assert(sem1.cnt == 0, "counter not zero");
for (i = 0; i < MB_SIZE; i++) {
msg1 = chMBPostTimeout(&mb1, 'B' + i, TIME_INFINITE);
test_assert(msg1 == MSG_OK, "wrong wake-up message");
}
}
/* [1.3.2] Testing non-timeout condition.*/
/* [1.3.2] Testing chMBPostTimeout(), chMBPostI(),
chMBPostAheadTimeout() and chMBPostAheadI() timeout.*/
test_set_step(2);
{
threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriorityX() - 1,
thread2, 0);
msg = chSemWaitTimeout(&sem1, TIME_MS2I(500));
test_wait_threads();
test_assert(msg == MSG_OK, "wrong wake-up message");
test_assert(queue_isempty(&sem1.queue), "queue not empty");
test_assert(sem1.cnt == 0, "counter not zero");
msg1 = chMBPostTimeout(&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 = chMBPostAheadTimeout(&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");
}
/* [1.3.3] Testing timeout condition.*/
/* [1.3.3] Resetting the mailbox. The mailbox is then returned in
active state.*/
test_set_step(3);
{
target_time = test_wait_tick() + TIME_MS2I(5 * 50);
for (i = 0; i < 5; i++) {
test_emit_token('A' + i);
msg = chSemWaitTimeout(&sem1, TIME_MS2I(50));
test_assert(msg == MSG_TIMEOUT, "wrong wake-up message");
test_assert(queue_isempty(&sem1.queue), "queue not empty");
test_assert(sem1.cnt == 0, "counter not zero");
}
test_assert_sequence("ABCDE", "invalid sequence");
test_assert_time_window(target_time, target_time + ALLOWED_DELAY,
"out of time window");
chMBReset(&mb1);
chMBResumeX(&mb1);
}
/* [1.3.4] Testing chMBFetchTimeout() and chMBFetchI() timeout.*/
test_set_step(4);
{
msg1 = chMBFetchTimeout(&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 oslib_test_001_003 = {
"Semaphore timeout test",
"Mailbox timeouts",
oslib_test_001_003_setup,
NULL,
oslib_test_001_003_teardown,
oslib_test_001_003_execute
};
/**
* @page oslib_test_001_004 [1.4] Testing chSemAddCounterI() functionality
*
* <h2>Description</h2>
* The functon is tested by waking up a thread then the semaphore
* counter value is tested.
*
* <h2>Test Steps</h2>
* - [1.4.1] A thread is created, it goes to wait on the semaphore.
* - [1.4.2] The semaphore counter is increased by two, it is then
* tested to be one, the thread must have completed.
* .
*/
static void oslib_test_001_004_setup(void) {
chSemObjectInit(&sem1, 0);
}
static void oslib_test_001_004_execute(void) {
/* [1.4.1] A thread is created, it goes to wait on the semaphore.*/
test_set_step(1);
{
threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriorityX()+1, thread1, "A");
}
/* [1.4.2] The semaphore counter is increased by two, it is then
tested to be one, the thread must have completed.*/
test_set_step(2);
{
chSysLock();
chSemAddCounterI(&sem1, 2);
chSchRescheduleS();
chSysUnlock();
test_wait_threads();
test_assert_lock(chSemGetCounterI(&sem1) == 1, "invalid counter");
test_assert_sequence("A", "invalid sequence");
}
}
static const testcase_t oslib_test_001_004 = {
"Testing chSemAddCounterI() functionality",
oslib_test_001_004_setup,
NULL,
oslib_test_001_004_execute
};
/**
* @page oslib_test_001_005 [1.5] Testing chSemWaitSignal() functionality
*
* <h2>Description</h2>
* This test case explicitly addresses the @p chSemWaitSignal()
* function. A thread is created that performs a wait and a signal
* operations. The tester thread is awakened from an atomic wait/signal
* operation. The test expects that the semaphore wait function returns
* the correct value in each of the above scenario and that the
* semaphore structure status is correct after each operation.
*
* <h2>Test Steps</h2>
* - [1.5.1] An higher priority thread is created that performs
* non-atomical wait and signal operations on a semaphore.
* - [1.5.2] The function chSemSignalWait() is invoked by specifying
* the same semaphore for the wait and signal phases. The counter
* value must be one on exit.
* - [1.5.3] The function chSemSignalWait() is invoked again by
* specifying the same semaphore for the wait and signal phases. The
* counter value must be one on exit.
* .
*/
static void oslib_test_001_005_setup(void) {
chSemObjectInit(&sem1, 0);
}
static void oslib_test_001_005_teardown(void) {
test_wait_threads();
}
static void oslib_test_001_005_execute(void) {
/* [1.5.1] An higher priority thread is created that performs
non-atomical wait and signal operations on a semaphore.*/
test_set_step(1);
{
threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriorityX()+1, thread3, 0);
}
/* [1.5.2] The function chSemSignalWait() is invoked by specifying
the same semaphore for the wait and signal phases. The counter
value must be one on exit.*/
test_set_step(2);
{
chSemSignalWait(&sem1, &sem1);
test_assert(queue_isempty(&sem1.queue), "queue not empty");
test_assert(sem1.cnt == 0, "counter not zero");
}
/* [1.5.3] The function chSemSignalWait() is invoked again by
specifying the same semaphore for the wait and signal phases. The
counter value must be one on exit.*/
test_set_step(3);
{
chSemSignalWait(&sem1, &sem1);
test_assert(queue_isempty(&sem1.queue), "queue not empty");
test_assert(sem1.cnt == 0, "counter not zero");
}
}
static const testcase_t oslib_test_001_005 = {
"Testing chSemWaitSignal() functionality",
oslib_test_001_005_setup,
oslib_test_001_005_teardown,
oslib_test_001_005_execute
};
/**
* @page oslib_test_001_006 [1.6] Testing Binary Semaphores special case
*
* <h2>Description</h2>
* This test case tests the binary semaphores functionality. The test
* both checks the binary semaphore status and the expected status of
* the underlying counting semaphore.
*
* <h2>Test Steps</h2>
* - [1.6.1] Creating a binary semaphore in "taken" state, the state is
* checked.
* - [1.6.2] Resetting the binary semaphore in "taken" state, the state
* must not change.
* - [1.6.3] Starting a signaler thread at a lower priority.
* - [1.6.4] Waiting for the binary semaphore to be signaled, the
* semaphore is expected to be taken.
* - [1.6.5] Signaling the binary semaphore, checking the binary
* semaphore state to be "not taken" and the underlying counter
* semaphore counter to be one.
* - [1.6.6] Signaling the binary semaphore again, the internal state
* must not change from "not taken".
* .
*/
static void oslib_test_001_006_teardown(void) {
test_wait_threads();
}
static void oslib_test_001_006_execute(void) {
binary_semaphore_t bsem;
msg_t msg;
/* [1.6.1] Creating a binary semaphore in "taken" state, the state is
checked.*/
test_set_step(1);
{
chBSemObjectInit(&bsem, true);
test_assert_lock(chBSemGetStateI(&bsem) == true, "not taken");
}
/* [1.6.2] Resetting the binary semaphore in "taken" state, the state
must not change.*/
test_set_step(2);
{
chBSemReset(&bsem, true);
test_assert_lock(chBSemGetStateI(&bsem) == true, "not taken");
}
/* [1.6.3] Starting a signaler thread at a lower priority.*/
test_set_step(3);
{
threads[0] = chThdCreateStatic(wa[0], WA_SIZE,
chThdGetPriorityX()-1, thread4, &bsem);
}
/* [1.6.4] Waiting for the binary semaphore to be signaled, the
semaphore is expected to be taken.*/
test_set_step(4);
{
msg = chBSemWait(&bsem);
test_assert_lock(chBSemGetStateI(&bsem) == true, "not taken");
test_assert(msg == MSG_OK, "unexpected message");
}
/* [1.6.5] Signaling the binary semaphore, checking the binary
semaphore state to be "not taken" and the underlying counter
semaphore counter to be one.*/
test_set_step(5);
{
chBSemSignal(&bsem);
test_assert_lock(chBSemGetStateI(&bsem) ==false, "still taken");
test_assert_lock(chSemGetCounterI(&bsem.sem) == 1, "unexpected counter");
}
/* [1.6.6] Signaling the binary semaphore again, the internal state
must not change from "not taken".*/
test_set_step(6);
{
chBSemSignal(&bsem);
test_assert_lock(chBSemGetStateI(&bsem) == false, "taken");
test_assert_lock(chSemGetCounterI(&bsem.sem) == 1, "unexpected counter");
}
}
static const testcase_t oslib_test_001_006 = {
"Testing Binary Semaphores special case",
NULL,
oslib_test_001_006_teardown,
oslib_test_001_006_execute
};
/****************************************************************************
* Exported data.
****************************************************************************/
@ -498,18 +402,15 @@ const testcase_t * const oslib_test_sequence_001_array[] = {
&oslib_test_001_001,
&oslib_test_001_002,
&oslib_test_001_003,
&oslib_test_001_004,
&oslib_test_001_005,
&oslib_test_001_006,
NULL
};
/**
* @brief Binary Semaphores.
* @brief Mailboxes.
*/
const testsequence_t oslib_test_sequence_001 = {
NULL,
oslib_test_sequence_001_array
};
#endif /* CH_CFG_USE_SEMAPHORES */
#endif /* CH_CFG_USE_MAILBOXES */

View File

@ -21,18 +21,18 @@
* @file oslib_test_sequence_002.c
* @brief Test Sequence 002 code.
*
* @page oslib_test_sequence_002 [2] Mailboxes
* @page oslib_test_sequence_002 [2] Memory Pools
*
* File: @ref oslib_test_sequence_002.c
*
* <h2>Description</h2>
* This sequence tests the ChibiOS libraryfunctionalities related to
* mailboxes.
* This sequence tests the ChibiOS library functionalities related to
* memory pools.
*
* <h2>Conditions</h2>
* This sequence is only executed if the following preprocessor condition
* evaluates to true:
* - CH_CFG_USE_MAILBOXES
* - CH_CFG_USE_MEMPOOLS
* .
*
* <h2>Test Cases</h2>
@ -42,354 +42,237 @@
* .
*/
#if (CH_CFG_USE_MAILBOXES) || defined(__DOXYGEN__)
#if (CH_CFG_USE_MEMPOOLS) || defined(__DOXYGEN__)
/****************************************************************************
* Shared code.
****************************************************************************/
#define MB_SIZE 4
#define MEMORY_POOL_SIZE 4
static msg_t mb_buffer[MB_SIZE];
static MAILBOX_DECL(mb1, mb_buffer, MB_SIZE);
static uint32_t objects[MEMORY_POOL_SIZE];
static MEMORYPOOL_DECL(mp1, sizeof (uint32_t), PORT_NATURAL_ALIGN, NULL);
#if CH_CFG_USE_SEMAPHORES
static GUARDEDMEMORYPOOL_DECL(gmp1, sizeof (uint32_t), PORT_NATURAL_ALIGN);
#endif
static void *null_provider(size_t size, unsigned align) {
(void)size;
(void)align;
return NULL;
}
/****************************************************************************
* Test cases.
****************************************************************************/
/**
* @page oslib_test_002_001 [2.1] Mailbox normal API, non-blocking tests
* @page oslib_test_002_001 [2.1] Loading and emptying a memory pool
*
* <h2>Description</h2>
* The mailbox normal API is tested without triggering blocking
* conditions.
* The memory pool functionality is tested by loading and emptying it,
* all conditions are tested.
*
* <h2>Test Steps</h2>
* - [2.1.1] Testing the mailbox size.
* - [2.1.2] Resetting the mailbox, conditions are checked, no errors
* expected.
* - [2.1.3] Testing the behavior of API when the mailbox is in reset
* state then return in active state.
* - [2.1.4] Filling the mailbox using chMBPostTimeout() and
* chMBPostAheadTimeout() once, no errors expected.
* - [2.1.5] Testing intermediate conditions. Data pointers must be
* aligned, semaphore counters are checked.
* - [2.1.6] Emptying the mailbox using chMBFetchTimeout(), no errors
* expected.
* - [2.1.7] Posting and then fetching one more message, no errors
* expected.
* - [2.1.8] Testing final conditions. Data pointers must be aligned to
* buffer start, semaphore counters are checked.
* - [2.1.1] Adding the objects to the pool using chPoolLoadArray().
* - [2.1.2] Emptying the pool using chPoolAlloc().
* - [2.1.3] Now must be empty.
* - [2.1.4] Adding the objects to the pool using chPoolFree().
* - [2.1.5] Emptying the pool using chPoolAlloc() again.
* - [2.1.6] Now must be empty again.
* - [2.1.7] Covering the case where a provider is unable to return
* more memory.
* .
*/
static void oslib_test_002_001_setup(void) {
chMBObjectInit(&mb1, mb_buffer, MB_SIZE);
}
static void oslib_test_002_001_teardown(void) {
chMBReset(&mb1);
chPoolObjectInit(&mp1, sizeof (uint32_t), NULL);
}
static void oslib_test_002_001_execute(void) {
msg_t msg1, msg2;
unsigned i;
/* [2.1.1] Testing the mailbox size.*/
/* [2.1.1] Adding the objects to the pool using chPoolLoadArray().*/
test_set_step(1);
{
test_assert_lock(chMBGetFreeCountI(&mb1) == MB_SIZE, "wrong size");
chPoolLoadArray(&mp1, objects, MEMORY_POOL_SIZE);
}
/* [2.1.2] Resetting the mailbox, conditions are checked, no errors
expected.*/
/* [2.1.2] Emptying the pool using chPoolAlloc().*/
test_set_step(2);
{
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");
for (i = 0; i < MEMORY_POOL_SIZE; i++)
test_assert(chPoolAlloc(&mp1) != NULL, "list empty");
}
/* [2.1.3] Testing the behavior of API when the mailbox is in reset
state then return in active state.*/
/* [2.1.3] Now must be empty.*/
test_set_step(3);
{
msg1 = chMBPostTimeout(&mb1, (msg_t)0, TIME_INFINITE);
test_assert(msg1 == MSG_RESET, "not in reset state");
msg1 = chMBPostAheadTimeout(&mb1, (msg_t)0, TIME_INFINITE);
test_assert(msg1 == MSG_RESET, "not in reset state");
msg1 = chMBFetchTimeout(&mb1, &msg2, TIME_INFINITE);
test_assert(msg1 == MSG_RESET, "not in reset state");
chMBResumeX(&mb1);
test_assert(chPoolAlloc(&mp1) == NULL, "list not empty");
}
/* [2.1.4] Filling the mailbox using chMBPostTimeout() and
chMBPostAheadTimeout() once, no errors expected.*/
/* [2.1.4] Adding the objects to the pool using chPoolFree().*/
test_set_step(4);
{
for (i = 0; i < MB_SIZE - 1; i++) {
msg1 = chMBPostTimeout(&mb1, 'B' + i, TIME_INFINITE);
test_assert(msg1 == MSG_OK, "wrong wake-up message");
}
msg1 = chMBPostAheadTimeout(&mb1, 'A', TIME_INFINITE);
test_assert(msg1 == MSG_OK, "wrong wake-up message");
for (i = 0; i < MEMORY_POOL_SIZE; i++)
chPoolFree(&mp1, &objects[i]);
}
/* [2.1.5] Testing intermediate conditions. Data pointers must be
aligned, semaphore counters are checked.*/
/* [2.1.5] Emptying the pool using chPoolAlloc() again.*/
test_set_step(5);
{
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");
for (i = 0; i < MEMORY_POOL_SIZE; i++)
test_assert(chPoolAlloc(&mp1) != NULL, "list empty");
}
/* [2.1.6] Emptying the mailbox using chMBFetchTimeout(), no errors
expected.*/
/* [2.1.6] Now must be empty again.*/
test_set_step(6);
{
for (i = 0; i < MB_SIZE; i++) {
msg1 = chMBFetchTimeout(&mb1, &msg2, TIME_INFINITE);
test_assert(msg1 == MSG_OK, "wrong wake-up message");
test_emit_token(msg2);
}
test_assert_sequence("ABCD", "wrong get sequence");
test_assert(chPoolAlloc(&mp1) == NULL, "list not empty");
}
/* [2.1.7] Posting and then fetching one more message, no errors
expected.*/
/* [2.1.7] Covering the case where a provider is unable to return
more memory.*/
test_set_step(7);
{
msg1 = chMBPostTimeout(&mb1, 'B' + i, TIME_INFINITE);
test_assert(msg1 == MSG_OK, "wrong wake-up message");
msg1 = chMBFetchTimeout(&mb1, &msg2, TIME_INFINITE);
test_assert(msg1 == MSG_OK, "wrong wake-up message");
}
/* [2.1.8] Testing final conditions. Data pointers must be aligned to
buffer start, semaphore counters are checked.*/
test_set_step(8);
{
test_assert_lock(chMBGetFreeCountI(&mb1) == MB_SIZE, "not empty");
test_assert_lock(chMBGetUsedCountI(&mb1) == 0, "still 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");
chPoolObjectInit(&mp1, sizeof (uint32_t), null_provider);
test_assert(chPoolAlloc(&mp1) == NULL, "provider returned memory");
}
}
static const testcase_t oslib_test_002_001 = {
"Mailbox normal API, non-blocking tests",
"Loading and emptying a memory pool",
oslib_test_002_001_setup,
oslib_test_002_001_teardown,
NULL,
oslib_test_002_001_execute
};
#if (CH_CFG_USE_SEMAPHORES) || defined(__DOXYGEN__)
/**
* @page oslib_test_002_002 [2.2] Mailbox I-Class API, non-blocking tests
* @page oslib_test_002_002 [2.2] Loading and emptying a guarded memory pool without waiting
*
* <h2>Description</h2>
* The mailbox I-Class API is tested without triggering blocking
* conditions.
* The memory pool functionality is tested by loading and emptying it,
* all conditions are tested.
*
* <h2>Conditions</h2>
* This test is only executed if the following preprocessor condition
* evaluates to true:
* - CH_CFG_USE_SEMAPHORES
* .
*
* <h2>Test Steps</h2>
* - [2.2.1] Testing the mailbox size.
* - [2.2.2] Resetting the mailbox, conditions are checked, no errors
* expected. The mailbox is then returned in active state.
* - [2.2.3] Filling the mailbox using chMBPostI() and chMBPostAheadI()
* once, no errors expected.
* - [2.2.4] Testing intermediate conditions. Data pointers must be
* aligned, semaphore counters are checked.
* - [2.2.5] Emptying the mailbox using chMBFetchI(), no errors
* expected.
* - [2.2.6] Posting and then fetching one more message, no errors
* expected.
* - [2.2.7] Testing final conditions. Data pointers must be aligned to
* buffer start, semaphore counters are checked.
* - [2.2.1] Adding the objects to the pool using
* chGuardedPoolLoadArray().
* - [2.2.2] Emptying the pool using chGuardedPoolAllocTimeout().
* - [2.2.3] Now must be empty.
* - [2.2.4] Adding the objects to the pool using chGuardedPoolFree().
* - [2.2.5] Emptying the pool using chGuardedPoolAllocTimeout() again.
* - [2.2.6] Now must be empty again.
* .
*/
static void oslib_test_002_002_setup(void) {
chMBObjectInit(&mb1, mb_buffer, MB_SIZE);
}
static void oslib_test_002_002_teardown(void) {
chMBReset(&mb1);
chGuardedPoolObjectInit(&gmp1, sizeof (uint32_t));
}
static void oslib_test_002_002_execute(void) {
msg_t msg1, msg2;
unsigned i;
/* [2.2.1] Testing the mailbox size.*/
/* [2.2.1] Adding the objects to the pool using
chGuardedPoolLoadArray().*/
test_set_step(1);
{
test_assert_lock(chMBGetFreeCountI(&mb1) == MB_SIZE, "wrong size");
chGuardedPoolLoadArray(&gmp1, objects, MEMORY_POOL_SIZE);
}
/* [2.2.2] Resetting the mailbox, conditions are checked, no errors
expected. The mailbox is then returned in active state.*/
/* [2.2.2] Emptying the pool using chGuardedPoolAllocTimeout().*/
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");
chMBResumeX(&mb1);
for (i = 0; i < MEMORY_POOL_SIZE; i++)
test_assert(chGuardedPoolAllocTimeout(&gmp1, TIME_IMMEDIATE) != NULL, "list empty");
}
/* [2.2.3] Filling the mailbox using chMBPostI() and chMBPostAheadI()
once, no errors expected.*/
/* [2.2.3] Now must be empty.*/
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");
test_assert(chGuardedPoolAllocTimeout(&gmp1, TIME_IMMEDIATE) == NULL, "list not empty");
}
/* [2.2.4] Testing intermediate conditions. Data pointers must be
aligned, semaphore counters are checked.*/
/* [2.2.4] Adding the objects to the pool using
chGuardedPoolFree().*/
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");
for (i = 0; i < MEMORY_POOL_SIZE; i++)
chGuardedPoolFree(&gmp1, &objects[i]);
}
/* [2.2.5] Emptying the mailbox using chMBFetchI(), no errors
expected.*/
/* [2.2.5] Emptying the pool using chGuardedPoolAllocTimeout()
again.*/
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("ABCD", "wrong get sequence");
for (i = 0; i < MEMORY_POOL_SIZE; i++)
test_assert(chGuardedPoolAllocTimeout(&gmp1, TIME_IMMEDIATE) != NULL, "list empty");
}
/* [2.2.6] Posting and then fetching one more message, no errors
expected.*/
/* [2.2.6] Now must be empty again.*/
test_set_step(6);
{
msg1 = chMBPostTimeout(&mb1, 'B' + i, TIME_INFINITE);
test_assert(msg1 == MSG_OK, "wrong wake-up message");
msg1 = chMBFetchTimeout(&mb1, &msg2, TIME_INFINITE);
test_assert(msg1 == MSG_OK, "wrong wake-up message");
}
/* [2.2.7] Testing final conditions. Data pointers must be aligned to
buffer start, semaphore counters are checked.*/
test_set_step(7);
{
test_assert_lock(chMBGetFreeCountI(&mb1) == MB_SIZE, "not empty");
test_assert_lock(chMBGetUsedCountI(&mb1) == 0, "still 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");
test_assert(chGuardedPoolAllocTimeout(&gmp1, TIME_IMMEDIATE) == NULL, "list not empty");
}
}
static const testcase_t oslib_test_002_002 = {
"Mailbox I-Class API, non-blocking tests",
"Loading and emptying a guarded memory pool without waiting",
oslib_test_002_002_setup,
oslib_test_002_002_teardown,
NULL,
oslib_test_002_002_execute
};
#endif /* CH_CFG_USE_SEMAPHORES */
#if (CH_CFG_USE_SEMAPHORES) || defined(__DOXYGEN__)
/**
* @page oslib_test_002_003 [2.3] Mailbox timeouts
* @page oslib_test_002_003 [2.3] Guarded Memory Pools timeout
*
* <h2>Description</h2>
* The mailbox API is tested for timeouts.
* The timeout features for the Guarded Memory Pools is tested.
*
* <h2>Conditions</h2>
* This test is only executed if the following preprocessor condition
* evaluates to true:
* - CH_CFG_USE_SEMAPHORES
* .
*
* <h2>Test Steps</h2>
* - [2.3.1] Filling the mailbox.
* - [2.3.2] Testing chMBPostTimeout(), chMBPostI(),
* chMBPostAheadTimeout() and chMBPostAheadI() timeout.
* - [2.3.3] Resetting the mailbox. The mailbox is then returned in
* active state.
* - [2.3.4] Testing chMBFetchTimeout() and chMBFetchI() timeout.
* - [2.3.1] Trying to allocate with 100mS timeout, must fail because
* the pool is empty.
* .
*/
static void oslib_test_002_003_setup(void) {
chMBObjectInit(&mb1, mb_buffer, MB_SIZE);
}
static void oslib_test_002_003_teardown(void) {
chMBReset(&mb1);
chGuardedPoolObjectInit(&gmp1, sizeof (uint32_t));
}
static void oslib_test_002_003_execute(void) {
msg_t msg1, msg2;
unsigned i;
/* [2.3.1] Filling the mailbox.*/
/* [2.3.1] Trying to allocate with 100mS timeout, must fail because
the pool is empty.*/
test_set_step(1);
{
for (i = 0; i < MB_SIZE; i++) {
msg1 = chMBPostTimeout(&mb1, 'B' + i, TIME_INFINITE);
test_assert(msg1 == MSG_OK, "wrong wake-up message");
}
}
/* [2.3.2] Testing chMBPostTimeout(), chMBPostI(),
chMBPostAheadTimeout() and chMBPostAheadI() timeout.*/
test_set_step(2);
{
msg1 = chMBPostTimeout(&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 = chMBPostAheadTimeout(&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");
}
/* [2.3.3] Resetting the mailbox. The mailbox is then returned in
active state.*/
test_set_step(3);
{
chMBReset(&mb1);
chMBResumeX(&mb1);
}
/* [2.3.4] Testing chMBFetchTimeout() and chMBFetchI() timeout.*/
test_set_step(4);
{
msg1 = chMBFetchTimeout(&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");
test_assert(chGuardedPoolAllocTimeout(&gmp1, TIME_MS2I(100)) == NULL, "list not empty");
}
}
static const testcase_t oslib_test_002_003 = {
"Mailbox timeouts",
"Guarded Memory Pools timeout",
oslib_test_002_003_setup,
oslib_test_002_003_teardown,
NULL,
oslib_test_002_003_execute
};
#endif /* CH_CFG_USE_SEMAPHORES */
/****************************************************************************
* Exported data.
@ -400,17 +283,21 @@ static const testcase_t oslib_test_002_003 = {
*/
const testcase_t * const oslib_test_sequence_002_array[] = {
&oslib_test_002_001,
#if (CH_CFG_USE_SEMAPHORES) || defined(__DOXYGEN__)
&oslib_test_002_002,
#endif
#if (CH_CFG_USE_SEMAPHORES) || defined(__DOXYGEN__)
&oslib_test_002_003,
#endif
NULL
};
/**
* @brief Mailboxes.
* @brief Memory Pools.
*/
const testsequence_t oslib_test_sequence_002 = {
NULL,
oslib_test_sequence_002_array
};
#endif /* CH_CFG_USE_MAILBOXES */
#endif /* CH_CFG_USE_MEMPOOLS */

View File

@ -21,258 +21,240 @@
* @file oslib_test_sequence_003.c
* @brief Test Sequence 003 code.
*
* @page oslib_test_sequence_003 [3] Memory Pools
* @page oslib_test_sequence_003 [3] Memory Heaps
*
* File: @ref oslib_test_sequence_003.c
*
* <h2>Description</h2>
* This sequence tests the ChibiOS library functionalities related to
* memory pools.
* memory heaps.
*
* <h2>Conditions</h2>
* This sequence is only executed if the following preprocessor condition
* evaluates to true:
* - CH_CFG_USE_MEMPOOLS
* - CH_CFG_USE_HEAP
* .
*
* <h2>Test Cases</h2>
* - @subpage oslib_test_003_001
* - @subpage oslib_test_003_002
* - @subpage oslib_test_003_003
* .
*/
#if (CH_CFG_USE_MEMPOOLS) || defined(__DOXYGEN__)
#if (CH_CFG_USE_HEAP) || defined(__DOXYGEN__)
/****************************************************************************
* Shared code.
****************************************************************************/
#define MEMORY_POOL_SIZE 4
#define ALLOC_SIZE 16
#define HEAP_SIZE (ALLOC_SIZE * 8)
static uint32_t objects[MEMORY_POOL_SIZE];
static MEMORYPOOL_DECL(mp1, sizeof (uint32_t), PORT_NATURAL_ALIGN, NULL);
#if CH_CFG_USE_SEMAPHORES
static GUARDEDMEMORYPOOL_DECL(gmp1, sizeof (uint32_t), PORT_NATURAL_ALIGN);
#endif
static void *null_provider(size_t size, unsigned align) {
(void)size;
(void)align;
return NULL;
}
static memory_heap_t test_heap;
static uint8_t test_heap_buffer[HEAP_SIZE];
/****************************************************************************
* Test cases.
****************************************************************************/
/**
* @page oslib_test_003_001 [3.1] Loading and emptying a memory pool
* @page oslib_test_003_001 [3.1] Allocation and fragmentation
*
* <h2>Description</h2>
* The memory pool functionality is tested by loading and emptying it,
* all conditions are tested.
* Series of allocations/deallocations are performed in carefully
* designed sequences in order to stimulate all the possible code paths
* inside the allocator. The test expects to find the heap back to the
* initial status after each sequence.
*
* <h2>Test Steps</h2>
* - [3.1.1] Adding the objects to the pool using chPoolLoadArray().
* - [3.1.2] Emptying the pool using chPoolAlloc().
* - [3.1.3] Now must be empty.
* - [3.1.4] Adding the objects to the pool using chPoolFree().
* - [3.1.5] Emptying the pool using chPoolAlloc() again.
* - [3.1.6] Now must be empty again.
* - [3.1.7] Covering the case where a provider is unable to return
* more memory.
* - [3.1.1] Testing initial conditions, the heap must not be
* fragmented and one free block present.
* - [3.1.2] Trying to allocate an block bigger than available space,
* an error is expected.
* - [3.1.3] Single block allocation using chHeapAlloc() then the block
* is freed using chHeapFree(), must not fail.
* - [3.1.4] Using chHeapStatus() to assess the heap state. There must
* be at least one free block of sufficient size.
* - [3.1.5] Allocating then freeing in the same order.
* - [3.1.6] Allocating then freeing in reverse order.
* - [3.1.7] Small fragments handling. Checking the behavior when
* allocating blocks with size not multiple of alignment unit.
* - [3.1.8] Skipping a fragment, the first fragment in the list is too
* small so the allocator must pick the second one.
* - [3.1.9] Allocating the whole available space.
* - [3.1.10] Testing final conditions. The heap geometry must be the
* same than the one registered at beginning.
* .
*/
static void oslib_test_003_001_setup(void) {
chPoolObjectInit(&mp1, sizeof (uint32_t), NULL);
chHeapObjectInit(&test_heap, test_heap_buffer, sizeof(test_heap_buffer));
}
static void oslib_test_003_001_execute(void) {
unsigned i;
void *p1, *p2, *p3;
size_t n, sz;
/* [3.1.1] Adding the objects to the pool using chPoolLoadArray().*/
/* [3.1.1] Testing initial conditions, the heap must not be
fragmented and one free block present.*/
test_set_step(1);
{
chPoolLoadArray(&mp1, objects, MEMORY_POOL_SIZE);
test_assert(chHeapStatus(&test_heap, &sz, NULL) == 1, "heap fragmented");
}
/* [3.1.2] Emptying the pool using chPoolAlloc().*/
/* [3.1.2] Trying to allocate an block bigger than available space,
an error is expected.*/
test_set_step(2);
{
for (i = 0; i < MEMORY_POOL_SIZE; i++)
test_assert(chPoolAlloc(&mp1) != NULL, "list empty");
p1 = chHeapAlloc(&test_heap, sizeof test_heap_buffer * 2);
test_assert(p1 == NULL, "allocation not failed");
}
/* [3.1.3] Now must be empty.*/
/* [3.1.3] Single block allocation using chHeapAlloc() then the block
is freed using chHeapFree(), must not fail.*/
test_set_step(3);
{
test_assert(chPoolAlloc(&mp1) == NULL, "list not empty");
p1 = chHeapAlloc(&test_heap, ALLOC_SIZE);
test_assert(p1 != NULL, "allocation failed");
chHeapFree(p1);
}
/* [3.1.4] Adding the objects to the pool using chPoolFree().*/
/* [3.1.4] Using chHeapStatus() to assess the heap state. There must
be at least one free block of sufficient size.*/
test_set_step(4);
{
for (i = 0; i < MEMORY_POOL_SIZE; i++)
chPoolFree(&mp1, &objects[i]);
size_t total_size, largest_size;
n = chHeapStatus(&test_heap, &total_size, &largest_size);
test_assert(n == 1, "missing free block");
test_assert(total_size >= ALLOC_SIZE, "unexpected heap state");
test_assert(total_size == largest_size, "unexpected heap state");
}
/* [3.1.5] Emptying the pool using chPoolAlloc() again.*/
/* [3.1.5] Allocating then freeing in the same order.*/
test_set_step(5);
{
for (i = 0; i < MEMORY_POOL_SIZE; i++)
test_assert(chPoolAlloc(&mp1) != NULL, "list empty");
p1 = chHeapAlloc(&test_heap, ALLOC_SIZE);
p2 = chHeapAlloc(&test_heap, ALLOC_SIZE);
p3 = chHeapAlloc(&test_heap, ALLOC_SIZE);
chHeapFree(p1); /* Does not merge.*/
chHeapFree(p2); /* Merges backward.*/
chHeapFree(p3); /* Merges both sides.*/
test_assert(chHeapStatus(&test_heap, &n, NULL) == 1, "heap fragmented");
}
/* [3.1.6] Now must be empty again.*/
/* [3.1.6] Allocating then freeing in reverse order.*/
test_set_step(6);
{
test_assert(chPoolAlloc(&mp1) == NULL, "list not empty");
p1 = chHeapAlloc(&test_heap, ALLOC_SIZE);
p2 = chHeapAlloc(&test_heap, ALLOC_SIZE);
p3 = chHeapAlloc(&test_heap, ALLOC_SIZE);
chHeapFree(p3); /* Merges forward.*/
chHeapFree(p2); /* Merges forward.*/
chHeapFree(p1); /* Merges forward.*/
test_assert(chHeapStatus(&test_heap, &n, NULL) == 1, "heap fragmented");
}
/* [3.1.7] Covering the case where a provider is unable to return
more memory.*/
/* [3.1.7] Small fragments handling. Checking the behavior when
allocating blocks with size not multiple of alignment unit.*/
test_set_step(7);
{
chPoolObjectInit(&mp1, sizeof (uint32_t), null_provider);
test_assert(chPoolAlloc(&mp1) == NULL, "provider returned memory");
p1 = chHeapAlloc(&test_heap, ALLOC_SIZE + 1);
p2 = chHeapAlloc(&test_heap, ALLOC_SIZE);
chHeapFree(p1);
test_assert(chHeapStatus(&test_heap, &n, NULL) == 2, "invalid state");
p1 = chHeapAlloc(&test_heap, ALLOC_SIZE);
/* Note, the first situation happens when the alignment size is smaller
than the header size, the second in the other cases.*/
test_assert((chHeapStatus(&test_heap, &n, NULL) == 1) ||
(chHeapStatus(&test_heap, &n, NULL) == 2), "heap fragmented");
chHeapFree(p2);
chHeapFree(p1);
test_assert(chHeapStatus(&test_heap, &n, NULL) == 1, "heap fragmented");
}
/* [3.1.8] Skipping a fragment, the first fragment in the list is too
small so the allocator must pick the second one.*/
test_set_step(8);
{
p1 = chHeapAlloc(&test_heap, ALLOC_SIZE);
p2 = chHeapAlloc(&test_heap, ALLOC_SIZE);
chHeapFree(p1);
test_assert( chHeapStatus(&test_heap, &n, NULL) == 2, "invalid state");
p1 = chHeapAlloc(&test_heap, ALLOC_SIZE * 2); /* Skips first fragment.*/
chHeapFree(p1);
chHeapFree(p2);
test_assert(chHeapStatus(&test_heap, &n, NULL) == 1, "heap fragmented");
}
/* [3.1.9] Allocating the whole available space.*/
test_set_step(9);
{
(void)chHeapStatus(&test_heap, &n, NULL);
p1 = chHeapAlloc(&test_heap, n);
test_assert(p1 != NULL, "allocation failed");
test_assert(chHeapStatus(&test_heap, NULL, NULL) == 0, "not empty");
chHeapFree(p1);
}
/* [3.1.10] Testing final conditions. The heap geometry must be the
same than the one registered at beginning.*/
test_set_step(10);
{
test_assert(chHeapStatus(&test_heap, &n, NULL) == 1, "heap fragmented");
test_assert(n == sz, "size changed");
}
}
static const testcase_t oslib_test_003_001 = {
"Loading and emptying a memory pool",
"Allocation and fragmentation",
oslib_test_003_001_setup,
NULL,
oslib_test_003_001_execute
};
#if (CH_CFG_USE_SEMAPHORES) || defined(__DOXYGEN__)
/**
* @page oslib_test_003_002 [3.2] Loading and emptying a guarded memory pool without waiting
* @page oslib_test_003_002 [3.2] Default Heap
*
* <h2>Description</h2>
* The memory pool functionality is tested by loading and emptying it,
* all conditions are tested.
*
* <h2>Conditions</h2>
* This test is only executed if the following preprocessor condition
* evaluates to true:
* - CH_CFG_USE_SEMAPHORES
* .
* The default heap is pre-allocated in the system. We test base
* functionality.
*
* <h2>Test Steps</h2>
* - [3.2.1] Adding the objects to the pool using
* chGuardedPoolLoadArray().
* - [3.2.2] Emptying the pool using chGuardedPoolAllocTimeout().
* - [3.2.3] Now must be empty.
* - [3.2.4] Adding the objects to the pool using chGuardedPoolFree().
* - [3.2.5] Emptying the pool using chGuardedPoolAllocTimeout() again.
* - [3.2.6] Now must be empty again.
* - [3.2.1] Single block allocation using chHeapAlloc() then the block
* is freed using chHeapFree(), must not fail.
* - [3.2.2] Testing allocation failure.
* .
*/
static void oslib_test_003_002_setup(void) {
chGuardedPoolObjectInit(&gmp1, sizeof (uint32_t));
}
static void oslib_test_003_002_execute(void) {
unsigned i;
void *p1;
size_t total_size, largest_size;
/* [3.2.1] Adding the objects to the pool using
chGuardedPoolLoadArray().*/
/* [3.2.1] Single block allocation using chHeapAlloc() then the block
is freed using chHeapFree(), must not fail.*/
test_set_step(1);
{
chGuardedPoolLoadArray(&gmp1, objects, MEMORY_POOL_SIZE);
(void)chHeapStatus(NULL, &total_size, &largest_size);
p1 = chHeapAlloc(&test_heap, ALLOC_SIZE);
test_assert(p1 != NULL, "allocation failed");
chHeapFree(p1);
}
/* [3.2.2] Emptying the pool using chGuardedPoolAllocTimeout().*/
/* [3.2.2] Testing allocation failure.*/
test_set_step(2);
{
for (i = 0; i < MEMORY_POOL_SIZE; i++)
test_assert(chGuardedPoolAllocTimeout(&gmp1, TIME_IMMEDIATE) != NULL, "list empty");
}
/* [3.2.3] Now must be empty.*/
test_set_step(3);
{
test_assert(chGuardedPoolAllocTimeout(&gmp1, TIME_IMMEDIATE) == NULL, "list not empty");
}
/* [3.2.4] Adding the objects to the pool using
chGuardedPoolFree().*/
test_set_step(4);
{
for (i = 0; i < MEMORY_POOL_SIZE; i++)
chGuardedPoolFree(&gmp1, &objects[i]);
}
/* [3.2.5] Emptying the pool using chGuardedPoolAllocTimeout()
again.*/
test_set_step(5);
{
for (i = 0; i < MEMORY_POOL_SIZE; i++)
test_assert(chGuardedPoolAllocTimeout(&gmp1, TIME_IMMEDIATE) != NULL, "list empty");
}
/* [3.2.6] Now must be empty again.*/
test_set_step(6);
{
test_assert(chGuardedPoolAllocTimeout(&gmp1, TIME_IMMEDIATE) == NULL, "list not empty");
p1 = chHeapAlloc(NULL, (size_t)-256);
test_assert(p1 == NULL, "allocation not failed");
}
}
static const testcase_t oslib_test_003_002 = {
"Loading and emptying a guarded memory pool without waiting",
oslib_test_003_002_setup,
"Default Heap",
NULL,
NULL,
oslib_test_003_002_execute
};
#endif /* CH_CFG_USE_SEMAPHORES */
#if (CH_CFG_USE_SEMAPHORES) || defined(__DOXYGEN__)
/**
* @page oslib_test_003_003 [3.3] Guarded Memory Pools timeout
*
* <h2>Description</h2>
* The timeout features for the Guarded Memory Pools is tested.
*
* <h2>Conditions</h2>
* This test is only executed if the following preprocessor condition
* evaluates to true:
* - CH_CFG_USE_SEMAPHORES
* .
*
* <h2>Test Steps</h2>
* - [3.3.1] Trying to allocate with 100mS timeout, must fail because
* the pool is empty.
* .
*/
static void oslib_test_003_003_setup(void) {
chGuardedPoolObjectInit(&gmp1, sizeof (uint32_t));
}
static void oslib_test_003_003_execute(void) {
/* [3.3.1] Trying to allocate with 100mS timeout, must fail because
the pool is empty.*/
test_set_step(1);
{
test_assert(chGuardedPoolAllocTimeout(&gmp1, TIME_MS2I(100)) == NULL, "list not empty");
}
}
static const testcase_t oslib_test_003_003 = {
"Guarded Memory Pools timeout",
oslib_test_003_003_setup,
NULL,
oslib_test_003_003_execute
};
#endif /* CH_CFG_USE_SEMAPHORES */
/****************************************************************************
* Exported data.
@ -283,21 +265,16 @@ static const testcase_t oslib_test_003_003 = {
*/
const testcase_t * const oslib_test_sequence_003_array[] = {
&oslib_test_003_001,
#if (CH_CFG_USE_SEMAPHORES) || defined(__DOXYGEN__)
&oslib_test_003_002,
#endif
#if (CH_CFG_USE_SEMAPHORES) || defined(__DOXYGEN__)
&oslib_test_003_003,
#endif
NULL
};
/**
* @brief Memory Pools.
* @brief Memory Heaps.
*/
const testsequence_t oslib_test_sequence_003 = {
NULL,
oslib_test_sequence_003_array
};
#endif /* CH_CFG_USE_MEMPOOLS */
#endif /* CH_CFG_USE_HEAP */

View File

@ -1,279 +0,0 @@
/*
ChibiOS - Copyright (C) 2006..2017 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 "oslib_test_root.h"
/**
* @file oslib_test_sequence_004.c
* @brief Test Sequence 004 code.
*
* @page oslib_test_sequence_004 [4] Memory Heaps
*
* File: @ref oslib_test_sequence_004.c
*
* <h2>Description</h2>
* This sequence tests the ChibiOS library functionalities related to
* memory heaps.
*
* <h2>Conditions</h2>
* This sequence is only executed if the following preprocessor condition
* evaluates to true:
* - CH_CFG_USE_HEAP
* .
*
* <h2>Test Cases</h2>
* - @subpage oslib_test_004_001
* - @subpage oslib_test_004_002
* .
*/
#if (CH_CFG_USE_HEAP) || defined(__DOXYGEN__)
/****************************************************************************
* Shared code.
****************************************************************************/
#define ALLOC_SIZE 16
#define HEAP_SIZE (ALLOC_SIZE * 8)
memory_heap_t test_heap;
/****************************************************************************
* Test cases.
****************************************************************************/
/**
* @page oslib_test_004_001 [4.1] Allocation and fragmentation
*
* <h2>Description</h2>
* Series of allocations/deallocations are performed in carefully
* designed sequences in order to stimulate all the possible code paths
* inside the allocator. The test expects to find the heap back to the
* initial status after each sequence.
*
* <h2>Test Steps</h2>
* - [4.1.1] Testing initial conditions, the heap must not be
* fragmented and one free block present.
* - [4.1.2] Trying to allocate an block bigger than available space,
* an error is expected.
* - [4.1.3] Single block allocation using chHeapAlloc() then the block
* is freed using chHeapFree(), must not fail.
* - [4.1.4] Using chHeapStatus() to assess the heap state. There must
* be at least one free block of sufficient size.
* - [4.1.5] Allocating then freeing in the same order.
* - [4.1.6] Allocating then freeing in reverse order.
* - [4.1.7] Small fragments handling. Checking the behavior when
* allocating blocks with size not multiple of alignment unit.
* - [4.1.8] Skipping a fragment, the first fragment in the list is too
* small so the allocator must pick the second one.
* - [4.1.9] Allocating the whole available space.
* - [4.1.10] Testing final conditions. The heap geometry must be the
* same than the one registered at beginning.
* .
*/
static void oslib_test_004_001_setup(void) {
chHeapObjectInit(&test_heap, test_buffer, sizeof(test_buffer));
}
static void oslib_test_004_001_execute(void) {
void *p1, *p2, *p3;
size_t n, sz;
/* [4.1.1] Testing initial conditions, the heap must not be
fragmented and one free block present.*/
test_set_step(1);
{
test_assert(chHeapStatus(&test_heap, &sz, NULL) == 1, "heap fragmented");
}
/* [4.1.2] Trying to allocate an block bigger than available space,
an error is expected.*/
test_set_step(2);
{
p1 = chHeapAlloc(&test_heap, sizeof test_buffer * 2);
test_assert(p1 == NULL, "allocation not failed");
}
/* [4.1.3] Single block allocation using chHeapAlloc() then the block
is freed using chHeapFree(), must not fail.*/
test_set_step(3);
{
p1 = chHeapAlloc(&test_heap, ALLOC_SIZE);
test_assert(p1 != NULL, "allocation failed");
chHeapFree(p1);
}
/* [4.1.4] Using chHeapStatus() to assess the heap state. There must
be at least one free block of sufficient size.*/
test_set_step(4);
{
size_t total_size, largest_size;
n = chHeapStatus(&test_heap, &total_size, &largest_size);
test_assert(n == 1, "missing free block");
test_assert(total_size >= ALLOC_SIZE, "unexpected heap state");
test_assert(total_size == largest_size, "unexpected heap state");
}
/* [4.1.5] Allocating then freeing in the same order.*/
test_set_step(5);
{
p1 = chHeapAlloc(&test_heap, ALLOC_SIZE);
p2 = chHeapAlloc(&test_heap, ALLOC_SIZE);
p3 = chHeapAlloc(&test_heap, ALLOC_SIZE);
chHeapFree(p1); /* Does not merge.*/
chHeapFree(p2); /* Merges backward.*/
chHeapFree(p3); /* Merges both sides.*/
test_assert(chHeapStatus(&test_heap, &n, NULL) == 1, "heap fragmented");
}
/* [4.1.6] Allocating then freeing in reverse order.*/
test_set_step(6);
{
p1 = chHeapAlloc(&test_heap, ALLOC_SIZE);
p2 = chHeapAlloc(&test_heap, ALLOC_SIZE);
p3 = chHeapAlloc(&test_heap, ALLOC_SIZE);
chHeapFree(p3); /* Merges forward.*/
chHeapFree(p2); /* Merges forward.*/
chHeapFree(p1); /* Merges forward.*/
test_assert(chHeapStatus(&test_heap, &n, NULL) == 1, "heap fragmented");
}
/* [4.1.7] Small fragments handling. Checking the behavior when
allocating blocks with size not multiple of alignment unit.*/
test_set_step(7);
{
p1 = chHeapAlloc(&test_heap, ALLOC_SIZE + 1);
p2 = chHeapAlloc(&test_heap, ALLOC_SIZE);
chHeapFree(p1);
test_assert(chHeapStatus(&test_heap, &n, NULL) == 2, "invalid state");
p1 = chHeapAlloc(&test_heap, ALLOC_SIZE);
/* Note, the first situation happens when the alignment size is smaller
than the header size, the second in the other cases.*/
test_assert((chHeapStatus(&test_heap, &n, NULL) == 1) ||
(chHeapStatus(&test_heap, &n, NULL) == 2), "heap fragmented");
chHeapFree(p2);
chHeapFree(p1);
test_assert(chHeapStatus(&test_heap, &n, NULL) == 1, "heap fragmented");
}
/* [4.1.8] Skipping a fragment, the first fragment in the list is too
small so the allocator must pick the second one.*/
test_set_step(8);
{
p1 = chHeapAlloc(&test_heap, ALLOC_SIZE);
p2 = chHeapAlloc(&test_heap, ALLOC_SIZE);
chHeapFree(p1);
test_assert( chHeapStatus(&test_heap, &n, NULL) == 2, "invalid state");
p1 = chHeapAlloc(&test_heap, ALLOC_SIZE * 2); /* Skips first fragment.*/
chHeapFree(p1);
chHeapFree(p2);
test_assert(chHeapStatus(&test_heap, &n, NULL) == 1, "heap fragmented");
}
/* [4.1.9] Allocating the whole available space.*/
test_set_step(9);
{
(void)chHeapStatus(&test_heap, &n, NULL);
p1 = chHeapAlloc(&test_heap, n);
test_assert(p1 != NULL, "allocation failed");
test_assert(chHeapStatus(&test_heap, NULL, NULL) == 0, "not empty");
chHeapFree(p1);
}
/* [4.1.10] Testing final conditions. The heap geometry must be the
same than the one registered at beginning.*/
test_set_step(10);
{
test_assert(chHeapStatus(&test_heap, &n, NULL) == 1, "heap fragmented");
test_assert(n == sz, "size changed");
}
}
static const testcase_t oslib_test_004_001 = {
"Allocation and fragmentation",
oslib_test_004_001_setup,
NULL,
oslib_test_004_001_execute
};
/**
* @page oslib_test_004_002 [4.2] Default Heap
*
* <h2>Description</h2>
* The default heap is pre-allocated in the system. We test base
* functionality.
*
* <h2>Test Steps</h2>
* - [4.2.1] Single block allocation using chHeapAlloc() then the block
* is freed using chHeapFree(), must not fail.
* - [4.2.2] Testing allocation failure.
* .
*/
static void oslib_test_004_002_execute(void) {
void *p1;
size_t total_size, largest_size;
/* [4.2.1] Single block allocation using chHeapAlloc() then the block
is freed using chHeapFree(), must not fail.*/
test_set_step(1);
{
(void)chHeapStatus(NULL, &total_size, &largest_size);
p1 = chHeapAlloc(&test_heap, ALLOC_SIZE);
test_assert(p1 != NULL, "allocation failed");
chHeapFree(p1);
}
/* [4.2.2] Testing allocation failure.*/
test_set_step(2);
{
p1 = chHeapAlloc(NULL, (size_t)-256);
test_assert(p1 == NULL, "allocation not failed");
}
}
static const testcase_t oslib_test_004_002 = {
"Default Heap",
NULL,
NULL,
oslib_test_004_002_execute
};
/****************************************************************************
* Exported data.
****************************************************************************/
/**
* @brief Array of test cases.
*/
const testcase_t * const oslib_test_sequence_004_array[] = {
&oslib_test_004_001,
&oslib_test_004_002,
NULL
};
/**
* @brief Memory Heaps.
*/
const testsequence_t oslib_test_sequence_004 = {
NULL,
oslib_test_sequence_004_array
};
#endif /* CH_CFG_USE_HEAP */

View File

@ -1,27 +0,0 @@
/*
ChibiOS - Copyright (C) 2006..2017 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.
*/
/**
* @file oslib_test_sequence_004.h
* @brief Test Sequence 004 header.
*/
#ifndef OSLIB_TEST_SEQUENCE_004_H
#define OSLIB_TEST_SEQUENCE_004_H
extern const testsequence_t oslib_test_sequence_004;
#endif /* OSLIB_TEST_SEQUENCE_004_H */

View File

@ -35,9 +35,7 @@
<value>rt_</value>
</code_prefix>
<global_definitions>
<value><![CDATA[#define TEST_SUITE_NAME "ChibiOS/RT Test Suite"
/*
<value><![CDATA[/*
* Allowed delay in timeout checks.
*/
#define ALLOWED_DELAY TIME_MS2I(2)
@ -1058,7 +1056,7 @@ test_assert(MSG_TIMEOUT == msg, "wrong returned message");]]></value>
<value>Internal Tests</value>
</type>
<brief>
<value>Counter and Binary Semaphores.</value>
<value>Counter Semaphores.</value>
</brief>
<description>
<value>This sequence tests the ChibiOS/RT functionalities related to counter semaphores.</value>
@ -3142,909 +3140,6 @@ test_assert(!chEvtIsListeningI(&es2), "stuck listener");]]></value>
</case>
</cases>
</sequence>
<sequence>
<type index="0">
<value>Internal Tests</value>
</type>
<brief>
<value>Mailboxes.</value>
</brief>
<description>
<value>This sequence tests the ChibiOS/RT functionalities related to mailboxes.</value>
</description>
<condition>
<value>CH_CFG_USE_MAILBOXES</value>
</condition>
<shared_code>
<value><![CDATA[#define MB_SIZE 4
static msg_t mb_buffer[MB_SIZE];
static MAILBOX_DECL(mb1, mb_buffer, MB_SIZE);]]></value>
</shared_code>
<cases>
<case>
<brief>
<value>Mailbox normal API, non-blocking tests.</value>
</brief>
<description>
<value>The mailbox normal API is tested without triggering blocking conditions.</value>
</description>
<condition>
<value />
</condition>
<various_code>
<setup_code>
<value><![CDATA[chMBObjectInit(&mb1, mb_buffer, MB_SIZE);]]></value>
</setup_code>
<teardown_code>
<value><![CDATA[chMBReset(&mb1);]]></value>
</teardown_code>
<local_variables>
<value><![CDATA[msg_t msg1, msg2;
unsigned i;]]></value>
</local_variables>
</various_code>
<steps>
<step>
<description>
<value>Testing the mailbox size.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[test_assert_lock(chMBGetFreeCountI(&mb1) == MB_SIZE, "wrong size");]]></value>
</code>
</step>
<step>
<description>
<value>Resetting the mailbox, conditions are checked, no errors expected.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[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");]]></value>
</code>
</step>
<step>
<description>
<value>Testing the behavior of API when the mailbox is in reset state then return in active state.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[msg1 = chMBPostTimeout(&mb1, (msg_t)0, TIME_INFINITE);
test_assert(msg1 == MSG_RESET, "not in reset state");
msg1 = chMBPostAheadTimeout(&mb1, (msg_t)0, TIME_INFINITE);
test_assert(msg1 == MSG_RESET, "not in reset state");
msg1 = chMBFetchTimeout(&mb1, &msg2, TIME_INFINITE);
test_assert(msg1 == MSG_RESET, "not in reset state");
chMBResumeX(&mb1);]]></value>
</code>
</step>
<step>
<description>
<value>Filling the mailbox using chMBPostTimeout() and chMBPostAheadTimeout() once, no errors expected.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[for (i = 0; i < MB_SIZE - 1; i++) {
msg1 = chMBPostTimeout(&mb1, 'B' + i, TIME_INFINITE);
test_assert(msg1 == MSG_OK, "wrong wake-up message");
}
msg1 = chMBPostAheadTimeout(&mb1, 'A', TIME_INFINITE);
test_assert(msg1 == MSG_OK, "wrong wake-up message");]]></value>
</code>
</step>
<step>
<description>
<value>Testing intermediate conditions. Data pointers must be aligned, semaphore counters are checked.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[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");]]></value>
</code>
</step>
<step>
<description>
<value>Emptying the mailbox using chMBFetchTimeout(), no errors expected.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[for (i = 0; i < MB_SIZE; i++) {
msg1 = chMBFetchTimeout(&mb1, &msg2, TIME_INFINITE);
test_assert(msg1 == MSG_OK, "wrong wake-up message");
test_emit_token(msg2);
}
test_assert_sequence("ABCD", "wrong get sequence");]]></value>
</code>
</step>
<step>
<description>
<value>Posting and then fetching one more message, no errors expected.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[msg1 = chMBPostTimeout(&mb1, 'B' + i, TIME_INFINITE);
test_assert(msg1 == MSG_OK, "wrong wake-up message");
msg1 = chMBFetchTimeout(&mb1, &msg2, TIME_INFINITE);
test_assert(msg1 == MSG_OK, "wrong wake-up message");]]></value>
</code>
</step>
<step>
<description>
<value>Testing final conditions. Data pointers must be aligned to buffer start, semaphore counters are checked.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[test_assert_lock(chMBGetFreeCountI(&mb1) == MB_SIZE, "not empty");
test_assert_lock(chMBGetUsedCountI(&mb1) == 0, "still 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");]]></value>
</code>
</step>
</steps>
</case>
<case>
<brief>
<value>Mailbox I-Class API, non-blocking tests.</value>
</brief>
<description>
<value>The mailbox I-Class API is tested without triggering blocking conditions.</value>
</description>
<condition>
<value />
</condition>
<various_code>
<setup_code>
<value><![CDATA[chMBObjectInit(&mb1, mb_buffer, MB_SIZE);]]></value>
</setup_code>
<teardown_code>
<value><![CDATA[chMBReset(&mb1);]]></value>
</teardown_code>
<local_variables>
<value><![CDATA[msg_t msg1, msg2;
unsigned i;]]></value>
</local_variables>
</various_code>
<steps>
<step>
<description>
<value>Testing the mailbox size.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[test_assert_lock(chMBGetFreeCountI(&mb1) == MB_SIZE, "wrong size");]]></value>
</code>
</step>
<step>
<description>
<value>Resetting the mailbox, conditions are checked, no errors expected. The mailbox is then returned in active state.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[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");
chMBResumeX(&mb1);]]></value>
</code>
</step>
<step>
<description>
<value>Filling the mailbox using chMBPostI() and chMBPostAheadI() once, no errors expected.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[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");]]></value>
</code>
</step>
<step>
<description>
<value>Testing intermediate conditions. Data pointers must be aligned, semaphore counters are checked.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[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");]]></value>
</code>
</step>
<step>
<description>
<value>Emptying the mailbox using chMBFetchI(), no errors expected.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[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("ABCD", "wrong get sequence");]]></value>
</code>
</step>
<step>
<description>
<value>Posting and then fetching one more message, no errors expected.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[msg1 = chMBPostTimeout(&mb1, 'B' + i, TIME_INFINITE);
test_assert(msg1 == MSG_OK, "wrong wake-up message");
msg1 = chMBFetchTimeout(&mb1, &msg2, TIME_INFINITE);
test_assert(msg1 == MSG_OK, "wrong wake-up message");]]></value>
</code>
</step>
<step>
<description>
<value>Testing final conditions. Data pointers must be aligned to buffer start, semaphore counters are checked.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[test_assert_lock(chMBGetFreeCountI(&mb1) == MB_SIZE, "not empty");
test_assert_lock(chMBGetUsedCountI(&mb1) == 0, "still 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");]]></value>
</code>
</step>
</steps>
</case>
<case>
<brief>
<value>Mailbox timeouts.</value>
</brief>
<description>
<value>The mailbox API is tested for timeouts.</value>
</description>
<condition>
<value />
</condition>
<various_code>
<setup_code>
<value><![CDATA[chMBObjectInit(&mb1, mb_buffer, MB_SIZE);]]></value>
</setup_code>
<teardown_code>
<value><![CDATA[chMBReset(&mb1);]]></value>
</teardown_code>
<local_variables>
<value><![CDATA[msg_t msg1, msg2;
unsigned i;]]></value>
</local_variables>
</various_code>
<steps>
<step>
<description>
<value>Filling the mailbox.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[for (i = 0; i < MB_SIZE; i++) {
msg1 = chMBPostTimeout(&mb1, 'B' + i, TIME_INFINITE);
test_assert(msg1 == MSG_OK, "wrong wake-up message");
}]]></value>
</code>
</step>
<step>
<description>
<value>Testing chMBPostTimeout(), chMBPostI(), chMBPostAheadTimeout() and chMBPostAheadI() timeout.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[msg1 = chMBPostTimeout(&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 = chMBPostAheadTimeout(&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");]]></value>
</code>
</step>
<step>
<description>
<value>Resetting the mailbox. The mailbox is then returned in active state.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[chMBReset(&mb1);
chMBResumeX(&mb1);]]></value>
</code>
</step>
<step>
<description>
<value>Testing chMBFetchTimeout() and chMBFetchI() timeout.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[msg1 = chMBFetchTimeout(&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");]]></value>
</code>
</step>
</steps>
</case>
</cases>
</sequence>
<sequence>
<type index="0">
<value>Internal Tests</value>
</type>
<brief>
<value>Memory Pools.</value>
</brief>
<description>
<value>This sequence tests the ChibiOS/RT functionalities related to memory pools.</value>
</description>
<condition>
<value>CH_CFG_USE_MEMPOOLS</value>
</condition>
<shared_code>
<value><![CDATA[#define MEMORY_POOL_SIZE 4
static uint32_t objects[MEMORY_POOL_SIZE];
static MEMORYPOOL_DECL(mp1, sizeof (uint32_t), PORT_NATURAL_ALIGN, NULL);
#if CH_CFG_USE_SEMAPHORES
static GUARDEDMEMORYPOOL_DECL(gmp1, sizeof (uint32_t), PORT_NATURAL_ALIGN);
#endif
static void *null_provider(size_t size, unsigned align) {
(void)size;
(void)align;
return NULL;
}]]></value>
</shared_code>
<cases>
<case>
<brief>
<value>Loading and emptying a memory pool.</value>
</brief>
<description>
<value>The memory pool functionality is tested by loading and emptying it, all conditions are tested.</value>
</description>
<condition>
<value />
</condition>
<various_code>
<setup_code>
<value><![CDATA[chPoolObjectInit(&mp1, sizeof (uint32_t), NULL);]]></value>
</setup_code>
<teardown_code>
<value />
</teardown_code>
<local_variables>
<value><![CDATA[unsigned i;]]></value>
</local_variables>
</various_code>
<steps>
<step>
<description>
<value>Adding the objects to the pool using chPoolLoadArray().</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[chPoolLoadArray(&mp1, objects, MEMORY_POOL_SIZE);]]></value>
</code>
</step>
<step>
<description>
<value>Emptying the pool using chPoolAlloc().</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[for (i = 0; i < MEMORY_POOL_SIZE; i++)
test_assert(chPoolAlloc(&mp1) != NULL, "list empty");]]></value>
</code>
</step>
<step>
<description>
<value>Now must be empty.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[test_assert(chPoolAlloc(&mp1) == NULL, "list not empty");]]></value>
</code>
</step>
<step>
<description>
<value>Adding the objects to the pool using chPoolFree().</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[for (i = 0; i < MEMORY_POOL_SIZE; i++)
chPoolFree(&mp1, &objects[i]);]]></value>
</code>
</step>
<step>
<description>
<value>Emptying the pool using chPoolAlloc() again.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[for (i = 0; i < MEMORY_POOL_SIZE; i++)
test_assert(chPoolAlloc(&mp1) != NULL, "list empty");]]></value>
</code>
</step>
<step>
<description>
<value>Now must be empty again.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[test_assert(chPoolAlloc(&mp1) == NULL, "list not empty");]]></value>
</code>
</step>
<step>
<description>
<value>Covering the case where a provider is unable to return more memory.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[chPoolObjectInit(&mp1, sizeof (uint32_t), null_provider);
test_assert(chPoolAlloc(&mp1) == NULL, "provider returned memory");]]></value>
</code>
</step>
</steps>
</case>
<case>
<brief>
<value>Loading and emptying a guarded memory pool without waiting.</value>
</brief>
<description>
<value>The memory pool functionality is tested by loading and emptying it, all conditions are tested.</value>
</description>
<condition>
<value>CH_CFG_USE_SEMAPHORES</value>
</condition>
<various_code>
<setup_code>
<value><![CDATA[chGuardedPoolObjectInit(&gmp1, sizeof (uint32_t));]]></value>
</setup_code>
<teardown_code>
<value />
</teardown_code>
<local_variables>
<value><![CDATA[unsigned i;]]></value>
</local_variables>
</various_code>
<steps>
<step>
<description>
<value>Adding the objects to the pool using chGuardedPoolLoadArray().</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[chGuardedPoolLoadArray(&gmp1, objects, MEMORY_POOL_SIZE);]]></value>
</code>
</step>
<step>
<description>
<value>Emptying the pool using chGuardedPoolAllocTimeout().</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[for (i = 0; i < MEMORY_POOL_SIZE; i++)
test_assert(chGuardedPoolAllocTimeout(&gmp1, TIME_IMMEDIATE) != NULL, "list empty");]]></value>
</code>
</step>
<step>
<description>
<value>Now must be empty.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[test_assert(chGuardedPoolAllocTimeout(&gmp1, TIME_IMMEDIATE) == NULL, "list not empty");]]></value>
</code>
</step>
<step>
<description>
<value>Adding the objects to the pool using chGuardedPoolFree().</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[for (i = 0; i < MEMORY_POOL_SIZE; i++)
chGuardedPoolFree(&gmp1, &objects[i]);]]></value>
</code>
</step>
<step>
<description>
<value>Emptying the pool using chGuardedPoolAllocTimeout() again.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[for (i = 0; i < MEMORY_POOL_SIZE; i++)
test_assert(chGuardedPoolAllocTimeout(&gmp1, TIME_IMMEDIATE) != NULL, "list empty");]]></value>
</code>
</step>
<step>
<description>
<value>Now must be empty again.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[test_assert(chGuardedPoolAllocTimeout(&gmp1, TIME_IMMEDIATE) == NULL, "list not empty");]]></value>
</code>
</step>
</steps>
</case>
<case>
<brief>
<value>Guarded Memory Pools timeout.</value>
</brief>
<description>
<value>The timeout features for the Guarded Memory Pools is tested.</value>
</description>
<condition>
<value>CH_CFG_USE_SEMAPHORES</value>
</condition>
<various_code>
<setup_code>
<value><![CDATA[chGuardedPoolObjectInit(&gmp1, sizeof (uint32_t));]]></value>
</setup_code>
<teardown_code>
<value />
</teardown_code>
<local_variables>
<value />
</local_variables>
</various_code>
<steps>
<step>
<description>
<value>Trying to allocate with 100mS timeout, must fail because the pool is empty.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[test_assert(chGuardedPoolAllocTimeout(&gmp1, TIME_MS2I(100)) == NULL, "list not empty");]]></value>
</code>
</step>
</steps>
</case>
</cases>
</sequence>
<sequence>
<type index="0">
<value>Internal Tests</value>
</type>
<brief>
<value>Memory Heaps.</value>
</brief>
<description>
<value>This sequence tests the ChibiOS/RT functionalities related to memory heaps.</value>
</description>
<condition>
<value>CH_CFG_USE_HEAP</value>
</condition>
<shared_code>
<value><![CDATA[#define ALLOC_SIZE 16
#define HEAP_SIZE (ALLOC_SIZE * 8)
memory_heap_t test_heap;]]></value>
</shared_code>
<cases>
<case>
<brief>
<value>Allocation and fragmentation.</value>
</brief>
<description>
<value>Series of allocations/deallocations are performed in carefully designed sequences in order to stimulate all the possible code paths inside the allocator. The test expects to find the heap back to the initial status after each sequence.</value>
</description>
<condition>
<value />
</condition>
<various_code>
<setup_code>
<value><![CDATA[chHeapObjectInit(&test_heap, test_buffer, sizeof(test_buffer));]]></value>
</setup_code>
<teardown_code>
<value />
</teardown_code>
<local_variables>
<value><![CDATA[void *p1, *p2, *p3;
size_t n, sz;]]></value>
</local_variables>
</various_code>
<steps>
<step>
<description>
<value>Testing initial conditions, the heap must not be fragmented and one free block present.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[test_assert(chHeapStatus(&test_heap, &sz, NULL) == 1, "heap fragmented");]]></value>
</code>
</step>
<step>
<description>
<value>Trying to allocate an block bigger than available space, an error is expected.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[p1 = chHeapAlloc(&test_heap, sizeof test_buffer * 2);
test_assert(p1 == NULL, "allocation not failed");]]></value>
</code>
</step>
<step>
<description>
<value>Single block allocation using chHeapAlloc() then the block is freed using chHeapFree(), must not fail.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[p1 = chHeapAlloc(&test_heap, ALLOC_SIZE);
test_assert(p1 != NULL, "allocation failed");
chHeapFree(p1);]]></value>
</code>
</step>
<step>
<description>
<value>Using chHeapStatus() to assess the heap state. There must be at least one free block of sufficient size.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[size_t total_size, largest_size;
n = chHeapStatus(&test_heap, &total_size, &largest_size);
test_assert(n == 1, "missing free block");
test_assert(total_size >= ALLOC_SIZE, "unexpected heap state");
test_assert(total_size == largest_size, "unexpected heap state");]]></value>
</code>
</step>
<step>
<description>
<value>Allocating then freeing in the same order.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[p1 = chHeapAlloc(&test_heap, ALLOC_SIZE);
p2 = chHeapAlloc(&test_heap, ALLOC_SIZE);
p3 = chHeapAlloc(&test_heap, ALLOC_SIZE);
chHeapFree(p1); /* Does not merge.*/
chHeapFree(p2); /* Merges backward.*/
chHeapFree(p3); /* Merges both sides.*/
test_assert(chHeapStatus(&test_heap, &n, NULL) == 1, "heap fragmented");]]></value>
</code>
</step>
<step>
<description>
<value>Allocating then freeing in reverse order.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[p1 = chHeapAlloc(&test_heap, ALLOC_SIZE);
p2 = chHeapAlloc(&test_heap, ALLOC_SIZE);
p3 = chHeapAlloc(&test_heap, ALLOC_SIZE);
chHeapFree(p3); /* Merges forward.*/
chHeapFree(p2); /* Merges forward.*/
chHeapFree(p1); /* Merges forward.*/
test_assert(chHeapStatus(&test_heap, &n, NULL) == 1, "heap fragmented");]]></value>
</code>
</step>
<step>
<description>
<value>Small fragments handling. Checking the behavior when allocating blocks with size not multiple of alignment unit.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[p1 = chHeapAlloc(&test_heap, ALLOC_SIZE + 1);
p2 = chHeapAlloc(&test_heap, ALLOC_SIZE);
chHeapFree(p1);
test_assert(chHeapStatus(&test_heap, &n, NULL) == 2, "invalid state");
p1 = chHeapAlloc(&test_heap, ALLOC_SIZE);
/* Note, the first situation happens when the alignment size is smaller
than the header size, the second in the other cases.*/
test_assert((chHeapStatus(&test_heap, &n, NULL) == 1) ||
(chHeapStatus(&test_heap, &n, NULL) == 2), "heap fragmented");
chHeapFree(p2);
chHeapFree(p1);
test_assert(chHeapStatus(&test_heap, &n, NULL) == 1, "heap fragmented");]]></value>
</code>
</step>
<step>
<description>
<value>Skipping a fragment, the first fragment in the list is too small so the allocator must pick the second one.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[p1 = chHeapAlloc(&test_heap, ALLOC_SIZE);
p2 = chHeapAlloc(&test_heap, ALLOC_SIZE);
chHeapFree(p1);
test_assert( chHeapStatus(&test_heap, &n, NULL) == 2, "invalid state");
p1 = chHeapAlloc(&test_heap, ALLOC_SIZE * 2); /* Skips first fragment.*/
chHeapFree(p1);
chHeapFree(p2);
test_assert(chHeapStatus(&test_heap, &n, NULL) == 1, "heap fragmented");]]></value>
</code>
</step>
<step>
<description>
<value>Allocating the whole available space.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[(void)chHeapStatus(&test_heap, &n, NULL);
p1 = chHeapAlloc(&test_heap, n);
test_assert(p1 != NULL, "allocation failed");
test_assert(chHeapStatus(&test_heap, NULL, NULL) == 0, "not empty");
chHeapFree(p1);]]></value>
</code>
</step>
<step>
<description>
<value>Testing final conditions. The heap geometry must be the same than the one registered at beginning.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[test_assert(chHeapStatus(&test_heap, &n, NULL) == 1, "heap fragmented");
test_assert(n == sz, "size changed");]]></value>
</code>
</step>
</steps>
</case>
<case>
<brief>
<value>Default Heap.</value>
</brief>
<description>
<value>The default heap is pre-allocated in the system. We test base functionality.</value>
</description>
<condition>
<value />
</condition>
<various_code>
<setup_code>
<value />
</setup_code>
<teardown_code>
<value />
</teardown_code>
<local_variables>
<value><![CDATA[void *p1;
size_t total_size, largest_size;]]></value>
</local_variables>
</various_code>
<steps>
<step>
<description>
<value>Single block allocation using chHeapAlloc() then the block is freed using chHeapFree(), must not fail.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[(void)chHeapStatus(NULL, &total_size, &largest_size);
p1 = chHeapAlloc(&test_heap, ALLOC_SIZE);
test_assert(p1 != NULL, "allocation failed");
chHeapFree(p1);]]></value>
</code>
</step>
<step>
<description>
<value>Testing allocation failure.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[p1 = chHeapAlloc(NULL, (size_t)-256);
test_assert(p1 == NULL, "allocation not failed");]]></value>
</code>
</step>
</steps>
</case>
</cases>
</sequence>
<sequence>
<type index="0">
<value>Internal Tests</value>

15
test/rt/rt_test.mk Normal file
View File

@ -0,0 +1,15 @@
# List of all the ChibiOS/RT test files.
TESTSRC += ${CHIBIOS}/test/rt/source/test/rt_test_root.c \
${CHIBIOS}/test/rt/source/test/rt_test_sequence_001.c \
${CHIBIOS}/test/rt/source/test/rt_test_sequence_002.c \
${CHIBIOS}/test/rt/source/test/rt_test_sequence_003.c \
${CHIBIOS}/test/rt/source/test/rt_test_sequence_004.c \
${CHIBIOS}/test/rt/source/test/rt_test_sequence_005.c \
${CHIBIOS}/test/rt/source/test/rt_test_sequence_006.c \
${CHIBIOS}/test/rt/source/test/rt_test_sequence_007.c \
${CHIBIOS}/test/rt/source/test/rt_test_sequence_008.c \
${CHIBIOS}/test/rt/source/test/rt_test_sequence_009.c \
${CHIBIOS}/test/rt/source/test/rt_test_sequence_010.c
# Required include directories
TESTINC += ${CHIBIOS}/test/rt/source/test

View File

@ -31,9 +31,6 @@
* - @subpage rt_test_sequence_008
* - @subpage rt_test_sequence_009
* - @subpage rt_test_sequence_010
* - @subpage rt_test_sequence_011
* - @subpage rt_test_sequence_012
* - @subpage rt_test_sequence_013
* .
*/
@ -71,19 +68,10 @@ const testsequence_t * const rt_test_suite_array[] = {
#if (CH_CFG_USE_EVENTS) || defined(__DOXYGEN__)
&rt_test_sequence_008,
#endif
#if (CH_CFG_USE_MAILBOXES) || defined(__DOXYGEN__)
#if (CH_CFG_USE_DYNAMIC) || defined(__DOXYGEN__)
&rt_test_sequence_009,
#endif
#if (CH_CFG_USE_MEMPOOLS) || defined(__DOXYGEN__)
&rt_test_sequence_010,
#endif
#if (CH_CFG_USE_HEAP) || defined(__DOXYGEN__)
&rt_test_sequence_011,
#endif
#if (CH_CFG_USE_DYNAMIC) || defined(__DOXYGEN__)
&rt_test_sequence_012,
#endif
&rt_test_sequence_013,
NULL
};

View File

@ -34,9 +34,6 @@
#include "rt_test_sequence_008.h"
#include "rt_test_sequence_009.h"
#include "rt_test_sequence_010.h"
#include "rt_test_sequence_011.h"
#include "rt_test_sequence_012.h"
#include "rt_test_sequence_013.h"
#if !defined(__DOXYGEN__)
@ -57,8 +54,6 @@ extern "C" {
/* Shared definitions. */
/*===========================================================================*/
#define TEST_SUITE_NAME "ChibiOS/RT Test Suite"
/*
* Allowed delay in timeout checks.
*/

View File

@ -21,7 +21,7 @@
* @file rt_test_sequence_005.c
* @brief Test Sequence 005 code.
*
* @page rt_test_sequence_005 [5] Counter and Binary Semaphores
* @page rt_test_sequence_005 [5] Counter Semaphores
*
* File: @ref rt_test_sequence_005.c
*
@ -505,7 +505,7 @@ const testcase_t * const rt_test_sequence_005_array[] = {
};
/**
* @brief Counter and Binary Semaphores.
* @brief Counter Semaphores.
*/
const testsequence_t rt_test_sequence_005 = {
NULL,

View File

@ -21,375 +21,247 @@
* @file rt_test_sequence_009.c
* @brief Test Sequence 009 code.
*
* @page rt_test_sequence_009 [9] Mailboxes
* @page rt_test_sequence_009 [9] Dynamic threads
*
* File: @ref rt_test_sequence_009.c
*
* <h2>Description</h2>
* This sequence tests the ChibiOS/RT functionalities related to
* mailboxes.
* This module implements the test sequence for the dynamic thread
* creation APIs.
*
* <h2>Conditions</h2>
* This sequence is only executed if the following preprocessor condition
* evaluates to true:
* - CH_CFG_USE_MAILBOXES
* - CH_CFG_USE_DYNAMIC
* .
*
* <h2>Test Cases</h2>
* - @subpage rt_test_009_001
* - @subpage rt_test_009_002
* - @subpage rt_test_009_003
* .
*/
#if (CH_CFG_USE_MAILBOXES) || defined(__DOXYGEN__)
#if (CH_CFG_USE_DYNAMIC) || defined(__DOXYGEN__)
/****************************************************************************
* Shared code.
****************************************************************************/
#define MB_SIZE 4
#if CH_CFG_USE_HEAP
static memory_heap_t heap1;
#endif
#if CH_CFG_USE_MEMPOOLS
static memory_pool_t mp1;
#endif
static msg_t mb_buffer[MB_SIZE];
static MAILBOX_DECL(mb1, mb_buffer, MB_SIZE);
static THD_FUNCTION(dyn_thread1, p) {
test_emit_token(*(char *)p);
}
/****************************************************************************
* Test cases.
****************************************************************************/
#if (CH_CFG_USE_HEAP) || defined(__DOXYGEN__)
/**
* @page rt_test_009_001 [9.1] Mailbox normal API, non-blocking tests
* @page rt_test_009_001 [9.1] Threads creation from Memory Heap
*
* <h2>Description</h2>
* The mailbox normal API is tested without triggering blocking
* conditions.
* Two threads are started by allocating the memory from the Memory
* Heap then a third thread is started with a huge stack
* requirement.<br> The test expects the first two threads to
* successfully start and the third one to fail.
*
* <h2>Conditions</h2>
* This test is only executed if the following preprocessor condition
* evaluates to true:
* - CH_CFG_USE_HEAP
* .
*
* <h2>Test Steps</h2>
* - [9.1.1] Testing the mailbox size.
* - [9.1.2] Resetting the mailbox, conditions are checked, no errors
* expected.
* - [9.1.3] Testing the behavior of API when the mailbox is in reset
* state then return in active state.
* - [9.1.4] Filling the mailbox using chMBPostTimeout() and
* chMBPostAheadTimeout() once, no errors expected.
* - [9.1.5] Testing intermediate conditions. Data pointers must be
* aligned, semaphore counters are checked.
* - [9.1.6] Emptying the mailbox using chMBFetchTimeout(), no errors
* expected.
* - [9.1.7] Posting and then fetching one more message, no errors
* expected.
* - [9.1.8] Testing final conditions. Data pointers must be aligned to
* buffer start, semaphore counters are checked.
* - [9.1.1] Getting base priority for threads.
* - [9.1.2] Getting heap info before the test.
* - [9.1.3] Creating thread 1, it is expected to succeed.
* - [9.1.4] Creating thread 2, it is expected to succeed.
* - [9.1.5] Creating thread 3, it is expected to fail.
* - [9.1.6] Letting threads execute then checking the start order and
* freeing memory.
* - [9.1.7] Getting heap info again for verification.
* .
*/
static void rt_test_009_001_setup(void) {
chMBObjectInit(&mb1, mb_buffer, MB_SIZE);
}
static void rt_test_009_001_teardown(void) {
chMBReset(&mb1);
chHeapObjectInit(&heap1, test_buffer, sizeof test_buffer);
}
static void rt_test_009_001_execute(void) {
msg_t msg1, msg2;
unsigned i;
size_t n1, total1, largest1;
size_t n2, total2, largest2;
tprio_t prio;
/* [9.1.1] Testing the mailbox size.*/
/* [9.1.1] Getting base priority for threads.*/
test_set_step(1);
{
test_assert_lock(chMBGetFreeCountI(&mb1) == MB_SIZE, "wrong size");
prio = chThdGetPriorityX();
}
/* [9.1.2] Resetting the mailbox, conditions are checked, no errors
expected.*/
/* [9.1.2] Getting heap info before the test.*/
test_set_step(2);
{
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");
n1 = chHeapStatus(&heap1, &total1, &largest1);
test_assert(n1 == 1, "heap fragmented");
}
/* [9.1.3] Testing the behavior of API when the mailbox is in reset
state then return in active state.*/
/* [9.1.3] Creating thread 1, it is expected to succeed.*/
test_set_step(3);
{
msg1 = chMBPostTimeout(&mb1, (msg_t)0, TIME_INFINITE);
test_assert(msg1 == MSG_RESET, "not in reset state");
msg1 = chMBPostAheadTimeout(&mb1, (msg_t)0, TIME_INFINITE);
test_assert(msg1 == MSG_RESET, "not in reset state");
msg1 = chMBFetchTimeout(&mb1, &msg2, TIME_INFINITE);
test_assert(msg1 == MSG_RESET, "not in reset state");
chMBResumeX(&mb1);
threads[0] = chThdCreateFromHeap(&heap1,
THD_WORKING_AREA_SIZE(THREADS_STACK_SIZE),
"dyn1",
prio-1, dyn_thread1, "A");
test_assert(threads[0] != NULL, "thread creation failed");
}
/* [9.1.4] Filling the mailbox using chMBPostTimeout() and
chMBPostAheadTimeout() once, no errors expected.*/
/* [9.1.4] Creating thread 2, it is expected to succeed.*/
test_set_step(4);
{
for (i = 0; i < MB_SIZE - 1; i++) {
msg1 = chMBPostTimeout(&mb1, 'B' + i, TIME_INFINITE);
test_assert(msg1 == MSG_OK, "wrong wake-up message");
}
msg1 = chMBPostAheadTimeout(&mb1, 'A', TIME_INFINITE);
test_assert(msg1 == MSG_OK, "wrong wake-up message");
threads[1] = chThdCreateFromHeap(&heap1,
THD_WORKING_AREA_SIZE(THREADS_STACK_SIZE),
"dyn2",
prio-2, dyn_thread1, "B");
test_assert(threads[1] != NULL, "thread creation failed");
}
/* [9.1.5] Testing intermediate conditions. Data pointers must be
aligned, semaphore counters are checked.*/
/* [9.1.5] Creating thread 3, it is expected to fail.*/
test_set_step(5);
{
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");
threads[2] = chThdCreateFromHeap(&heap1,
THD_WORKING_AREA_SIZE(THREADS_STACK_SIZE * 1024),
"dyn3",
prio-3, dyn_thread1, "C");
test_assert(threads[2] == NULL, "thread creation not failed");
}
/* [9.1.6] Emptying the mailbox using chMBFetchTimeout(), no errors
expected.*/
/* [9.1.6] Letting threads execute then checking the start order and
freeing memory.*/
test_set_step(6);
{
for (i = 0; i < MB_SIZE; i++) {
msg1 = chMBFetchTimeout(&mb1, &msg2, TIME_INFINITE);
test_assert(msg1 == MSG_OK, "wrong wake-up message");
test_emit_token(msg2);
}
test_assert_sequence("ABCD", "wrong get sequence");
test_wait_threads();
test_assert_sequence("AB", "invalid sequence");
}
/* [9.1.7] Posting and then fetching one more message, no errors
expected.*/
/* [9.1.7] Getting heap info again for verification.*/
test_set_step(7);
{
msg1 = chMBPostTimeout(&mb1, 'B' + i, TIME_INFINITE);
test_assert(msg1 == MSG_OK, "wrong wake-up message");
msg1 = chMBFetchTimeout(&mb1, &msg2, TIME_INFINITE);
test_assert(msg1 == MSG_OK, "wrong wake-up message");
}
/* [9.1.8] Testing final conditions. Data pointers must be aligned to
buffer start, semaphore counters are checked.*/
test_set_step(8);
{
test_assert_lock(chMBGetFreeCountI(&mb1) == MB_SIZE, "not empty");
test_assert_lock(chMBGetUsedCountI(&mb1) == 0, "still 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");
n2 = chHeapStatus(&heap1, &total2, &largest2);
test_assert(n1 == n2, "fragmentation changed");
test_assert(total1 == total2, "total free space changed");
test_assert(largest1 == largest2, "largest fragment size changed");
}
}
static const testcase_t rt_test_009_001 = {
"Mailbox normal API, non-blocking tests",
"Threads creation from Memory Heap",
rt_test_009_001_setup,
rt_test_009_001_teardown,
NULL,
rt_test_009_001_execute
};
#endif /* CH_CFG_USE_HEAP */
#if (CH_CFG_USE_MEMPOOLS) || defined(__DOXYGEN__)
/**
* @page rt_test_009_002 [9.2] Mailbox I-Class API, non-blocking tests
* @page rt_test_009_002 [9.2] Threads creation from Memory Pool
*
* <h2>Description</h2>
* The mailbox I-Class API is tested without triggering blocking
* conditions.
* Five thread creation are attempted from a pool containing only four
* elements.<br> The test expects the first four threads to
* successfully start and the last one to fail.
*
* <h2>Conditions</h2>
* This test is only executed if the following preprocessor condition
* evaluates to true:
* - CH_CFG_USE_MEMPOOLS
* .
*
* <h2>Test Steps</h2>
* - [9.2.1] Testing the mailbox size.
* - [9.2.2] Resetting the mailbox, conditions are checked, no errors
* expected. The mailbox is then returned in active state.
* - [9.2.3] Filling the mailbox using chMBPostI() and chMBPostAheadI()
* once, no errors expected.
* - [9.2.4] Testing intermediate conditions. Data pointers must be
* aligned, semaphore counters are checked.
* - [9.2.5] Emptying the mailbox using chMBFetchI(), no errors
* expected.
* - [9.2.6] Posting and then fetching one more message, no errors
* expected.
* - [9.2.7] Testing final conditions. Data pointers must be aligned to
* buffer start, semaphore counters are checked.
* - [9.2.1] Adding four working areas to the pool.
* - [9.2.2] Getting base priority for threads.
* - [9.2.3] Creating the five threads.
* - [9.2.4] Testing that only the fifth thread creation failed.
* - [9.2.5] Letting them run, free the memory then checking the
* execution sequence.
* - [9.2.6] Testing that the pool contains four elements again.
* .
*/
static void rt_test_009_002_setup(void) {
chMBObjectInit(&mb1, mb_buffer, MB_SIZE);
}
static void rt_test_009_002_teardown(void) {
chMBReset(&mb1);
chPoolObjectInit(&mp1, THD_WORKING_AREA_SIZE(THREADS_STACK_SIZE), NULL);
}
static void rt_test_009_002_execute(void) {
msg_t msg1, msg2;
unsigned i;
tprio_t prio;
/* [9.2.1] Testing the mailbox size.*/
/* [9.2.1] Adding four working areas to the pool.*/
test_set_step(1);
{
test_assert_lock(chMBGetFreeCountI(&mb1) == MB_SIZE, "wrong size");
for (i = 0; i < 4; i++)
chPoolFree(&mp1, wa[i]);
}
/* [9.2.2] Resetting the mailbox, conditions are checked, no errors
expected. The mailbox is then returned in active state.*/
/* [9.2.2] Getting base priority for threads.*/
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");
chMBResumeX(&mb1);
prio = chThdGetPriorityX();
}
/* [9.2.3] Filling the mailbox using chMBPostI() and chMBPostAheadI()
once, no errors expected.*/
/* [9.2.3] Creating the five threads.*/
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");
threads[0] = chThdCreateFromMemoryPool(&mp1, "dyn1", prio-1, dyn_thread1, "A");
threads[1] = chThdCreateFromMemoryPool(&mp1, "dyn2", prio-2, dyn_thread1, "B");
threads[2] = chThdCreateFromMemoryPool(&mp1, "dyn3", prio-3, dyn_thread1, "C");
threads[3] = chThdCreateFromMemoryPool(&mp1, "dyn4", prio-4, dyn_thread1, "D");
threads[4] = chThdCreateFromMemoryPool(&mp1, "dyn5", prio-5, dyn_thread1, "E");
}
/* [9.2.4] Testing intermediate conditions. Data pointers must be
aligned, semaphore counters are checked.*/
/* [9.2.4] Testing that only the fifth thread creation failed.*/
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");
test_assert((threads[0] != NULL) &&
(threads[1] != NULL) &&
(threads[2] != NULL) &&
(threads[3] != NULL),
"thread creation failed");
test_assert(threads[4] == NULL,
"thread creation not failed");
}
/* [9.2.5] Emptying the mailbox using chMBFetchI(), no errors
expected.*/
/* [9.2.5] Letting them run, free the memory then checking the
execution sequence.*/
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("ABCD", "wrong get sequence");
test_wait_threads();
test_assert_sequence("ABCD", "invalid sequence");
}
/* [9.2.6] Posting and then fetching one more message, no errors
expected.*/
/* [9.2.6] Testing that the pool contains four elements again.*/
test_set_step(6);
{
msg1 = chMBPostTimeout(&mb1, 'B' + i, TIME_INFINITE);
test_assert(msg1 == MSG_OK, "wrong wake-up message");
msg1 = chMBFetchTimeout(&mb1, &msg2, TIME_INFINITE);
test_assert(msg1 == MSG_OK, "wrong wake-up message");
}
/* [9.2.7] Testing final conditions. Data pointers must be aligned to
buffer start, semaphore counters are checked.*/
test_set_step(7);
{
test_assert_lock(chMBGetFreeCountI(&mb1) == MB_SIZE, "not empty");
test_assert_lock(chMBGetUsedCountI(&mb1) == 0, "still 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");
for (i = 0; i < 4; i++)
test_assert(chPoolAlloc(&mp1) != NULL, "pool list empty");
test_assert(chPoolAlloc(&mp1) == NULL, "pool list not empty");
}
}
static const testcase_t rt_test_009_002 = {
"Mailbox I-Class API, non-blocking tests",
"Threads creation from Memory Pool",
rt_test_009_002_setup,
rt_test_009_002_teardown,
NULL,
rt_test_009_002_execute
};
/**
* @page rt_test_009_003 [9.3] Mailbox timeouts
*
* <h2>Description</h2>
* The mailbox API is tested for timeouts.
*
* <h2>Test Steps</h2>
* - [9.3.1] Filling the mailbox.
* - [9.3.2] Testing chMBPostTimeout(), chMBPostI(),
* chMBPostAheadTimeout() and chMBPostAheadI() timeout.
* - [9.3.3] Resetting the mailbox. The mailbox is then returned in
* active state.
* - [9.3.4] Testing chMBFetchTimeout() and chMBFetchI() timeout.
* .
*/
static void rt_test_009_003_setup(void) {
chMBObjectInit(&mb1, mb_buffer, MB_SIZE);
}
static void rt_test_009_003_teardown(void) {
chMBReset(&mb1);
}
static void rt_test_009_003_execute(void) {
msg_t msg1, msg2;
unsigned i;
/* [9.3.1] Filling the mailbox.*/
test_set_step(1);
{
for (i = 0; i < MB_SIZE; i++) {
msg1 = chMBPostTimeout(&mb1, 'B' + i, TIME_INFINITE);
test_assert(msg1 == MSG_OK, "wrong wake-up message");
}
}
/* [9.3.2] Testing chMBPostTimeout(), chMBPostI(),
chMBPostAheadTimeout() and chMBPostAheadI() timeout.*/
test_set_step(2);
{
msg1 = chMBPostTimeout(&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 = chMBPostAheadTimeout(&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");
}
/* [9.3.3] Resetting the mailbox. The mailbox is then returned in
active state.*/
test_set_step(3);
{
chMBReset(&mb1);
chMBResumeX(&mb1);
}
/* [9.3.4] Testing chMBFetchTimeout() and chMBFetchI() timeout.*/
test_set_step(4);
{
msg1 = chMBFetchTimeout(&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 rt_test_009_003 = {
"Mailbox timeouts",
rt_test_009_003_setup,
rt_test_009_003_teardown,
rt_test_009_003_execute
};
#endif /* CH_CFG_USE_MEMPOOLS */
/****************************************************************************
* Exported data.
@ -399,18 +271,21 @@ static const testcase_t rt_test_009_003 = {
* @brief Array of test cases.
*/
const testcase_t * const rt_test_sequence_009_array[] = {
#if (CH_CFG_USE_HEAP) || defined(__DOXYGEN__)
&rt_test_009_001,
#endif
#if (CH_CFG_USE_MEMPOOLS) || defined(__DOXYGEN__)
&rt_test_009_002,
&rt_test_009_003,
#endif
NULL
};
/**
* @brief Mailboxes.
* @brief Dynamic threads.
*/
const testsequence_t rt_test_sequence_009 = {
NULL,
rt_test_sequence_009_array
};
#endif /* CH_CFG_USE_MAILBOXES */
#endif /* CH_CFG_USE_DYNAMIC */

File diff suppressed because it is too large Load Diff

View File

@ -1,279 +0,0 @@
/*
ChibiOS - Copyright (C) 2006..2017 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 "rt_test_root.h"
/**
* @file rt_test_sequence_011.c
* @brief Test Sequence 011 code.
*
* @page rt_test_sequence_011 [11] Memory Heaps
*
* File: @ref rt_test_sequence_011.c
*
* <h2>Description</h2>
* This sequence tests the ChibiOS/RT functionalities related to memory
* heaps.
*
* <h2>Conditions</h2>
* This sequence is only executed if the following preprocessor condition
* evaluates to true:
* - CH_CFG_USE_HEAP
* .
*
* <h2>Test Cases</h2>
* - @subpage rt_test_011_001
* - @subpage rt_test_011_002
* .
*/
#if (CH_CFG_USE_HEAP) || defined(__DOXYGEN__)
/****************************************************************************
* Shared code.
****************************************************************************/
#define ALLOC_SIZE 16
#define HEAP_SIZE (ALLOC_SIZE * 8)
memory_heap_t test_heap;
/****************************************************************************
* Test cases.
****************************************************************************/
/**
* @page rt_test_011_001 [11.1] Allocation and fragmentation
*
* <h2>Description</h2>
* Series of allocations/deallocations are performed in carefully
* designed sequences in order to stimulate all the possible code paths
* inside the allocator. The test expects to find the heap back to the
* initial status after each sequence.
*
* <h2>Test Steps</h2>
* - [11.1.1] Testing initial conditions, the heap must not be
* fragmented and one free block present.
* - [11.1.2] Trying to allocate an block bigger than available space,
* an error is expected.
* - [11.1.3] Single block allocation using chHeapAlloc() then the
* block is freed using chHeapFree(), must not fail.
* - [11.1.4] Using chHeapStatus() to assess the heap state. There must
* be at least one free block of sufficient size.
* - [11.1.5] Allocating then freeing in the same order.
* - [11.1.6] Allocating then freeing in reverse order.
* - [11.1.7] Small fragments handling. Checking the behavior when
* allocating blocks with size not multiple of alignment unit.
* - [11.1.8] Skipping a fragment, the first fragment in the list is
* too small so the allocator must pick the second one.
* - [11.1.9] Allocating the whole available space.
* - [11.1.10] Testing final conditions. The heap geometry must be the
* same than the one registered at beginning.
* .
*/
static void rt_test_011_001_setup(void) {
chHeapObjectInit(&test_heap, test_buffer, sizeof(test_buffer));
}
static void rt_test_011_001_execute(void) {
void *p1, *p2, *p3;
size_t n, sz;
/* [11.1.1] Testing initial conditions, the heap must not be
fragmented and one free block present.*/
test_set_step(1);
{
test_assert(chHeapStatus(&test_heap, &sz, NULL) == 1, "heap fragmented");
}
/* [11.1.2] Trying to allocate an block bigger than available space,
an error is expected.*/
test_set_step(2);
{
p1 = chHeapAlloc(&test_heap, sizeof test_buffer * 2);
test_assert(p1 == NULL, "allocation not failed");
}
/* [11.1.3] Single block allocation using chHeapAlloc() then the
block is freed using chHeapFree(), must not fail.*/
test_set_step(3);
{
p1 = chHeapAlloc(&test_heap, ALLOC_SIZE);
test_assert(p1 != NULL, "allocation failed");
chHeapFree(p1);
}
/* [11.1.4] Using chHeapStatus() to assess the heap state. There must
be at least one free block of sufficient size.*/
test_set_step(4);
{
size_t total_size, largest_size;
n = chHeapStatus(&test_heap, &total_size, &largest_size);
test_assert(n == 1, "missing free block");
test_assert(total_size >= ALLOC_SIZE, "unexpected heap state");
test_assert(total_size == largest_size, "unexpected heap state");
}
/* [11.1.5] Allocating then freeing in the same order.*/
test_set_step(5);
{
p1 = chHeapAlloc(&test_heap, ALLOC_SIZE);
p2 = chHeapAlloc(&test_heap, ALLOC_SIZE);
p3 = chHeapAlloc(&test_heap, ALLOC_SIZE);
chHeapFree(p1); /* Does not merge.*/
chHeapFree(p2); /* Merges backward.*/
chHeapFree(p3); /* Merges both sides.*/
test_assert(chHeapStatus(&test_heap, &n, NULL) == 1, "heap fragmented");
}
/* [11.1.6] Allocating then freeing in reverse order.*/
test_set_step(6);
{
p1 = chHeapAlloc(&test_heap, ALLOC_SIZE);
p2 = chHeapAlloc(&test_heap, ALLOC_SIZE);
p3 = chHeapAlloc(&test_heap, ALLOC_SIZE);
chHeapFree(p3); /* Merges forward.*/
chHeapFree(p2); /* Merges forward.*/
chHeapFree(p1); /* Merges forward.*/
test_assert(chHeapStatus(&test_heap, &n, NULL) == 1, "heap fragmented");
}
/* [11.1.7] Small fragments handling. Checking the behavior when
allocating blocks with size not multiple of alignment unit.*/
test_set_step(7);
{
p1 = chHeapAlloc(&test_heap, ALLOC_SIZE + 1);
p2 = chHeapAlloc(&test_heap, ALLOC_SIZE);
chHeapFree(p1);
test_assert(chHeapStatus(&test_heap, &n, NULL) == 2, "invalid state");
p1 = chHeapAlloc(&test_heap, ALLOC_SIZE);
/* Note, the first situation happens when the alignment size is smaller
than the header size, the second in the other cases.*/
test_assert((chHeapStatus(&test_heap, &n, NULL) == 1) ||
(chHeapStatus(&test_heap, &n, NULL) == 2), "heap fragmented");
chHeapFree(p2);
chHeapFree(p1);
test_assert(chHeapStatus(&test_heap, &n, NULL) == 1, "heap fragmented");
}
/* [11.1.8] Skipping a fragment, the first fragment in the list is
too small so the allocator must pick the second one.*/
test_set_step(8);
{
p1 = chHeapAlloc(&test_heap, ALLOC_SIZE);
p2 = chHeapAlloc(&test_heap, ALLOC_SIZE);
chHeapFree(p1);
test_assert( chHeapStatus(&test_heap, &n, NULL) == 2, "invalid state");
p1 = chHeapAlloc(&test_heap, ALLOC_SIZE * 2); /* Skips first fragment.*/
chHeapFree(p1);
chHeapFree(p2);
test_assert(chHeapStatus(&test_heap, &n, NULL) == 1, "heap fragmented");
}
/* [11.1.9] Allocating the whole available space.*/
test_set_step(9);
{
(void)chHeapStatus(&test_heap, &n, NULL);
p1 = chHeapAlloc(&test_heap, n);
test_assert(p1 != NULL, "allocation failed");
test_assert(chHeapStatus(&test_heap, NULL, NULL) == 0, "not empty");
chHeapFree(p1);
}
/* [11.1.10] Testing final conditions. The heap geometry must be the
same than the one registered at beginning.*/
test_set_step(10);
{
test_assert(chHeapStatus(&test_heap, &n, NULL) == 1, "heap fragmented");
test_assert(n == sz, "size changed");
}
}
static const testcase_t rt_test_011_001 = {
"Allocation and fragmentation",
rt_test_011_001_setup,
NULL,
rt_test_011_001_execute
};
/**
* @page rt_test_011_002 [11.2] Default Heap
*
* <h2>Description</h2>
* The default heap is pre-allocated in the system. We test base
* functionality.
*
* <h2>Test Steps</h2>
* - [11.2.1] Single block allocation using chHeapAlloc() then the
* block is freed using chHeapFree(), must not fail.
* - [11.2.2] Testing allocation failure.
* .
*/
static void rt_test_011_002_execute(void) {
void *p1;
size_t total_size, largest_size;
/* [11.2.1] Single block allocation using chHeapAlloc() then the
block is freed using chHeapFree(), must not fail.*/
test_set_step(1);
{
(void)chHeapStatus(NULL, &total_size, &largest_size);
p1 = chHeapAlloc(&test_heap, ALLOC_SIZE);
test_assert(p1 != NULL, "allocation failed");
chHeapFree(p1);
}
/* [11.2.2] Testing allocation failure.*/
test_set_step(2);
{
p1 = chHeapAlloc(NULL, (size_t)-256);
test_assert(p1 == NULL, "allocation not failed");
}
}
static const testcase_t rt_test_011_002 = {
"Default Heap",
NULL,
NULL,
rt_test_011_002_execute
};
/****************************************************************************
* Exported data.
****************************************************************************/
/**
* @brief Array of test cases.
*/
const testcase_t * const rt_test_sequence_011_array[] = {
&rt_test_011_001,
&rt_test_011_002,
NULL
};
/**
* @brief Memory Heaps.
*/
const testsequence_t rt_test_sequence_011 = {
NULL,
rt_test_sequence_011_array
};
#endif /* CH_CFG_USE_HEAP */

View File

@ -1,27 +0,0 @@
/*
ChibiOS - Copyright (C) 2006..2017 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.
*/
/**
* @file rt_test_sequence_011.h
* @brief Test Sequence 011 header.
*/
#ifndef RT_TEST_SEQUENCE_011_H
#define RT_TEST_SEQUENCE_011_H
extern const testsequence_t rt_test_sequence_011;
#endif /* RT_TEST_SEQUENCE_011_H */

View File

@ -1,291 +0,0 @@
/*
ChibiOS - Copyright (C) 2006..2017 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 "rt_test_root.h"
/**
* @file rt_test_sequence_012.c
* @brief Test Sequence 012 code.
*
* @page rt_test_sequence_012 [12] Dynamic threads
*
* File: @ref rt_test_sequence_012.c
*
* <h2>Description</h2>
* This module implements the test sequence for the dynamic thread
* creation APIs.
*
* <h2>Conditions</h2>
* This sequence is only executed if the following preprocessor condition
* evaluates to true:
* - CH_CFG_USE_DYNAMIC
* .
*
* <h2>Test Cases</h2>
* - @subpage rt_test_012_001
* - @subpage rt_test_012_002
* .
*/
#if (CH_CFG_USE_DYNAMIC) || defined(__DOXYGEN__)
/****************************************************************************
* Shared code.
****************************************************************************/
#if CH_CFG_USE_HEAP
static memory_heap_t heap1;
#endif
#if CH_CFG_USE_MEMPOOLS
static memory_pool_t mp1;
#endif
static THD_FUNCTION(dyn_thread1, p) {
test_emit_token(*(char *)p);
}
/****************************************************************************
* Test cases.
****************************************************************************/
#if (CH_CFG_USE_HEAP) || defined(__DOXYGEN__)
/**
* @page rt_test_012_001 [12.1] Threads creation from Memory Heap
*
* <h2>Description</h2>
* Two threads are started by allocating the memory from the Memory
* Heap then a third thread is started with a huge stack
* requirement.<br> The test expects the first two threads to
* successfully start and the third one to fail.
*
* <h2>Conditions</h2>
* This test is only executed if the following preprocessor condition
* evaluates to true:
* - CH_CFG_USE_HEAP
* .
*
* <h2>Test Steps</h2>
* - [12.1.1] Getting base priority for threads.
* - [12.1.2] Getting heap info before the test.
* - [12.1.3] Creating thread 1, it is expected to succeed.
* - [12.1.4] Creating thread 2, it is expected to succeed.
* - [12.1.5] Creating thread 3, it is expected to fail.
* - [12.1.6] Letting threads execute then checking the start order and
* freeing memory.
* - [12.1.7] Getting heap info again for verification.
* .
*/
static void rt_test_012_001_setup(void) {
chHeapObjectInit(&heap1, test_buffer, sizeof test_buffer);
}
static void rt_test_012_001_execute(void) {
size_t n1, total1, largest1;
size_t n2, total2, largest2;
tprio_t prio;
/* [12.1.1] Getting base priority for threads.*/
test_set_step(1);
{
prio = chThdGetPriorityX();
}
/* [12.1.2] Getting heap info before the test.*/
test_set_step(2);
{
n1 = chHeapStatus(&heap1, &total1, &largest1);
test_assert(n1 == 1, "heap fragmented");
}
/* [12.1.3] Creating thread 1, it is expected to succeed.*/
test_set_step(3);
{
threads[0] = chThdCreateFromHeap(&heap1,
THD_WORKING_AREA_SIZE(THREADS_STACK_SIZE),
"dyn1",
prio-1, dyn_thread1, "A");
test_assert(threads[0] != NULL, "thread creation failed");
}
/* [12.1.4] Creating thread 2, it is expected to succeed.*/
test_set_step(4);
{
threads[1] = chThdCreateFromHeap(&heap1,
THD_WORKING_AREA_SIZE(THREADS_STACK_SIZE),
"dyn2",
prio-2, dyn_thread1, "B");
test_assert(threads[1] != NULL, "thread creation failed");
}
/* [12.1.5] Creating thread 3, it is expected to fail.*/
test_set_step(5);
{
threads[2] = chThdCreateFromHeap(&heap1,
THD_WORKING_AREA_SIZE(THREADS_STACK_SIZE * 1024),
"dyn3",
prio-3, dyn_thread1, "C");
test_assert(threads[2] == NULL, "thread creation not failed");
}
/* [12.1.6] Letting threads execute then checking the start order and
freeing memory.*/
test_set_step(6);
{
test_wait_threads();
test_assert_sequence("AB", "invalid sequence");
}
/* [12.1.7] Getting heap info again for verification.*/
test_set_step(7);
{
n2 = chHeapStatus(&heap1, &total2, &largest2);
test_assert(n1 == n2, "fragmentation changed");
test_assert(total1 == total2, "total free space changed");
test_assert(largest1 == largest2, "largest fragment size changed");
}
}
static const testcase_t rt_test_012_001 = {
"Threads creation from Memory Heap",
rt_test_012_001_setup,
NULL,
rt_test_012_001_execute
};
#endif /* CH_CFG_USE_HEAP */
#if (CH_CFG_USE_MEMPOOLS) || defined(__DOXYGEN__)
/**
* @page rt_test_012_002 [12.2] Threads creation from Memory Pool
*
* <h2>Description</h2>
* Five thread creation are attempted from a pool containing only four
* elements.<br> The test expects the first four threads to
* successfully start and the last one to fail.
*
* <h2>Conditions</h2>
* This test is only executed if the following preprocessor condition
* evaluates to true:
* - CH_CFG_USE_MEMPOOLS
* .
*
* <h2>Test Steps</h2>
* - [12.2.1] Adding four working areas to the pool.
* - [12.2.2] Getting base priority for threads.
* - [12.2.3] Creating the five threads.
* - [12.2.4] Testing that only the fifth thread creation failed.
* - [12.2.5] Letting them run, free the memory then checking the
* execution sequence.
* - [12.2.6] Testing that the pool contains four elements again.
* .
*/
static void rt_test_012_002_setup(void) {
chPoolObjectInit(&mp1, THD_WORKING_AREA_SIZE(THREADS_STACK_SIZE), NULL);
}
static void rt_test_012_002_execute(void) {
unsigned i;
tprio_t prio;
/* [12.2.1] Adding four working areas to the pool.*/
test_set_step(1);
{
for (i = 0; i < 4; i++)
chPoolFree(&mp1, wa[i]);
}
/* [12.2.2] Getting base priority for threads.*/
test_set_step(2);
{
prio = chThdGetPriorityX();
}
/* [12.2.3] Creating the five threads.*/
test_set_step(3);
{
threads[0] = chThdCreateFromMemoryPool(&mp1, "dyn1", prio-1, dyn_thread1, "A");
threads[1] = chThdCreateFromMemoryPool(&mp1, "dyn2", prio-2, dyn_thread1, "B");
threads[2] = chThdCreateFromMemoryPool(&mp1, "dyn3", prio-3, dyn_thread1, "C");
threads[3] = chThdCreateFromMemoryPool(&mp1, "dyn4", prio-4, dyn_thread1, "D");
threads[4] = chThdCreateFromMemoryPool(&mp1, "dyn5", prio-5, dyn_thread1, "E");
}
/* [12.2.4] Testing that only the fifth thread creation failed.*/
test_set_step(4);
{
test_assert((threads[0] != NULL) &&
(threads[1] != NULL) &&
(threads[2] != NULL) &&
(threads[3] != NULL),
"thread creation failed");
test_assert(threads[4] == NULL,
"thread creation not failed");
}
/* [12.2.5] Letting them run, free the memory then checking the
execution sequence.*/
test_set_step(5);
{
test_wait_threads();
test_assert_sequence("ABCD", "invalid sequence");
}
/* [12.2.6] Testing that the pool contains four elements again.*/
test_set_step(6);
{
for (i = 0; i < 4; i++)
test_assert(chPoolAlloc(&mp1) != NULL, "pool list empty");
test_assert(chPoolAlloc(&mp1) == NULL, "pool list not empty");
}
}
static const testcase_t rt_test_012_002 = {
"Threads creation from Memory Pool",
rt_test_012_002_setup,
NULL,
rt_test_012_002_execute
};
#endif /* CH_CFG_USE_MEMPOOLS */
/****************************************************************************
* Exported data.
****************************************************************************/
/**
* @brief Array of test cases.
*/
const testcase_t * const rt_test_sequence_012_array[] = {
#if (CH_CFG_USE_HEAP) || defined(__DOXYGEN__)
&rt_test_012_001,
#endif
#if (CH_CFG_USE_MEMPOOLS) || defined(__DOXYGEN__)
&rt_test_012_002,
#endif
NULL
};
/**
* @brief Dynamic threads.
*/
const testsequence_t rt_test_sequence_012 = {
NULL,
rt_test_sequence_012_array
};
#endif /* CH_CFG_USE_DYNAMIC */

View File

@ -1,27 +0,0 @@
/*
ChibiOS - Copyright (C) 2006..2017 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.
*/
/**
* @file rt_test_sequence_012.h
* @brief Test Sequence 012 header.
*/
#ifndef RT_TEST_SEQUENCE_012_H
#define RT_TEST_SEQUENCE_012_H
extern const testsequence_t rt_test_sequence_012;
#endif /* RT_TEST_SEQUENCE_012_H */

File diff suppressed because it is too large Load Diff

View File

@ -1,27 +0,0 @@
/*
ChibiOS - Copyright (C) 2006..2017 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.
*/
/**
* @file rt_test_sequence_013.h
* @brief Test Sequence 013 header.
*/
#ifndef RT_TEST_SEQUENCE_013_H
#define RT_TEST_SEQUENCE_013_H
extern const testsequence_t rt_test_sequence_013;
#endif /* RT_TEST_SEQUENCE_013_H */

View File

@ -1,20 +0,0 @@
# List of all the ChibiOS/RT test files.
TESTSRC = ${CHIBIOS}/test/lib/ch_test.c \
${CHIBIOS}/test/rt/source/test/rt_test_root.c \
${CHIBIOS}/test/rt/source/test/rt_test_sequence_001.c \
${CHIBIOS}/test/rt/source/test/rt_test_sequence_002.c \
${CHIBIOS}/test/rt/source/test/rt_test_sequence_003.c \
${CHIBIOS}/test/rt/source/test/rt_test_sequence_004.c \
${CHIBIOS}/test/rt/source/test/rt_test_sequence_005.c \
${CHIBIOS}/test/rt/source/test/rt_test_sequence_006.c \
${CHIBIOS}/test/rt/source/test/rt_test_sequence_007.c \
${CHIBIOS}/test/rt/source/test/rt_test_sequence_008.c \
${CHIBIOS}/test/rt/source/test/rt_test_sequence_009.c \
${CHIBIOS}/test/rt/source/test/rt_test_sequence_010.c \
${CHIBIOS}/test/rt/source/test/rt_test_sequence_011.c \
${CHIBIOS}/test/rt/source/test/rt_test_sequence_012.c \
${CHIBIOS}/test/rt/source/test/rt_test_sequence_013.c
# Required include directories
TESTINC = ${CHIBIOS}/test/lib \
${CHIBIOS}/test/rt/source/test