From 3a48ef2df6ad7864e55c6b32f5450ea3d28d0943 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Fri, 18 Mar 2016 09:21:32 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@9133 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- ...F746G-DISCOVERY (OpenOCD, Flash and Run).launch | 2 +- test/nil/configuration.xml | 132 ++++++++++++++++++ test/nil/source/test/test_root.c | 2 + test/nil/source/test/test_root.h | 1 + test/nil/source/test/test_sequence_005.c | 147 +++++++++++++++++++++ test/nil/source/test/test_sequence_005.h | 17 +++ test/nil/test.mk | 3 +- 7 files changed, 302 insertions(+), 2 deletions(-) create mode 100644 test/nil/source/test/test_sequence_005.c create mode 100644 test/nil/source/test/test_sequence_005.h diff --git a/demos/STM32/NIL-STM32F746G-DISCOVERY/debug/NIL-STM32F746G-DISCOVERY (OpenOCD, Flash and Run).launch b/demos/STM32/NIL-STM32F746G-DISCOVERY/debug/NIL-STM32F746G-DISCOVERY (OpenOCD, Flash and Run).launch index a3e804ff4..6068cf8e3 100644 --- a/demos/STM32/NIL-STM32F746G-DISCOVERY/debug/NIL-STM32F746G-DISCOVERY (OpenOCD, Flash and Run).launch +++ b/demos/STM32/NIL-STM32F746G-DISCOVERY/debug/NIL-STM32F746G-DISCOVERY (OpenOCD, Flash and Run).launch @@ -33,7 +33,7 @@ - + diff --git a/test/nil/configuration.xml b/test/nil/configuration.xml index e5a2fd8b6..7488bf61f 100644 --- a/test/nil/configuration.xml +++ b/test/nil/configuration.xml @@ -916,6 +916,138 @@ test_assert(msg1 == MSG_TIMEOUT, "wrong wake-up message");]]> + + + Internal Tests + + + Memory Pools. + + + This sequence tests the ChibiOS/NIL functionalities related to memory pools. + + + + + + + + Loading and empting the memory pool. + + + The memory pool functionality is tested by loading and empting it, all conditions are tested. + + + + + + + + + + + + + + + + + + + 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. + + + + + + + + + + + + diff --git a/test/nil/source/test/test_root.c b/test/nil/source/test/test_root.c index 1d42a6d44..1516898c5 100644 --- a/test/nil/source/test/test_root.c +++ b/test/nil/source/test/test_root.c @@ -25,6 +25,7 @@ * - @subpage test_sequence_002 * - @subpage test_sequence_003 * - @subpage test_sequence_004 + * - @subpage test_sequence_005 * . */ @@ -52,6 +53,7 @@ const testcase_t * const *test_suite[] = { test_sequence_002, test_sequence_003, test_sequence_004, + test_sequence_005, NULL }; diff --git a/test/nil/source/test/test_root.h b/test/nil/source/test/test_root.h index 10daddeef..ee0c42d0b 100644 --- a/test/nil/source/test/test_root.h +++ b/test/nil/source/test/test_root.h @@ -29,6 +29,7 @@ #include "test_sequence_002.h" #include "test_sequence_003.h" #include "test_sequence_004.h" +#include "test_sequence_005.h" /*===========================================================================*/ /* External declarations. */ diff --git a/test/nil/source/test/test_sequence_005.c b/test/nil/source/test/test_sequence_005.c new file mode 100644 index 000000000..546cc9664 --- /dev/null +++ b/test/nil/source/test/test_sequence_005.c @@ -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 + * + *

Description

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

Test Cases

+ * - @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 + * + *

Description

+ * The memory pool functionality is tested by loading and empting it, + * all conditions are tested. + * + *

Test Steps

+ * - 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 +}; diff --git a/test/nil/source/test/test_sequence_005.h b/test/nil/source/test/test_sequence_005.h new file mode 100644 index 000000000..4cb8e1db0 --- /dev/null +++ b/test/nil/source/test/test_sequence_005.h @@ -0,0 +1,17 @@ +/* + ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +extern const testcase_t * const test_sequence_005[]; diff --git a/test/nil/test.mk b/test/nil/test.mk index 2fc7b8b9e..04890b633 100644 --- a/test/nil/test.mk +++ b/test/nil/test.mk @@ -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_002.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 TESTINC = ${CHIBIOS}/test/lib \ -- cgit v1.2.3