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

This commit is contained in:
Giovanni Di Sirio 2016-03-09 16:06:50 +00:00
parent 0d4df3cf1b
commit 0a24a2e426
6 changed files with 339 additions and 22 deletions

View File

@ -54,6 +54,7 @@ extern "C" {
#endif
void OS_set_printf(int (*printf)(const char *fmt, ...));
boolean OS_TaskDeleteCheck(void);
int32 OS_TaskWait(uint32 task_id);
#ifdef __cplusplus
}
#endif

View File

@ -1911,6 +1911,28 @@ void OS_TaskExit(void) {
chThdExit(MSG_OK);
}
/**
* @brief Wait for task termination.
* @note This is a ChibiOS/RT extension, added for improved testability.
*
* @param[in] task_id the task id
* @return An error code.
*
* @api
*/
int32 OS_TaskWait(uint32 task_id) {
thread_t *tp = (thread_t *)task_id;
/* Check for thread validity, getting a reference.*/
if (chRegFindThreadByPointer(tp) == NULL) {
return OS_ERR_INVALID_ID;
}
(void) chThdWait(tp);
return OS_SUCCESS;
}
/**
* @brief Task delay.
*

View File

@ -283,7 +283,8 @@ err = OS_TaskCreate(&tid,
0);
test_assert(err == OS_ERR_NO_FREE_IDS, "stack conflict not detected");
OS_TaskDelay(5);
err = OS_TaskWait(tid);
test_assert(err == OS_SUCCESS, "wait failed");
test_assert_sequence("A", "task not executed");
err = OS_TaskCreate(&tid,
@ -295,7 +296,8 @@ err = OS_TaskCreate(&tid,
0);
test_assert(err == OS_SUCCESS, "task creation failed");
OS_TaskDelay(5);
err = OS_TaskWait(tid);
test_assert(err == OS_SUCCESS, "wait failed");
test_assert_sequence("A", "task not executed");]]></value>
</code>
</step>
@ -616,13 +618,13 @@ test_assert_sequence("ABC", "events order violation");]]></value>
<value>This sequence tests the NASA OSAL over ChibiOS/RT functionalities related to queues</value>
</description>
<shared_code>
<value><![CDATA[#include <string.h>
<value><![CDATA[#include <string.h>
#include "osapi.h"
uint32 qid;
uint32 qid, tid;
#define WRITER_NUM_MESSAGES 16
#define WRITER_NUM_MESSAGES 16
#define MESSAGE_SIZE 20
static void test_task_writer(void) {
@ -765,15 +767,20 @@ test_assert(err == OS_SUCCESS, "queue deletion failed");]]></value>
</condition>
<various_code>
<setup_code>
<value><![CDATA[qid = 0;]]></value>
<value><![CDATA[qid = 0;
tid = 0;]]></value>
</setup_code>
<teardown_code>
<value><![CDATA[if (qid != 0) {
(void) OS_QueueDelete(qid);
<value><![CDATA[if (qid != 0) {
(void) OS_QueueDelete(qid);
}
if (tid != 0) {
(void) OS_TaskWait(tid);
}]]></value>
</teardown_code>
<local_variables>
<value><![CDATA[uint32 tid;
<value><![CDATA[uint32 tid;
unsigned i;]]></value>
</local_variables>
</various_code>
@ -820,15 +827,15 @@ test_assert(err == OS_SUCCESS, "writer task creation failed");]]></value>
<value />
</tags>
<code>
<value><![CDATA[for (i = 0; i < WRITER_NUM_MESSAGES; i++) {
int32 err;
char data[MESSAGE_SIZE];
uint32 copied;
err = OS_QueueGet(qid, data, MESSAGE_SIZE, &copied, OS_Milli2Ticks(200));
test_assert(err == OS_SUCCESS, "timed out");
test_assert(strncmp(data, "Hello World", sizeof (data)) == 0,
"wrong message");
<value><![CDATA[for (i = 0; i < WRITER_NUM_MESSAGES; i++) {
int32 err;
char data[MESSAGE_SIZE];
uint32 copied;
err = OS_QueueGet(qid, data, MESSAGE_SIZE, &copied, OS_Milli2Ticks(200));
test_assert(err == OS_SUCCESS, "timed out");
test_assert(strncmp(data, "Hello World", sizeof (data)) == 0,
"wrong message");
}]]></value>
</code>
</step>
@ -840,7 +847,8 @@ test_assert(err == OS_SUCCESS, "writer task creation failed");]]></value>
<value />
</tags>
<code>
<value><![CDATA[OS_TaskDelay(10);
<value><![CDATA[(void) OS_TaskWait(tid);
tid = 0;
test_assert_sequence("", "queue write errors occurred");]]></value>
</code>
</step>

View File

@ -257,7 +257,8 @@ static void test_001_001_execute(void) {
0);
test_assert(err == OS_ERR_NO_FREE_IDS, "stack conflict not detected");
OS_TaskDelay(5);
err = OS_TaskWait(tid);
test_assert(err == OS_SUCCESS, "wait failed");
test_assert_sequence("A", "task not executed");
err = OS_TaskCreate(&tid,
@ -269,7 +270,8 @@ static void test_001_001_execute(void) {
0);
test_assert(err == OS_SUCCESS, "task creation failed");
OS_TaskDelay(5);
err = OS_TaskWait(tid);
test_assert(err == OS_SUCCESS, "wait failed");
test_assert_sequence("A", "task not executed");
}
}

View File

@ -0,0 +1,267 @@
/*
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_002 Queues Functionality
*
* File: @ref test_sequence_002.c
*
* <h2>Description</h2>
* This sequence tests the NASA OSAL over ChibiOS/RT functionalities
* related to queues.
*
* <h2>Test Cases</h2>
* - @subpage test_002_001
* - @subpage test_002_002
* .
*/
/****************************************************************************
* Shared code.
****************************************************************************/
#include <string.h>
#include "osapi.h"
uint32 qid, tid;
#define WRITER_NUM_MESSAGES 16
#define MESSAGE_SIZE 20
static void test_task_writer(void) {
unsigned i;
int32 err;
for (i = 0; i < WRITER_NUM_MESSAGES; i++) {
err = OS_QueuePut(qid, "Hello World", 12, 0);
if (err != OS_SUCCESS) {
test_emit_token('*');
}
}
}
/****************************************************************************
* Test cases.
****************************************************************************/
/**
* @page test_002_001 OS_QueueCreate() and OS_QueueDelete() errors
*
* <h2>Description</h2>
* Parameters checking in OS_QueueCreate() and OS_QueueDelete() is
* tested.
*
* <h2>Test Steps</h2>
* - OS_QueueCreate() is invoked with queue_id set to NULL, an error is
* expected.
* - OS_QueueCreate() is invoked with task_name set to NULL, an error
* is expected.
* - OS_QueueCreate() is invoked with a very long task name, an error
* is expected.
* - 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().
* .
*/
static void test_002_001_execute(void) {
/* OS_QueueCreate() is invoked with queue_id set to NULL, an error is
expected.*/
test_set_step(1);
{
int32 err;
err = OS_QueueCreate(NULL, /* Error.*/
"failing queue",
4,
128,
0);
test_assert(err == OS_INVALID_POINTER, "NULL not detected");
}
/* OS_QueueCreate() is invoked with task_name set to NULL, an error
is expected.*/
test_set_step(2);
{
int32 err;
uint32 qid;
err = OS_QueueCreate(&qid,
NULL, /* Error.*/
4,
128,
0);
test_assert(err == OS_INVALID_POINTER, "NULL not detected");
}
/* OS_QueueCreate() is invoked with a very long task name, an error
is expected.*/
test_set_step(3);
{
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");
}
/* OS_QueueDelete() is invoked with queue_id set to -1, an error is
expected.*/
test_set_step(4);
{
int32 err;
err = OS_QueueDelete((uint32)-1);
test_assert(err == OS_ERR_INVALID_ID, "wrong queue id not detected");
}
/* OS_QueueCreate() is invoked twice with duplicated name, an error
is expected, then the queue is deleted using OS_DeleteQueue().*/
test_set_step(5);
{
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_002_001 = {
"OS_QueueCreate() and OS_QueueDelete() errors",
NULL,
NULL,
test_002_001_execute
};
/**
* @page test_002_002 OS_QueuePut() and OS_QueueGet() functionality
*
* <h2>Description</h2>
* A task writes on a queue, the messages are retrieved on the other
* side in blocking mode.
*
* <h2>Test Steps</h2>
* - Creataing a queue with depth 4 and message size 20.
* - Creating the writer task.
* - Reading messages from the writer task.
* - Waiting for task termination then checking for errors.
* .
*/
static void test_002_002_setup(void) {
qid = 0;
tid = 0;
}
static void test_002_002_teardown(void) {
if (qid != 0) {
(void) OS_QueueDelete(qid);
}
if (tid != 0) {
(void) OS_TaskWait(tid);
}
}
static void test_002_002_execute(void) {
uint32 tid;
unsigned i;
/* Creataing a queue with depth 4 and message size 20.*/
test_set_step(1);
{
int32 err;
err = OS_QueueCreate(&qid, "test queue", 4, MESSAGE_SIZE, 0);
test_assert(err == OS_SUCCESS, "queue creation failed");
}
/* Creating the writer task.*/
test_set_step(2);
{
int32 err;
err = OS_TaskCreate(&tid,
"writer task",
test_task_writer,
(uint32 *)wa_test1,
sizeof wa_test1,
TASKS_BASE_PRIORITY,
0);
test_assert(err == OS_SUCCESS, "writer task creation failed");
}
/* Reading messages from the writer task.*/
test_set_step(3);
{
for (i = 0; i < WRITER_NUM_MESSAGES; i++) {
int32 err;
char data[MESSAGE_SIZE];
uint32 copied;
err = OS_QueueGet(qid, data, MESSAGE_SIZE, &copied, OS_Milli2Ticks(200));
test_assert(err == OS_SUCCESS, "timed out");
test_assert(strncmp(data, "Hello World", sizeof (data)) == 0,
"wrong message");
}
}
/* Waiting for task termination then checking for errors.*/
test_set_step(4);
{
(void) OS_TaskWait(tid);
tid = 0;
test_assert_sequence("", "queue write errors occurred");
}
}
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
};
/****************************************************************************
* Exported data.
****************************************************************************/
/**
* @brief Queues Functionality.
*/
const testcase_t * const test_sequence_002[] = {
&test_002_001,
&test_002_002,
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_002[];