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

This commit is contained in:
Giovanni Di Sirio 2016-03-18 09:21:32 +00:00
parent cc04b48370
commit 3a48ef2df6
7 changed files with 302 additions and 2 deletions

View File

@ -33,7 +33,7 @@
<intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="2"/> <intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="2"/>
<stringAttribute key="org.eclipse.cdt.launch.COREFILE_PATH" value=""/> <stringAttribute key="org.eclipse.cdt.launch.COREFILE_PATH" value=""/>
<stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_REGISTER_GROUPS" value=""/> <stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_REGISTER_GROUPS" value=""/>
<stringAttribute key="org.eclipse.cdt.launch.FORMAT" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&lt;contentList&gt;&lt;content id=&quot;r0-(format)&quot; val=&quot;4&quot;/&gt;&lt;content id=&quot;r1-(format)&quot; val=&quot;4&quot;/&gt;&lt;/contentList&gt;"/> <stringAttribute key="org.eclipse.cdt.launch.FORMAT" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&lt;contentList&gt;&lt;content id=&quot;r1-(format)&quot; val=&quot;4&quot;/&gt;&lt;content id=&quot;r0-(format)&quot; val=&quot;4&quot;/&gt;&lt;/contentList&gt;"/>
<stringAttribute key="org.eclipse.cdt.launch.GLOBAL_VARIABLES" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;globalVariableList/&gt;&#13;&#10;"/> <stringAttribute key="org.eclipse.cdt.launch.GLOBAL_VARIABLES" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;globalVariableList/&gt;&#13;&#10;"/>
<stringAttribute key="org.eclipse.cdt.launch.MEMORY_BLOCKS" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;memoryBlockExpressionList/&gt;&#13;&#10;"/> <stringAttribute key="org.eclipse.cdt.launch.MEMORY_BLOCKS" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;memoryBlockExpressionList/&gt;&#13;&#10;"/>
<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="./build/ch.elf"/> <stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="./build/ch.elf"/>

View File

@ -916,6 +916,138 @@ test_assert(msg1 == MSG_TIMEOUT, "wrong wake-up message");]]></value>
</case> </case>
</cases> </cases>
</sequence> </sequence>
<sequence>
<type index="0">
<value>Internal Tests</value>
</type>
<brief>
<value>Memory Pools.</value>
</brief>
<description>
<value>This sequence tests the ChibiOS/NIL functionalities related to memory pools.</value>
</description>
<shared_code>
<value><![CDATA[#define MEMORY_POOL_SIZE 4
static uint32_t objects[MEMORY_POOL_SIZE];
static MEMORYPOOL_DECL(mp1, sizeof (uint32_t), NULL);
static void *null_provider(size_t size, unsigned align) {
(void)size;
(void)align;
return NULL;
}]]></value>
</shared_code>
<cases>
<case>
<brief>
<value>Loading and empting the memory pool.</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[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>
</cases>
</sequence>
</sequences> </sequences>
</instance> </instance>
</instances> </instances>

View File

@ -25,6 +25,7 @@
* - @subpage test_sequence_002 * - @subpage test_sequence_002
* - @subpage test_sequence_003 * - @subpage test_sequence_003
* - @subpage test_sequence_004 * - @subpage test_sequence_004
* - @subpage test_sequence_005
* . * .
*/ */
@ -52,6 +53,7 @@ const testcase_t * const *test_suite[] = {
test_sequence_002, test_sequence_002,
test_sequence_003, test_sequence_003,
test_sequence_004, test_sequence_004,
test_sequence_005,
NULL NULL
}; };

View File

@ -29,6 +29,7 @@
#include "test_sequence_002.h" #include "test_sequence_002.h"
#include "test_sequence_003.h" #include "test_sequence_003.h"
#include "test_sequence_004.h" #include "test_sequence_004.h"
#include "test_sequence_005.h"
/*===========================================================================*/ /*===========================================================================*/
/* External declarations. */ /* External declarations. */

View File

@ -0,0 +1,147 @@
/*
ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "hal.h"
#include "ch_test.h"
#include "test_root.h"
/**
* @page test_sequence_005 Memory Pools
*
* File: @ref test_sequence_005.c
*
* <h2>Description</h2>
* This sequence tests the ChibiOS/NIL functionalities related to
* memory pools.
*
* <h2>Test Cases</h2>
* - @subpage test_005_001
* .
*/
/****************************************************************************
* Shared code.
****************************************************************************/
#define MEMORY_POOL_SIZE 4
static uint32_t objects[MEMORY_POOL_SIZE];
static MEMORYPOOL_DECL(mp1, sizeof (uint32_t), NULL);
static void *null_provider(size_t size, unsigned align) {
(void)size;
(void)align;
return NULL;
}
/****************************************************************************
* Test cases.
****************************************************************************/
/**
* @page test_005_001 Loading and empting the memory pool
*
* <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 chPoolLoadArray().
* - Emptying the pool using chPoolAlloc().
* - Now must be empty.
* - Adding the objects to the pool using chPoolFree().
* - Emptying the pool using chPoolAlloc() again.
* - Now must be empty again.
* - Covering the case where a provider is unable to return more
* memory.
* .
*/
static void test_005_001_setup(void) {
chPoolObjectInit(&mp1, sizeof (uint32_t), NULL);
}
static void test_005_001_execute(void) {
unsigned i;
/* Adding the objects to the pool using chPoolLoadArray().*/
test_set_step(1);
{
chPoolLoadArray(&mp1, objects, MEMORY_POOL_SIZE);
}
/* Emptying the pool using chPoolAlloc().*/
test_set_step(2);
{
for (i = 0; i < MEMORY_POOL_SIZE; i++)
test_assert(chPoolAlloc(&mp1) != NULL, "list empty");
}
/* Now must be empty.*/
test_set_step(3);
{
test_assert(chPoolAlloc(&mp1) == NULL, "list not empty");
}
/* Adding the objects to the pool using chPoolFree().*/
test_set_step(4);
{
for (i = 0; i < MEMORY_POOL_SIZE; i++)
chPoolFree(&mp1, &objects[i]);
}
/* Emptying the pool using chPoolAlloc() again.*/
test_set_step(5);
{
for (i = 0; i < MEMORY_POOL_SIZE; i++)
test_assert(chPoolAlloc(&mp1) != NULL, "list empty");
}
/* Now must be empty again.*/
test_set_step(6);
{
test_assert(chPoolAlloc(&mp1) == NULL, "list not empty");
}
/* Covering the case where a provider is unable to return more
memory.*/
test_set_step(7);
{
chPoolObjectInit(&mp1, sizeof (uint32_t), null_provider);
test_assert(chPoolAlloc(&mp1) == NULL, "provider returned memory");
}
}
static const testcase_t test_005_001 = {
"Loading and empting the memory pool",
test_005_001_setup,
NULL,
test_005_001_execute
};
/****************************************************************************
* Exported data.
****************************************************************************/
/**
* @brief Memory Pools.
*/
const testcase_t * const test_sequence_005[] = {
&test_005_001,
NULL
};

View File

@ -0,0 +1,17 @@
/*
ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
extern const testcase_t * const test_sequence_005[];

View File

@ -4,7 +4,8 @@ TESTSRC = ${CHIBIOS}/test/lib/ch_test.c \
${CHIBIOS}/test/nil/source/test/test_sequence_001.c \ ${CHIBIOS}/test/nil/source/test/test_sequence_001.c \
${CHIBIOS}/test/nil/source/test/test_sequence_002.c \ ${CHIBIOS}/test/nil/source/test/test_sequence_002.c \
${CHIBIOS}/test/nil/source/test/test_sequence_003.c \ ${CHIBIOS}/test/nil/source/test/test_sequence_003.c \
${CHIBIOS}/test/nil/source/test/test_sequence_004.c ${CHIBIOS}/test/nil/source/test/test_sequence_004.c \
${CHIBIOS}/test/nil/source/test/test_sequence_005.c
# Required include directories # Required include directories
TESTINC = ${CHIBIOS}/test/lib \ TESTINC = ${CHIBIOS}/test/lib \