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