rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
test.h
Go to the documentation of this file.
1/*
2 ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17/**
18 * @file test.h
19 * @brief Tests support header.
20 *
21 * @addtogroup test
22 * @{
23 */
24
25#pragma once
26
27/**
28 * @brief Delay inserted between test cases.
29 */
30#if !defined(DELAY_BETWEEN_TESTS)
31#define DELAY_BETWEEN_TESTS 200
32#endif
33
34/**
35 * @brief If @p TRUE then benchmarks are not included.
36 */
37#if !defined(TEST_NO_BENCHMARKS)
38#define TEST_NO_BENCHMARKS FALSE
39#endif
40
41#define MAX_THREADS 5
42#define MAX_TOKENS 16
43
44#if defined(CH_ARCHITECTURE_AVR) || defined(CH_ARCHITECTURE_MSP430)
45#define THREADS_STACK_SIZE 48
46#elif defined(CH_ARCHITECTURE_STM8)
47#define THREADS_STACK_SIZE 64
48#elif defined(CH_ARCHITECTURE_SIMIA32)
49#define THREADS_STACK_SIZE 512
50#else
51#define THREADS_STACK_SIZE 128
52#endif
53#define WA_SIZE THD_WA_SIZE(THREADS_STACK_SIZE)
54
55/**
56 * @brief Structure representing a test case.
57 */
58struct testcase {
59 const char *name; /**< @brief Test case name. */
60 void (*setup)(void); /**< @brief Test case preparation function. */
61 void (*teardown)(void); /**< @brief Test case clean up function. */
62 void (*execute)(void); /**< @brief Test case execution function. */
63};
64
65#ifndef __DOXYGEN__
67 struct {
68 WORKING_AREA(T0, THREADS_STACK_SIZE);
69 WORKING_AREA(T1, THREADS_STACK_SIZE);
70 WORKING_AREA(T2, THREADS_STACK_SIZE);
71 WORKING_AREA(T3, THREADS_STACK_SIZE);
72 WORKING_AREA(T4, THREADS_STACK_SIZE);
73 } wa;
74 uint8_t buffer[WA_SIZE * 5];
75};
76#endif
77
78#ifdef __cplusplus
79extern "C" {
80#endif
81 msg_t TestThread(void *p);
82 void test_printn(uint32_t n);
83 void test_print(const char *msgp);
84 void test_println(const char *msgp);
85 void test_emit_token(char token);
86 bool _test_fail(unsigned point);
87 bool _test_assert(unsigned point, bool condition);
88 bool _test_assert_sequence(unsigned point, char *expected);
89 bool _test_assert_time_window(unsigned point, systime_t start, systime_t end);
90 void test_terminate_threads(void);
91 void test_wait_threads(void);
93 void test_start_timer(unsigned ms);
94#if CH_DBG_THREADS_PROFILING
95 void test_cpu_pulse(unsigned duration);
96#endif
97#if defined(WIN32)
98 void ChkIntSources(void);
99#endif
100#ifdef __cplusplus
101}
102#endif
103
104/**
105 * @brief Test failure enforcement.
106 */
107#define test_fail(point) { \
108 _test_fail(point); \
109 return; \
110}
111
112/**
113 * @brief Test assertion.
114 *
115 * @param[in] point numeric assertion identifier
116 * @param[in] condition a boolean expression that must be verified to be true
117 * @param[in] msg failure message
118 */
119#define test_assert(point, condition, msg) { \
120 if (_test_assert(point, condition)) \
121 return; \
122}
123
124/**
125 * @brief Test assertion with lock.
126 *
127 * @param[in] point numeric assertion identifier
128 * @param[in] condition a boolean expression that must be verified to be true
129 * @param[in] msg failure message
130 */
131#define test_assert_lock(point, condition, msg) { \
132 chSysLock(); \
133 if (_test_assert(point, condition)) { \
134 chSysUnlock(); \
135 return; \
136 } \
137 chSysUnlock(); \
138}
139
140/**
141 * @brief Test sequence assertion.
142 *
143 * @param[in] point numeric assertion identifier
144 * @param[in] expected string to be matched with the tokens buffer
145 */
146#define test_assert_sequence(point, expected) { \
147 if (_test_assert_sequence(point, expected)) \
148 return; \
149}
150
151/**
152 * @brief Test time window assertion.
153 *
154 * @param[in] point numeric assertion identifier
155 * @param[in] start initial time in the window (included)
156 * @param[in] end final time in the window (not included)
157 */
158#define test_assert_time_window(point, start, end) { \
159 if (_test_assert_time_window(point, start, end)) \
160 return; \
161}
162
163#if !defined(__DOXYGEN__)
164extern Thread *threads[MAX_THREADS];
165extern union test_buffers test;
166extern void * ROMCONST wa[];
167extern bool test_timer_done;
168#endif
169
170/** @} */
void ChkIntSources(void)
Thread * threads[MAX_THREADS]
Definition test.c:55
bool _test_fail(unsigned point)
Definition test.c:139
void test_wait_threads(void)
Waits for the completion of all the test-spawned threads.
Definition test.c:189
void *ROMCONST wa[]
Definition test.c:60
void test_printn(uint32_t n)
Prints a decimal unsigned number.
Definition test.c:73
msg_t TestThread(void *p)
Test execution thread function.
Definition test.c:296
bool _test_assert_sequence(unsigned point, char *expected)
Definition test.c:154
union test_buffers test
Definition test.c:50
void test_cpu_pulse(unsigned duration)
CPU pulse.
Definition test.c:206
void test_terminate_threads(void)
Sets a termination request in all the test-spawned threads.
Definition test.c:178
void test_emit_token(char token)
Emits a token into the tokens buffer.
Definition test.c:129
systime_t test_wait_tick(void)
Delays execution until next system time tick.
Definition test.c:227
void test_start_timer(unsigned ms)
Starts the test timer.
Definition test.c:254
bool _test_assert(unsigned point, bool condition)
Definition test.c:147
void test_print(const char *msgp)
Prints a line without final end-of-line.
Definition test.c:92
bool test_timer_done
Set to TRUE when the test timer reaches its deadline.
Definition test.c:240
bool _test_assert_time_window(unsigned point, systime_t start, systime_t end)
Definition test.c:166
void test_println(const char *msgp)
Prints a line.
Definition test.c:103
Structure representing a test case.
Definition test.h:58
void(* execute)(void)
Test case execution function.
Definition test.h:62
const char * name
Test case name.
Definition test.h:59
void(* setup)(void)
Test case preparation function.
Definition test.h:60
void(* teardown)(void)
Test case clean up function.
Definition test.h:61
struct test_buffers::@28 wa
uint8_t buffer[WA_SIZE *5]
Definition test.h:74