GCC Code Coverage Report


Directory: ./
File: Fw/Time/TimeInterval.cpp
Date: 2026-10-14 21:15:02
Exec Total Coverage
Lines: 81 87 93.1%
Functions: 19 21 90.5%
Branches: 37 39 94.9%

Line Branch Exec Source
1 #include <Fw/FPrimeBasicTypes.hpp>
2 #include <Fw/Time/TimeInterval.hpp>
3
4 namespace Fw {
5
1/1
✓ Branch 10 taken 1 times.
1 TimeInterval::TimeInterval(const TimeInterval& other) : Serializable() {
6
1/1
✓ Branch 11 taken 1 times.
1 this->m_val = other.m_val;
7 1 }
8
9
1/1
✓ Branch 10 taken 33424 times.
33419 TimeInterval::TimeInterval(U32 seconds, U32 useconds) : Serializable() {
10
1/1
✓ Branch 4 taken 33414 times.
33424 this->set(seconds, useconds);
11 33414 }
12
13 4889 TimeInterval::TimeInterval(const Time& start, const Time& end)
14
3/3
✓ Branch 5 taken 4889 times.
✓ Branch 11 taken 4889 times.
✓ Branch 14 taken 4889 times.
9778 : TimeInterval(TimeInterval::sub(TimeInterval(end.getSeconds(), end.getUSeconds()),
15
4/4
✓ Branch 5 taken 4889 times.
✓ Branch 11 taken 4889 times.
✓ Branch 14 taken 4889 times.
✓ Branch 19 taken 4889 times.
14667 TimeInterval(start.getSeconds(), start.getUSeconds()))) {}
16
17 39332 void TimeInterval::set(U32 seconds, U32 useconds) {
18 // Assert microseconds portion is less than 10^6
19 39332 FW_ASSERT(useconds < 1000000, static_cast<FwAssertArgType>(useconds));
20 39332 this->m_val.set(seconds, useconds);
21 39323 }
22
23 1194 TimeInterval& TimeInterval::operator=(const TimeInterval& other) {
24
1/2
✓ Branch 0 taken 1194 times.
✗ Branch 1 not taken.
1194 if (this != &other) {
25 1194 this->m_val = other.m_val;
26 }
27 1194 return *this;
28 }
29
30 718 bool TimeInterval::operator==(const TimeInterval& other) const {
31 718 return (TimeInterval::compare(*this, other) == EQ);
32 }
33
34 3 bool TimeInterval::operator!=(const TimeInterval& other) const {
35 3 return (TimeInterval::compare(*this, other) != EQ);
36 }
37
38 11237 bool TimeInterval::operator>(const TimeInterval& other) const {
39 11237 return (TimeInterval::compare(*this, other) == GT);
40 }
41
42 2626 bool TimeInterval::operator<(const TimeInterval& other) const {
43 2626 return (TimeInterval::compare(*this, other) == LT);
44 }
45
46 2448 bool TimeInterval::operator>=(const TimeInterval& other) const {
47 2448 TimeInterval::Comparison c = TimeInterval::compare(*this, other);
48
4/4
✓ Branch 0 taken 2447 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 2443 times.
2448 return ((GT == c) or (EQ == c));
49 }
50
51 4 bool TimeInterval::operator<=(const TimeInterval& other) const {
52 4 TimeInterval::Comparison c = TimeInterval::compare(*this, other);
53
4/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
4 return ((LT == c) or (EQ == c));
54 }
55
56 1 TimeIntervalValue TimeInterval::asTimeIntervalValue() const {
57 1 return this->m_val;
58 }
59
60 ✗ SerializeStatus TimeInterval::serializeTo(SerialBufferBase& buffer, Fw::Endianness mode) const {
61 // Use TimeIntervalValue's built-in serialization
62 ✗ return this->m_val.serializeTo(buffer, mode);
63 }
64
65 ✗ SerializeStatus TimeInterval::deserializeFrom(SerialBufferBase& buffer, Fw::Endianness mode) {
66 // Use TimeIntervalValue's built-in deserialization
67 ✗ return this->m_val.deserializeFrom(buffer, mode);
68 }
69
70 62451 U32 TimeInterval::getSeconds() const {
71 62451 return this->m_val.get_seconds();
72 }
73
74 74143 U32 TimeInterval::getUSeconds() const {
75 74143 return this->m_val.get_useconds();
76 }
77
78 17041 TimeInterval::Comparison TimeInterval ::compare(const TimeInterval& time1, const TimeInterval& time2) {
79 17041 const U32 s1 = time1.getSeconds();
80 17041 const U32 s2 = time2.getSeconds();
81 17041 const U32 us1 = time1.getUSeconds();
82 17041 const U32 us2 = time2.getUSeconds();
83
84
2/2
✓ Branch 0 taken 5076 times.
✓ Branch 1 taken 11965 times.
17041 if (s1 < s2) {
85 5076 return LT;
86
2/2
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 11938 times.
11965 } else if (s1 > s2) {
87 27 return GT;
88
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 11921 times.
11938 } else if (us1 < us2) {
89 17 return LT;
90
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 11919 times.
11921 } else if (us1 > us2) {
91 2 return GT;
92 } else {
93 11919 return EQ;
94 }
95 }
96
97 1 TimeInterval TimeInterval ::add(const TimeInterval& a, const TimeInterval& b) {
98 1 U32 seconds = a.getSeconds() + b.getSeconds();
99 1 U32 uSeconds = a.getUSeconds() + b.getUSeconds();
100 1 FW_ASSERT(uSeconds < 1999999);
101
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (uSeconds >= 1000000) {
102 ✗ ++seconds;
103 ✗ uSeconds -= 1000000;
104 }
105 1 TimeInterval c(seconds, uSeconds);
106 1 return c;
107 }
108
109 5617 TimeInterval TimeInterval ::sub(const TimeInterval& t1, //!< TimeInterval t1
110 const TimeInterval& t2 //!< TimeInterval t2
111 ) {
112
2/2
✓ Branch 4 taken 11 times.
✓ Branch 5 taken 5606 times.
5617 const TimeInterval& minuend = (t1 > t2) ? t1 : t2;
113
2/2
✓ Branch 4 taken 11 times.
✓ Branch 5 taken 5606 times.
5617 const TimeInterval& subtrahend = (t1 > t2) ? t2 : t1;
114
115 5617 U32 seconds = minuend.getSeconds() - subtrahend.getSeconds();
116 U32 uSeconds;
117
2/2
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 5616 times.
5617 if (subtrahend.getUSeconds() > minuend.getUSeconds()) {
118 1 seconds--;
119 1 uSeconds = minuend.getUSeconds() + 1000000 - subtrahend.getUSeconds();
120 } else {
121 5616 uSeconds = minuend.getUSeconds() - subtrahend.getUSeconds();
122 }
123 // Microseconds portion must be normalized to less than 10^6
124 5617 FW_ASSERT(uSeconds < 1000000, static_cast<FwAssertArgType>(uSeconds));
125 5617 return TimeInterval(seconds, static_cast<U32>(uSeconds));
126 }
127
128 147 void TimeInterval::add(U32 seconds, U32 useconds) {
129 147 U32 newSeconds = this->m_val.get_seconds() + seconds;
130 147 U32 newUSeconds = this->m_val.get_useconds() + useconds;
131 147 FW_ASSERT(newUSeconds < 1999999, static_cast<FwAssertArgType>(newUSeconds));
132
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 146 times.
147 if (newUSeconds >= 1000000) {
133 1 newSeconds += 1;
134 1 newUSeconds -= 1000000;
135 }
136 // Assert microseconds portion is less than 10^6
137 147 FW_ASSERT(newUSeconds < 1000000, static_cast<FwAssertArgType>(newUSeconds));
138 147 this->m_val.set(newSeconds, newUSeconds);
139 147 }
140
141 #ifdef BUILD_UT
142 3 std::ostream& operator<<(std::ostream& os, const TimeInterval& val) {
143 3 os << "(" << val.getSeconds() << "s," << val.getUSeconds() << "us)";
144 3 return os;
145 }
146 #endif
147
148 } // namespace Fw
149