From 0e3a108a64d9d2ac6d820f90b35a47c2d6cad2cc Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Thu, 19 Oct 2017 09:16:38 +0000 Subject: NIL test suite updated. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@10864 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- test/nil/source/test/nil_test_root.c | 122 ++++++++ test/nil/source/test/nil_test_root.h | 64 +++++ test/nil/source/test/nil_test_sequence_001.c | 182 ++++++++++++ test/nil/source/test/nil_test_sequence_001.h | 27 ++ test/nil/source/test/nil_test_sequence_002.c | 190 +++++++++++++ test/nil/source/test/nil_test_sequence_002.h | 27 ++ test/nil/source/test/nil_test_sequence_003.c | 266 +++++++++++++++++ test/nil/source/test/nil_test_sequence_003.h | 27 ++ test/nil/source/test/nil_test_sequence_004.c | 206 ++++++++++++++ test/nil/source/test/nil_test_sequence_004.h | 27 ++ test/nil/source/test/test_root.c | 127 --------- test/nil/source/test/test_root.h | 65 ----- test/nil/source/test/test_sequence_001.c | 175 ------------ test/nil/source/test/test_sequence_001.h | 27 -- test/nil/source/test/test_sequence_002.c | 183 ------------ test/nil/source/test/test_sequence_002.h | 27 -- test/nil/source/test/test_sequence_003.c | 259 ----------------- test/nil/source/test/test_sequence_003.h | 27 -- test/nil/source/test/test_sequence_004.c | 199 ------------- test/nil/source/test/test_sequence_004.h | 27 -- test/nil/source/test/test_sequence_005.c | 408 --------------------------- test/nil/source/test/test_sequence_005.h | 27 -- test/nil/source/test/test_sequence_006.c | 296 ------------------- test/nil/source/test/test_sequence_006.h | 27 -- test/nil/source/test/test_sequence_007.c | 273 ------------------ test/nil/source/test/test_sequence_007.h | 27 -- 26 files changed, 1138 insertions(+), 2174 deletions(-) create mode 100644 test/nil/source/test/nil_test_root.c create mode 100644 test/nil/source/test/nil_test_root.h create mode 100644 test/nil/source/test/nil_test_sequence_001.c create mode 100644 test/nil/source/test/nil_test_sequence_001.h create mode 100644 test/nil/source/test/nil_test_sequence_002.c create mode 100644 test/nil/source/test/nil_test_sequence_002.h create mode 100644 test/nil/source/test/nil_test_sequence_003.c create mode 100644 test/nil/source/test/nil_test_sequence_003.h create mode 100644 test/nil/source/test/nil_test_sequence_004.c create mode 100644 test/nil/source/test/nil_test_sequence_004.h delete mode 100644 test/nil/source/test/test_root.c delete mode 100644 test/nil/source/test/test_root.h delete mode 100644 test/nil/source/test/test_sequence_001.c delete mode 100644 test/nil/source/test/test_sequence_001.h delete mode 100644 test/nil/source/test/test_sequence_002.c delete mode 100644 test/nil/source/test/test_sequence_002.h delete mode 100644 test/nil/source/test/test_sequence_003.c delete mode 100644 test/nil/source/test/test_sequence_003.h delete mode 100644 test/nil/source/test/test_sequence_004.c delete mode 100644 test/nil/source/test/test_sequence_004.h delete mode 100644 test/nil/source/test/test_sequence_005.c delete mode 100644 test/nil/source/test/test_sequence_005.h delete mode 100644 test/nil/source/test/test_sequence_006.c delete mode 100644 test/nil/source/test/test_sequence_006.h delete mode 100644 test/nil/source/test/test_sequence_007.c delete mode 100644 test/nil/source/test/test_sequence_007.h (limited to 'test/nil/source') diff --git a/test/nil/source/test/nil_test_root.c b/test/nil/source/test/nil_test_root.c new file mode 100644 index 000000000..4974bad56 --- /dev/null +++ b/test/nil/source/test/nil_test_root.c @@ -0,0 +1,122 @@ +/* + ChibiOS - Copyright (C) 2006..2017 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. +*/ + +/** + * @mainpage Test Suite Specification + * Test suite for ChibiOS/NIL. The purpose of this suite is to perform + * unit tests on the NIL modules and to converge to 100% code coverage + * through successive improvements. + * + *

Test Sequences

+ * - @subpage nil_test_sequence_001 + * - @subpage nil_test_sequence_002 + * - @subpage nil_test_sequence_003 + * - @subpage nil_test_sequence_004 + * . + */ + +/** + * @file nil_test_root.c + * @brief Test Suite root structures code. + */ + +#include "hal.h" +#include "nil_test_root.h" + +#if !defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Module exported variables. */ +/*===========================================================================*/ + +/** + * @brief Array of test sequences. + */ +const testsequence_t * const nil_test_suite_array[] = { + &nil_test_sequence_001, + &nil_test_sequence_002, +#if (CH_CFG_USE_SEMAPHORES) || defined(__DOXYGEN__) + &nil_test_sequence_003, +#endif + &nil_test_sequence_004, + NULL +}; + +/** + * @brief Test suite root structure. + */ +const testsuite_t nil_test_suite = { + "Test Specification for ChibiOS/NIL.", + nil_test_suite_array +}; + +/*===========================================================================*/ +/* Shared code. */ +/*===========================================================================*/ + +void test_print_port_info(void) { + +#ifdef PORT_COMPILER_NAME + test_print("*** Compiler: "); + test_println(PORT_COMPILER_NAME); +#endif + test_print("*** Architecture: "); + test_println(PORT_ARCHITECTURE_NAME); +#ifdef PORT_CORE_VARIANT_NAME + test_print("*** Core Variant: "); + test_println(PORT_CORE_VARIANT_NAME); +#endif +#ifdef PORT_INFO + test_print("*** Port Info: "); + test_println(PORT_INFO); +#endif +} + +semaphore_t gsem1, gsem2; +thread_reference_t gtr1; + +/* + * Support thread. + */ +THD_WORKING_AREA(wa_test_support, 128); +THD_FUNCTION(test_support, arg) { +#if CH_CFG_USE_EVENTS == TRUE + thread_t *tp = (thread_t *)arg; +#else + (void)arg; +#endif + + /* Initializing global resources.*/ + chSemObjectInit(&gsem1, 0); + chSemObjectInit(&gsem2, 0); + + while (true) { + chSysLock(); + if (chSemGetCounterI(&gsem1) < 0) + chSemSignalI(&gsem1); + chSemResetI(&gsem2, 0); + chThdResumeI(>r1, MSG_OK); +#if CH_CFG_USE_EVENTS == TRUE + chEvtSignalI(tp, 0x55); +#endif + chSchRescheduleS(); + chSysUnlock(); + + chThdSleepMilliseconds(250); + } +} + +#endif /* !defined(__DOXYGEN__) */ diff --git a/test/nil/source/test/nil_test_root.h b/test/nil/source/test/nil_test_root.h new file mode 100644 index 000000000..1f523d5e4 --- /dev/null +++ b/test/nil/source/test/nil_test_root.h @@ -0,0 +1,64 @@ +/* + ChibiOS - Copyright (C) 2006..2017 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. +*/ + +/** + * @file nil_test_root.h + * @brief Test Suite root structures header. + */ + +#ifndef NIL_TEST_ROOT_H +#define NIL_TEST_ROOT_H + +#include "ch_test.h" + +#include "nil_test_sequence_001.h" +#include "nil_test_sequence_002.h" +#include "nil_test_sequence_003.h" +#include "nil_test_sequence_004.h" + +#if !defined(__DOXYGEN__) + +/*===========================================================================*/ +/* External declarations. */ +/*===========================================================================*/ + +extern const testsuite_t nil_test_suite; + +#ifdef __cplusplus +extern "C" { +#endif +#ifdef __cplusplus +} +#endif + +/*===========================================================================*/ +/* Shared definitions. */ +/*===========================================================================*/ + +#define TEST_SUITE_NAME "ChibiOS/NIL Test Suite" + +#define TEST_REPORT_HOOK_HEADER test_print_port_info(); + +extern semaphore_t gsem1, gsem2; +extern thread_reference_t gtr1; +extern THD_WORKING_AREA(wa_test_support, 128); + +void test_print_port_info(void); +THD_FUNCTION(test_support, arg); + +#endif /* !defined(__DOXYGEN__) */ + +#endif /* NIL_TEST_ROOT_H */ diff --git a/test/nil/source/test/nil_test_sequence_001.c b/test/nil/source/test/nil_test_sequence_001.c new file mode 100644 index 000000000..1040700ef --- /dev/null +++ b/test/nil/source/test/nil_test_sequence_001.c @@ -0,0 +1,182 @@ +/* + ChibiOS - Copyright (C) 2006..2017 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 "nil_test_root.h" + +/** + * @file nil_test_sequence_001.c + * @brief Test Sequence 001 code. + * + * @page nil_test_sequence_001 [1] Information + * + * File: @ref nil_test_sequence_001.c + * + *

Description

+ * This sequence reports configuration and version information about + * the NIL kernel. + * + *

Test Cases

+ * - @subpage nil_test_001_001 + * - @subpage nil_test_001_002 + * . + */ + +/**************************************************************************** + * Shared code. + ****************************************************************************/ + +#include "ch.h" + +/**************************************************************************** + * Test cases. + ****************************************************************************/ + +/** + * @page nil_test_001_001 [1.1] Kernel Info + * + *

Description

+ * The version numbers are reported. + * + *

Test Steps

+ * - [1.1.1] Prints the version string. + * . + */ + +static void nil_test_001_001_execute(void) { + + /* [1.1.1] Prints the version string.*/ + test_set_step(1); + { + test_println("--- Product: ChibiOS/NIL"); + test_print("--- Stable Flag: "); + test_printn(CH_KERNEL_STABLE); + test_println(""); + test_print("--- Version String: "); + test_println(CH_KERNEL_VERSION); + test_print("--- Major Number: "); + test_printn(CH_KERNEL_MAJOR); + test_println(""); + test_print("--- Minor Number: "); + test_printn(CH_KERNEL_MINOR); + test_println(""); + test_print("--- Patch Number: "); + test_printn(CH_KERNEL_PATCH); + test_println(""); + } +} + +static const testcase_t nil_test_001_001 = { + "Kernel Info", + NULL, + NULL, + nil_test_001_001_execute +}; + +/** + * @page nil_test_001_002 [1.2] Kernel Settings + * + *

Description

+ * The static kernel settings are reported. + * + *

Test Steps

+ * - [1.2.1] Prints the configuration options settings. + * . + */ + +static void nil_test_001_002_execute(void) { + + /* [1.2.1] Prints the configuration options settings.*/ + test_set_step(1); + { + test_print("--- CH_CFG_NUM_THREADS: "); + test_printn(CH_CFG_NUM_THREADS); + test_println(""); + test_print("--- CH_CFG_ST_RESOLUTION: "); + test_printn(CH_CFG_ST_RESOLUTION); + test_println(""); + test_print("--- CH_CFG_ST_FREQUENCY: "); + test_printn(CH_CFG_ST_FREQUENCY); + test_println(""); + test_print("--- CH_CFG_ST_TIMEDELTA: "); + test_printn(CH_CFG_ST_TIMEDELTA); + test_println(""); + test_print("--- CH_CFG_USE_SEMAPHORES: "); + test_printn(CH_CFG_USE_SEMAPHORES); + test_println(""); + test_print("--- CH_CFG_USE_MUTEXES: "); + test_printn(CH_CFG_USE_MUTEXES); + test_println(""); + test_print("--- CH_CFG_USE_EVENTS: "); + test_printn(CH_CFG_USE_EVENTS); + test_println(""); + test_print("--- CH_CFG_USE_MAILBOXES: "); + test_printn(CH_CFG_USE_MAILBOXES); + test_println(""); + test_print("--- CH_CFG_USE_MEMCORE: "); + test_printn(CH_CFG_USE_MEMCORE); + test_println(""); + test_print("--- CH_CFG_USE_HEAP: "); + test_printn(CH_CFG_USE_HEAP); + test_println(""); + test_print("--- CH_CFG_USE_MEMPOOLS: "); + test_printn(CH_CFG_USE_MEMPOOLS); + test_println(""); + test_print("--- CH_DBG_STATISTICS: "); + test_printn(CH_DBG_STATISTICS); + test_println(""); + test_print("--- CH_DBG_SYSTEM_STATE_CHECK: "); + test_printn(CH_DBG_SYSTEM_STATE_CHECK); + test_println(""); + test_print("--- CH_DBG_ENABLE_CHECKS: "); + test_printn(CH_DBG_ENABLE_CHECKS); + test_println(""); + test_print("--- CH_DBG_ENABLE_ASSERTS: "); + test_printn(CH_DBG_ENABLE_ASSERTS); + test_println(""); + test_print("--- CH_DBG_ENABLE_STACK_CHECK: "); + test_printn(CH_DBG_ENABLE_STACK_CHECK); + test_println(""); + } +} + +static const testcase_t nil_test_001_002 = { + "Kernel Settings", + NULL, + NULL, + nil_test_001_002_execute +}; + +/**************************************************************************** + * Exported data. + ****************************************************************************/ + +/** + * @brief Array of test cases. + */ +const testcase_t * const nil_test_sequence_001_array[] = { + &nil_test_001_001, + &nil_test_001_002, + NULL +}; + +/** + * @brief Information. + */ +const testsequence_t nil_test_sequence_001 = { + NULL, + nil_test_sequence_001_array +}; diff --git a/test/nil/source/test/nil_test_sequence_001.h b/test/nil/source/test/nil_test_sequence_001.h new file mode 100644 index 000000000..5d1781747 --- /dev/null +++ b/test/nil/source/test/nil_test_sequence_001.h @@ -0,0 +1,27 @@ +/* + ChibiOS - Copyright (C) 2006..2017 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. +*/ + +/** + * @file nil_test_sequence_001.h + * @brief Test Sequence 001 header. + */ + +#ifndef NIL_TEST_SEQUENCE_001_H +#define NIL_TEST_SEQUENCE_001_H + +extern const testsequence_t nil_test_sequence_001; + +#endif /* NIL_TEST_SEQUENCE_001_H */ diff --git a/test/nil/source/test/nil_test_sequence_002.c b/test/nil/source/test/nil_test_sequence_002.c new file mode 100644 index 000000000..26d511714 --- /dev/null +++ b/test/nil/source/test/nil_test_sequence_002.c @@ -0,0 +1,190 @@ +/* + ChibiOS - Copyright (C) 2006..2017 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 "nil_test_root.h" + +/** + * @file nil_test_sequence_002.c + * @brief Test Sequence 002 code. + * + * @page nil_test_sequence_002 [2] Threads Functionality + * + * File: @ref nil_test_sequence_002.c + * + *

Description

+ * This sequence tests the ChibiOS/NIL functionalities related to + * threading. + * + *

Test Cases

+ * - @subpage nil_test_002_001 + * - @subpage nil_test_002_002 + * . + */ + +/**************************************************************************** + * Shared code. + ****************************************************************************/ + +#include "ch.h" + +/**************************************************************************** + * Test cases. + ****************************************************************************/ + +/** + * @page nil_test_002_001 [2.1] System Tick Counter functionality + * + *

Description

+ * The functionality of the API @p chVTGetSystemTimeX() is tested. + * + *

Test Steps

+ * - [2.1.1] A System Tick Counter increment is expected, the test + * simply hangs if it does not happen. + * . + */ + +static void nil_test_002_001_execute(void) { + + /* [2.1.1] A System Tick Counter increment is expected, the test + simply hangs if it does not happen.*/ + test_set_step(1); + { + systime_t time = chVTGetSystemTimeX(); + while (time == chVTGetSystemTimeX()) { + } + } +} + +static const testcase_t nil_test_002_001 = { + "System Tick Counter functionality", + NULL, + NULL, + nil_test_002_001_execute +}; + +/** + * @page nil_test_002_002 [2.2] Thread Sleep functionality + * + *

Description

+ * The functionality of @p chThdSleep() and derivatives is tested. + * + *

Test Steps

+ * - [2.2.1] The current system time is read then a sleep is performed + * for 100 system ticks and on exit the system time is verified + * again. + * - [2.2.2] The current system time is read then a sleep is performed + * for 100000 microseconds and on exit the system time is verified + * again. + * - [2.2.3] The current system time is read then a sleep is performed + * for 100 milliseconds and on exit the system time is verified + * again. + * - [2.2.4] The current system time is read then a sleep is performed + * for 1 second and on exit the system time is verified again. + * - [2.2.5] Function chThdSleepUntil() is tested with a timeline of + * "now" + 100 ticks. + * . + */ + +static void nil_test_002_002_execute(void) { + systime_t time; + + /* [2.2.1] The current system time is read then a sleep is performed + for 100 system ticks and on exit the system time is verified + again.*/ + test_set_step(1); + { + time = chVTGetSystemTimeX(); + chThdSleep(100); + test_assert_time_window(chTimeAddX(time, 100), + chTimeAddX(time, 100 + 1), + "out of time window"); + } + + /* [2.2.2] The current system time is read then a sleep is performed + for 100000 microseconds and on exit the system time is verified + again.*/ + test_set_step(2); + { + time = chVTGetSystemTimeX(); + chThdSleepMicroseconds(100000); + test_assert_time_window(chTimeAddX(time, TIME_US2I(100000)), + chTimeAddX(time, TIME_US2I(100000) + 1), + "out of time window"); + } + + /* [2.2.3] The current system time is read then a sleep is performed + for 100 milliseconds and on exit the system time is verified + again.*/ + test_set_step(3); + { + time = chVTGetSystemTimeX(); + chThdSleepMilliseconds(100); + test_assert_time_window(chTimeAddX(time, TIME_MS2I(100)), + chTimeAddX(time, TIME_MS2I(100) + 1), + "out of time window"); + } + + /* [2.2.4] The current system time is read then a sleep is performed + for 1 second and on exit the system time is verified again.*/ + test_set_step(4); + { + time = chVTGetSystemTimeX(); + chThdSleepSeconds(1); + test_assert_time_window(chTimeAddX(time, TIME_S2I(1)), + chTimeAddX(time, TIME_S2I(1) + 1), + "out of time window"); + } + + /* [2.2.5] Function chThdSleepUntil() is tested with a timeline of + "now" + 100 ticks.*/ + test_set_step(5); + { + time = chVTGetSystemTimeX(); + chThdSleepUntil(chTimeAddX(time, 100)); + test_assert_time_window(chTimeAddX(time, 100), + chTimeAddX(time, 100 + 1), + "out of time window"); + } +} + +static const testcase_t nil_test_002_002 = { + "Thread Sleep functionality", + NULL, + NULL, + nil_test_002_002_execute +}; + +/**************************************************************************** + * Exported data. + ****************************************************************************/ + +/** + * @brief Array of test cases. + */ +const testcase_t * const nil_test_sequence_002_array[] = { + &nil_test_002_001, + &nil_test_002_002, + NULL +}; + +/** + * @brief Threads Functionality. + */ +const testsequence_t nil_test_sequence_002 = { + NULL, + nil_test_sequence_002_array +}; diff --git a/test/nil/source/test/nil_test_sequence_002.h b/test/nil/source/test/nil_test_sequence_002.h new file mode 100644 index 000000000..4b62bd4d6 --- /dev/null +++ b/test/nil/source/test/nil_test_sequence_002.h @@ -0,0 +1,27 @@ +/* + ChibiOS - Copyright (C) 2006..2017 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. +*/ + +/** + * @file nil_test_sequence_002.h + * @brief Test Sequence 002 header. + */ + +#ifndef NIL_TEST_SEQUENCE_002_H +#define NIL_TEST_SEQUENCE_002_H + +extern const testsequence_t nil_test_sequence_002; + +#endif /* NIL_TEST_SEQUENCE_002_H */ diff --git a/test/nil/source/test/nil_test_sequence_003.c b/test/nil/source/test/nil_test_sequence_003.c new file mode 100644 index 000000000..6fe29ef46 --- /dev/null +++ b/test/nil/source/test/nil_test_sequence_003.c @@ -0,0 +1,266 @@ +/* + ChibiOS - Copyright (C) 2006..2017 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 "nil_test_root.h" + +/** + * @file nil_test_sequence_003.c + * @brief Test Sequence 003 code. + * + * @page nil_test_sequence_003 [3] Semaphores + * + * File: @ref nil_test_sequence_003.c + * + *

Description

+ * This sequence tests the ChibiOS/NIL functionalities related to + * counter semaphores. + * + *

Conditions

+ * This sequence is only executed if the following preprocessor condition + * evaluates to true: + * - CH_CFG_USE_SEMAPHORES + * . + * + *

Test Cases

+ * - @subpage nil_test_003_001 + * - @subpage nil_test_003_002 + * - @subpage nil_test_003_003 + * . + */ + +#if (CH_CFG_USE_SEMAPHORES) || defined(__DOXYGEN__) + +/**************************************************************************** + * Shared code. + ****************************************************************************/ + +#include "ch.h" + +static semaphore_t sem1; + +/**************************************************************************** + * Test cases. + ****************************************************************************/ + +/** + * @page nil_test_003_001 [3.1] Semaphore primitives, no state change + * + *

Description

+ * Wait, Signal and Reset primitives are tested. The testing thread + * does not trigger a state change. + * + *

Test Steps

+ * - [3.1.1] The function chSemWait() is invoked, after return the + * counter and the returned message are tested. + * - [3.1.2] The function chSemSignal() is invoked, after return the + * counter is tested. + * - [3.1.3] The function chSemReset() is invoked, after return the + * counter is tested. + * . + */ + +static void nil_test_003_001_setup(void) { + chSemObjectInit(&sem1, 1); +} + +static void nil_test_003_001_teardown(void) { + chSemReset(&sem1, 0); +} + +static void nil_test_003_001_execute(void) { + + /* [3.1.1] The function chSemWait() is invoked, after return the + counter and the returned message are tested.*/ + test_set_step(1); + { + msg_t msg; + + msg = chSemWait(&sem1); + test_assert_lock(chSemGetCounterI(&sem1) == 0, "wrong counter value"); + test_assert(MSG_OK == msg, "wrong returned message"); + } + + /* [3.1.2] The function chSemSignal() is invoked, after return the + counter is tested.*/ + test_set_step(2); + { + chSemSignal(&sem1); + test_assert_lock(chSemGetCounterI(&sem1) == 1, "wrong counter value"); + } + + /* [3.1.3] The function chSemReset() is invoked, after return the + counter is tested.*/ + test_set_step(3); + { + chSemReset(&sem1, 2); + test_assert_lock(chSemGetCounterI(&sem1) == 2, "wrong counter value"); + } +} + +static const testcase_t nil_test_003_001 = { + "Semaphore primitives, no state change", + nil_test_003_001_setup, + nil_test_003_001_teardown, + nil_test_003_001_execute +}; + +/** + * @page nil_test_003_002 [3.2] Semaphore primitives, with state change + * + *

Description

+ * Wait, Signal and Reset primitives are tested. The testing thread + * triggers a state change. + * + *

Test Steps

+ * - [3.2.1] The function chSemWait() is invoked, after return the + * counter and the returned message are tested. The semaphore is + * signaled by another thread. + * - [3.2.2] The function chSemWait() is invoked, after return the + * counter and the returned message are tested. The semaphore is + * reset by another thread. + * . + */ + +static void nil_test_003_002_setup(void) { + chSemObjectInit(&gsem1, 0); +} + +static void nil_test_003_002_teardown(void) { + chSemReset(&gsem1, 0); +} + +static void nil_test_003_002_execute(void) { + + /* [3.2.1] The function chSemWait() is invoked, after return the + counter and the returned message are tested. The semaphore is + signaled by another thread.*/ + test_set_step(1); + { + msg_t msg; + + msg = chSemWait(&gsem1); + test_assert_lock(chSemGetCounterI(&gsem1) == 0, "wrong counter value"); + test_assert(MSG_OK == msg, "wrong returned message"); + } + + /* [3.2.2] The function chSemWait() is invoked, after return the + counter and the returned message are tested. The semaphore is + reset by another thread.*/ + test_set_step(2); + { + msg_t msg; + + msg = chSemWait(&gsem2); + test_assert_lock(chSemGetCounterI(&gsem2) == 0,"wrong counter value"); + test_assert(MSG_RESET == msg, "wrong returned message"); + } +} + +static const testcase_t nil_test_003_002 = { + "Semaphore primitives, with state change", + nil_test_003_002_setup, + nil_test_003_002_teardown, + nil_test_003_002_execute +}; + +/** + * @page nil_test_003_003 [3.3] Semaphores timeout + * + *

Description

+ * Timeout on semaphores is tested. + * + *

Test Steps

+ * - [3.3.1] The function chSemWaitTimeout() is invoked a first time, + * after return the system time, the counter and the returned message + * are tested. + * - [3.3.2] The function chSemWaitTimeout() is invoked again, after + * return the system time, the counter and the returned message are + * tested. + * . + */ + +static void nil_test_003_003_setup(void) { + chSemObjectInit(&sem1, 0); +} + +static void nil_test_003_003_teardown(void) { + chSemReset(&sem1, 0); +} + +static void nil_test_003_003_execute(void) { + systime_t time; + msg_t msg; + + /* [3.3.1] The function chSemWaitTimeout() is invoked a first time, + after return the system time, the counter and the returned message + are tested.*/ + test_set_step(1); + { + time = chVTGetSystemTimeX(); + msg = chSemWaitTimeout(&sem1, TIME_MS2I(1000)); + test_assert_time_window(chTimeAddX(time, TIME_MS2I(1000)), + chTimeAddX(time, TIME_MS2I(1000) + 1), + "out of time window"); + test_assert_lock(chSemGetCounterI(&sem1) == 0, "wrong counter value"); + test_assert(MSG_TIMEOUT == msg, "wrong timeout message"); + } + + /* [3.3.2] The function chSemWaitTimeout() is invoked again, after + return the system time, the counter and the returned message are + tested.*/ + test_set_step(2); + { + time = chVTGetSystemTimeX(); + msg = chSemWaitTimeout(&sem1, TIME_MS2I(1000)); + test_assert_time_window(chTimeAddX(time, TIME_MS2I(1000)), + chTimeAddX(time, TIME_MS2I(1000) + 1), + "out of time window"); + test_assert_lock(chSemGetCounterI(&sem1) == 0, "wrong counter value"); + test_assert(MSG_TIMEOUT == msg, "wrong timeout message"); + } +} + +static const testcase_t nil_test_003_003 = { + "Semaphores timeout", + nil_test_003_003_setup, + nil_test_003_003_teardown, + nil_test_003_003_execute +}; + +/**************************************************************************** + * Exported data. + ****************************************************************************/ + +/** + * @brief Array of test cases. + */ +const testcase_t * const nil_test_sequence_003_array[] = { + &nil_test_003_001, + &nil_test_003_002, + &nil_test_003_003, + NULL +}; + +/** + * @brief Semaphores. + */ +const testsequence_t nil_test_sequence_003 = { + NULL, + nil_test_sequence_003_array +}; + +#endif /* CH_CFG_USE_SEMAPHORES */ diff --git a/test/nil/source/test/nil_test_sequence_003.h b/test/nil/source/test/nil_test_sequence_003.h new file mode 100644 index 000000000..10adaeaf5 --- /dev/null +++ b/test/nil/source/test/nil_test_sequence_003.h @@ -0,0 +1,27 @@ +/* + ChibiOS - Copyright (C) 2006..2017 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. +*/ + +/** + * @file nil_test_sequence_003.h + * @brief Test Sequence 003 header. + */ + +#ifndef NIL_TEST_SEQUENCE_003_H +#define NIL_TEST_SEQUENCE_003_H + +extern const testsequence_t nil_test_sequence_003; + +#endif /* NIL_TEST_SEQUENCE_003_H */ diff --git a/test/nil/source/test/nil_test_sequence_004.c b/test/nil/source/test/nil_test_sequence_004.c new file mode 100644 index 000000000..719a114e1 --- /dev/null +++ b/test/nil/source/test/nil_test_sequence_004.c @@ -0,0 +1,206 @@ +/* + ChibiOS - Copyright (C) 2006..2017 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 "nil_test_root.h" + +/** + * @file nil_test_sequence_004.c + * @brief Test Sequence 004 code. + * + * @page nil_test_sequence_004 [4] Suspend/Resume and Event Flags + * + * File: @ref nil_test_sequence_004.c + * + *

Description

+ * This sequence tests the ChibiOS/NIL functionalities related to + * threads suspend/resume and event flags. + * + *

Test Cases

+ * - @subpage nil_test_004_001 + * - @subpage nil_test_004_002 + * . + */ + +/**************************************************************************** + * Shared code. + ****************************************************************************/ + +static thread_reference_t tr1; + +/**************************************************************************** + * Test cases. + ****************************************************************************/ + +/** + * @page nil_test_004_001 [4.1] Suspend and Resume functionality + * + *

Description

+ * The functionality of chThdSuspendTimeoutS() and chThdResumeI() is + * tested. + * + *

Test Steps

+ * - [4.1.1] The function chThdSuspendTimeoutS() is invoked, the thread + * is remotely resumed with message @p MSG_OK. On return the message + * and the state of the reference are tested. + * - [4.1.2] The function chThdSuspendTimeoutS() is invoked, the thread + * is not resumed so a timeout must occur. On return the message and + * the state of the reference are tested. + * . + */ + +static void nil_test_004_001_setup(void) { + tr1 = NULL; +} + +static void nil_test_004_001_execute(void) { + systime_t time; + msg_t msg; + + /* [4.1.1] The function chThdSuspendTimeoutS() is invoked, the thread + is remotely resumed with message @p MSG_OK. On return the message + and the state of the reference are tested.*/ + test_set_step(1); + { + chSysLock(); + msg = chThdSuspendTimeoutS(>r1, TIME_INFINITE); + chSysUnlock(); + test_assert(NULL == gtr1, "not NULL"); + test_assert(MSG_OK == msg,"wrong returned message"); + } + + /* [4.1.2] The function chThdSuspendTimeoutS() is invoked, the thread + is not resumed so a timeout must occur. On return the message and + the state of the reference are tested.*/ + test_set_step(2); + { + chSysLock(); + time = chVTGetSystemTimeX(); + msg = chThdSuspendTimeoutS(&tr1, TIME_MS2I(1000)); + chSysUnlock(); + test_assert_time_window(chTimeAddX(time, TIME_MS2I(1000)), + chTimeAddX(time, TIME_MS2I(1000) + 1), + "out of time window"); + test_assert(NULL == tr1, "not NULL"); + test_assert(MSG_TIMEOUT == msg, "wrong returned message"); + } +} + +static const testcase_t nil_test_004_001 = { + "Suspend and Resume functionality", + nil_test_004_001_setup, + NULL, + nil_test_004_001_execute +}; + +#if (CH_CFG_USE_EVENTS) || defined(__DOXYGEN__) +/** + * @page nil_test_004_002 [4.2] Events Flags functionality + * + *

Description

+ * Event flags functionality is tested. + * + *

Conditions

+ * This test is only executed if the following preprocessor condition + * evaluates to true: + * - CH_CFG_USE_EVENTS + * . + * + *

Test Steps

+ * - [4.2.1] A set of event flags are set on the current thread then + * the function chEvtWaitAnyTimeout() is invoked, the function is + * supposed to return immediately because the event flags are already + * pending, after return the events mask is tested. + * - [4.2.2] The pending event flags mask is cleared then the function + * chEvtWaitAnyTimeout() is invoked, after return the events mask is + * tested. The thread is signaled by another thread. + * - [4.2.3] The function chEvtWaitAnyTimeout() is invoked, no event + * can wakeup the thread, the function must return because timeout. + * . + */ + +static void nil_test_004_002_execute(void) { + systime_t time; + eventmask_t events; + + /* [4.2.1] A set of event flags are set on the current thread then + the function chEvtWaitAnyTimeout() is invoked, the function is + supposed to return immediately because the event flags are already + pending, after return the events mask is tested.*/ + test_set_step(1); + { + time = chVTGetSystemTimeX(); + chEvtSignal(chThdGetSelfX(), 0x55); + events = chEvtWaitAnyTimeout(ALL_EVENTS, TIME_MS2I(1000)); + test_assert((eventmask_t)0 != events, "timed out"); + test_assert((eventmask_t)0x55 == events, "wrong events mask"); + } + + /* [4.2.2] The pending event flags mask is cleared then the function + chEvtWaitAnyTimeout() is invoked, after return the events mask is + tested. The thread is signaled by another thread.*/ + test_set_step(2); + { + time = chVTGetSystemTimeX(); + chThdGetSelfX()->epmask = 0; + events = chEvtWaitAnyTimeout(ALL_EVENTS, TIME_MS2I(1000)); + test_assert((eventmask_t)0 != events, "timed out"); + test_assert((eventmask_t)0x55 == events, "wrong events mask"); + } + + /* [4.2.3] The function chEvtWaitAnyTimeout() is invoked, no event + can wakeup the thread, the function must return because timeout.*/ + test_set_step(3); + { + time = chVTGetSystemTimeX(); + events = chEvtWaitAnyTimeout(0, TIME_MS2I(1000)); + test_assert_time_window(chTimeAddX(time, TIME_MS2I(1000)), + chTimeAddX(time, TIME_MS2I(1000) + 1), + "out of time window"); + test_assert((eventmask_t)0 == events, "wrong events mask"); + } +} + +static const testcase_t nil_test_004_002 = { + "Events Flags functionality", + NULL, + NULL, + nil_test_004_002_execute +}; +#endif /* CH_CFG_USE_EVENTS */ + +/**************************************************************************** + * Exported data. + ****************************************************************************/ + +/** + * @brief Array of test cases. + */ +const testcase_t * const nil_test_sequence_004_array[] = { + &nil_test_004_001, +#if (CH_CFG_USE_EVENTS) || defined(__DOXYGEN__) + &nil_test_004_002, +#endif + NULL +}; + +/** + * @brief Suspend/Resume and Event Flags. + */ +const testsequence_t nil_test_sequence_004 = { + NULL, + nil_test_sequence_004_array +}; diff --git a/test/nil/source/test/nil_test_sequence_004.h b/test/nil/source/test/nil_test_sequence_004.h new file mode 100644 index 000000000..88a1080ab --- /dev/null +++ b/test/nil/source/test/nil_test_sequence_004.h @@ -0,0 +1,27 @@ +/* + ChibiOS - Copyright (C) 2006..2017 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. +*/ + +/** + * @file nil_test_sequence_004.h + * @brief Test Sequence 004 header. + */ + +#ifndef NIL_TEST_SEQUENCE_004_H +#define NIL_TEST_SEQUENCE_004_H + +extern const testsequence_t nil_test_sequence_004; + +#endif /* NIL_TEST_SEQUENCE_004_H */ diff --git a/test/nil/source/test/test_root.c b/test/nil/source/test/test_root.c deleted file mode 100644 index 6006e4e2d..000000000 --- a/test/nil/source/test/test_root.c +++ /dev/null @@ -1,127 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2017 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. -*/ - -/** - * @mainpage Test Suite Specification - * Test suite for ChibiOS/NIL. The purpose of this suite is to perform - * unit tests on the NIL modules and to converge to 100% code coverage - * through successive improvements. - * - *

Test Sequences

- * - @subpage test_sequence_001 - * - @subpage test_sequence_002 - * - @subpage test_sequence_003 - * - @subpage test_sequence_004 - * - @subpage test_sequence_005 - * - @subpage test_sequence_006 - * - @subpage test_sequence_007 - * . - */ - -/** - * @file test_root.c - * @brief Test Suite root structures code. - */ - -#include "hal.h" -#include "ch_test.h" -#include "test_root.h" - -#if !defined(__DOXYGEN__) - -/*===========================================================================*/ -/* Module exported variables. */ -/*===========================================================================*/ - -/** - * @brief Array of all the test sequences. - */ -const testcase_t * const *test_suite[] = { - test_sequence_001, - test_sequence_002, -#if (CH_CFG_USE_SEMAPHORES) || defined(__DOXYGEN__) - test_sequence_003, -#endif - test_sequence_004, -#if (CH_CFG_USE_MAILBOXES) || defined(__DOXYGEN__) - test_sequence_005, -#endif -#if (CH_CFG_USE_MEMPOOLS) || defined(__DOXYGEN__) - test_sequence_006, -#endif -#if (CH_CFG_USE_HEAP) || defined(__DOXYGEN__) - test_sequence_007, -#endif - NULL -}; - -/*===========================================================================*/ -/* Shared code. */ -/*===========================================================================*/ - -void test_print_port_info(void) { - -#ifdef PORT_COMPILER_NAME - test_print("*** Compiler: "); - test_println(PORT_COMPILER_NAME); -#endif - test_print("*** Architecture: "); - test_println(PORT_ARCHITECTURE_NAME); -#ifdef PORT_CORE_VARIANT_NAME - test_print("*** Core Variant: "); - test_println(PORT_CORE_VARIANT_NAME); -#endif -#ifdef PORT_INFO - test_print("*** Port Info: "); - test_println(PORT_INFO); -#endif -} - -semaphore_t gsem1, gsem2; -thread_reference_t gtr1; - -/* - * Support thread. - */ -THD_WORKING_AREA(wa_test_support, 128); -THD_FUNCTION(test_support, arg) { -#if CH_CFG_USE_EVENTS == TRUE - thread_t *tp = (thread_t *)arg; -#else - (void)arg; -#endif - - /* Initializing global resources.*/ - chSemObjectInit(&gsem1, 0); - chSemObjectInit(&gsem2, 0); - - while (true) { - chSysLock(); - if (chSemGetCounterI(&gsem1) < 0) - chSemSignalI(&gsem1); - chSemResetI(&gsem2, 0); - chThdResumeI(>r1, MSG_OK); -#if CH_CFG_USE_EVENTS == TRUE - chEvtSignalI(tp, 0x55); -#endif - chSchRescheduleS(); - chSysUnlock(); - - chThdSleepMilliseconds(250); - } -} - -#endif /* !defined(__DOXYGEN__) */ diff --git a/test/nil/source/test/test_root.h b/test/nil/source/test/test_root.h deleted file mode 100644 index 39c680871..000000000 --- a/test/nil/source/test/test_root.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2017 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. -*/ - -/** - * @file test_root.h - * @brief Test Suite root structures header. - */ - -#ifndef TEST_ROOT_H -#define TEST_ROOT_H - -#include "test_sequence_001.h" -#include "test_sequence_002.h" -#include "test_sequence_003.h" -#include "test_sequence_004.h" -#include "test_sequence_005.h" -#include "test_sequence_006.h" -#include "test_sequence_007.h" - -#if !defined(__DOXYGEN__) - -/*===========================================================================*/ -/* External declarations. */ -/*===========================================================================*/ - -extern const testcase_t * const *test_suite[]; - -#ifdef __cplusplus -extern "C" { -#endif -#ifdef __cplusplus -} -#endif - -/*===========================================================================*/ -/* Shared definitions. */ -/*===========================================================================*/ - -#define TEST_SUITE_NAME "ChibiOS/NIL Test Suite" - -#define TEST_REPORT_HOOK_HEADER test_print_port_info(); - -extern semaphore_t gsem1, gsem2; -extern thread_reference_t gtr1; -extern THD_WORKING_AREA(wa_test_support, 128); - -void test_print_port_info(void); -THD_FUNCTION(test_support, arg); - -#endif /* !defined(__DOXYGEN__) */ - -#endif /* TEST_ROOT_H */ diff --git a/test/nil/source/test/test_sequence_001.c b/test/nil/source/test/test_sequence_001.c deleted file mode 100644 index f20e3a3fd..000000000 --- a/test/nil/source/test/test_sequence_001.c +++ /dev/null @@ -1,175 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2017 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" - -/** - * @file test_sequence_001.c - * @brief Test Sequence 001 code. - * - * @page test_sequence_001 [1] Information - * - * File: @ref test_sequence_001.c - * - *

Description

- * This sequence reports configuration and version information about - * the NIL kernel. - * - *

Test Cases

- * - @subpage test_001_001 - * - @subpage test_001_002 - * . - */ - -/**************************************************************************** - * Shared code. - ****************************************************************************/ - -#include "ch.h" - -/**************************************************************************** - * Test cases. - ****************************************************************************/ - -/** - * @page test_001_001 [1.1] Kernel Info - * - *

Description

- * The version numbers are reported. - * - *

Test Steps

- * - [1.1.1] Prints the version string. - * . - */ - -static void test_001_001_execute(void) { - - /* [1.1.1] Prints the version string.*/ - test_set_step(1); - { - test_println("--- Product: ChibiOS/NIL"); - test_print("--- Stable Flag: "); - test_printn(CH_KERNEL_STABLE); - test_println(""); - test_print("--- Version String: "); - test_println(CH_KERNEL_VERSION); - test_print("--- Major Number: "); - test_printn(CH_KERNEL_MAJOR); - test_println(""); - test_print("--- Minor Number: "); - test_printn(CH_KERNEL_MINOR); - test_println(""); - test_print("--- Patch Number: "); - test_printn(CH_KERNEL_PATCH); - test_println(""); - } -} - -static const testcase_t test_001_001 = { - "Kernel Info", - NULL, - NULL, - test_001_001_execute -}; - -/** - * @page test_001_002 [1.2] Kernel Settings - * - *

Description

- * The static kernel settings are reported. - * - *

Test Steps

- * - [1.2.1] Prints the configuration options settings. - * . - */ - -static void test_001_002_execute(void) { - - /* [1.2.1] Prints the configuration options settings.*/ - test_set_step(1); - { - test_print("--- CH_CFG_NUM_THREADS: "); - test_printn(CH_CFG_NUM_THREADS); - test_println(""); - test_print("--- CH_CFG_ST_RESOLUTION: "); - test_printn(CH_CFG_ST_RESOLUTION); - test_println(""); - test_print("--- CH_CFG_ST_FREQUENCY: "); - test_printn(CH_CFG_ST_FREQUENCY); - test_println(""); - test_print("--- CH_CFG_ST_TIMEDELTA: "); - test_printn(CH_CFG_ST_TIMEDELTA); - test_println(""); - test_print("--- CH_CFG_USE_SEMAPHORES: "); - test_printn(CH_CFG_USE_SEMAPHORES); - test_println(""); - test_print("--- CH_CFG_USE_MUTEXES: "); - test_printn(CH_CFG_USE_MUTEXES); - test_println(""); - test_print("--- CH_CFG_USE_EVENTS: "); - test_printn(CH_CFG_USE_EVENTS); - test_println(""); - test_print("--- CH_CFG_USE_MAILBOXES: "); - test_printn(CH_CFG_USE_MAILBOXES); - test_println(""); - test_print("--- CH_CFG_USE_MEMCORE: "); - test_printn(CH_CFG_USE_MEMCORE); - test_println(""); - test_print("--- CH_CFG_USE_HEAP: "); - test_printn(CH_CFG_USE_HEAP); - test_println(""); - test_print("--- CH_CFG_USE_MEMPOOLS: "); - test_printn(CH_CFG_USE_MEMPOOLS); - test_println(""); - test_print("--- CH_DBG_STATISTICS: "); - test_printn(CH_DBG_STATISTICS); - test_println(""); - test_print("--- CH_DBG_SYSTEM_STATE_CHECK: "); - test_printn(CH_DBG_SYSTEM_STATE_CHECK); - test_println(""); - test_print("--- CH_DBG_ENABLE_CHECKS: "); - test_printn(CH_DBG_ENABLE_CHECKS); - test_println(""); - test_print("--- CH_DBG_ENABLE_ASSERTS: "); - test_printn(CH_DBG_ENABLE_ASSERTS); - test_println(""); - test_print("--- CH_DBG_ENABLE_STACK_CHECK: "); - test_printn(CH_DBG_ENABLE_STACK_CHECK); - test_println(""); - } -} - -static const testcase_t test_001_002 = { - "Kernel Settings", - NULL, - NULL, - test_001_002_execute -}; - -/**************************************************************************** - * Exported data. - ****************************************************************************/ - -/** - * @brief Information. - */ -const testcase_t * const test_sequence_001[] = { - &test_001_001, - &test_001_002, - NULL -}; diff --git a/test/nil/source/test/test_sequence_001.h b/test/nil/source/test/test_sequence_001.h deleted file mode 100644 index 9684d47f6..000000000 --- a/test/nil/source/test/test_sequence_001.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2017 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. -*/ - -/** - * @file test_sequence_001.h - * @brief Test Sequence 001 header. - */ - -#ifndef TEST_SEQUENCE_001_H -#define TEST_SEQUENCE_001_H - -extern const testcase_t * const test_sequence_001[]; - -#endif /* TEST_SEQUENCE_001_H */ diff --git a/test/nil/source/test/test_sequence_002.c b/test/nil/source/test/test_sequence_002.c deleted file mode 100644 index db5aff647..000000000 --- a/test/nil/source/test/test_sequence_002.c +++ /dev/null @@ -1,183 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2017 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" - -/** - * @file test_sequence_002.c - * @brief Test Sequence 002 code. - * - * @page test_sequence_002 [2] Threads Functionality - * - * File: @ref test_sequence_002.c - * - *

Description

- * This sequence tests the ChibiOS/NIL functionalities related to - * threading. - * - *

Test Cases

- * - @subpage test_002_001 - * - @subpage test_002_002 - * . - */ - -/**************************************************************************** - * Shared code. - ****************************************************************************/ - -#include "ch.h" - -/**************************************************************************** - * Test cases. - ****************************************************************************/ - -/** - * @page test_002_001 [2.1] System Tick Counter functionality - * - *

Description

- * The functionality of the API @p chVTGetSystemTimeX() is tested. - * - *

Test Steps

- * - [2.1.1] A System Tick Counter increment is expected, the test - * simply hangs if it does not happen. - * . - */ - -static void test_002_001_execute(void) { - - /* [2.1.1] A System Tick Counter increment is expected, the test - simply hangs if it does not happen.*/ - test_set_step(1); - { - systime_t time = chVTGetSystemTimeX(); - while (time == chVTGetSystemTimeX()) { - } - } -} - -static const testcase_t test_002_001 = { - "System Tick Counter functionality", - NULL, - NULL, - test_002_001_execute -}; - -/** - * @page test_002_002 [2.2] Thread Sleep functionality - * - *

Description

- * The functionality of @p chThdSleep() and derivatives is tested. - * - *

Test Steps

- * - [2.2.1] The current system time is read then a sleep is performed - * for 100 system ticks and on exit the system time is verified - * again. - * - [2.2.2] The current system time is read then a sleep is performed - * for 100000 microseconds and on exit the system time is verified - * again. - * - [2.2.3] The current system time is read then a sleep is performed - * for 100 milliseconds and on exit the system time is verified - * again. - * - [2.2.4] The current system time is read then a sleep is performed - * for 1 second and on exit the system time is verified again. - * - [2.2.5] Function chThdSleepUntil() is tested with a timeline of - * "now" + 100 ticks. - * . - */ - -static void test_002_002_execute(void) { - systime_t time; - - /* [2.2.1] The current system time is read then a sleep is performed - for 100 system ticks and on exit the system time is verified - again.*/ - test_set_step(1); - { - time = chVTGetSystemTimeX(); - chThdSleep(100); - test_assert_time_window(time + 100, - time + 100 + 1, - "out of time window"); - } - - /* [2.2.2] The current system time is read then a sleep is performed - for 100000 microseconds and on exit the system time is verified - again.*/ - test_set_step(2); - { - time = chVTGetSystemTimeX(); - chThdSleepMicroseconds(100000); - test_assert_time_window(time + US2ST(100000), - time + US2ST(100000) + 1, - "out of time window"); - } - - /* [2.2.3] The current system time is read then a sleep is performed - for 100 milliseconds and on exit the system time is verified - again.*/ - test_set_step(3); - { - time = chVTGetSystemTimeX(); - chThdSleepMilliseconds(100); - test_assert_time_window(time + MS2ST(100), - time + MS2ST(100) + 1, - "out of time window"); - } - - /* [2.2.4] The current system time is read then a sleep is performed - for 1 second and on exit the system time is verified again.*/ - test_set_step(4); - { - time = chVTGetSystemTimeX(); - chThdSleepSeconds(1); - test_assert_time_window(time + S2ST(1), - time + S2ST(1) + 1, - "out of time window"); - } - - /* [2.2.5] Function chThdSleepUntil() is tested with a timeline of - "now" + 100 ticks.*/ - test_set_step(5); - { - time = chVTGetSystemTimeX(); - chThdSleepUntil(time + 100); - test_assert_time_window(time + 100, - time + 100 + 1, - "out of time window"); - } -} - -static const testcase_t test_002_002 = { - "Thread Sleep functionality", - NULL, - NULL, - test_002_002_execute -}; - -/**************************************************************************** - * Exported data. - ****************************************************************************/ - -/** - * @brief Threads Functionality. - */ -const testcase_t * const test_sequence_002[] = { - &test_002_001, - &test_002_002, - NULL -}; diff --git a/test/nil/source/test/test_sequence_002.h b/test/nil/source/test/test_sequence_002.h deleted file mode 100644 index 190f9ca46..000000000 --- a/test/nil/source/test/test_sequence_002.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2017 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. -*/ - -/** - * @file test_sequence_002.h - * @brief Test Sequence 002 header. - */ - -#ifndef TEST_SEQUENCE_002_H -#define TEST_SEQUENCE_002_H - -extern const testcase_t * const test_sequence_002[]; - -#endif /* TEST_SEQUENCE_002_H */ diff --git a/test/nil/source/test/test_sequence_003.c b/test/nil/source/test/test_sequence_003.c deleted file mode 100644 index 48159347d..000000000 --- a/test/nil/source/test/test_sequence_003.c +++ /dev/null @@ -1,259 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2017 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" - -/** - * @file test_sequence_003.c - * @brief Test Sequence 003 code. - * - * @page test_sequence_003 [3] Semaphores - * - * File: @ref test_sequence_003.c - * - *

Description

- * This sequence tests the ChibiOS/NIL functionalities related to - * counter semaphores. - * - *

Conditions

- * This sequence is only executed if the following preprocessor condition - * evaluates to true: - * - CH_CFG_USE_SEMAPHORES - * . - * - *

Test Cases

- * - @subpage test_003_001 - * - @subpage test_003_002 - * - @subpage test_003_003 - * . - */ - -#if (CH_CFG_USE_SEMAPHORES) || defined(__DOXYGEN__) - -/**************************************************************************** - * Shared code. - ****************************************************************************/ - -#include "ch.h" - -static semaphore_t sem1; - -/**************************************************************************** - * Test cases. - ****************************************************************************/ - -/** - * @page test_003_001 [3.1] Semaphore primitives, no state change - * - *

Description

- * Wait, Signal and Reset primitives are tested. The testing thread - * does not trigger a state change. - * - *

Test Steps

- * - [3.1.1] The function chSemWait() is invoked, after return the - * counter and the returned message are tested. - * - [3.1.2] The function chSemSignal() is invoked, after return the - * counter is tested. - * - [3.1.3] The function chSemReset() is invoked, after return the - * counter is tested. - * . - */ - -static void test_003_001_setup(void) { - chSemObjectInit(&sem1, 1); -} - -static void test_003_001_teardown(void) { - chSemReset(&sem1, 0); -} - -static void test_003_001_execute(void) { - - /* [3.1.1] The function chSemWait() is invoked, after return the - counter and the returned message are tested.*/ - test_set_step(1); - { - msg_t msg; - - msg = chSemWait(&sem1); - test_assert_lock(chSemGetCounterI(&sem1) == 0, "wrong counter value"); - test_assert(MSG_OK == msg, "wrong returned message"); - } - - /* [3.1.2] The function chSemSignal() is invoked, after return the - counter is tested.*/ - test_set_step(2); - { - chSemSignal(&sem1); - test_assert_lock(chSemGetCounterI(&sem1) == 1, "wrong counter value"); - } - - /* [3.1.3] The function chSemReset() is invoked, after return the - counter is tested.*/ - test_set_step(3); - { - chSemReset(&sem1, 2); - test_assert_lock(chSemGetCounterI(&sem1) == 2, "wrong counter value"); - } -} - -static const testcase_t test_003_001 = { - "Semaphore primitives, no state change", - test_003_001_setup, - test_003_001_teardown, - test_003_001_execute -}; - -/** - * @page test_003_002 [3.2] Semaphore primitives, with state change - * - *

Description

- * Wait, Signal and Reset primitives are tested. The testing thread - * triggers a state change. - * - *

Test Steps

- * - [3.2.1] The function chSemWait() is invoked, after return the - * counter and the returned message are tested. The semaphore is - * signaled by another thread. - * - [3.2.2] The function chSemWait() is invoked, after return the - * counter and the returned message are tested. The semaphore is - * reset by another thread. - * . - */ - -static void test_003_002_setup(void) { - chSemObjectInit(&gsem1, 0); -} - -static void test_003_002_teardown(void) { - chSemReset(&gsem1, 0); -} - -static void test_003_002_execute(void) { - - /* [3.2.1] The function chSemWait() is invoked, after return the - counter and the returned message are tested. The semaphore is - signaled by another thread.*/ - test_set_step(1); - { - msg_t msg; - - msg = chSemWait(&gsem1); - test_assert_lock(chSemGetCounterI(&gsem1) == 0, "wrong counter value"); - test_assert(MSG_OK == msg, "wrong returned message"); - } - - /* [3.2.2] The function chSemWait() is invoked, after return the - counter and the returned message are tested. The semaphore is - reset by another thread.*/ - test_set_step(2); - { - msg_t msg; - - msg = chSemWait(&gsem2); - test_assert_lock(chSemGetCounterI(&gsem2) == 0,"wrong counter value"); - test_assert(MSG_RESET == msg, "wrong returned message"); - } -} - -static const testcase_t test_003_002 = { - "Semaphore primitives, with state change", - test_003_002_setup, - test_003_002_teardown, - test_003_002_execute -}; - -/** - * @page test_003_003 [3.3] Semaphores timeout - * - *

Description

- * Timeout on semaphores is tested. - * - *

Test Steps

- * - [3.3.1] The function chSemWaitTimeout() is invoked a first time, - * after return the system time, the counter and the returned message - * are tested. - * - [3.3.2] The function chSemWaitTimeout() is invoked again, after - * return the system time, the counter and the returned message are - * tested. - * . - */ - -static void test_003_003_setup(void) { - chSemObjectInit(&sem1, 0); -} - -static void test_003_003_teardown(void) { - chSemReset(&sem1, 0); -} - -static void test_003_003_execute(void) { - systime_t time; - msg_t msg; - - /* [3.3.1] The function chSemWaitTimeout() is invoked a first time, - after return the system time, the counter and the returned message - are tested.*/ - test_set_step(1); - { - time = chVTGetSystemTimeX(); - msg = chSemWaitTimeout(&sem1, MS2ST(1000)); - test_assert_time_window(time + MS2ST(1000), - time + MS2ST(1000) + 1, - "out of time window"); - test_assert_lock(chSemGetCounterI(&sem1) == 0, "wrong counter value"); - test_assert(MSG_TIMEOUT == msg, "wrong timeout message"); - } - - /* [3.3.2] The function chSemWaitTimeout() is invoked again, after - return the system time, the counter and the returned message are - tested.*/ - test_set_step(2); - { - time = chVTGetSystemTimeX(); - msg = chSemWaitTimeout(&sem1, MS2ST(1000)); - test_assert_time_window(time + MS2ST(1000), - time + MS2ST(1000) + 1, - "out of time window"); - test_assert_lock(chSemGetCounterI(&sem1) == 0, "wrong counter value"); - test_assert(MSG_TIMEOUT == msg, "wrong timeout message"); - } -} - -static const testcase_t test_003_003 = { - "Semaphores timeout", - test_003_003_setup, - test_003_003_teardown, - test_003_003_execute -}; - -/**************************************************************************** - * Exported data. - ****************************************************************************/ - -/** - * @brief Semaphores. - */ -const testcase_t * const test_sequence_003[] = { - &test_003_001, - &test_003_002, - &test_003_003, - NULL -}; - -#endif /* CH_CFG_USE_SEMAPHORES */ diff --git a/test/nil/source/test/test_sequence_003.h b/test/nil/source/test/test_sequence_003.h deleted file mode 100644 index 2de592a2f..000000000 --- a/test/nil/source/test/test_sequence_003.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2017 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. -*/ - -/** - * @file test_sequence_003.h - * @brief Test Sequence 003 header. - */ - -#ifndef TEST_SEQUENCE_003_H -#define TEST_SEQUENCE_003_H - -extern const testcase_t * const test_sequence_003[]; - -#endif /* TEST_SEQUENCE_003_H */ diff --git a/test/nil/source/test/test_sequence_004.c b/test/nil/source/test/test_sequence_004.c deleted file mode 100644 index 0b9c8bc96..000000000 --- a/test/nil/source/test/test_sequence_004.c +++ /dev/null @@ -1,199 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2017 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" - -/** - * @file test_sequence_004.c - * @brief Test Sequence 004 code. - * - * @page test_sequence_004 [4] Suspend/Resume and Event Flags - * - * File: @ref test_sequence_004.c - * - *

Description

- * This sequence tests the ChibiOS/NIL functionalities related to - * threads suspend/resume and event flags. - * - *

Test Cases

- * - @subpage test_004_001 - * - @subpage test_004_002 - * . - */ - -/**************************************************************************** - * Shared code. - ****************************************************************************/ - -static thread_reference_t tr1; - -/**************************************************************************** - * Test cases. - ****************************************************************************/ - -/** - * @page test_004_001 [4.1] Suspend and Resume functionality - * - *

Description

- * The functionality of chThdSuspendTimeoutS() and chThdResumeI() is - * tested. - * - *

Test Steps

- * - [4.1.1] The function chThdSuspendTimeoutS() is invoked, the thread - * is remotely resumed with message @p MSG_OK. On return the message - * and the state of the reference are tested. - * - [4.1.2] The function chThdSuspendTimeoutS() is invoked, the thread - * is not resumed so a timeout must occur. On return the message and - * the state of the reference are tested. - * . - */ - -static void test_004_001_setup(void) { - tr1 = NULL; -} - -static void test_004_001_execute(void) { - systime_t time; - msg_t msg; - - /* [4.1.1] The function chThdSuspendTimeoutS() is invoked, the thread - is remotely resumed with message @p MSG_OK. On return the message - and the state of the reference are tested.*/ - test_set_step(1); - { - chSysLock(); - msg = chThdSuspendTimeoutS(>r1, TIME_INFINITE); - chSysUnlock(); - test_assert(NULL == gtr1, "not NULL"); - test_assert(MSG_OK == msg,"wrong returned message"); - } - - /* [4.1.2] The function chThdSuspendTimeoutS() is invoked, the thread - is not resumed so a timeout must occur. On return the message and - the state of the reference are tested.*/ - test_set_step(2); - { - chSysLock(); - time = chVTGetSystemTimeX(); - msg = chThdSuspendTimeoutS(&tr1, MS2ST(1000)); - chSysUnlock(); - test_assert_time_window(time + MS2ST(1000), - time + MS2ST(1000) + 1, - "out of time window"); - test_assert(NULL == tr1, "not NULL"); - test_assert(MSG_TIMEOUT == msg, "wrong returned message"); - } -} - -static const testcase_t test_004_001 = { - "Suspend and Resume functionality", - test_004_001_setup, - NULL, - test_004_001_execute -}; - -#if (CH_CFG_USE_EVENTS) || defined(__DOXYGEN__) -/** - * @page test_004_002 [4.2] Events Flags functionality - * - *

Description

- * Event flags functionality is tested. - * - *

Conditions

- * This test is only executed if the following preprocessor condition - * evaluates to true: - * - CH_CFG_USE_EVENTS - * . - * - *

Test Steps

- * - [4.2.1] A set of event flags are set on the current thread then - * the function chEvtWaitAnyTimeout() is invoked, the function is - * supposed to return immediately because the event flags are already - * pending, after return the events mask is tested. - * - [4.2.2] The pending event flags mask is cleared then the function - * chEvtWaitAnyTimeout() is invoked, after return the events mask is - * tested. The thread is signaled by another thread. - * - [4.2.3] The function chEvtWaitAnyTimeout() is invoked, no event - * can wakeup the thread, the function must return because timeout. - * . - */ - -static void test_004_002_execute(void) { - systime_t time; - eventmask_t events; - - /* [4.2.1] A set of event flags are set on the current thread then - the function chEvtWaitAnyTimeout() is invoked, the function is - supposed to return immediately because the event flags are already - pending, after return the events mask is tested.*/ - test_set_step(1); - { - time = chVTGetSystemTimeX(); - chEvtSignal(chThdGetSelfX(), 0x55); - events = chEvtWaitAnyTimeout(ALL_EVENTS, MS2ST(1000)); - test_assert((eventmask_t)0 != events, "timed out"); - test_assert((eventmask_t)0x55 == events, "wrong events mask"); - } - - /* [4.2.2] The pending event flags mask is cleared then the function - chEvtWaitAnyTimeout() is invoked, after return the events mask is - tested. The thread is signaled by another thread.*/ - test_set_step(2); - { - time = chVTGetSystemTimeX(); - chThdGetSelfX()->epmask = 0; - events = chEvtWaitAnyTimeout(ALL_EVENTS, MS2ST(1000)); - test_assert((eventmask_t)0 != events, "timed out"); - test_assert((eventmask_t)0x55 == events, "wrong events mask"); - } - - /* [4.2.3] The function chEvtWaitAnyTimeout() is invoked, no event - can wakeup the thread, the function must return because timeout.*/ - test_set_step(3); - { - time = chVTGetSystemTimeX(); - events = chEvtWaitAnyTimeout(0, MS2ST(1000)); - test_assert_time_window(time + MS2ST(1000), - time + MS2ST(1000) + 1, - "out of time window"); - test_assert((eventmask_t)0 == events, "wrong events mask"); - } -} - -static const testcase_t test_004_002 = { - "Events Flags functionality", - NULL, - NULL, - test_004_002_execute -}; -#endif /* CH_CFG_USE_EVENTS */ - -/**************************************************************************** - * Exported data. - ****************************************************************************/ - -/** - * @brief Suspend/Resume and Event Flags. - */ -const testcase_t * const test_sequence_004[] = { - &test_004_001, -#if (CH_CFG_USE_EVENTS) || defined(__DOXYGEN__) - &test_004_002, -#endif - NULL -}; diff --git a/test/nil/source/test/test_sequence_004.h b/test/nil/source/test/test_sequence_004.h deleted file mode 100644 index 19d8c1bd7..000000000 --- a/test/nil/source/test/test_sequence_004.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2017 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. -*/ - -/** - * @file test_sequence_004.h - * @brief Test Sequence 004 header. - */ - -#ifndef TEST_SEQUENCE_004_H -#define TEST_SEQUENCE_004_H - -extern const testcase_t * const test_sequence_004[]; - -#endif /* TEST_SEQUENCE_004_H */ diff --git a/test/nil/source/test/test_sequence_005.c b/test/nil/source/test/test_sequence_005.c deleted file mode 100644 index fbca897f9..000000000 --- a/test/nil/source/test/test_sequence_005.c +++ /dev/null @@ -1,408 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2017 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" - -/** - * @file test_sequence_005.c - * @brief Test Sequence 005 code. - * - * @page test_sequence_005 [5] Mailboxes - * - * File: @ref test_sequence_005.c - * - *

Description

- * This sequence tests the ChibiOS/NIL functionalities related to - * mailboxes. - * - *

Conditions

- * This sequence is only executed if the following preprocessor condition - * evaluates to true: - * - CH_CFG_USE_MAILBOXES - * . - * - *

Test Cases

- * - @subpage test_005_001 - * - @subpage test_005_002 - * - @subpage test_005_003 - * . - */ - -#if (CH_CFG_USE_MAILBOXES) || defined(__DOXYGEN__) - -/**************************************************************************** - * Shared code. - ****************************************************************************/ - -#define ALLOWED_DELAY MS2ST(5) -#define MB_SIZE 4 - -static msg_t mb_buffer[MB_SIZE]; -static MAILBOX_DECL(mb1, mb_buffer, MB_SIZE); - -/**************************************************************************** - * Test cases. - ****************************************************************************/ - -/** - * @page test_005_001 [5.1] Mailbox normal API, non-blocking tests - * - *

Description

- * The mailbox normal API is tested without triggering blocking - * conditions. - * - *

Test Steps

- * - [5.1.1] Testing the mailbox size. - * - [5.1.2] Resetting the mailbox, conditions are checked, no errors - * expected. - * - [5.1.3] Testing the behavior of API when the mailbox is in reset - * state then return in active state. - * - [5.1.4] Filling the mailbox using chMBPostTimeout() and - * chMBPostAheadTimeout() once, no errors expected. - * - [5.1.5] Testing intermediate conditions. Data pointers must be - * aligned, semaphore counters are checked. - * - [5.1.6] Emptying the mailbox using chMBFetchTimeout(), no errors - * expected. - * - [5.1.7] Posting and then fetching one more message, no errors - * expected. - * - [5.1.8] Testing final conditions. Data pointers must be aligned to - * buffer start, semaphore counters are checked. - * . - */ - -static void test_005_001_setup(void) { - chMBObjectInit(&mb1, mb_buffer, MB_SIZE); -} - -static void test_005_001_teardown(void) { - chMBReset(&mb1); -} - -static void test_005_001_execute(void) { - msg_t msg1, msg2; - unsigned i; - - /* [5.1.1] Testing the mailbox size.*/ - test_set_step(1); - { - test_assert_lock(chMBGetFreeCountI(&mb1) == MB_SIZE, "wrong size"); - } - - /* [5.1.2] Resetting the mailbox, conditions are checked, no errors - expected.*/ - test_set_step(2); - { - chMBReset(&mb1); - test_assert_lock(chMBGetFreeCountI(&mb1) == MB_SIZE, "not empty"); - test_assert_lock(chMBGetUsedCountI(&mb1) == 0, "still full"); - test_assert_lock(mb1.buffer == mb1.wrptr, "write pointer not aligned to base"); - test_assert_lock(mb1.buffer == mb1.rdptr, "read pointer not aligned to base"); - } - - /* [5.1.3] Testing the behavior of API when the mailbox is in reset - state then return in active state.*/ - test_set_step(3); - { - msg1 = chMBPostTimeout(&mb1, (msg_t)0, TIME_INFINITE); - test_assert(msg1 == MSG_RESET, "not in reset state"); - msg1 = chMBPostAheadTimeout(&mb1, (msg_t)0, TIME_INFINITE); - test_assert(msg1 == MSG_RESET, "not in reset state"); - msg1 = chMBFetchTimeout(&mb1, &msg2, TIME_INFINITE); - test_assert(msg1 == MSG_RESET, "not in reset state"); - chMBResumeX(&mb1); - } - - /* [5.1.4] Filling the mailbox using chMBPostTimeout() and - chMBPostAheadTimeout() once, no errors expected.*/ - test_set_step(4); - { - for (i = 0; i < MB_SIZE - 1; i++) { - msg1 = chMBPostTimeout(&mb1, 'B' + i, TIME_INFINITE); - test_assert(msg1 == MSG_OK, "wrong wake-up message"); - } - msg1 = chMBPostAheadTimeout(&mb1, 'A', TIME_INFINITE); - test_assert(msg1 == MSG_OK, "wrong wake-up message"); - } - - /* [5.1.5] Testing intermediate conditions. Data pointers must be - aligned, semaphore counters are checked.*/ - test_set_step(5); - { - test_assert_lock(chMBGetFreeCountI(&mb1) == 0, "still empty"); - test_assert_lock(chMBGetUsedCountI(&mb1) == MB_SIZE, "not full"); - test_assert_lock(mb1.rdptr == mb1.wrptr, "pointers not aligned"); - } - - /* [5.1.6] Emptying the mailbox using chMBFetchTimeout(), no errors - expected.*/ - test_set_step(6); - { - for (i = 0; i < MB_SIZE; i++) { - msg1 = chMBFetchTimeout(&mb1, &msg2, TIME_INFINITE); - test_assert(msg1 == MSG_OK, "wrong wake-up message"); - test_emit_token(msg2); - } - test_assert_sequence("ABCD", "wrong get sequence"); - } - - /* [5.1.7] Posting and then fetching one more message, no errors - expected.*/ - test_set_step(7); - { - msg1 = chMBPostTimeout(&mb1, 'B' + i, TIME_INFINITE); - test_assert(msg1 == MSG_OK, "wrong wake-up message"); - msg1 = chMBFetchTimeout(&mb1, &msg2, TIME_INFINITE); - test_assert(msg1 == MSG_OK, "wrong wake-up message"); - } - - /* [5.1.8] Testing final conditions. Data pointers must be aligned to - buffer start, semaphore counters are checked.*/ - test_set_step(8); - { - test_assert_lock(chMBGetFreeCountI(&mb1) == MB_SIZE, "not empty"); - test_assert_lock(chMBGetUsedCountI(&mb1) == 0, "still full"); - test_assert(mb1.buffer == mb1.wrptr, "write pointer not aligned to base"); - test_assert(mb1.buffer == mb1.rdptr, "read pointer not aligned to base"); - } -} - -static const testcase_t test_005_001 = { - "Mailbox normal API, non-blocking tests", - test_005_001_setup, - test_005_001_teardown, - test_005_001_execute -}; - -/** - * @page test_005_002 [5.2] Mailbox I-Class API, non-blocking tests - * - *

Description

- * The mailbox I-Class API is tested without triggering blocking - * conditions. - * - *

Test Steps

- * - [5.2.1] Testing the mailbox size. - * - [5.2.2] Resetting the mailbox, conditions are checked, no errors - * expected. - * - [5.2.3] Filling the mailbox using chMBPostI() and chMBPostAheadI() - * once, no errors expected. - * - [5.2.4] Testing intermediate conditions. Data pointers must be - * aligned, semaphore counters are checked. - * - [5.2.5] Emptying the mailbox using chMBFetchI(), no errors - * expected. - * - [5.2.6] Posting and then fetching one more message, no errors - * expected. - * - [5.2.7] Testing final conditions. Data pointers must be aligned to - * buffer start, semaphore counters are checked. - * . - */ - -static void test_005_002_setup(void) { - chMBObjectInit(&mb1, mb_buffer, MB_SIZE); -} - -static void test_005_002_teardown(void) { - chMBReset(&mb1); -} - -static void test_005_002_execute(void) { - msg_t msg1, msg2; - unsigned i; - - /* [5.2.1] Testing the mailbox size.*/ - test_set_step(1); - { - test_assert_lock(chMBGetFreeCountI(&mb1) == MB_SIZE, "wrong size"); - } - - /* [5.2.2] Resetting the mailbox, conditions are checked, no errors - expected.*/ - test_set_step(2); - { - chSysLock(); - chMBResetI(&mb1); - chSysUnlock(); - test_assert_lock(chMBGetFreeCountI(&mb1) == MB_SIZE, "not empty"); - test_assert_lock(chMBGetUsedCountI(&mb1) == 0, "still full"); - test_assert_lock(mb1.buffer == mb1.wrptr, "write pointer not aligned to base"); - test_assert_lock(mb1.buffer == mb1.rdptr, "read pointer not aligned to base"); - chMBResumeX(&mb1); - } - - /* [5.2.3] Filling the mailbox using chMBPostI() and chMBPostAheadI() - once, no errors expected.*/ - test_set_step(3); - { - for (i = 0; i < MB_SIZE - 1; i++) { - chSysLock(); - msg1 = chMBPostI(&mb1, 'B' + i); - chSysUnlock(); - test_assert(msg1 == MSG_OK, "wrong wake-up message"); - } - chSysLock(); - msg1 = chMBPostAheadI(&mb1, 'A'); - chSysUnlock(); - test_assert(msg1 == MSG_OK, "wrong wake-up message"); - } - - /* [5.2.4] Testing intermediate conditions. Data pointers must be - aligned, semaphore counters are checked.*/ - test_set_step(4); - { - test_assert_lock(chMBGetFreeCountI(&mb1) == 0, "still empty"); - test_assert_lock(chMBGetUsedCountI(&mb1) == MB_SIZE, "not full"); - test_assert_lock(mb1.rdptr == mb1.wrptr, "pointers not aligned"); - } - - /* [5.2.5] Emptying the mailbox using chMBFetchI(), no errors - expected.*/ - test_set_step(5); - { - for (i = 0; i < MB_SIZE; i++) { - chSysLock(); - msg1 = chMBFetchI(&mb1, &msg2); - chSysUnlock(); - test_assert(msg1 == MSG_OK, "wrong wake-up message"); - test_emit_token(msg2); - } - test_assert_sequence("ABCD", "wrong get sequence"); - } - - /* [5.2.6] Posting and then fetching one more message, no errors - expected.*/ - test_set_step(6); - { - msg1 = chMBPostTimeout(&mb1, 'B' + i, TIME_INFINITE); - test_assert(msg1 == MSG_OK, "wrong wake-up message"); - msg1 = chMBFetchTimeout(&mb1, &msg2, TIME_INFINITE); - test_assert(msg1 == MSG_OK, "wrong wake-up message"); - } - - /* [5.2.7] Testing final conditions. Data pointers must be aligned to - buffer start, semaphore counters are checked.*/ - test_set_step(7); - { - test_assert_lock(chMBGetFreeCountI(&mb1) == MB_SIZE, "not empty"); - test_assert_lock(chMBGetUsedCountI(&mb1) == 0, "still full"); - test_assert(mb1.buffer == mb1.wrptr, "write pointer not aligned to base"); - test_assert(mb1.buffer == mb1.rdptr, "read pointer not aligned to base"); - } -} - -static const testcase_t test_005_002 = { - "Mailbox I-Class API, non-blocking tests", - test_005_002_setup, - test_005_002_teardown, - test_005_002_execute -}; - -/** - * @page test_005_003 [5.3] Mailbox timeouts - * - *

Description

- * The mailbox API is tested for timeouts. - * - *

Test Steps

- * - [5.3.1] Filling the mailbox. - * - [5.3.2] Testing chMBPostTimeout(), chMBPostI(), - * chMBPostAheadTimeout() and chMBPostAheadI() timeout. - * - [5.3.3] Resetting the mailbox. - * - [5.3.4] Testing chMBFetchTimeout() and chMBFetchI() timeout. - * . - */ - -static void test_005_003_setup(void) { - chMBObjectInit(&mb1, mb_buffer, MB_SIZE); -} - -static void test_005_003_teardown(void) { - chMBReset(&mb1); -} - -static void test_005_003_execute(void) { - msg_t msg1, msg2; - unsigned i; - - /* [5.3.1] Filling the mailbox.*/ - test_set_step(1); - { - for (i = 0; i < MB_SIZE; i++) { - msg1 = chMBPostTimeout(&mb1, 'B' + i, TIME_INFINITE); - test_assert(msg1 == MSG_OK, "wrong wake-up message"); - } - } - - /* [5.3.2] Testing chMBPostTimeout(), chMBPostI(), - chMBPostAheadTimeout() and chMBPostAheadI() timeout.*/ - test_set_step(2); - { - msg1 = chMBPostTimeout(&mb1, 'X', 1); - test_assert(msg1 == MSG_TIMEOUT, "wrong wake-up message"); - chSysLock(); - msg1 = chMBPostI(&mb1, 'X'); - chSysUnlock(); - test_assert(msg1 == MSG_TIMEOUT, "wrong wake-up message"); - msg1 = chMBPostAheadTimeout(&mb1, 'X', 1); - test_assert(msg1 == MSG_TIMEOUT, "wrong wake-up message"); - chSysLock(); - msg1 = chMBPostAheadI(&mb1, 'X'); - chSysUnlock(); - test_assert(msg1 == MSG_TIMEOUT, "wrong wake-up message"); - } - - /* [5.3.3] Resetting the mailbox.*/ - test_set_step(3); - { - chMBReset(&mb1);; - chMBResumeX(&mb1); - } - - /* [5.3.4] Testing chMBFetchTimeout() and chMBFetchI() timeout.*/ - test_set_step(4); - { - msg1 = chMBFetchTimeout(&mb1, &msg2, 1); - test_assert(msg1 == MSG_TIMEOUT, "wrong wake-up message"); - chSysLock(); - msg1 = chMBFetchI(&mb1, &msg2); - chSysUnlock(); - test_assert(msg1 == MSG_TIMEOUT, "wrong wake-up message"); - } -} - -static const testcase_t test_005_003 = { - "Mailbox timeouts", - test_005_003_setup, - test_005_003_teardown, - test_005_003_execute -}; - -/**************************************************************************** - * Exported data. - ****************************************************************************/ - -/** - * @brief Mailboxes. - */ -const testcase_t * const test_sequence_005[] = { - &test_005_001, - &test_005_002, - &test_005_003, - NULL -}; - -#endif /* CH_CFG_USE_MAILBOXES */ diff --git a/test/nil/source/test/test_sequence_005.h b/test/nil/source/test/test_sequence_005.h deleted file mode 100644 index d2df83307..000000000 --- a/test/nil/source/test/test_sequence_005.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2017 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. -*/ - -/** - * @file test_sequence_005.h - * @brief Test Sequence 005 header. - */ - -#ifndef TEST_SEQUENCE_005_H -#define TEST_SEQUENCE_005_H - -extern const testcase_t * const test_sequence_005[]; - -#endif /* TEST_SEQUENCE_005_H */ diff --git a/test/nil/source/test/test_sequence_006.c b/test/nil/source/test/test_sequence_006.c deleted file mode 100644 index 123b6d5e7..000000000 --- a/test/nil/source/test/test_sequence_006.c +++ /dev/null @@ -1,296 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2017 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" - -/** - * @file test_sequence_006.c - * @brief Test Sequence 006 code. - * - * @page test_sequence_006 [6] Memory Pools - * - * File: @ref test_sequence_006.c - * - *

Description

- * This sequence tests the ChibiOS/NIL functionalities related to - * memory pools. - * - *

Conditions

- * This sequence is only executed if the following preprocessor condition - * evaluates to true: - * - CH_CFG_USE_MEMPOOLS - * . - * - *

Test Cases

- * - @subpage test_006_001 - * - @subpage test_006_002 - * - @subpage test_006_003 - * . - */ - -#if (CH_CFG_USE_MEMPOOLS) || defined(__DOXYGEN__) - -/**************************************************************************** - * Shared code. - ****************************************************************************/ - -#define MEMORY_POOL_SIZE 4 - -static uint32_t objects[MEMORY_POOL_SIZE]; -static MEMORYPOOL_DECL(mp1, sizeof (uint32_t), PORT_NATURAL_ALIGN, NULL); - -#if CH_CFG_USE_SEMAPHORES -static GUARDEDMEMORYPOOL_DECL(gmp1, sizeof (uint32_t), PORT_NATURAL_ALIGN); -#endif - -static void *null_provider(size_t size, unsigned align) { - - (void)size; - (void)align; - - return NULL; -} - -/**************************************************************************** - * Test cases. - ****************************************************************************/ - -/** - * @page test_006_001 [6.1] Loading and emptying a memory pool - * - *

Description

- * The memory pool functionality is tested by loading and emptying it, - * all conditions are tested. - * - *

Test Steps

- * - [6.1.1] Adding the objects to the pool using chPoolLoadArray(). - * - [6.1.2] Emptying the pool using chPoolAlloc(). - * - [6.1.3] Now must be empty. - * - [6.1.4] Adding the objects to the pool using chPoolFree(). - * - [6.1.5] Emptying the pool using chPoolAlloc() again. - * - [6.1.6] Now must be empty again. - * - [6.1.7] Covering the case where a provider is unable to return - * more memory. - * . - */ - -static void test_006_001_setup(void) { - chPoolObjectInit(&mp1, sizeof (uint32_t), NULL); -} - -static void test_006_001_execute(void) { - unsigned i; - - /* [6.1.1] Adding the objects to the pool using chPoolLoadArray().*/ - test_set_step(1); - { - chPoolLoadArray(&mp1, objects, MEMORY_POOL_SIZE); - } - - /* [6.1.2] Emptying the pool using chPoolAlloc().*/ - test_set_step(2); - { - for (i = 0; i < MEMORY_POOL_SIZE; i++) - test_assert(chPoolAlloc(&mp1) != NULL, "list empty"); - } - - /* [6.1.3] Now must be empty.*/ - test_set_step(3); - { - test_assert(chPoolAlloc(&mp1) == NULL, "list not empty"); - } - - /* [6.1.4] Adding the objects to the pool using chPoolFree().*/ - test_set_step(4); - { - for (i = 0; i < MEMORY_POOL_SIZE; i++) - chPoolFree(&mp1, &objects[i]); - } - - /* [6.1.5] Emptying the pool using chPoolAlloc() again.*/ - test_set_step(5); - { - for (i = 0; i < MEMORY_POOL_SIZE; i++) - test_assert(chPoolAlloc(&mp1) != NULL, "list empty"); - } - - /* [6.1.6] Now must be empty again.*/ - test_set_step(6); - { - test_assert(chPoolAlloc(&mp1) == NULL, "list not empty"); - } - - /* [6.1.7] Covering the case where a provider is unable to return - more memory.*/ - test_set_step(7); - { - chPoolObjectInit(&mp1, sizeof (uint32_t), null_provider); - test_assert(chPoolAlloc(&mp1) == NULL, "provider returned memory"); - } -} - -static const testcase_t test_006_001 = { - "Loading and emptying a memory pool", - test_006_001_setup, - NULL, - test_006_001_execute -}; - -#if (CH_CFG_USE_SEMAPHORES) || defined(__DOXYGEN__) -/** - * @page test_006_002 [6.2] Loading and emptying a guarded memory pool without waiting - * - *

Description

- * The memory pool functionality is tested by loading and emptying it, - * all conditions are tested. - * - *

Conditions

- * This test is only executed if the following preprocessor condition - * evaluates to true: - * - CH_CFG_USE_SEMAPHORES - * . - * - *

Test Steps

- * - [6.2.1] Adding the objects to the pool using - * chGuardedPoolLoadArray(). - * - [6.2.2] Emptying the pool using chGuardedPoolAllocTimeout(). - * - [6.2.3] Now must be empty. - * - [6.2.4] Adding the objects to the pool using chGuardedPoolFree(). - * - [6.2.5] Emptying the pool using chGuardedPoolAllocTimeout() again. - * - [6.2.6] Now must be empty again. - * . - */ - -static void test_006_002_setup(void) { - chGuardedPoolObjectInit(&gmp1, sizeof (uint32_t)); -} - -static void test_006_002_execute(void) { - unsigned i; - - /* [6.2.1] Adding the objects to the pool using - chGuardedPoolLoadArray().*/ - test_set_step(1); - { - chGuardedPoolLoadArray(&gmp1, objects, MEMORY_POOL_SIZE); - } - - /* [6.2.2] Emptying the pool using chGuardedPoolAllocTimeout().*/ - test_set_step(2); - { - for (i = 0; i < MEMORY_POOL_SIZE; i++) - test_assert(chGuardedPoolAllocTimeout(&gmp1, TIME_IMMEDIATE) != NULL, "list empty"); - } - - /* [6.2.3] Now must be empty.*/ - test_set_step(3); - { - test_assert(chGuardedPoolAllocTimeout(&gmp1, TIME_IMMEDIATE) == NULL, "list not empty"); - } - - /* [6.2.4] Adding the objects to the pool using - chGuardedPoolFree().*/ - test_set_step(4); - { - for (i = 0; i < MEMORY_POOL_SIZE; i++) - chGuardedPoolFree(&gmp1, &objects[i]); - } - - /* [6.2.5] Emptying the pool using chGuardedPoolAllocTimeout() - again.*/ - test_set_step(5); - { - for (i = 0; i < MEMORY_POOL_SIZE; i++) - test_assert(chGuardedPoolAllocTimeout(&gmp1, TIME_IMMEDIATE) != NULL, "list empty"); - } - - /* [6.2.6] Now must be empty again.*/ - test_set_step(6); - { - test_assert(chGuardedPoolAllocTimeout(&gmp1, TIME_IMMEDIATE) == NULL, "list not empty"); - } -} - -static const testcase_t test_006_002 = { - "Loading and emptying a guarded memory pool without waiting", - test_006_002_setup, - NULL, - test_006_002_execute -}; -#endif /* CH_CFG_USE_SEMAPHORES */ - -#if (CH_CFG_USE_SEMAPHORES) || defined(__DOXYGEN__) -/** - * @page test_006_003 [6.3] Guarded Memory Pools timeout - * - *

Description

- * The timeout features for the Guarded Memory Pools is tested. - * - *

Conditions

- * This test is only executed if the following preprocessor condition - * evaluates to true: - * - CH_CFG_USE_SEMAPHORES - * . - * - *

Test Steps

- * - [6.3.1] Trying to allocate with 100mS timeout, must fail because - * the pool is empty. - * . - */ - -static void test_006_003_setup(void) { - chGuardedPoolObjectInit(&gmp1, sizeof (uint32_t)); -} - -static void test_006_003_execute(void) { - - /* [6.3.1] Trying to allocate with 100mS timeout, must fail because - the pool is empty.*/ - test_set_step(1); - { - test_assert(chGuardedPoolAllocTimeout(&gmp1, MS2ST(100)) == NULL, "list not empty"); - } -} - -static const testcase_t test_006_003 = { - "Guarded Memory Pools timeout", - test_006_003_setup, - NULL, - test_006_003_execute -}; -#endif /* CH_CFG_USE_SEMAPHORES */ - -/**************************************************************************** - * Exported data. - ****************************************************************************/ - -/** - * @brief Memory Pools. - */ -const testcase_t * const test_sequence_006[] = { - &test_006_001, -#if (CH_CFG_USE_SEMAPHORES) || defined(__DOXYGEN__) - &test_006_002, -#endif -#if (CH_CFG_USE_SEMAPHORES) || defined(__DOXYGEN__) - &test_006_003, -#endif - NULL -}; - -#endif /* CH_CFG_USE_MEMPOOLS */ diff --git a/test/nil/source/test/test_sequence_006.h b/test/nil/source/test/test_sequence_006.h deleted file mode 100644 index 959689dc1..000000000 --- a/test/nil/source/test/test_sequence_006.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2017 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. -*/ - -/** - * @file test_sequence_006.h - * @brief Test Sequence 006 header. - */ - -#ifndef TEST_SEQUENCE_006_H -#define TEST_SEQUENCE_006_H - -extern const testcase_t * const test_sequence_006[]; - -#endif /* TEST_SEQUENCE_006_H */ diff --git a/test/nil/source/test/test_sequence_007.c b/test/nil/source/test/test_sequence_007.c deleted file mode 100644 index 4e5908ab0..000000000 --- a/test/nil/source/test/test_sequence_007.c +++ /dev/null @@ -1,273 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2017 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" - -/** - * @file test_sequence_007.c - * @brief Test Sequence 007 code. - * - * @page test_sequence_007 [7] Memory Heaps - * - * File: @ref test_sequence_007.c - * - *

Description

- * This sequence tests the ChibiOS/NIL functionalities related to - * memory heaps. - * - *

Conditions

- * This sequence is only executed if the following preprocessor condition - * evaluates to true: - * - CH_CFG_USE_HEAP - * . - * - *

Test Cases

- * - @subpage test_007_001 - * - @subpage test_007_002 - * . - */ - -#if (CH_CFG_USE_HEAP) || defined(__DOXYGEN__) - -/**************************************************************************** - * Shared code. - ****************************************************************************/ - -#define ALLOC_SIZE 16 -#define HEAP_SIZE (ALLOC_SIZE * 8) - -static memory_heap_t test_heap; -static CH_HEAP_AREA(myheap, HEAP_SIZE); - -/**************************************************************************** - * Test cases. - ****************************************************************************/ - -/** - * @page test_007_001 [7.1] Allocation and fragmentation - * - *

Description

- * Series of allocations/deallocations are performed in carefully - * designed sequences in order to stimulate all the possible code paths - * inside the allocator. The test expects to find the heap back to the - * initial status after each sequence. - * - *

Test Steps

- * - [7.1.1] Testing initial conditions, the heap must not be - * fragmented and one free block present. - * - [7.1.2] Trying to allocate an block bigger than available space, - * an error is expected. - * - [7.1.3] Single block allocation using chHeapAlloc() then the block - * is freed using chHeapFree(), must not fail. - * - [7.1.4] Using chHeapStatus() to assess the heap state. There must - * be at least one free block of sufficient size. - * - [7.1.5] Allocating then freeing in the same order. - * - [7.1.6] Allocating then freeing in reverse order. - * - [7.1.7] Small fragments handling. Checking the behavior when - * allocating blocks with size not multiple of alignment unit. - * - [7.1.8] Skipping a fragment, the first fragment in the list is too - * small so the allocator must pick the second one. - * - [7.1.9] Allocating the whole available space. - * - [7.1.10] Testing final conditions. The heap geometry must be the - * same than the one registered at beginning. - * . - */ - -static void test_007_001_setup(void) { - chHeapObjectInit(&test_heap, myheap, sizeof(myheap)); -} - -static void test_007_001_execute(void) { - void *p1, *p2, *p3; - size_t n, sz; - - /* [7.1.1] Testing initial conditions, the heap must not be - fragmented and one free block present.*/ - test_set_step(1); - { - test_assert(chHeapStatus(&test_heap, &sz, NULL) == 1, "heap fragmented"); - } - - /* [7.1.2] Trying to allocate an block bigger than available space, - an error is expected.*/ - test_set_step(2); - { - p1 = chHeapAlloc(&test_heap, HEAP_SIZE * 2); - test_assert(p1 == NULL, "allocation not failed"); - } - - /* [7.1.3] Single block allocation using chHeapAlloc() then the block - is freed using chHeapFree(), must not fail.*/ - test_set_step(3); - { - p1 = chHeapAlloc(&test_heap, ALLOC_SIZE); - test_assert(p1 != NULL, "allocation failed"); - chHeapFree(p1); - } - - /* [7.1.4] Using chHeapStatus() to assess the heap state. There must - be at least one free block of sufficient size.*/ - test_set_step(4); - { - size_t total_size, largest_size; - - n = chHeapStatus(&test_heap, &total_size, &largest_size); - test_assert(n == 1, "missing free block"); - test_assert(total_size >= ALLOC_SIZE, "unexpected heap state"); - test_assert(total_size == largest_size, "unexpected heap state"); - } - - /* [7.1.5] Allocating then freeing in the same order.*/ - test_set_step(5); - { - p1 = chHeapAlloc(&test_heap, ALLOC_SIZE); - p2 = chHeapAlloc(&test_heap, ALLOC_SIZE); - p3 = chHeapAlloc(&test_heap, ALLOC_SIZE); - chHeapFree(p1); /* Does not merge.*/ - chHeapFree(p2); /* Merges backward.*/ - chHeapFree(p3); /* Merges both sides.*/ - test_assert(chHeapStatus(&test_heap, &n, NULL) == 1, "heap fragmented"); - } - - /* [7.1.6] Allocating then freeing in reverse order.*/ - test_set_step(6); - { - p1 = chHeapAlloc(&test_heap, ALLOC_SIZE); - p2 = chHeapAlloc(&test_heap, ALLOC_SIZE); - p3 = chHeapAlloc(&test_heap, ALLOC_SIZE); - chHeapFree(p3); /* Merges forward.*/ - chHeapFree(p2); /* Merges forward.*/ - chHeapFree(p1); /* Merges forward.*/ - test_assert(chHeapStatus(&test_heap, &n, NULL) == 1, "heap fragmented"); - } - - /* [7.1.7] Small fragments handling. Checking the behavior when - allocating blocks with size not multiple of alignment unit.*/ - test_set_step(7); - { - p1 = chHeapAlloc(&test_heap, ALLOC_SIZE + 1); - p2 = chHeapAlloc(&test_heap, ALLOC_SIZE); - chHeapFree(p1); - test_assert(chHeapStatus(&test_heap, &n, NULL) == 2, "invalid state"); - p1 = chHeapAlloc(&test_heap, ALLOC_SIZE); - /* Note, the first situation happens when the alignment size is smaller - than the header size, the second in the other cases.*/ - test_assert((chHeapStatus(&test_heap, &n, NULL) == 1) || - (chHeapStatus(&test_heap, &n, NULL) == 2), "heap fragmented"); - chHeapFree(p2); - chHeapFree(p1); - test_assert(chHeapStatus(&test_heap, &n, NULL) == 1, "heap fragmented"); - } - - /* [7.1.8] Skipping a fragment, the first fragment in the list is too - small so the allocator must pick the second one.*/ - test_set_step(8); - { - p1 = chHeapAlloc(&test_heap, ALLOC_SIZE); - p2 = chHeapAlloc(&test_heap, ALLOC_SIZE); - chHeapFree(p1); - test_assert( chHeapStatus(&test_heap, &n, NULL) == 2, "invalid state"); - p1 = chHeapAlloc(&test_heap, ALLOC_SIZE * 2); /* Skips first fragment.*/ - chHeapFree(p1); - chHeapFree(p2); - test_assert(chHeapStatus(&test_heap, &n, NULL) == 1, "heap fragmented"); - } - - /* [7.1.9] Allocating the whole available space.*/ - test_set_step(9); - { - (void)chHeapStatus(&test_heap, &n, NULL); - p1 = chHeapAlloc(&test_heap, n); - test_assert(p1 != NULL, "allocation failed"); - test_assert(chHeapStatus(&test_heap, NULL, NULL) == 0, "not empty"); - chHeapFree(p1); - } - - /* [7.1.10] Testing final conditions. The heap geometry must be the - same than the one registered at beginning.*/ - test_set_step(10); - { - test_assert(chHeapStatus(&test_heap, &n, NULL) == 1, "heap fragmented"); - test_assert(n == sz, "size changed"); - } -} - -static const testcase_t test_007_001 = { - "Allocation and fragmentation", - test_007_001_setup, - NULL, - test_007_001_execute -}; - -/** - * @page test_007_002 [7.2] Default Heap - * - *

Description

- * The default heap is pre-allocated in the system. We test base - * functionality. - * - *

Test Steps

- * - [7.2.1] Single block allocation using chHeapAlloc() then the block - * is freed using chHeapFree(), must not fail. - * - [7.2.2] Testing allocation failure. - * . - */ - -static void test_007_002_execute(void) { - void *p1; - size_t total_size, largest_size; - - /* [7.2.1] Single block allocation using chHeapAlloc() then the block - is freed using chHeapFree(), must not fail.*/ - test_set_step(1); - { - (void)chHeapStatus(NULL, &total_size, &largest_size); - p1 = chHeapAlloc(&test_heap, ALLOC_SIZE); - test_assert(p1 != NULL, "allocation failed"); - chHeapFree(p1); - } - - /* [7.2.2] Testing allocation failure.*/ - test_set_step(2); - { - p1 = chHeapAlloc(NULL, (size_t)-256); - test_assert(p1 == NULL, "allocation not failed"); - } -} - -static const testcase_t test_007_002 = { - "Default Heap", - NULL, - NULL, - test_007_002_execute -}; - -/**************************************************************************** - * Exported data. - ****************************************************************************/ - -/** - * @brief Memory Heaps. - */ -const testcase_t * const test_sequence_007[] = { - &test_007_001, - &test_007_002, - NULL -}; - -#endif /* CH_CFG_USE_HEAP */ diff --git a/test/nil/source/test/test_sequence_007.h b/test/nil/source/test/test_sequence_007.h deleted file mode 100644 index b0b926223..000000000 --- a/test/nil/source/test/test_sequence_007.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2017 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. -*/ - -/** - * @file test_sequence_007.h - * @brief Test Sequence 007 header. - */ - -#ifndef TEST_SEQUENCE_007_H -#define TEST_SEQUENCE_007_H - -extern const testcase_t * const test_sequence_007[]; - -#endif /* TEST_SEQUENCE_007_H */ -- cgit v1.2.3