| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // ====================================================================== | ||
| 2 | // \title fputs_assert_hook.cpp | ||
| 3 | // \author Andrei Tumbar | ||
| 4 | // \brief cpp file for assert hook functions using fputs implementation | ||
| 5 | // ====================================================================== | ||
| 6 | #include <Fw/Types/assert_hook.hpp> | ||
| 7 | #include <Fw/Types/format.hpp> | ||
| 8 | #include <cassert> | ||
| 9 | #include <cstdio> | ||
| 10 | |||
| 11 | #if FW_ASSERT_LEVEL == FW_FILEID_ASSERT | ||
| 12 | #define fileIdFs "Assert: 0x%08" PRIx32 ":%" PRI_FwSizeType "" | ||
| 13 | #else | ||
| 14 | #define fileIdFs "Assert: \"%s:%" PRI_FwSizeType "\"" | ||
| 15 | #endif | ||
| 16 | |||
| 17 | ✗ | void Fw::terminateOnAssert() { | |
| 18 | ✗ | assert(false); | |
| 19 | } | ||
| 20 | |||
| 21 | 1 | void Fw::printAssertMessage(const CHAR* msg) { | |
| 22 | // Write to stderr w/o formatting | ||
| 23 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
1 | (void)fputs(msg, stderr); |
| 24 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | (void)fputs("\n", stderr); |
| 25 | 1 | } | |
| 26 | |||
| 27 | 8 | void Fw::formatAssertMessage(FILE_NAME_ARG file, | |
| 28 | FwSizeType lineNo, | ||
| 29 | FwSizeType numArgs, | ||
| 30 | FwAssertArgType arg1, | ||
| 31 | FwAssertArgType arg2, | ||
| 32 | FwAssertArgType arg3, | ||
| 33 | FwAssertArgType arg4, | ||
| 34 | FwAssertArgType arg5, | ||
| 35 | FwAssertArgType arg6, | ||
| 36 | CHAR* destBuffer, | ||
| 37 | FwSizeType buffSize) { | ||
| 38 | // Format status is discarded: a truncated assert message is still useful and there is no better recourse here | ||
| 39 |
8/8✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 1 times.
|
8 | switch (numArgs) { |
| 40 | 1 | case 0: | |
| 41 | 1 | (void)stringFormat(destBuffer, buffSize, fileIdFs, file, lineNo); | |
| 42 | 1 | break; | |
| 43 | 1 | case 1: | |
| 44 | 1 | (void)stringFormat(destBuffer, buffSize, fileIdFs " %" PRI_FwAssertArgType, file, lineNo, arg1); | |
| 45 | 1 | break; | |
| 46 | 1 | case 2: | |
| 47 | 1 | (void)stringFormat(destBuffer, buffSize, fileIdFs " %" PRI_FwAssertArgType " %" PRI_FwAssertArgType, file, | |
| 48 | lineNo, arg1, arg2); | ||
| 49 | 1 | break; | |
| 50 | 1 | case 3: | |
| 51 | 1 | (void)stringFormat(destBuffer, buffSize, | |
| 52 | fileIdFs " %" PRI_FwAssertArgType " %" PRI_FwAssertArgType " %" PRI_FwAssertArgType, | ||
| 53 | file, lineNo, arg1, arg2, arg3); | ||
| 54 | 1 | break; | |
| 55 | 1 | case 4: | |
| 56 | 1 | (void)stringFormat(destBuffer, buffSize, | |
| 57 | fileIdFs " %" PRI_FwAssertArgType " %" PRI_FwAssertArgType " %" PRI_FwAssertArgType | ||
| 58 | " %" PRI_FwAssertArgType, | ||
| 59 | file, lineNo, arg1, arg2, arg3, arg4); | ||
| 60 | 1 | break; | |
| 61 | 1 | case 5: | |
| 62 | 1 | (void)stringFormat(destBuffer, buffSize, | |
| 63 | fileIdFs " %" PRI_FwAssertArgType " %" PRI_FwAssertArgType " %" PRI_FwAssertArgType | ||
| 64 | " %" PRI_FwAssertArgType " %" PRI_FwAssertArgType, | ||
| 65 | file, lineNo, arg1, arg2, arg3, arg4, arg5); | ||
| 66 | 1 | break; | |
| 67 | 1 | case 6: | |
| 68 | 1 | (void)stringFormat(destBuffer, buffSize, | |
| 69 | fileIdFs " %" PRI_FwAssertArgType " %" PRI_FwAssertArgType " %" PRI_FwAssertArgType | ||
| 70 | " %" PRI_FwAssertArgType " %" PRI_FwAssertArgType " %" PRI_FwAssertArgType, | ||
| 71 | file, lineNo, arg1, arg2, arg3, arg4, arg5, arg6); | ||
| 72 | 1 | break; | |
| 73 | 1 | default: // in an assert already, what can we do? | |
| 74 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (buffSize > 0) { |
| 75 | 1 | destBuffer[0] = '\0'; | |
| 76 | } | ||
| 77 | 1 | break; | |
| 78 | } | ||
| 79 | 8 | } | |
| 80 |