robo 8080
/
BLE_TEST_konashi
konashi/SBBLEのテスト
Fork of BLE_LoopbackUART by
nRF51822/common/assertion.h@5:61109bce11fe, 2014-08-16 (annotated)
- Committer:
- robo8080
- Date:
- Sat Aug 16 02:10:08 2014 +0000
- Revision:
- 5:61109bce11fe
test1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
robo8080 | 5:61109bce11fe | 1 | /**************************************************************************/ |
robo8080 | 5:61109bce11fe | 2 | /*! |
robo8080 | 5:61109bce11fe | 3 | @file assertion.h |
robo8080 | 5:61109bce11fe | 4 | @author hathach (tinyusb.org) |
robo8080 | 5:61109bce11fe | 5 | |
robo8080 | 5:61109bce11fe | 6 | @section LICENSE |
robo8080 | 5:61109bce11fe | 7 | |
robo8080 | 5:61109bce11fe | 8 | Software License Agreement (BSD License) |
robo8080 | 5:61109bce11fe | 9 | |
robo8080 | 5:61109bce11fe | 10 | Copyright (c) 2013, K. Townsend (microBuilder.eu) |
robo8080 | 5:61109bce11fe | 11 | All rights reserved. |
robo8080 | 5:61109bce11fe | 12 | |
robo8080 | 5:61109bce11fe | 13 | Redistribution and use in source and binary forms, with or without |
robo8080 | 5:61109bce11fe | 14 | modification, are permitted provided that the following conditions are met: |
robo8080 | 5:61109bce11fe | 15 | 1. Redistributions of source code must retain the above copyright |
robo8080 | 5:61109bce11fe | 16 | notice, this list of conditions and the following disclaimer. |
robo8080 | 5:61109bce11fe | 17 | 2. Redistributions in binary form must reproduce the above copyright |
robo8080 | 5:61109bce11fe | 18 | notice, this list of conditions and the following disclaimer in the |
robo8080 | 5:61109bce11fe | 19 | documentation and/or other materials provided with the distribution. |
robo8080 | 5:61109bce11fe | 20 | 3. Neither the name of the copyright holders nor the |
robo8080 | 5:61109bce11fe | 21 | names of its contributors may be used to endorse or promote products |
robo8080 | 5:61109bce11fe | 22 | derived from this software without specific prior written permission. |
robo8080 | 5:61109bce11fe | 23 | |
robo8080 | 5:61109bce11fe | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY |
robo8080 | 5:61109bce11fe | 25 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
robo8080 | 5:61109bce11fe | 26 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
robo8080 | 5:61109bce11fe | 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY |
robo8080 | 5:61109bce11fe | 28 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
robo8080 | 5:61109bce11fe | 29 | INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
robo8080 | 5:61109bce11fe | 30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND |
robo8080 | 5:61109bce11fe | 31 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
robo8080 | 5:61109bce11fe | 32 | INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS |
robo8080 | 5:61109bce11fe | 33 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
robo8080 | 5:61109bce11fe | 34 | */ |
robo8080 | 5:61109bce11fe | 35 | /**************************************************************************/ |
robo8080 | 5:61109bce11fe | 36 | |
robo8080 | 5:61109bce11fe | 37 | /** \file |
robo8080 | 5:61109bce11fe | 38 | * \brief TBD |
robo8080 | 5:61109bce11fe | 39 | * |
robo8080 | 5:61109bce11fe | 40 | * \note TBD |
robo8080 | 5:61109bce11fe | 41 | */ |
robo8080 | 5:61109bce11fe | 42 | |
robo8080 | 5:61109bce11fe | 43 | /** \ingroup TBD |
robo8080 | 5:61109bce11fe | 44 | * \defgroup TBD |
robo8080 | 5:61109bce11fe | 45 | * \brief TBD |
robo8080 | 5:61109bce11fe | 46 | * |
robo8080 | 5:61109bce11fe | 47 | * @{ |
robo8080 | 5:61109bce11fe | 48 | */ |
robo8080 | 5:61109bce11fe | 49 | |
robo8080 | 5:61109bce11fe | 50 | #ifndef _ASSERTION_H_ |
robo8080 | 5:61109bce11fe | 51 | #define _ASSERTION_H_ |
robo8080 | 5:61109bce11fe | 52 | |
robo8080 | 5:61109bce11fe | 53 | #include "projectconfig.h" |
robo8080 | 5:61109bce11fe | 54 | |
robo8080 | 5:61109bce11fe | 55 | #ifdef __cplusplus |
robo8080 | 5:61109bce11fe | 56 | extern "C" |
robo8080 | 5:61109bce11fe | 57 | { |
robo8080 | 5:61109bce11fe | 58 | #endif |
robo8080 | 5:61109bce11fe | 59 | |
robo8080 | 5:61109bce11fe | 60 | static inline void debugger_breakpoint(void) ATTR_ALWAYS_INLINE; |
robo8080 | 5:61109bce11fe | 61 | static inline void debugger_breakpoint(void) |
robo8080 | 5:61109bce11fe | 62 | { |
robo8080 | 5:61109bce11fe | 63 | #ifndef _TEST_ |
robo8080 | 5:61109bce11fe | 64 | __asm("BKPT #0\n"); |
robo8080 | 5:61109bce11fe | 65 | #endif |
robo8080 | 5:61109bce11fe | 66 | } |
robo8080 | 5:61109bce11fe | 67 | |
robo8080 | 5:61109bce11fe | 68 | //--------------------------------------------------------------------+ |
robo8080 | 5:61109bce11fe | 69 | // Compile-time Assert |
robo8080 | 5:61109bce11fe | 70 | //--------------------------------------------------------------------+ |
robo8080 | 5:61109bce11fe | 71 | #if defined __COUNTER__ && __COUNTER__ != __COUNTER__ |
robo8080 | 5:61109bce11fe | 72 | #define _ASSERT_COUNTER __COUNTER__ |
robo8080 | 5:61109bce11fe | 73 | #else |
robo8080 | 5:61109bce11fe | 74 | #define _ASSERT_COUNTER __LINE__ |
robo8080 | 5:61109bce11fe | 75 | #endif |
robo8080 | 5:61109bce11fe | 76 | |
robo8080 | 5:61109bce11fe | 77 | #define ASSERT_STATIC(const_expr, message) enum { XSTRING_CONCAT_(static_assert_, _ASSERT_COUNTER) = 1/(!!(const_expr)) } |
robo8080 | 5:61109bce11fe | 78 | |
robo8080 | 5:61109bce11fe | 79 | //--------------------------------------------------------------------+ |
robo8080 | 5:61109bce11fe | 80 | // Assert Helper |
robo8080 | 5:61109bce11fe | 81 | //--------------------------------------------------------------------+ |
robo8080 | 5:61109bce11fe | 82 | //#ifndef _TEST_ |
robo8080 | 5:61109bce11fe | 83 | // #define ASSERT_MESSAGE(format, ...)\ |
robo8080 | 5:61109bce11fe | 84 | // _PRINTF("Assert at %s: %s: %d: " format "\n", __BASE_FILE__, __PRETTY_FUNCTION__, __LINE__, __VA_ARGS__) |
robo8080 | 5:61109bce11fe | 85 | //#else |
robo8080 | 5:61109bce11fe | 86 | // #define ASSERT_MESSAGE(format, ...)\ |
robo8080 | 5:61109bce11fe | 87 | // _PRINTF("%d:note: Assert " format "\n", __LINE__, __VA_ARGS__) |
robo8080 | 5:61109bce11fe | 88 | //#endif |
robo8080 | 5:61109bce11fe | 89 | |
robo8080 | 5:61109bce11fe | 90 | #if CFG_DEBUG == 3 |
robo8080 | 5:61109bce11fe | 91 | #define ASSERT_MESSAGE(format, ...) debugger_breakpoint() |
robo8080 | 5:61109bce11fe | 92 | #elif CFG_DEBUG == 2 |
robo8080 | 5:61109bce11fe | 93 | #define ASSERT_MESSAGE(format, ...) printf("Assert at %s: %s: %d: " format "\n", __BASE_FILE__, __PRETTY_FUNCTION__, __LINE__, __VA_ARGS__) |
robo8080 | 5:61109bce11fe | 94 | #else |
robo8080 | 5:61109bce11fe | 95 | #define ASSERT_MESSAGE(format, ...) |
robo8080 | 5:61109bce11fe | 96 | #endif |
robo8080 | 5:61109bce11fe | 97 | |
robo8080 | 5:61109bce11fe | 98 | #define ASSERT_ERROR_HANDLER(x, para) \ |
robo8080 | 5:61109bce11fe | 99 | return (x) |
robo8080 | 5:61109bce11fe | 100 | |
robo8080 | 5:61109bce11fe | 101 | #define ASSERT_DEFINE_WITH_HANDLER(error_handler, handler_para, setup_statement, condition, error, format, ...) \ |
robo8080 | 5:61109bce11fe | 102 | do{\ |
robo8080 | 5:61109bce11fe | 103 | setup_statement;\ |
robo8080 | 5:61109bce11fe | 104 | if (!(condition)) {\ |
robo8080 | 5:61109bce11fe | 105 | ASSERT_MESSAGE(format, __VA_ARGS__);\ |
robo8080 | 5:61109bce11fe | 106 | error_handler(error, handler_para);\ |
robo8080 | 5:61109bce11fe | 107 | }\ |
robo8080 | 5:61109bce11fe | 108 | }while(0) |
robo8080 | 5:61109bce11fe | 109 | |
robo8080 | 5:61109bce11fe | 110 | #define ASSERT_DEFINE(...) ASSERT_DEFINE_WITH_HANDLER(ASSERT_ERROR_HANDLER, NULL, __VA_ARGS__) |
robo8080 | 5:61109bce11fe | 111 | |
robo8080 | 5:61109bce11fe | 112 | //--------------------------------------------------------------------+ |
robo8080 | 5:61109bce11fe | 113 | // error_t Status Assert TODO use ASSERT_DEFINE |
robo8080 | 5:61109bce11fe | 114 | //--------------------------------------------------------------------+ |
robo8080 | 5:61109bce11fe | 115 | #define ASSERT_STATUS_MESSAGE(sts, message) \ |
robo8080 | 5:61109bce11fe | 116 | ASSERT_DEFINE(error_t status = (error_t)(sts),\ |
robo8080 | 5:61109bce11fe | 117 | ERROR_NONE == status, status, "%s: %s", ErrorStr[status], message) |
robo8080 | 5:61109bce11fe | 118 | |
robo8080 | 5:61109bce11fe | 119 | #define ASSERT_STATUS(sts) \ |
robo8080 | 5:61109bce11fe | 120 | ASSERT_DEFINE(error_t status = (error_t)(sts),\ |
robo8080 | 5:61109bce11fe | 121 | ERROR_NONE == status, status, "error = %d", status) |
robo8080 | 5:61109bce11fe | 122 | |
robo8080 | 5:61109bce11fe | 123 | #define ASSERT_STATUS_RET_VOID(sts) \ |
robo8080 | 5:61109bce11fe | 124 | ASSERT_DEFINE(error_t status = (error_t)(sts),\ |
robo8080 | 5:61109bce11fe | 125 | ERROR_NONE == status, (void) 0, "error = %d", status) |
robo8080 | 5:61109bce11fe | 126 | |
robo8080 | 5:61109bce11fe | 127 | //--------------------------------------------------------------------+ |
robo8080 | 5:61109bce11fe | 128 | // Logical Assert |
robo8080 | 5:61109bce11fe | 129 | //--------------------------------------------------------------------+ |
robo8080 | 5:61109bce11fe | 130 | #define ASSERT(...) ASSERT_TRUE(__VA_ARGS__) |
robo8080 | 5:61109bce11fe | 131 | #define ASSERT_TRUE(condition , error) ASSERT_DEFINE( , (condition), error, "%s", "evaluated to false") |
robo8080 | 5:61109bce11fe | 132 | #define ASSERT_FALSE(condition , error) ASSERT_DEFINE( ,!(condition), error, "%s", "evaluated to true") |
robo8080 | 5:61109bce11fe | 133 | |
robo8080 | 5:61109bce11fe | 134 | //--------------------------------------------------------------------+ |
robo8080 | 5:61109bce11fe | 135 | // Pointer Assert |
robo8080 | 5:61109bce11fe | 136 | //--------------------------------------------------------------------+ |
robo8080 | 5:61109bce11fe | 137 | #define ASSERT_PTR(...) ASSERT_PTR_NOT_NULL(__VA_ARGS__) |
robo8080 | 5:61109bce11fe | 138 | #define ASSERT_PTR_NOT_NULL(pointer, error) ASSERT_DEFINE( , NULL != (pointer), error, "%s", "pointer is NULL") |
robo8080 | 5:61109bce11fe | 139 | #define ASSERT_PTR_NULL(pointer, error) ASSERT_DEFINE( , NULL == (pointer), error, "%s", "pointer is not NULL") |
robo8080 | 5:61109bce11fe | 140 | |
robo8080 | 5:61109bce11fe | 141 | //--------------------------------------------------------------------+ |
robo8080 | 5:61109bce11fe | 142 | // Integral Assert |
robo8080 | 5:61109bce11fe | 143 | //--------------------------------------------------------------------+ |
robo8080 | 5:61109bce11fe | 144 | #define ASSERT_XXX_EQUAL(type_format, expected, actual, error) \ |
robo8080 | 5:61109bce11fe | 145 | ASSERT_DEFINE(\ |
robo8080 | 5:61109bce11fe | 146 | uint32_t exp = (expected); uint32_t act = (actual),\ |
robo8080 | 5:61109bce11fe | 147 | exp==act,\ |
robo8080 | 5:61109bce11fe | 148 | error,\ |
robo8080 | 5:61109bce11fe | 149 | "expected " type_format ", actual " type_format, exp, act) |
robo8080 | 5:61109bce11fe | 150 | |
robo8080 | 5:61109bce11fe | 151 | #define ASSERT_XXX_WITHIN(type_format, lower, upper, actual, error) \ |
robo8080 | 5:61109bce11fe | 152 | ASSERT_DEFINE(\ |
robo8080 | 5:61109bce11fe | 153 | uint32_t low = (lower); uint32_t up = (upper); uint32_t act = (actual),\ |
robo8080 | 5:61109bce11fe | 154 | (low <= act) && (act <= up),\ |
robo8080 | 5:61109bce11fe | 155 | error,\ |
robo8080 | 5:61109bce11fe | 156 | "expected within " type_format " - " type_format ", actual " type_format, low, up, act) |
robo8080 | 5:61109bce11fe | 157 | |
robo8080 | 5:61109bce11fe | 158 | //--------------------------------------------------------------------+ |
robo8080 | 5:61109bce11fe | 159 | // Integer Assert |
robo8080 | 5:61109bce11fe | 160 | //--------------------------------------------------------------------+ |
robo8080 | 5:61109bce11fe | 161 | #define ASSERT_INT(...) ASSERT_INT_EQUAL(__VA_ARGS__) |
robo8080 | 5:61109bce11fe | 162 | #define ASSERT_INT_EQUAL(...) ASSERT_XXX_EQUAL("%d", __VA_ARGS__) |
robo8080 | 5:61109bce11fe | 163 | #define ASSERT_INT_WITHIN(...) ASSERT_XXX_WITHIN("%d", __VA_ARGS__) |
robo8080 | 5:61109bce11fe | 164 | |
robo8080 | 5:61109bce11fe | 165 | //--------------------------------------------------------------------+ |
robo8080 | 5:61109bce11fe | 166 | // Hex Assert |
robo8080 | 5:61109bce11fe | 167 | //--------------------------------------------------------------------+ |
robo8080 | 5:61109bce11fe | 168 | #define ASSERT_HEX(...) ASSERT_HEX_EQUAL(__VA_ARGS__) |
robo8080 | 5:61109bce11fe | 169 | #define ASSERT_HEX_EQUAL(...) ASSERT_XXX_EQUAL("0x%x", __VA_ARGS__) |
robo8080 | 5:61109bce11fe | 170 | #define ASSERT_HEX_WITHIN(...) ASSERT_XXX_WITHIN("0x%x", __VA_ARGS__) |
robo8080 | 5:61109bce11fe | 171 | |
robo8080 | 5:61109bce11fe | 172 | //--------------------------------------------------------------------+ |
robo8080 | 5:61109bce11fe | 173 | // Bin Assert |
robo8080 | 5:61109bce11fe | 174 | //--------------------------------------------------------------------+ |
robo8080 | 5:61109bce11fe | 175 | #define BIN8_PRINTF_PATTERN "%d%d%d%d%d%d%d%d" |
robo8080 | 5:61109bce11fe | 176 | #define BIN8_PRINTF_CONVERT(byte) \ |
robo8080 | 5:61109bce11fe | 177 | ((byte) & 0x80 ? 1 : 0), \ |
robo8080 | 5:61109bce11fe | 178 | ((byte) & 0x40 ? 1 : 0), \ |
robo8080 | 5:61109bce11fe | 179 | ((byte) & 0x20 ? 1 : 0), \ |
robo8080 | 5:61109bce11fe | 180 | ((byte) & 0x10 ? 1 : 0), \ |
robo8080 | 5:61109bce11fe | 181 | ((byte) & 0x08 ? 1 : 0), \ |
robo8080 | 5:61109bce11fe | 182 | ((byte) & 0x04 ? 1 : 0), \ |
robo8080 | 5:61109bce11fe | 183 | ((byte) & 0x02 ? 1 : 0), \ |
robo8080 | 5:61109bce11fe | 184 | ((byte) & 0x01 ? 1 : 0) |
robo8080 | 5:61109bce11fe | 185 | |
robo8080 | 5:61109bce11fe | 186 | #define ASSERT_BIN8(...) ASSERT_BIN8_EQUAL(__VA_ARGS__) |
robo8080 | 5:61109bce11fe | 187 | #define ASSERT_BIN8_EQUAL(expected, actual, error)\ |
robo8080 | 5:61109bce11fe | 188 | ASSERT_DEFINE(\ |
robo8080 | 5:61109bce11fe | 189 | uint8_t exp = (expected); uint8_t act = (actual),\ |
robo8080 | 5:61109bce11fe | 190 | exp==act,\ |
robo8080 | 5:61109bce11fe | 191 | error,\ |
robo8080 | 5:61109bce11fe | 192 | "expected " BIN8_PRINTF_PATTERN ", actual " BIN8_PRINTF_PATTERN, BIN8_PRINTF_CONVERT(exp), BIN8_PRINTF_CONVERT(act) ) |
robo8080 | 5:61109bce11fe | 193 | |
robo8080 | 5:61109bce11fe | 194 | #ifdef __cplusplus |
robo8080 | 5:61109bce11fe | 195 | } |
robo8080 | 5:61109bce11fe | 196 | #endif |
robo8080 | 5:61109bce11fe | 197 | |
robo8080 | 5:61109bce11fe | 198 | #endif /* _ASSERTION_H_ */ |
robo8080 | 5:61109bce11fe | 199 | |
robo8080 | 5:61109bce11fe | 200 | /** @} */ |