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

This commit is contained in:
Giovanni Di Sirio 2016-03-10 14:57:26 +00:00
parent 6495240dcd
commit ade53fbc15
4 changed files with 378 additions and 167 deletions

View File

@ -215,6 +215,31 @@ uint32 queue_find(const char *queue_name) {
return 0; return 0;
} }
/**
* @brief Finds a timer by name.
*/
uint32 timer_find(const char *timer_name) {
osal_timer_t *otp;
/* Searching the queue in the table.*/
for (otp = &osal.timers[0]; otp < &osal.timers[OS_MAX_TIMERS]; otp++) {
/* Entering a reentrant critical zone.*/
syssts_t sts = chSysGetStatusAndLockX();
if (!otp->is_free &&
(strncmp(otp->name, timer_name, OS_MAX_API_NAME - 1) == 0)) {
/* Leaving the critical zone.*/
chSysRestoreStatusX(sts);
return (uint32)otp;
}
/* Leaving the critical zone.*/
chSysRestoreStatusX(sts);
}
return 0;
}
/*===========================================================================*/ /*===========================================================================*/
/* Module exported functions. */ /* Module exported functions. */
/*===========================================================================*/ /*===========================================================================*/
@ -429,23 +454,32 @@ int32 OS_TimerCreate(uint32 *timer_id, const char *timer_name,
/* NULL pointer checks.*/ /* NULL pointer checks.*/
if ((timer_id == NULL) || (timer_name == NULL) || if ((timer_id == NULL) || (timer_name == NULL) ||
(clock_accuracy == NULL) || (callback_ptr == NULL)) { (clock_accuracy == NULL)) {
return OS_INVALID_POINTER; return OS_INVALID_POINTER;
} }
/* NULL callback check.*/ /* NULL callback check.*/
if (callback_ptr == NULL) { if (callback_ptr == NULL) {
*timer_id = 0;
return OS_TIMER_ERR_INVALID_ARGS; return OS_TIMER_ERR_INVALID_ARGS;
} }
/* Checking timer name length.*/ /* Checking timer name length.*/
if (strlen(timer_name) >= OS_MAX_API_NAME) { if (strlen(timer_name) >= OS_MAX_API_NAME) {
*timer_id = 0;
return OS_ERR_NAME_TOO_LONG; return OS_ERR_NAME_TOO_LONG;
} }
/* Checking if the name is already taken.*/
if (timer_find(timer_name) > 0) {
*timer_id = 0;
return OS_ERR_NAME_TAKEN;
}
/* Getting object.*/ /* Getting object.*/
otp = chPoolAlloc(&osal.timers_pool); otp = chPoolAlloc(&osal.timers_pool);
if (otp == NULL) { if (otp == NULL) {
*timer_id = 0;
return OS_ERR_NO_FREE_IDS; return OS_ERR_NO_FREE_IDS;
} }
@ -552,7 +586,6 @@ int32 OS_TimerSet(uint32 timer_id, uint32 start_time, uint32 interval_time) {
* @api * @api
*/ */
int32 OS_TimerGetIdByName(uint32 *timer_id, const char *timer_name) { int32 OS_TimerGetIdByName(uint32 *timer_id, const char *timer_name) {
osal_timer_t *otp;
/* NULL pointer checks.*/ /* NULL pointer checks.*/
if ((timer_id == NULL) || (timer_name == NULL)) { if ((timer_id == NULL) || (timer_name == NULL)) {
@ -564,24 +597,12 @@ int32 OS_TimerGetIdByName(uint32 *timer_id, const char *timer_name) {
return OS_ERR_NAME_TOO_LONG; return OS_ERR_NAME_TOO_LONG;
} }
/* Searching the timer in the table.*/ /* Searching the queue.*/
for (otp = &osal.timers[0]; otp < &osal.timers[OS_MAX_QUEUES]; otp++) { *timer_id = timer_find(timer_name);
/* Entering a reentrant critical zone.*/ if (*timer_id > 0) {
syssts_t sts = chSysGetStatusAndLockX();
if (!otp->is_free &&
(strncmp(otp->name, timer_name, OS_MAX_API_NAME - 1) == 0)) {
*timer_id = (uint32)otp;
/* Leaving the critical zone.*/
chSysRestoreStatusX(sts);
return OS_SUCCESS; return OS_SUCCESS;
} }
/* Leaving the critical zone.*/
chSysRestoreStatusX(sts);
}
return OS_ERR_NAME_NOT_FOUND; return OS_ERR_NAME_NOT_FOUND;
} }

View File

@ -755,6 +755,72 @@ test_assert(err == OS_SUCCESS, "queue deletion failed");]]></value>
</step> </step>
</steps> </steps>
</case> </case>
<case>
<brief>
<value>OS_QueueGetIdByName() errors</value>
</brief>
<description>
<value>Parameters checking in OS_QueueGetIdByName() 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_QueueGetIdByName() is invoked with queue_id set to NULL, an error is expected.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[int32 err;
err = OS_QueueGetIdByName(NULL, "queue");
test_assert(err == OS_INVALID_POINTER, "NULL not detected");]]></value>
</code>
</step>
<step>
<description>
<value>OS_QueueGetIdByName() is invoked with queue_name set to NULL, an error is expected.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[int32 err;
err = OS_QueueGetIdByName(&qid, NULL);
test_assert(err == OS_INVALID_POINTER, "NULL not detected");]]></value>
</code>
</step>
<step>
<description>
<value>OS_QueueGetIdByName() is invoked with a very long task name, an error is expected.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[int32 err;
err = OS_QueueGetIdByName(&qid, "very very long queue name");
test_assert(err == OS_ERR_NAME_TOO_LONG, "name limit not detected");]]></value>
</code>
</step>
</steps>
</case>
<case> <case>
<brief> <brief>
<value>OS_QueuePut() and OS_QueueGet() functionality</value> <value>OS_QueuePut() and OS_QueueGet() functionality</value>
@ -856,73 +922,7 @@ test_assert_sequence("", "queue write errors occurred");]]></value>
</case> </case>
<case> <case>
<brief> <brief>
<value>OS_QueueGetIdByName() errors</value> <value>OS_QueueGet() with timeout functionality</value>
</brief>
<description>
<value>Parameters checking in OS_QueueGetIdByName() 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_QueueGetIdByName() is invoked with queue_id set to NULL, an error is expected.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[int32 err;
err = OS_QueueGetIdByName(NULL, "queue");
test_assert(err == OS_INVALID_POINTER, "NULL not detected");]]></value>
</code>
</step>
<step>
<description>
<value>OS_QueueGetIdByName() is invoked with queue_name set to NULL, an error is expected.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[int32 err;
err = OS_QueueGetIdByName(&qid, NULL);
test_assert(err == OS_INVALID_POINTER, "NULL not detected");]]></value>
</code>
</step>
<step>
<description>
<value>OS_QueueGetIdByName() is invoked with a very long task name, an error is expected.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[int32 err;
err = OS_QueueGetIdByName(&qid, "very very long queue name");
test_assert(err == OS_ERR_NAME_TOO_LONG, "name limit not detected");]]></value>
</code>
</step>
</steps>
</case>
<case>
<brief>
<value>OS_QueueGet() with timeout</value>
</brief> </brief>
<description> <description>
<value>OS_QueueGetIdByName is tested.</value> <value>OS_QueueGetIdByName is tested.</value>
@ -949,7 +949,7 @@ char data[MESSAGE_SIZE];]]></value>
<steps> <steps>
<step> <step>
<description> <description>
<value>Retrieving the queue name.</value> <value>Retrieving the queue by name.</value>
</description> </description>
<tags> <tags>
<value /> <value />
@ -1009,10 +1009,13 @@ test_assert(err == OS_QUEUE_EMPTY, "unexpected error code");]]></value>
#include "osapi.h" #include "osapi.h"
uint32 tmid; uint32 tmid;
uint32 cnt;
static void tmr_callback(uint32 timer_id) { static void tmr_callback(uint32 timer_id) {
(void)timer_id; (void)timer_id;
cnt++;
}]]></value> }]]></value>
</shared_code> </shared_code>
<cases> <cases>
@ -1109,7 +1112,7 @@ err = OS_TimerCreate(&tmid,
"failing timer", "failing timer",
&accuracy, &accuracy,
NULL); /* Error.*/ NULL); /* Error.*/
test_assert(err == OS_INVALID_POINTER, "NULL not detected");]]></value> test_assert(err == OS_TIMER_ERR_INVALID_ARGS, "NULL not detected");]]></value>
</code> </code>
</step> </step>
<step> <step>
@ -1284,7 +1287,11 @@ test_assert(err == OS_ERR_NAME_TOO_LONG, "name limit not detected");]]></value>
</condition> </condition>
<various_code> <various_code>
<setup_code> <setup_code>
<value><![CDATA[tmid = 0;]]></value> <value><![CDATA[uint32 accuracy;
cnt = 0;
tmid = 0;
(void) OS_TimerCreate(&tmid, "test timer", &accuracy, tmr_callback);]]></value>
</setup_code> </setup_code>
<teardown_code> <teardown_code>
<value><![CDATA[if (tmid != 0) { <value><![CDATA[if (tmid != 0) {
@ -1292,10 +1299,51 @@ test_assert(err == OS_ERR_NAME_TOO_LONG, "name limit not detected");]]></value>
}]]></value> }]]></value>
</teardown_code> </teardown_code>
<local_variables> <local_variables>
<value /> <value><![CDATA[uint32 local_tmid;]]></value>
</local_variables> </local_variables>
</various_code> </various_code>
<steps /> <steps>
<step>
<description>
<value>Retrieving the timer by name.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[int32 err;
err = OS_TimerGetIdByName(&local_tmid, "test timer");
test_assert(err == OS_SUCCESS, "timer not found");]]></value>
</code>
</step>
<step>
<description>
<value>Setting up the timer for a 70mS one-shot tick.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[uint32 err;
err = OS_TimerSet(local_tmid, 70000, 0);
test_assert(err == OS_SUCCESS, "timer setup failed");]]></value>
</code>
</step>
<step>
<description>
<value>Waiting one second then counting the occurred ticks.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[(void) OS_TaskDelay(1000);
test_assert(cnt == 1, "wrong ticks");]]></value>
</code>
</step>
</steps>
</case> </case>
<case> <case>
<brief> <brief>
@ -1309,18 +1357,78 @@ test_assert(err == OS_ERR_NAME_TOO_LONG, "name limit not detected");]]></value>
</condition> </condition>
<various_code> <various_code>
<setup_code> <setup_code>
<value><![CDATA[tmid = 0;]]></value> <value><![CDATA[uint32 accuracy;
cnt = 0;
tmid = 0;
(void) OS_TimerCreate(&tmid, "test timer", &accuracy, tmr_callback);]]></value>
</setup_code> </setup_code>
<teardown_code> <teardown_code>
<value><![CDATA[if (tmid != 0) { <value><![CDATA[if (tmid != 0) {
(void) OS_TimerSet(tmid, 0, 0);
(void) OS_TimerDelete(tmid); (void) OS_TimerDelete(tmid);
}]]></value> }]]></value>
</teardown_code> </teardown_code>
<local_variables> <local_variables>
<value /> <value><![CDATA[uint32 local_tmid;]]></value>
</local_variables> </local_variables>
</various_code> </various_code>
<steps /> <steps>
<step>
<description>
<value>Retrieving the timer by name.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[int32 err;
err = OS_TimerGetIdByName(&local_tmid, "test timer");
test_assert(err == OS_SUCCESS, "timer not found");]]></value>
</code>
</step>
<step>
<description>
<value>Setting up the timer for a 70mS periodic tick.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[uint32 err;
err = OS_TimerSet(local_tmid, 70000, 70000);
test_assert(err == OS_SUCCESS, "timer setup failed");]]></value>
</code>
</step>
<step>
<description>
<value>Waiting one second then counting the occurred ticks.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[(void) OS_TaskDelay(1000);
test_assert(cnt == 14, "wrong ticks");]]></value>
</code>
</step>
<step>
<description>
<value>Stopping the timer.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[uint32 err;
err = OS_TimerSet(local_tmid, 0, 0);
test_assert(err == OS_SUCCESS, "timer stop failed");]]></value>
</code>
</step>
</steps>
</case> </case>
</cases> </cases>
</sequence> </sequence>

View File

@ -167,7 +167,63 @@ static const testcase_t test_002_001 = {
}; };
/** /**
* @page test_002_002 OS_QueuePut() and OS_QueueGet() functionality * @page test_002_002 OS_QueueGetIdByName() errors
*
* <h2>Description</h2>
* Parameters checking in OS_QueueGetIdByName() is tested.
*
* <h2>Test Steps</h2>
* - OS_QueueGetIdByName() is invoked with queue_id set to NULL, an
* error is expected.
* - OS_QueueGetIdByName() is invoked with queue_name set to NULL, an
* error is expected.
* - OS_QueueGetIdByName() is invoked with a very long task name, an
* error is expected.
* .
*/
static void test_002_002_execute(void) {
/* OS_QueueGetIdByName() is invoked with queue_id set to NULL, an
error is expected.*/
test_set_step(1);
{
int32 err;
err = OS_QueueGetIdByName(NULL, "queue");
test_assert(err == OS_INVALID_POINTER, "NULL not detected");
}
/* OS_QueueGetIdByName() is invoked with queue_name set to NULL, an
error is expected.*/
test_set_step(2);
{
int32 err;
err = OS_QueueGetIdByName(&qid, NULL);
test_assert(err == OS_INVALID_POINTER, "NULL not detected");
}
/* OS_QueueGetIdByName() is invoked with a very long task name, an
error is expected.*/
test_set_step(3);
{
int32 err;
err = OS_QueueGetIdByName(&qid, "very very long queue name");
test_assert(err == OS_ERR_NAME_TOO_LONG, "name limit not detected");
}
}
static const testcase_t test_002_002 = {
"OS_QueueGetIdByName() errors",
NULL,
NULL,
test_002_002_execute
};
/**
* @page test_002_003 OS_QueuePut() and OS_QueueGet() functionality
* *
* <h2>Description</h2> * <h2>Description</h2>
* A task writes on a queue, the messages are retrieved on the other * A task writes on a queue, the messages are retrieved on the other
@ -181,12 +237,12 @@ static const testcase_t test_002_001 = {
* . * .
*/ */
static void test_002_002_setup(void) { static void test_002_003_setup(void) {
qid = 0; qid = 0;
tid = 0; tid = 0;
} }
static void test_002_002_teardown(void) { static void test_002_003_teardown(void) {
if (qid != 0) { if (qid != 0) {
(void) OS_QueueDelete(qid); (void) OS_QueueDelete(qid);
} }
@ -196,7 +252,7 @@ static void test_002_002_teardown(void) {
} }
} }
static void test_002_002_execute(void) { static void test_002_003_execute(void) {
uint32 tid; uint32 tid;
unsigned i; unsigned i;
@ -248,77 +304,21 @@ static void test_002_002_execute(void) {
} }
} }
static const testcase_t test_002_002 = {
"OS_QueuePut() and OS_QueueGet() functionality",
test_002_002_setup,
test_002_002_teardown,
test_002_002_execute
};
/**
* @page test_002_003 OS_QueueGetIdByName() errors
*
* <h2>Description</h2>
* Parameters checking in OS_QueueGetIdByName() is tested.
*
* <h2>Test Steps</h2>
* - OS_QueueGetIdByName() is invoked with queue_id set to NULL, an
* error is expected.
* - OS_QueueGetIdByName() is invoked with queue_name set to NULL, an
* error is expected.
* - OS_QueueGetIdByName() is invoked with a very long task name, an
* error is expected.
* .
*/
static void test_002_003_execute(void) {
/* OS_QueueGetIdByName() is invoked with queue_id set to NULL, an
error is expected.*/
test_set_step(1);
{
int32 err;
err = OS_QueueGetIdByName(NULL, "queue");
test_assert(err == OS_INVALID_POINTER, "NULL not detected");
}
/* OS_QueueGetIdByName() is invoked with queue_name set to NULL, an
error is expected.*/
test_set_step(2);
{
int32 err;
err = OS_QueueGetIdByName(&qid, NULL);
test_assert(err == OS_INVALID_POINTER, "NULL not detected");
}
/* OS_QueueGetIdByName() is invoked with a very long task name, an
error is expected.*/
test_set_step(3);
{
int32 err;
err = OS_QueueGetIdByName(&qid, "very very long queue name");
test_assert(err == OS_ERR_NAME_TOO_LONG, "name limit not detected");
}
}
static const testcase_t test_002_003 = { static const testcase_t test_002_003 = {
"OS_QueueGetIdByName() errors", "OS_QueuePut() and OS_QueueGet() functionality",
NULL, test_002_003_setup,
NULL, test_002_003_teardown,
test_002_003_execute test_002_003_execute
}; };
/** /**
* @page test_002_004 OS_QueueGet() with timeout * @page test_002_004 OS_QueueGet() with timeout functionality
* *
* <h2>Description</h2> * <h2>Description</h2>
* OS_QueueGetIdByName is tested. * OS_QueueGetIdByName is tested.
* *
* <h2>Test Steps</h2> * <h2>Test Steps</h2>
* - Retrieving the queue name. * - Retrieving the queue by name.
* - Get operation with a one second timeout, an error is expected. * - Get operation with a one second timeout, an error is expected.
* - Get operation in non-blocking mode, an error is expected. * - Get operation in non-blocking mode, an error is expected.
* . * .
@ -340,7 +340,7 @@ static void test_002_004_execute(void) {
uint32 copied; uint32 copied;
char data[MESSAGE_SIZE]; char data[MESSAGE_SIZE];
/* Retrieving the queue name.*/ /* Retrieving the queue by name.*/
test_set_step(1); test_set_step(1);
{ {
int32 err; int32 err;
@ -369,7 +369,7 @@ static void test_002_004_execute(void) {
} }
static const testcase_t test_002_004 = { static const testcase_t test_002_004 = {
"OS_QueueGet() with timeout", "OS_QueueGet() with timeout functionality",
test_002_004_setup, test_002_004_setup,
test_002_004_teardown, test_002_004_teardown,
test_002_004_execute test_002_004_execute

View File

@ -45,10 +45,13 @@
#include "osapi.h" #include "osapi.h"
uint32 tmid; uint32 tmid;
uint32 cnt;
static void tmr_callback(uint32 timer_id) { static void tmr_callback(uint32 timer_id) {
(void)timer_id; (void)timer_id;
cnt++;
} }
/**************************************************************************** /****************************************************************************
@ -137,7 +140,7 @@ static void test_003_001_execute(void) {
"failing timer", "failing timer",
&accuracy, &accuracy,
NULL); /* Error.*/ NULL); /* Error.*/
test_assert(err == OS_INVALID_POINTER, "NULL not detected"); test_assert(err == OS_TIMER_ERR_INVALID_ARGS, "NULL not detected");
} }
/* OS_TimerCreate() is invoked with a very long timer name, an error /* OS_TimerCreate() is invoked with a very long timer name, an error
@ -285,10 +288,18 @@ static const testcase_t test_003_003 = {
* A timer is tested in one-shot mode. * A timer is tested in one-shot mode.
* *
* <h2>Test Steps</h2> * <h2>Test Steps</h2>
* - Retrieving the timer by name.
* - Setting up the timer for a 70mS one-shot tick.
* - Waiting one second then counting the occurred ticks.
* .
*/ */
static void test_003_004_setup(void) { static void test_003_004_setup(void) {
uint32 accuracy;
cnt = 0;
tmid = 0; tmid = 0;
(void) OS_TimerCreate(&tmid, "test timer", &accuracy, tmr_callback);
} }
static void test_003_004_teardown(void) { static void test_003_004_teardown(void) {
@ -298,6 +309,32 @@ static void test_003_004_teardown(void) {
} }
static void test_003_004_execute(void) { static void test_003_004_execute(void) {
uint32 local_tmid;
/* Retrieving the timer by name.*/
test_set_step(1);
{
int32 err;
err = OS_TimerGetIdByName(&local_tmid, "test timer");
test_assert(err == OS_SUCCESS, "timer not found");
}
/* Setting up the timer for a 70mS one-shot tick.*/
test_set_step(2);
{
uint32 err;
err = OS_TimerSet(local_tmid, 70000, 0);
test_assert(err == OS_SUCCESS, "timer setup failed");
}
/* Waiting one second then counting the occurred ticks.*/
test_set_step(3);
{
(void) OS_TaskDelay(1000);
test_assert(cnt == 1, "wrong ticks");
}
} }
static const testcase_t test_003_004 = { static const testcase_t test_003_004 = {
@ -314,19 +351,64 @@ static const testcase_t test_003_004 = {
* A timer is tested in periodic mode. * A timer is tested in periodic mode.
* *
* <h2>Test Steps</h2> * <h2>Test Steps</h2>
* - Retrieving the timer by name.
* - Setting up the timer for a 70mS periodic tick.
* - Waiting one second then counting the occurred ticks.
* - Stopping the timer.
* .
*/ */
static void test_003_005_setup(void) { static void test_003_005_setup(void) {
uint32 accuracy;
cnt = 0;
tmid = 0; tmid = 0;
(void) OS_TimerCreate(&tmid, "test timer", &accuracy, tmr_callback);
} }
static void test_003_005_teardown(void) { static void test_003_005_teardown(void) {
if (tmid != 0) { if (tmid != 0) {
(void) OS_TimerSet(tmid, 0, 0);
(void) OS_TimerDelete(tmid); (void) OS_TimerDelete(tmid);
} }
} }
static void test_003_005_execute(void) { static void test_003_005_execute(void) {
uint32 local_tmid;
/* Retrieving the timer by name.*/
test_set_step(1);
{
int32 err;
err = OS_TimerGetIdByName(&local_tmid, "test timer");
test_assert(err == OS_SUCCESS, "timer not found");
}
/* Setting up the timer for a 70mS periodic tick.*/
test_set_step(2);
{
uint32 err;
err = OS_TimerSet(local_tmid, 70000, 70000);
test_assert(err == OS_SUCCESS, "timer setup failed");
}
/* Waiting one second then counting the occurred ticks.*/
test_set_step(3);
{
(void) OS_TaskDelay(1000);
test_assert(cnt == 14, "wrong ticks");
}
/* Stopping the timer.*/
test_set_step(4);
{
uint32 err;
err = OS_TimerSet(local_tmid, 0, 0);
test_assert(err == OS_SUCCESS, "timer stop failed");
}
} }
static const testcase_t test_003_005 = { static const testcase_t test_003_005 = {