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-info.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 | #define check_dispatch_disable_level( _expect ) \ |
---|
51 | do { \ |
---|
52 | if ( (_expect) != -1 \ |
---|
53 | && (((!_Thread_Dispatch_is_enabled()) == false && (_expect) != 0) \ |
---|
54 | || ((!_Thread_Dispatch_is_enabled()) && (_expect) == 0)) \ |
---|
55 | ) { \ |
---|
56 | printf( \ |
---|
57 | "\n_Thread_Dispatch_disable_level is (%i)" \ |
---|
58 | " not %d detected at %s:%d\n", \ |
---|
59 | !_Thread_Dispatch_is_enabled(), (_expect), __FILE__, __LINE__ ); \ |
---|
60 | rtems_test_exit( 1 ); \ |
---|
61 | } \ |
---|
62 | } while ( 0 ) |
---|
63 | |
---|
64 | /* |
---|
65 | * Check that that the allocator mutex is not owned by the executing thread. |
---|
66 | */ |
---|
67 | #include <rtems/score/apimutex.h> |
---|
68 | #define check_if_allocator_mutex_is_not_owned() \ |
---|
69 | do { \ |
---|
70 | if ( _RTEMS_Allocator_is_owner() ) { \ |
---|
71 | printf( \ |
---|
72 | "\nRTEMS Allocator Mutex is owned by executing thread " \ |
---|
73 | "and should not be.\n" \ |
---|
74 | "Detected at %s:%d\n", \ |
---|
75 | __FILE__, \ |
---|
76 | __LINE__ \ |
---|
77 | ); \ |
---|
78 | rtems_test_exit( 1 ); \ |
---|
79 | } \ |
---|
80 | } while ( 0 ) |
---|
81 | |
---|
82 | /* |
---|
83 | * These macros properly report errors within the Classic API |
---|
84 | */ |
---|
85 | #define directive_failed( _dirstat, _failmsg ) \ |
---|
86 | fatal_directive_status( _dirstat, RTEMS_SUCCESSFUL, _failmsg ) |
---|
87 | |
---|
88 | #define directive_failed_with_level( _dirstat, _failmsg, _level ) \ |
---|
89 | fatal_directive_status_with_level( \ |
---|
90 | _dirstat, RTEMS_SUCCESSFUL, _failmsg, _level ) |
---|
91 | |
---|
92 | #define fatal_directive_status( _stat, _desired, _msg ) \ |
---|
93 | fatal_directive_status_with_level( _stat, _desired, _msg, 0 ) |
---|
94 | |
---|
95 | #define fatal_directive_check_status_only( _stat, _desired, _msg ) \ |
---|
96 | do { \ |
---|
97 | if ( (_stat) != (_desired) ) { \ |
---|
98 | printf( "\n%s FAILED -- expected (%s) got (%s)\n", \ |
---|
99 | (_msg), rtems_status_text(_desired), rtems_status_text(_stat) ); \ |
---|
100 | rtems_test_exit( _stat ); \ |
---|
101 | } \ |
---|
102 | } while ( 0 ) |
---|
103 | |
---|
104 | #define fatal_directive_status_with_level( _stat, _desired, _msg, _level ) \ |
---|
105 | do { \ |
---|
106 | check_dispatch_disable_level( _level ); \ |
---|
107 | check_if_allocator_mutex_is_not_owned(); \ |
---|
108 | fatal_directive_check_status_only( _stat, _desired, _msg ); \ |
---|
109 | } while ( 0 ) |
---|
110 | |
---|
111 | /* |
---|
112 | * These macros properly report errors from the POSIX API |
---|
113 | */ |
---|
114 | |
---|
115 | #define posix_service_failed( _dirstat, _failmsg ) \ |
---|
116 | fatal_posix_service_status( _dirstat, 0, _failmsg ) |
---|
117 | |
---|
118 | #define posix_service_failed_with_level( _dirstat, _failmsg, _level ) \ |
---|
119 | fatal_posix_service_status_with_level( _dirstat, 0, _failmsg, _level ) |
---|
120 | |
---|
121 | #define fatal_posix_service_status_errno( _stat, _desired, _msg ) \ |
---|
122 | if ( (_stat != -1) && (errno) != (_desired) ) { \ |
---|
123 | long statx = _stat; \ |
---|
124 | check_dispatch_disable_level( 0 ); \ |
---|
125 | check_if_allocator_mutex_is_not_owned(); \ |
---|
126 | printf( "\n%s FAILED -- expected (%d - %s) got (%ld %d - %s)\n", \ |
---|
127 | (_msg), _desired, strerror(_desired), \ |
---|
128 | statx, errno, strerror(errno) ); \ |
---|
129 | rtems_test_exit( _stat ); \ |
---|
130 | } |
---|
131 | |
---|
132 | #define fatal_posix_service_status( _stat, _desired, _msg ) \ |
---|
133 | fatal_posix_service_status_with_level( _stat, _desired, _msg, 0 ) |
---|
134 | |
---|
135 | #define fatal_posix_service_status_with_level( _stat, _desired, _msg, _level ) \ |
---|
136 | do { \ |
---|
137 | check_dispatch_disable_level( _level ); \ |
---|
138 | check_if_allocator_mutex_is_not_owned(); \ |
---|
139 | if ( (_stat) != (_desired) ) { \ |
---|
140 | printf( "\n%s FAILED -- expected (%d - %s) got (%d - %s)\n", \ |
---|
141 | (_msg), _desired, strerror(_desired), _stat, strerror(_stat) ); \ |
---|
142 | printf( "\n FAILED -- errno (%d - %s)\n", \ |
---|
143 | errno, strerror(errno) ); \ |
---|
144 | rtems_test_exit( _stat ); \ |
---|
145 | } \ |
---|
146 | } while ( 0 ) |
---|
147 | |
---|
148 | /* |
---|
149 | * This macro evaluates the semaphore id returned. |
---|
150 | */ |
---|
151 | #define fatal_posix_sem( _ptr, _msg ) \ |
---|
152 | if ( (_ptr != SEM_FAILED) ) { \ |
---|
153 | check_dispatch_disable_level( 0 ); \ |
---|
154 | printf( "\n%s FAILED -- expected (-1) got (%p - %d/%s)\n", \ |
---|
155 | (_msg), _ptr, errno, strerror(errno) ); \ |
---|
156 | rtems_test_exit( -1 ); \ |
---|
157 | } |
---|
158 | |
---|
159 | /* |
---|
160 | * This macro evaluates the message queue id returned. |
---|
161 | */ |
---|
162 | #define fatal_posix_mqd( _ptr, _msg ) \ |
---|
163 | if ( (_ptr != (mqd_t) -1) ) { \ |
---|
164 | check_dispatch_disable_level( 0 ); \ |
---|
165 | printf( "\n%s FAILED -- expected (-1) got (%" PRId32 " - %d/%s)\n", \ |
---|
166 | (_msg), _ptr, errno, strerror(errno) ); \ |
---|
167 | rtems_test_exit( -1 ); \ |
---|
168 | } |
---|
169 | |
---|
170 | /* |
---|
171 | * Generic integer version of the error reporting |
---|
172 | */ |
---|
173 | |
---|
174 | #define int_service_failed( _dirstat, _failmsg ) \ |
---|
175 | fatal_int_service_status( _dirstat, RTEMS_SUCCESSFUL, _failmsg ) |
---|
176 | |
---|
177 | #define int_service_failed_with_level( _dirstat, _failmsg, _level ) \ |
---|
178 | fatal_int_service_status_with_level( \ |
---|
179 | _dirstat, RTEMS_SUCCESSFUL, _failmsg, _level ) |
---|
180 | |
---|
181 | #define fatal_int_service_status( _stat, _desired, _msg ) \ |
---|
182 | fatal_int_service_status_with_level( _stat, _desired, _msg, 0 ) |
---|
183 | |
---|
184 | #define fatal_int_service_status_with_level( _stat, _desired, _msg, _level ) \ |
---|
185 | do { \ |
---|
186 | check_dispatch_disable_level( _level ); \ |
---|
187 | if ( (_stat) != (_desired) ) { \ |
---|
188 | printf( "\n%s FAILED -- expected (%d) got (%d)\n", \ |
---|
189 | (_msg), (_desired), (_stat) ); \ |
---|
190 | rtems_test_exit( _stat ); \ |
---|
191 | } \ |
---|
192 | } while ( 0 ) |
---|
193 | |
---|
194 | |
---|
195 | /* |
---|
196 | * Print the time |
---|
197 | */ |
---|
198 | |
---|
199 | #define sprint_time(_str, _s1, _tb, _s2) \ |
---|
200 | do { \ |
---|
201 | sprintf( (_str), "%s%02d:%02d:%02d %02d/%02d/%04d%s", \ |
---|
202 | _s1, (_tb)->hour, (_tb)->minute, (_tb)->second, \ |
---|
203 | (_tb)->month, (_tb)->day, (_tb)->year, _s2 ); \ |
---|
204 | } while ( 0 ) |
---|
205 | |
---|
206 | #define print_time(_s1, _tb, _s2) \ |
---|
207 | do { \ |
---|
208 | printf( "%s%02" PRIu32 ":%02" PRIu32 ":%02" PRIu32 " %02" PRIu32 "/%02" PRIu32 "/%04" PRIu32 "%s", \ |
---|
209 | _s1, (_tb)->hour, (_tb)->minute, (_tb)->second, \ |
---|
210 | (_tb)->month, (_tb)->day, (_tb)->year, _s2 ); \ |
---|
211 | } while ( 0 ) |
---|
212 | |
---|
213 | #define put_dot( _c ) \ |
---|
214 | do { \ |
---|
215 | putchar( _c ); \ |
---|
216 | } while ( 0 ) |
---|
217 | |
---|
218 | #define new_line puts( "" ) |
---|
219 | |
---|
220 | #define puts_nocr printf |
---|
221 | |
---|
222 | #define put_name( name, crlf ) \ |
---|
223 | { int c0, c1, c2, c3; \ |
---|
224 | c0 = (name >> 24) & 0xff; \ |
---|
225 | c1 = (name >> 16) & 0xff; \ |
---|
226 | c2 = (name >> 8) & 0xff; \ |
---|
227 | c3 = name & 0xff; \ |
---|
228 | putchar( (isprint(c0)) ? c0 : '*' ); \ |
---|
229 | if ( c1 ) putchar( (isprint(c1)) ? c1 : '*' ); \ |
---|
230 | if ( c2 ) putchar( (isprint(c2)) ? c2 : '*' ); \ |
---|
231 | if ( c3 ) putchar( (isprint(c3)) ? c3 : '*' ); \ |
---|
232 | if ( crlf ) \ |
---|
233 | putchar( '\n' ); \ |
---|
234 | } |
---|
235 | |
---|
236 | #ifndef build_time |
---|
237 | #define build_time( TB, MON, DAY, YR, HR, MIN, SEC, TK ) \ |
---|
238 | { (TB)->year = YR; \ |
---|
239 | (TB)->month = MON; \ |
---|
240 | (TB)->day = DAY; \ |
---|
241 | (TB)->hour = HR; \ |
---|
242 | (TB)->minute = MIN; \ |
---|
243 | (TB)->second = SEC; \ |
---|
244 | (TB)->ticks = TK; } |
---|
245 | #endif |
---|
246 | |
---|
247 | #define task_number( tid ) \ |
---|
248 | ( rtems_object_id_get_index( tid ) - \ |
---|
249 | rtems_configuration_get_rtems_api_configuration()-> \ |
---|
250 | number_of_initialization_tasks ) |
---|
251 | |
---|
252 | #define rtems_test_assert(__exp) \ |
---|
253 | do { \ |
---|
254 | if (!(__exp)) { \ |
---|
255 | printf( "%s: %d %s\n", __FILE__, __LINE__, #__exp ); \ |
---|
256 | rtems_test_exit(0); \ |
---|
257 | } \ |
---|
258 | } while (0) |
---|
259 | |
---|
260 | /** |
---|
261 | * This assists in clearly disabling warnings on GCC in certain very |
---|
262 | * specific cases. |
---|
263 | * |
---|
264 | * + -Wnon-null - If a method is declared as never having a NULL first |
---|
265 | * parameter. We need to explicitly disable this compiler warning to make |
---|
266 | * the code warning free. |
---|
267 | */ |
---|
268 | #ifdef __GNUC__ |
---|
269 | #define COMPILER_DIAGNOSTIC_SETTINGS_PUSH _Pragma("GCC diagnostic push") |
---|
270 | #define COMPILER_DIAGNOSTIC_SETTINGS_POP _Pragma("GCC diagnostic pop") |
---|
271 | #define COMPILER_DIAGNOSTIC_SETTINGS_DISABLE_NONNULL \ |
---|
272 | _Pragma("GCC diagnostic ignored \"-Wnonnull\"") |
---|
273 | #else |
---|
274 | #define COMPILER_DIAGNOSTIC_SETTINGS_PUSH |
---|
275 | #define COMPILER_DIAGNOSTIC_SETTINGS_POP |
---|
276 | #define COMPILER_DIAGNOSTIC_SETTINGS_DISABLE_NONNULL |
---|
277 | #endif |
---|
278 | |
---|
279 | #ifdef __cplusplus |
---|
280 | } |
---|
281 | #endif |
---|
282 | |
---|
283 | #endif |
---|