From 0a24a2e42658ec42b7f0217b5e5022877bd0ea0a Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Wed, 9 Mar 2016 16:06:50 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@9059 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- test/nasa_osal/source/test/test_sequence_001.c | 6 +- test/nasa_osal/source/test/test_sequence_002.c | 267 +++++++++++++++++++++++++ test/nasa_osal/source/test/test_sequence_002.h | 17 ++ 3 files changed, 288 insertions(+), 2 deletions(-) create mode 100644 test/nasa_osal/source/test/test_sequence_002.c create mode 100644 test/nasa_osal/source/test/test_sequence_002.h (limited to 'test/nasa_osal/source') diff --git a/test/nasa_osal/source/test/test_sequence_001.c b/test/nasa_osal/source/test/test_sequence_001.c index f8081cde1..de643b95e 100644 --- a/test/nasa_osal/source/test/test_sequence_001.c +++ b/test/nasa_osal/source/test/test_sequence_001.c @@ -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"); } } diff --git a/test/nasa_osal/source/test/test_sequence_002.c b/test/nasa_osal/source/test/test_sequence_002.c new file mode 100644 index 000000000..4b9da0522 --- /dev/null +++ b/test/nasa_osal/source/test/test_sequence_002.c @@ -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 + * + *

Description

+ * This sequence tests the NASA OSAL over ChibiOS/RT functionalities + * related to queues. + * + *

Test Cases

+ * - @subpage test_002_001 + * - @subpage test_002_002 + * . + */ + +/**************************************************************************** + * Shared code. + ****************************************************************************/ + +#include + +#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 + * + *

Description

+ * Parameters checking in OS_QueueCreate() and OS_QueueDelete() is + * tested. + * + *

Test Steps

+ * - 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 + * + *

Description

+ * A task writes on a queue, the messages are retrieved on the other + * side in blocking mode. + * + *

Test Steps

+ * - 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 +}; diff --git a/test/nasa_osal/source/test/test_sequence_002.h b/test/nasa_osal/source/test/test_sequence_002.h new file mode 100644 index 000000000..bd7b6c764 --- /dev/null +++ b/test/nasa_osal/source/test/test_sequence_002.h @@ -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[]; -- cgit v1.2.3