@@ -16,7 +16,8 @@ namespace Svc {
1616
1717FrameAccumulatorTester ::FrameAccumulatorTester ()
1818 : FrameAccumulatorGTestBase(" FrameAccumulatorTester" , FrameAccumulatorTester::MAX_HISTORY_SIZE),
19- component(" FrameAccumulator" ) {
19+ component(" FrameAccumulator" ),
20+ m_failBufferAllocate(false ) {
2021 component.configure (this ->mockDetector , 1 , this ->mallocator , 2048 );
2122 this ->initComponents ();
2223 this ->connectPorts ();
@@ -160,6 +161,28 @@ void FrameAccumulatorTester ::testBufferReturnDeallocation() {
160161 ASSERT_EQ (this ->fromPortHistory_bufferDeallocate ->at (0 ).fwBuffer .getSize (), sizeof (data));
161162}
162163
164+ void FrameAccumulatorTester ::testDropValidFrameWhenAllocationFailsAndRingIsFull () {
165+ U8 data[2048 ] = {};
166+ Fw::Buffer buffer (data, sizeof (data));
167+ ComCfg::FrameContext context;
168+ const FwSizeType ringCapacity = this ->component .m_inRing .get_capacity ();
169+
170+ ASSERT_EQ (ringCapacity, sizeof (data));
171+ ASSERT_EQ (this ->component .m_inRing .get_free_size (), ringCapacity);
172+
173+ this ->m_failBufferAllocate = true ;
174+ this ->mockDetector .set_next_result (FrameDetector::Status::FRAME_DETECTED, buffer.getSize ());
175+ this ->invoke_to_dataIn (0 , buffer, context);
176+
177+ ASSERT_from_dataReturnOut_SIZE (1 ); // input buffer ownership was returned
178+ ASSERT_from_dataOut_SIZE (0 ); // no frame was sent because allocation failed
179+ ASSERT_EQ (this ->component .m_inRing .get_allocated_size (), 0 );
180+ ASSERT_EQ (this ->component .m_inRing .get_free_size (), ringCapacity);
181+ ASSERT_EVENTS_SIZE (2 );
182+ ASSERT_EVENTS_NoBufferAvailable_SIZE (1 );
183+ ASSERT_EVENTS_FrameDetectionValidFrameDropped_SIZE (1 );
184+ }
185+
163186void FrameAccumulatorTester ::testDetectionErrorHandling () {
164187 FwSizeType too_large_size = this ->component .m_inRing .get_capacity () + 1 ;
165188 // Using buffer_size=1 to simplify test since otherwise Accumulator will loop `buffer_size` times
@@ -247,6 +270,10 @@ void FrameAccumulatorTester ::mockAccumulateFullFrame(U32& frame_size, U32& buff
247270// ----------------------------------------------------------------------
248271Fw::Buffer FrameAccumulatorTester ::from_bufferAllocate_handler (FwIndexType portNum, FwSizeType size) {
249272 this ->pushFromPortEntry_bufferAllocate (size);
273+ if (this ->m_failBufferAllocate ) {
274+ this ->m_failBufferAllocate = false ;
275+ return Fw::Buffer ();
276+ }
250277 this ->m_buffer .setData (this ->m_buffer_slot );
251278 this ->m_buffer .setSize (size);
252279 ::memset (this ->m_buffer.getData(), 0, size);
0 commit comments