source: rtems/testsuites/support/include/tmacros.h @ 3699e143

4.104.115
Last change on this file since 3699e143 was 3699e143, checked in by Ralf Corsepius <ralf.corsepius@…>, on 11/01/09 at 06:38:59

Add PRIxino_t, PRIdoff_t, PRIxblksize_t, PRIxblkcnt_t.
Comment cleanups.

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