GCC Code Coverage Report


Directory: ./
File: Os/DelegateRawTime.cpp
Date: 2026-09-23 21:11:01
Exec Total Coverage
Lines: 64 66 97.0%
Functions: 15 15 100.0%
Branches: 22 25 88.0%

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 101517 times.
101517 DelegateRawTime::DelegateRawTime() : m_delegate(*RawTimeInterface::getDelegate(m_handle_storage)) {
12 101517 FW_ASSERT(&this->m_delegate == reinterpret_cast<RawTimeInterface*>(&this->m_handle_storage[0]));
13 101517 }
14
15 57 DelegateRawTime::DelegateRawTime(RawTimeSource source)
16
1/1
✓ Branch 9 taken 57 times.
57 : m_delegate(*RawTimeInterface::getDelegate(m_handle_storage, nullptr, source)), m_source(source) {
17 57 FW_ASSERT(&this->m_delegate == reinterpret_cast<RawTimeInterface*>(&this->m_handle_storage[0]));
18 57 }
19
20 203156 DelegateRawTime::~DelegateRawTime() {
21 203154 FW_ASSERT(&this->m_delegate == reinterpret_cast<RawTimeInterface*>(&this->m_handle_storage[0]));
22 203154 m_delegate.~RawTimeInterface();
23 203156 }
24
25 // m_handle_storage is placement-new storage populated by getDelegate below
26 // cppcheck-suppress missingMemberCopy
27 3 DelegateRawTime::DelegateRawTime(const DelegateRawTime& other)
28
1/1
✓ Branch 11 taken 3 times.
3 : m_delegate(*RawTimeInterface::getDelegate(m_handle_storage, &other.m_delegate, other.m_source)),
29 6 m_source(other.m_source) {
30 3 FW_ASSERT(&this->m_delegate == reinterpret_cast<RawTimeInterface*>(&this->m_handle_storage[0]));
31 3 }
32
33 790 DelegateRawTime& DelegateRawTime::operator=(const DelegateRawTime& other) {
34
1/2
✓ Branch 0 taken 790 times.
✗ Branch 1 not taken.
790 if (this != &other) {
35 790 this->m_source = other.m_source;
36 790 this->m_delegate = *RawTimeInterface::getDelegate(m_handle_storage, &other.m_delegate, other.m_source);
37 }
38 790 return *this;
39 }
40
41 6032 RawTimeHandle* DelegateRawTime::getHandle() {
42 6032 FW_ASSERT(&this->m_delegate == reinterpret_cast<RawTimeInterface*>(&this->m_handle_storage[0]));
43 6032 return this->m_delegate.getHandle();
44 }
45
46 1176 DelegateRawTime::Status DelegateRawTime::now() {
47 1176 FW_ASSERT(&this->m_delegate == reinterpret_cast<RawTimeInterface*>(&this->m_handle_storage[0]));
48 1176 return this->m_delegate.now();
49 }
50
51 738 DelegateRawTime::Status DelegateRawTime::getTimeInterval(const Os::RawTime& other, Fw::TimeInterval& result) const {
52 738 FW_ASSERT(&this->m_delegate == reinterpret_cast<const RawTimeInterface*>(&this->m_handle_storage[0]));
53 738 return this->m_delegate.getTimeInterval(other, result);
54 }
55
56 762 Fw::SerializeStatus DelegateRawTime::serializeTo(Fw::SerialBufferBase& buffer, Fw::Endianness mode) const {
57 762 FW_ASSERT(&this->m_delegate == reinterpret_cast<const RawTimeInterface*>(&this->m_handle_storage[0]));
58 762 return this->m_delegate.serializeTo(buffer, mode);
59 }
60
61 717 Fw::SerializeStatus DelegateRawTime::deserializeFrom(Fw::SerialBufferBase& buffer, Fw::Endianness mode) {
62 717 FW_ASSERT(&this->m_delegate == reinterpret_cast<const RawTimeInterface*>(&this->m_handle_storage[0]));
63 717 return this->m_delegate.deserializeFrom(buffer, mode);
64 }
65
66 2997 DelegateRawTime::Status DelegateRawTime::getDiffUsec(const RawTime& other, U32& result) const {
67 2997 FW_ASSERT(&this->m_delegate == reinterpret_cast<const RawTimeInterface*>(&this->m_handle_storage[0]));
68 2997 return this->m_delegate.getDiffUsec(other, result);
69 }
70
71 1543 bool DelegateRawTime::operator==(const RawTime& other) const {
72 1543 FW_ASSERT(&this->m_delegate == reinterpret_cast<const RawTimeInterface*>(&this->m_handle_storage[0]));
73 1543 return this->m_delegate == other;
74 }
75
76 10 RawTimeSource DelegateRawTime::getSource() const {
77 10 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 2997 RawTimeInterface::Status RawTimeInterface::getDiffUsec(const RawTime& other, U32& result) const {
87
1/1
✓ Branch 2 taken 2997 times.
2997 Fw::TimeInterval interval;
88
1/1
✓ Branch 7 taken 2997 times.
2997 Status status = this->getTimeInterval(other, interval);
89
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2996 times.
2997 if (status != Status::OP_OK) {
90 1 return status;
91 }
92
93 // Check overflows in computation
94
1/1
✓ Branch 2 taken 2996 times.
2996 U32 seconds = interval.getSeconds();
95
1/1
✓ Branch 2 taken 2996 times.
2996 U32 useconds = interval.getUSeconds();
96
2/2
✓ Branch 0 taken 757 times.
✓ Branch 1 taken 2239 times.
2996 if (seconds > (std::numeric_limits<U32>::max() / 1000000)) {
97 757 result = std::numeric_limits<U32>::max();
98 757 return Status::OP_OVERFLOW;
99 }
100 2239 U32 secToUsec = seconds * 1000000;
101
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2239 times.
2239 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 2239 result = secToUsec + useconds;
107 2239 return status;
108 2997 }
109
110 1543 bool RawTimeInterface::operator==(const RawTime& other) const {
111
1/1
✓ Branch 2 taken 1543 times.
1543 Fw::TimeInterval interval;
112
1/1
✓ Branch 7 taken 1543 times.
1543 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
7/8
✓ Branch 0 taken 1542 times.
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1542 times.
✓ Branch 6 taken 772 times.
✓ Branch 7 taken 770 times.
✓ Branch 10 taken 772 times.
✓ Branch 12 taken 772 times.
✗ Branch 13 not taken.
3086 return status == Status::OP_OK && interval.getSeconds() == 0 && interval.getUSeconds() == 0;
117 1543 }
118
119 } // namespace Os
120