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

4.104.114.84.95
Last change on this file since cd9396e was cd9396e, checked in by Joel Sherrill <joel.sherrill@…>, on 08/02/02 at 00:51:52

2002-08-01 Joel Sherrill <joel@…>

  • Per PR47 add support for buffered test output. This involved adding defines to redirect output to a buffer and dump it when full, at "test pause", and at exit. To avoid problems when redefining exit(), all tests were modified to call rtems_test_exit(). Some tests, notable psxtests, had to be modified to include the standard test macro .h file (pmacros.h or tmacros.h) to enable this support.
  • include/buffer_test_io.h: New file.
  • Property mode set to 100644
File size: 6.4 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#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
47#define check_dispatch_disable_level( _expect ) \
48  do { \
49    extern volatile rtems_unsigned32 _Thread_Dispatch_disable_level; \
50    if ( (_expect) != -1 && _Thread_Dispatch_disable_level != (_expect) ) { \
51      printf( "\n_Thread_Dispatch_disable_level is (%d) not %d\n", \
52              _Thread_Dispatch_disable_level, (_expect) ); \
53      FLUSH_OUTPUT(); \
54      rtems_test_exit( 1 ); \
55    } \
56  } while ( 0 )
57
58/*
59 *  These macros properly report errors within the Classic API
60 */
61
62#define directive_failed( _dirstat, _failmsg )  \
63 fatal_directive_status( _dirstat, RTEMS_SUCCESSFUL, _failmsg )
64
65#define directive_failed_with_level( _dirstat, _failmsg, _level )  \
66 fatal_directive_status_with_level( \
67      _dirstat, RTEMS_SUCCESSFUL, _failmsg, _level )
68
69#define fatal_directive_status( _stat, _desired, _msg ) \
70  fatal_directive_status_with_level( _stat, _desired, _msg, 0 )
71
72#define fatal_directive_check_status_only( _stat, _desired, _msg ) \
73  do { \
74    if ( (_stat) != (_desired) ) { \
75      printf( "\n%s FAILED -- expected (%s) got (%s)\n", \
76              (_msg), rtems_status_text(_desired), rtems_status_text(_stat) ); \
77      FLUSH_OUTPUT(); \
78      rtems_test_exit( _stat ); \
79    } \
80  } while ( 0 )
81
82#define fatal_directive_status_with_level( _stat, _desired, _msg, _level ) \
83  do { \
84    check_dispatch_disable_level( _level ); \
85    fatal_directive_check_status_only( _stat, _desired, _msg ); \
86  } while ( 0 )
87
88/*
89 *  These macros properly report errors from the POSIX API
90 */
91
92#define posix_service_failed( _dirstat, _failmsg )  \
93 fatal_posix_service_status( _dirstat, RTEMS_SUCCESSFUL, _failmsg )
94
95#define posix_service_failed_with_level( _dirstat, _failmsg, _level )  \
96 fatal_posix_service_status_with_level( \
97      _dirstat, RTEMS_SUCCESSFUL, _failmsg, _level )
98
99#define fatal_posix_service_status( _stat, _desired, _msg ) \
100  fatal_posix_service_status_with_level( _stat, _desired, _msg, 0 )
101
102#define fatal_posix_service_status_with_level( _stat, _desired, _msg, _level ) \
103  do { \
104    check_dispatch_disable_level( _level ); \
105    if ( (_stat) != (_desired) ) { \
106      printf( "\n%s FAILED -- expected (%d - %s) got (%d - %s)\n", \
107              (_msg), _desired, strerror(_desired), _stat, strerror(_stat) ); \
108      printf( "\n FAILED -- errno (%d - %s)\n", \
109              errno, strerror(errno) ); \
110      FLUSH_OUTPUT(); \
111      rtems_test_exit( _stat ); \
112    } \
113  } while ( 0 )
114
115/*
116 *  Generic integer version of the error reporting
117 */
118
119#define int_service_failed( _dirstat, _failmsg )  \
120 fatal_int_service_status( _dirstat, RTEMS_SUCCESSFUL, _failmsg )
121
122#define int_service_failed_with_level( _dirstat, _failmsg, _level )  \
123 fatal_int_service_status_with_level( \
124      _dirstat, RTEMS_SUCCESSFUL, _failmsg, _level )
125
126#define fatal_int_service_status( _stat, _desired, _msg ) \
127  fatal_int_service_status_with_level( _stat, _desired, _msg, 0 )
128
129#define fatal_int_service_status_with_level( _stat, _desired, _msg, _level ) \
130  do { \
131    check_dispatch_disable_level( _level ); \
132    if ( (_stat) != (_desired) ) { \
133      printf( "\n%s FAILED -- expected (%d) got (%d)\n", \
134              (_msg), (_desired), (_stat) ); \
135      FLUSH_OUTPUT(); \
136      rtems_test_exit( _stat ); \
137    } \
138  } while ( 0 )
139
140
141/*
142 *  Print the time
143 */
144
145#define sprint_time(_str, _s1, _tb, _s2) \
146  do { \
147    sprintf( (str), "%s%02d:%02d:%02d   %02d/%02d/%04d%s", \
148       _s1, (_tb)->hour, (_tb)->minute, (_tb)->second, \
149       (_tb)->month, (_tb)->day, (_tb)->year, _s2 ); \
150  } while ( 0 )
151
152#define print_time(_s1, _tb, _s2) \
153  do { \
154    printf( "%s%02d:%02d:%02d   %02d/%02d/%04d%s", \
155       _s1, (_tb)->hour, (_tb)->minute, (_tb)->second, \
156       (_tb)->month, (_tb)->day, (_tb)->year, _s2 ); \
157  } while ( 0 )
158
159#define put_dot( _c ) \
160  do { \
161    putchar( _c ); \
162    FLUSH_OUTPUT(); \
163  } while ( 0 )
164
165#define new_line  puts( "" )
166
167#define puts_nocr printf
168
169#ifdef RTEMS_TEST_NO_PAUSE
170#define rtems_test_pause() \
171    do { \
172      printf( "<pause>\n" ); \
173      FLUSH_OUTPUT(); \
174  } while ( 0 )
175
176#define rtems_test_pause_and_screen_number( _screen ) \
177  do { \
178    printf( "<pause - screen %d>\n", (_screen) ); \
179    FLUSH_OUTPUT(); \
180  } while ( 0 )
181#else
182#define rtems_test_pause() \
183  do { \
184    char buffer[ 80 ]; \
185    printf( "<pause>" ); \
186    FLUSH_OUTPUT(); \
187    gets( buffer ); \
188    puts( "" ); \
189  } while ( 0 )
190
191#define rtems_test_pause_and_screen_number( _screen ) \
192  do { \
193    char buffer[ 80 ]; \
194    printf( "<pause - screen %d>", (_screen) ); \
195    FLUSH_OUTPUT(); \
196    gets( buffer ); \
197    puts( "" ); \
198  } while ( 0 )
199#endif
200
201#define put_name( name, crlf ) \
202{ rtems_unsigned32 c0, c1, c2, c3; \
203  c0 = (name >> 24) & 0xff; \
204  c1 = (name >> 16) & 0xff; \
205  c2 = (name >> 8) & 0xff; \
206  c3 = name & 0xff; \
207  putchar( (char)c0 ); \
208  if ( c1 ) putchar( (char)c1 ); \
209  if ( c2 ) putchar( (char)c2 ); \
210  if ( c3 ) putchar( (char)c3 ); \
211  if ( crlf ) \
212    putchar( '\n' ); \
213}
214
215#ifndef build_time
216#define build_time( TB, MON, DAY, YR, HR, MIN, SEC, TK ) \
217  { (TB)->year   = YR;  \
218    (TB)->month  = MON; \
219    (TB)->day    = DAY; \
220    (TB)->hour   = HR;  \
221    (TB)->minute = MIN; \
222    (TB)->second = SEC; \
223    (TB)->ticks  = TK; }
224#endif
225
226#define task_number( tid ) \
227  ( rtems_get_index( tid ) - \
228     rtems_configuration_get_rtems_api_configuration()->number_of_initialization_tasks )
229
230static inline rtems_unsigned32 get_ticks_per_second( void )
231{
232  rtems_interval ticks_per_second;
233  (void) rtems_clock_get( RTEMS_CLOCK_GET_TICKS_PER_SECOND, &ticks_per_second );
234  return ticks_per_second;
235}
236
237#define TICKS_PER_SECOND get_ticks_per_second()
238
239#ifdef __cplusplus
240}
241#endif
242
243#endif
Note: See TracBrowser for help on using the repository browser.