aboutsummaryrefslogtreecommitdiffstats
path: root/test/oslib/source/test/oslib_test_sequence_002.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/oslib/source/test/oslib_test_sequence_002.c')
-rw-r--r--test/oslib/source/test/oslib_test_sequence_002.c234
1 files changed, 45 insertions, 189 deletions
diff --git a/test/oslib/source/test/oslib_test_sequence_002.c b/test/oslib/source/test/oslib_test_sequence_002.c
index bd661ce13..406b4f21d 100644
--- a/test/oslib/source/test/oslib_test_sequence_002.c
+++ b/test/oslib/source/test/oslib_test_sequence_002.c
@@ -21,259 +21,121 @@
* @file oslib_test_sequence_002.c
* @brief Test Sequence 002 code.
*
- * @page oslib_test_sequence_002 [2] Memory Pools
+ * @page oslib_test_sequence_002 [2] Pipes
*
* File: @ref oslib_test_sequence_002.c
*
* <h2>Description</h2>
* This sequence tests the ChibiOS library functionalities related to
- * memory pools.
+ * pipes.
*
* <h2>Conditions</h2>
* This sequence is only executed if the following preprocessor condition
* evaluates to true:
- * - CH_CFG_USE_MEMPOOLS
+ * - CH_CFG_USE_PIPES
* .
*
* <h2>Test Cases</h2>
* - @subpage oslib_test_002_001
- * - @subpage oslib_test_002_002
- * - @subpage oslib_test_002_003
* .
*/
-#if (CH_CFG_USE_MEMPOOLS) || defined(__DOXYGEN__)
+#if (CH_CFG_USE_PIPES) || defined(__DOXYGEN__)
/****************************************************************************
* Shared code.
****************************************************************************/
-#define MEMORY_POOL_SIZE 4
+#define PIPE_SIZE 16
-static uint32_t objects[MEMORY_POOL_SIZE];
-static MEMORYPOOL_DECL(mp1, sizeof (uint32_t), PORT_NATURAL_ALIGN, NULL);
+static uint8_t buffer[PIPE_SIZE];
+static PIPE_DECL(pipe1, buffer, PIPE_SIZE);
-#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 const uint8_t pipe_pattern[] = "0123456789ABCDEF";
/****************************************************************************
* Test cases.
****************************************************************************/
/**
- * @page oslib_test_002_001 [2.1] Loading and emptying a memory pool
+ * @page oslib_test_002_001 [2.1] Loading and emptying a pipe, non blocking
*
* <h2>Description</h2>
- * The memory pool functionality is tested by loading and emptying it,
- * all conditions are tested.
+ * The pipe functionality is tested by loading and emptying it, all
+ * conditions are tested.
*
* <h2>Test Steps</h2>
- * - [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.
+ * - [2.1.1] Filling whole pipe.
+ * - [2.1.2] Emptying pipe.
+ * - [2.1.3].
+ * - [2.1.4].
+ * - [2.1.5].
+ * - [2.1.6].
* .
*/
static void oslib_test_002_001_setup(void) {
- chPoolObjectInit(&mp1, sizeof (uint32_t), NULL);
+ chPipeObjectInit(&pipe1, buffer, PIPE_SIZE);
}
static void oslib_test_002_001_execute(void) {
unsigned i;
- /* [2.1.1] Adding the objects to the pool using chPoolLoadArray().*/
+ /* [2.1.1] Filling whole pipe.*/
test_set_step(1);
{
- chPoolLoadArray(&mp1, objects, MEMORY_POOL_SIZE);
+ msg_t msg;
+
+ msg = chPipeWriteTimeout(&pipe1, pipe_pattern, PIPE_SIZE, TIME_IMMEDIATE);
+ test_assert(msg == PIPE_SIZE, "wrong size");
+ test_assert((pipe1.rdptr == pipe1.buffer) &&
+ (pipe1.wrptr == pipe1.buffer) &&
+ (pipe1.cnt == PIPE_SIZE),
+ "invalid pipe state");
}
- /* [2.1.2] Emptying the pool using chPoolAlloc().*/
+ /* [2.1.2] Emptying pipe.*/
test_set_step(2);
{
- for (i = 0; i < MEMORY_POOL_SIZE; i++)
- test_assert(chPoolAlloc(&mp1) != NULL, "list empty");
+ msg_t msg;
+ uint8_t buf[PIPE_SIZE];
+
+ msg = chPipeReadTimeout(&pipe1, buf, PIPE_SIZE, TIME_IMMEDIATE);
+ test_assert(msg == PIPE_SIZE, "wrong size");
+ test_assert((pipe1.rdptr == pipe1.buffer) &&
+ (pipe1.wrptr == pipe1.buffer) &&
+ (pipe1.cnt == 0),
+ "invalid pipe state");
}
- /* [2.1.3] Now must be empty.*/
+ /* [2.1.3].*/
test_set_step(3);
{
- test_assert(chPoolAlloc(&mp1) == NULL, "list not empty");
}
- /* [2.1.4] Adding the objects to the pool using chPoolFree().*/
+ /* [2.1.4].*/
test_set_step(4);
{
- for (i = 0; i < MEMORY_POOL_SIZE; i++)
- chPoolFree(&mp1, &objects[i]);
}
- /* [2.1.5] Emptying the pool using chPoolAlloc() again.*/
+ /* [2.1.5].*/
test_set_step(5);
{
- for (i = 0; i < MEMORY_POOL_SIZE; i++)
- test_assert(chPoolAlloc(&mp1) != NULL, "list empty");
}
- /* [2.1.6] Now must be empty again.*/
+ /* [2.1.6].*/
test_set_step(6);
{
- test_assert(chPoolAlloc(&mp1) == NULL, "list not empty");
- }
-
- /* [2.1.7] 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 oslib_test_002_001 = {
- "Loading and emptying a memory pool",
+ "Loading and emptying a pipe, non blocking",
oslib_test_002_001_setup,
NULL,
oslib_test_002_001_execute
};
-#if (CH_CFG_USE_SEMAPHORES) || defined(__DOXYGEN__)
-/**
- * @page oslib_test_002_002 [2.2] Loading and emptying a guarded memory pool without waiting
- *
- * <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
- * .
- *
- * <h2>Test Steps</h2>
- * - [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) {
- chGuardedPoolObjectInit(&gmp1, sizeof (uint32_t));
-}
-
-static void oslib_test_002_002_execute(void) {
- unsigned i;
-
- /* [2.2.1] Adding the objects to the pool using
- chGuardedPoolLoadArray().*/
- test_set_step(1);
- {
- chGuardedPoolLoadArray(&gmp1, objects, MEMORY_POOL_SIZE);
- }
-
- /* [2.2.2] 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");
- }
-
- /* [2.2.3] Now must be empty.*/
- test_set_step(3);
- {
- test_assert(chGuardedPoolAllocTimeout(&gmp1, TIME_IMMEDIATE) == NULL, "list not empty");
- }
-
- /* [2.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]);
- }
-
- /* [2.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");
- }
-
- /* [2.2.6] Now must be empty again.*/
- test_set_step(6);
- {
- test_assert(chGuardedPoolAllocTimeout(&gmp1, TIME_IMMEDIATE) == NULL, "list not empty");
- }
-}
-
-static const testcase_t oslib_test_002_002 = {
- "Loading and emptying a guarded memory pool without waiting",
- oslib_test_002_002_setup,
- 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] 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>
- * - [2.3.1] Trying to allocate with 100mS timeout, must fail because
- * the pool is empty.
- * .
- */
-
-static void oslib_test_002_003_setup(void) {
- chGuardedPoolObjectInit(&gmp1, sizeof (uint32_t));
-}
-
-static void oslib_test_002_003_execute(void) {
-
- /* [2.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_002_003 = {
- "Guarded Memory Pools timeout",
- oslib_test_002_003_setup,
- NULL,
- oslib_test_002_003_execute
-};
-#endif /* CH_CFG_USE_SEMAPHORES */
-
/****************************************************************************
* Exported data.
****************************************************************************/
@@ -283,21 +145,15 @@ 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 Memory Pools.
+ * @brief Pipes.
*/
const testsequence_t oslib_test_sequence_002 = {
- "Memory Pools",
+ "Pipes",
oslib_test_sequence_002_array
};
-#endif /* CH_CFG_USE_MEMPOOLS */
+#endif /* CH_CFG_USE_PIPES */