mirror of
https://github.com/nasa/fprime.git
synced 2025-12-11 04:35:25 -06:00
* 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
171 lines
6.7 KiB
C++
171 lines
6.7 KiB
C++
// ======================================================================
|
|
// \title ComStub.hpp
|
|
// \author mstarch
|
|
// \brief cpp file for ComStub test harness implementation class
|
|
// ======================================================================
|
|
|
|
#include "ComStubTester.hpp"
|
|
#include <STest/Pick/Pick.hpp>
|
|
|
|
namespace Svc {
|
|
|
|
// ----------------------------------------------------------------------
|
|
// Construction and destruction
|
|
// ----------------------------------------------------------------------
|
|
|
|
ComStubTester ::ComStubTester()
|
|
: ComStubGTestBase("Tester", MAX_HISTORY_SIZE),
|
|
component("ComStub"),
|
|
m_send_mode(Drv::ByteStreamStatus::OP_OK),
|
|
m_retries(0) {
|
|
this->initComponents();
|
|
this->connectPorts();
|
|
}
|
|
|
|
ComStubTester ::~ComStubTester() {}
|
|
|
|
// ----------------------------------------------------------------------
|
|
// Helpers
|
|
// ----------------------------------------------------------------------
|
|
void ComStubTester ::fill(Fw::Buffer& buffer_to_fill) {
|
|
U8 size = static_cast<U8>(STest::Pick::lowerUpper(1, sizeof(buffer_to_fill.getSize())));
|
|
for (U32 i = 0; i < size; i++) {
|
|
buffer_to_fill.getData()[i] = static_cast<U8>(STest::Pick::any());
|
|
}
|
|
buffer_to_fill.setSize(size);
|
|
}
|
|
|
|
// ----------------------------------------------------------------------
|
|
// Tests
|
|
// ----------------------------------------------------------------------
|
|
void ComStubTester ::test_initial() {
|
|
Fw::Success condition = Fw::Success::SUCCESS;
|
|
invoke_to_drvConnected(0);
|
|
ASSERT_from_comStatusOut_SIZE(1);
|
|
ASSERT_from_comStatusOut(0, condition);
|
|
this->fromPortHistory_comStatusOut->clear();
|
|
}
|
|
|
|
void ComStubTester ::test_basic() {
|
|
this->test_initial();
|
|
U8 storage[8];
|
|
Fw::Buffer buffer(storage, sizeof(storage));
|
|
Fw::Success condition = Fw::Success::SUCCESS;
|
|
ComCfg::FrameContext context;
|
|
this->fill(buffer);
|
|
|
|
// Downlink
|
|
invoke_to_comDataIn(0, buffer, context);
|
|
ASSERT_from_drvDataOut_SIZE(1);
|
|
ASSERT_from_drvDataOut(0, buffer);
|
|
|
|
// Uplink
|
|
invoke_to_drvDataIn(0, buffer, Drv::ByteStreamStatus::OP_OK);
|
|
ASSERT_from_comDataOut_SIZE(1);
|
|
ASSERT_from_comDataOut(0, buffer);
|
|
}
|
|
|
|
void ComStubTester ::test_fail() {
|
|
this->test_initial();
|
|
U8 storage[8];
|
|
Fw::Buffer buffer(storage, sizeof(storage));
|
|
this->fill(buffer);
|
|
Fw::Success condition = Fw::Success::FAILURE;
|
|
m_send_mode = Drv::ByteStreamStatus::OTHER_ERROR;
|
|
ComCfg::FrameContext context;
|
|
|
|
// Downlink
|
|
invoke_to_comDataIn(0, buffer, context);
|
|
ASSERT_from_drvDataOut_SIZE(1);
|
|
ASSERT_from_drvDataOut(0, buffer);
|
|
|
|
// Uplink
|
|
invoke_to_drvDataIn(0, buffer, Drv::ByteStreamStatus::OTHER_ERROR);
|
|
ASSERT_from_comDataOut_SIZE(0); // receiving failure should not send anything
|
|
}
|
|
|
|
void ComStubTester ::test_retry() {
|
|
this->test_initial();
|
|
FwIndexType MAX_ITERS = this->component.RETRY_LIMIT + 1;
|
|
|
|
// Make small individual buffers for testing
|
|
U8 storage[MAX_ITERS][8];
|
|
Fw::Buffer buffers[MAX_ITERS];
|
|
for (FwIndexType i = 0; i < MAX_ITERS; i++) {
|
|
buffers[i].setData(storage[i]);
|
|
buffers[i].setSize(sizeof(storage[i]));
|
|
buffers[i].setContext(static_cast<U32>(i));
|
|
this->fill(buffers[i]);
|
|
}
|
|
// Retrying for as many times as the RETRY_LIMIT should be ok
|
|
for (FwIndexType i = 0; i < this->component.RETRY_LIMIT; i++) {
|
|
invoke_to_dataReturnIn(0, buffers[i], Drv::ByteStreamStatus::SEND_RETRY);
|
|
// Test we have indeed retried (data sent on drvDataOut)
|
|
ASSERT_from_drvDataOut_SIZE(static_cast<U32>(i + 1));
|
|
ASSERT_from_drvDataOut(static_cast<U32>(i), buffers[i]);
|
|
}
|
|
ASSERT_from_drvDataOut_SIZE(static_cast<U32>(this->component.RETRY_LIMIT));
|
|
ASSERT_EQ(this->component.m_retry_count, this->component.RETRY_LIMIT);
|
|
// Retry one more time should block from retrying and reset retry count
|
|
invoke_to_dataReturnIn(0, buffers[MAX_ITERS - 1], Drv::ByteStreamStatus::SEND_RETRY);
|
|
ASSERT_from_drvDataOut_SIZE(static_cast<U32>(this->component.RETRY_LIMIT)); // no drvDataOut sent when SEND_RETRY
|
|
ASSERT_from_dataReturnOut_SIZE(1); // buffer ownership was returned
|
|
ASSERT_EQ(this->component.m_retry_count, 0);
|
|
}
|
|
|
|
void ComStubTester ::test_retry_reset() {
|
|
this->test_initial();
|
|
FwIndexType MAX_ITERS = this->component.RETRY_LIMIT + 1;
|
|
U32 expected_drvDataOut_count = 0;
|
|
|
|
// Make small individual buffers for testing
|
|
U8 storage[MAX_ITERS][8];
|
|
Fw::Buffer buffers[MAX_ITERS];
|
|
for (FwIndexType i = 0; i < MAX_ITERS; i++) {
|
|
buffers[i].setData(storage[i]);
|
|
buffers[i].setSize(sizeof(storage[i]));
|
|
buffers[i].setContext(static_cast<U32>(i));
|
|
this->fill(buffers[i]);
|
|
}
|
|
|
|
// Retrying for as many times as the RETRY_LIMIT should be ok
|
|
for (FwIndexType i = 0; i < this->component.RETRY_LIMIT; i++) {
|
|
invoke_to_dataReturnIn(0, buffers[i], Drv::ByteStreamStatus::SEND_RETRY);
|
|
ASSERT_from_drvDataOut(expected_drvDataOut_count, buffers[i]);
|
|
expected_drvDataOut_count++; // trick: increment now to use as index prior and size after
|
|
ASSERT_from_drvDataOut_SIZE(expected_drvDataOut_count);
|
|
}
|
|
// Now, we receive a OP_OK, which should not retry (drvDataOut should not be called) and reset the retry count
|
|
ASSERT_from_drvDataOut_SIZE(expected_drvDataOut_count); // no drvDataOut sent when OP_OK
|
|
invoke_to_dataReturnIn(0, buffers[0], Drv::ByteStreamStatus::OP_OK);
|
|
ASSERT_from_drvDataOut_SIZE(expected_drvDataOut_count); // no drvDataOut sent when OP_OK
|
|
// Now that retry count is reset, we can retry again without a problem
|
|
for (FwIndexType i = 0; i < this->component.RETRY_LIMIT; i++) {
|
|
invoke_to_dataReturnIn(0, buffers[i], Drv::ByteStreamStatus::SEND_RETRY);
|
|
ASSERT_from_drvDataOut(expected_drvDataOut_count, buffers[i]);
|
|
expected_drvDataOut_count++; // trick: increment now to use as index prior and size after
|
|
ASSERT_from_drvDataOut_SIZE(expected_drvDataOut_count);
|
|
}
|
|
ASSERT_from_drvDataOut_SIZE(expected_drvDataOut_count); // no drvDataOut sent when OP_OK
|
|
}
|
|
|
|
// ----------------------------------------------------------------------
|
|
// Handlers for typed from ports
|
|
// ----------------------------------------------------------------------
|
|
|
|
void ComStubTester ::from_comDataOut_handler(const FwIndexType portNum,
|
|
Fw::Buffer& recvBuffer) {
|
|
this->pushFromPortEntry_comDataOut(recvBuffer);
|
|
}
|
|
|
|
void ComStubTester ::from_comStatusOut_handler(const FwIndexType portNum, Fw::Success& condition) {
|
|
this->pushFromPortEntry_comStatusOut(condition);
|
|
}
|
|
|
|
void ComStubTester ::from_drvDataOut_handler(const FwIndexType portNum, Fw::Buffer& sendBuffer) {
|
|
this->pushFromPortEntry_drvDataOut(sendBuffer);
|
|
}
|
|
|
|
|
|
} // end namespace Svc
|