GCC Code Coverage Report


Directory: ./
File: Fw/Port/PortBase.cpp
Date: 2026-09-23 21:11:01
Exec Total Coverage
Lines: 18 48 37.5%
Functions: 5 10 50.0%
Branches: 5 22 22.7%

Line Branch Exec Source
1 #include <Fw/FPrimeBasicTypes.hpp>
2 #include <Fw/Logger/Logger.hpp>
3 #include <Fw/Port/PortBase.hpp>
4 #include <cstdio>
5 #include "Fw/Types/Assert.hpp"
6 #include "Fw/Types/ExternalString.hpp"
7
8 #if FW_PORT_TRACING
9 ✗ void setConnTrace(bool trace) {
10 ✗ Fw::PortBase::setTrace(trace);
11 ✗ }
12
13 namespace Fw {
14 bool PortBase::s_trace = false;
15 }
16
17 #endif // FW_PORT_TRACING
18
19 namespace Fw {
20
21 70778 PortBase::PortBase()
22 : Fw::ObjBase(nullptr),
23 70778 m_connObj(nullptr)
24 #if FW_PORT_TRACING == 1
25 ,
26 70778 m_trace(false),
27 141556 m_ovr_trace(false)
28 #endif
29 {
30 70778 }
31
32 141556 PortBase::~PortBase() {}
33
34 70400 void PortBase::init() {
35 70400 ObjBase::init();
36 70400 }
37
38 3163293 bool PortBase::isConnected() const {
39 3163293 return m_connObj == nullptr ? false : true;
40 }
41
42 #if FW_PORT_TRACING == 1
43
44 2007140 void PortBase::trace() const {
45 // Ports are only traced as part of invocation, which requires a connection
46 2007140 FW_ASSERT(this->isConnected());
47 2007140 bool do_trace = false;
48
49
2/4
✗ Branch 3 not taken.
✓ Branch 4 taken 2007140 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2007140 times.
2007140 if (this->m_ovr_trace) {
50 ✗ if (this->m_trace) {
51 ✗ do_trace = true;
52 }
53
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2007140 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2007140 times.
2007140 } else if (PortBase::s_trace) {
54 ✗ do_trace = true;
55 }
56
57
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2007140 times.
2007140 if (do_trace) {
58 #if FW_OBJECT_NAMES == 1
59 ✗ Fw::Logger::log("Trace: %s\n", this->m_objName.toChar());
60 #else
61 Fw::Logger::log("Trace: %p\n", this);
62 #endif
63 }
64 2007140 }
65
66 ✗ void PortBase::setTrace(bool trace) {
67 ✗ PortBase::s_trace = trace;
68 ✗ }
69
70 ✗ void PortBase::ovrTrace(bool ovr, bool trace) {
71 ✗ this->m_ovr_trace = ovr;
72 ✗ this->m_trace = trace;
73 ✗ }
74
75 #endif // FW_PORT_TRACING
76
77 #if FW_OBJECT_TO_STRING == 1
78 ✗ const char* PortBase::getToStringFormatString() {
79 ✗ return "Port: %s %s->(%s)";
80 }
81
82 ✗ void PortBase::toString(char* buffer, FwSizeType size) {
83 ✗ FW_ASSERT(size > 0);
84 ✗ FW_ASSERT(buffer != nullptr);
85 // Get the port-custom format string
86 ✗ const char* formatString = this->getToStringFormatString();
87 // Determine this port object name (or use "UNKNOWN")
88 const char* object_name =
89 #if FW_OBJECT_NAMES == 1
90 ✗ this->m_objName.toChar();
91 #else
92 "UNKNOWN";
93 #endif
94 // Get the C/NC for connected or not
95 ✗ const char* this_is_connected = this->isConnected() ? "C" : "NC";
96
97 // Get the name of the connection object, "UNKNOWN" or "NONE"
98 ✗ const char* connected_to = this->isConnected() ?
99 #if FW_OBJECT_NAMES == 1
100 ✗ this->m_connObj->getObjName()
101 #else
102 "UNKNOWN"
103 #endif
104 ✗ : "None";
105 // Format the external string or use "" on error
106 ✗ const Fw::FormatStatus formatStatus = Fw::ExternalString(buffer, static_cast<Fw::ExternalString::SizeType>(size))
107 ✗ .format(formatString, object_name, this_is_connected, connected_to);
108 ✗ if (formatStatus != Fw::FormatStatus::SUCCESS) {
109 ✗ buffer[0] = 0;
110 }
111 ✗ }
112 #endif // FW_OBJECT_TO_STRING
113
114 } // namespace Fw
115