[ac7d5ef0] | 1 | /* tmacros.h |
---|
| 2 | * |
---|
| 3 | * This include file contains macros which are useful in the RTEMS |
---|
| 4 | * test suites. |
---|
| 5 | * |
---|
[08311cc3] | 6 | * COPYRIGHT (c) 1989-1999. |
---|
[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 |
---|
[9cc61367] | 11 | * http://www.rtems.com/license/LICENSE. |
---|
[ac7d5ef0] | 12 | * |
---|
[3235ad9] | 13 | * $Id$ |
---|
[ac7d5ef0] | 14 | */ |
---|
| 15 | |
---|
| 16 | #ifndef __TMACROS_h |
---|
| 17 | #define __TMACROS_h |
---|
| 18 | |
---|
| 19 | #ifdef __cplusplus |
---|
| 20 | extern "C" { |
---|
| 21 | #endif |
---|
| 22 | |
---|
[c64e4ed4] | 23 | #include <bsp.h> /* includes <rtems.h> */ |
---|
[8d47a15] | 24 | |
---|
| 25 | #include <stdio.h> |
---|
| 26 | #include <stdlib.h> |
---|
[85d62357] | 27 | #include <string.h> |
---|
[4b960e5] | 28 | #include <assert.h> |
---|
[f388d36] | 29 | #include <rtems/error.h> |
---|
[ac7d5ef0] | 30 | |
---|
| 31 | #define FOREVER 1 /* infinite loop */ |
---|
| 32 | |
---|
[3a4ae6c] | 33 | #ifdef TEST_INIT |
---|
| 34 | #define TEST_EXTERN |
---|
| 35 | #define CONFIGURE_INIT |
---|
| 36 | #else |
---|
| 37 | #define TEST_EXTERN extern |
---|
| 38 | #endif |
---|
| 39 | |
---|
[cd9396e] | 40 | #include <buffer_test_io.h> |
---|
| 41 | |
---|
| 42 | /* |
---|
| 43 | * Check that that the dispatch disable level is proper for the |
---|
| 44 | * mode/state of the test. Normally it should be 0 when in task space. |
---|
| 45 | */ |
---|
| 46 | |
---|
[4b960e5] | 47 | #define check_dispatch_disable_level( _expect ) \ |
---|
| 48 | do { \ |
---|
| 49 | extern volatile rtems_unsigned32 _Thread_Dispatch_disable_level; \ |
---|
[96c2db6] | 50 | if ( (_expect) != -1 && _Thread_Dispatch_disable_level != (_expect) ) { \ |
---|
[4b960e5] | 51 | printf( "\n_Thread_Dispatch_disable_level is (%d) not %d\n", \ |
---|
| 52 | _Thread_Dispatch_disable_level, (_expect) ); \ |
---|
[cd9396e] | 53 | FLUSH_OUTPUT(); \ |
---|
| 54 | rtems_test_exit( 1 ); \ |
---|
[4b960e5] | 55 | } \ |
---|
| 56 | } while ( 0 ) |
---|
| 57 | |
---|
[85d62357] | 58 | /* |
---|
| 59 | * These macros properly report errors within the Classic API |
---|
| 60 | */ |
---|
| 61 | |
---|
[4b960e5] | 62 | #define directive_failed( _dirstat, _failmsg ) \ |
---|
| 63 | fatal_directive_status( _dirstat, RTEMS_SUCCESSFUL, _failmsg ) |
---|
| 64 | |
---|
| 65 | #define directive_failed_with_level( _dirstat, _failmsg, _level ) \ |
---|
| 66 | fatal_directive_status_with_level( \ |
---|
| 67 | _dirstat, RTEMS_SUCCESSFUL, _failmsg, _level ) |
---|
| 68 | |
---|
| 69 | #define fatal_directive_status( _stat, _desired, _msg ) \ |
---|
| 70 | fatal_directive_status_with_level( _stat, _desired, _msg, 0 ) |
---|
| 71 | |
---|
[f96cb0b] | 72 | #define fatal_directive_check_status_only( _stat, _desired, _msg ) \ |
---|
[4b960e5] | 73 | do { \ |
---|
| 74 | if ( (_stat) != (_desired) ) { \ |
---|
[f388d36] | 75 | printf( "\n%s FAILED -- expected (%s) got (%s)\n", \ |
---|
| 76 | (_msg), rtems_status_text(_desired), rtems_status_text(_stat) ); \ |
---|
[cd9396e] | 77 | FLUSH_OUTPUT(); \ |
---|
| 78 | rtems_test_exit( _stat ); \ |
---|
[4b960e5] | 79 | } \ |
---|
[f96cb0b] | 80 | } while ( 0 ) |
---|
| 81 | |
---|
| 82 | #define fatal_directive_status_with_level( _stat, _desired, _msg, _level ) \ |
---|
| 83 | do { \ |
---|
| 84 | check_dispatch_disable_level( _level ); \ |
---|
| 85 | fatal_directive_check_status_only( _stat, _desired, _msg ); \ |
---|
[4b960e5] | 86 | } while ( 0 ) |
---|
| 87 | |
---|
[85d62357] | 88 | /* |
---|
| 89 | * These macros properly report errors from the POSIX API |
---|
| 90 | */ |
---|
| 91 | |
---|
| 92 | #define posix_service_failed( _dirstat, _failmsg ) \ |
---|
| 93 | fatal_posix_service_status( _dirstat, RTEMS_SUCCESSFUL, _failmsg ) |
---|
| 94 | |
---|
| 95 | #define posix_service_failed_with_level( _dirstat, _failmsg, _level ) \ |
---|
| 96 | fatal_posix_service_status_with_level( \ |
---|
| 97 | _dirstat, RTEMS_SUCCESSFUL, _failmsg, _level ) |
---|
| 98 | |
---|
| 99 | #define fatal_posix_service_status( _stat, _desired, _msg ) \ |
---|
| 100 | fatal_posix_service_status_with_level( _stat, _desired, _msg, 0 ) |
---|
| 101 | |
---|
| 102 | #define fatal_posix_service_status_with_level( _stat, _desired, _msg, _level ) \ |
---|
| 103 | do { \ |
---|
| 104 | check_dispatch_disable_level( _level ); \ |
---|
| 105 | if ( (_stat) != (_desired) ) { \ |
---|
[413043b7] | 106 | printf( "\n%s FAILED -- expected (%d - %s) got (%d - %s)\n", \ |
---|
| 107 | (_msg), _desired, strerror(_desired), _stat, strerror(_stat) ); \ |
---|
| 108 | printf( "\n FAILED -- errno (%d - %s)\n", \ |
---|
| 109 | errno, strerror(errno) ); \ |
---|
[cd9396e] | 110 | FLUSH_OUTPUT(); \ |
---|
| 111 | rtems_test_exit( _stat ); \ |
---|
[85d62357] | 112 | } \ |
---|
| 113 | } while ( 0 ) |
---|
| 114 | |
---|
| 115 | /* |
---|
| 116 | * Generic integer version of the error reporting |
---|
| 117 | */ |
---|
| 118 | |
---|
| 119 | #define int_service_failed( _dirstat, _failmsg ) \ |
---|
| 120 | fatal_int_service_status( _dirstat, RTEMS_SUCCESSFUL, _failmsg ) |
---|
| 121 | |
---|
| 122 | #define int_service_failed_with_level( _dirstat, _failmsg, _level ) \ |
---|
| 123 | fatal_int_service_status_with_level( \ |
---|
| 124 | _dirstat, RTEMS_SUCCESSFUL, _failmsg, _level ) |
---|
| 125 | |
---|
| 126 | #define fatal_int_service_status( _stat, _desired, _msg ) \ |
---|
| 127 | fatal_int_service_status_with_level( _stat, _desired, _msg, 0 ) |
---|
| 128 | |
---|
| 129 | #define fatal_int_service_status_with_level( _stat, _desired, _msg, _level ) \ |
---|
| 130 | do { \ |
---|
| 131 | check_dispatch_disable_level( _level ); \ |
---|
| 132 | if ( (_stat) != (_desired) ) { \ |
---|
| 133 | printf( "\n%s FAILED -- expected (%d) got (%d)\n", \ |
---|
| 134 | (_msg), (_desired), (_stat) ); \ |
---|
[cd9396e] | 135 | FLUSH_OUTPUT(); \ |
---|
| 136 | rtems_test_exit( _stat ); \ |
---|
[85d62357] | 137 | } \ |
---|
| 138 | } while ( 0 ) |
---|
| 139 | |
---|
| 140 | |
---|
| 141 | /* |
---|
| 142 | * Print the time |
---|
| 143 | */ |
---|
| 144 | |
---|
[4b960e5] | 145 | #define sprint_time(_str, _s1, _tb, _s2) \ |
---|
[c64e4ed4] | 146 | do { \ |
---|
[ac7d5ef0] | 147 | sprintf( (str), "%s%02d:%02d:%02d %02d/%02d/%04d%s", \ |
---|
[4b960e5] | 148 | _s1, (_tb)->hour, (_tb)->minute, (_tb)->second, \ |
---|
| 149 | (_tb)->month, (_tb)->day, (_tb)->year, _s2 ); \ |
---|
[c64e4ed4] | 150 | } while ( 0 ) |
---|
[ac7d5ef0] | 151 | |
---|
[4b960e5] | 152 | #define print_time(_s1, _tb, _s2) \ |
---|
[c64e4ed4] | 153 | do { \ |
---|
[ac7d5ef0] | 154 | printf( "%s%02d:%02d:%02d %02d/%02d/%04d%s", \ |
---|
[4b960e5] | 155 | _s1, (_tb)->hour, (_tb)->minute, (_tb)->second, \ |
---|
| 156 | (_tb)->month, (_tb)->day, (_tb)->year, _s2 ); \ |
---|
[c64e4ed4] | 157 | } while ( 0 ) |
---|
[ac7d5ef0] | 158 | |
---|
[4b960e5] | 159 | #define put_dot( _c ) \ |
---|
| 160 | do { \ |
---|
| 161 | putchar( _c ); \ |
---|
[cd9396e] | 162 | FLUSH_OUTPUT(); \ |
---|
[4b960e5] | 163 | } while ( 0 ) |
---|
[ac7d5ef0] | 164 | |
---|
| 165 | #define new_line puts( "" ) |
---|
| 166 | |
---|
| 167 | #define puts_nocr printf |
---|
| 168 | |
---|
[2a3d1fd] | 169 | #ifdef RTEMS_TEST_NO_PAUSE |
---|
| 170 | #define rtems_test_pause() \ |
---|
| 171 | do { \ |
---|
[cd9396e] | 172 | printf( "<pause>\n" ); \ |
---|
| 173 | FLUSH_OUTPUT(); \ |
---|
[2a3d1fd] | 174 | } while ( 0 ) |
---|
| 175 | |
---|
| 176 | #define rtems_test_pause_and_screen_number( _screen ) \ |
---|
| 177 | do { \ |
---|
[cd9396e] | 178 | printf( "<pause - screen %d>\n", (_screen) ); \ |
---|
| 179 | FLUSH_OUTPUT(); \ |
---|
[2a3d1fd] | 180 | } while ( 0 ) |
---|
| 181 | #else |
---|
[ba39113] | 182 | #define rtems_test_pause() \ |
---|
[ac7d5ef0] | 183 | do { \ |
---|
| 184 | char buffer[ 80 ]; \ |
---|
[cd9396e] | 185 | printf( "<pause>" ); \ |
---|
| 186 | FLUSH_OUTPUT(); \ |
---|
[ac7d5ef0] | 187 | gets( buffer ); \ |
---|
| 188 | puts( "" ); \ |
---|
| 189 | } while ( 0 ) |
---|
| 190 | |
---|
[ba39113] | 191 | #define rtems_test_pause_and_screen_number( _screen ) \ |
---|
[ac7d5ef0] | 192 | do { \ |
---|
| 193 | char buffer[ 80 ]; \ |
---|
[cd9396e] | 194 | printf( "<pause - screen %d>", (_screen) ); \ |
---|
| 195 | FLUSH_OUTPUT(); \ |
---|
[ac7d5ef0] | 196 | gets( buffer ); \ |
---|
| 197 | puts( "" ); \ |
---|
| 198 | } while ( 0 ) |
---|
[2a3d1fd] | 199 | #endif |
---|
[ac7d5ef0] | 200 | |
---|
| 201 | #define put_name( name, crlf ) \ |
---|
| 202 | { rtems_unsigned32 c0, c1, c2, c3; \ |
---|
| 203 | c0 = (name >> 24) & 0xff; \ |
---|
| 204 | c1 = (name >> 16) & 0xff; \ |
---|
| 205 | c2 = (name >> 8) & 0xff; \ |
---|
| 206 | c3 = name & 0xff; \ |
---|
| 207 | putchar( (char)c0 ); \ |
---|
| 208 | if ( c1 ) putchar( (char)c1 ); \ |
---|
| 209 | if ( c2 ) putchar( (char)c2 ); \ |
---|
| 210 | if ( c3 ) putchar( (char)c3 ); \ |
---|
| 211 | if ( crlf ) \ |
---|
| 212 | putchar( '\n' ); \ |
---|
| 213 | } |
---|
| 214 | |
---|
[b8cda5a6] | 215 | #ifndef build_time |
---|
[ac7d5ef0] | 216 | #define build_time( TB, MON, DAY, YR, HR, MIN, SEC, TK ) \ |
---|
| 217 | { (TB)->year = YR; \ |
---|
| 218 | (TB)->month = MON; \ |
---|
| 219 | (TB)->day = DAY; \ |
---|
| 220 | (TB)->hour = HR; \ |
---|
| 221 | (TB)->minute = MIN; \ |
---|
| 222 | (TB)->second = SEC; \ |
---|
| 223 | (TB)->ticks = TK; } |
---|
[b8cda5a6] | 224 | #endif |
---|
[ac7d5ef0] | 225 | |
---|
| 226 | #define task_number( tid ) \ |
---|
[e6d4b1d] | 227 | ( rtems_get_index( tid ) - \ |
---|
[458bd34] | 228 | rtems_configuration_get_rtems_api_configuration()->number_of_initialization_tasks ) |
---|
[ac7d5ef0] | 229 | |
---|
| 230 | static inline rtems_unsigned32 get_ticks_per_second( void ) |
---|
| 231 | { |
---|
| 232 | rtems_interval ticks_per_second; |
---|
| 233 | (void) rtems_clock_get( RTEMS_CLOCK_GET_TICKS_PER_SECOND, &ticks_per_second ); |
---|
| 234 | return ticks_per_second; |
---|
| 235 | } |
---|
| 236 | |
---|
| 237 | #define TICKS_PER_SECOND get_ticks_per_second() |
---|
| 238 | |
---|
| 239 | #ifdef __cplusplus |
---|
| 240 | } |
---|
| 241 | #endif |
---|
| 242 | |
---|
| 243 | #endif |
---|