GCC Code Coverage Report


Directory: Svc/EventManager/
File: EventManager.cpp
Date: 2026-09-03 21:17:41
Exec Total Coverage
Lines: 84 94 89.4%
Functions: 8 9 88.9%
Branches: 100 114 87.7%

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 11 taken 7 times.
✓ Branch 17 taken 7 times.
✓ Branch 23 taken 7 times.
✓ Branch 29 taken 7 times.
✓ Branch 35 taken 7 times.
7 EventManager::EventManager(const char* name) : EventManagerComponentBase(name), m_severityFilter() {
20 // set filter defaults
21
2/2
✓ Branch 5 taken 7 times.
✓ Branch 8 taken 7 times.
7 this->m_severityFilter.setFilter(Fw::LogSeverity::WARNING_HI, FILTER_WARNING_HI_DEFAULT);
22
2/2
✓ Branch 5 taken 7 times.
✓ Branch 8 taken 7 times.
7 this->m_severityFilter.setFilter(Fw::LogSeverity::WARNING_LO, FILTER_WARNING_LO_DEFAULT);
23
2/2
✓ Branch 5 taken 7 times.
✓ Branch 8 taken 7 times.
7 this->m_severityFilter.setFilter(Fw::LogSeverity::COMMAND, FILTER_COMMAND_DEFAULT);
24
2/2
✓ Branch 5 taken 7 times.
✓ Branch 8 taken 7 times.
7 this->m_severityFilter.setFilter(Fw::LogSeverity::ACTIVITY_HI, FILTER_ACTIVITY_HI_DEFAULT);
25
2/2
✓ Branch 5 taken 7 times.
✓ Branch 8 taken 7 times.
7 this->m_severityFilter.setFilter(Fw::LogSeverity::ACTIVITY_LO, FILTER_ACTIVITY_LO_DEFAULT);
26
2/2
✓ Branch 5 taken 7 times.
✓ Branch 8 taken 7 times.
7 this->m_severityFilter.setFilter(Fw::LogSeverity::DIAGNOSTIC, FILTER_DIAGNOSTIC_DEFAULT);
27 7 }
28
29 14 EventManager::~EventManager() {}
30
31 54 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 4 taken 54 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 54 times.
54 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 return;
42 }
43
44 // Check severity filter (FATAL always passes through)
45
4/4
✓ Branch 5 taken 54 times.
✓ Branch 8 taken 54 times.
✓ Branch 13 taken 6 times.
✓ Branch 14 taken 48 times.
54 if (this->m_severityFilter.isFiltered(severity)) {
46 6 return;
47 }
48
49 // check ID filters
50
1/1
✓ Branch 6 taken 48 times.
48 this->m_idFilterLock.lock();
51
1/1
✓ Branch 4 taken 48 times.
48 Fw::Success findStatus = m_filteredIDs.find(id);
52
1/1
✓ Branch 6 taken 48 times.
48 this->m_idFilterLock.unLock();
53
6/6
✓ Branch 2 taken 26 times.
✓ Branch 3 taken 22 times.
✓ Branch 8 taken 25 times.
✓ Branch 9 taken 1 times.
✓ Branch 10 taken 25 times.
✓ Branch 11 taken 23 times.
48 if ((findStatus == Fw::Success::SUCCESS) && (severity != Fw::LogSeverity::FATAL)) {
54 25 return;
55 }
56
57 // send event to the logger thread
58
1/1
✓ Branch 7 taken 23 times.
23 this->loqQueue_internalInterfaceInvoke(id, timeTag, severity, args);
59
60 // if connected, announce the FATAL
61
3/4
✗ Branch 3 not taken.
✓ Branch 4 taken 23 times.
✓ Branch 5 taken 3 times.
✓ Branch 6 taken 20 times.
23 if (Fw::LogSeverity::FATAL == severity.e) {
62
2/3
✓ Branch 5 taken 3 times.
✓ Branch 7 taken 3 times.
✗ Branch 8 not taken.
3 if (this->isConnected_FatalAnnounce_OutputPort(0)) {
63
1/1
✓ Branch 5 taken 3 times.
3 this->FatalAnnounce_out(0, id);
64 }
65 }
66 48 }
67
68 20 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 20 this->m_logPacket.setId(id);
74 20 this->m_logPacket.setTimeTag(timeTag);
75 20 this->m_logPacket.setLogBuffer(args);
76 20 this->m_comBuffer.resetSer();
77 20 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 20 times.
20 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 5 taken 20 times.
✗ Branch 6 not taken.
20 if (this->isConnected_PktSend_OutputPort(0)) {
88 20 this->PktSend_out(0, this->m_comBuffer, 0);
89 }
90 }
91
92 30 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 2 taken 30 times.
30 Fw::LogSeverity logSeverity;
105
2/3
✗ Branch 4 not taken.
✓ Branch 5 taken 30 times.
✓ Branch 7 taken 30 times.
30 Fw::Success status = EventSeverityFilter::fromIndex(static_cast<FwSizeType>(filterLevel.e), logSeverity);
106
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 30 times.
30 if (status != Fw::Success::SUCCESS) {
107 this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::VALIDATION_ERROR);
108 return;
109 }
110
3/4
✗ Branch 6 not taken.
✓ Branch 7 taken 30 times.
✓ Branch 10 taken 30 times.
✓ Branch 13 taken 30 times.
30 this->m_severityFilter.setFilter(logSeverity, filterEnable.e == Enabled::ENABLED);
111
2/2
✓ Branch 6 taken 30 times.
✓ Branch 9 taken 30 times.
30 this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
112 30 }
113
114 80 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
3/4
✗ Branch 3 not taken.
✓ Branch 4 taken 80 times.
✓ Branch 5 taken 54 times.
✓ Branch 6 taken 26 times.
80 if (Enabled::ENABLED == idEnabled.e) { // add ID
120
1/1
✓ Branch 6 taken 54 times.
54 this->m_idFilterLock.lock();
121
1/1
✓ Branch 4 taken 54 times.
54 const Fw::Success insertStatus = m_filteredIDs.insert(ID);
122
1/1
✓ Branch 6 taken 54 times.
54 this->m_idFilterLock.unLock();
123
2/2
✓ Branch 2 taken 53 times.
✓ Branch 3 taken 1 times.
54 if (insertStatus == Fw::Success::SUCCESS) {
124
2/2
✓ Branch 6 taken 53 times.
✓ Branch 9 taken 53 times.
53 this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
125
1/1
✓ Branch 5 taken 53 times.
53 this->log_ACTIVITY_HI_ID_FILTER_ENABLED(ID);
126 } else {
127 // if an empty slot was not found, send an error event
128
1/1
✓ Branch 5 taken 1 times.
1 this->log_WARNING_LO_ID_FILTER_LIST_FULL(ID);
129
2/2
✓ Branch 6 taken 1 times.
✓ Branch 9 taken 1 times.
1 this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::EXECUTION_ERROR);
130 }
131 54 } else { // remove ID
132
1/1
✓ Branch 6 taken 26 times.
26 this->m_idFilterLock.lock();
133
1/1
✓ Branch 4 taken 26 times.
26 const Fw::Success removeStatus = m_filteredIDs.remove(ID);
134
1/1
✓ Branch 6 taken 26 times.
26 this->m_idFilterLock.unLock();
135
2/2
✓ Branch 2 taken 25 times.
✓ Branch 3 taken 1 times.
26 if (removeStatus == Fw::Success::SUCCESS) {
136
2/2
✓ Branch 6 taken 25 times.
✓ Branch 9 taken 25 times.
25 this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
137
1/1
✓ Branch 5 taken 25 times.
25 this->log_ACTIVITY_HI_ID_FILTER_REMOVED(ID);
138 } else {
139 // Entry wasn't found
140
1/1
✓ Branch 5 taken 1 times.
1 this->log_WARNING_LO_ID_FILTER_NOT_FOUND(ID);
141
2/2
✓ Branch 6 taken 1 times.
✓ Branch 9 taken 1 times.
1 this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::EXECUTION_ERROR);
142 }
143 26 }
144 80 }
145
146 1 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
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1 times.
7 for (FwEnumStoreType filter = 0; filter < FilterSeverity::NUM_CONSTANTS; filter++) {
151
1/1
✓ Branch 2 taken 6 times.
6 FilterSeverity filterState(static_cast<FilterSeverity::t>(filter));
152
1/1
✓ Branch 2 taken 6 times.
6 Fw::LogSeverity logSeverity;
153
1/1
✓ Branch 2 taken 6 times.
6 Fw::Success status = EventSeverityFilter::fromIndex(static_cast<FwSizeType>(filter), logSeverity);
154 6 FW_ASSERT(status == Fw::Success::SUCCESS, static_cast<FwAssertArgType>(filter));
155
3/3
✓ Branch 9 taken 6 times.
✓ Branch 12 taken 6 times.
✓ Branch 15 taken 6 times.
6 this->log_ACTIVITY_LO_SEVERITY_FILTER_STATE(filterState, this->m_severityFilter.isEnabled(logSeverity));
156 6 }
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 1 FwEventIdType filteredIDs[TELEM_ID_FILTER_SIZE];
161 1 FwSizeType numFilteredIDs = 0;
162
1/1
✓ Branch 6 taken 1 times.
1 this->m_idFilterLock.lock();
163
6/6
✓ Branch 5 taken 1 times.
✓ Branch 9 taken 1 times.
✓ Branch 12 taken 3 times.
✓ Branch 16 taken 4 times.
✓ Branch 18 taken 3 times.
✓ Branch 19 taken 1 times.
4 for (FwEventIdType ID : m_filteredIDs) {
164 3 FW_ASSERT(numFilteredIDs < TELEM_ID_FILTER_SIZE, static_cast<FwAssertArgType>(numFilteredIDs));
165 3 filteredIDs[numFilteredIDs] = ID;
166
1/1
✓ Branch 1 taken 3 times.
3 numFilteredIDs++;
167 1 }
168
1/1
✓ Branch 6 taken 1 times.
1 this->m_idFilterLock.unLock();
169
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
4 for (FwSizeType i = 0; i < numFilteredIDs; i++) {
170
1/1
✓ Branch 8 taken 3 times.
3 this->log_ACTIVITY_HI_ID_FILTER_ENABLED(filteredIDs[i]);
171 }
172
173
2/2
✓ Branch 6 taken 1 times.
✓ Branch 9 taken 1 times.
1 this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
174 1 }
175
176 2 void EventManager::run_handler(FwIndexType portNum, U32 context) {
177
3/3
✓ Branch 6 taken 2 times.
✓ Branch 13 taken 2 times.
✓ Branch 16 taken 2 times.
2 this->tlmWrite_EventsDropped(this->getNumMsgsDropped());
178 2 }
179
180 void EventManager::pingIn_handler(const FwIndexType portNum, U32 key) {
181 // return key
182 this->pingOut_out(0, key);
183 }
184
185 } // namespace Svc
186