1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * This include file contains macros which are useful in the RTEMS |
---|
5 | * test suites. |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2014. |
---|
10 | * On-Line Applications Research Corporation (OAR). |
---|
11 | * |
---|
12 | * The license and distribution terms for this file may be |
---|
13 | * found in the file LICENSE in this distribution or at |
---|
14 | * http://www.rtems.org/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #ifndef __TMACROS_h |
---|
18 | #define __TMACROS_h |
---|
19 | |
---|
20 | #include <inttypes.h> |
---|
21 | #include <rtems/inttypes.h> |
---|
22 | #include <bsp.h> /* includes <rtems.h> */ |
---|
23 | |
---|
24 | #include <ctype.h> |
---|
25 | #include <stdio.h> |
---|
26 | #include <stdlib.h> |
---|
27 | #include <string.h> |
---|
28 | #include <rtems/error.h> |
---|
29 | #include <rtems/test.h> |
---|
30 | #include <rtems/score/threaddispatch.h> |
---|
31 | |
---|
32 | #include <buffer_test_io.h> |
---|
33 | |
---|
34 | #ifdef __cplusplus |
---|
35 | extern "C" { |
---|
36 | #endif |
---|
37 | |
---|
38 | #define FOREVER 1 /* infinite loop */ |
---|
39 | |
---|
40 | #ifdef CONFIGURE_INIT |
---|
41 | #define TEST_EXTERN |
---|
42 | #else |
---|
43 | #define TEST_EXTERN extern |
---|
44 | #endif |
---|
45 | |
---|
46 | /* |
---|
47 | * Check that that the dispatch disable level is proper for the |
---|
48 | * mode/state of the test. Normally it should be 0 when in task space. |
---|
49 | * |
---|
50 | * This test is only valid when in a non-SMP system. In an smp system |
---|
51 | * another cpu may be accessing the core at any point when this core |
---|
52 | * does not have it locked. |
---|
53 | */ |
---|
54 | #if defined SMPTEST |
---|
55 | #define check_dispatch_disable_level( _expect ) |
---|
56 | #else |
---|
57 | #define check_dispatch_disable_level( _expect ) \ |
---|
58 | do { \ |
---|
59 | if ( (_expect) != -1 \ |
---|
60 | && (((!_Thread_Dispatch_is_enabled()) == false && (_expect) != 0) \ |
---|
61 | || ((!_Thread_Dispatch_is_enabled()) && (_expect) == 0)) \ |
---|
62 | ) { \ |
---|
63 | printf( \ |
---|
64 | "\n_Thread_Dispatch_disable_level is (%i)" \ |
---|
65 | " not %d detected at %s:%d\n", \ |
---|
66 | !_Thread_Dispatch_is_enabled(), (_expect), __FILE__, __LINE__ ); \ |
---|
67 | rtems_test_exit( 1 ); \ |
---|
68 | } \ |
---|
69 | } while ( 0 ) |
---|
70 | #endif |
---|
71 | |
---|
72 | /* |
---|
73 | * Check that that the allocator mutex is not owned by the executing thread. |
---|
74 | */ |
---|
75 | #include <rtems/score/apimutex.h> |
---|
76 | #define check_if_allocator_mutex_is_not_owned() \ |
---|
77 | do { \ |
---|
78 | if ( _RTEMS_Allocator_is_owner() ) { \ |
---|
79 | printf( \ |
---|
80 | "\nRTEMS Allocator Mutex is owned by executing thread " \ |
---|
81 | "and should not be.\n" \ |
---|
82 | "Detected at %s:%d\n", \ |
---|
83 | __FILE__, \ |
---|
84 | __LINE__ \ |
---|
85 | ); \ |
---|
86 | rtems_test_exit( 1 ); \ |
---|
87 | } \ |
---|
88 | } while ( 0 ) |
---|
89 | |
---|
90 | /* |
---|
91 | * These macros properly report errors within the Classic API |
---|
92 | */ |
---|
93 | #define directive_failed( _dirstat, _failmsg ) \ |
---|
94 | fatal_directive_status( _dirstat, RTEMS_SUCCESSFUL, _failmsg ) |
---|
95 | |
---|
96 | #define directive_failed_with_level( _dirstat, _failmsg, _level ) \ |
---|
97 | fatal_directive_status_with_level( \ |
---|
98 | _dirstat, RTEMS_SUCCESSFUL, _failmsg, _level ) |
---|
99 | |
---|
100 | #define fatal_directive_status( _stat, _desired, _msg ) \ |
---|
101 | fatal_directive_status_with_level( _stat, _desired, _msg, 0 ) |
---|
102 | |
---|
103 | #define fatal_directive_check_status_only( _stat, _desired, _msg ) \ |
---|
104 | do { \ |
---|
105 | if ( (_stat) != (_desired) ) { \ |
---|
106 | printf( "\n%s FAILED -- expected (%s) got (%s)\n", \ |
---|
107 | (_msg), rtems_status_text(_desired), rtems_status_text(_stat) ); \ |
---|
108 | rtems_test_exit( _stat ); \ |
---|
109 | } \ |
---|
110 | } while ( 0 ) |
---|
111 | |
---|
112 | #define fatal_directive_status_with_level( _stat, _desired, _msg, _level ) \ |
---|
113 | do { \ |
---|
114 | check_dispatch_disable_level( _level ); \ |
---|
115 | check_if_allocator_mutex_is_not_owned(); \ |
---|
116 | fatal_directive_check_status_only( _stat, _desired, _msg ); \ |
---|
117 | } while ( 0 ) |
---|
118 | |
---|
119 | /* |
---|
120 | * These macros properly report errors from the POSIX API |
---|
121 | */ |
---|
122 | |
---|
123 | #define posix_service_failed( _dirstat, _failmsg ) \ |
---|
124 | fatal_posix_service_status( _dirstat, 0, _failmsg ) |
---|
125 | |
---|
126 | #define posix_service_failed_with_level( _dirstat, _failmsg, _level ) \ |
---|
127 | fatal_posix_service_status_with_level( _dirstat, 0, _failmsg, _level ) |
---|
128 | |
---|
129 | #define fatal_posix_service_status_errno( _stat, _desired, _msg ) \ |
---|
130 | if ( (_stat != -1) && (errno) != (_desired) ) { \ |
---|
131 | long statx = _stat; \ |
---|
132 | check_dispatch_disable_level( 0 ); \ |
---|
133 | check_if_allocator_mutex_is_not_owned(); \ |
---|
134 | printf( "\n%s FAILED -- expected (%d - %s) got (%ld %d - %s)\n", \ |
---|
135 | (_msg), _desired, strerror(_desired), \ |
---|
136 | statx, errno, strerror(errno) ); \ |
---|
137 | rtems_test_exit( _stat ); \ |
---|
138 | } |
---|
139 | |
---|
140 | #define fatal_posix_service_status( _stat, _desired, _msg ) \ |
---|
141 | fatal_posix_service_status_with_level( _stat, _desired, _msg, 0 ) |
---|
142 | |
---|
143 | #define fatal_posix_service_status_with_level( _stat, _desired, _msg, _level ) \ |
---|
144 | do { \ |
---|
145 | check_dispatch_disable_level( _level ); \ |
---|
146 | check_if_allocator_mutex_is_not_owned(); \ |
---|
147 | if ( (_stat) != (_desired) ) { \ |
---|
148 | printf( "\n%s FAILED -- expected (%d - %s) got (%d - %s)\n", \ |
---|
149 | (_msg), _desired, strerror(_desired), _stat, strerror(_stat) ); \ |
---|
150 | printf( "\n FAILED -- errno (%d - %s)\n", \ |
---|
151 | errno, strerror(errno) ); \ |
---|
152 | rtems_test_exit( _stat ); \ |
---|
153 | } \ |
---|
154 | } while ( 0 ) |
---|
155 | |
---|
156 | /* |
---|
157 | * This macro evaluates the semaphore id returned. |
---|
158 | */ |
---|
159 | #define fatal_posix_sem( _ptr, _msg ) \ |
---|
160 | if ( (_ptr != SEM_FAILED) ) { \ |
---|
161 | check_dispatch_disable_level( 0 ); \ |
---|
162 | printf( "\n%s FAILED -- expected (-1) got (%p - %d/%s)\n", \ |
---|
163 | (_msg), _ptr, errno, strerror(errno) ); \ |
---|
164 | rtems_test_exit( -1 ); \ |
---|
165 | } |
---|
166 | |
---|
167 | /* |
---|
168 | * This macro evaluates the message queue id returned. |
---|
169 | */ |
---|
170 | #define fatal_posix_mqd( _ptr, _msg ) \ |
---|
171 | if ( (_ptr != (mqd_t) -1) ) { \ |
---|
172 | check_dispatch_disable_level( 0 ); \ |
---|
173 | printf( "\n%s FAILED -- expected (-1) got (%" PRId32 " - %d/%s)\n", \ |
---|
174 | (_msg), _ptr, errno, strerror(errno) ); \ |
---|
175 | rtems_test_exit( -1 ); \ |
---|
176 | } |
---|
177 | |
---|
178 | /* |
---|
179 | * Generic integer version of the error reporting |
---|
180 | */ |
---|
181 | |
---|
182 | #define int_service_failed( _dirstat, _failmsg ) \ |
---|
183 | fatal_int_service_status( _dirstat, RTEMS_SUCCESSFUL, _failmsg ) |
---|
184 | |
---|
185 | #define int_service_failed_with_level( _dirstat, _failmsg, _level ) \ |
---|
186 | fatal_int_service_status_with_level( \ |
---|
187 | _dirstat, RTEMS_SUCCESSFUL, _failmsg, _level ) |
---|
188 | |
---|
189 | #define fatal_int_service_status( _stat, _desired, _msg ) \ |
---|
190 | fatal_int_service_status_with_level( _stat, _desired, _msg, 0 ) |
---|
191 | |
---|
192 | #define fatal_int_service_status_with_level( _stat, _desired, _msg, _level ) \ |
---|
193 | do { \ |
---|
194 | check_dispatch_disable_level( _level ); \ |
---|
195 | if ( (_stat) != (_desired) ) { \ |
---|
196 | printf( "\n%s FAILED -- expected (%d) got (%d)\n", \ |
---|
197 | (_msg), (_desired), (_stat) ); \ |
---|
198 | rtems_test_exit( _stat ); \ |
---|
199 | } \ |
---|
200 | } while ( 0 ) |
---|
201 | |
---|
202 | |
---|
203 | /* |
---|
204 | * Print the time |
---|
205 | */ |
---|
206 | |
---|
207 | #define sprint_time(_str, _s1, _tb, _s2) \ |
---|
208 | do { \ |
---|
209 | sprintf( (_str), "%s%02d:%02d:%02d %02d/%02d/%04d%s", \ |
---|
210 | _s1, (_tb)->hour, (_tb)->minute, (_tb)->second, \ |
---|
211 | (_tb)->month, (_tb)->day, (_tb)->year, _s2 ); \ |
---|
212 | } while ( 0 ) |
---|
213 | |
---|
214 | #define print_time(_s1, _tb, _s2) \ |
---|
215 | do { \ |
---|
216 | printf( "%s%02" PRIu32 ":%02" PRIu32 ":%02" PRIu32 " %02" PRIu32 "/%02" PRIu32 "/%04" PRIu32 "%s", \ |
---|
217 | _s1, (_tb)->hour, (_tb)->minute, (_tb)->second, \ |
---|
218 | (_tb)->month, (_tb)->day, (_tb)->year, _s2 ); \ |
---|
219 | } while ( 0 ) |
---|
220 | |
---|
221 | #define put_dot( _c ) \ |
---|
222 | do { \ |
---|
223 | putchar( _c ); \ |
---|
224 | } while ( 0 ) |
---|
225 | |
---|
226 | #define new_line puts( "" ) |
---|
227 | |
---|
228 | #define puts_nocr printf |
---|
229 | |
---|
230 | #ifdef RTEMS_TEST_NO_PAUSE |
---|
231 | #define rtems_test_pause() \ |
---|
232 | do { \ |
---|
233 | printf( "<pause>\n" ); \ |
---|
234 | } while ( 0 ) |
---|
235 | |
---|
236 | #define rtems_test_pause_and_screen_number( _screen ) \ |
---|
237 | do { \ |
---|
238 | printf( "<pause - screen %d>\n", (_screen) ); \ |
---|
239 | } while ( 0 ) |
---|
240 | #else |
---|
241 | #define rtems_test_pause() \ |
---|
242 | do { \ |
---|
243 | char buffer[ 80 ]; \ |
---|
244 | printf( "<pause>" ); \ |
---|
245 | gets( buffer ); \ |
---|
246 | puts( "" ); \ |
---|
247 | } while ( 0 ) |
---|
248 | |
---|
249 | #define rtems_test_pause_and_screen_number( _screen ) \ |
---|
250 | do { \ |
---|
251 | char buffer[ 80 ]; \ |
---|
252 | printf( "<pause - screen %d>", (_screen) ); \ |
---|
253 | gets( buffer ); \ |
---|
254 | puts( "" ); \ |
---|
255 | } while ( 0 ) |
---|
256 | #endif |
---|
257 | |
---|
258 | #define put_name( name, crlf ) \ |
---|
259 | { int c0, c1, c2, c3; \ |
---|
260 | c0 = (name >> 24) & 0xff; \ |
---|
261 | c1 = (name >> 16) & 0xff; \ |
---|
262 | c2 = (name >> 8) & 0xff; \ |
---|
263 | c3 = name & 0xff; \ |
---|
264 | putchar( (isprint(c0)) ? c0 : '*' ); \ |
---|
265 | if ( c1 ) putchar( (isprint(c1)) ? c1 : '*' ); \ |
---|
266 | if ( c2 ) putchar( (isprint(c2)) ? c2 : '*' ); \ |
---|
267 | if ( c3 ) putchar( (isprint(c3)) ? c3 : '*' ); \ |
---|
268 | if ( crlf ) \ |
---|
269 | putchar( '\n' ); \ |
---|
270 | } |
---|
271 | |
---|
272 | #ifndef build_time |
---|
273 | #define build_time( TB, MON, DAY, YR, HR, MIN, SEC, TK ) \ |
---|
274 | { (TB)->year = YR; \ |
---|
275 | (TB)->month = MON; \ |
---|
276 | (TB)->day = DAY; \ |
---|
277 | (TB)->hour = HR; \ |
---|
278 | (TB)->minute = MIN; \ |
---|
279 | (TB)->second = SEC; \ |
---|
280 | (TB)->ticks = TK; } |
---|
281 | #endif |
---|
282 | |
---|
283 | #define task_number( tid ) \ |
---|
284 | ( rtems_object_id_get_index( tid ) - \ |
---|
285 | rtems_configuration_get_rtems_api_configuration()-> \ |
---|
286 | number_of_initialization_tasks ) |
---|
287 | |
---|
288 | #define rtems_test_assert(__exp) \ |
---|
289 | do { \ |
---|
290 | if (!(__exp)) { \ |
---|
291 | printf( "%s: %d %s\n", __FILE__, __LINE__, #__exp ); \ |
---|
292 | rtems_test_exit(0); \ |
---|
293 | } \ |
---|
294 | } while (0) |
---|
295 | |
---|
296 | /** |
---|
297 | * This assists in clearly disabling warnings on GCC in certain very |
---|
298 | * specific cases. |
---|
299 | * |
---|
300 | * + -Wnon-null - If a method is declared as never having a NULL first |
---|
301 | * parameter. We need to explicitly disable this compiler warning to make |
---|
302 | * the code warning free. |
---|
303 | */ |
---|
304 | #ifdef __GNUC__ |
---|
305 | #define COMPILER_DIAGNOSTIC_SETTINGS_PUSH _Pragma("GCC diagnostic push") |
---|
306 | #define COMPILER_DIAGNOSTIC_SETTINGS_POP _Pragma("GCC diagnostic pop") |
---|
307 | #define COMPILER_DIAGNOSTIC_SETTINGS_DISABLE_NONNULL \ |
---|
308 | _Pragma("GCC diagnostic ignored \"-Wnonnull\"") |
---|
309 | #else |
---|
310 | #define COMPILER_DIAGNOSTIC_SETTINGS_PUSH |
---|
311 | #define COMPILER_DIAGNOSTIC_SETTINGS_POP |
---|
312 | #define COMPILER_DIAGNOSTIC_SETTINGS_DISABLE_NONNULL |
---|
313 | #endif |
---|
314 | |
---|
315 | #ifdef __cplusplus |
---|
316 | } |
---|
317 | #endif |
---|
318 | |
---|
319 | #endif |
---|