source: rtems/testsuites/support/include/tmacros.h @ d504e48

4.115
Last change on this file since d504e48 was d504e48, checked in by Jennifer Averett <Jennifer.Averett@…>, on 07/01/11 at 14:28:03

2011-07-01 Jennifer Averett <Jennifer.Averett@…>

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