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

master
Giovanni Di Sirio 2016-03-10 12:54:10 +00:00
parent 21a8820047
commit 6495240dcd
8 changed files with 719 additions and 13 deletions

View File

@ -428,7 +428,8 @@ int32 OS_TimerCreate(uint32 *timer_id, const char *timer_name,
osal_timer_t *otp;
/* NULL pointer checks.*/
if ((timer_id == NULL) || (timer_name == NULL) || (clock_accuracy == NULL)) {
if ((timer_id == NULL) || (timer_name == NULL) ||
(clock_accuracy == NULL) || (callback_ptr == NULL)) {
return OS_INVALID_POINTER;
}

View File

@ -734,7 +734,7 @@ test_assert(err == OS_ERR_INVALID_ID, "wrong queue id not detected");]]></value>
</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>
<value>OS_QueueCreate() is invoked twice with duplicated name, an error is expected, then the queue is deleted using OS_QueueDelete().</value>
</description>
<tags>
<value />
@ -941,8 +941,8 @@ test_assert(err == OS_ERR_NAME_TOO_LONG, "name limit not detected");]]></value>
}]]></value>
</teardown_code>
<local_variables>
<value><![CDATA[uint32 local_qid;
uint32 copied;
<value><![CDATA[uint32 local_qid;
uint32 copied;
char data[MESSAGE_SIZE];]]></value>
</local_variables>
</various_code>
@ -969,9 +969,9 @@ test_assert(err == OS_SUCCESS, "queue not found");]]></value>
<value />
</tags>
<code>
<value><![CDATA[int32 err;
err = OS_QueueGet(qid, data, MESSAGE_SIZE, &copied, OS_Milli2Ticks(1000));
<value><![CDATA[int32 err;
err = OS_QueueGet(qid, data, MESSAGE_SIZE, &copied, OS_Milli2Ticks(1000));
test_assert(err == OS_QUEUE_TIMEOUT, "unexpected error code");]]></value>
</code>
</step>
@ -983,9 +983,9 @@ test_assert(err == OS_QUEUE_TIMEOUT, "unexpected error code");]]></value>
<value />
</tags>
<code>
<value><![CDATA[int32 err;
err = OS_QueueGet(qid, data, MESSAGE_SIZE, &copied, OS_CHECK);
<value><![CDATA[int32 err;
err = OS_QueueGet(qid, data, MESSAGE_SIZE, &copied, OS_CHECK);
test_assert(err == OS_QUEUE_EMPTY, "unexpected error code");]]></value>
</code>
</step>
@ -993,6 +993,337 @@ test_assert(err == OS_QUEUE_EMPTY, "unexpected error code");]]></value>
</case>
</cases>
</sequence>
<sequence>
<type index="0">
<value>Internal Tests</value>
</type>
<brief>
<value>Timers Functionality</value>
</brief>
<description>
<value>This sequence tests the NASA OSAL over ChibiOS/RT functionalities related to timers</value>
</description>
<shared_code>
<value><![CDATA[#include <string.h>
#include "osapi.h"
uint32 tmid;
static void tmr_callback(uint32 timer_id) {
(void)timer_id;
}]]></value>
</shared_code>
<cases>
<case>
<brief>
<value>OS_TimerCreate() and OS_TimerDelete() errors</value>
</brief>
<description>
<value>Parameters checking in OS_TimerCreate() and OS_TimerDelete() 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_TimerCreate() is invoked with timer_id set to NULL, an error is expected.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[int32 err;
uint32 accuracy;
err = OS_TimerCreate(NULL, /* Error.*/
"failing timer",
&accuracy,
tmr_callback);
test_assert(err == OS_INVALID_POINTER, "NULL not detected");]]></value>
</code>
</step>
<step>
<description>
<value>OS_TimerCreate() is invoked with timer_name set to NULL, an error is expected.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[int32 err;
uint32 tmid;
uint32 accuracy;
err = OS_TimerCreate(&tmid,
NULL, /* Error.*/
&accuracy,
tmr_callback);
test_assert(err == OS_INVALID_POINTER, "NULL not detected");]]></value>
</code>
</step>
<step>
<description>
<value>OS_TimerCreate() is invoked with accuracy set to NULL, an error is expected.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[int32 err;
uint32 tmid;
err = OS_TimerCreate(&tmid,
"failing timer",
NULL, /* Error.*/
tmr_callback);
test_assert(err == OS_INVALID_POINTER, "NULL not detected");]]></value>
</code>
</step>
<step>
<description>
<value>OS_TimerCreate() is invoked with callback_ptr set to NULL, an error is expected.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[int32 err;
uint32 tmid;
uint32 accuracy;
err = OS_TimerCreate(&tmid,
"failing timer",
&accuracy,
NULL); /* Error.*/
test_assert(err == OS_INVALID_POINTER, "NULL not detected");]]></value>
</code>
</step>
<step>
<description>
<value>OS_TimerCreate() is invoked with a very long timer name, an error is expected.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[int32 err;
uint32 tmid;
uint32 accuracy;
err = OS_TimerCreate(&tmid,
"very very long timer name", /* Error.*/
&accuracy,
tmr_callback);
test_assert(err == OS_ERR_NAME_TOO_LONG, "name limit not detected");]]></value>
</code>
</step>
<step>
<description>
<value>OS_TimerDelete() is invoked with timer_id set to -1, an error is expected.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[int32 err;
err = OS_TimerDelete((uint32)-1);
test_assert(err == OS_ERR_INVALID_ID, "wrong timer id not detected");]]></value>
</code>
</step>
<step>
<description>
<value>OS_TimerCreate() is invoked twice with duplicated name, an error is expected, then the queue is deleted using OS_TimerDelete().</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>
<case>
<brief>
<value>OS_TimerSet() errors</value>
</brief>
<description>
<value>Parameters checking in OS_TimerSet() 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_TimerSet() is invoked with timer_id set to -1, an error is expected.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[int32 err;
err = OS_TimerSet((uint32)-1, 10, 10);
test_assert(err == OS_ERR_INVALID_ID, "invalid timer_id not detected");]]></value>
</code>
</step>
</steps>
</case>
<case>
<brief>
<value>OS_TimerGetIdByName() errors</value>
</brief>
<description>
<value>Parameters checking in OS_TimerGetIdByName() 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_TimerGetIdByName() is invoked with timer_id set to NULL, an error is expected.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[int32 err;
err = OS_TimerGetIdByName(NULL, "timer");
test_assert(err == OS_INVALID_POINTER, "NULL not detected");]]></value>
</code>
</step>
<step>
<description>
<value>OS_TimerGetIdByName() is invoked with timer name set to NULL, an error is expected.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[int32 err;
err = OS_TimerGetIdByName(&tmid, NULL);
test_assert(err == OS_INVALID_POINTER, "NULL not detected");]]></value>
</code>
</step>
<step>
<description>
<value>OS_TimerGetIdByName() is invoked with a very long task name, an error is expected.</value>
</description>
<tags>
<value />
</tags>
<code>
<value><![CDATA[int32 err;
err = OS_TimerGetIdByName(&tmid, "very very long timer name");
test_assert(err == OS_ERR_NAME_TOO_LONG, "name limit not detected");]]></value>
</code>
</step>
</steps>
</case>
<case>
<brief>
<value>OS_TimerSet() one-shot functionality</value>
</brief>
<description>
<value>A timer is tested in one-shot mode.</value>
</description>
<condition>
<value />
</condition>
<various_code>
<setup_code>
<value><![CDATA[tmid = 0;]]></value>
</setup_code>
<teardown_code>
<value><![CDATA[if (tmid != 0) {
(void) OS_TimerDelete(tmid);
}]]></value>
</teardown_code>
<local_variables>
<value />
</local_variables>
</various_code>
<steps />
</case>
<case>
<brief>
<value>OS_TimerSet() periodic functionality</value>
</brief>
<description>
<value>A timer is tested in periodic mode.</value>
</description>
<condition>
<value />
</condition>
<various_code>
<setup_code>
<value><![CDATA[tmid = 0;]]></value>
</setup_code>
<teardown_code>
<value><![CDATA[if (tmid != 0) {
(void) OS_TimerDelete(tmid);
}]]></value>
</teardown_code>
<local_variables>
<value />
</local_variables>
</various_code>
<steps />
</case>
</cases>
</sequence>
</sequences>
</instance>
</instances>

View File

@ -23,6 +23,7 @@
* <h2>Test Sequences</h2>
* - @subpage test_sequence_001
* - @subpage test_sequence_002
* - @subpage test_sequence_003
* .
*/
@ -48,6 +49,7 @@
const testcase_t * const *test_suite[] = {
test_sequence_001,
test_sequence_002,
test_sequence_003,
NULL
};

View File

@ -27,6 +27,7 @@
#include "test_sequence_001.h"
#include "test_sequence_002.h"
#include "test_sequence_003.h"
/*===========================================================================*/
/* External declarations. */

View File

@ -81,7 +81,7 @@ static void test_task_writer(void) {
* - OS_QueueDelete() is invoked with queue_id set to -1, an error is
* expected.
* - OS_QueueCreate() is invoked twice with duplicated name, an error
* is expected, then the queue is deleted using OS_DeleteQueue().
* is expected, then the queue is deleted using OS_QueueDelete().
* .
*/
@ -142,7 +142,7 @@ static void test_002_001_execute(void) {
}
/* OS_QueueCreate() is invoked twice with duplicated name, an error
is expected, then the queue is deleted using OS_DeleteQueue().*/
is expected, then the queue is deleted using OS_QueueDelete().*/
test_set_step(5);
{
int32 err;

View File

@ -0,0 +1,353 @@
/*
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_003 Timers Functionality
*
* File: @ref test_sequence_003.c
*
* <h2>Description</h2>
* This sequence tests the NASA OSAL over ChibiOS/RT functionalities
* related to timers.
*
* <h2>Test Cases</h2>
* - @subpage test_003_001
* - @subpage test_003_002
* - @subpage test_003_003
* - @subpage test_003_004
* - @subpage test_003_005
* .
*/
/****************************************************************************
* Shared code.
****************************************************************************/
#include <string.h>
#include "osapi.h"
uint32 tmid;
static void tmr_callback(uint32 timer_id) {
(void)timer_id;
}
/****************************************************************************
* Test cases.
****************************************************************************/
/**
* @page test_003_001 OS_TimerCreate() and OS_TimerDelete() errors
*
* <h2>Description</h2>
* Parameters checking in OS_TimerCreate() and OS_TimerDelete() is
* tested.
*
* <h2>Test Steps</h2>
* - OS_TimerCreate() is invoked with timer_id set to NULL, an error is
* expected.
* - OS_TimerCreate() is invoked with timer_name set to NULL, an error
* is expected.
* - OS_TimerCreate() is invoked with accuracy set to NULL, an error is
* expected.
* - OS_TimerCreate() is invoked with callback_ptr set to NULL, an
* error is expected.
* - OS_TimerCreate() is invoked with a very long timer name, an error
* is expected.
* - OS_TimerDelete() is invoked with timer_id set to -1, an error is
* expected.
* - OS_TimerCreate() is invoked twice with duplicated name, an error
* is expected, then the queue is deleted using OS_TimerDelete().
* .
*/
static void test_003_001_execute(void) {
/* OS_TimerCreate() is invoked with timer_id set to NULL, an error is
expected.*/
test_set_step(1);
{
int32 err;
uint32 accuracy;
err = OS_TimerCreate(NULL, /* Error.*/
"failing timer",
&accuracy,
tmr_callback);
test_assert(err == OS_INVALID_POINTER, "NULL not detected");
}
/* OS_TimerCreate() is invoked with timer_name set to NULL, an error
is expected.*/
test_set_step(2);
{
int32 err;
uint32 tmid;
uint32 accuracy;
err = OS_TimerCreate(&tmid,
NULL, /* Error.*/
&accuracy,
tmr_callback);
test_assert(err == OS_INVALID_POINTER, "NULL not detected");
}
/* OS_TimerCreate() is invoked with accuracy set to NULL, an error is
expected.*/
test_set_step(3);
{
int32 err;
uint32 tmid;
err = OS_TimerCreate(&tmid,
"failing timer",
NULL, /* Error.*/
tmr_callback);
test_assert(err == OS_INVALID_POINTER, "NULL not detected");
}
/* OS_TimerCreate() is invoked with callback_ptr set to NULL, an
error is expected.*/
test_set_step(4);
{
int32 err;
uint32 tmid;
uint32 accuracy;
err = OS_TimerCreate(&tmid,
"failing timer",
&accuracy,
NULL); /* Error.*/
test_assert(err == OS_INVALID_POINTER, "NULL not detected");
}
/* OS_TimerCreate() is invoked with a very long timer name, an error
is expected.*/
test_set_step(5);
{
int32 err;
uint32 tmid;
uint32 accuracy;
err = OS_TimerCreate(&tmid,
"very very long timer name", /* Error.*/
&accuracy,
tmr_callback);
test_assert(err == OS_ERR_NAME_TOO_LONG, "name limit not detected");
}
/* OS_TimerDelete() is invoked with timer_id set to -1, an error is
expected.*/
test_set_step(6);
{
int32 err;
err = OS_TimerDelete((uint32)-1);
test_assert(err == OS_ERR_INVALID_ID, "wrong timer id not detected");
}
/* OS_TimerCreate() is invoked twice with duplicated name, an error
is expected, then the queue is deleted using OS_TimerDelete().*/
test_set_step(7);
{
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");
}
}
static const testcase_t test_003_001 = {
"OS_TimerCreate() and OS_TimerDelete() errors",
NULL,
NULL,
test_003_001_execute
};
/**
* @page test_003_002 OS_TimerSet() errors
*
* <h2>Description</h2>
* Parameters checking in OS_TimerSet() is tested.
*
* <h2>Test Steps</h2>
* - OS_TimerSet() is invoked with timer_id set to -1, an error is
* expected.
* .
*/
static void test_003_002_execute(void) {
/* OS_TimerSet() is invoked with timer_id set to -1, an error is
expected.*/
test_set_step(1);
{
int32 err;
err = OS_TimerSet((uint32)-1, 10, 10);
test_assert(err == OS_ERR_INVALID_ID, "invalid timer_id not detected");
}
}
static const testcase_t test_003_002 = {
"OS_TimerSet() errors",
NULL,
NULL,
test_003_002_execute
};
/**
* @page test_003_003 OS_TimerGetIdByName() errors
*
* <h2>Description</h2>
* Parameters checking in OS_TimerGetIdByName() is tested.
*
* <h2>Test Steps</h2>
* - OS_TimerGetIdByName() is invoked with timer_id set to NULL, an
* error is expected.
* - OS_TimerGetIdByName() is invoked with timer name set to NULL, an
* error is expected.
* - OS_TimerGetIdByName() is invoked with a very long task name, an
* error is expected.
* .
*/
static void test_003_003_execute(void) {
/* OS_TimerGetIdByName() is invoked with timer_id set to NULL, an
error is expected.*/
test_set_step(1);
{
int32 err;
err = OS_TimerGetIdByName(NULL, "timer");
test_assert(err == OS_INVALID_POINTER, "NULL not detected");
}
/* OS_TimerGetIdByName() is invoked with timer name set to NULL, an
error is expected.*/
test_set_step(2);
{
int32 err;
err = OS_TimerGetIdByName(&tmid, NULL);
test_assert(err == OS_INVALID_POINTER, "NULL not detected");
}
/* OS_TimerGetIdByName() is invoked with a very long task name, an
error is expected.*/
test_set_step(3);
{
int32 err;
err = OS_TimerGetIdByName(&tmid, "very very long timer name");
test_assert(err == OS_ERR_NAME_TOO_LONG, "name limit not detected");
}
}
static const testcase_t test_003_003 = {
"OS_TimerGetIdByName() errors",
NULL,
NULL,
test_003_003_execute
};
/**
* @page test_003_004 OS_TimerSet() one-shot functionality
*
* <h2>Description</h2>
* A timer is tested in one-shot mode.
*
* <h2>Test Steps</h2>
*/
static void test_003_004_setup(void) {
tmid = 0;
}
static void test_003_004_teardown(void) {
if (tmid != 0) {
(void) OS_TimerDelete(tmid);
}
}
static void test_003_004_execute(void) {
}
static const testcase_t test_003_004 = {
"OS_TimerSet() one-shot functionality",
test_003_004_setup,
test_003_004_teardown,
test_003_004_execute
};
/**
* @page test_003_005 OS_TimerSet() periodic functionality
*
* <h2>Description</h2>
* A timer is tested in periodic mode.
*
* <h2>Test Steps</h2>
*/
static void test_003_005_setup(void) {
tmid = 0;
}
static void test_003_005_teardown(void) {
if (tmid != 0) {
(void) OS_TimerDelete(tmid);
}
}
static void test_003_005_execute(void) {
}
static const testcase_t test_003_005 = {
"OS_TimerSet() periodic functionality",
test_003_005_setup,
test_003_005_teardown,
test_003_005_execute
};
/****************************************************************************
* Exported data.
****************************************************************************/
/**
* @brief Timers Functionality.
*/
const testcase_t * const test_sequence_003[] = {
&test_003_001,
&test_003_002,
&test_003_003,
&test_003_004,
&test_003_005,
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_003[];

View File

@ -2,7 +2,8 @@
TESTSRC = ${CHIBIOS}/test/lib/ch_test.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_002.c
${CHIBIOS}/test/nasa_osal/source/test/test_sequence_002.c \
${CHIBIOS}/test/nasa_osal/source/test/test_sequence_003.c
# Required include directories
TESTINC = ${CHIBIOS}/test/lib \