GCC Code Coverage Report


Directory: ./
File: Os/DelegateRawTime.cpp
Date: 2026-11-03 21:15:54
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 101762 times.
101762 DelegateRawTime::DelegateRawTime() : m_delegate(*RawTimeInterface::getDelegate(m_handle_storage)) {
12 101762 FW_ASSERT(&this->m_delegate == reinterpret_cast<RawTimeInterface*>(&this->m_handle_storage[0]));
13 101762 }
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 203646 DelegateRawTime::~DelegateRawTime() {
21 203644 FW_ASSERT(&this->m_delegate == reinterpret_cast<RawTimeInterface*>(&this->m_handle_storage[0]));
22 203644 m_delegate.~RawTimeInterface();
23 203646 }
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 748 DelegateRawTime& DelegateRawTime::operator=(const DelegateRawTime& other) {
34
1/2
✓ Branch 0 taken 748 times.
✗ Branch 1 not taken.
748 if (this != &other) {
35 748 this->m_source = other.m_source;
36 748 this->m_delegate = *RawTimeInterface::getDelegate(m_handle_storage, &other.m_delegate, other.m_source);
37 }
38 748 return *this;
39 }
40
41 5992 RawTimeHandle* DelegateRawTime::getHandle() {
42 5992 FW_ASSERT(&this->m_delegate == reinterpret_cast<RawTimeInterface*>(&this->m_handle_storage[0]));
43 5992 return this->m_delegate.getHandle();
44 }
45
46 1149 DelegateRawTime::Status DelegateRawTime::now() {
47 1149 FW_ASSERT(&this->m_delegate == reinterpret_cast<RawTimeInterface*>(&this->m_handle_storage[0]));
48 1149 return this->m_delegate.now();
49 }
50
51 765 DelegateRawTime::Status DelegateRawTime::getTimeInterval(const Os::RawTime& other, Fw::TimeInterval& result) const {
52 765 FW_ASSERT(&this->m_delegate == reinterpret_cast<const RawTimeInterface*>(&this->m_handle_storage[0]));
53 765 return this->m_delegate.getTimeInterval(other, result);
54 }
55
56 790 Fw::SerializeStatus DelegateRawTime::serializeTo(Fw::SerialBufferBase& buffer, Fw::Endianness mode) const {
57 790 FW_ASSERT(&this->m_delegate == reinterpret_cast<const RawTimeInterface*>(&this->m_handle_storage[0]));
58 790 return this->m_delegate.serializeTo(buffer, mode);
59 }
60
61 745 Fw::SerializeStatus DelegateRawTime::deserializeFrom(Fw::SerialBufferBase& buffer, Fw::Endianness mode) {
62 745 FW_ASSERT(&this->m_delegate == reinterpret_cast<const RawTimeInterface*>(&this->m_handle_storage[0]));
63 745 return this->m_delegate.deserializeFrom(buffer, mode);
64 }
65
66 3043 DelegateRawTime::Status DelegateRawTime::getDiffUsec(const RawTime& other, U32& result) const {
67 3043 FW_ASSERT(&this->m_delegate == reinterpret_cast<const RawTimeInterface*>(&this->m_handle_storage[0]));
68 3043 return this->m_delegate.getDiffUsec(other, result);
69 }
70
71 1459 bool DelegateRawTime::operator==(const RawTime& other) const {
72 1459 FW_ASSERT(&this->m_delegate == reinterpret_cast<const RawTimeInterface*>(&this->m_handle_storage[0]));
73 1459 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 3043 RawTimeInterface::Status RawTimeInterface::getDiffUsec(const RawTime& other, U32& result) const {
87
1/1
✓ Branch 2 taken 3043 times.
3043 Fw::TimeInterval interval;
88
1/1
✓ Branch 7 taken 3043 times.
3043 Status status = this->getTimeInterval(other, interval);
89
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3042 times.
3043 if (status != Status::OP_OK) {
90 1 return status;
91 }
92
93 // Check overflows in computation
94
1/1
✓ Branch 2 taken 3042 times.
3042 U32 seconds = interval.getSeconds();
95
1/1
✓ Branch 2 taken 3042 times.
3042 U32 useconds = interval.getUSeconds();
96
2/2
✓ Branch 0 taken 734 times.
✓ Branch 1 taken 2308 times.
3042 if (seconds > (std::numeric_limits<U32>::max() / 1000000)) {
97 734 result = std::numeric_limits<U32>::max();
98 734 return Status::OP_OVERFLOW;
99 }
100 2308 U32 secToUsec = seconds * 1000000;
101
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2308 times.
2308 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 2308 result = secToUsec + useconds;
107 2308 return status;
108 3043 }
109
110 1459 bool RawTimeInterface::operator==(const RawTime& other) const {
111
1/1
✓ Branch 2 taken 1459 times.
1459 Fw::TimeInterval interval;
112
1/1
✓ Branch 7 taken 1459 times.
1459 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 1458 times.
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1458 times.
✓ Branch 6 taken 730 times.
✓ Branch 7 taken 728 times.
✓ Branch 10 taken 730 times.
✓ Branch 12 taken 730 times.
✗ Branch 13 not taken.
2918 return status == Status::OP_OK && interval.getSeconds() == 0 && interval.getUSeconds() == 0;
117 1459 }
118
119 } // namespace Os
120