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

This commit is contained in:
Giovanni Di Sirio 2016-03-09 14:35:51 +00:00
parent 8b32e5715e
commit 8795d60114
5 changed files with 194 additions and 35 deletions

View File

@ -190,6 +190,31 @@ static void timer_handler(void *p) {
} }
} }
/**
* @brief Finds a queue by name.
*/
uint32 queue_find(const char *queue_name) {
osal_queue_t *oqp;
/* Searching the queue in the table.*/
for (oqp = &osal.queues[0]; oqp < &osal.queues[OS_MAX_QUEUES]; oqp++) {
/* Entering a reentrant critical zone.*/
syssts_t sts = chSysGetStatusAndLockX();
if (!oqp->is_free &&
(strncmp(oqp->name, queue_name, OS_MAX_API_NAME - 1) == 0)) {
/* Leaving the critical zone.*/
chSysRestoreStatusX(sts);
return (uint32)oqp;
}
/* Leaving the critical zone.*/
chSysRestoreStatusX(sts);
}
return 0;
}
/*===========================================================================*/ /*===========================================================================*/
/* Module exported functions. */ /* Module exported functions. */
/*===========================================================================*/ /*===========================================================================*/
@ -225,40 +250,40 @@ int32 OS_API_Init(void) {
sizeof (osal_timer_t), sizeof (osal_timer_t),
NULL); NULL);
chPoolLoadArray(&osal.timers_pool, chPoolLoadArray(&osal.timers_pool,
&osal.timers, &osal.timers[0],
sizeof (osal_timer_t)); OS_MAX_TIMERS);
/* Queues pool initialization.*/ /* Queues pool initialization.*/
chPoolObjectInit(&osal.queues_pool, chPoolObjectInit(&osal.queues_pool,
sizeof (osal_queue_t), sizeof (osal_queue_t),
NULL); NULL);
chPoolLoadArray(&osal.queues_pool, chPoolLoadArray(&osal.queues_pool,
&osal.queues, &osal.queues[0],
sizeof (osal_queue_t)); OS_MAX_QUEUES);
/* Binary Semaphores pool initialization.*/ /* Binary Semaphores pool initialization.*/
chPoolObjectInit(&osal.binary_semaphores_pool, chPoolObjectInit(&osal.binary_semaphores_pool,
sizeof (binary_semaphore_t), sizeof (binary_semaphore_t),
NULL); NULL);
chPoolLoadArray(&osal.binary_semaphores_pool, chPoolLoadArray(&osal.binary_semaphores_pool,
&osal.binary_semaphores, &osal.binary_semaphores[0],
sizeof (binary_semaphore_t)); OS_MAX_BIN_SEMAPHORES);
/* Counter Semaphores pool initialization.*/ /* Counter Semaphores pool initialization.*/
chPoolObjectInit(&osal.count_semaphores_pool, chPoolObjectInit(&osal.count_semaphores_pool,
sizeof (semaphore_t), sizeof (semaphore_t),
NULL); NULL);
chPoolLoadArray(&osal.count_semaphores_pool, chPoolLoadArray(&osal.count_semaphores_pool,
&osal.count_semaphores, &osal.count_semaphores[0],
sizeof (semaphore_t)); OS_MAX_COUNT_SEMAPHORES);
/* Mutexes pool initialization.*/ /* Mutexes pool initialization.*/
chPoolObjectInit(&osal.mutexes_pool, chPoolObjectInit(&osal.mutexes_pool,
sizeof (mutex_t), sizeof (mutex_t),
NULL); NULL);
chPoolLoadArray(&osal.mutexes_pool, chPoolLoadArray(&osal.mutexes_pool,
&osal.mutexes, &osal.mutexes[0],
sizeof (mutex_t)); OS_MAX_MUTEXES);
return OS_SUCCESS; return OS_SUCCESS;
} }
@ -635,18 +660,27 @@ int32 OS_QueueCreate(uint32 *queue_id, const char *queue_name,
/* Checking queue name length.*/ /* Checking queue name length.*/
if (strlen(queue_name) >= OS_MAX_API_NAME) { if (strlen(queue_name) >= OS_MAX_API_NAME) {
*queue_id = 0;
return OS_ERR_NAME_TOO_LONG; return OS_ERR_NAME_TOO_LONG;
} }
/* Checking if the name is already taken.*/
if (queue_find(queue_name) > 0) {
*queue_id = 0;
return OS_ERR_NAME_TAKEN;
}
/* Checks on queue limits. There is no dedicated error code.*/ /* Checks on queue limits. There is no dedicated error code.*/
if ((data_size < MIN_MESSAGE_SIZE) || (data_size < MAX_MESSAGE_SIZE) || if ((data_size < MIN_MESSAGE_SIZE) || (data_size > MAX_MESSAGE_SIZE) ||
(queue_depth < MIN_QUEUE_DEPTH) || (queue_depth < MAX_QUEUE_DEPTH)) { (queue_depth < MIN_QUEUE_DEPTH) || (queue_depth > MAX_QUEUE_DEPTH)) {
*queue_id = 0;
return OS_ERROR; return OS_ERROR;
} }
/* Getting object.*/ /* Getting object.*/
oqp = chPoolAlloc(&osal.queues_pool); oqp = chPoolAlloc(&osal.queues_pool);
if (oqp == NULL) { if (oqp == NULL) {
*queue_id = 0;
return OS_ERR_NO_FREE_IDS; return OS_ERR_NO_FREE_IDS;
} }
@ -656,6 +690,7 @@ int32 OS_QueueCreate(uint32 *queue_id, const char *queue_name,
msgsize * (size_t)queue_depth, msgsize * (size_t)queue_depth,
PORT_NATURAL_ALIGN); PORT_NATURAL_ALIGN);
if (oqp->mb_buffer == NULL) { if (oqp->mb_buffer == NULL) {
*queue_id = 0;
return OS_ERROR; return OS_ERROR;
} }
@ -664,6 +699,7 @@ int32 OS_QueueCreate(uint32 *queue_id, const char *queue_name,
sizeof (msg_t) * (size_t)queue_depth, sizeof (msg_t) * (size_t)queue_depth,
PORT_NATURAL_ALIGN); PORT_NATURAL_ALIGN);
if (oqp->q_buffer == NULL) { if (oqp->q_buffer == NULL) {
*queue_id = 0;
chHeapFree(oqp->mb_buffer); chHeapFree(oqp->mb_buffer);
return OS_ERROR; return OS_ERROR;
} }
@ -677,6 +713,7 @@ int32 OS_QueueCreate(uint32 *queue_id, const char *queue_name,
oqp->depth = queue_depth; oqp->depth = queue_depth;
oqp->size = data_size; oqp->size = data_size;
oqp->is_free = 0; /* Note, last.*/ oqp->is_free = 0; /* Note, last.*/
*queue_id = (uint32)oqp;
return OS_SUCCESS; return OS_SUCCESS;
} }
@ -867,7 +904,6 @@ int32 OS_QueuePut(uint32 queue_id, void *data, uint32 size, uint32 flags) {
* @api * @api
*/ */
int32 OS_QueueGetIdByName(uint32 *queue_id, const char *queue_name) { int32 OS_QueueGetIdByName(uint32 *queue_id, const char *queue_name) {
osal_queue_t *oqp;
/* NULL pointer checks.*/ /* NULL pointer checks.*/
if ((queue_id == NULL) || (queue_name == NULL)) { if ((queue_id == NULL) || (queue_name == NULL)) {
@ -879,22 +915,10 @@ int32 OS_QueueGetIdByName(uint32 *queue_id, const char *queue_name) {
return OS_ERR_NAME_TOO_LONG; return OS_ERR_NAME_TOO_LONG;
} }
/* Searching the queue in the table.*/ /* Searching the queue.*/
for (oqp = &osal.queues[0]; oqp < &osal.queues[OS_MAX_QUEUES]; oqp++) { *queue_id = queue_find(queue_name);
/* Entering a reentrant critical zone.*/ if (*queue_id > 0) {
syssts_t sts = chSysGetStatusAndLockX(); return OS_SUCCESS;
if (!oqp->is_free &&
(strncmp(oqp->name, queue_name, OS_MAX_API_NAME - 1) == 0)) {
*queue_id = (uint32)oqp;
/* Leaving the critical zone.*/
chSysRestoreStatusX(sts);
return OS_SUCCESS;
}
/* Leaving the critical zone.*/
chSysRestoreStatusX(sts);
} }
return OS_ERR_NAME_NOT_FOUND; return OS_ERR_NAME_NOT_FOUND;

View File

@ -593,11 +593,11 @@ test_assert(err == OS_SUCCESS, "deletable task creation failed");]]></value>
<value /> <value />
</tags> </tags>
<code> <code>
<value><![CDATA[int32 err; <value><![CDATA[int32 err;
(void) OS_TaskDelay(50); (void) OS_TaskDelay(50);
err = OS_TaskDelete(tid); err = OS_TaskDelete(tid);
test_assert(err == OS_SUCCESS, "delete failed"); test_assert(err == OS_SUCCESS, "delete failed");
test_assert_sequence("ABC", "events order violation");]]></value> test_assert_sequence("ABC", "events order violation");]]></value>
</code> </code>
</step> </step>
@ -605,6 +605,137 @@ test_assert_sequence("ABC", "events order violation");]]></value>
</case> </case>
</cases> </cases>
</sequence> </sequence>
<sequence>
<type index="0">
<value>Internal Tests</value>
</type>
<brief>
<value>Queues Functionality.</value>
</brief>
<description>
<value>This sequence tests the NASA OSAL over ChibiOS/RT functionalities related to queues</value>
</description>
<shared_code>
<value><![CDATA[#include "osapi.h"]]></value>
</shared_code>
<cases>
<case>
<brief>
<value>OS_QueueCreate() and OS_QueueDelete() errors</value>
</brief>
<description>
<value>Parameters checking in OS_QueueCreate() and OS_QueueDelete() is tested.</value>
</description>
<condition>
<value />
</condition>
<various_code>
<setup_code>
<value />
</setup_code>
<teardown_code>
<value />
</teardown_code>
<local_variables>
<value />
</local_variables>
</various_code>
<steps>
<step>
<description>
<value>OS_QueueCreate() is invoked with queue_id set to NULL, an error is expected.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[int32 err;
err = OS_QueueCreate(NULL, /* Error.*/
"failing queue",
4,
128,
0);
test_assert(err == OS_INVALID_POINTER, "NULL not detected");]]></value>
</code>
</step>
<step>
<description>
<value>OS_QueueCreate() is invoked with task_name set to NULL, an error is expected.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[int32 err;
uint32 qid;
err = OS_QueueCreate(&qid,
NULL, /* Error.*/
4,
128,
0);
test_assert(err == OS_INVALID_POINTER, "NULL not detected");]]></value>
</code>
</step>
<step>
<description>
<value>OS_QueueCreate() is invoked with a very long task name, an error is expected.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[int32 err;
uint32 qid;
err = OS_QueueCreate(&qid,
"very very long queue name", /* Error.*/
4,
128,
0);
test_assert(err == OS_ERR_NAME_TOO_LONG, "name limit not detected");]]></value>
</code>
</step>
<step>
<description>
<value>OS_QueueDelete() is invoked with queue_id set to -1, an error is expected.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[int32 err;
err = OS_QueueDelete((uint32)-1);
test_assert(err == OS_ERR_INVALID_ID, "wrong queue id not detected");]]></value>
</code>
</step>
<step>
<description>
<value>OS_QueueCreate() is invoked twice with duplicated name, an error is expected, then the queue is deleted using OS_DeleteQueue().</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[int32 err;
uint32 qid1, qid2;
err = OS_QueueCreate(&qid1, "my queue", 4, 128, 0);
test_assert(err == OS_SUCCESS, "queue creation failed");
err = OS_QueueCreate(&qid2, "my queue", 4, 128, 0);
test_assert(err == OS_ERR_NAME_TAKEN, "name conflict not detected");
err = OS_QueueDelete(qid1);
test_assert(err == OS_SUCCESS, "queue deletion failed");]]></value>
</code>
</step>
</steps>
</case>
</cases>
</sequence>
</sequences> </sequences>
</instance> </instance>
</instances> </instances>

View File

@ -22,6 +22,7 @@
* *
* <h2>Test Sequences</h2> * <h2>Test Sequences</h2>
* - @subpage test_sequence_001 * - @subpage test_sequence_001
* - @subpage test_sequence_002
* . * .
*/ */
@ -46,6 +47,7 @@
*/ */
const testcase_t * const *test_suite[] = { const testcase_t * const *test_suite[] = {
test_sequence_001, test_sequence_001,
test_sequence_002,
NULL NULL
}; };

View File

@ -26,6 +26,7 @@
#define _SPC5_TEST_ROOT_H_ #define _SPC5_TEST_ROOT_H_
#include "test_sequence_001.h" #include "test_sequence_001.h"
#include "test_sequence_002.h"
/*===========================================================================*/ /*===========================================================================*/
/* External declarations. */ /* External declarations. */

View File

@ -1,7 +1,8 @@
# List of all the NASA OSAL over ChibiOS/RT test files. # List of all the NASA OSAL over ChibiOS/RT test files.
TESTSRC = ${CHIBIOS}/test/lib/ch_test.c \ TESTSRC = ${CHIBIOS}/test/lib/ch_test.c \
${CHIBIOS}/test/nasa_osal/source/test/test_root.c \ ${CHIBIOS}/test/nasa_osal/source/test/test_root.c \
${CHIBIOS}/test/nasa_osal/source/test/test_sequence_001.c ${CHIBIOS}/test/nasa_osal/source/test/test_sequence_001.c \
${CHIBIOS}/test/nasa_osal/source/test/test_sequence_002.c
# Required include directories # Required include directories
TESTINC = ${CHIBIOS}/test/lib \ TESTINC = ${CHIBIOS}/test/lib \