GCC Code Coverage Report


Directory: ./
File: Svc/BufferAccumulator/ArrayFIFOBuffer.cpp
Date: 2026-09-03 22:12:29
Exec Total Coverage
Lines: 31 36 86.1%
Functions: 6 7 85.7%
Branches: 8 13 61.5%

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 1 BufferAccumulator::ArrayFIFOBuffer ::ArrayFIFOBuffer()
25 1 : m_elements(nullptr), m_capacity(0), m_enqueueIndex(0), m_dequeueIndex(0), m_size(0) {}
26
27 1 BufferAccumulator::ArrayFIFOBuffer ::~ArrayFIFOBuffer() {}
28
29 // ----------------------------------------------------------------------
30 // Public functions
31 // ----------------------------------------------------------------------
32
33 1 void BufferAccumulator::ArrayFIFOBuffer ::init(Fw::Buffer* const elements, FwSizeType capacity) {
34 1 this->m_elements = elements;
35 1 this->m_capacity = capacity;
36
37 // Construct all elements
38
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 1 times.
11 for (FwSizeType idx = 0; idx < capacity; idx++) {
39
1/3
✓ Branch 2 taken 10 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
10 new (&this->m_elements[idx]) Fw::Buffer;
40 }
41 1 }
42
43 2 bool BufferAccumulator::ArrayFIFOBuffer ::enqueue(const Fw::Buffer& e) {
44
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (this->m_elements == nullptr) {
45 return false;
46 }
47
48 bool status;
49
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (this->m_size < this->m_capacity) {
50 // enqueueIndex is unsigned, no need to compare with 0
51 2 FW_ASSERT(m_enqueueIndex < this->m_capacity, static_cast<FwAssertArgType>(m_enqueueIndex));
52 2 this->m_elements[this->m_enqueueIndex] = e;
53 2 this->m_enqueueIndex = (this->m_enqueueIndex + 1) % this->m_capacity;
54 2 status = true;
55 2 this->m_size++;
56 } else {
57 status = false;
58 }
59
60 2 return status;
61 }
62
63 4 bool BufferAccumulator::ArrayFIFOBuffer ::dequeue(Fw::Buffer& e) {
64
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (this->m_elements == nullptr) {
65 return false;
66 }
67
68 4 FW_ASSERT(this->m_elements != nullptr);
69 bool status;
70
71
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 if (this->m_size > 0) {
72 // dequeueIndex is unsigned, no need to compare with 0
73 2 FW_ASSERT(m_dequeueIndex < this->m_capacity, static_cast<FwAssertArgType>(m_dequeueIndex));
74 2 e = this->m_elements[this->m_dequeueIndex];
75 2 this->m_dequeueIndex = (this->m_dequeueIndex + 1) % this->m_capacity;
76 2 this->m_size--;
77 2 status = true;
78 } else {
79 2 status = false;
80 }
81
82 4 return status;
83 }
84
85 6 FwSizeType BufferAccumulator::ArrayFIFOBuffer ::getSize() const {
86 6 return this->m_size;
87 }
88
89 FwSizeType BufferAccumulator::ArrayFIFOBuffer ::getCapacity() const {
90 return this->m_capacity;
91 }
92
93 } // namespace Svc
94