GCC Code Coverage Report


Directory: /home/runner/work/fprime/fprime/Svc/EventManager/
File: EventManager.cpp
Date: 2026-09-03 22:13:39
Exec Total Coverage
Lines: 43 93 46.2%
Functions: 7 9 77.8%
Branches: 42 104 40.4%

Line Branch Exec Source
1 /*
2 * TestCommand1Impl.cpp
3 *
4 * Created on: Mar 28, 2014
5 * Author: tcanham
6 */
7
8 #include <Fw/Logger/Logger.hpp>
9 #include <Fw/Types/Assert.hpp>
10 #include <Os/File.hpp>
11 #include <Svc/EventManager/EventManager.hpp>
12
13 namespace Svc {
14 static_assert(std::numeric_limits<FwSizeType>::max() >= TELEM_ID_FILTER_SIZE,
15 "TELEM_ID_FILTER_SIZE must fit within range of FwSizeType");
16 typedef EventManager_Enabled Enabled;
17 typedef EventManager_FilterSeverity FilterSeverity;
18
19
5/5
✓ Branch 2 taken 1 times.
✓ Branch 5 taken 1 times.
✓ Branch 8 taken 1 times.
✓ Branch 11 taken 1 times.
✓ Branch 14 taken 1 times.
1 EventManager::EventManager(const char* name) : EventManagerComponentBase(name), m_severityFilter() {
20 // set filter defaults
21
2/2
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
1 this->m_severityFilter.setFilter(Fw::LogSeverity::WARNING_HI, FILTER_WARNING_HI_DEFAULT);
22
2/2
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
1 this->m_severityFilter.setFilter(Fw::LogSeverity::WARNING_LO, FILTER_WARNING_LO_DEFAULT);
23
2/2
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
1 this->m_severityFilter.setFilter(Fw::LogSeverity::COMMAND, FILTER_COMMAND_DEFAULT);
24
2/2
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
1 this->m_severityFilter.setFilter(Fw::LogSeverity::ACTIVITY_HI, FILTER_ACTIVITY_HI_DEFAULT);
25
2/2
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
1 this->m_severityFilter.setFilter(Fw::LogSeverity::ACTIVITY_LO, FILTER_ACTIVITY_LO_DEFAULT);
26
2/2
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
1 this->m_severityFilter.setFilter(Fw::LogSeverity::DIAGNOSTIC, FILTER_DIAGNOSTIC_DEFAULT);
27 1 }
28
29 2 EventManager::~EventManager() {}
30
31 555 void EventManager::LogRecv_handler(FwIndexType portNum,
32 FwEventIdType id,
33 Fw::Time& timeTag,
34 const Fw::LogSeverity& severity,
35 Fw::LogBuffer& args) {
36 // Severity may arrive from external sources (e.g. a hub bridging another
37 // address space), so drop invalid values rather than asserting
38
2/3
✓ Branch 1 taken 555 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 555 times.
555 if (!severity.isValid()) {
39 Fw::Logger::log("[ERROR] EventManager: dropping event 0x%x (invalid severity %d)\n", static_cast<U32>(id),
40 static_cast<I32>(severity.e));
41 113 return;
42 }
43
44 // Check severity filter (FATAL always passes through)
45
4/4
✓ Branch 1 taken 555 times.
✓ Branch 4 taken 555 times.
✓ Branch 7 taken 113 times.
✓ Branch 8 taken 442 times.
555 if (this->m_severityFilter.isFiltered(severity)) {
46 113 return;
47 }
48
49 // check ID filters
50
1/1
✓ Branch 1 taken 442 times.
442 this->m_idFilterLock.lock();
51
1/1
✓ Branch 1 taken 442 times.
442 Fw::Success findStatus = m_filteredIDs.find(id);
52
1/1
✓ Branch 1 taken 442 times.
442 this->m_idFilterLock.unLock();
53
2/6
✗ Branch 1 not taken.
✓ Branch 2 taken 442 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 442 times.
442 if ((findStatus == Fw::Success::SUCCESS) && (severity != Fw::LogSeverity::FATAL)) {
54 return;
55 }
56
57 // send event to the logger thread
58
1/1
✓ Branch 1 taken 442 times.
442 this->loqQueue_internalInterfaceInvoke(id, timeTag, severity, args);
59
60 // if connected, announce the FATAL
61
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 442 times.
442 if (Fw::LogSeverity::FATAL == severity.e) {
62 if (this->isConnected_FatalAnnounce_OutputPort(0)) {
63 this->FatalAnnounce_out(0, id);
64 }
65 }
66 442 }
67
68 442 void EventManager::loqQueue_internalInterfaceHandler(FwEventIdType id,
69 const Fw::Time& timeTag,
70 const Fw::LogSeverity& severity,
71 const Fw::LogBuffer& args) {
72 // Serialize event
73 442 this->m_logPacket.setId(id);
74 442 this->m_logPacket.setTimeTag(timeTag);
75 442 this->m_logPacket.setLogBuffer(args);
76 442 this->m_comBuffer.resetSer();
77 442 Fw::SerializeStatus stat = this->m_logPacket.serializeTo(this->m_comBuffer);
78 // A maximum-size LogBuffer plus the packet header can exceed the com buffer capacity.
79 // Drop the event rather than asserting, since the arguments may arrive from
80 // external sources (e.g. a hub bridging another address space).
81
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 442 times.
442 if (Fw::FW_SERIALIZE_OK != stat) {
82 Fw::Logger::log("[ERROR] EventManager: dropping event 0x%x (serialize status %d)\n", static_cast<U32>(id),
83 static_cast<I32>(stat));
84 return;
85 }
86
87
1/2
✓ Branch 1 taken 442 times.
✗ Branch 2 not taken.
442 if (this->isConnected_PktSend_OutputPort(0)) {
88 442 this->PktSend_out(0, this->m_comBuffer, 0);
89 }
90 }
91
92 13 void EventManager::SET_EVENT_FILTER_cmdHandler(FwOpcodeType opCode,
93 U32 cmdSeq,
94 const FilterSeverity& filterLevel,
95 const Enabled& filterEnable) {
96 // Verify FilterSeverity enum values match EventSeverityFilter index ordering
97 static_assert(static_cast<FwSizeType>(FilterSeverity::WARNING_HI) == 0, "FilterSeverity ordering mismatch");
98 static_assert(static_cast<FwSizeType>(FilterSeverity::WARNING_LO) == 1, "FilterSeverity ordering mismatch");
99 static_assert(static_cast<FwSizeType>(FilterSeverity::COMMAND) == 2, "FilterSeverity ordering mismatch");
100 static_assert(static_cast<FwSizeType>(FilterSeverity::ACTIVITY_HI) == 3, "FilterSeverity ordering mismatch");
101 static_assert(static_cast<FwSizeType>(FilterSeverity::ACTIVITY_LO) == 4, "FilterSeverity ordering mismatch");
102 static_assert(static_cast<FwSizeType>(FilterSeverity::DIAGNOSTIC) == 5, "FilterSeverity ordering mismatch");
103
104
1/1
✓ Branch 1 taken 13 times.
13 Fw::LogSeverity logSeverity;
105
1/1
✓ Branch 1 taken 13 times.
13 Fw::Success status = EventSeverityFilter::fromIndex(static_cast<FwSizeType>(filterLevel.e), logSeverity);
106
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 13 times.
13 if (status != Fw::Success::SUCCESS) {
107 this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::VALIDATION_ERROR);
108 return;
109 }
110
2/2
✓ Branch 1 taken 13 times.
✓ Branch 4 taken 13 times.
13 this->m_severityFilter.setFilter(logSeverity, filterEnable.e == Enabled::ENABLED);
111
2/2
✓ Branch 1 taken 13 times.
✓ Branch 4 taken 13 times.
13 this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
112 13 }
113
114 void EventManager::SET_ID_FILTER_cmdHandler(FwOpcodeType opCode, //!< The opcode
115 U32 cmdSeq, //!< The command sequence number
116 FwEventIdType ID,
117 const Enabled& idEnabled //!< ID filter state
118 ) {
119 if (Enabled::ENABLED == idEnabled.e) { // add ID
120 this->m_idFilterLock.lock();
121 const Fw::Success insertStatus = m_filteredIDs.insert(ID);
122 this->m_idFilterLock.unLock();
123 if (insertStatus == Fw::Success::SUCCESS) {
124 this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
125 this->log_ACTIVITY_HI_ID_FILTER_ENABLED(ID);
126 } else {
127 // if an empty slot was not found, send an error event
128 this->log_WARNING_LO_ID_FILTER_LIST_FULL(ID);
129 this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::EXECUTION_ERROR);
130 }
131 } else { // remove ID
132 this->m_idFilterLock.lock();
133 const Fw::Success removeStatus = m_filteredIDs.remove(ID);
134 this->m_idFilterLock.unLock();
135 if (removeStatus == Fw::Success::SUCCESS) {
136 this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
137 this->log_ACTIVITY_HI_ID_FILTER_REMOVED(ID);
138 } else {
139 // Entry wasn't found
140 this->log_WARNING_LO_ID_FILTER_NOT_FOUND(ID);
141 this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::EXECUTION_ERROR);
142 }
143 }
144 }
145
146 void EventManager::DUMP_FILTER_STATE_cmdHandler(FwOpcodeType opCode, //!< The opcode
147 U32 cmdSeq //!< The command sequence number
148 ) {
149 // first, iterate through severity filters
150 for (FwEnumStoreType filter = 0; filter < FilterSeverity::NUM_CONSTANTS; filter++) {
151 FilterSeverity filterState(static_cast<FilterSeverity::t>(filter));
152 Fw::LogSeverity logSeverity;
153 Fw::Success status = EventSeverityFilter::fromIndex(static_cast<FwSizeType>(filter), logSeverity);
154 FW_ASSERT(status == Fw::Success::SUCCESS, static_cast<FwAssertArgType>(filter));
155 this->log_ACTIVITY_LO_SEVERITY_FILTER_STATE(filterState, this->m_severityFilter.isEnabled(logSeverity));
156 }
157
158 // Snapshot the ID filter under the lock; log after release since LogRecv is
159 // a sync input that may re-enter this component and take the same lock
160 FwEventIdType filteredIDs[TELEM_ID_FILTER_SIZE];
161 FwSizeType numFilteredIDs = 0;
162 this->m_idFilterLock.lock();
163 for (FwEventIdType ID : m_filteredIDs) {
164 FW_ASSERT(numFilteredIDs < TELEM_ID_FILTER_SIZE, static_cast<FwAssertArgType>(numFilteredIDs));
165 filteredIDs[numFilteredIDs] = ID;
166 numFilteredIDs++;
167 }
168 this->m_idFilterLock.unLock();
169 for (FwSizeType i = 0; i < numFilteredIDs; i++) {
170 this->log_ACTIVITY_HI_ID_FILTER_ENABLED(filteredIDs[i]);
171 }
172
173 this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
174 }
175
176 59 void EventManager::run_handler(FwIndexType portNum, U32 context) {
177
3/3
✓ Branch 1 taken 59 times.
✓ Branch 4 taken 59 times.
✓ Branch 7 taken 59 times.
59 this->tlmWrite_EventsDropped(this->getNumMsgsDropped());
178 59 }
179
180 59 void EventManager::pingIn_handler(const FwIndexType portNum, U32 key) {
181 // return key
182 59 this->pingOut_out(0, key);
183 59 }
184
185 } // namespace Svc
186