1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright (c) 2014, STMicroelectronics International N.V.
4  */
5 #ifndef ASSERT_H
6 #define ASSERT_H
7 
8 #include <compiler.h>
9 #include <trace.h>
10 
11 void __noreturn _assert_break(void);
12 void _assert_log(const char *expr, const char *file, const int line,
13 			const char *func);
14 
15 /* assert() specs: generates a log but does not panic if NDEBUG is defined */
16 #ifdef NDEBUG
17 #define assert(expr)	do { } while (0)
18 #else
19 #define assert(expr) \
20 	do { \
21 		if (!(expr)) { \
22 			_assert_log(#expr, __FILE__, __LINE__, __func__); \
23 			_assert_break(); \
24 		} \
25 	} while (0)
26 #endif
27 
28 #define COMPILE_TIME_ASSERT(x) \
29 	do { \
30 		switch (0) { case 0: case ((x) ? 1: 0): default : break; } \
31 	} while (0)
32 
33 #endif
34