Guarded pools tested.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@9137 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
parent
b3fe630e4b
commit
d29098e7f6
|
@ -120,21 +120,19 @@ typedef struct {
|
||||||
*/
|
*/
|
||||||
#define _GUARDEDMEMORYPOOL_DATA(name, size) { \
|
#define _GUARDEDMEMORYPOOL_DATA(name, size) { \
|
||||||
_SEMAPHORE_DATA(name.sem, (cnt_t)0), \
|
_SEMAPHORE_DATA(name.sem, (cnt_t)0), \
|
||||||
NULL, \
|
_MEMORYPOOL_DATA(NULL, size, NULL) \
|
||||||
size, \
|
|
||||||
NULL \
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Static guarded memory pool initializer.
|
* @brief Static guarded memory pool initializer.
|
||||||
* @details Statically initialized guardedmemory pools require no explicit
|
* @details Statically initialized guarded memory pools require no explicit
|
||||||
* initialization using @p chGuardedPoolInit().
|
* initialization using @p chGuardedPoolInit().
|
||||||
*
|
*
|
||||||
* @param[in] name the name of the guarded memory pool variable
|
* @param[in] name the name of the guarded memory pool variable
|
||||||
* @param[in] size size of the memory pool contained objects
|
* @param[in] size size of the memory pool contained objects
|
||||||
*/
|
*/
|
||||||
#define GUARDEDMEMORYPOOL_DECL(name, size) \
|
#define GUARDEDMEMORYPOOL_DECL(name, size) \
|
||||||
memory_pool_t name = _MEMORYPOOL_DATA(name, size)
|
guarded_memory_pool_t name = _GUARDEDMEMORYPOOL_DATA(name, size)
|
||||||
#endif /* CH_CFG_USE_SEMAPHORES == TRUE */
|
#endif /* CH_CFG_USE_SEMAPHORES == TRUE */
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
|
|
@ -265,7 +265,7 @@ typedef struct {
|
||||||
#endif
|
#endif
|
||||||
/* End of the mandatory fields.*/
|
/* End of the mandatory fields.*/
|
||||||
/**
|
/**
|
||||||
* @brief Total transmit transfer size.
|
* @brief Total receive transfer size.
|
||||||
*/
|
*/
|
||||||
size_t totsize;
|
size_t totsize;
|
||||||
} USBOutEndpointState;
|
} USBOutEndpointState;
|
||||||
|
|
|
@ -1,5 +1,28 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<SPC5-Patch version="1.0.0">
|
<SPC5-Patch version="1.0.0">
|
||||||
<!--It is your patch repository, do not break your XML File.-->
|
<!--It is your patch repository, do not break your XML File.-->
|
||||||
<files />
|
<files>
|
||||||
|
<file componentId="org.chibios.spc5.components.chibios_unitary_tests_engine" version="1.0.0.qualifier" path="component/lib/include/ch_test.h" user="false">
|
||||||
|
<diff><![CDATA[--- components/chibios_unit_tests_engine_component/lib/include/ch_test.h
|
||||||
|
+++ components/chibios_unit_tests_engine_component/lib/include/ch_test.h
|
||||||
|
@@ -1,5 +1,5 @@
|
||||||
|
/*
|
||||||
|
- ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio
|
||||||
|
+ ChibiOS - Copyright (C) 2006..2016 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.]]></diff>
|
||||||
|
</file>
|
||||||
|
<file componentId="org.chibios.spc5.components.chibios_unitary_tests_engine" version="1.0.0.qualifier" path="component/lib/src/ch_test.c" user="false">
|
||||||
|
<diff><![CDATA[--- components/chibios_unit_tests_engine_component/lib/src/ch_test.c
|
||||||
|
+++ components/chibios_unit_tests_engine_component/lib/src/ch_test.c
|
||||||
|
@@ -1,5 +1,5 @@
|
||||||
|
/*
|
||||||
|
- ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio
|
||||||
|
+ ChibiOS - Copyright (C) 2006..2016 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.]]></diff>
|
||||||
|
</file>
|
||||||
|
</files>
|
||||||
</SPC5-Patch>
|
</SPC5-Patch>
|
||||||
|
|
|
@ -818,9 +818,9 @@ test_assert(msg1 == MSG_OK, "wrong wake-up message");]]></value>
|
||||||
<value />
|
<value />
|
||||||
</tags>
|
</tags>
|
||||||
<code>
|
<code>
|
||||||
<value><![CDATA[test_assert_lock(chMBGetFreeCountI(&mb1) == MB_SIZE, "not empty");
|
<value><![CDATA[test_assert_lock(chMBGetFreeCountI(&mb1) == MB_SIZE, "not empty");
|
||||||
test_assert_lock(chMBGetUsedCountI(&mb1) == 0, "still full");
|
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.wrptr, "write pointer not aligned to base");
|
||||||
test_assert(mb1.buffer == mb1.rdptr, "read pointer not aligned to base");]]></value>
|
test_assert(mb1.buffer == mb1.rdptr, "read pointer not aligned to base");]]></value>
|
||||||
</code>
|
</code>
|
||||||
</step>
|
</step>
|
||||||
|
@ -927,23 +927,24 @@ test_assert(msg1 == MSG_TIMEOUT, "wrong wake-up message");]]></value>
|
||||||
<value>This sequence tests the ChibiOS/NIL functionalities related to memory pools.</value>
|
<value>This sequence tests the ChibiOS/NIL functionalities related to memory pools.</value>
|
||||||
</description>
|
</description>
|
||||||
<shared_code>
|
<shared_code>
|
||||||
<value><![CDATA[#define MEMORY_POOL_SIZE 4
|
<value><![CDATA[#define MEMORY_POOL_SIZE 4
|
||||||
|
|
||||||
static uint32_t objects[MEMORY_POOL_SIZE];
|
static uint32_t objects[MEMORY_POOL_SIZE];
|
||||||
static MEMORYPOOL_DECL(mp1, sizeof (uint32_t), NULL);
|
static MEMORYPOOL_DECL(mp1, sizeof (uint32_t), NULL);
|
||||||
|
static GUARDEDMEMORYPOOL_DECL(gmp1, sizeof (uint32_t));
|
||||||
static void *null_provider(size_t size, unsigned align) {
|
|
||||||
|
static void *null_provider(size_t size, unsigned align) {
|
||||||
(void)size;
|
|
||||||
(void)align;
|
(void)size;
|
||||||
|
(void)align;
|
||||||
return NULL;
|
|
||||||
|
return NULL;
|
||||||
}]]></value>
|
}]]></value>
|
||||||
</shared_code>
|
</shared_code>
|
||||||
<cases>
|
<cases>
|
||||||
<case>
|
<case>
|
||||||
<brief>
|
<brief>
|
||||||
<value>Loading and empting the memory pool.</value>
|
<value>Loading and empting a memory pool.</value>
|
||||||
</brief>
|
</brief>
|
||||||
<description>
|
<description>
|
||||||
<value>The memory pool functionality is tested by loading and empting it, all conditions are tested.</value>
|
<value>The memory pool functionality is tested by loading and empting it, all conditions are tested.</value>
|
||||||
|
@ -982,7 +983,7 @@ static void *null_provider(size_t size, unsigned align) {
|
||||||
<value />
|
<value />
|
||||||
</tags>
|
</tags>
|
||||||
<code>
|
<code>
|
||||||
<value><![CDATA[for (i = 0; i < MEMORY_POOL_SIZE; i++)
|
<value><![CDATA[for (i = 0; i < MEMORY_POOL_SIZE; i++)
|
||||||
test_assert(chPoolAlloc(&mp1) != NULL, "list empty");]]></value>
|
test_assert(chPoolAlloc(&mp1) != NULL, "list empty");]]></value>
|
||||||
</code>
|
</code>
|
||||||
</step>
|
</step>
|
||||||
|
@ -1005,7 +1006,7 @@ static void *null_provider(size_t size, unsigned align) {
|
||||||
<value />
|
<value />
|
||||||
</tags>
|
</tags>
|
||||||
<code>
|
<code>
|
||||||
<value><![CDATA[for (i = 0; i < MEMORY_POOL_SIZE; i++)
|
<value><![CDATA[for (i = 0; i < MEMORY_POOL_SIZE; i++)
|
||||||
chPoolFree(&mp1, &objects[i]);]]></value>
|
chPoolFree(&mp1, &objects[i]);]]></value>
|
||||||
</code>
|
</code>
|
||||||
</step>
|
</step>
|
||||||
|
@ -1017,7 +1018,7 @@ static void *null_provider(size_t size, unsigned align) {
|
||||||
<value />
|
<value />
|
||||||
</tags>
|
</tags>
|
||||||
<code>
|
<code>
|
||||||
<value><![CDATA[for (i = 0; i < MEMORY_POOL_SIZE; i++)
|
<value><![CDATA[for (i = 0; i < MEMORY_POOL_SIZE; i++)
|
||||||
test_assert(chPoolAlloc(&mp1) != NULL, "list empty");]]></value>
|
test_assert(chPoolAlloc(&mp1) != NULL, "list empty");]]></value>
|
||||||
</code>
|
</code>
|
||||||
</step>
|
</step>
|
||||||
|
@ -1040,12 +1041,140 @@ static void *null_provider(size_t size, unsigned align) {
|
||||||
<value />
|
<value />
|
||||||
</tags>
|
</tags>
|
||||||
<code>
|
<code>
|
||||||
<value><![CDATA[chPoolObjectInit(&mp1, sizeof (uint32_t), null_provider);
|
<value><![CDATA[chPoolObjectInit(&mp1, sizeof (uint32_t), null_provider);
|
||||||
test_assert(chPoolAlloc(&mp1) == NULL, "provider returned memory");]]></value>
|
test_assert(chPoolAlloc(&mp1) == NULL, "provider returned memory");]]></value>
|
||||||
</code>
|
</code>
|
||||||
</step>
|
</step>
|
||||||
</steps>
|
</steps>
|
||||||
</case>
|
</case>
|
||||||
|
<case>
|
||||||
|
<brief>
|
||||||
|
<value>Loading and empting a guarded memory pool without waiting.</value>
|
||||||
|
</brief>
|
||||||
|
<description>
|
||||||
|
<value>The memory pool functionality is tested by loading and empting it, all conditions are tested.</value>
|
||||||
|
</description>
|
||||||
|
<condition>
|
||||||
|
<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 />
|
||||||
|
</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, MS2ST(100)) == NULL, "list not empty");]]></value>
|
||||||
|
</code>
|
||||||
|
</step>
|
||||||
|
</steps>
|
||||||
|
</case>
|
||||||
</cases>
|
</cases>
|
||||||
</sequence>
|
</sequence>
|
||||||
</sequences>
|
</sequences>
|
||||||
|
|
|
@ -1,5 +1,28 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<SPC5-Patch version="1.0.0">
|
<SPC5-Patch version="1.0.0">
|
||||||
<!--It is your patch repository, do not break your XML File.-->
|
<!--It is your patch repository, do not break your XML File.-->
|
||||||
<files />
|
<files>
|
||||||
|
<file componentId="org.chibios.spc5.components.chibios_unitary_tests_engine" version="1.0.0.qualifier" path="component/lib/include/ch_test.h" user="false">
|
||||||
|
<diff><![CDATA[--- components/chibios_unit_tests_engine_component/lib/include/ch_test.h
|
||||||
|
+++ components/chibios_unit_tests_engine_component/lib/include/ch_test.h
|
||||||
|
@@ -1,5 +1,5 @@
|
||||||
|
/*
|
||||||
|
- ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio
|
||||||
|
+ ChibiOS - Copyright (C) 2006..2016 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.]]></diff>
|
||||||
|
</file>
|
||||||
|
<file componentId="org.chibios.spc5.components.chibios_unitary_tests_engine" version="1.0.0.qualifier" path="component/lib/src/ch_test.c" user="false">
|
||||||
|
<diff><![CDATA[--- components/chibios_unit_tests_engine_component/lib/src/ch_test.c
|
||||||
|
+++ components/chibios_unit_tests_engine_component/lib/src/ch_test.c
|
||||||
|
@@ -1,5 +1,5 @@
|
||||||
|
/*
|
||||||
|
- ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio
|
||||||
|
+ ChibiOS - Copyright (C) 2006..2016 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.]]></diff>
|
||||||
|
</file>
|
||||||
|
</files>
|
||||||
</SPC5-Patch>
|
</SPC5-Patch>
|
||||||
|
|
|
@ -61,38 +61,38 @@ const testcase_t * const *test_suite[] = {
|
||||||
/* Shared code. */
|
/* Shared code. */
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
|
||||||
semaphore_t gsem1, gsem2;
|
semaphore_t gsem1, gsem2;
|
||||||
thread_reference_t gtr1;
|
thread_reference_t gtr1;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Support thread.
|
* Support thread.
|
||||||
*/
|
*/
|
||||||
THD_WORKING_AREA(wa_test_support, 128);
|
THD_WORKING_AREA(wa_test_support, 128);
|
||||||
THD_FUNCTION(test_support, arg) {
|
THD_FUNCTION(test_support, arg) {
|
||||||
#if CH_CFG_USE_EVENTS == TRUE
|
#if CH_CFG_USE_EVENTS == TRUE
|
||||||
thread_t *tp = (thread_t *)arg;
|
thread_t *tp = (thread_t *)arg;
|
||||||
#else
|
#else
|
||||||
(void)arg;
|
(void)arg;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Initializing global resources.*/
|
/* Initializing global resources.*/
|
||||||
chSemObjectInit(&gsem1, 0);
|
chSemObjectInit(&gsem1, 0);
|
||||||
chSemObjectInit(&gsem2, 0);
|
chSemObjectInit(&gsem2, 0);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
chSysLock();
|
chSysLock();
|
||||||
if (chSemGetCounterI(&gsem1) < 0)
|
if (chSemGetCounterI(&gsem1) < 0)
|
||||||
chSemSignalI(&gsem1);
|
chSemSignalI(&gsem1);
|
||||||
chSemResetI(&gsem2, 0);
|
chSemResetI(&gsem2, 0);
|
||||||
chThdResumeI(>r1, MSG_OK);
|
chThdResumeI(>r1, MSG_OK);
|
||||||
#if CH_CFG_USE_EVENTS == TRUE
|
#if CH_CFG_USE_EVENTS == TRUE
|
||||||
chEvtSignalI(tp, 0x55);
|
chEvtSignalI(tp, 0x55);
|
||||||
#endif
|
#endif
|
||||||
chSchRescheduleS();
|
chSchRescheduleS();
|
||||||
chSysUnlock();
|
chSysUnlock();
|
||||||
|
|
||||||
chThdSleepMilliseconds(250);
|
chThdSleepMilliseconds(250);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio
|
ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
@ -48,12 +48,12 @@ extern "C" {
|
||||||
/* Shared definitions. */
|
/* Shared definitions. */
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
|
||||||
#define TEST_SUITE_NAME "ChibiOS/NIL Test Suite"
|
#define TEST_SUITE_NAME "ChibiOS/NIL Test Suite"
|
||||||
|
|
||||||
extern semaphore_t gsem1, gsem2;
|
extern semaphore_t gsem1, gsem2;
|
||||||
extern thread_reference_t gtr1;
|
extern thread_reference_t gtr1;
|
||||||
extern THD_WORKING_AREA(wa_test_support, 128);
|
extern THD_WORKING_AREA(wa_test_support, 128);
|
||||||
|
|
||||||
THD_FUNCTION(test_support, arg);
|
THD_FUNCTION(test_support, arg);
|
||||||
|
|
||||||
#endif /* _SPC5_TEST_ROOT_H_ */
|
#endif /* _SPC5_TEST_ROOT_H_ */
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio
|
ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio
|
ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio
|
ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
@ -38,8 +38,8 @@
|
||||||
* Shared code.
|
* Shared code.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "ch.h"
|
#include "ch.h"
|
||||||
|
|
||||||
static semaphore_t sem1;
|
static semaphore_t sem1;
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio
|
ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio
|
ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio
|
ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio
|
ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
@ -38,10 +38,10 @@
|
||||||
* Shared code.
|
* Shared code.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#define ALLOWED_DELAY MS2ST(5)
|
#define ALLOWED_DELAY MS2ST(5)
|
||||||
#define MB_SIZE 4
|
#define MB_SIZE 4
|
||||||
|
|
||||||
static msg_t mb_buffer[MB_SIZE];
|
static msg_t mb_buffer[MB_SIZE];
|
||||||
static MAILBOX_DECL(mb1, mb_buffer, MB_SIZE);
|
static MAILBOX_DECL(mb1, mb_buffer, MB_SIZE);
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio
|
ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio
|
ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
@ -29,6 +29,8 @@
|
||||||
*
|
*
|
||||||
* <h2>Test Cases</h2>
|
* <h2>Test Cases</h2>
|
||||||
* - @subpage test_005_001
|
* - @subpage test_005_001
|
||||||
|
* - @subpage test_005_002
|
||||||
|
* - @subpage test_005_003
|
||||||
* .
|
* .
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -36,17 +38,18 @@
|
||||||
* Shared code.
|
* Shared code.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#define MEMORY_POOL_SIZE 4
|
#define MEMORY_POOL_SIZE 4
|
||||||
|
|
||||||
static uint32_t objects[MEMORY_POOL_SIZE];
|
static uint32_t objects[MEMORY_POOL_SIZE];
|
||||||
static MEMORYPOOL_DECL(mp1, sizeof (uint32_t), NULL);
|
static MEMORYPOOL_DECL(mp1, sizeof (uint32_t), NULL);
|
||||||
|
static GUARDEDMEMORYPOOL_DECL(gmp1, sizeof (uint32_t));
|
||||||
static void *null_provider(size_t size, unsigned align) {
|
|
||||||
|
static void *null_provider(size_t size, unsigned align) {
|
||||||
(void)size;
|
|
||||||
(void)align;
|
(void)size;
|
||||||
|
(void)align;
|
||||||
return NULL;
|
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
@ -54,7 +57,7 @@ static void *null_provider(size_t size, unsigned align) {
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @page test_005_001 Loading and empting the memory pool
|
* @page test_005_001 Loading and empting a memory pool
|
||||||
*
|
*
|
||||||
* <h2>Description</h2>
|
* <h2>Description</h2>
|
||||||
* The memory pool functionality is tested by loading and empting it,
|
* The memory pool functionality is tested by loading and empting it,
|
||||||
|
@ -128,12 +131,116 @@ static void test_005_001_execute(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static const testcase_t test_005_001 = {
|
static const testcase_t test_005_001 = {
|
||||||
"Loading and empting the memory pool",
|
"Loading and empting a memory pool",
|
||||||
test_005_001_setup,
|
test_005_001_setup,
|
||||||
NULL,
|
NULL,
|
||||||
test_005_001_execute
|
test_005_001_execute
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @page test_005_002 Loading and empting a guarded memory pool without waiting
|
||||||
|
*
|
||||||
|
* <h2>Description</h2>
|
||||||
|
* The memory pool functionality is tested by loading and empting it,
|
||||||
|
* all conditions are tested.
|
||||||
|
*
|
||||||
|
* <h2>Test Steps</h2>
|
||||||
|
* - Adding the objects to the pool using chGuardedPoolLoadArray().
|
||||||
|
* - Emptying the pool using chGuardedPoolAllocTimeout().
|
||||||
|
* - Now must be empty.
|
||||||
|
* - Adding the objects to the pool using chGuardedPoolFree().
|
||||||
|
* - Emptying the pool using chGuardedPoolAllocTimeout() again.
|
||||||
|
* - Now must be empty again.
|
||||||
|
* .
|
||||||
|
*/
|
||||||
|
|
||||||
|
static void test_005_002_setup(void) {
|
||||||
|
chGuardedPoolObjectInit(&gmp1, sizeof (uint32_t));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_005_002_execute(void) {
|
||||||
|
unsigned i;
|
||||||
|
|
||||||
|
/* Adding the objects to the pool using chGuardedPoolLoadArray().*/
|
||||||
|
test_set_step(1);
|
||||||
|
{
|
||||||
|
chGuardedPoolLoadArray(&gmp1, objects, MEMORY_POOL_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Emptying the pool using chGuardedPoolAllocTimeout().*/
|
||||||
|
test_set_step(2);
|
||||||
|
{
|
||||||
|
for (i = 0; i < MEMORY_POOL_SIZE; i++)
|
||||||
|
test_assert(chGuardedPoolAllocTimeout(&gmp1, TIME_IMMEDIATE) != NULL, "list empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Now must be empty.*/
|
||||||
|
test_set_step(3);
|
||||||
|
{
|
||||||
|
test_assert(chGuardedPoolAllocTimeout(&gmp1, TIME_IMMEDIATE) == NULL, "list not empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Adding the objects to the pool using chGuardedPoolFree().*/
|
||||||
|
test_set_step(4);
|
||||||
|
{
|
||||||
|
for (i = 0; i < MEMORY_POOL_SIZE; i++)
|
||||||
|
chGuardedPoolFree(&gmp1, &objects[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 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");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Now must be empty again.*/
|
||||||
|
test_set_step(6);
|
||||||
|
{
|
||||||
|
test_assert(chGuardedPoolAllocTimeout(&gmp1, TIME_IMMEDIATE) == NULL, "list not empty");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static const testcase_t test_005_002 = {
|
||||||
|
"Loading and empting a guarded memory pool without waiting",
|
||||||
|
test_005_002_setup,
|
||||||
|
NULL,
|
||||||
|
test_005_002_execute
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @page test_005_003 Guarded Memory Pools timeout
|
||||||
|
*
|
||||||
|
* <h2>Description</h2>
|
||||||
|
* The timeout features for the Guarded Memory Pools is tested.
|
||||||
|
*
|
||||||
|
* <h2>Test Steps</h2>
|
||||||
|
* - Trying to allocate with 100mS timeout, must fail because the pool
|
||||||
|
* is empty.
|
||||||
|
* .
|
||||||
|
*/
|
||||||
|
|
||||||
|
static void test_005_003_setup(void) {
|
||||||
|
chGuardedPoolObjectInit(&gmp1, sizeof (uint32_t));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_005_003_execute(void) {
|
||||||
|
|
||||||
|
/* Trying to allocate with 100mS timeout, must fail because the pool
|
||||||
|
is empty.*/
|
||||||
|
test_set_step(1);
|
||||||
|
{
|
||||||
|
test_assert(chGuardedPoolAllocTimeout(&gmp1, MS2ST(100)) == NULL, "list not empty");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static const testcase_t test_005_003 = {
|
||||||
|
"Guarded Memory Pools timeout",
|
||||||
|
test_005_003_setup,
|
||||||
|
NULL,
|
||||||
|
test_005_003_execute
|
||||||
|
};
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Exported data.
|
* Exported data.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
@ -143,5 +250,7 @@ static const testcase_t test_005_001 = {
|
||||||
*/
|
*/
|
||||||
const testcase_t * const test_sequence_005[] = {
|
const testcase_t * const test_sequence_005[] = {
|
||||||
&test_005_001,
|
&test_005_001,
|
||||||
|
&test_005_002,
|
||||||
|
&test_005_003,
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio
|
ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
|
Loading…
Reference in New Issue