From 6495240dcd6df5d7026429f75f2d0a2bfd87018a Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Thu, 10 Mar 2016 12:54:10 +0000 Subject: [PATCH] git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@9064 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/common/abstractions/nasa_osal/src/osapi.c | 3 +- test/nasa_osal/configuration.xml | 349 ++++++++++++++++- test/nasa_osal/source/test/test_root.c | 2 + test/nasa_osal/source/test/test_root.h | 1 + .../nasa_osal/source/test/test_sequence_002.c | 4 +- .../nasa_osal/source/test/test_sequence_003.c | 353 ++++++++++++++++++ .../nasa_osal/source/test/test_sequence_003.h | 17 + test/nasa_osal/test.mk | 3 +- 8 files changed, 719 insertions(+), 13 deletions(-) create mode 100644 test/nasa_osal/source/test/test_sequence_003.c create mode 100644 test/nasa_osal/source/test/test_sequence_003.h diff --git a/os/common/abstractions/nasa_osal/src/osapi.c b/os/common/abstractions/nasa_osal/src/osapi.c index 4dc39969d..25e2d9702 100644 --- a/os/common/abstractions/nasa_osal/src/osapi.c +++ b/os/common/abstractions/nasa_osal/src/osapi.c @@ -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; } diff --git a/test/nasa_osal/configuration.xml b/test/nasa_osal/configuration.xml index 6924cd1a4..df5342bff 100644 --- a/test/nasa_osal/configuration.xml +++ b/test/nasa_osal/configuration.xml @@ -734,7 +734,7 @@ 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(). + OS_QueueCreate() is invoked twice with duplicated name, an error is expected, then the queue is deleted using OS_QueueDelete(). @@ -941,8 +941,8 @@ test_assert(err == OS_ERR_NAME_TOO_LONG, "name limit not detected");]]> }]]> - @@ -969,9 +969,9 @@ test_assert(err == OS_SUCCESS, "queue not found");]]> - @@ -983,9 +983,9 @@ test_assert(err == OS_QUEUE_TIMEOUT, "unexpected error code");]]> - @@ -993,6 +993,337 @@ test_assert(err == OS_QUEUE_EMPTY, "unexpected error code");]]> + + + Internal Tests + + + Timers Functionality + + + This sequence tests the NASA OSAL over ChibiOS/RT functionalities related to timers + + + + +#include "osapi.h" + +uint32 tmid; + +static void tmr_callback(uint32 timer_id) { + + (void)timer_id; +}]]> + + + + + OS_TimerCreate() and OS_TimerDelete() errors + + + Parameters checking in OS_TimerCreate() and OS_TimerDelete() is tested. + + + + + + + + + + + + + + + + + + + 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(). + + + + + + + + + + + + + OS_TimerSet() errors + + + Parameters checking in OS_TimerSet() is tested. + + + + + + + + + + + + + + + + + + + OS_TimerSet() is invoked with timer_id set to -1, an error is expected. + + + + + + + + + + + + + OS_TimerGetIdByName() errors + + + Parameters checking in OS_TimerGetIdByName() is tested. + + + + + + + + + + + + + + + + + + + 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. + + + + + + + + + + + + + OS_TimerSet() one-shot functionality + + + A timer is tested in one-shot mode. + + + + + + + + + + + + + + + + + + + + OS_TimerSet() periodic functionality + + + A timer is tested in periodic mode. + + + + + + + + + + + + + + + + + + + diff --git a/test/nasa_osal/source/test/test_root.c b/test/nasa_osal/source/test/test_root.c index 4639ada20..eb349d4d2 100644 --- a/test/nasa_osal/source/test/test_root.c +++ b/test/nasa_osal/source/test/test_root.c @@ -23,6 +23,7 @@ *

Test Sequences

* - @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 }; diff --git a/test/nasa_osal/source/test/test_root.h b/test/nasa_osal/source/test/test_root.h index 4790201e0..9acbcb27c 100644 --- a/test/nasa_osal/source/test/test_root.h +++ b/test/nasa_osal/source/test/test_root.h @@ -27,6 +27,7 @@ #include "test_sequence_001.h" #include "test_sequence_002.h" +#include "test_sequence_003.h" /*===========================================================================*/ /* External declarations. */ diff --git a/test/nasa_osal/source/test/test_sequence_002.c b/test/nasa_osal/source/test/test_sequence_002.c index 44a4fe5df..7600c5f99 100644 --- a/test/nasa_osal/source/test/test_sequence_002.c +++ b/test/nasa_osal/source/test/test_sequence_002.c @@ -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; diff --git a/test/nasa_osal/source/test/test_sequence_003.c b/test/nasa_osal/source/test/test_sequence_003.c new file mode 100644 index 000000000..87338fc05 --- /dev/null +++ b/test/nasa_osal/source/test/test_sequence_003.c @@ -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 + * + *

Description

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

Test Cases

+ * - @subpage test_003_001 + * - @subpage test_003_002 + * - @subpage test_003_003 + * - @subpage test_003_004 + * - @subpage test_003_005 + * . + */ + +/**************************************************************************** + * Shared code. + ****************************************************************************/ + +#include + +#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 + * + *

Description

+ * Parameters checking in OS_TimerCreate() and OS_TimerDelete() is + * tested. + * + *

Test Steps

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

Description

+ * Parameters checking in OS_TimerSet() is tested. + * + *

Test Steps

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

Description

+ * Parameters checking in OS_TimerGetIdByName() is tested. + * + *

Test Steps

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

Description

+ * A timer is tested in one-shot mode. + * + *

Test Steps

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

Description

+ * A timer is tested in periodic mode. + * + *

Test Steps

+ */ + +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 +}; diff --git a/test/nasa_osal/source/test/test_sequence_003.h b/test/nasa_osal/source/test/test_sequence_003.h new file mode 100644 index 000000000..587acc5de --- /dev/null +++ b/test/nasa_osal/source/test/test_sequence_003.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_003[]; diff --git a/test/nasa_osal/test.mk b/test/nasa_osal/test.mk index 1ed8cad43..f3474941f 100644 --- a/test/nasa_osal/test.mk +++ b/test/nasa_osal/test.mk @@ -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 \