source: rtems/testsuites/support/include/tmacros.h @ 5618c37a

4.115
Last change on this file since 5618c37a was 5618c37a, checked in by Sebastian Huber <sebastian.huber@…>, on 07/24/13 at 13:14:48

score: Create thread implementation header

Move implementation specific parts of thread.h and thread.inl into new
header file threadimpl.h. The thread.h contains now only the
application visible API.

Remove superfluous header file includes from various files.

  • Property mode set to 100644
File size: 8.5 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
14#ifndef __TMACROS_h
15#define __TMACROS_h
16
17#include <inttypes.h>
18#include <bsp.h>    /* includes <rtems.h> */
19
20#include <ctype.h>
21#include <stdio.h>
22#include <stdlib.h>
23#include <string.h>
24#include <rtems/error.h>
25#include <rtems/score/threaddispatch.h>
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31
32#define FOREVER 1                  /* infinite loop */
33
34#ifdef CONFIGURE_INIT
35#define TEST_EXTERN
36#else
37#define TEST_EXTERN extern
38#endif
39
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 *  This test is only valid when in a non smp system.  In an smp system
47 *  another cpu may be accessing the core at any point when this core
48 *  does not have it locked.
49 */
50#if defined SMPTEST
51 #define check_dispatch_disable_level( _expect )
52#else
53 #define check_dispatch_disable_level( _expect ) \
54  do { \
55    if ( (_expect) != -1 \
56           && ((!_Thread_Dispatch_is_enabled() == false && (_expect) != 0) \
57             || (!_Thread_Dispatch_is_enabled() && (_expect) == 0)) \
58    ) { \
59      printk( \
60        "\n_Thread_Dispatch_disable_level is (%" PRId32 \
61           ") not %d detected at %s:%d\n", \
62         !_Thread_Dispatch_is_enabled(), (_expect), __FILE__, __LINE__ ); \
63      FLUSH_OUTPUT(); \
64      rtems_test_exit( 1 ); \
65    } \
66  } while ( 0 )
67#endif
68
69/*
70 *  These macros properly report errors within the Classic API
71 */
72#define directive_failed( _dirstat, _failmsg )  \
73 fatal_directive_status( _dirstat, RTEMS_SUCCESSFUL, _failmsg )
74
75#define directive_failed_with_level( _dirstat, _failmsg, _level )  \
76 fatal_directive_status_with_level( \
77      _dirstat, RTEMS_SUCCESSFUL, _failmsg, _level )
78
79#define fatal_directive_status( _stat, _desired, _msg ) \
80  fatal_directive_status_with_level( _stat, _desired, _msg, 0 )
81
82#define fatal_directive_check_status_only( _stat, _desired, _msg ) \
83  do { \
84    if ( (_stat) != (_desired) ) { \
85      printf( "\n%s FAILED -- expected (%s) got (%s)\n", \
86              (_msg), rtems_status_text(_desired), rtems_status_text(_stat) ); \
87      FLUSH_OUTPUT(); \
88      rtems_test_exit( _stat ); \
89    } \
90  } while ( 0 )
91
92#define fatal_directive_status_with_level( _stat, _desired, _msg, _level ) \
93  do { \
94    check_dispatch_disable_level( _level ); \
95    fatal_directive_check_status_only( _stat, _desired, _msg ); \
96  } while ( 0 )
97
98/*
99 *  These macros properly report errors from the POSIX API
100 */
101
102#define posix_service_failed( _dirstat, _failmsg )  \
103 fatal_posix_service_status( _dirstat, 0, _failmsg )
104
105#define posix_service_failed_with_level( _dirstat, _failmsg, _level )  \
106 fatal_posix_service_status_with_level( _dirstat, 0, _failmsg, _level )
107
108#define fatal_posix_service_status_errno( _stat, _desired, _msg ) \
109  if ( (_stat != -1) && (errno) != (_desired) ) { \
110    long statx = _stat; \
111    check_dispatch_disable_level( 0 ); \
112    printf( "\n%s FAILED -- expected (%d - %s) got (%ld %d - %s)\n", \
113            (_msg), _desired, strerror(_desired), \
114            statx, errno, strerror(errno) ); \
115    FLUSH_OUTPUT(); \
116    rtems_test_exit( _stat ); \
117  }
118
119#define fatal_posix_service_status( _stat, _desired, _msg ) \
120  fatal_posix_service_status_with_level( _stat, _desired, _msg, 0 )
121
122#define fatal_posix_service_status_with_level( _stat, _desired, _msg, _level ) \
123  do { \
124    check_dispatch_disable_level( _level ); \
125    if ( (_stat) != (_desired) ) { \
126      printf( "\n%s FAILED -- expected (%d - %s) got (%d - %s)\n", \
127              (_msg), _desired, strerror(_desired), _stat, strerror(_stat) ); \
128      printf( "\n FAILED -- errno (%d - %s)\n", \
129              errno, strerror(errno) ); \
130      FLUSH_OUTPUT(); \
131      rtems_test_exit( _stat ); \
132    } \
133  } while ( 0 )
134
135/*
136 *  Generic integer version of the error reporting
137 */
138
139#define int_service_failed( _dirstat, _failmsg )  \
140 fatal_int_service_status( _dirstat, RTEMS_SUCCESSFUL, _failmsg )
141
142#define int_service_failed_with_level( _dirstat, _failmsg, _level )  \
143 fatal_int_service_status_with_level( \
144      _dirstat, RTEMS_SUCCESSFUL, _failmsg, _level )
145
146#define fatal_int_service_status( _stat, _desired, _msg ) \
147  fatal_int_service_status_with_level( _stat, _desired, _msg, 0 )
148
149#define fatal_int_service_status_with_level( _stat, _desired, _msg, _level ) \
150  do { \
151    check_dispatch_disable_level( _level ); \
152    if ( (_stat) != (_desired) ) { \
153      printf( "\n%s FAILED -- expected (%d) got (%d)\n", \
154              (_msg), (_desired), (_stat) ); \
155      FLUSH_OUTPUT(); \
156      rtems_test_exit( _stat ); \
157    } \
158  } while ( 0 )
159
160
161/*
162 *  Print the time
163 */
164
165#define sprint_time(_str, _s1, _tb, _s2) \
166  do { \
167    sprintf( (_str), "%s%02d:%02d:%02d   %02d/%02d/%04d%s", \
168       _s1, (_tb)->hour, (_tb)->minute, (_tb)->second, \
169       (_tb)->month, (_tb)->day, (_tb)->year, _s2 ); \
170  } while ( 0 )
171
172#define print_time(_s1, _tb, _s2) \
173  do { \
174    printf( "%s%02" PRIu32 ":%02" PRIu32 ":%02" PRIu32 "   %02" PRIu32 "/%02" PRIu32 "/%04" PRIu32 "%s", \
175       _s1, (_tb)->hour, (_tb)->minute, (_tb)->second, \
176       (_tb)->month, (_tb)->day, (_tb)->year, _s2 ); \
177  } while ( 0 )
178
179#define put_dot( _c ) \
180  do { \
181    putchar( _c ); \
182    FLUSH_OUTPUT(); \
183  } while ( 0 )
184
185#define new_line  puts( "" )
186
187#define puts_nocr printf
188
189#ifdef RTEMS_TEST_NO_PAUSE
190#define rtems_test_pause() \
191    do { \
192      printf( "<pause>\n" ); \
193      FLUSH_OUTPUT(); \
194  } while ( 0 )
195
196#define rtems_test_pause_and_screen_number( _screen ) \
197  do { \
198    printf( "<pause - screen %d>\n", (_screen) ); \
199    FLUSH_OUTPUT(); \
200  } while ( 0 )
201#else
202#define rtems_test_pause() \
203  do { \
204    char buffer[ 80 ]; \
205    printf( "<pause>" ); \
206    FLUSH_OUTPUT(); \
207    gets( buffer ); \
208    puts( "" ); \
209  } while ( 0 )
210
211#define rtems_test_pause_and_screen_number( _screen ) \
212  do { \
213    char buffer[ 80 ]; \
214    printf( "<pause - screen %d>", (_screen) ); \
215    FLUSH_OUTPUT(); \
216    gets( buffer ); \
217    puts( "" ); \
218  } while ( 0 )
219#endif
220
221#define put_name( name, crlf ) \
222{ int c0, c1, c2, c3; \
223  c0 = (name >> 24) & 0xff; \
224  c1 = (name >> 16) & 0xff; \
225  c2 = (name >> 8) & 0xff; \
226  c3 = name & 0xff; \
227  putchar( (isprint(c0)) ? c0 : '*' ); \
228  if ( c1 ) putchar( (isprint(c1)) ? c1 : '*' ); \
229  if ( c2 ) putchar( (isprint(c2)) ? c2 : '*' ); \
230  if ( c3 ) putchar( (isprint(c3)) ? c3 : '*' ); \
231  if ( crlf ) \
232    putchar( '\n' ); \
233}
234
235#ifndef build_time
236#define build_time( TB, MON, DAY, YR, HR, MIN, SEC, TK ) \
237  { (TB)->year   = YR;  \
238    (TB)->month  = MON; \
239    (TB)->day    = DAY; \
240    (TB)->hour   = HR;  \
241    (TB)->minute = MIN; \
242    (TB)->second = SEC; \
243    (TB)->ticks  = TK; }
244#endif
245
246#define task_number( tid ) \
247  ( rtems_object_id_get_index( tid ) - \
248      rtems_configuration_get_rtems_api_configuration()-> \
249        number_of_initialization_tasks )
250
251#define rtems_test_assert(__exp) \
252  do { \
253    if (!(__exp)) { \
254      printf( "%s: %d %s\n", __FILE__, __LINE__, #__exp ); \
255      rtems_test_exit(0); \
256    } \
257  } while (0)
258
259/*
260 * Various inttypes.h-stype macros to assist printing
261 * certain system types on different targets.
262 */
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#ifdef __cplusplus
301}
302#endif
303
304#endif
Note: See TracBrowser for help on using the repository browser.