source: rtems/testsuites/support/include/tmacros.h @ 98c6d50

5
Last change on this file since 98c6d50 was 98c6d50, checked in by Chris Johns <chrisj@…>, on 10/19/17 at 05:39:16

testsuite: Use printk for all test output where possible.

  • Remove the printf support leaving the direct printk support configured with TESTS_USE_PRINTK and all other output goes via a buffered vsniprintf call to printk.
  • Control the test's single init for functions and global data with TEST_INIT and not CONFIGURE_INIT. They are now separate.

Updates #3170.

  • Property mode set to 100644
File size: 9.3 KB
Line 
1/**
2 * @file
3 *
4 * This include file contains macros which are useful in the RTEMS
5 * test suites.
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2014.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.org/license/LICENSE.
15 */
16
17#ifndef __TMACROS_h
18#define __TMACROS_h
19
20#include <inttypes.h>
21#include <rtems/inttypes.h>
22#include <bsp.h>    /* includes <rtems.h> */
23
24#include <ctype.h>
25#include <stdio.h>
26#include <stdlib.h>
27#include <string.h>
28#include <rtems/error.h>
29#include <rtems/test.h>
30#include <rtems/score/threaddispatch.h>
31
32#include <buffer_test_io.h>
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38#define FOREVER 1                  /* infinite loop */
39
40#ifdef TEST_INIT
41#define TEST_EXTERN
42#else
43#define TEST_EXTERN extern
44#endif
45
46/*
47 *  Check that that the dispatch disable level is proper for the
48 *  mode/state of the test.  Normally it should be 0 when in task space.
49 *
50 *  This test is only valid when in a non-SMP system.  In an smp system
51 *  another cpu may be accessing the core at any point when this core
52 *  does not have it locked.
53 */
54#if defined SMPTEST
55 #define check_dispatch_disable_level( _expect )
56#else
57 #define check_dispatch_disable_level( _expect ) \
58  do { \
59    if ( (_expect) != -1 \
60           && (((!_Thread_Dispatch_is_enabled()) == false && (_expect) != 0) \
61             || ((!_Thread_Dispatch_is_enabled()) && (_expect) == 0)) \
62    ) { \
63      printk( \
64        "\n_Thread_Dispatch_disable_level is (%i)" \
65           " not %d detected at %s:%d\n", \
66         !_Thread_Dispatch_is_enabled(), (_expect), __FILE__, __LINE__ ); \
67      FLUSH_OUTPUT(); \
68      rtems_test_exit( 1 ); \
69    } \
70  } while ( 0 )
71#endif
72
73/*
74 *  Check that that the allocator mutex is not owned by the executing thread.
75 */
76#include <rtems/score/apimutex.h>
77#define check_if_allocator_mutex_is_not_owned() \
78  do { \
79    if ( _RTEMS_Allocator_is_owner() ) { \
80      printk( \
81        "\nRTEMS Allocator Mutex is owned by executing thread " \
82          "and should not be.\n" \
83        "Detected at %s:%d\n", \
84        __FILE__, \
85        __LINE__ \
86      ); \
87      FLUSH_OUTPUT(); \
88      rtems_test_exit( 1 ); \
89    } \
90  } while ( 0 )
91
92/*
93 *  These macros properly report errors within the Classic API
94 */
95#define directive_failed( _dirstat, _failmsg )  \
96 fatal_directive_status( _dirstat, RTEMS_SUCCESSFUL, _failmsg )
97
98#define directive_failed_with_level( _dirstat, _failmsg, _level )  \
99 fatal_directive_status_with_level( \
100      _dirstat, RTEMS_SUCCESSFUL, _failmsg, _level )
101
102#define fatal_directive_status( _stat, _desired, _msg ) \
103  fatal_directive_status_with_level( _stat, _desired, _msg, 0 )
104
105#define fatal_directive_check_status_only( _stat, _desired, _msg ) \
106  do { \
107    if ( (_stat) != (_desired) ) { \
108      printf( "\n%s FAILED -- expected (%s) got (%s)\n", \
109              (_msg), rtems_status_text(_desired), rtems_status_text(_stat) ); \
110      FLUSH_OUTPUT(); \
111      rtems_test_exit( _stat ); \
112    } \
113  } while ( 0 )
114
115#define fatal_directive_status_with_level( _stat, _desired, _msg, _level ) \
116  do { \
117    check_dispatch_disable_level( _level ); \
118    check_if_allocator_mutex_is_not_owned(); \
119    fatal_directive_check_status_only( _stat, _desired, _msg ); \
120  } while ( 0 )
121
122/*
123 *  These macros properly report errors from the POSIX API
124 */
125
126#define posix_service_failed( _dirstat, _failmsg )  \
127 fatal_posix_service_status( _dirstat, 0, _failmsg )
128
129#define posix_service_failed_with_level( _dirstat, _failmsg, _level )  \
130 fatal_posix_service_status_with_level( _dirstat, 0, _failmsg, _level )
131
132#define fatal_posix_service_status_errno( _stat, _desired, _msg ) \
133  if ( (_stat != -1) && (errno) != (_desired) ) { \
134    long statx = _stat; \
135    check_dispatch_disable_level( 0 ); \
136    check_if_allocator_mutex_is_not_owned(); \
137    printf( "\n%s FAILED -- expected (%d - %s) got (%ld %d - %s)\n", \
138            (_msg), _desired, strerror(_desired), \
139            statx, errno, strerror(errno) ); \
140    FLUSH_OUTPUT(); \
141    rtems_test_exit( _stat ); \
142  }
143
144#define fatal_posix_service_status( _stat, _desired, _msg ) \
145  fatal_posix_service_status_with_level( _stat, _desired, _msg, 0 )
146
147#define fatal_posix_service_status_with_level( _stat, _desired, _msg, _level ) \
148  do { \
149    check_dispatch_disable_level( _level ); \
150    check_if_allocator_mutex_is_not_owned(); \
151    if ( (_stat) != (_desired) ) { \
152      printf( "\n%s FAILED -- expected (%d - %s) got (%d - %s)\n", \
153              (_msg), _desired, strerror(_desired), _stat, strerror(_stat) ); \
154      printf( "\n FAILED -- errno (%d - %s)\n", \
155              errno, strerror(errno) ); \
156      FLUSH_OUTPUT(); \
157      rtems_test_exit( _stat ); \
158    } \
159  } while ( 0 )
160
161/*
162 * This macro evaluates the semaphore id returned.
163 */
164#define fatal_posix_sem( _ptr, _msg ) \
165  if ( (_ptr != SEM_FAILED) ) { \
166    check_dispatch_disable_level( 0 ); \
167    printf( "\n%s FAILED -- expected (-1) got (%p - %d/%s)\n", \
168            (_msg), _ptr, errno, strerror(errno) ); \
169    FLUSH_OUTPUT(); \
170    rtems_test_exit( -1 ); \
171  }
172
173/*
174 * This macro evaluates the message queue id returned.
175 */
176#define fatal_posix_mqd( _ptr, _msg ) \
177  if ( (_ptr != (mqd_t) -1) ) { \
178    check_dispatch_disable_level( 0 ); \
179    printf( "\n%s FAILED -- expected (-1) got (%" PRId32 " - %d/%s)\n", \
180            (_msg), _ptr, errno, strerror(errno) ); \
181    FLUSH_OUTPUT(); \
182    rtems_test_exit( -1 ); \
183  }
184
185/*
186 *  Generic integer version of the error reporting
187 */
188
189#define int_service_failed( _dirstat, _failmsg )  \
190 fatal_int_service_status( _dirstat, RTEMS_SUCCESSFUL, _failmsg )
191
192#define int_service_failed_with_level( _dirstat, _failmsg, _level )  \
193 fatal_int_service_status_with_level( \
194      _dirstat, RTEMS_SUCCESSFUL, _failmsg, _level )
195
196#define fatal_int_service_status( _stat, _desired, _msg ) \
197  fatal_int_service_status_with_level( _stat, _desired, _msg, 0 )
198
199#define fatal_int_service_status_with_level( _stat, _desired, _msg, _level ) \
200  do { \
201    check_dispatch_disable_level( _level ); \
202    if ( (_stat) != (_desired) ) { \
203      printf( "\n%s FAILED -- expected (%d) got (%d)\n", \
204              (_msg), (_desired), (_stat) ); \
205      FLUSH_OUTPUT(); \
206      rtems_test_exit( _stat ); \
207    } \
208  } while ( 0 )
209
210
211/*
212 *  Print the time
213 */
214
215#define sprint_time(_str, _s1, _tb, _s2) \
216  do { \
217    sprintf( (_str), "%s%02d:%02d:%02d   %02d/%02d/%04d%s", \
218       _s1, (_tb)->hour, (_tb)->minute, (_tb)->second, \
219       (_tb)->month, (_tb)->day, (_tb)->year, _s2 ); \
220  } while ( 0 )
221
222#define print_time(_s1, _tb, _s2) \
223  do { \
224    printf( "%s%02" PRIu32 ":%02" PRIu32 ":%02" PRIu32 "   %02" PRIu32 "/%02" PRIu32 "/%04" PRIu32 "%s", \
225       _s1, (_tb)->hour, (_tb)->minute, (_tb)->second, \
226       (_tb)->month, (_tb)->day, (_tb)->year, _s2 ); \
227  } while ( 0 )
228
229#define put_dot( _c ) \
230  do { \
231    putchar( _c ); \
232    FLUSH_OUTPUT(); \
233  } while ( 0 )
234
235#define new_line  puts( "" )
236
237#define puts_nocr printf
238
239#ifdef RTEMS_TEST_NO_PAUSE
240#define rtems_test_pause() \
241    do { \
242      printf( "<pause>\n" ); \
243      FLUSH_OUTPUT(); \
244  } while ( 0 )
245
246#define rtems_test_pause_and_screen_number( _screen ) \
247  do { \
248    printf( "<pause - screen %d>\n", (_screen) ); \
249    FLUSH_OUTPUT(); \
250  } while ( 0 )
251#else
252#define rtems_test_pause() \
253  do { \
254    char buffer[ 80 ]; \
255    printf( "<pause>" ); \
256    FLUSH_OUTPUT(); \
257    gets( buffer ); \
258    puts( "" ); \
259  } while ( 0 )
260
261#define rtems_test_pause_and_screen_number( _screen ) \
262  do { \
263    char buffer[ 80 ]; \
264    printf( "<pause - screen %d>", (_screen) ); \
265    FLUSH_OUTPUT(); \
266    gets( buffer ); \
267    puts( "" ); \
268  } while ( 0 )
269#endif
270
271#define put_name( name, crlf ) \
272{ int c0, c1, c2, c3; \
273  c0 = (name >> 24) & 0xff; \
274  c1 = (name >> 16) & 0xff; \
275  c2 = (name >> 8) & 0xff; \
276  c3 = name & 0xff; \
277  putchar( (isprint(c0)) ? c0 : '*' ); \
278  if ( c1 ) putchar( (isprint(c1)) ? c1 : '*' ); \
279  if ( c2 ) putchar( (isprint(c2)) ? c2 : '*' ); \
280  if ( c3 ) putchar( (isprint(c3)) ? c3 : '*' ); \
281  if ( crlf ) \
282    putchar( '\n' ); \
283}
284
285#ifndef build_time
286#define build_time( TB, MON, DAY, YR, HR, MIN, SEC, TK ) \
287  { (TB)->year   = YR;  \
288    (TB)->month  = MON; \
289    (TB)->day    = DAY; \
290    (TB)->hour   = HR;  \
291    (TB)->minute = MIN; \
292    (TB)->second = SEC; \
293    (TB)->ticks  = TK; }
294#endif
295
296#define task_number( tid ) \
297  ( rtems_object_id_get_index( tid ) - \
298      rtems_configuration_get_rtems_api_configuration()-> \
299        number_of_initialization_tasks )
300
301#define rtems_test_assert(__exp) \
302  do { \
303    if (!(__exp)) { \
304      printf( "%s: %d %s\n", __FILE__, __LINE__, #__exp ); \
305      rtems_test_exit(0); \
306    } \
307  } while (0)
308
309/**
310 * This assists in clearly disabling warnings on GCC in certain very
311 * specific cases.
312 *
313 * + -Wnon-null - If a method is declared as never having a NULL first
314 *   parameter. We need to explicitly disable this compiler warning to make
315 *   the code warning free.
316 */
317#ifdef __GNUC__
318  #define COMPILER_DIAGNOSTIC_SETTINGS_PUSH _Pragma("GCC diagnostic push")
319  #define COMPILER_DIAGNOSTIC_SETTINGS_POP _Pragma("GCC diagnostic pop")
320  #define COMPILER_DIAGNOSTIC_SETTINGS_DISABLE_NONNULL \
321    _Pragma("GCC diagnostic ignored \"-Wnonnull\"")
322#else
323  #define COMPILER_DIAGNOSTIC_SETTINGS_PUSH
324  #define COMPILER_DIAGNOSTIC_SETTINGS_POP
325  #define COMPILER_DIAGNOSTIC_SETTINGS_DISABLE_NONNULL
326#endif
327
328#ifdef __cplusplus
329}
330#endif
331
332#endif
Note: See TracBrowser for help on using the repository browser.