source: rtems/testsuites/support/include/tmacros.h @ 413043b7

4.104.114.84.95
Last change on this file since 413043b7 was 413043b7, checked in by Joel Sherrill <joel.sherrill@…>, on 08/16/01 at 19:42:02

2001-08-16 Joel Sherrill <joel@…>

  • include/tmacros.h: Attempt to print errno as further information.
  • Property mode set to 100644
File size: 6.1 KB
RevLine 
[ac7d5ef0]1/*  tmacros.h
2 *
3 *  This include file contains macros which are useful in the RTEMS
4 *  test suites.
5 *
[08311cc3]6 *  COPYRIGHT (c) 1989-1999.
[ac7d5ef0]7 *  On-Line Applications Research Corporation (OAR).
8 *
[98e4ebf5]9 *  The license and distribution terms for this file may be
10 *  found in the file LICENSE in this distribution or at
[03f2154e]11 *  http://www.OARcorp.com/rtems/license.html.
[ac7d5ef0]12 *
[3235ad9]13 *  $Id$
[ac7d5ef0]14 */
15
16#ifndef __TMACROS_h
17#define __TMACROS_h
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
[c64e4ed4]23#include <bsp.h>    /* includes <rtems.h> */
[8d47a15]24
25#include <stdio.h>
26#include <stdlib.h>
[85d62357]27#include <string.h>
[4b960e5]28#include <assert.h>
[f388d36]29#include <rtems/error.h>
[ac7d5ef0]30
31#define FOREVER 1                  /* infinite loop */
32
[3a4ae6c]33#ifdef TEST_INIT
34#define TEST_EXTERN
35#define CONFIGURE_INIT
36#else
37#define TEST_EXTERN extern
38#endif
39
[4b960e5]40#define check_dispatch_disable_level( _expect ) \
41  do { \
42    extern volatile rtems_unsigned32 _Thread_Dispatch_disable_level; \
[96c2db6]43    if ( (_expect) != -1 && _Thread_Dispatch_disable_level != (_expect) ) { \
[4b960e5]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
[85d62357]51/*
52 *  These macros properly report errors within the Classic API
53 */
54
[4b960e5]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) ) { \
[f388d36]69      printf( "\n%s FAILED -- expected (%s) got (%s)\n", \
70              (_msg), rtems_status_text(_desired), rtems_status_text(_stat) ); \
[4b960e5]71      fflush(stdout); \
72      exit( _stat ); \
73    } \
74  } while ( 0 )
75
[85d62357]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) ) { \
[413043b7]94      printf( "\n%s FAILED -- expected (%d - %s) got (%d - %s)\n", \
95              (_msg), _desired, strerror(_desired), _stat, strerror(_stat) ); \
96      printf( "\n FAILED -- errno (%d - %s)\n", \
97              errno, strerror(errno) ); \
[85d62357]98      fflush(stdout); \
99      exit( _stat ); \
100    } \
101  } while ( 0 )
102
103/*
104 *  Generic integer version of the error reporting
105 */
106
107#define int_service_failed( _dirstat, _failmsg )  \
108 fatal_int_service_status( _dirstat, RTEMS_SUCCESSFUL, _failmsg )
109
110#define int_service_failed_with_level( _dirstat, _failmsg, _level )  \
111 fatal_int_service_status_with_level( \
112      _dirstat, RTEMS_SUCCESSFUL, _failmsg, _level )
113
114#define fatal_int_service_status( _stat, _desired, _msg ) \
115  fatal_int_service_status_with_level( _stat, _desired, _msg, 0 )
116
117#define fatal_int_service_status_with_level( _stat, _desired, _msg, _level ) \
118  do { \
119    check_dispatch_disable_level( _level ); \
120    if ( (_stat) != (_desired) ) { \
121      printf( "\n%s FAILED -- expected (%d) got (%d)\n", \
122              (_msg), (_desired), (_stat) ); \
123      fflush(stdout); \
124      exit( _stat ); \
125    } \
126  } while ( 0 )
127
128
129/*
130 *  Print the time
131 */
132
[4b960e5]133#define sprint_time(_str, _s1, _tb, _s2) \
[c64e4ed4]134  do { \
[ac7d5ef0]135    sprintf( (str), "%s%02d:%02d:%02d   %02d/%02d/%04d%s", \
[4b960e5]136       _s1, (_tb)->hour, (_tb)->minute, (_tb)->second, \
137       (_tb)->month, (_tb)->day, (_tb)->year, _s2 ); \
[c64e4ed4]138  } while ( 0 )
[ac7d5ef0]139
[4b960e5]140#define print_time(_s1, _tb, _s2) \
[c64e4ed4]141  do { \
[ac7d5ef0]142    printf( "%s%02d:%02d:%02d   %02d/%02d/%04d%s", \
[4b960e5]143       _s1, (_tb)->hour, (_tb)->minute, (_tb)->second, \
144       (_tb)->month, (_tb)->day, (_tb)->year, _s2 ); \
[c64e4ed4]145    fflush(stdout); \
146  } while ( 0 )
[ac7d5ef0]147
[4b960e5]148#define put_dot( _c ) \
149  do { \
150    putchar( _c ); \
151    fflush( stdout ); \
152  } while ( 0 )
[ac7d5ef0]153
154#define new_line  puts( "" )
155
156#define puts_nocr printf
157
[2a3d1fd]158#ifdef RTEMS_TEST_NO_PAUSE
159#define rtems_test_pause() \
160    do { \
161      printf( "<pause>\n" ); fflush( stdout ); \
162  } while ( 0 )
163
164#define rtems_test_pause_and_screen_number( _screen ) \
165  do { \
166    printf( "<pause - screen %d>\n", (_screen) ); fflush( stdout ); \
167  } while ( 0 )
168#else
[ba39113]169#define rtems_test_pause() \
[ac7d5ef0]170  do { \
171    char buffer[ 80 ]; \
[8d47a15]172    printf( "<pause>" ); fflush( stdout ); \
[ac7d5ef0]173    gets( buffer ); \
174    puts( "" ); \
175  } while ( 0 )
176
[ba39113]177#define rtems_test_pause_and_screen_number( _screen ) \
[ac7d5ef0]178  do { \
179    char buffer[ 80 ]; \
[4b374f36]180    printf( "<pause - screen %d>", (_screen) ); fflush( stdout ); \
[ac7d5ef0]181    gets( buffer ); \
182    puts( "" ); \
183  } while ( 0 )
[2a3d1fd]184#endif
[ac7d5ef0]185
186#define put_name( name, crlf ) \
187{ rtems_unsigned32 c0, c1, c2, c3; \
188  c0 = (name >> 24) & 0xff; \
189  c1 = (name >> 16) & 0xff; \
190  c2 = (name >> 8) & 0xff; \
191  c3 = name & 0xff; \
192  putchar( (char)c0 ); \
193  if ( c1 ) putchar( (char)c1 ); \
194  if ( c2 ) putchar( (char)c2 ); \
195  if ( c3 ) putchar( (char)c3 ); \
196  if ( crlf ) \
197    putchar( '\n' ); \
198}
199
[b8cda5a6]200#ifndef build_time
[ac7d5ef0]201#define build_time( TB, MON, DAY, YR, HR, MIN, SEC, TK ) \
202  { (TB)->year   = YR;  \
203    (TB)->month  = MON; \
204    (TB)->day    = DAY; \
205    (TB)->hour   = HR;  \
206    (TB)->minute = MIN; \
207    (TB)->second = SEC; \
208    (TB)->ticks  = TK; }
[b8cda5a6]209#endif
[ac7d5ef0]210
211#define task_number( tid ) \
[e6d4b1d]212  ( rtems_get_index( tid ) - \
[458bd34]213     rtems_configuration_get_rtems_api_configuration()->number_of_initialization_tasks )
[ac7d5ef0]214
215static inline rtems_unsigned32 get_ticks_per_second( void )
216{
217  rtems_interval ticks_per_second;
218  (void) rtems_clock_get( RTEMS_CLOCK_GET_TICKS_PER_SECOND, &ticks_per_second );
219  return ticks_per_second;
220}
221
222#define TICKS_PER_SECOND get_ticks_per_second()
223
224#ifdef __cplusplus
225}
226#endif
227
228#endif
Note: See TracBrowser for help on using the repository browser.