GCC Code Coverage Report


Directory: ./
File: Svc/Version/Version.cpp
Date: 2026-11-03 21:15:54
Exec Total Coverage
Lines: 166 172 96.5%
Functions: 14 14 100.0%
Branches: 134 148 90.5%

Line Branch Exec Source
1 // ======================================================================
2 // \title Version.cpp
3 // \author sreddy
4 // \brief cpp file for Version component implementation class
5 // ======================================================================
6
7 #include "Svc/Version/Version.hpp"
8 #include "Fw/FPrimeBasicTypes.hpp"
9
10 #include "versions/version.hpp" //autogenerated file containing hardcoded project and framework versions
11
12 namespace Svc {
13
14 // ----------------------------------------------------------------------
15 // Component construction and destruction
16 // ----------------------------------------------------------------------
17
18 7 Version ::Version(const char* const compName)
19
3/9
✓ Branch 9 taken 70 times.
✓ Branch 12 taken 70 times.
✓ Branch 13 taken 7 times.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
77 : VersionComponentBase(compName), m_enable(false), m_num_custom_elements(0) {
20
1/1
✓ Branch 2 taken 7 times.
7 Fw::String version_string = "no_ver";
21 // initialize all custom entries
22
2/2
✓ Branch 0 taken 70 times.
✓ Branch 1 taken 7 times.
77 for (FwIndexType id = 0; id < Svc::VersionCfg::VersionEnum::NUM_CONSTANTS; id++) {
23 // setVersion_enum is by default set to the first enum value, so not setting it here
24
1/1
✓ Branch 7 taken 70 times.
70 this->verId_db[id].set_version_value(version_string);
25
1/1
✓ Branch 7 taken 70 times.
70 this->verId_db[id].set_version_status(VersionStatus::FAILURE);
26 }
27 14 }
28
29
3/4
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
✓ Branch 11 taken 70 times.
✓ Branch 12 taken 7 times.
154 Version ::~Version() {}
30
31 1 void Version::config(bool enable) {
32 // Set Verbosity for custom versions
33 1 this->m_enable = enable;
34 1 }
35
36 1 void Version::start() {
37 // Send startup TLM and EVENTS
38 1 this->fwVersion_tlm();
39 1 this->projectVersion_tlm();
40 1 this->libraryVersion_tlm();
41 1 }
42 // ----------------------------------------------------------------------
43 // Handler implementations for user-defined typed input ports
44 // ----------------------------------------------------------------------
45
46 6 void Version ::getVersion_handler(FwIndexType portNum,
47 const Svc::VersionCfg::VersionEnum& version_id,
48 Fw::StringBase& version_string,
49 Svc::VersionStatus& status) {
50 6 FW_ASSERT(version_id.isValid(), version_id.e);
51 6 FW_ASSERT(static_cast<Svc::VersionCfg::VersionEnum::SerialType>(version_id.e) <
52 Svc::VersionCfg::VersionEnum::NUM_CONSTANTS,
53 version_id.e);
54
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
6 U8 version_slot = VersionSlot(version_id.e);
55 6 version_string = static_cast<const Fw::StringBase&>(this->verId_db[version_slot].get_version_value());
56 6 status = this->verId_db[version_slot].get_version_status();
57 6 }
58
59 354 void Version ::setVersion_handler(FwIndexType portNum,
60 const Svc::VersionCfg::VersionEnum& version_id,
61 Fw::StringBase& version_string,
62 Svc::VersionStatus& status) {
63 354 FW_ASSERT(version_id.isValid(), version_id.e);
64 354 FW_ASSERT(static_cast<Svc::VersionCfg::VersionEnum::SerialType>(version_id.e) <
65 Svc::VersionCfg::VersionEnum::NUM_CONSTANTS,
66 version_id.e);
67
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 354 times.
354 auto ver_slot = VersionSlot(version_id.e);
68 // Count each slot once: rewrites of a populated slot must not grow the count
69
4/4
✓ Branch 12 taken 35 times.
✓ Branch 13 taken 319 times.
✓ Branch 14 taken 35 times.
✓ Branch 15 taken 319 times.
389 if ((this->verId_db[ver_slot].get_version_value() == "no_ver") &&
70
1/2
✓ Branch 4 taken 35 times.
✗ Branch 5 not taken.
35 (this->m_num_custom_elements < Svc::VersionCfg::VersionEnum::NUM_CONSTANTS)) {
71 35 this->m_num_custom_elements++;
72 }
73 354 this->verId_db[ver_slot].set_version_enum(version_id);
74 354 this->verId_db[ver_slot].set_version_value(version_string);
75 354 this->verId_db[ver_slot].set_version_status(status);
76 354 this->customVersion_tlm(ver_slot);
77 354 }
78
79 // Scheduled handler to periodically re-emit all version information (without event spamming)
80 5 void Version ::schedIn_handler(FwIndexType portNum, U32 context) {
81 5 this->projectVersion_tlm(/* sendEvent = */ false);
82 5 this->fwVersion_tlm(/* sendEvent = */ false);
83 5 this->libraryVersion_tlm(/* sendEvent = */ false);
84 5 this->customVersion_tlm_all(/* sendEvent = */ false);
85 5 }
86
87 // ----------------------------------------------------------------------
88 // Handler implementations for commands
89 // ----------------------------------------------------------------------
90
91 9 void Version ::ENABLE_cmdHandler(FwOpcodeType opCode, U32 cmdSeq, const Svc::VersionEnabled& enable) {
92 9 this->m_enable = (enable == VersionEnabled::ENABLED);
93
94
2/2
✓ Branch 6 taken 9 times.
✓ Branch 9 taken 9 times.
9 this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
95 9 }
96
97 // Command handler to event versions
98 11 void Version ::VERSION_cmdHandler(FwOpcodeType opCode, U32 cmdSeq, const Svc::VersionType& version_type) {
99 11 FW_ASSERT(version_type.isValid(), version_type.e);
100
101
5/6
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 5 times.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
11 switch (version_type) {
102 1 case (Svc::VersionType::PROJECT):
103 1 this->projectVersion_tlm();
104 1 break;
105
106 1 case (Svc::VersionType::FRAMEWORK):
107 1 this->fwVersion_tlm();
108 1 break;
109
110 1 case (Svc::VersionType::LIBRARY):
111 1 this->libraryVersion_tlm();
112 1 break;
113
114 5 case (Svc::VersionType::CUSTOM):
115 5 this->customVersion_tlm_all();
116 5 break;
117
118 3 case (Svc::VersionType::ALL):
119 3 this->projectVersion_tlm();
120 3 this->fwVersion_tlm();
121 3 this->libraryVersion_tlm();
122 3 this->customVersion_tlm_all();
123 3 break;
124 ✗ default:
125 ✗ FW_ASSERT(false, version_type);
126 ✗ break;
127 }
128
129
2/2
✓ Branch 6 taken 11 times.
✓ Branch 9 taken 11 times.
11 this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
130 11 }
131 // ----------------------------------------------------------------------
132 // implementations for internal functions
133 // ----------------------------------------------------------------------
134 // Write framework version tlm; also emit the event when sendEvent is true (default in Version.hpp)
135 10 void Version ::fwVersion_tlm(bool sendEvent) {
136
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
10 if (sendEvent) {
137
1/1
✓ Branch 2 taken 5 times.
5 Fw::LogStringArg fw_event = (Project::Version::FRAMEWORK_VERSION);
138
1/1
✓ Branch 5 taken 5 times.
5 this->log_ACTIVITY_LO_FrameworkVersion(fw_event);
139 5 }
140
1/1
✓ Branch 2 taken 10 times.
10 Fw::TlmString fw_tlm = (Project::Version::FRAMEWORK_VERSION);
141
2/2
✓ Branch 6 taken 10 times.
✓ Branch 9 taken 10 times.
10 this->tlmWrite_FrameworkVersion(fw_tlm);
142 20 }
143 // Write project version tlm; also emit the event when sendEvent is true (default in Version.hpp)
144 10 void Version ::projectVersion_tlm(bool sendEvent) {
145
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
10 if (sendEvent) {
146
1/1
✓ Branch 2 taken 5 times.
5 Fw::LogStringArg proj_event = Project::Version::PROJECT_VERSION;
147
1/1
✓ Branch 5 taken 5 times.
5 this->log_ACTIVITY_LO_ProjectVersion(proj_event);
148 5 }
149
1/1
✓ Branch 2 taken 10 times.
10 Fw::TlmString proj_tlm = Project::Version::PROJECT_VERSION;
150
2/2
✓ Branch 6 taken 10 times.
✓ Branch 9 taken 10 times.
10 this->tlmWrite_ProjectVersion(proj_tlm);
151 20 }
152 // Write library version tlm; also emit the event when sendEvent is true (default in Version.hpp)
153 10 void Version ::libraryVersion_tlm(bool sendEvent) {
154 // Process libraries array
155
2/2
✓ Branch 0 taken 120 times.
✓ Branch 1 taken 10 times.
130 for (FwIndexType i = 0; i < Project::Version::LIBRARY_VERSIONS_COUNT; i++) {
156 120 FW_ASSERT(Project::Version::LIBRARY_VERSIONS[i] != nullptr, static_cast<FwAssertArgType>(i));
157 // Write to Events, if enabled via sendEvent function argument
158
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 60 times.
120 if (sendEvent) {
159
2/2
✓ Branch 7 taken 60 times.
✓ Branch 11 taken 60 times.
60 this->log_ACTIVITY_LO_LibraryVersions(Fw::LogStringArg(Project::Version::LIBRARY_VERSIONS[i]));
160 }
161
162 // Emit TLM on library versions
163
11/11
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 10 times.
✓ Branch 4 taken 10 times.
✓ Branch 5 taken 10 times.
✓ Branch 6 taken 10 times.
✓ Branch 7 taken 10 times.
✓ Branch 8 taken 10 times.
✓ Branch 9 taken 10 times.
✓ Branch 10 taken 20 times.
120 switch (i) {
164 10 case VER_SLOT_00:
165
3/3
✓ Branch 6 taken 10 times.
✓ Branch 11 taken 10 times.
✓ Branch 15 taken 10 times.
10 this->tlmWrite_LibraryVersion01(Fw::TlmString(Project::Version::LIBRARY_VERSIONS[i]));
166 10 break;
167 10 case VER_SLOT_01:
168
3/3
✓ Branch 6 taken 10 times.
✓ Branch 11 taken 10 times.
✓ Branch 15 taken 10 times.
10 this->tlmWrite_LibraryVersion02(Fw::TlmString(Project::Version::LIBRARY_VERSIONS[i]));
169 10 break;
170 10 case VER_SLOT_02:
171
3/3
✓ Branch 6 taken 10 times.
✓ Branch 11 taken 10 times.
✓ Branch 15 taken 10 times.
10 this->tlmWrite_LibraryVersion03(Fw::TlmString(Project::Version::LIBRARY_VERSIONS[i]));
172 10 break;
173 10 case VER_SLOT_03:
174
3/3
✓ Branch 6 taken 10 times.
✓ Branch 11 taken 10 times.
✓ Branch 15 taken 10 times.
10 this->tlmWrite_LibraryVersion04(Fw::TlmString(Project::Version::LIBRARY_VERSIONS[i]));
175 10 break;
176 10 case VER_SLOT_04:
177
3/3
✓ Branch 6 taken 10 times.
✓ Branch 11 taken 10 times.
✓ Branch 15 taken 10 times.
10 this->tlmWrite_LibraryVersion05(Fw::TlmString(Project::Version::LIBRARY_VERSIONS[i]));
178 10 break;
179 10 case VER_SLOT_05:
180
3/3
✓ Branch 6 taken 10 times.
✓ Branch 11 taken 10 times.
✓ Branch 15 taken 10 times.
10 this->tlmWrite_LibraryVersion06(Fw::TlmString(Project::Version::LIBRARY_VERSIONS[i]));
181 10 break;
182 10 case VER_SLOT_06:
183
3/3
✓ Branch 6 taken 10 times.
✓ Branch 11 taken 10 times.
✓ Branch 15 taken 10 times.
10 this->tlmWrite_LibraryVersion07(Fw::TlmString(Project::Version::LIBRARY_VERSIONS[i]));
184 10 break;
185 10 case VER_SLOT_07:
186
3/3
✓ Branch 6 taken 10 times.
✓ Branch 11 taken 10 times.
✓ Branch 15 taken 10 times.
10 this->tlmWrite_LibraryVersion08(Fw::TlmString(Project::Version::LIBRARY_VERSIONS[i]));
187 10 break;
188 10 case VER_SLOT_08:
189
3/3
✓ Branch 6 taken 10 times.
✓ Branch 11 taken 10 times.
✓ Branch 15 taken 10 times.
10 this->tlmWrite_LibraryVersion09(Fw::TlmString(Project::Version::LIBRARY_VERSIONS[i]));
190 10 break;
191 10 case VER_SLOT_09:
192
3/3
✓ Branch 6 taken 10 times.
✓ Branch 11 taken 10 times.
✓ Branch 15 taken 10 times.
10 this->tlmWrite_LibraryVersion10(Fw::TlmString(Project::Version::LIBRARY_VERSIONS[i]));
193 10 break;
194 20 default:
195 // It is possible to have more than 10 library versions; however design agreed to only
196 // provide 10 TLM channels for it
197 20 break;
198 }
199 }
200 10 }
201 // Write all custom version tlm; also emit the event when sendEvent is true (default in Version.hpp)
202 13 void Version ::customVersion_tlm_all(bool sendEvent) {
203 // projects may define a maximum of 10 custom slots
204 static_assert(Svc::VersionCfg::VersionEnum::NUM_CONSTANTS <= VER_SLOT_09 + 1,
205 "Svc::Version supports at most 10 custom version slots");
206
4/4
✓ Branch 4 taken 132 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 120 times.
✓ Branch 7 taken 12 times.
133 for (U8 i = 0; (m_num_custom_elements != 0) && (i < Svc::VersionCfg::VersionEnum::NUM_CONSTANTS); i++) {
207 120 this->customVersion_tlm(static_cast<VersionSlot>(i), sendEvent);
208 }
209 13 }
210 // Write custom version tlm; also emit the event when sendEvent is true (default in Version.hpp)
211 474 void Version ::customVersion_tlm(VersionSlot custom_slot, bool sendEvent) {
212 // Process custom version TLM only if verbosity is enabled and there are any valid writes to it;
213 // it doesn't necessarily have to be consecutive
214
4/4
✓ Branch 12 taken 425 times.
✓ Branch 13 taken 49 times.
✓ Branch 14 taken 425 times.
✓ Branch 15 taken 49 times.
899 if ((this->verId_db[custom_slot].get_version_value() != "no_ver") &&
215
1/2
✓ Branch 4 taken 425 times.
✗ Branch 5 not taken.
425 (this->m_num_custom_elements > 0)) { // Write TLM for valid writes
216
217 // Write to Events, if enabled via sendEvent function argument
218
2/2
✓ Branch 0 taken 393 times.
✓ Branch 1 taken 32 times.
425 if (sendEvent) {
219
2/2
✓ Branch 15 taken 393 times.
✓ Branch 19 taken 393 times.
786 this->log_ACTIVITY_LO_CustomVersions(this->verId_db[custom_slot].get_version_enum(),
220 393 this->verId_db[custom_slot].get_version_value());
221 }
222
223
3/4
✗ Branch 3 not taken.
✓ Branch 4 taken 425 times.
✓ Branch 5 taken 399 times.
✓ Branch 6 taken 26 times.
425 if (m_enable == true) { // Send TLM only if verbosity is enabled
224 // Write to TLM
225
10/11
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 310 times.
✓ Branch 4 taken 9 times.
✓ Branch 5 taken 13 times.
✓ Branch 6 taken 9 times.
✓ Branch 7 taken 9 times.
✓ Branch 8 taken 9 times.
✓ Branch 9 taken 9 times.
✗ Branch 10 not taken.
399 switch (custom_slot) {
226 13 case VER_SLOT_00:
227
2/2
✓ Branch 6 taken 13 times.
✓ Branch 13 taken 13 times.
13 this->tlmWrite_CustomVersion01(verId_db[custom_slot]);
228 13 break;
229 9 case VER_SLOT_01:
230
2/2
✓ Branch 6 taken 9 times.
✓ Branch 13 taken 9 times.
9 this->tlmWrite_CustomVersion02(verId_db[custom_slot]);
231 9 break;
232 9 case VER_SLOT_02:
233
2/2
✓ Branch 6 taken 9 times.
✓ Branch 13 taken 9 times.
9 this->tlmWrite_CustomVersion03(verId_db[custom_slot]);
234 9 break;
235 310 case VER_SLOT_03:
236
2/2
✓ Branch 6 taken 310 times.
✓ Branch 13 taken 310 times.
310 this->tlmWrite_CustomVersion04(verId_db[custom_slot]);
237 310 break;
238 9 case VER_SLOT_04:
239
2/2
✓ Branch 6 taken 9 times.
✓ Branch 13 taken 9 times.
9 this->tlmWrite_CustomVersion05(verId_db[custom_slot]);
240 9 break;
241 13 case VER_SLOT_05:
242
2/2
✓ Branch 6 taken 13 times.
✓ Branch 13 taken 13 times.
13 this->tlmWrite_CustomVersion06(verId_db[custom_slot]);
243 13 break;
244 9 case VER_SLOT_06:
245
2/2
✓ Branch 6 taken 9 times.
✓ Branch 13 taken 9 times.
9 this->tlmWrite_CustomVersion07(verId_db[custom_slot]);
246 9 break;
247 9 case VER_SLOT_07:
248
2/2
✓ Branch 6 taken 9 times.
✓ Branch 13 taken 9 times.
9 this->tlmWrite_CustomVersion08(verId_db[custom_slot]);
249 9 break;
250 9 case VER_SLOT_08:
251
2/2
✓ Branch 6 taken 9 times.
✓ Branch 13 taken 9 times.
9 this->tlmWrite_CustomVersion09(verId_db[custom_slot]);
252 9 break;
253 9 case VER_SLOT_09:
254
2/2
✓ Branch 6 taken 9 times.
✓ Branch 13 taken 9 times.
9 this->tlmWrite_CustomVersion10(verId_db[custom_slot]);
255 9 break;
256 ✗ default:
257 // There are only 10 custom slots available
258 ✗ FW_ASSERT(false, custom_slot);
259 ✗ break;
260 }
261 }
262 }
263 474 }
264
265 } // namespace Svc
266