GCC Code Coverage Report


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