fprime/Svc/FprimeFramer/test/ut/FprimeFramerTester.cpp
Thomas Boyer-Chammard d0246f148b
Add Framer FPP interface, implement FprimeFramer and adapt ComQueue (#3486)
* Initial FprimeFramer and FprimePacketizer

* Code clarity + set up UTs

* Rework ComQueue and ComStub to use DataWithContext

* Add packets to RefPackets.fppi

* Fix ComQueue tests

* Add hotfix to FileDownlink instead of ComQueue

* Fix cancelPacket as well

* Fix ComQueue UTs by removing hotfix

* Refactor DataWithContext to use an FPP object for context instead of Fw.Buffer

* Touch up testing

* Add docs

* more docs

* More docs

* Rework buffer deallocation pattern to pass-through ComQueue

* Update ComStub UTs

* Restore original FileDownlink.cpp

* Formatting tweak

* Update deprecated getSerializeRepr() calls

* deserialization methods

* Fix spelling

* add cast for safety

* CMakefile change

* Bump ComQueue depth

* Update RPI deployment with new Downlink stack

* Rename comQueueIn port to comPktQueueIn

* Fix comQueueIn to comPktQueueIn change

* Remove legacy Svc.Framer

* Fix CMake UTs

* Fix RPI topology config

* Fix FprimeProtocol.fpp module

* Fix namespacing

* Use const reference for FrameContext port

* Review comments EXCEPT port passback refactor

* Rework ComStub with new ByteStream

* New ByteStream - ComInterface model

* Rework TcpClient / TcpServer with new bytestream

* Adapt UDP component for new ByteStream

* Adapt FrameAccumulator for new ByteStream

* Adapt FprimeFramer for new ByteStream

* Update Ref topology with new ByteStream model

* Remove all legacy deallocates from Drivers; reintroduce DEPRECATED model types

* Fix spelling and include error

* More spelling....

* RPI and RpiDemo fixes

* Fix conversion warning on RPI

* static_cast for short int on RPI

* Standardize port names

* Remove legacy Drv types and merge RECV/SEND enum type, delete StreamCrossover

* Update SDDs

* Update SDDs

* Fix ComInterface <-> Framer interfaction, clarify comments and fix annotations

* Switch ComStub from ASSERT to log failure and return buffer

* Add history size check + clarify test handler overrides

* Fix RPI topology to wire comStub on Uplink

* Rename comm to comDriver in RPI topology

* Update communication adapter interface docs
2025-04-29 16:40:36 -07:00

94 lines
3.7 KiB
C++

// ======================================================================
// \title FprimeFramerTester.cpp
// \author thomas-bc
// \brief cpp file for FprimeFramer component test harness implementation class
// ======================================================================
#include "FprimeFramerTester.hpp"
#include "Svc/FprimeProtocol/FrameHeaderSerializableAc.hpp"
#include "Svc/FprimeProtocol/FrameTrailerSerializableAc.hpp"
namespace Svc {
// ----------------------------------------------------------------------
// Construction and destruction
// ----------------------------------------------------------------------
FprimeFramerTester ::FprimeFramerTester()
: FprimeFramerGTestBase("FprimeFramerTester", FprimeFramerTester::MAX_HISTORY_SIZE), component("FprimeFramer") {
this->initComponents();
this->connectPorts();
}
FprimeFramerTester ::~FprimeFramerTester() {}
// ----------------------------------------------------------------------
// Tests
// ----------------------------------------------------------------------
void FprimeFramerTester ::testFrameDeallocation() {
// When receiving a buffer on dataReturnIn, the buffer should be deallocated
Fw::Buffer buffer;
ComCfg::FrameContext context;
this->invoke_to_dataReturnIn(0, buffer, context);
ASSERT_from_bufferDeallocate_SIZE(1);
ASSERT_from_bufferDeallocate(0, buffer);
}
void FprimeFramerTester ::testComStatusPassThrough() {
// Send a status message to the component
Fw::Success inputStatus = Fw::Success::SUCCESS;
this->invoke_to_comStatusIn(0, inputStatus);
ASSERT_from_comStatusOut_SIZE(1);
ASSERT_from_comStatusOut(0, inputStatus); // at index 0, received SUCCESS
inputStatus = Fw::Success::FAILURE;
this->invoke_to_comStatusIn(0, inputStatus);
ASSERT_from_comStatusOut_SIZE(2);
ASSERT_from_comStatusOut(1, inputStatus); // at index 1, received FAILURE
}
void FprimeFramerTester ::testNominalFraming() {
U8 bufferData[100];
Fw::Buffer buffer(bufferData, sizeof(bufferData));
ComCfg::FrameContext context;
// Fill the buffer with some data
for (U32 i = 0; i < sizeof(bufferData); ++i) {
bufferData[i] = static_cast<U8>(i);
}
// Send the buffer to the component
this->invoke_to_dataIn(0, buffer, context);
ASSERT_from_dataOut_SIZE(1); // One frame emitted
ASSERT_from_dataReturnOut_SIZE(1); // Original data buffer ownership returned
Fw::Buffer outputBuffer = this->fromPortHistory_dataOut->at(0).data;
// Check the size of the output buffer
ASSERT_EQ(outputBuffer.getSize(), sizeof(bufferData) + FprimeProtocol::FrameHeader::SERIALIZED_SIZE + FprimeProtocol::FrameTrailer::SERIALIZED_SIZE);
// Check header
FprimeProtocol::FrameHeader defaultHeader;
FprimeProtocol::FrameHeader outputHeader;
outputBuffer.getDeserializer().deserialize(outputHeader);
ASSERT_EQ(outputHeader.getstartWord(), defaultHeader.getstartWord());
ASSERT_EQ(outputHeader.getlengthField(), sizeof(bufferData));
// Check data
for (U32 i = 0; i < sizeof(bufferData); ++i) {
ASSERT_EQ(outputBuffer.getData()[i + FprimeProtocol::FrameHeader::SERIALIZED_SIZE], bufferData[i]);
}
}
// ----------------------------------------------------------------------
// Test Harness: Handler implementations for output ports
// ----------------------------------------------------------------------
Fw::Buffer FprimeFramerTester::from_bufferAllocate_handler(FwIndexType portNum, U32 size){
this->pushFromPortEntry_bufferAllocate(size);
this->m_buffer.setData(this->m_buffer_slot);
this->m_buffer.setSize(size);
::memset(this->m_buffer.getData(), 0, size);
return this->m_buffer;
}
} // namespace Svc