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