| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include <Fw/FPrimeBasicTypes.hpp> | ||
| 2 | #include <Fw/Types/Assert.hpp> | ||
| 3 | #include <Fw/Types/StringUtils.hpp> | ||
| 4 | #include <Fw/Types/format.hpp> | ||
| 5 | #include <cassert> | ||
| 6 | #include <cstdio> | ||
| 7 | #include <cstdlib> | ||
| 8 | |||
| 9 | #if FW_ASSERT_LEVEL == FW_FILEID_ASSERT | ||
| 10 | #define fileIdFs "Assert: 0x%08" PRIx32 ":%" PRI_FwSizeType "" | ||
| 11 | #else | ||
| 12 | #define fileIdFs "Assert: \"%s:%" PRI_FwSizeType "\"" | ||
| 13 | #endif | ||
| 14 | |||
| 15 | namespace Fw { | ||
| 16 | |||
| 17 | ✗ | void defaultPrintAssert(const CHAR* msg) { | |
| 18 | // Write to stderr w/o formatting | ||
| 19 | ✗ | (void)fputs(msg, stderr); | |
| 20 | ✗ | (void)fputs("\n", stderr); | |
| 21 | ✗ | } | |
| 22 | |||
| 23 | 12 | void defaultReportAssert(FILE_NAME_ARG file, | |
| 24 | FwSizeType lineNo, | ||
| 25 | FwSizeType numArgs, | ||
| 26 | FwAssertArgType arg1, | ||
| 27 | FwAssertArgType arg2, | ||
| 28 | FwAssertArgType arg3, | ||
| 29 | FwAssertArgType arg4, | ||
| 30 | FwAssertArgType arg5, | ||
| 31 | FwAssertArgType arg6, | ||
| 32 | CHAR* destBuffer, | ||
| 33 | FwSizeType buffSize) { | ||
| 34 |
8/8✓ Branch 0 taken 3 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 1 times.
|
12 | switch (numArgs) { |
| 35 | 3 | case 0: | |
| 36 | 3 | (void)stringFormat(destBuffer, buffSize, fileIdFs, file, lineNo); | |
| 37 | 3 | break; | |
| 38 | 2 | case 1: | |
| 39 | 2 | (void)stringFormat(destBuffer, buffSize, fileIdFs " %" PRI_FwAssertArgType, file, lineNo, arg1); | |
| 40 | 2 | break; | |
| 41 | 1 | case 2: | |
| 42 | 1 | (void)stringFormat(destBuffer, buffSize, fileIdFs " %" PRI_FwAssertArgType " %" PRI_FwAssertArgType, file, | |
| 43 | lineNo, arg1, arg2); | ||
| 44 | 1 | break; | |
| 45 | 2 | case 3: | |
| 46 | 2 | (void)stringFormat(destBuffer, buffSize, | |
| 47 | fileIdFs " %" PRI_FwAssertArgType " %" PRI_FwAssertArgType " %" PRI_FwAssertArgType, | ||
| 48 | file, lineNo, arg1, arg2, arg3); | ||
| 49 | 2 | break; | |
| 50 | 1 | case 4: | |
| 51 | 1 | (void)stringFormat(destBuffer, buffSize, | |
| 52 | fileIdFs " %" PRI_FwAssertArgType " %" PRI_FwAssertArgType " %" PRI_FwAssertArgType | ||
| 53 | " %" PRI_FwAssertArgType, | ||
| 54 | file, lineNo, arg1, arg2, arg3, arg4); | ||
| 55 | 1 | break; | |
| 56 | 1 | case 5: | |
| 57 | 1 | (void)stringFormat(destBuffer, buffSize, | |
| 58 | fileIdFs " %" PRI_FwAssertArgType " %" PRI_FwAssertArgType " %" PRI_FwAssertArgType | ||
| 59 | " %" PRI_FwAssertArgType " %" PRI_FwAssertArgType, | ||
| 60 | file, lineNo, arg1, arg2, arg3, arg4, arg5); | ||
| 61 | 1 | break; | |
| 62 | 1 | case 6: | |
| 63 | 1 | (void)stringFormat(destBuffer, buffSize, | |
| 64 | fileIdFs " %" PRI_FwAssertArgType " %" PRI_FwAssertArgType " %" PRI_FwAssertArgType | ||
| 65 | " %" PRI_FwAssertArgType " %" PRI_FwAssertArgType " %" PRI_FwAssertArgType, | ||
| 66 | file, lineNo, arg1, arg2, arg3, arg4, arg5, arg6); | ||
| 67 | 1 | break; | |
| 68 | 1 | default: // in an assert already, what can we do? | |
| 69 | 1 | break; | |
| 70 | } | ||
| 71 | 12 | } | |
| 72 | |||
| 73 | ✗ | void AssertHook::printAssert(const CHAR* msg) { | |
| 74 | ✗ | defaultPrintAssert(msg); | |
| 75 | ✗ | } | |
| 76 | |||
| 77 | ✗ | void AssertHook::reportAssert(FILE_NAME_ARG file, | |
| 78 | FwSizeType lineNo, | ||
| 79 | FwSizeType numArgs, | ||
| 80 | FwAssertArgType arg1, | ||
| 81 | FwAssertArgType arg2, | ||
| 82 | FwAssertArgType arg3, | ||
| 83 | FwAssertArgType arg4, | ||
| 84 | FwAssertArgType arg5, | ||
| 85 | FwAssertArgType arg6) { | ||
| 86 | ✗ | CHAR destBuffer[FW_ASSERT_TEXT_SIZE] = {0}; | |
| 87 | ✗ | defaultReportAssert(file, lineNo, numArgs, arg1, arg2, arg3, arg4, arg5, arg6, destBuffer, | |
| 88 | static_cast<FwSizeType>(sizeof(destBuffer))); | ||
| 89 | // print message | ||
| 90 | ✗ | this->printAssert(destBuffer); | |
| 91 | ✗ | } | |
| 92 | |||
| 93 | ✗ | void AssertHook::doAssert() { | |
| 94 | ✗ | assert(false); | |
| 95 | } | ||
| 96 | |||
| 97 | AssertHook* AssertHook::s_assertHook = nullptr; | ||
| 98 | |||
| 99 | 7 | void AssertHook::registerHook() { | |
| 100 | 7 | this->previousHook = s_assertHook; | |
| 101 | 7 | s_assertHook = this; | |
| 102 | 7 | } | |
| 103 | |||
| 104 | 3 | void AssertHook::deregisterHook() { | |
| 105 | 3 | s_assertHook = this->previousHook; | |
| 106 | 3 | } | |
| 107 | |||
| 108 | 22 | AssertHook* AssertHook::getRegisteredHook() { | |
| 109 | 22 | return s_assertHook; | |
| 110 | } | ||
| 111 | |||
| 112 | // Default handler of SwAssert functions | ||
| 113 | 15 | FW_ASSERT_NORETURN void defaultSwAssert(FILE_NAME_ARG file, | |
| 114 | FwSizeType lineNo, | ||
| 115 | FwSizeType numArgs, | ||
| 116 | FwAssertArgType arg1, | ||
| 117 | FwAssertArgType arg2, | ||
| 118 | FwAssertArgType arg3, | ||
| 119 | FwAssertArgType arg4, | ||
| 120 | FwAssertArgType arg5, | ||
| 121 | FwAssertArgType arg6) { | ||
| 122 | 15 | Fw::AssertHook* const registeredHook = Fw::AssertHook::getRegisteredHook(); | |
| 123 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
|
15 | if (nullptr == registeredHook) { |
| 124 | ✗ | CHAR assertMsg[FW_ASSERT_TEXT_SIZE]; | |
| 125 | ✗ | defaultReportAssert(file, lineNo, numArgs, arg1, arg2, arg3, arg4, arg5, arg6, assertMsg, | |
| 126 | static_cast<FwSizeType>(sizeof(assertMsg))); | ||
| 127 | ✗ | defaultPrintAssert(assertMsg); | |
| 128 | ✗ | assert(false); | |
| 129 | } else { | ||
| 130 | 15 | registeredHook->reportAssert(file, lineNo, numArgs, arg1, arg2, arg3, arg4, arg5, arg6); | |
| 131 | 15 | registeredHook->doAssert(); | |
| 132 | } | ||
| 133 | #if FW_ASSERTIONS_ALWAYS_ABORT | ||
| 134 | abort(); | ||
| 135 | #endif | ||
| 136 | 15 | } | |
| 137 | |||
| 138 | 3 | void SwAssert(FILE_NAME_ARG file, FwSizeType lineNo) { | |
| 139 | 3 | defaultSwAssert(file, lineNo, 0, 0, 0, 0, 0, 0, 0); | |
| 140 | 3 | } | |
| 141 | |||
| 142 | 2 | void SwAssert(FILE_NAME_ARG file, FwAssertArgType arg1, FwSizeType lineNo) { | |
| 143 | 2 | defaultSwAssert(file, lineNo, 1, arg1, 0, 0, 0, 0, 0); | |
| 144 | 2 | } | |
| 145 | |||
| 146 | 2 | void SwAssert(FILE_NAME_ARG file, FwAssertArgType arg1, FwAssertArgType arg2, FwSizeType lineNo) { | |
| 147 | 2 | defaultSwAssert(file, lineNo, 2, arg1, arg2, 0, 0, 0, 0); | |
| 148 | 2 | } | |
| 149 | |||
| 150 | 2 | void SwAssert(FILE_NAME_ARG file, FwAssertArgType arg1, FwAssertArgType arg2, FwAssertArgType arg3, FwSizeType lineNo) { | |
| 151 | 2 | defaultSwAssert(file, lineNo, 3, arg1, arg2, arg3, 0, 0, 0); | |
| 152 | 2 | } | |
| 153 | |||
| 154 | 2 | void SwAssert(FILE_NAME_ARG file, | |
| 155 | FwAssertArgType arg1, | ||
| 156 | FwAssertArgType arg2, | ||
| 157 | FwAssertArgType arg3, | ||
| 158 | FwAssertArgType arg4, | ||
| 159 | FwSizeType lineNo) { | ||
| 160 | 2 | defaultSwAssert(file, lineNo, 4, arg1, arg2, arg3, arg4, 0, 0); | |
| 161 | 2 | } | |
| 162 | |||
| 163 | 2 | void SwAssert(FILE_NAME_ARG file, | |
| 164 | FwAssertArgType arg1, | ||
| 165 | FwAssertArgType arg2, | ||
| 166 | FwAssertArgType arg3, | ||
| 167 | FwAssertArgType arg4, | ||
| 168 | FwAssertArgType arg5, | ||
| 169 | FwSizeType lineNo) { | ||
| 170 | 2 | defaultSwAssert(file, lineNo, 5, arg1, arg2, arg3, arg4, arg5, 0); | |
| 171 | 2 | } | |
| 172 | |||
| 173 | 2 | void SwAssert(FILE_NAME_ARG file, | |
| 174 | FwAssertArgType arg1, | ||
| 175 | FwAssertArgType arg2, | ||
| 176 | FwAssertArgType arg3, | ||
| 177 | FwAssertArgType arg4, | ||
| 178 | FwAssertArgType arg5, | ||
| 179 | FwAssertArgType arg6, | ||
| 180 | FwSizeType lineNo) { | ||
| 181 | 2 | defaultSwAssert(file, lineNo, 6, arg1, arg2, arg3, arg4, arg5, arg6); | |
| 182 | 2 | } | |
| 183 | } // namespace Fw | ||
| 184 | |||
| 185 | // define C asserts with C linkage | ||
| 186 | extern "C" { | ||
| 187 | I8 CAssert0(FILE_NAME_ARG file, FwSizeType lineNo); | ||
| 188 | I8 CAssert1(FILE_NAME_ARG file, FwAssertArgType arg1, FwSizeType lineNo); | ||
| 189 | I8 CAssert2(FILE_NAME_ARG file, FwAssertArgType arg1, FwAssertArgType arg2, FwSizeType lineNo); | ||
| 190 | I8 CAssert3(FILE_NAME_ARG file, FwAssertArgType arg1, FwAssertArgType arg2, FwAssertArgType arg3, FwSizeType lineNo); | ||
| 191 | I8 CAssert4(FILE_NAME_ARG file, | ||
| 192 | FwAssertArgType arg1, | ||
| 193 | FwAssertArgType arg2, | ||
| 194 | FwAssertArgType arg3, | ||
| 195 | FwAssertArgType arg4, | ||
| 196 | FwSizeType lineNo); | ||
| 197 | I8 CAssert5(FILE_NAME_ARG file, | ||
| 198 | FwAssertArgType arg1, | ||
| 199 | FwAssertArgType arg2, | ||
| 200 | FwAssertArgType arg3, | ||
| 201 | FwAssertArgType arg4, | ||
| 202 | FwAssertArgType arg5, | ||
| 203 | FwSizeType lineNo); | ||
| 204 | I8 CAssert6(FILE_NAME_ARG file, | ||
| 205 | FwAssertArgType arg1, | ||
| 206 | FwAssertArgType arg2, | ||
| 207 | FwAssertArgType arg3, | ||
| 208 | FwAssertArgType arg4, | ||
| 209 | FwAssertArgType arg5, | ||
| 210 | FwAssertArgType arg6, | ||
| 211 | FwSizeType lineNo); | ||
| 212 | } | ||
| 213 | |||
| 214 | 1 | I8 CAssert0(FILE_NAME_ARG file, FwSizeType lineNo) { | |
| 215 | 1 | Fw::AssertHook* const registeredHook = Fw::AssertHook::getRegisteredHook(); | |
| 216 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (nullptr == registeredHook) { |
| 217 | ✗ | CHAR assertMsg[FW_ASSERT_TEXT_SIZE]; | |
| 218 | ✗ | Fw::defaultReportAssert(file, lineNo, 0, 0, 0, 0, 0, 0, 0, assertMsg, | |
| 219 | static_cast<FwSizeType>(sizeof(assertMsg))); | ||
| 220 | ✗ | Fw::defaultPrintAssert(assertMsg); | |
| 221 | ✗ | assert(false); | |
| 222 | } else { | ||
| 223 | 1 | registeredHook->reportAssert(file, lineNo, 0, 0, 0, 0, 0, 0, 0); | |
| 224 | 1 | registeredHook->doAssert(); | |
| 225 | } | ||
| 226 | 1 | return 0; | |
| 227 | } | ||
| 228 | |||
| 229 | 1 | I8 CAssert1(FILE_NAME_ARG file, FwAssertArgType arg1, FwSizeType lineNo) { | |
| 230 | 1 | Fw::AssertHook* const registeredHook = Fw::AssertHook::getRegisteredHook(); | |
| 231 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (nullptr == registeredHook) { |
| 232 | ✗ | CHAR assertMsg[FW_ASSERT_TEXT_SIZE]; | |
| 233 | ✗ | Fw::defaultReportAssert(file, lineNo, 1, arg1, 0, 0, 0, 0, 0, assertMsg, | |
| 234 | static_cast<FwSizeType>(sizeof(assertMsg))); | ||
| 235 | ✗ | Fw::defaultPrintAssert(assertMsg); | |
| 236 | ✗ | assert(false); | |
| 237 | } else { | ||
| 238 | 1 | registeredHook->reportAssert(file, lineNo, 1, arg1, 0, 0, 0, 0, 0); | |
| 239 | 1 | registeredHook->doAssert(); | |
| 240 | } | ||
| 241 | 1 | return 0; | |
| 242 | } | ||
| 243 | |||
| 244 | 1 | I8 CAssert2(FILE_NAME_ARG file, FwAssertArgType arg1, FwAssertArgType arg2, FwSizeType lineNo) { | |
| 245 | 1 | Fw::AssertHook* const registeredHook = Fw::AssertHook::getRegisteredHook(); | |
| 246 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (nullptr == registeredHook) { |
| 247 | ✗ | CHAR assertMsg[FW_ASSERT_TEXT_SIZE]; | |
| 248 | ✗ | Fw::defaultReportAssert(file, lineNo, 2, arg1, arg2, 0, 0, 0, 0, assertMsg, | |
| 249 | static_cast<FwSizeType>(sizeof(assertMsg))); | ||
| 250 | ✗ | Fw::defaultPrintAssert(assertMsg); | |
| 251 | ✗ | assert(false); | |
| 252 | } else { | ||
| 253 | 1 | registeredHook->reportAssert(file, lineNo, 2, arg1, arg2, 0, 0, 0, 0); | |
| 254 | 1 | registeredHook->doAssert(); | |
| 255 | } | ||
| 256 | 1 | return 0; | |
| 257 | } | ||
| 258 | |||
| 259 | 1 | I8 CAssert3(FILE_NAME_ARG file, FwAssertArgType arg1, FwAssertArgType arg2, FwAssertArgType arg3, FwSizeType lineNo) { | |
| 260 | 1 | Fw::AssertHook* const registeredHook = Fw::AssertHook::getRegisteredHook(); | |
| 261 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (nullptr == registeredHook) { |
| 262 | ✗ | CHAR assertMsg[FW_ASSERT_TEXT_SIZE]; | |
| 263 | ✗ | Fw::defaultReportAssert(file, lineNo, 3, arg1, arg2, arg3, 0, 0, 0, assertMsg, | |
| 264 | static_cast<FwSizeType>(sizeof(assertMsg))); | ||
| 265 | ✗ | Fw::defaultPrintAssert(assertMsg); | |
| 266 | ✗ | assert(false); | |
| 267 | } else { | ||
| 268 | 1 | registeredHook->reportAssert(file, lineNo, 3, arg1, arg2, arg3, 0, 0, 0); | |
| 269 | 1 | registeredHook->doAssert(); | |
| 270 | } | ||
| 271 | 1 | return 0; | |
| 272 | } | ||
| 273 | |||
| 274 | 1 | I8 CAssert4(FILE_NAME_ARG file, | |
| 275 | FwAssertArgType arg1, | ||
| 276 | FwAssertArgType arg2, | ||
| 277 | FwAssertArgType arg3, | ||
| 278 | FwAssertArgType arg4, | ||
| 279 | FwSizeType lineNo) { | ||
| 280 | 1 | Fw::AssertHook* const registeredHook = Fw::AssertHook::getRegisteredHook(); | |
| 281 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (nullptr == registeredHook) { |
| 282 | ✗ | CHAR assertMsg[FW_ASSERT_TEXT_SIZE]; | |
| 283 | ✗ | Fw::defaultReportAssert(file, lineNo, 4, arg1, arg2, arg3, arg4, 0, 0, assertMsg, | |
| 284 | static_cast<FwSizeType>(sizeof(assertMsg))); | ||
| 285 | ✗ | Fw::defaultPrintAssert(assertMsg); | |
| 286 | ✗ | assert(false); | |
| 287 | } else { | ||
| 288 | 1 | registeredHook->reportAssert(file, lineNo, 4, arg1, arg2, arg3, arg4, 0, 0); | |
| 289 | 1 | registeredHook->doAssert(); | |
| 290 | } | ||
| 291 | 1 | return 0; | |
| 292 | } | ||
| 293 | |||
| 294 | 1 | I8 CAssert5(FILE_NAME_ARG file, | |
| 295 | FwAssertArgType arg1, | ||
| 296 | FwAssertArgType arg2, | ||
| 297 | FwAssertArgType arg3, | ||
| 298 | FwAssertArgType arg4, | ||
| 299 | FwAssertArgType arg5, | ||
| 300 | FwSizeType lineNo) { | ||
| 301 | 1 | Fw::AssertHook* const registeredHook = Fw::AssertHook::getRegisteredHook(); | |
| 302 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (nullptr == registeredHook) { |
| 303 | ✗ | CHAR assertMsg[FW_ASSERT_TEXT_SIZE]; | |
| 304 | ✗ | Fw::defaultReportAssert(file, lineNo, 5, arg1, arg2, arg3, arg4, arg5, 0, assertMsg, | |
| 305 | static_cast<FwSizeType>(sizeof(assertMsg))); | ||
| 306 | ✗ | Fw::defaultPrintAssert(assertMsg); | |
| 307 | ✗ | assert(false); | |
| 308 | } else { | ||
| 309 | 1 | registeredHook->reportAssert(file, lineNo, 5, arg1, arg2, arg3, arg4, arg5, 0); | |
| 310 | 1 | registeredHook->doAssert(); | |
| 311 | } | ||
| 312 | 1 | return 0; | |
| 313 | } | ||
| 314 | |||
| 315 | 1 | I8 CAssert6(FILE_NAME_ARG file, | |
| 316 | FwAssertArgType arg1, | ||
| 317 | FwAssertArgType arg2, | ||
| 318 | FwAssertArgType arg3, | ||
| 319 | FwAssertArgType arg4, | ||
| 320 | FwAssertArgType arg5, | ||
| 321 | FwAssertArgType arg6, | ||
| 322 | FwSizeType lineNo) { | ||
| 323 | 1 | Fw::AssertHook* const registeredHook = Fw::AssertHook::getRegisteredHook(); | |
| 324 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (nullptr == registeredHook) { |
| 325 | ✗ | CHAR assertMsg[FW_ASSERT_TEXT_SIZE]; | |
| 326 | ✗ | Fw::defaultReportAssert(file, lineNo, 6, arg1, arg2, arg3, arg4, arg5, arg6, assertMsg, | |
| 327 | static_cast<FwSizeType>(sizeof(assertMsg))); | ||
| 328 | ✗ | Fw::defaultPrintAssert(assertMsg); | |
| 329 | ✗ | assert(false); | |
| 330 | } else { | ||
| 331 | 1 | registeredHook->reportAssert(file, lineNo, 6, arg1, arg2, arg3, arg4, arg5, arg6); | |
| 332 | 1 | registeredHook->doAssert(); | |
| 333 | } | ||
| 334 | 1 | return 0; | |
| 335 | } | ||
| 336 |