GCC Code Coverage Report


Directory: ./
File: Os/Queue.cpp
Date: 2026-11-03 21:15:54
Exec Total Coverage
Lines: 71 77 92.2%
Functions: 16 17 94.1%
Branches: 36 46 78.3%

Line Branch Exec Source
1 // ======================================================================
2 // \title Os/Queue.cpp
3 // \brief common function implementation for Os::Queue
4 // ======================================================================
5 #include "Os/Queue.hpp"
6 #include "Fw/Types/Assert.hpp"
7 #include "Fw/Types/Serializable.hpp"
8
9 namespace Os {
10
11 FwSizeType Queue::s_queueCount = 0;
12 #if FW_QUEUE_REGISTRATION
13 QueueRegistry* Queue::s_queueRegistry = nullptr;
14 #endif
15
16
2/2
✓ Branch 10 taken 2175 times.
✓ Branch 24 taken 2175 times.
2175 Queue::Queue() : m_name(""), m_depth(0), m_size(0), m_delegate(*QueueInterface::getDelegate(m_handle_storage)) {}
17
18 8702 Queue::~Queue() {
19 4350 m_delegate.~QueueInterface();
20 4352 }
21
22 8124 QueueInterface::Status Queue ::create(FwEnumStoreType id,
23 const Fw::ConstStringBase& name,
24 FwSizeType depth,
25 FwSizeType messageSize) {
26 8124 FW_ASSERT(&this->m_delegate == reinterpret_cast<QueueInterface*>(&this->m_handle_storage[0]));
27 8124 FW_ASSERT(depth > 0);
28 8124 FW_ASSERT(messageSize > 0);
29 // Check for previous creation call
30
3/4
✓ Branch 4 taken 2127 times.
✓ Branch 5 taken 5997 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 2127 times.
8124 if (this->m_depth > 0 || this->m_size > 0) {
31 5997 return QueueInterface::Status::ALREADY_CREATED;
32 }
33 2127 QueueInterface::Status status = this->m_delegate.create(id, name, depth, messageSize);
34
2/2
✓ Branch 0 taken 2126 times.
✓ Branch 1 taken 1 times.
2127 if (status == QueueInterface::Status::OP_OK) {
35
1/1
✓ Branch 6 taken 2126 times.
2126 this->m_name = name;
36 2126 this->m_depth = depth;
37 2126 this->m_size = messageSize;
38
2/2
✓ Branch 2 taken 2126 times.
✓ Branch 7 taken 2126 times.
2126 ScopeLock lock(Queue::getStaticMutex());
39 2126 Queue::s_queueCount++;
40 #if FW_QUEUE_REGISTRATION
41
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 2096 times.
2126 if (Queue::s_queueRegistry != nullptr) {
42
1/1
✓ Branch 7 taken 30 times.
30 Queue::s_queueRegistry->registerQueue(this);
43 }
44 #endif
45 2126 }
46 2127 return status;
47 }
48
49 2149 void Queue::teardown() {
50 2149 FW_ASSERT(&this->m_delegate == reinterpret_cast<QueueInterface*>(&this->m_handle_storage[0]));
51 2149 return this->m_delegate.teardown();
52 }
53
54 2376368 QueueInterface::Status Queue::send(const U8* buffer,
55 FwSizeType size,
56 FwQueuePriorityType priority,
57 QueueInterface::BlockingType blockType) {
58 2376368 FW_ASSERT(&this->m_delegate == reinterpret_cast<QueueInterface*>(&this->m_handle_storage[0]));
59 2378872 FW_ASSERT(buffer != nullptr);
60 // Check if initialized
61
3/4
✓ Branch 4 taken 2379089 times.
✗ Branch 5 not taken.
✓ Branch 10 taken 176 times.
✓ Branch 11 taken 2378560 times.
2378872 if (this->m_depth == 0 || this->m_size == 0) {
62 6 return QueueInterface::Status::UNINITIALIZED;
63 }
64 // Check size before proceeding
65
2/2
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 2376668 times.
2378560 else if (size > this->getMessageSize()) {
66 1 return QueueInterface::Status::SIZE_MISMATCH;
67 }
68 2376668 return this->m_delegate.send(buffer, size, priority, blockType);
69 }
70
71 2801323 QueueInterface::Status Queue::receive(U8* destination,
72 FwSizeType capacity,
73 QueueInterface::BlockingType blockType,
74 FwSizeType& actualSize,
75 FwQueuePriorityType& priority) {
76 2801323 FW_ASSERT(&this->m_delegate == reinterpret_cast<QueueInterface*>(&this->m_handle_storage[0]));
77 2821082 FW_ASSERT(destination != nullptr);
78 // Check if initialized
79
3/4
✓ Branch 4 taken 2816798 times.
✗ Branch 5 not taken.
✓ Branch 10 taken 2263 times.
✓ Branch 11 taken 2817352 times.
2821082 if (this->m_depth == 0 || this->m_size == 0) {
80 6 return QueueInterface::Status::UNINITIALIZED;
81 }
82 // Check capacity before proceeding
83
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 2808715 times.
2817352 else if (capacity < this->getMessageSize()) {
84 ✗ return QueueInterface::Status::SIZE_MISMATCH;
85 }
86 2808715 return this->m_delegate.receive(destination, capacity, blockType, actualSize, priority);
87 }
88
89 767769 FwSizeType Queue::getMessagesAvailable() const {
90 767769 FW_ASSERT(&this->m_delegate == reinterpret_cast<const QueueInterface*>(&this->m_handle_storage[0]));
91 767769 return this->m_delegate.getMessagesAvailable();
92 }
93
94 727508 FwSizeType Queue::getMessageHighWaterMark() const {
95 727508 FW_ASSERT(&this->m_delegate == reinterpret_cast<const QueueInterface*>(&this->m_handle_storage[0]));
96 727508 return this->m_delegate.getMessageHighWaterMark();
97 }
98
99 1 QueueHandle* Queue::getHandle() {
100 1 FW_ASSERT(&this->m_delegate == reinterpret_cast<const QueueInterface*>(&this->m_handle_storage[0]));
101 1 return this->m_delegate.getHandle();
102 }
103
104 180622 QueueInterface::Status Queue::send(const Fw::LinearBufferBase& message,
105 FwQueuePriorityType priority,
106 QueueInterface::BlockingType blockType) {
107 180622 return this->send(message.getBuffAddr(), message.getSize(), priority, blockType);
108 }
109
110 101094 QueueInterface::Status Queue::receive(Fw::LinearBufferBase& destination,
111 QueueInterface::BlockingType blockType,
112 FwQueuePriorityType& priority) {
113 101094 FwSizeType actualSize = 0;
114
1/1
✓ Branch 7 taken 101094 times.
101094 destination.resetSer(); // Reset the buffer
115 QueueInterface::Status status =
116
3/3
✓ Branch 10 taken 101094 times.
✓ Branch 16 taken 101094 times.
✓ Branch 19 taken 101094 times.
101094 this->receive(destination.getBuffAddrSer(), destination.getCapacity(), blockType, actualSize, priority);
117
2/2
✓ Branch 0 taken 99911 times.
✓ Branch 1 taken 1183 times.
101094 if (status == QueueInterface::Status::OP_OK) {
118 Fw::SerializeStatus serializeStatus =
119
1/1
✓ Branch 7 taken 99911 times.
99911 destination.setBuffLen(static_cast<Fw::Serializable::SizeType>(actualSize));
120
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 99911 times.
99911 if (serializeStatus != Fw::SerializeStatus::FW_SERIALIZE_OK) {
121 ✗ status = QueueInterface::Status::SIZE_MISMATCH;
122 }
123 }
124 101094 return status;
125 }
126
127 731204 FwSizeType Queue::getDepth() const {
128 731204 return this->m_depth;
129 }
130
131 5873453 FwSizeType Queue::getMessageSize() const {
132 5873453 return this->m_size;
133 }
134
135 6028 const QueueString& Queue::getName() const {
136 6028 return this->m_name;
137 }
138
139 ✗ FwSizeType Queue::getNumQueues() {
140 ✗ ScopeLock lock(Queue::getStaticMutex());
141 ✗ return Queue::s_queueCount;
142 ✗ }
143
144 2156 Os::Mutex& Queue::getStaticMutex() {
145
4/7
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 2123 times.
✓ Branch 3 taken 33 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 33 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
2156 static Os::Mutex s_mutex;
146 2156 return s_mutex;
147 }
148
149 #if FW_QUEUE_REGISTRATION
150 30 void Queue::setRegistry(QueueRegistry* registry) {
151
2/2
✓ Branch 2 taken 30 times.
✓ Branch 7 taken 30 times.
30 ScopeLock lock(Queue::getStaticMutex());
152 30 Queue::s_queueRegistry = registry;
153 60 }
154 #endif
155
156 } // namespace Os
157