| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // ====================================================================== | ||
| 2 | // \title AssertFatalAdapterImpl.cpp | ||
| 3 | // \author tcanham | ||
| 4 | // \brief cpp file for AssertFatalAdapter component implementation class | ||
| 5 | // | ||
| 6 | // \copyright | ||
| 7 | // Copyright 2009-2015, by the California Institute of Technology. | ||
| 8 | // ALL RIGHTS RESERVED. United States Government Sponsorship | ||
| 9 | // acknowledged. | ||
| 10 | // | ||
| 11 | // ====================================================================== | ||
| 12 | |||
| 13 | #include <Fw/FPrimeBasicTypes.hpp> | ||
| 14 | #include <Fw/Logger/Logger.hpp> | ||
| 15 | #include <Fw/Types/Assert.hpp> | ||
| 16 | #include <Fw/Types/StringUtils.hpp> | ||
| 17 | #include <Svc/AssertFatalAdapter/AssertFatalAdapterComponentImpl.hpp> | ||
| 18 | #include <algorithm> | ||
| 19 | #include <cassert> | ||
| 20 | #include <cstdio> | ||
| 21 | #include <limits> | ||
| 22 | |||
| 23 | namespace Fw { | ||
| 24 | void defaultReportAssert(FILE_NAME_ARG file, | ||
| 25 | FwSizeType lineNo, | ||
| 26 | FwSizeType numArgs, | ||
| 27 | FwAssertArgType arg1, | ||
| 28 | FwAssertArgType arg2, | ||
| 29 | FwAssertArgType arg3, | ||
| 30 | FwAssertArgType arg4, | ||
| 31 | FwAssertArgType arg5, | ||
| 32 | FwAssertArgType arg6, | ||
| 33 | CHAR* destBuffer, | ||
| 34 | FwSizeType buffSize); | ||
| 35 | |||
| 36 | } | ||
| 37 | |||
| 38 | namespace Svc { | ||
| 39 | |||
| 40 | // ---------------------------------------------------------------------- | ||
| 41 | // Construction, initialization, and destruction | ||
| 42 | // ---------------------------------------------------------------------- | ||
| 43 | |||
| 44 | 2 | AssertFatalAdapterComponentImpl ::AssertFatalAdapterComponentImpl(const char* const compName) | |
| 45 | 2 | : AssertFatalAdapterComponentBase(compName) { | |
| 46 | // register component with adapter | ||
| 47 | 2 | this->m_adapter.regAssertReporter(this); | |
| 48 | // register adapter | ||
| 49 |
1/1✓ Branch 6 taken 2 times.
|
2 | this->m_adapter.registerHook(); |
| 50 | // Initialize the assert counter | ||
| 51 | 2 | this->m_assertCount = 0; | |
| 52 | 2 | } | |
| 53 | |||
| 54 | 4 | AssertFatalAdapterComponentImpl ::~AssertFatalAdapterComponentImpl() {} | |
| 55 | |||
| 56 | 7 | void AssertFatalAdapterComponentImpl::AssertFatalAdapter::reportAssert(FILE_NAME_ARG file, | |
| 57 | FwSizeType lineNo, | ||
| 58 | FwSizeType numArgs, | ||
| 59 | FwAssertArgType arg1, | ||
| 60 | FwAssertArgType arg2, | ||
| 61 | FwAssertArgType arg3, | ||
| 62 | FwAssertArgType arg4, | ||
| 63 | FwAssertArgType arg5, | ||
| 64 | FwAssertArgType arg6) { | ||
| 65 |
1/2✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
|
7 | if (m_compPtr) { |
| 66 | 7 | m_compPtr->reportAssert(file, lineNo, numArgs, arg1, arg2, arg3, arg4, arg5, arg6); | |
| 67 | } else { | ||
| 68 | // Can't assert, what else can we do? Maybe somebody will see it. | ||
| 69 | ✗ | Fw::Logger::log("Svc::AssertFatalAdapter not registered!\n"); | |
| 70 | ✗ | assert(false); | |
| 71 | } | ||
| 72 | 7 | } | |
| 73 | |||
| 74 | 2 | void AssertFatalAdapterComponentImpl::AssertFatalAdapter::regAssertReporter(AssertFatalAdapterComponentImpl* compPtr) { | |
| 75 | 2 | this->m_compPtr = compPtr; | |
| 76 | 2 | } | |
| 77 | |||
| 78 | 2 | AssertFatalAdapterComponentImpl::AssertFatalAdapter::AssertFatalAdapter() : m_compPtr(nullptr) {} | |
| 79 | |||
| 80 | 4 | AssertFatalAdapterComponentImpl::AssertFatalAdapter::~AssertFatalAdapter() {} | |
| 81 | |||
| 82 | 7 | void AssertFatalAdapterComponentImpl::AssertFatalAdapter::doAssert() { | |
| 83 | // do nothing since there will be a FATAL | ||
| 84 | 7 | } | |
| 85 | |||
| 86 | 12 | void AssertFatalAdapterComponentImpl::reportAssert(FILE_NAME_ARG file, | |
| 87 | FwSizeType lineNo, | ||
| 88 | FwSizeType numArgs, | ||
| 89 | FwAssertArgType arg1, | ||
| 90 | FwAssertArgType arg2, | ||
| 91 | FwAssertArgType arg3, | ||
| 92 | FwAssertArgType arg4, | ||
| 93 | FwAssertArgType arg5, | ||
| 94 | FwAssertArgType arg6) { | ||
| 95 | // Get file arg for events | ||
| 96 | #if FW_ASSERT_LEVEL == FW_FILEID_ASSERT | ||
| 97 | Fw::LogStringArg fileArg; | ||
| 98 | fileArg.format("0x%08" PRIX32, file); | ||
| 99 | #else | ||
| 100 | 12 | const FwSizeType outputSize = std::min(static_cast<FwSizeType>(AssertFatalAdapterEventFileSize), | |
| 101 | static_cast<FwSizeType>(FW_LOG_STRING_MAX_SIZE)); | ||
| 102 | // File name argument is derived from a compiler string literal. Per the C++ standard, string literals are | ||
| 103 | // guaranteed to be null-terminated and whose maximum length is from U16_MAX to available system memory size. Thus, | ||
| 104 | // we choose a bound of the lowest allowed maximum literal length. | ||
| 105 |
1/1✓ Branch 2 taken 12 times.
|
12 | const CHAR* start = Fw::StringUtils::string_last_n(file, outputSize, std::numeric_limits<U16>::max()); |
| 106 | |||
| 107 |
1/1✓ Branch 2 taken 12 times.
|
12 | Fw::LogStringArg fileArg(start); |
| 108 | #endif | ||
| 109 | |||
| 110 | 12 | CHAR msg[Fw::StringBase::BUFFER_SIZE(FW_ASSERT_TEXT_SIZE)] = {0}; | |
| 111 |
1/1✓ Branch 1 taken 12 times.
|
12 | Fw::defaultReportAssert(file, static_cast<U32>(lineNo), numArgs, arg1, arg2, arg3, arg4, arg5, arg6, msg, |
| 112 | sizeof(msg)); | ||
| 113 |
1/1✓ Branch 1 taken 12 times.
|
12 | Fw::Logger::log("%s\n", msg); |
| 114 | |||
| 115 | // Increment active assert counter | ||
| 116 | 12 | this->m_assertCount++; | |
| 117 | |||
| 118 | // Handle the case where the ports aren't connected yet or we've surpassed the maximum cascading FW_ASSERT failures | ||
| 119 |
4/7✓ Branch 5 taken 12 times.
✓ Branch 7 taken 12 times.
✗ Branch 8 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 12 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 12 times.
|
12 | if (not this->isConnected_Log_OutputPort(0) || this->m_assertCount > FW_ASSERT_COUNT_MAX) { |
| 120 | // assert() is a no-op when NDEBUG is defined, so this counter must be released here as it | ||
| 121 | // is on the normal path below. Otherwise unreported asserts accumulate until the count | ||
| 122 | // exceeds FW_ASSERT_COUNT_MAX permanently and no further assert is ever reported. | ||
| 123 | ✗ | this->m_assertCount--; | |
| 124 | ✗ | assert(false); | |
| 125 | return; | ||
| 126 | } | ||
| 127 | |||
| 128 |
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) { |
| 129 | 3 | case 0: | |
| 130 |
1/1✓ Branch 5 taken 3 times.
|
3 | this->log_FATAL_AF_ASSERT_0(fileArg, static_cast<U32>(lineNo)); |
| 131 | 3 | break; | |
| 132 | 2 | case 1: | |
| 133 |
1/1✓ Branch 5 taken 2 times.
|
2 | this->log_FATAL_AF_ASSERT_1(fileArg, static_cast<U32>(lineNo), static_cast<U32>(arg1)); |
| 134 | 2 | break; | |
| 135 | 1 | case 2: | |
| 136 |
1/1✓ Branch 5 taken 1 times.
|
1 | this->log_FATAL_AF_ASSERT_2(fileArg, static_cast<U32>(lineNo), static_cast<U32>(arg1), |
| 137 | static_cast<U32>(arg2)); | ||
| 138 | 1 | break; | |
| 139 | 2 | case 3: | |
| 140 |
1/1✓ Branch 5 taken 2 times.
|
2 | this->log_FATAL_AF_ASSERT_3(fileArg, static_cast<U32>(lineNo), static_cast<U32>(arg1), |
| 141 | static_cast<U32>(arg2), static_cast<U32>(arg3)); | ||
| 142 | 2 | break; | |
| 143 | 1 | case 4: | |
| 144 |
1/1✓ Branch 5 taken 1 times.
|
1 | this->log_FATAL_AF_ASSERT_4(fileArg, static_cast<U32>(lineNo), static_cast<U32>(arg1), |
| 145 | static_cast<U32>(arg2), static_cast<U32>(arg3), static_cast<U32>(arg4)); | ||
| 146 | 1 | break; | |
| 147 | 1 | case 5: | |
| 148 |
1/1✓ Branch 5 taken 1 times.
|
1 | this->log_FATAL_AF_ASSERT_5(fileArg, static_cast<U32>(lineNo), static_cast<U32>(arg1), |
| 149 | static_cast<U32>(arg2), static_cast<U32>(arg3), static_cast<U32>(arg4), | ||
| 150 | static_cast<U32>(arg5)); | ||
| 151 | 1 | break; | |
| 152 | 1 | case 6: | |
| 153 |
1/1✓ Branch 5 taken 1 times.
|
1 | this->log_FATAL_AF_ASSERT_6(fileArg, static_cast<U32>(lineNo), static_cast<U32>(arg1), |
| 154 | static_cast<U32>(arg2), static_cast<U32>(arg3), static_cast<U32>(arg4), | ||
| 155 | static_cast<U32>(arg5), static_cast<U32>(arg6)); | ||
| 156 | 1 | break; | |
| 157 | 1 | default: | |
| 158 |
1/1✓ Branch 5 taken 1 times.
|
1 | this->log_FATAL_AF_UNEXPECTED_ASSERT(fileArg, static_cast<U32>(lineNo), static_cast<U32>(numArgs)); |
| 159 | 1 | break; | |
| 160 | } | ||
| 161 | // Assert processing complete, decrement active assert counter | ||
| 162 | 12 | this->m_assertCount--; | |
| 163 | 12 | } | |
| 164 | } // end namespace Svc | ||
| 165 |