Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | /* * Copyright (c) 2011-2014 Wind River Systems, Inc. * * SPDX-License-Identifier: Apache-2.0 */ #ifndef ZEPHYR_INCLUDE_SYS___ASSERT_H_ #define ZEPHYR_INCLUDE_SYS___ASSERT_H_ #include <stdbool.h> #include <zephyr/toolchain.h> #ifdef CONFIG_ASSERT #ifndef __ASSERT_ON #define __ASSERT_ON CONFIG_ASSERT_LEVEL #endif #endif #ifdef CONFIG_FORCE_NO_ASSERT #undef __ASSERT_ON #define __ASSERT_ON 0 #endif #ifdef __cplusplus extern "C" { #endif /* Wrapper around printk to avoid including printk.h in assert.h */ void assert_print(const char *fmt, ...); #ifdef __cplusplus } #endif #if defined(CONFIG_ASSERT_VERBOSE) #define __ASSERT_PRINT(fmt, ...) assert_print(fmt, ##__VA_ARGS__) #else /* CONFIG_ASSERT_VERBOSE */ #define __ASSERT_PRINT(fmt, ...) #endif /* CONFIG_ASSERT_VERBOSE */ #ifdef CONFIG_ASSERT_NO_MSG_INFO #define __ASSERT_MSG_INFO(fmt, ...) #else /* CONFIG_ASSERT_NO_MSG_INFO */ #define __ASSERT_MSG_INFO(fmt, ...) __ASSERT_PRINT("\t" fmt "\n", ##__VA_ARGS__) #endif /* CONFIG_ASSERT_NO_MSG_INFO */ #if !defined(CONFIG_ASSERT_NO_COND_INFO) && !defined(CONFIG_ASSERT_NO_FILE_INFO) #define __ASSERT_LOC(test) \ __ASSERT_PRINT("ASSERTION FAIL [%s] @ %s:%d\n", \ Z_STRINGIFY(test), \ __FILE__, __LINE__) #endif #if defined(CONFIG_ASSERT_NO_COND_INFO) && !defined(CONFIG_ASSERT_NO_FILE_INFO) #define __ASSERT_LOC(test) \ __ASSERT_PRINT("ASSERTION FAIL @ %s:%d\n", \ __FILE__, __LINE__) #endif #if !defined(CONFIG_ASSERT_NO_COND_INFO) && defined(CONFIG_ASSERT_NO_FILE_INFO) #define __ASSERT_LOC(test) \ __ASSERT_PRINT("ASSERTION FAIL [%s]\n", \ Z_STRINGIFY(test)) #endif #if defined(CONFIG_ASSERT_NO_COND_INFO) && defined(CONFIG_ASSERT_NO_FILE_INFO) #define __ASSERT_LOC(test) \ __ASSERT_PRINT("ASSERTION FAIL\n") #endif #ifdef __ASSERT_ON #if (__ASSERT_ON < 0) || (__ASSERT_ON > 2) #error "Invalid __ASSERT() level: must be between 0 and 2" #endif #if __ASSERT_ON #ifdef __cplusplus extern "C" { #endif #ifdef CONFIG_ASSERT_NO_FILE_INFO void assert_post_action(void); #define __ASSERT_POST_ACTION() assert_post_action() #else /* CONFIG_ASSERT_NO_FILE_INFO */ void assert_post_action(const char *file, unsigned int line); #define __ASSERT_POST_ACTION() assert_post_action(__FILE__, __LINE__) #endif /* CONFIG_ASSERT_NO_FILE_INFO */ #ifdef __cplusplus } #endif #define __ASSERT_NO_MSG(test) \ do { \ if (!(test)) { \ __ASSERT_LOC(test); \ __ASSERT_POST_ACTION(); \ } \ } while (false) #define __ASSERT(test, fmt, ...) \ do { \ if (!(test)) { \ __ASSERT_LOC(test); \ __ASSERT_MSG_INFO(fmt, ##__VA_ARGS__); \ __ASSERT_POST_ACTION(); \ } \ } while (false) #define __ASSERT_EVAL(expr1, expr2, test, fmt, ...) \ do { \ expr2; \ __ASSERT(test, fmt, ##__VA_ARGS__); \ } while (false) #if (__ASSERT_ON == 1) #warning "__ASSERT() statements are ENABLED" #endif #else #define __ASSERT(test, fmt, ...) { } #define __ASSERT_EVAL(expr1, expr2, test, fmt, ...) expr1 #define __ASSERT_NO_MSG(test) { } #endif #else #define __ASSERT(test, fmt, ...) { } #define __ASSERT_EVAL(expr1, expr2, test, fmt, ...) expr1 #define __ASSERT_NO_MSG(test) { } #endif #endif /* ZEPHYR_INCLUDE_SYS___ASSERT_H_ */ |