GCC Code Coverage Report


Directory: ./
File: Fw/Time/TimeInterval.cpp
Date: 2026-09-03 21:13:48
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 13086 times.
13083 TimeInterval::TimeInterval(U32 seconds, U32 useconds) : Serializable() {
10
1/1
✓ Branch 4 taken 13079 times.
13086 this->set(seconds, useconds);
11 13079 }
12
13 1 TimeInterval::TimeInterval(const Time& start, const Time& end)
14
3/3
✓ Branch 5 taken 1 times.
✓ Branch 11 taken 1 times.
✓ Branch 14 taken 1 times.
2 : TimeInterval(TimeInterval::sub(TimeInterval(end.getSeconds(), end.getUSeconds()),
15
4/4
✓ Branch 5 taken 1 times.
✓ Branch 11 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 19 taken 1 times.
3 TimeInterval(start.getSeconds(), start.getUSeconds()))) {}
16
17 19116 void TimeInterval::set(U32 seconds, U32 useconds) {
18 // Assert microseconds portion is less than 10^6
19 19116 FW_ASSERT(useconds < 1000000, static_cast<FwAssertArgType>(useconds));
20 19116 this->m_val.set(seconds, useconds);
21 19106 }
22
23 1216 TimeInterval& TimeInterval::operator=(const TimeInterval& other) {
24
1/2
✓ Branch 0 taken 1216 times.
✗ Branch 1 not taken.
1216 if (this != &other) {
25 1216 this->m_val = other.m_val;
26 }
27 1216 return *this;
28 }
29
30 732 bool TimeInterval::operator==(const TimeInterval& other) const {
31 732 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 1491 bool TimeInterval::operator>(const TimeInterval& other) const {
39 1491 return (TimeInterval::compare(*this, other) == GT);
40 }
41
42 183 bool TimeInterval::operator<(const TimeInterval& other) const {
43 183 return (TimeInterval::compare(*this, other) == LT);
44 }
45
46 4 bool TimeInterval::operator>=(const TimeInterval& other) const {
47 4 TimeInterval::Comparison c = TimeInterval::compare(*this, other);
48
4/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 1 times.
4 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 22718 U32 TimeInterval::getSeconds() const {
71 22718 return this->m_val.get_seconds();
72 }
73
74 24670 U32 TimeInterval::getUSeconds() const {
75 24670 return this->m_val.get_useconds();
76 }
77
78 2422 TimeInterval::Comparison TimeInterval ::compare(const TimeInterval& time1, const TimeInterval& time2) {
79 2422 const U32 s1 = time1.getSeconds();
80 2422 const U32 s2 = time2.getSeconds();
81 2422 const U32 us1 = time1.getUSeconds();
82 2422 const U32 us2 = time2.getUSeconds();
83
84
2/2
✓ Branch 0 taken 193 times.
✓ Branch 1 taken 2229 times.
2422 if (s1 < s2) {
85 193 return LT;
86
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 2218 times.
2229 } else if (s1 > s2) {
87 11 return GT;
88
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 2201 times.
2218 } else if (us1 < us2) {
89 17 return LT;
90
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2199 times.
2201 } else if (us1 > us2) {
91 2 return GT;
92 } else {
93 2199 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 744 TimeInterval TimeInterval ::sub(const TimeInterval& t1, //!< TimeInterval t1
110 const TimeInterval& t2 //!< TimeInterval t2
111 ) {
112
2/2
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 741 times.
744 const TimeInterval& minuend = (t1 > t2) ? t1 : t2;
113
2/2
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 741 times.
744 const TimeInterval& subtrahend = (t1 > t2) ? t2 : t1;
114
115 744 U32 seconds = minuend.getSeconds() - subtrahend.getSeconds();
116 U32 uSeconds;
117
2/2
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 743 times.
744 if (subtrahend.getUSeconds() > minuend.getUSeconds()) {
118 1 seconds--;
119 1 uSeconds = minuend.getUSeconds() + 1000000 - subtrahend.getUSeconds();
120 } else {
121 743 uSeconds = minuend.getUSeconds() - subtrahend.getUSeconds();
122 }
123 // Microseconds portion must be normalized to less than 10^6
124 744 FW_ASSERT(uSeconds < 1000000, static_cast<FwAssertArgType>(uSeconds));
125 744 return TimeInterval(seconds, static_cast<U32>(uSeconds));
126 }
127
128 148 void TimeInterval::add(U32 seconds, U32 useconds) {
129 148 U32 newSeconds = this->m_val.get_seconds() + seconds;
130 148 U32 newUSeconds = this->m_val.get_useconds() + useconds;
131 148 FW_ASSERT(newUSeconds < 1999999, static_cast<FwAssertArgType>(newUSeconds));
132
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 147 times.
148 if (newUSeconds >= 1000000) {
133 1 newSeconds += 1;
134 1 newUSeconds -= 1000000;
135 }
136 // Assert microseconds portion is less than 10^6
137 148 FW_ASSERT(newUSeconds < 1000000, static_cast<FwAssertArgType>(newUSeconds));
138 148 this->m_val.set(newSeconds, newUSeconds);
139 148 }
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