source: rtems/c/src/tests/support/include/tmacros.h @ 85d62357

4.104.114.84.95
Last change on this file since 85d62357 was 85d62357, checked in by Joel Sherrill <joel.sherrill@…>, on Jan 13, 2000 at 7:26:38 PM

Changed error checking macros for POSIX.

  • Property mode set to 100644
File size: 6.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-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 *  $Id$
14 */
15
16#ifndef __TMACROS_h
17#define __TMACROS_h
18
19#ifdef __cplusplus
20extern "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#define CONFIGURE_INIT
36#else
37#define TEST_EXTERN extern
38#endif
39
40#define check_dispatch_disable_level( _expect ) \
41  do { \
42    extern volatile rtems_unsigned32 _Thread_Dispatch_disable_level; \
43    if ( (_expect) != -1 && _Thread_Dispatch_disable_level != (_expect) ) { \
44      printf( "\n_Thread_Dispatch_disable_level is (%d) not %d\n", \
45              _Thread_Dispatch_disable_level, (_expect) ); \
46      fflush(stdout); \
47      exit( 1 ); \
48    } \
49  } while ( 0 )
50
51/*
52 *  These macros properly report errors within the Classic API
53 */
54
55#define directive_failed( _dirstat, _failmsg )  \
56 fatal_directive_status( _dirstat, RTEMS_SUCCESSFUL, _failmsg )
57
58#define directive_failed_with_level( _dirstat, _failmsg, _level )  \
59 fatal_directive_status_with_level( \
60      _dirstat, RTEMS_SUCCESSFUL, _failmsg, _level )
61
62#define fatal_directive_status( _stat, _desired, _msg ) \
63  fatal_directive_status_with_level( _stat, _desired, _msg, 0 )
64
65#define fatal_directive_status_with_level( _stat, _desired, _msg, _level ) \
66  do { \
67    check_dispatch_disable_level( _level ); \
68    if ( (_stat) != (_desired) ) { \
69      printf( "\n%s FAILED -- expected (%s) got (%s)\n", \
70              (_msg), rtems_status_text(_desired), rtems_status_text(_stat) ); \
71      fflush(stdout); \
72      exit( _stat ); \
73    } \
74  } while ( 0 )
75
76/*
77 *  These macros properly report errors from the POSIX API
78 */
79
80#define posix_service_failed( _dirstat, _failmsg )  \
81 fatal_posix_service_status( _dirstat, RTEMS_SUCCESSFUL, _failmsg )
82
83#define posix_service_failed_with_level( _dirstat, _failmsg, _level )  \
84 fatal_posix_service_status_with_level( \
85      _dirstat, RTEMS_SUCCESSFUL, _failmsg, _level )
86
87#define fatal_posix_service_status( _stat, _desired, _msg ) \
88  fatal_posix_service_status_with_level( _stat, _desired, _msg, 0 )
89
90#define fatal_posix_service_status_with_level( _stat, _desired, _msg, _level ) \
91  do { \
92    check_dispatch_disable_level( _level ); \
93    if ( (_stat) != (_desired) ) { \
94      printf( "\n%s FAILED -- expected (%s) got (%s)\n", \
95              (_msg), strerror(_desired), strerror(_stat) ); \
96      fflush(stdout); \
97      exit( _stat ); \
98    } \
99  } while ( 0 )
100
101/*
102 *  Generic integer version of the error reporting
103 */
104
105#define int_service_failed( _dirstat, _failmsg )  \
106 fatal_int_service_status( _dirstat, RTEMS_SUCCESSFUL, _failmsg )
107
108#define int_service_failed_with_level( _dirstat, _failmsg, _level )  \
109 fatal_int_service_status_with_level( \
110      _dirstat, RTEMS_SUCCESSFUL, _failmsg, _level )
111
112#define fatal_int_service_status( _stat, _desired, _msg ) \
113  fatal_int_service_status_with_level( _stat, _desired, _msg, 0 )
114
115#define fatal_int_service_status_with_level( _stat, _desired, _msg, _level ) \
116  do { \
117    check_dispatch_disable_level( _level ); \
118    if ( (_stat) != (_desired) ) { \
119      printf( "\n%s FAILED -- expected (%d) got (%d)\n", \
120              (_msg), (_desired), (_stat) ); \
121      fflush(stdout); \
122      exit( _stat ); \
123    } \
124  } while ( 0 )
125
126
127/*
128 *  Print the time
129 */
130
131#define sprint_time(_str, _s1, _tb, _s2) \
132  do { \
133    sprintf( (str), "%s%02d:%02d:%02d   %02d/%02d/%04d%s", \
134       _s1, (_tb)->hour, (_tb)->minute, (_tb)->second, \
135       (_tb)->month, (_tb)->day, (_tb)->year, _s2 ); \
136  } while ( 0 )
137
138#define print_time(_s1, _tb, _s2) \
139  do { \
140    printf( "%s%02d:%02d:%02d   %02d/%02d/%04d%s", \
141       _s1, (_tb)->hour, (_tb)->minute, (_tb)->second, \
142       (_tb)->month, (_tb)->day, (_tb)->year, _s2 ); \
143    fflush(stdout); \
144  } while ( 0 )
145
146#define put_dot( _c ) \
147  do { \
148    putchar( _c ); \
149    fflush( stdout ); \
150  } while ( 0 )
151
152#define new_line  puts( "" )
153
154#define puts_nocr printf
155
156#ifdef RTEMS_TEST_NO_PAUSE
157#define rtems_test_pause() \
158    do { \
159      printf( "<pause>\n" ); fflush( stdout ); \
160  } while ( 0 )
161
162#define rtems_test_pause_and_screen_number( _screen ) \
163  do { \
164    printf( "<pause - screen %d>\n", (_screen) ); fflush( stdout ); \
165  } while ( 0 )
166#else
167#define rtems_test_pause() \
168  do { \
169    char buffer[ 80 ]; \
170    printf( "<pause>" ); fflush( stdout ); \
171    gets( buffer ); \
172    puts( "" ); \
173  } while ( 0 )
174
175#define rtems_test_pause_and_screen_number( _screen ) \
176  do { \
177    char buffer[ 80 ]; \
178    printf( "<pause - screen %d>", (_screen) ); fflush( stdout ); \
179    gets( buffer ); \
180    puts( "" ); \
181  } while ( 0 )
182#endif
183
184#define put_name( name, crlf ) \
185{ rtems_unsigned32 c0, c1, c2, c3; \
186  c0 = (name >> 24) & 0xff; \
187  c1 = (name >> 16) & 0xff; \
188  c2 = (name >> 8) & 0xff; \
189  c3 = name & 0xff; \
190  putchar( (char)c0 ); \
191  if ( c1 ) putchar( (char)c1 ); \
192  if ( c2 ) putchar( (char)c2 ); \
193  if ( c3 ) putchar( (char)c3 ); \
194  if ( crlf ) \
195    putchar( '\n' ); \
196}
197
198#ifndef build_time
199#define build_time( TB, MON, DAY, YR, HR, MIN, SEC, TK ) \
200  { (TB)->year   = YR;  \
201    (TB)->month  = MON; \
202    (TB)->day    = DAY; \
203    (TB)->hour   = HR;  \
204    (TB)->minute = MIN; \
205    (TB)->second = SEC; \
206    (TB)->ticks  = TK; }
207#endif
208
209#define task_number( tid ) \
210  ( rtems_get_index( tid ) - \
211     rtems_configuration_get_rtems_api_configuration()->number_of_initialization_tasks )
212
213static inline rtems_unsigned32 get_ticks_per_second( void )
214{
215  rtems_interval ticks_per_second;
216  (void) rtems_clock_get( RTEMS_CLOCK_GET_TICKS_PER_SECOND, &ticks_per_second );
217  return ticks_per_second;
218}
219
220#define TICKS_PER_SECOND get_ticks_per_second()
221
222#ifdef __cplusplus
223}
224#endif
225
226#endif
Note: See TracBrowser for help on using the repository browser.