Tizen RT Libs&Environment  v1.0 D5
assert.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright 2016 Samsung Electronics All Rights Reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing,
12  * software distributed under the License is distributed on an
13  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
14  * either express or implied. See the License for the specific
15  * language governing permissions and limitations under the License.
16  *
17  ****************************************************************************/
18 /****************************************************************************
19  * include/assert.h
20  *
21  * Copyright (C) 2007-2009, 2011-2013 Gregory Nutt. All rights reserved.
22  * Author: Gregory Nutt <gnutt@nuttx.org>
23  *
24  * Redistribution and use in source and binary forms, with or without
25  * modification, are permitted provided that the following conditions
26  * are met:
27  *
28  * 1. Redistributions of source code must retain the above copyright
29  * notice, this list of conditions and the following disclaimer.
30  * 2. Redistributions in binary form must reproduce the above copyright
31  * notice, this list of conditions and the following disclaimer in
32  * the documentation and/or other materials provided with the
33  * distribution.
34  * 3. Neither the name NuttX nor the names of its contributors may be
35  * used to endorse or promote products derived from this software
36  * without specific prior written permission.
37  *
38  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
39  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
40  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
41  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
42  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
43  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
44  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
45  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
46  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
47  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
48  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49  * POSSIBILITY OF SUCH DAMAGE.
50  *
51  ****************************************************************************/
60 
63 #ifndef __INCLUDE_ASSERT_H
64 #define __INCLUDE_ASSERT_H
65 
66 /****************************************************************************
67  * Included Files
68  ****************************************************************************/
69 
70 #include <tinyara/compiler.h>
71 #include <stdint.h>
72 
73 /****************************************************************************
74  * Pre-processor Definitions
75  ****************************************************************************/
76 
77 /* Macro Name: ASSERT, VERIFY, et al. */
78 
79 #undef ASSERT /* Assert if the condition is not true */
80 #undef VERIFY /* Assert if a function returns a negative value */
81 #undef DEBUGASSERT /* Like ASSERT, but only if CONFIG_DEBUG is defined */
82 #undef DEBUGVERIFY /* Like VERIFY, but only if CONFIG_DEBUG is defined */
83 #undef PANIC /* Unconditional abort */
84 
85 #ifdef CONFIG_HAVE_FILENAME
86 
87 #define ASSERT(f) \
88  { if (!(f)) up_assert((const uint8_t *)__FILE__, (int)__LINE__); }
89 
90 #define VERIFY(f) \
91  { if ((f) < 0) up_assert((const uint8_t *)__FILE__, (int)__LINE__); }
92 
93 #define PANIC() \
94  up_assert((const uint8_t *)__FILE__, (int)__LINE__)
95 
96 #ifdef CONFIG_DEBUG
97 
98 #define DEBUGASSERT(f) \
99  { if (!(f)) up_assert((const uint8_t *)__FILE__, (int)__LINE__); }
100 
101 #define DEBUGVERIFY(f) \
102  { if ((f) < 0) up_assert((const uint8_t *)__FILE__, (int)__LINE__); }
103 
104 #define DEBUGPANIC() \
105  up_assert((const uint8_t *)__FILE__, (int)__LINE__)
106 
107 #else
108 
109 #define DEBUGASSERT(f)
110 #define DEBUGVERIFY(f) ((void)(f))
111 #define DEBUGPANIC()
112 
113 #endif /* CONFIG_DEBUG */
114 
115 #else
116 
124 #define ASSERT(f) { if (!(f)) up_assert(); }
125 
132 #define VERIFY(f) { if ((f) < 0) up_assert(); }
133 
139 #define PANIC() up_assert()
140 
141 #ifdef CONFIG_DEBUG
142 
150 #define DEBUGASSERT(f) { if (!(f)) up_assert(); }
151 
158 #define DEBUGVERIFY(f) { if ((f) < 0) up_assert(); }
159 
165 #define DEBUGPANIC() up_assert()
166 
167 #else
168 
169 #define DEBUGASSERT(f)
170 #define DEBUGVERIFY(f) ((void)(f))
171 #define DEBUGPANIC()
172 
173 #endif /* CONFIG_DEBUG */
174 #endif
175 
181 #ifndef assert
182 #define assert ASSERT
183 #endif
184 
185 /****************************************************************************
186  * Included Files
187  ****************************************************************************/
188 
189 /****************************************************************************
190  * Public Data
191  ****************************************************************************/
192 
193 #ifdef __cplusplus
194 #define EXTERN extern "C"
195 extern "C" {
196 #else
197 #define EXTERN extern
198 #endif
199 
200 /****************************************************************************
201  * Public Function Prototypes
202  ****************************************************************************/
203 
204 #ifdef CONFIG_HAVE_FILENAME
205 void up_assert(FAR const uint8_t *filename, int linenum) noreturn_function;
206 #else
207 void up_assert(void) noreturn_function;
208 #endif
209 
214 #undef EXTERN
215 #ifdef __cplusplus
216 }
217 #endif
218 
219 #endif /* __INCLUDE_ASSERT_H */
220 //end of ASSERT_KERNEL