ChibiOS/RT Architecture - Reference Manual - Guides |
00001 /* 00002 ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. 00003 00004 This file is part of ChibiOS/RT. 00005 00006 ChibiOS/RT is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 3 of the License, or 00009 (at your option) any later version. 00010 00011 ChibiOS/RT is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program. If not, see <http://www.gnu.org/licenses/>. 00018 00019 --- 00020 00021 A special exception to the GPL can be applied should you wish to distribute 00022 a combined work that includes ChibiOS/RT, without being obliged to provide 00023 the source code for any proprietary components. See the file exception.txt 00024 for full details of how and when the exception can be applied. 00025 */ 00026 00027 /** 00028 * @file test.h 00029 * @brief Tests support header. 00030 * 00031 * @addtogroup test 00032 * @{ 00033 */ 00034 00035 #ifndef _TEST_H_ 00036 #define _TEST_H_ 00037 00038 /** 00039 * @brief Delay inserted between test cases. 00040 */ 00041 #if !defined(DELAY_BETWEEN_TESTS) || defined(__DOXYGEN__) 00042 #define DELAY_BETWEEN_TESTS 200 00043 #endif 00044 00045 /** 00046 * @brief If @p TRUE then benchmarks are not included. 00047 */ 00048 #if !defined(TEST_NO_BENCHMARKS) || defined(__DOXYGEN__) 00049 #define TEST_NO_BENCHMARKS FALSE 00050 #endif 00051 00052 #define MAX_THREADS 5 00053 #define MAX_TOKENS 16 00054 00055 #if defined(CH_ARCHITECTURE_AVR) || \ 00056 defined(CH_ARCHITECTURE_MSP430) || \ 00057 defined(CH_ARCHITECTURE_STM8) 00058 #define THREADS_STACK_SIZE 48 00059 #elif defined(CH_ARCHITECTURE_SIMIA32) 00060 #define THREADS_STACK_SIZE 512 00061 #else 00062 #define THREADS_STACK_SIZE 128 00063 #endif 00064 #define WA_SIZE THD_WA_SIZE(THREADS_STACK_SIZE) 00065 00066 /** 00067 * @brief Structure representing a test case. 00068 */ 00069 struct testcase { 00070 char *(*gettest)(void); /**< @brief Test case name get function. */ 00071 void (*setup)(void); /**< @brief Test case preparation function. */ 00072 void (*teardown)(void); /**< @brief Test case clean up function. */ 00073 void (*execute)(void); /**< @brief Test case execution function. */ 00074 }; 00075 00076 #ifndef __DOXYGEN__ 00077 union test_buffers { 00078 struct { 00079 WORKING_AREA(T0, THREADS_STACK_SIZE); 00080 WORKING_AREA(T1, THREADS_STACK_SIZE); 00081 WORKING_AREA(T2, THREADS_STACK_SIZE); 00082 WORKING_AREA(T3, THREADS_STACK_SIZE); 00083 WORKING_AREA(T4, THREADS_STACK_SIZE); 00084 } wa; 00085 uint8_t buffer[WA_SIZE * 5]; 00086 }; 00087 #endif 00088 00089 #ifdef __cplusplus 00090 extern "C" { 00091 #endif 00092 msg_t TestThread(void *p); 00093 void test_printn(uint32_t n); 00094 void test_print(char *msgp); 00095 void test_println(char *msgp); 00096 void test_emit_token(char token); 00097 bool_t _test_fail(unsigned point); 00098 bool_t _test_assert(unsigned point, bool_t condition); 00099 bool_t _test_assert_sequence(unsigned point, char *expected); 00100 bool_t _test_assert_time_window(unsigned point, systime_t start, systime_t end); 00101 void test_terminate_threads(void); 00102 void test_wait_threads(void); 00103 systime_t test_wait_tick(void); 00104 void test_start_timer(unsigned ms); 00105 #if CH_DBG_THREADS_PROFILING 00106 void test_cpu_pulse(unsigned duration); 00107 #endif 00108 #if defined(WIN32) 00109 void ChkIntSources(void); 00110 #endif 00111 #ifdef __cplusplus 00112 } 00113 #endif 00114 00115 /** 00116 * @brief Test failure enforcement. 00117 */ 00118 #define test_fail(point) { \ 00119 _test_fail(point); \ 00120 return; \ 00121 } 00122 00123 /** 00124 * @brief Test assertion. 00125 * 00126 * @param[in] point numeric assertion identifier 00127 * @param[in] condition a boolean expression that must be verified to be true 00128 * @param[in] msg failure message 00129 */ 00130 #define test_assert(point, condition, msg) { \ 00131 if (_test_assert(point, condition)) \ 00132 return; \ 00133 } 00134 00135 /** 00136 * @brief Test sequence assertion. 00137 * 00138 * @param[in] point numeric assertion identifier 00139 * @param[in] expected string to be matched with the tokens buffer 00140 */ 00141 #define test_assert_sequence(point, expected) { \ 00142 if (_test_assert_sequence(point, expected)) \ 00143 return; \ 00144 } 00145 00146 /** 00147 * @brief Test time window assertion. 00148 * 00149 * @param[in] point numeric assertion identifier 00150 * @param[in] start initial time in the window (included) 00151 * @param[in] end final time in the window (not included) 00152 */ 00153 #define test_assert_time_window(point, start, end) { \ 00154 if (_test_assert_time_window(point, start, end)) \ 00155 return; \ 00156 } 00157 00158 #if !defined(__DOXYGEN__) 00159 extern Thread *threads[MAX_THREADS]; 00160 extern union test_buffers test; 00161 extern void * const wa[]; 00162 extern bool_t test_timer_done; 00163 #endif 00164 00165 #endif /* _TEST_H_ */ 00166 00167 /** @} */