GCC Code Coverage Report


Directory: ./
File: Svc/ComRetry/ComRetry.cpp
Date: 2026-09-03 21:13:48
Exec Total Coverage
Lines: 50 50 100.0%
Functions: 6 6 100.0%
Branches: 24 28 85.7%

Line Branch Exec Source
1 // ======================================================================
2 // \title ComRetry.cpp
3 // \author valdaarhun
4 // \brief cpp file for ComRetry component implementation class
5 // ======================================================================
6
7 #include "Svc/ComRetry/ComRetry.hpp"
8 #include "ComRetry.hpp"
9
10 namespace Svc {
11
12 // ----------------------------------------------------------------------
13 // Component construction and destruction
14 // ----------------------------------------------------------------------
15
16 4 ComRetry ::ComRetry(const char* const compName)
17 : ComRetryComponentBase(compName),
18 4 m_num_retries(3),
19 4 m_retry_count(0),
20 4 m_retry_state(WAITING_FOR_SEND),
21
2/2
✓ Branch 10 taken 4 times.
✓ Branch 16 taken 4 times.
8 m_bufferState(Fw::Buffer::OwnershipState::OWNED) {}
22
23 8 ComRetry ::~ComRetry() {}
24
25 2 void ComRetry::configure(U32 num_retries) {
26 2 this->m_num_retries = num_retries;
27 2 }
28
29 // ----------------------------------------------------------------------
30 // Handler implementations for typed input ports
31 // ----------------------------------------------------------------------
32
33 16 void ComRetry ::comStatusIn_handler(FwIndexType portNum, Fw::Success& condition) {
34 16 FW_ASSERT(this->m_bufferState == Fw::Buffer::OwnershipState::OWNED);
35
36 // When waiting for send, just pass the status up the stack as the buffer should still be upstream
37
3/4
✗ Branch 3 not taken.
✓ Branch 4 taken 16 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 14 times.
16 if (this->m_retry_state == WAITING_FOR_SEND) {
38 2 FW_ASSERT(!this->m_buffer.isValid());
39 2 this->comStatusOut_out(0, condition);
40 }
41 // Nominal case where delivery of buffer is successful, and everything is passed back up the stack
42
7/8
✗ Branch 3 not taken.
✓ Branch 4 taken 14 times.
✓ Branch 5 taken 10 times.
✓ Branch 6 taken 4 times.
✓ Branch 11 taken 5 times.
✓ Branch 12 taken 5 times.
✓ Branch 13 taken 5 times.
✓ Branch 14 taken 9 times.
14 else if ((this->m_retry_state == WAITING_FOR_STATUS) && (condition == Fw::Success::SUCCESS)) {
43 5 FW_ASSERT(this->m_buffer.isValid());
44 5 this->m_retry_state = WAITING_FOR_SEND; // Successful transmission, reset state
45 5 this->dataReturnOut_out(0, this->m_buffer, this->m_context);
46
2/2
✓ Branch 2 taken 5 times.
✓ Branch 11 taken 5 times.
5 this->m_buffer = Fw::Buffer(); // Clear buffer
47 5 this->comStatusOut_out(0, condition);
48 }
49 // When retrying, and "success" is received, this is the retry case
50
6/8
✗ Branch 3 not taken.
✓ Branch 4 taken 9 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 5 times.
✓ Branch 11 taken 4 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 4 times.
✓ Branch 14 taken 5 times.
9 else if ((this->m_retry_state == RETRYING) && (condition == Fw::Success::SUCCESS)) {
51 4 FW_ASSERT(this->m_buffer.isValid());
52 4 this->m_retry_count++;
53 4 this->m_retry_state = WAITING_FOR_STATUS;
54 4 this->m_bufferState = Fw::Buffer::OwnershipState::NOT_OWNED;
55 4 this->dataOut_out(0, this->m_buffer, this->m_context);
56 } else {
57 // When a failure has been seen, it can **only** be in WAITING_FOR_STATUS state
58 5 FW_ASSERT(this->m_retry_state == WAITING_FOR_STATUS);
59 5 FW_ASSERT(condition == Fw::Success::FAILURE);
60
61 // If we have retries left then switch to RETRYING, and wait for success
62
2/2
✓ Branch 8 taken 4 times.
✓ Branch 9 taken 1 times.
5 if (this->m_retry_count < this->m_num_retries) {
63 4 this->m_retry_state = RETRYING;
64 }
65 // If no retries left, pass failure back up the stack and reset state
66 else {
67 1 this->m_retry_state = WAITING_FOR_SEND;
68 1 this->dataReturnOut_out(0, this->m_buffer, this->m_context);
69
2/2
✓ Branch 2 taken 1 times.
✓ Branch 11 taken 1 times.
1 this->m_buffer = Fw::Buffer(); // Clear buffer
70 1 this->comStatusOut_out(0, condition);
71 }
72 }
73 16 }
74
75 6 void ComRetry ::dataIn_handler(FwIndexType portNum, Fw::Buffer& buffer, const ComCfg::FrameContext& context) {
76 6 FW_ASSERT(this->m_bufferState == Fw::Buffer::OwnershipState::OWNED);
77 6 FW_ASSERT(this->m_retry_state == WAITING_FOR_SEND);
78 6 this->m_bufferState = Fw::Buffer::OwnershipState::NOT_OWNED;
79 6 this->m_retry_state = WAITING_FOR_STATUS;
80 6 this->m_retry_count = 0;
81 6 this->dataOut_out(0, buffer, context);
82 6 }
83
84 10 void ComRetry ::dataReturnIn_handler(FwIndexType portNum, Fw::Buffer& buffer, const ComCfg::FrameContext& context) {
85 10 FW_ASSERT(this->m_bufferState == Fw::Buffer::OwnershipState::NOT_OWNED);
86 10 FW_ASSERT(this->m_retry_state == WAITING_FOR_STATUS);
87 10 this->m_bufferState = Fw::Buffer::OwnershipState::OWNED;
88 10 this->m_buffer = buffer;
89 10 this->m_context = context;
90 10 }
91
92 } // namespace Svc
93