GCC Code Coverage Report


Directory: ./
File: Svc/OsTime/OsTime.cpp
Date: 2026-09-03 21:13:48
Exec Total Coverage
Lines: 48 50 96.0%
Functions: 6 6 100.0%
Branches: 38 41 92.7%

Line Branch Exec Source
1 // ======================================================================
2 // \title OsTime.cpp
3 // \author kubiak
4 // \brief cpp file for OsTime component implementation class
5 // ======================================================================
6
7 #include "Svc/OsTime/OsTime.hpp"
8 #include "config/FpConfig.hpp"
9
10 #include <Fw/Time/TimeInterval.hpp>
11
12 namespace Svc {
13
14 // ----------------------------------------------------------------------
15 // Component construction and destruction
16 // ----------------------------------------------------------------------
17
18 6 OsTime ::OsTime(const char* const compName)
19 : OsTimeComponentBase(compName),
20
1/1
✓ Branch 4 taken 6 times.
6 m_epoch_fw_time(Fw::ZERO_TIME),
21
1/1
✓ Branch 5 taken 6 times.
6 m_epoch_os_time(),
22 6 m_epoch_valid(false),
23
1/1
✓ Branch 11 taken 6 times.
12 m_epoch_lock() {}
24
25 12 OsTime ::~OsTime() {}
26
27 4 void OsTime::set_epoch(const Fw::Time& fw_time, const Os::RawTime& os_time) {
28
1/1
✓ Branch 5 taken 4 times.
4 Os::ScopeLock lock(m_epoch_lock);
29
1/1
✓ Branch 6 taken 4 times.
4 m_epoch_fw_time = fw_time;
30
1/1
✓ Branch 7 taken 4 times.
4 m_epoch_os_time = os_time;
31 4 m_epoch_valid = true;
32 8 }
33
34 2 void OsTime::SetCurrentTime_cmdHandler(FwOpcodeType opCode, U32 cmdSeq, U32 seconds_now) {
35
1/1
✓ Branch 2 taken 2 times.
2 Os::RawTime time_now;
36
1/1
✓ Branch 2 taken 2 times.
2 Os::RawTime::Status stat = time_now.now();
37
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (stat != Os::RawTime::OP_OK) {
38
1/1
✓ Branch 5 taken 1 times.
1 this->log_WARNING_HI_SetCurrentTimeError(stat);
39
2/2
✓ Branch 6 taken 1 times.
✓ Branch 9 taken 1 times.
1 this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::EXECUTION_ERROR);
40 1 return;
41 }
42
1/1
✓ Branch 5 taken 1 times.
1 Os::ScopeLock lock(m_epoch_lock);
43
2/2
✓ Branch 2 taken 1 times.
✓ Branch 11 taken 1 times.
1 m_epoch_fw_time = Fw::Time(seconds_now, 0);
44
1/1
✓ Branch 6 taken 1 times.
1 m_epoch_os_time = time_now;
45 1 m_epoch_valid = true;
46
2/2
✓ Branch 6 taken 1 times.
✓ Branch 9 taken 1 times.
1 this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
47 2 }
48
49 // ----------------------------------------------------------------------
50 // Handler implementations for user-defined typed input ports
51 // ----------------------------------------------------------------------
52
53 13 void OsTime ::timeGetPort_handler(FwIndexType portNum, Fw::Time& time) {
54
1/1
✓ Branch 2 taken 13 times.
13 Fw::Time temp_epoch_fw_time;
55
1/1
✓ Branch 2 taken 13 times.
13 Os::RawTime temp_epoch_os_time;
56 bool temp_epoch_valid;
57
58 // Copy class state inside of a mutex
59 {
60
1/1
✓ Branch 5 taken 13 times.
13 Os::ScopeLock lock(m_epoch_lock);
61
1/1
✓ Branch 5 taken 13 times.
13 temp_epoch_fw_time = m_epoch_fw_time;
62
1/1
✓ Branch 5 taken 13 times.
13 temp_epoch_os_time = m_epoch_os_time;
63
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 13 times.
13 temp_epoch_valid = m_epoch_valid;
64 13 }
65
66
1/1
✓ Branch 5 taken 13 times.
13 time = Fw::ZERO_TIME;
67
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 10 times.
13 if (!temp_epoch_valid) {
68 3 return;
69 }
70
71
1/1
✓ Branch 2 taken 10 times.
10 Os::RawTime time_now;
72
1/1
✓ Branch 2 taken 10 times.
10 Os::RawTime::Status stat = time_now.now();
73
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (stat != Os::RawTime::OP_OK) {
74 return;
75 }
76
77
1/1
✓ Branch 2 taken 10 times.
10 Fw::TimeInterval elapsed;
78
1/1
✓ Branch 2 taken 10 times.
10 stat = time_now.getTimeInterval(temp_epoch_os_time, elapsed);
79
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (stat != Os::RawTime::OP_OK) {
80 return;
81 }
82
83
1/1
✓ Branch 4 taken 10 times.
10 time = temp_epoch_fw_time;
84
3/3
✓ Branch 5 taken 10 times.
✓ Branch 9 taken 10 times.
✓ Branch 12 taken 10 times.
10 time.add(elapsed.getSeconds(), elapsed.getUSeconds());
85 16 }
86
87 1 void OsTime ::setEpoch_handler(FwIndexType portNum, const Fw::Time& fw_time, const Os::RawTime& os_time) {
88 1 set_epoch(fw_time, os_time);
89 1 }
90
91 } // namespace Svc
92