GCC Code Coverage Report


Directory: ./
File: Svc/BufferAccumulator/ArrayFIFOBuffer.cpp
Date: 2026-09-03 21:13:48
Exec Total Coverage
Lines: 32 36 88.9%
Functions: 6 7 85.7%
Branches: 11 17 64.7%

Line Branch Exec Source
1 // ======================================================================
2 // \title ArrayFIFOBuffer.cpp
3 // \author mereweth
4 // \brief ArrayFIFOBuffer implementation
5 //
6 // \copyright
7 // Copyright (C) 2017 California Institute of Technology.
8 // ALL RIGHTS RESERVED. United States Government Sponsorship
9 // acknowledged.
10 //
11 // ======================================================================
12
13 #include <new> // For placement new
14 #include "Fw/Types/Assert.hpp"
15 #include "Fw/Types/BasicTypes.hpp"
16 #include "Svc/BufferAccumulator/BufferAccumulator.hpp"
17
18 namespace Svc {
19
20 // ----------------------------------------------------------------------
21 // Constructors
22 // ----------------------------------------------------------------------
23
24 7 BufferAccumulator::ArrayFIFOBuffer ::ArrayFIFOBuffer()
25 7 : m_elements(nullptr), m_capacity(0), m_enqueueIndex(0), m_dequeueIndex(0), m_size(0) {}
26
27 7 BufferAccumulator::ArrayFIFOBuffer ::~ArrayFIFOBuffer() {}
28
29 // ----------------------------------------------------------------------
30 // Public functions
31 // ----------------------------------------------------------------------
32
33 7 void BufferAccumulator::ArrayFIFOBuffer ::init(Fw::Buffer* const elements, FwSizeType capacity) {
34 7 this->m_elements = elements;
35 7 this->m_capacity = capacity;
36
37 // Construct all elements
38
2/2
✓ Branch 0 taken 70 times.
✓ Branch 1 taken 7 times.
77 for (FwSizeType idx = 0; idx < capacity; idx++) {
39
1/3
✓ Branch 5 taken 70 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
70 new (&this->m_elements[idx]) Fw::Buffer;
40 }
41 7 }
42
43 66 bool BufferAccumulator::ArrayFIFOBuffer ::enqueue(const Fw::Buffer& e) {
44
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 66 times.
66 if (this->m_elements == nullptr) {
45 return false;
46 }
47
48 bool status;
49
2/2
✓ Branch 4 taken 63 times.
✓ Branch 5 taken 3 times.
66 if (this->m_size < this->m_capacity) {
50 // enqueueIndex is unsigned, no need to compare with 0
51 63 FW_ASSERT(m_enqueueIndex < this->m_capacity, static_cast<FwAssertArgType>(m_enqueueIndex));
52 63 this->m_elements[this->m_enqueueIndex] = e;
53
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 63 times.
63 this->m_enqueueIndex = (this->m_enqueueIndex + 1) % this->m_capacity;
54 63 status = true;
55 63 this->m_size++;
56 } else {
57 3 status = false;
58 }
59
60 66 return status;
61 }
62
63 65 bool BufferAccumulator::ArrayFIFOBuffer ::dequeue(Fw::Buffer& e) {
64
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 65 times.
65 if (this->m_elements == nullptr) {
65 return false;
66 }
67
68 65 FW_ASSERT(this->m_elements != nullptr);
69 bool status;
70
71
2/2
✓ Branch 2 taken 53 times.
✓ Branch 3 taken 12 times.
65 if (this->m_size > 0) {
72 // dequeueIndex is unsigned, no need to compare with 0
73 53 FW_ASSERT(m_dequeueIndex < this->m_capacity, static_cast<FwAssertArgType>(m_dequeueIndex));
74 53 e = this->m_elements[this->m_dequeueIndex];
75
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 53 times.
53 this->m_dequeueIndex = (this->m_dequeueIndex + 1) % this->m_capacity;
76 53 this->m_size--;
77 53 status = true;
78 } else {
79 12 status = false;
80 }
81
82 65 return status;
83 }
84
85 131 FwSizeType BufferAccumulator::ArrayFIFOBuffer ::getSize() const {
86 131 return this->m_size;
87 }
88
89 FwSizeType BufferAccumulator::ArrayFIFOBuffer ::getCapacity() const {
90 return this->m_capacity;
91 }
92
93 } // namespace Svc
94