source: rtems/testsuites/support/include/tmacros.h @ 45215d2

4.104.11
Last change on this file since 45215d2 was 45215d2, checked in by Ralf Corsepius <ralf.corsepius@…>, on May 29, 2010 at 5:29:33 AM

2010-05-29 Ralf Corsépius <ralf.corsepius@…>

  • support/include/tmacros.h: Remove PRIdoff_t.
  • Property mode set to 100644
File size: 9.0 KB
Line 
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
30extern "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#define check_dispatch_disable_level( _expect ) \
49  do { \
50    if ( (_expect) != -1 \
51           && ((_Thread_Dispatch_disable_level == 0 && (_expect) != 0) \
52             || (_Thread_Dispatch_disable_level != 0 && (_expect) == 0)) \
53    ) { \
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__ ); \
58      FLUSH_OUTPUT(); \
59      rtems_test_exit( 1 ); \
60    } \
61  } while ( 0 )
62
63/*
64 *  These macros properly report errors within the Classic API
65 */
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
76#define fatal_directive_check_status_only( _stat, _desired, _msg ) \
77  do { \
78    if ( (_stat) != (_desired) ) { \
79      printf( "\n%s FAILED -- expected (%s) got (%s)\n", \
80              (_msg), rtems_status_text(_desired), rtems_status_text(_stat) ); \
81      FLUSH_OUTPUT(); \
82      rtems_test_exit( _stat ); \
83    } \
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 ); \
90  } while ( 0 )
91
92/*
93 *  These macros properly report errors from the POSIX API
94 */
95
96#define posix_service_failed( _dirstat, _failmsg )  \
97 fatal_posix_service_status( _dirstat, 0, _failmsg )
98
99#define posix_service_failed_with_level( _dirstat, _failmsg, _level )  \
100 fatal_posix_service_status_with_level( _dirstat, 0, _failmsg, _level )
101
102#define fatal_posix_service_status_errno( _stat, _desired, _msg ) \
103  if ( (_stat != -1) && (errno) != (_desired) ) { \
104    long statx = _stat; \
105    check_dispatch_disable_level( 0 ); \
106    printf( "\n%s FAILED -- expected (%d - %s) got (%ld %d - %s)\n", \
107            (_msg), _desired, strerror(_desired), \
108            statx, errno, strerror(errno) ); \
109    FLUSH_OUTPUT(); \
110    rtems_test_exit( _stat ); \
111  }
112
113#define fatal_posix_service_status( _stat, _desired, _msg ) \
114  fatal_posix_service_status_with_level( _stat, _desired, _msg, 0 )
115
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
125#define fatal_posix_service_status_with_level( _stat, _desired, _msg, _level ) \
126  do { \
127    check_dispatch_disable_level( _level ); \
128    if ( (_stat) != (_desired) ) { \
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) ); \
133      FLUSH_OUTPUT(); \
134      rtems_test_exit( _stat ); \
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) ); \
158      FLUSH_OUTPUT(); \
159      rtems_test_exit( _stat ); \
160    } \
161  } while ( 0 )
162
163
164/*
165 *  Print the time
166 */
167
168#define sprint_time(_str, _s1, _tb, _s2) \
169  do { \
170    sprintf( (_str), "%s%02d:%02d:%02d   %02d/%02d/%04d%s", \
171       _s1, (_tb)->hour, (_tb)->minute, (_tb)->second, \
172       (_tb)->month, (_tb)->day, (_tb)->year, _s2 ); \
173  } while ( 0 )
174
175#define print_time(_s1, _tb, _s2) \
176  do { \
177    printf( "%s%02" PRIu32 ":%02" PRIu32 ":%02" PRIu32 "   %02" PRIu32 "/%02" PRIu32 "/%04" PRIu32 "%s", \
178       _s1, (_tb)->hour, (_tb)->minute, (_tb)->second, \
179       (_tb)->month, (_tb)->day, (_tb)->year, _s2 ); \
180  } while ( 0 )
181
182#define put_dot( _c ) \
183  do { \
184    putchar( _c ); \
185    FLUSH_OUTPUT(); \
186  } while ( 0 )
187
188#define new_line  puts( "" )
189
190#define puts_nocr printf
191
192#ifdef RTEMS_TEST_NO_PAUSE
193#define rtems_test_pause() \
194    do { \
195      printf( "<pause>\n" ); \
196      FLUSH_OUTPUT(); \
197  } while ( 0 )
198
199#define rtems_test_pause_and_screen_number( _screen ) \
200  do { \
201    printf( "<pause - screen %d>\n", (_screen) ); \
202    FLUSH_OUTPUT(); \
203  } while ( 0 )
204#else
205#define rtems_test_pause() \
206  do { \
207    char buffer[ 80 ]; \
208    printf( "<pause>" ); \
209    FLUSH_OUTPUT(); \
210    gets( buffer ); \
211    puts( "" ); \
212  } while ( 0 )
213
214#define rtems_test_pause_and_screen_number( _screen ) \
215  do { \
216    char buffer[ 80 ]; \
217    printf( "<pause - screen %d>", (_screen) ); \
218    FLUSH_OUTPUT(); \
219    gets( buffer ); \
220    puts( "" ); \
221  } while ( 0 )
222#endif
223
224#define put_name( name, crlf ) \
225{ int c0, c1, c2, c3; \
226  c0 = (name >> 24) & 0xff; \
227  c1 = (name >> 16) & 0xff; \
228  c2 = (name >> 8) & 0xff; \
229  c3 = name & 0xff; \
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 : '*' ); \
234  if ( crlf ) \
235    putchar( '\n' ); \
236}
237
238#ifndef build_time
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; }
247#endif
248
249#define task_number( tid ) \
250  ( rtems_object_id_get_index( tid ) - \
251      rtems_configuration_get_rtems_api_configuration()-> \
252        number_of_initialization_tasks )
253
254#define rtems_test_assert(__exp) \
255  do { \
256    if (!(__exp)) { \
257      printf( "%s: %d %s\n", __FILE__, __LINE__, #__exp ); \
258      rtems_test_exit(0); \
259    } \
260  } while (0)
261
262/*
263 * Various inttypes.h-stype macros to assist printing
264 * certain system types on different targets.
265 */
266
267/* HACK: Presume time_t to be a "long" */
268/* HACK: There is no portable way to print time_t's */
269#define PRItime_t "ld"
270
271#if defined(RTEMS_USE_16_BIT_OBJECT)
272#define PRIxrtems_id PRIx16
273#else
274#define PRIxrtems_id PRIx32
275#endif
276
277/* c.f. cpukit/score/include/rtems/score/priority.h */
278#define PRIdPriority_Control PRId32
279#define PRIxPriority_Control PRIx32
280/* rtems_task_priority is a typedef to Priority_Control */
281#define PRIdrtems_task_priority PRIdPriority_Control
282#define PRIxrtems_task_priority PRIxPriority_Control
283
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
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
294/* rtems_event_set is a typedef to unit32_t */
295#define PRIxrtems_event_set PRIx32
296
297/* HACK: newlib defines pthread_t as a typedef to __uint32_t */
298/* HACK: There is no portable way to print pthread_t's */
299#define PRIxpthread_t PRIx32
300
301/* rtems_signal_set is a typedef to uint32_t */
302#define PRIxrtems_signal_set PRIx32
303
304/* newlib's ino_t is a typedef to "unsigned long" */
305#define PRIxino_t "lx"
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
Note: See TracBrowser for help on using the repository browser.