source: rtems/testsuites/support/include/tmacros.h @ 62cba156

5
Last change on this file since 62cba156 was ec84273d, checked in by Sebastian Huber <sebastian.huber@…>, on 05/27/15 at 09:43:44

score: Replace _API_Mutex_Is_locked()

Replace _API_Mutex_Is_locked() with _API_Mutex_Is_owner().

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