| 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 | 1 | AssertFatalAdapterComponentImpl ::AssertFatalAdapterComponentImpl(const char* const compName) | |
| 45 | 1 | : AssertFatalAdapterComponentBase(compName) { | |
| 46 | // register component with adapter | ||
| 47 | 1 | this->m_adapter.regAssertReporter(this); | |
| 48 | // register adapter | ||
| 49 |
1/1✓ Branch 1 taken 1 times.
|
1 | this->m_adapter.registerHook(); |
| 50 | // Initialize the assert counter | ||
| 51 | 1 | this->m_assertCount = 0; | |
| 52 | 1 | } | |
| 53 | |||
| 54 | 2 | AssertFatalAdapterComponentImpl ::~AssertFatalAdapterComponentImpl() {} | |
| 55 | |||
| 56 | ✗ | 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 | ✗ | if (m_compPtr) { | |
| 66 | ✗ | 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 | ✗ | } | |
| 73 | |||
| 74 | 1 | void AssertFatalAdapterComponentImpl::AssertFatalAdapter::regAssertReporter(AssertFatalAdapterComponentImpl* compPtr) { | |
| 75 | 1 | this->m_compPtr = compPtr; | |
| 76 | 1 | } | |
| 77 | |||
| 78 | 1 | AssertFatalAdapterComponentImpl::AssertFatalAdapter::AssertFatalAdapter() : m_compPtr(nullptr) {} | |
| 79 | |||
| 80 | 2 | AssertFatalAdapterComponentImpl::AssertFatalAdapter::~AssertFatalAdapter() {} | |
| 81 | |||
| 82 | ✗ | void AssertFatalAdapterComponentImpl::AssertFatalAdapter::doAssert() { | |
| 83 | // do nothing since there will be a FATAL | ||
| 84 | ✗ | } | |
| 85 | |||
| 86 | ✗ | 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 | ✗ | 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 | ✗ | const CHAR* start = Fw::StringUtils::string_last_n(file, outputSize, std::numeric_limits<U16>::max()); | |
| 106 | |||
| 107 | ✗ | Fw::LogStringArg fileArg(start); | |
| 108 | #endif | ||
| 109 | |||
| 110 | ✗ | CHAR msg[Fw::StringBase::BUFFER_SIZE(FW_ASSERT_TEXT_SIZE)] = {0}; | |
| 111 | ✗ | Fw::defaultReportAssert(file, static_cast<U32>(lineNo), numArgs, arg1, arg2, arg3, arg4, arg5, arg6, msg, | |
| 112 | sizeof(msg)); | ||
| 113 | ✗ | Fw::Logger::log("%s\n", msg); | |
| 114 | |||
| 115 | // Increment active assert counter | ||
| 116 | ✗ | 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 | ✗ | 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 | ✗ | switch (numArgs) { | |
| 129 | ✗ | case 0: | |
| 130 | ✗ | this->log_FATAL_AF_ASSERT_0(fileArg, static_cast<U32>(lineNo)); | |
| 131 | ✗ | break; | |
| 132 | ✗ | case 1: | |
| 133 | ✗ | this->log_FATAL_AF_ASSERT_1(fileArg, static_cast<U32>(lineNo), static_cast<U32>(arg1)); | |
| 134 | ✗ | break; | |
| 135 | ✗ | case 2: | |
| 136 | ✗ | this->log_FATAL_AF_ASSERT_2(fileArg, static_cast<U32>(lineNo), static_cast<U32>(arg1), | |
| 137 | static_cast<U32>(arg2)); | ||
| 138 | ✗ | break; | |
| 139 | ✗ | case 3: | |
| 140 | ✗ | 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 | ✗ | break; | |
| 143 | ✗ | case 4: | |
| 144 | ✗ | 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 | ✗ | break; | |
| 147 | ✗ | case 5: | |
| 148 | ✗ | 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 | ✗ | break; | |
| 152 | ✗ | case 6: | |
| 153 | ✗ | 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 | ✗ | break; | |
| 157 | ✗ | default: | |
| 158 | ✗ | this->log_FATAL_AF_UNEXPECTED_ASSERT(fileArg, static_cast<U32>(lineNo), static_cast<U32>(numArgs)); | |
| 159 | ✗ | break; | |
| 160 | } | ||
| 161 | // Assert processing complete, decrement active assert counter | ||
| 162 | ✗ | this->m_assertCount--; | |
| 163 | ✗ | } | |
| 164 | } // end namespace Svc | ||
| 165 |