GCC Code Coverage Report


Directory: ./
File: Os/DelegateRawTime.cpp
Date: 2026-09-03 21:13:48
Exec Total Coverage
Lines: 63 66 95.5%
Functions: 15 15 100.0%
Branches: 25 35 71.4%

Line Branch Exec Source
1 // ======================================================================
2 // \title Os/DelegateRawTime.cpp
3 // \brief common function implementation for Os::RawTimeInterface and Os::DelegateRawTime
4 // ======================================================================
5 #include <Fw/Types/Assert.hpp>
6 #include <Os/DelegateRawTime.hpp>
7 #include <Os/RawTime.hpp>
8
9 namespace Os {
10
11
1/1
✓ Branch 11 taken 101509 times.
101509 DelegateRawTime::DelegateRawTime() : m_delegate(*RawTimeInterface::getDelegate(m_handle_storage)) {
12 101509 FW_ASSERT(&this->m_delegate == reinterpret_cast<RawTimeInterface*>(&this->m_handle_storage[0]));
13 101509 }
14
15 48 DelegateRawTime::DelegateRawTime(RawTimeSource source)
16
1/1
✓ Branch 9 taken 48 times.
48 : m_delegate(*RawTimeInterface::getDelegate(m_handle_storage, nullptr, source)), m_source(source) {
17 48 FW_ASSERT(&this->m_delegate == reinterpret_cast<RawTimeInterface*>(&this->m_handle_storage[0]));
18 48 }
19
20 203120 DelegateRawTime::~DelegateRawTime() {
21 203118 FW_ASSERT(&this->m_delegate == reinterpret_cast<RawTimeInterface*>(&this->m_handle_storage[0]));
22 203118 m_delegate.~RawTimeInterface();
23 203120 }
24
25 // m_handle_storage is placement-new storage populated by getDelegate below
26 // cppcheck-suppress missingMemberCopy
27 2 DelegateRawTime::DelegateRawTime(const DelegateRawTime& other)
28
2/3
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✓ Branch 12 taken 2 times.
2 : m_delegate(*RawTimeInterface::getDelegate(m_handle_storage, &other.m_delegate, other.m_source)),
29
1/2
✗ Branch 11 not taken.
✓ Branch 12 taken 2 times.
4 m_source(other.m_source) {
30 2 FW_ASSERT(&this->m_delegate == reinterpret_cast<RawTimeInterface*>(&this->m_handle_storage[0]));
31 2 }
32
33 763 DelegateRawTime& DelegateRawTime::operator=(const DelegateRawTime& other) {
34
1/2
✓ Branch 0 taken 763 times.
✗ Branch 1 not taken.
763 if (this != &other) {
35
1/2
✗ Branch 5 not taken.
✓ Branch 6 taken 763 times.
763 this->m_source = other.m_source;
36
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 763 times.
763 this->m_delegate = *RawTimeInterface::getDelegate(m_handle_storage, &other.m_delegate, other.m_source);
37 }
38 763 return *this;
39 }
40
41 8008 RawTimeHandle* DelegateRawTime::getHandle() {
42 8008 FW_ASSERT(&this->m_delegate == reinterpret_cast<RawTimeInterface*>(&this->m_handle_storage[0]));
43 8008 return this->m_delegate.getHandle();
44 }
45
46 1104 DelegateRawTime::Status DelegateRawTime::now() {
47 1104 FW_ASSERT(&this->m_delegate == reinterpret_cast<RawTimeInterface*>(&this->m_handle_storage[0]));
48 1104 return this->m_delegate.now();
49 }
50
51 743 DelegateRawTime::Status DelegateRawTime::getTimeInterval(const Os::RawTime& other, Fw::TimeInterval& result) const {
52 743 FW_ASSERT(&this->m_delegate == reinterpret_cast<const RawTimeInterface*>(&this->m_handle_storage[0]));
53 743 return this->m_delegate.getTimeInterval(other, result);
54 }
55
56 814 Fw::SerializeStatus DelegateRawTime::serializeTo(Fw::SerialBufferBase& buffer, Fw::Endianness mode) const {
57 814 FW_ASSERT(&this->m_delegate == reinterpret_cast<const RawTimeInterface*>(&this->m_handle_storage[0]));
58 814 return this->m_delegate.serializeTo(buffer, mode);
59 }
60
61 769 Fw::SerializeStatus DelegateRawTime::deserializeFrom(Fw::SerialBufferBase& buffer, Fw::Endianness mode) {
62 769 FW_ASSERT(&this->m_delegate == reinterpret_cast<const RawTimeInterface*>(&this->m_handle_storage[0]));
63 769 return this->m_delegate.deserializeFrom(buffer, mode);
64 }
65
66 3076 DelegateRawTime::Status DelegateRawTime::getDiffUsec(const RawTime& other, U32& result) const {
67 3076 FW_ASSERT(&this->m_delegate == reinterpret_cast<const RawTimeInterface*>(&this->m_handle_storage[0]));
68 3076 return this->m_delegate.getDiffUsec(other, result);
69 }
70
71 1488 bool DelegateRawTime::operator==(const RawTime& other) const {
72 1488 FW_ASSERT(&this->m_delegate == reinterpret_cast<const RawTimeInterface*>(&this->m_handle_storage[0]));
73 1488 return this->m_delegate == other;
74 }
75
76 4 RawTimeSource DelegateRawTime::getSource() const {
77
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
4 return this->m_source;
78 }
79
80 // ------------------------------------------------------------
81 // RawTimeInterface default implementations
82 // Built on pure virtual methods. Located here (not RawTimeInterface.cpp)
83 // to keep RawTime implementation code in one translation unit.
84 // ------------------------------------------------------------
85
86 3076 RawTimeInterface::Status RawTimeInterface::getDiffUsec(const RawTime& other, U32& result) const {
87
1/1
✓ Branch 2 taken 3076 times.
3076 Fw::TimeInterval interval;
88
1/1
✓ Branch 7 taken 3076 times.
3076 Status status = this->getTimeInterval(other, interval);
89
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3076 times.
3076 if (status != Status::OP_OK) {
90 return status;
91 }
92
93 // Check overflows in computation
94
1/1
✓ Branch 2 taken 3076 times.
3076 U32 seconds = interval.getSeconds();
95
1/1
✓ Branch 2 taken 3076 times.
3076 U32 useconds = interval.getUSeconds();
96
2/2
✓ Branch 0 taken 725 times.
✓ Branch 1 taken 2351 times.
3076 if (seconds > (std::numeric_limits<U32>::max() / 1000000)) {
97 725 result = std::numeric_limits<U32>::max();
98 725 return Status::OP_OVERFLOW;
99 }
100 2351 U32 secToUsec = seconds * 1000000;
101
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2351 times.
2351 if (secToUsec > (std::numeric_limits<U32>::max() - useconds)) {
102 result = std::numeric_limits<U32>::max();
103 return Status::OP_OVERFLOW;
104 }
105 // No overflow, we can safely add values to get total microseconds
106 2351 result = secToUsec + useconds;
107 2351 return status;
108 3076 }
109
110 1488 bool RawTimeInterface::operator==(const RawTime& other) const {
111
1/1
✓ Branch 2 taken 1488 times.
1488 Fw::TimeInterval interval;
112
1/1
✓ Branch 7 taken 1488 times.
1488 Status status = this->getTimeInterval(other, interval);
113 // If we error out, then the values are either:
114 // 1) impossible to compare, in which case it's perfectly reasonable to consider them different, or
115 // 2) too far apart to fit in a TimeInterval, in which case they are definitely different
116
6/8
✓ Branch 0 taken 1488 times.
✗ Branch 1 not taken.
✓ Branch 4 taken 1488 times.
✓ Branch 6 taken 744 times.
✓ Branch 7 taken 744 times.
✓ Branch 10 taken 744 times.
✓ Branch 12 taken 744 times.
✗ Branch 13 not taken.
2976 return status == Status::OP_OK && interval.getSeconds() == 0 && interval.getUSeconds() == 0;
117 1488 }
118
119 } // namespace Os
120