1 | /* tmacros.h |
---|
2 | * |
---|
3 | * This include file contains macros which are useful in the RTEMS |
---|
4 | * test suites. |
---|
5 | * |
---|
6 | * COPYRIGHT (c) 1989-2009. |
---|
7 | * On-Line Applications Research Corporation (OAR). |
---|
8 | * |
---|
9 | * The license and distribution terms for this file may be |
---|
10 | * found in the file LICENSE in this distribution or at |
---|
11 | * http://www.rtems.com/license/LICENSE. |
---|
12 | * |
---|
13 | * $Id$ |
---|
14 | */ |
---|
15 | |
---|
16 | #ifndef __TMACROS_h |
---|
17 | #define __TMACROS_h |
---|
18 | |
---|
19 | #include <inttypes.h> |
---|
20 | #include <bsp.h> /* includes <rtems.h> */ |
---|
21 | |
---|
22 | #include <ctype.h> |
---|
23 | #include <stdio.h> |
---|
24 | #include <stdlib.h> |
---|
25 | #include <string.h> |
---|
26 | #include <rtems/error.h> |
---|
27 | #include <rtems/score/thread.h> /* _Thread_Dispatch_disable_level */ |
---|
28 | |
---|
29 | #ifdef __cplusplus |
---|
30 | extern "C" { |
---|
31 | #endif |
---|
32 | |
---|
33 | |
---|
34 | #define FOREVER 1 /* infinite loop */ |
---|
35 | |
---|
36 | #ifdef CONFIGURE_INIT |
---|
37 | #define TEST_EXTERN |
---|
38 | #else |
---|
39 | #define TEST_EXTERN extern |
---|
40 | #endif |
---|
41 | |
---|
42 | #include <buffer_test_io.h> |
---|
43 | |
---|
44 | /* |
---|
45 | * Check that that the dispatch disable level is proper for the |
---|
46 | * mode/state of the test. Normally it should be 0 when in task space. |
---|
47 | */ |
---|
48 | |
---|
49 | #define check_dispatch_disable_level( _expect ) \ |
---|
50 | do { \ |
---|
51 | if ( (_expect) != -1 && _Thread_Dispatch_disable_level != (_expect) ) { \ |
---|
52 | printf( "\n_Thread_Dispatch_disable_level is (%" PRId32 ") not %d\n", \ |
---|
53 | _Thread_Dispatch_disable_level, (_expect) ); \ |
---|
54 | FLUSH_OUTPUT(); \ |
---|
55 | rtems_test_exit( 1 ); \ |
---|
56 | } \ |
---|
57 | } while ( 0 ) |
---|
58 | |
---|
59 | /* |
---|
60 | * These macros properly report errors within the Classic API |
---|
61 | */ |
---|
62 | |
---|
63 | #define directive_failed( _dirstat, _failmsg ) \ |
---|
64 | fatal_directive_status( _dirstat, RTEMS_SUCCESSFUL, _failmsg ) |
---|
65 | |
---|
66 | #define directive_failed_with_level( _dirstat, _failmsg, _level ) \ |
---|
67 | fatal_directive_status_with_level( \ |
---|
68 | _dirstat, RTEMS_SUCCESSFUL, _failmsg, _level ) |
---|
69 | |
---|
70 | #define fatal_directive_status( _stat, _desired, _msg ) \ |
---|
71 | fatal_directive_status_with_level( _stat, _desired, _msg, 0 ) |
---|
72 | |
---|
73 | #define fatal_directive_check_status_only( _stat, _desired, _msg ) \ |
---|
74 | do { \ |
---|
75 | if ( (_stat) != (_desired) ) { \ |
---|
76 | printf( "\n%s FAILED -- expected (%s) got (%s)\n", \ |
---|
77 | (_msg), rtems_status_text(_desired), rtems_status_text(_stat) ); \ |
---|
78 | FLUSH_OUTPUT(); \ |
---|
79 | rtems_test_exit( _stat ); \ |
---|
80 | } \ |
---|
81 | } while ( 0 ) |
---|
82 | |
---|
83 | #define fatal_directive_status_with_level( _stat, _desired, _msg, _level ) \ |
---|
84 | do { \ |
---|
85 | check_dispatch_disable_level( _level ); \ |
---|
86 | fatal_directive_check_status_only( _stat, _desired, _msg ); \ |
---|
87 | } while ( 0 ) |
---|
88 | |
---|
89 | /* |
---|
90 | * These macros properly report errors from the POSIX API |
---|
91 | */ |
---|
92 | |
---|
93 | #define posix_service_failed( _dirstat, _failmsg ) \ |
---|
94 | fatal_posix_service_status( _dirstat, 0, _failmsg ) |
---|
95 | |
---|
96 | #define posix_service_failed_with_level( _dirstat, _failmsg, _level ) \ |
---|
97 | fatal_posix_service_status_with_level( _dirstat, 0, _failmsg, _level ) |
---|
98 | |
---|
99 | #define fatal_posix_service_status_errno( _stat, _desired, _msg ) \ |
---|
100 | if ( (_stat != -1) && (errno) != (_desired) ) { \ |
---|
101 | long statx = _stat; \ |
---|
102 | check_dispatch_disable_level( 0 ); \ |
---|
103 | printf( "\n%s FAILED -- expected (%d - %s) got (%ld %d - %s)\n", \ |
---|
104 | (_msg), _desired, strerror(_desired), \ |
---|
105 | statx, errno, strerror(errno) ); \ |
---|
106 | FLUSH_OUTPUT(); \ |
---|
107 | rtems_test_exit( _stat ); \ |
---|
108 | } |
---|
109 | |
---|
110 | #define fatal_posix_service_status( _stat, _desired, _msg ) \ |
---|
111 | fatal_posix_service_status_with_level( _stat, _desired, _msg, 0 ) |
---|
112 | |
---|
113 | #define fatal_posix_service_pointer_minus_one( _ptr, _msg ) \ |
---|
114 | if ( (_ptr != (void *)-1) ) { \ |
---|
115 | check_dispatch_disable_level( 0 ); \ |
---|
116 | printf( "\n%s FAILED -- expected (-1) got (%p - %d/%s)\n", \ |
---|
117 | (_msg), _ptr, errno, strerror(errno) ); \ |
---|
118 | FLUSH_OUTPUT(); \ |
---|
119 | rtems_test_exit( -1 ); \ |
---|
120 | } |
---|
121 | |
---|
122 | #define fatal_posix_service_status_with_level( _stat, _desired, _msg, _level ) \ |
---|
123 | do { \ |
---|
124 | check_dispatch_disable_level( _level ); \ |
---|
125 | if ( (_stat) != (_desired) ) { \ |
---|
126 | printf( "\n%s FAILED -- expected (%d - %s) got (%d - %s)\n", \ |
---|
127 | (_msg), _desired, strerror(_desired), _stat, strerror(_stat) ); \ |
---|
128 | printf( "\n FAILED -- errno (%d - %s)\n", \ |
---|
129 | errno, strerror(errno) ); \ |
---|
130 | FLUSH_OUTPUT(); \ |
---|
131 | rtems_test_exit( _stat ); \ |
---|
132 | } \ |
---|
133 | } while ( 0 ) |
---|
134 | |
---|
135 | /* |
---|
136 | * Generic integer version of the error reporting |
---|
137 | */ |
---|
138 | |
---|
139 | #define int_service_failed( _dirstat, _failmsg ) \ |
---|
140 | fatal_int_service_status( _dirstat, RTEMS_SUCCESSFUL, _failmsg ) |
---|
141 | |
---|
142 | #define int_service_failed_with_level( _dirstat, _failmsg, _level ) \ |
---|
143 | fatal_int_service_status_with_level( \ |
---|
144 | _dirstat, RTEMS_SUCCESSFUL, _failmsg, _level ) |
---|
145 | |
---|
146 | #define fatal_int_service_status( _stat, _desired, _msg ) \ |
---|
147 | fatal_int_service_status_with_level( _stat, _desired, _msg, 0 ) |
---|
148 | |
---|
149 | #define fatal_int_service_status_with_level( _stat, _desired, _msg, _level ) \ |
---|
150 | do { \ |
---|
151 | check_dispatch_disable_level( _level ); \ |
---|
152 | if ( (_stat) != (_desired) ) { \ |
---|
153 | printf( "\n%s FAILED -- expected (%d) got (%d)\n", \ |
---|
154 | (_msg), (_desired), (_stat) ); \ |
---|
155 | FLUSH_OUTPUT(); \ |
---|
156 | rtems_test_exit( _stat ); \ |
---|
157 | } \ |
---|
158 | } while ( 0 ) |
---|
159 | |
---|
160 | |
---|
161 | /* |
---|
162 | * Print the time |
---|
163 | */ |
---|
164 | |
---|
165 | #define sprint_time(_str, _s1, _tb, _s2) \ |
---|
166 | do { \ |
---|
167 | sprintf( (_str), "%s%02d:%02d:%02d %02d/%02d/%04d%s", \ |
---|
168 | _s1, (_tb)->hour, (_tb)->minute, (_tb)->second, \ |
---|
169 | (_tb)->month, (_tb)->day, (_tb)->year, _s2 ); \ |
---|
170 | } while ( 0 ) |
---|
171 | |
---|
172 | #define print_time(_s1, _tb, _s2) \ |
---|
173 | do { \ |
---|
174 | printf( "%s%02" PRIu32 ":%02" PRIu32 ":%02" PRIu32 " %02" PRIu32 "/%02" PRIu32 "/%04" PRIu32 "%s", \ |
---|
175 | _s1, (_tb)->hour, (_tb)->minute, (_tb)->second, \ |
---|
176 | (_tb)->month, (_tb)->day, (_tb)->year, _s2 ); \ |
---|
177 | } while ( 0 ) |
---|
178 | |
---|
179 | #define put_dot( _c ) \ |
---|
180 | do { \ |
---|
181 | putchar( _c ); \ |
---|
182 | FLUSH_OUTPUT(); \ |
---|
183 | } while ( 0 ) |
---|
184 | |
---|
185 | #define new_line puts( "" ) |
---|
186 | |
---|
187 | #define puts_nocr printf |
---|
188 | |
---|
189 | #ifdef RTEMS_TEST_NO_PAUSE |
---|
190 | #define rtems_test_pause() \ |
---|
191 | do { \ |
---|
192 | printf( "<pause>\n" ); \ |
---|
193 | FLUSH_OUTPUT(); \ |
---|
194 | } while ( 0 ) |
---|
195 | |
---|
196 | #define rtems_test_pause_and_screen_number( _screen ) \ |
---|
197 | do { \ |
---|
198 | printf( "<pause - screen %d>\n", (_screen) ); \ |
---|
199 | FLUSH_OUTPUT(); \ |
---|
200 | } while ( 0 ) |
---|
201 | #else |
---|
202 | #define rtems_test_pause() \ |
---|
203 | do { \ |
---|
204 | char buffer[ 80 ]; \ |
---|
205 | printf( "<pause>" ); \ |
---|
206 | FLUSH_OUTPUT(); \ |
---|
207 | gets( buffer ); \ |
---|
208 | puts( "" ); \ |
---|
209 | } while ( 0 ) |
---|
210 | |
---|
211 | #define rtems_test_pause_and_screen_number( _screen ) \ |
---|
212 | do { \ |
---|
213 | char buffer[ 80 ]; \ |
---|
214 | printf( "<pause - screen %d>", (_screen) ); \ |
---|
215 | FLUSH_OUTPUT(); \ |
---|
216 | gets( buffer ); \ |
---|
217 | puts( "" ); \ |
---|
218 | } while ( 0 ) |
---|
219 | #endif |
---|
220 | |
---|
221 | #define put_name( name, crlf ) \ |
---|
222 | { int c0, c1, c2, c3; \ |
---|
223 | c0 = (name >> 24) & 0xff; \ |
---|
224 | c1 = (name >> 16) & 0xff; \ |
---|
225 | c2 = (name >> 8) & 0xff; \ |
---|
226 | c3 = name & 0xff; \ |
---|
227 | putchar( (isprint(c0)) ? c0 : '*' ); \ |
---|
228 | if ( c1 ) putchar( (isprint(c1)) ? c1 : '*' ); \ |
---|
229 | if ( c2 ) putchar( (isprint(c2)) ? c2 : '*' ); \ |
---|
230 | if ( c3 ) putchar( (isprint(c3)) ? c3 : '*' ); \ |
---|
231 | if ( crlf ) \ |
---|
232 | putchar( '\n' ); \ |
---|
233 | } |
---|
234 | |
---|
235 | #ifndef build_time |
---|
236 | #define build_time( TB, MON, DAY, YR, HR, MIN, SEC, TK ) \ |
---|
237 | { (TB)->year = YR; \ |
---|
238 | (TB)->month = MON; \ |
---|
239 | (TB)->day = DAY; \ |
---|
240 | (TB)->hour = HR; \ |
---|
241 | (TB)->minute = MIN; \ |
---|
242 | (TB)->second = SEC; \ |
---|
243 | (TB)->ticks = TK; } |
---|
244 | #endif |
---|
245 | |
---|
246 | #define task_number( tid ) \ |
---|
247 | ( rtems_object_id_get_index( tid ) - \ |
---|
248 | rtems_configuration_get_rtems_api_configuration()-> \ |
---|
249 | number_of_initialization_tasks ) |
---|
250 | |
---|
251 | #define rtems_test_assert(__exp) \ |
---|
252 | do { \ |
---|
253 | if (!(__exp)) { \ |
---|
254 | printf( "%s: %d %s\n", __FILE__, __LINE__, #__exp ); \ |
---|
255 | rtems_test_exit(0); \ |
---|
256 | } \ |
---|
257 | } while (0) |
---|
258 | |
---|
259 | /* |
---|
260 | * Various inttypes.h-stype macros to assist printing |
---|
261 | * certain system types on different targets. |
---|
262 | */ |
---|
263 | |
---|
264 | /* HACK: Presume time_t to be a "long" */ |
---|
265 | /* HACK: There is no portable way to print time_t's */ |
---|
266 | #define PRItime_t "ld" |
---|
267 | |
---|
268 | #if defined(RTEMS_USE_16_BIT_OBJECT) |
---|
269 | #define PRIxrtems_id PRIx16 |
---|
270 | #else |
---|
271 | #define PRIxrtems_id PRIx32 |
---|
272 | #endif |
---|
273 | |
---|
274 | /* c.f. cpukit/score/include/rtems/score/priority.h */ |
---|
275 | #define PRIdPriority_Control PRId32 |
---|
276 | #define PRIxPriority_Control PRIx32 |
---|
277 | /* rtems_task_priority is a typedef to Priority_Control */ |
---|
278 | #define PRIdrtems_task_priority PRIdPriority_Control |
---|
279 | #define PRIxrtems_task_priority PRIxPriority_Control |
---|
280 | |
---|
281 | /* c.f. cpukit/score/include/rtems/score/watchdog.h */ |
---|
282 | #define PRIdWatchdog_Interval PRIu32 |
---|
283 | /* rtems_interval is a typedef to Watchdog_Interval */ |
---|
284 | #define PRIdrtems_interval PRIdWatchdog_Interval |
---|
285 | |
---|
286 | /* c.f. cpukit/score/include/rtems/score/thread.h */ |
---|
287 | #define PRIdThread_Entry_numeric_type PRIuPTR |
---|
288 | /* rtems_task_argument is a typedef to Thread_Entry_numeric_type */ |
---|
289 | #define PRIdrtems_task_argument PRIdThread_Entry_numeric_type |
---|
290 | |
---|
291 | /* rtems_event_set is a typedef to unit32_t */ |
---|
292 | #define PRIxrtems_event_set PRIx32 |
---|
293 | |
---|
294 | /* HACK: newlib defines pthread_t as a typedef to __uint32_t */ |
---|
295 | /* HACK: There is no portable way to print pthread_t's */ |
---|
296 | #define PRIxpthread_t PRIx32 |
---|
297 | |
---|
298 | /* rtems_signal_set is a typedef to uint32_t */ |
---|
299 | #define PRIxrtems_signal_set PRIx32 |
---|
300 | |
---|
301 | /* newlib's ino_t is a typedef to "unsigned long" */ |
---|
302 | #define PRIxino_t "lx" |
---|
303 | |
---|
304 | /* newlib's off_t is a typedef to "long" */ |
---|
305 | #define PRIdoff_t "ld" |
---|
306 | |
---|
307 | /* IEEE Std 1003.1-2008 defines a type blksize_t, |
---|
308 | * newlib currently doesn't have this type, but uses "long" */ |
---|
309 | #define PRIxblksize_t "lx" |
---|
310 | |
---|
311 | /* IEEE Std 1003.1-2008 defines a type blkcnt_t, |
---|
312 | * newlib currently doesn't have this type, but uses "long" */ |
---|
313 | #define PRIxblkcnt_t "lx" |
---|
314 | |
---|
315 | #ifdef __cplusplus |
---|
316 | } |
---|
317 | #endif |
---|
318 | |
---|
319 | #endif |
---|