source: rtems/cpukit/include/rtems/score/assert.h @ 7ebce359

Last change on this file since 7ebce359 was 7ebce359, checked in by Joel Sherrill <joel@…>, on 02/16/22 at 21:15:58

cpukit/include/rtems/score/[a-r]*.h: Change license to BSD-2

Updates #3053.

  • Property mode set to 100644
File size: 4.8 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/**
4 * @file
5 *
6 * @ingroup RTEMSScoreAssert
7 *
8 * @brief This header file provides the interfaces of the
9 *   @ref RTEMSScoreAssert.
10 */
11
12/*
13 * Copyright (c) 2013-2014 embedded brains GmbH.  All rights reserved.
14 *
15 *  embedded brains GmbH
16 *  Dornierstr. 4
17 *  82178 Puchheim
18 *  Germany
19 *  <rtems@embedded-brains.de>
20 *
21 * Redistribution and use in source and binary forms, with or without
22 * modification, are permitted provided that the following conditions
23 * are met:
24 * 1. Redistributions of source code must retain the above copyright
25 *    notice, this list of conditions and the following disclaimer.
26 * 2. Redistributions in binary form must reproduce the above copyright
27 *    notice, this list of conditions and the following disclaimer in the
28 *    documentation and/or other materials provided with the distribution.
29 *
30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
31 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
34 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
35 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
36 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
37 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
38 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
39 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
40 * POSSIBILITY OF SUCH DAMAGE.
41 */
42
43#ifndef _RTEMS_SCORE_ASSERT_H
44#define _RTEMS_SCORE_ASSERT_H
45
46#include <rtems/score/basedefs.h>
47
48/**
49 * @defgroup RTEMSScoreAssert Assert Handler
50 *
51 * @ingroup RTEMSScore
52 *
53 * @brief This group contains the Assert Handler implementation.
54 *
55 * @{
56 */
57
58#if defined( RTEMS_DEBUG )
59  #include <assert.h>
60#endif
61
62#ifdef __cplusplus
63extern "C" {
64#endif /* __cplusplus */
65
66/**
67 * @brief Assertion similar to assert() controlled via RTEMS_DEBUG instead of
68 *   NDEBUG and static analysis runs.
69 */
70#if defined( RTEMS_DEBUG ) || defined( RTEMS_STATIC_ANALYSIS )
71
72  /**
73   * @brief Macro with method name used in assert output
74   *
75   * Given the variations in compilers and standards, we have to poke a bit.
76   *
77   * @note This is based on the code in newlib's assert.h.
78   */
79  #ifndef __RTEMS_ASSERT_FUNCTION
80    /* Use g++'s demangled names in C++.  */
81    #if defined __cplusplus && defined __GNUC__
82      #define __RTEMS_ASSERT_FUNCTION __PRETTY_FUNCTION__
83
84    /* C99 requires the use of __func__.  */
85    #elif __STDC_VERSION__ >= 199901L
86      #define __RTEMS_ASSERT_FUNCTION __func__
87
88    /* Older versions of gcc don't have __func__ but can use __FUNCTION__.  */
89    #elif __GNUC__ >= 2
90      #define __RTEMS_ASSERT_FUNCTION __FUNCTION__
91
92    /* failed to detect __func__ support.  */
93    #else
94      #define __RTEMS_ASSERT_FUNCTION ((char *) 0)
95    #endif
96  #endif /* !__RTEMS_ASSERT_FUNCTION */
97
98  #if !defined( RTEMS_SCHEDSIM )
99    /* normal build is newlib. */
100
101    #define _Assert( _e ) \
102       ( ( _e ) ? \
103         ( void ) 0 : \
104           __assert_func( __FILE__, __LINE__, __RTEMS_ASSERT_FUNCTION, #_e ) )
105
106  #elif defined(__linux__)
107    /* Scheduler simulator has only beed tested on glibc. */
108    #define _Assert( _e ) \
109     ( ( _e ) ? \
110       ( void ) 0 : \
111         __assert_fail( #_e, __FILE__, __LINE__, __RTEMS_ASSERT_FUNCTION ) )
112  #else
113    #error "Implement RTEMS assert support for this C Library"
114  #endif
115
116#else
117  #define _Assert( _e ) ( ( void ) 0 )
118#endif
119
120/**
121 * @brief Assert if unused return value is equal.
122 *
123 * Assert whether @a _var and @a _val are equal and ensure @a _var is
124 * marked as used when not building for debug.
125 *
126 * @param _var The return value to be checked.
127 * @param _val Indicates what @a _var is supposed to be.
128 */
129#define _Assert_Unused_variable_equals(_var,_val) \
130        do { \
131          _Assert((_var) == (_val)); \
132          (void) (_var); \
133        } while (0)
134
135/**
136 * @brief Assert if unused return value is not equal.
137 *
138 * Assert whether @a _var and @a _val are not equal and ensure @a _var
139 * is marked as used when not building for debug.
140 *
141 * @param _var The return value to be checked.
142 * @param _val Indicates what @a _var is not supposed to be.
143 */
144#define _Assert_Unused_variable_unequal(_var,_val) \
145         do { \
146          _Assert((_var) != (_val)); \
147           (void) (_var); \
148        } while (0)
149
150/**
151 * @brief Returns true if thread dispatching is allowed.
152 *
153 * Thread dispatching can be repressed via _Thread_Disable_dispatch() or
154 * _ISR_Local_disable().
155 */
156#if defined( RTEMS_DEBUG )
157  bool _Debug_Is_thread_dispatching_allowed( void );
158#endif
159
160#ifdef __cplusplus
161}
162#endif /* __cplusplus */
163
164/** @} */
165
166#endif /* _RTEMS_SCORE_ASSERT_H */
Note: See TracBrowser for help on using the repository browser.