source: rtems/testsuites/support/include/tmacros.h @ 83a66aa

4.104.114.95
Last change on this file since 83a66aa was 83a66aa, checked in by Joel Sherrill <joel.sherrill@…>, on 01/29/08 at 21:53:40

2008-01-29 Joel Sherrill <joel.sherrill@…>

  • support/include/tmacros.h: Add new rtems_test_assert() which exits rather than calling fatal error.
  • Property mode set to 100644
File size: 7.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-2008.
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#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 uint32_t   _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_errno( _stat, _desired, _msg ) \
100  if ( (_stat != -1) && (errno) != (_desired) ) { \
101    check_dispatch_disable_level( 0 ); \
102    printf( "\n%s FAILED -- expected (%d - %s) got (%d %d - %s)\n", \
103            (_msg), _desired, strerror(_desired), \
104            _stat, errno, strerror(errno) ); \
105    FLUSH_OUTPUT(); \
106    rtems_test_exit( _stat ); \
107  }
108
109#define fatal_posix_service_status( _stat, _desired, _msg ) \
110  fatal_posix_service_status_with_level( _stat, _desired, _msg, 0 )
111
112#define fatal_posix_service_status_with_level( _stat, _desired, _msg, _level ) \
113  do { \
114    check_dispatch_disable_level( _level ); \
115    if ( (_stat) != (_desired) ) { \
116      printf( "\n%s FAILED -- expected (%d - %s) got (%d - %s)\n", \
117              (_msg), _desired, strerror(_desired), _stat, strerror(_stat) ); \
118      printf( "\n FAILED -- errno (%d - %s)\n", \
119              errno, strerror(errno) ); \
120      FLUSH_OUTPUT(); \
121      rtems_test_exit( _stat ); \
122    } \
123  } while ( 0 )
124
125/*
126 *  Generic integer version of the error reporting
127 */
128
129#define int_service_failed( _dirstat, _failmsg )  \
130 fatal_int_service_status( _dirstat, RTEMS_SUCCESSFUL, _failmsg )
131
132#define int_service_failed_with_level( _dirstat, _failmsg, _level )  \
133 fatal_int_service_status_with_level( \
134      _dirstat, RTEMS_SUCCESSFUL, _failmsg, _level )
135
136#define fatal_int_service_status( _stat, _desired, _msg ) \
137  fatal_int_service_status_with_level( _stat, _desired, _msg, 0 )
138
139#define fatal_int_service_status_with_level( _stat, _desired, _msg, _level ) \
140  do { \
141    check_dispatch_disable_level( _level ); \
142    if ( (_stat) != (_desired) ) { \
143      printf( "\n%s FAILED -- expected (%d) got (%d)\n", \
144              (_msg), (_desired), (_stat) ); \
145      FLUSH_OUTPUT(); \
146      rtems_test_exit( _stat ); \
147    } \
148  } while ( 0 )
149
150
151/*
152 *  Print the time
153 */
154
155#define sprint_time(_str, _s1, _tb, _s2) \
156  do { \
157    sprintf( (_str), "%s%02d:%02d:%02d   %02d/%02d/%04d%s", \
158       _s1, (_tb)->hour, (_tb)->minute, (_tb)->second, \
159       (_tb)->month, (_tb)->day, (_tb)->year, _s2 ); \
160  } while ( 0 )
161
162#define print_time(_s1, _tb, _s2) \
163  do { \
164    printf( "%s%02d:%02d:%02d   %02d/%02d/%04d%s", \
165       _s1, (_tb)->hour, (_tb)->minute, (_tb)->second, \
166       (_tb)->month, (_tb)->day, (_tb)->year, _s2 ); \
167  } while ( 0 )
168
169#define put_dot( _c ) \
170  do { \
171    putchar( _c ); \
172    FLUSH_OUTPUT(); \
173  } while ( 0 )
174
175#define new_line  puts( "" )
176
177#define puts_nocr printf
178
179#ifdef RTEMS_TEST_NO_PAUSE
180#define rtems_test_pause() \
181    do { \
182      printf( "<pause>\n" ); \
183      FLUSH_OUTPUT(); \
184  } while ( 0 )
185
186#define rtems_test_pause_and_screen_number( _screen ) \
187  do { \
188    printf( "<pause - screen %d>\n", (_screen) ); \
189    FLUSH_OUTPUT(); \
190  } while ( 0 )
191#else
192#define rtems_test_pause() \
193  do { \
194    char buffer[ 80 ]; \
195    printf( "<pause>" ); \
196    FLUSH_OUTPUT(); \
197    gets( buffer ); \
198    puts( "" ); \
199  } while ( 0 )
200
201#define rtems_test_pause_and_screen_number( _screen ) \
202  do { \
203    char buffer[ 80 ]; \
204    printf( "<pause - screen %d>", (_screen) ); \
205    FLUSH_OUTPUT(); \
206    gets( buffer ); \
207    puts( "" ); \
208  } while ( 0 )
209#endif
210
211#define put_name( name, crlf ) \
212{ uint32_t   c0, c1, c2, c3; \
213  c0 = (name >> 24) & 0xff; \
214  c1 = (name >> 16) & 0xff; \
215  c2 = (name >> 8) & 0xff; \
216  c3 = name & 0xff; \
217  putchar( (char)c0 ); \
218  if ( c1 ) putchar( (char)c1 ); \
219  if ( c2 ) putchar( (char)c2 ); \
220  if ( c3 ) putchar( (char)c3 ); \
221  if ( crlf ) \
222    putchar( '\n' ); \
223}
224
225#ifndef build_time
226#define build_time( TB, MON, DAY, YR, HR, MIN, SEC, TK ) \
227  { (TB)->year   = YR;  \
228    (TB)->month  = MON; \
229    (TB)->day    = DAY; \
230    (TB)->hour   = HR;  \
231    (TB)->minute = MIN; \
232    (TB)->second = SEC; \
233    (TB)->ticks  = TK; }
234#endif
235
236#define task_number( tid ) \
237  ( rtems_object_id_get_index( tid ) - \
238      rtems_configuration_get_rtems_api_configuration()-> \
239        number_of_initialization_tasks )
240
241static inline uint32_t   get_ticks_per_second( void )
242{
243  rtems_interval ticks_per_second;
244  (void) rtems_clock_get( RTEMS_CLOCK_GET_TICKS_PER_SECOND, &ticks_per_second );
245  return ticks_per_second;
246}
247
248#define TICKS_PER_SECOND get_ticks_per_second()
249
250#define rtems_test_assert(__exp) \
251  if (!(__exp)) { \
252    printf( "%s: %d %s\n", __FILE__, __LINE__, #__exp ); \
253    rtems_test_exit(0); \
254  }
255
256#ifdef __cplusplus
257}
258#endif
259
260#endif
Note: See TracBrowser for help on using the repository browser.