Skip to content

Commit

Permalink
Fix issues with DpContainer and ExternalSerializeBuffer (#2941)
Browse files Browse the repository at this point in the history
* Revise Fw/Types

* Revise DpContainer to reset data size when setting the buffer
* Revise ExternalSerializeBuffer to clear the serialization state
  when setting the buffer
* Add tests for ExternalSerializeBuffer

* Revise ExternalSerializeBuffer and tests

* Revise tests for ExternalSerializeBuffer

* Revise DpTest

* Add comment; remove blank line

* Fix spelling
  • Loading branch information
bocchino authored Oct 11, 2024
1 parent 4bee99e commit 4b379f8
Show file tree
Hide file tree
Showing 11 changed files with 215 additions and 27 deletions.
18 changes: 18 additions & 0 deletions FppTest/dp/DpTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ void DpTest::schedIn_handler(const NATIVE_INT_TYPE portNum, U32 context) {
void DpTest ::dpRecv_Container1_handler(DpContainer& container, Fw::Success::T status) {
// Test container assignment
this->m_container = container;
this->checkContainerEmpty(this->m_container);
if (status == Fw::Success::SUCCESS) {
auto serializeStatus = Fw::FW_SERIALIZE_OK;
for (FwSizeType i = 0; i < CONTAINER_1_DATA_SIZE; ++i) {
Expand All @@ -121,6 +122,7 @@ void DpTest ::dpRecv_Container1_handler(DpContainer& container, Fw::Success::T s
void DpTest ::dpRecv_Container2_handler(DpContainer& container, Fw::Success::T status) {
// Test container assignment
this->m_container = container;
this->checkContainerEmpty(this->m_container);
if (status == Fw::Success::SUCCESS) {
const DpTest_Data dataRecord(this->dataRecordData);
auto serializeStatus = Fw::FW_SERIALIZE_OK;
Expand All @@ -141,6 +143,7 @@ void DpTest ::dpRecv_Container2_handler(DpContainer& container, Fw::Success::T s
void DpTest ::dpRecv_Container3_handler(DpContainer& container, Fw::Success::T status) {
// Test container assignment
this->m_container = container;
this->checkContainerEmpty(this->m_container);
if (status == Fw::Success::SUCCESS) {
auto serializeStatus = Fw::FW_SERIALIZE_OK;
for (FwSizeType i = 0; i < CONTAINER_3_DATA_SIZE; ++i) {
Expand All @@ -161,6 +164,7 @@ void DpTest ::dpRecv_Container3_handler(DpContainer& container, Fw::Success::T s
void DpTest ::dpRecv_Container4_handler(DpContainer& container, Fw::Success::T status) {
// Test container assignment
this->m_container = container;
this->checkContainerEmpty(this->m_container);
if (status == Fw::Success::SUCCESS) {
auto serializeStatus = Fw::FW_SERIALIZE_OK;
for (FwSizeType i = 0; i < CONTAINER_4_DATA_SIZE; ++i) {
Expand All @@ -181,6 +185,7 @@ void DpTest ::dpRecv_Container4_handler(DpContainer& container, Fw::Success::T s
void DpTest ::dpRecv_Container5_handler(DpContainer& container, Fw::Success::T status) {
// Test container assignment
this->m_container = container;
this->checkContainerEmpty(this->m_container);
if (status == Fw::Success::SUCCESS) {
auto serializeStatus = Fw::FW_SERIALIZE_OK;
for (FwSizeType i = 0; i < CONTAINER_5_DATA_SIZE; ++i) {
Expand All @@ -201,6 +206,7 @@ void DpTest ::dpRecv_Container5_handler(DpContainer& container, Fw::Success::T s
void DpTest ::dpRecv_Container6_handler(DpContainer& container, Fw::Success::T status) {
// Test container assignment
this->m_container = container;
this->checkContainerEmpty(this->m_container);
if (status == Fw::Success::SUCCESS) {
auto serializeStatus = Fw::FW_SERIALIZE_OK;
for (FwSizeType i = 0; i < CONTAINER_6_DATA_SIZE; ++i) {
Expand All @@ -220,6 +226,7 @@ void DpTest ::dpRecv_Container6_handler(DpContainer& container, Fw::Success::T s
void DpTest ::dpRecv_Container7_handler(DpContainer& container, Fw::Success::T status) {
// Test container assignment
this->m_container = container;
this->checkContainerEmpty(this->m_container);
if (status == Fw::Success::SUCCESS) {
auto serializeStatus = Fw::FW_SERIALIZE_OK;
for (FwSizeType i = 0; i < CONTAINER_7_DATA_SIZE; ++i) {
Expand All @@ -241,10 +248,21 @@ void DpTest ::dpRecv_Container7_handler(DpContainer& container, Fw::Success::T s
// Private helper functions
// ----------------------------------------------------------------------

void DpTest::checkContainerEmpty(const DpContainer& container) const {
const FwSizeType dataSize = container.getDataSize();
FW_ASSERT(dataSize == 0, static_cast<FwAssertArgType>(dataSize));
const Fw::SerializeBufferBase& buffer = container.m_dataBuffer;
const FwSizeType buffLength = buffer.getBuffLength();
FW_ASSERT(buffLength == 0, static_cast<FwAssertArgType>(buffLength));
const FwSizeType buffLeft = buffer.getBuffLeft();
FW_ASSERT(buffLeft == 0, static_cast<FwAssertArgType>(buffLeft));
}

void DpTest::checkContainer(const DpContainer& container,
FwDpIdType localId,
FwSizeType size,
FwDpPriorityType priority) const {
this->checkContainerEmpty(container);
FW_ASSERT(container.getBaseId() == this->getIdBase(), container.getBaseId(), this->getIdBase());
FW_ASSERT(container.getId() == container.getBaseId() + localId, container.getId(), container.getBaseId(),
ContainerId::Container1);
Expand Down
5 changes: 4 additions & 1 deletion FppTest/dp/DpTest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
namespace FppTest {

class DpTest : public DpTestComponentBase {

// Friend class for testing
friend class Tester;

Expand Down Expand Up @@ -139,6 +138,10 @@ class DpTest : public DpTestComponentBase {
// Private helper functions
// ----------------------------------------------------------------------

//! Check that a container is empty
void checkContainerEmpty(const DpContainer& container //!< The container
) const;

//! Check a container for validity
void checkContainer(const DpContainer& container, //!< The container
FwDpIdType localId, //!< The expected local id
Expand Down
63 changes: 48 additions & 15 deletions FppTest/dp/test/ut/TestMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,94 +8,127 @@

using namespace FppTest;

// Iterate the tests to ensure that everything works after the first time
static constexpr FwIndexType NUM_ITERS = 2;

TEST(schedIn, OK) {
COMMENT("schedIn OK");
Tester tester;
tester.schedIn_OK();
for (FwIndexType i = 0; i < NUM_ITERS; i++) {
tester.schedIn_OK();
}
}

TEST(productRecvIn, Container1_SUCCESS) {
COMMENT("Receive Container1 SUCCESS");
Tester tester;
tester.productRecvIn_Container1_SUCCESS();
for (FwIndexType i = 0; i < NUM_ITERS; i++) {
tester.productRecvIn_Container1_SUCCESS();
}
}

TEST(productRecvIn, Container1_FAILURE) {
COMMENT("Receive Container1 FAILURE");
Tester tester;
tester.productRecvIn_Container1_FAILURE();
for (FwIndexType i = 0; i < NUM_ITERS; i++) {
tester.productRecvIn_Container1_FAILURE();
}
}

TEST(productRecvIn, Container2_SUCCESS) {
COMMENT("Receive Container2 SUCCESS");
Tester tester;
tester.productRecvIn_Container2_SUCCESS();
for (FwIndexType i = 0; i < NUM_ITERS; i++) {
tester.productRecvIn_Container2_SUCCESS();
}
}

TEST(productRecvIn, Container2_FAILURE) {
COMMENT("Receive Container2 FAILURE");
Tester tester;
tester.productRecvIn_Container2_FAILURE();
for (FwIndexType i = 0; i < NUM_ITERS; i++) {
tester.productRecvIn_Container2_FAILURE();
}
}

TEST(productRecvIn, Container3_SUCCESS) {
COMMENT("Receive Container3 SUCCESS");
Tester tester;
tester.productRecvIn_Container3_SUCCESS();
for (FwIndexType i = 0; i < NUM_ITERS; i++) {
tester.productRecvIn_Container3_SUCCESS();
}
}

TEST(productRecvIn, Container3_FAILURE) {
COMMENT("Receive Container3 FAILURE");
Tester tester;
tester.productRecvIn_Container3_FAILURE();
for (FwIndexType i = 0; i < NUM_ITERS; i++) {
tester.productRecvIn_Container3_FAILURE();
}
}

TEST(productRecvIn, Container4_SUCCESS) {
COMMENT("Receive Container4 SUCCESS");
Tester tester;
tester.productRecvIn_Container4_SUCCESS();
for (FwIndexType i = 0; i < NUM_ITERS; i++) {
tester.productRecvIn_Container4_SUCCESS();
}
}

TEST(productRecvIn, Container4_FAILURE) {
COMMENT("Receive Container4 FAILURE");
Tester tester;
tester.productRecvIn_Container4_FAILURE();
for (FwIndexType i = 0; i < NUM_ITERS; i++) {
tester.productRecvIn_Container4_FAILURE();
}
}

TEST(productRecvIn, Container5_SUCCESS) {
COMMENT("Receive Container5 SUCCESS");
Tester tester;
tester.productRecvIn_Container5_SUCCESS();
for (FwIndexType i = 0; i < NUM_ITERS; i++) {
tester.productRecvIn_Container5_SUCCESS();
}
}

TEST(productRecvIn, Container5_FAILURE) {
COMMENT("Receive Container5 FAILURE");
Tester tester;
tester.productRecvIn_Container5_FAILURE();
for (FwIndexType i = 0; i < NUM_ITERS; i++) {
tester.productRecvIn_Container5_FAILURE();
}
}

TEST(productRecvIn, Container6_SUCCESS) {
COMMENT("Receive Container6 SUCCESS");
Tester tester;
tester.productRecvIn_Container6_SUCCESS();
for (FwIndexType i = 0; i < NUM_ITERS; i++) {
tester.productRecvIn_Container6_SUCCESS();
}
}

TEST(productRecvIn, Container6_FAILURE) {
COMMENT("Receive Container6 FAILURE");
Tester tester;
tester.productRecvIn_Container6_FAILURE();
for (FwIndexType i = 0; i < NUM_ITERS; i++) {
tester.productRecvIn_Container6_FAILURE();
}
}

TEST(productRecvIn, Container7_SUCCESS) {
COMMENT("Receive Container7 SUCCESS");
Tester tester;
tester.productRecvIn_Container7_SUCCESS();
for (FwIndexType i = 0; i < NUM_ITERS; i++) {
tester.productRecvIn_Container7_SUCCESS();
}
}

TEST(productRecvIn, Container7_FAILURE) {
COMMENT("Receive Container7 FAILURE");
Tester tester;
tester.productRecvIn_Container7_FAILURE();
for (FwIndexType i = 0; i < NUM_ITERS; i++) {
tester.productRecvIn_Container7_FAILURE();
}
}

int main(int argc, char** argv) {
Expand Down
22 changes: 22 additions & 0 deletions FppTest/dp/test/ut/Tester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Tester::~Tester() {}
// ----------------------------------------------------------------------

void Tester::schedIn_OK() {
this->clearHistory();
this->invoke_to_schedIn(0, 0);
this->component.doDispatch();
ASSERT_PRODUCT_REQUEST_SIZE(6);
Expand All @@ -83,6 +84,8 @@ void Tester::schedIn_OK() {
void Tester::productRecvIn_Container1_SUCCESS() {
Fw::Buffer buffer;
FwSizeType expectedNumElts;
// Clear the history
this->clearHistory();
// Check the record size
constexpr FwSizeType recordSize = DpTestComponentBase::SIZE_OF_U32Record_RECORD;
ASSERT_EQ(recordSize, sizeof(FwDpIdType) + sizeof(U32));
Expand All @@ -107,12 +110,15 @@ void Tester::productRecvIn_Container1_SUCCESS() {
}

void Tester::productRecvIn_Container1_FAILURE() {
this->clearHistory();
productRecvIn_CheckFailure(DpTest::ContainerId::Container1, this->container1Buffer);
}

void Tester::productRecvIn_Container2_SUCCESS() {
Fw::Buffer buffer;
FwSizeType expectedNumElts;
// Clear the history
this->clearHistory();
// Check the record size
constexpr FwSizeType recordSize = DpTestComponentBase::SIZE_OF_DataRecord_RECORD;
ASSERT_EQ(recordSize, sizeof(FwDpIdType) + DpTest_Data::SERIALIZED_SIZE);
Expand All @@ -137,12 +143,15 @@ void Tester::productRecvIn_Container2_SUCCESS() {
}

void Tester::productRecvIn_Container2_FAILURE() {
this->clearHistory();
productRecvIn_CheckFailure(DpTest::ContainerId::Container2, this->container2Buffer);
}

void Tester::productRecvIn_Container3_SUCCESS() {
Fw::Buffer buffer;
FwSizeType expectedNumElts;
// Clear the history
this->clearHistory();
// Compute the data element size
const FwSizeType arraySize = this->u8ArrayRecordData.size();
const FwSizeType dataEltSize = sizeof(FwSizeStoreType) + arraySize;
Expand Down Expand Up @@ -178,12 +187,15 @@ void Tester::productRecvIn_Container3_SUCCESS() {
}

void Tester::productRecvIn_Container3_FAILURE() {
this->clearHistory();
productRecvIn_CheckFailure(DpTest::ContainerId::Container3, this->container3Buffer);
}

void Tester::productRecvIn_Container4_SUCCESS() {
Fw::Buffer buffer;
FwSizeType expectedNumElts;
// Clear the history
this->clearHistory();
// Compute the data element size
const FwSizeType arraySize = this->u32ArrayRecordData.size();
const FwSizeType dataEltSize = sizeof(FwSizeStoreType) + arraySize * sizeof(U32);
Expand Down Expand Up @@ -220,11 +232,14 @@ void Tester::productRecvIn_Container4_SUCCESS() {

void Tester::productRecvIn_Container4_FAILURE() {
productRecvIn_CheckFailure(DpTest::ContainerId::Container4, this->container4Buffer);
this->clearHistory();
}

void Tester::productRecvIn_Container5_SUCCESS() {
Fw::Buffer buffer;
FwSizeType expectedNumElts;
// Clear the history
this->clearHistory();
// Compute the data element size
const FwSizeType arraySize = this->dataArrayRecordData.size();
const FwSizeType dataEltSize = sizeof(FwSizeStoreType) + arraySize * DpTest_Data::SERIALIZED_SIZE;
Expand Down Expand Up @@ -260,12 +275,15 @@ void Tester::productRecvIn_Container5_SUCCESS() {
}

void Tester::productRecvIn_Container5_FAILURE() {
this->clearHistory();
productRecvIn_CheckFailure(DpTest::ContainerId::Container5, this->container5Buffer);
}

void Tester::productRecvIn_Container6_SUCCESS() {
Fw::Buffer buffer;
FwSizeType expectedNumElts;
// Clear the history
this->clearHistory();
// Check the record size
constexpr FwSizeType recordSize = DpTestComponentBase::SIZE_OF_StringRecord_RECORD;
ASSERT_EQ(recordSize, sizeof(FwDpIdType) + Fw::StringBase::STATIC_SERIALIZED_SIZE(DpTest_stringSize));
Expand Down Expand Up @@ -293,12 +311,15 @@ void Tester::productRecvIn_Container6_SUCCESS() {
}

void Tester::productRecvIn_Container6_FAILURE() {
this->clearHistory();
productRecvIn_CheckFailure(DpTest::ContainerId::Container6, this->container6Buffer);
}

void Tester::productRecvIn_Container7_SUCCESS() {
Fw::Buffer buffer;
FwSizeType expectedNumElts;
// Clear the history
this->clearHistory();
// Check the record size
const FwSizeType arraySize = DpTest::STRING_ARRAY_RECORD_ARRAY_SIZE;
const FwSizeType recordSize = DpTestComponentBase::SIZE_OF_StringArrayRecord_RECORD(arraySize);
Expand Down Expand Up @@ -337,6 +358,7 @@ void Tester::productRecvIn_Container7_SUCCESS() {
}

void Tester::productRecvIn_Container7_FAILURE() {
this->clearHistory();
productRecvIn_CheckFailure(DpTest::ContainerId::Container7, this->container7Buffer);
}

Expand Down
4 changes: 4 additions & 0 deletions Fw/Dp/DpContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,11 @@ void DpContainer::setBuffer(const Buffer& buffer) {
FW_ASSERT(bufferSize >= minBufferSize, static_cast<FwAssertArgType>(bufferSize),
static_cast<FwAssertArgType>(minBufferSize));
U8* const dataAddr = &buffAddr[DATA_OFFSET];
// Set the buffer
// This action also clears the serialization state in the buffer
this->m_dataBuffer.setExtBuffer(dataAddr, static_cast<Fw::Serializable::SizeType>(dataCapacity));
// Reset the data size
this->m_dataSize = 0;
}

Utils::HashBuffer DpContainer::getHeaderHash() const {
Expand Down
2 changes: 2 additions & 0 deletions Fw/Dp/DpContainer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ class DpContainer {
//! Invalidate the packet buffer
void invalidateBuffer() {
this->m_buffer = Fw::Buffer();
this->m_dataBuffer.clear();
this->m_dataSize = 0;
}

//! Get the stored header hash
Expand Down
2 changes: 2 additions & 0 deletions Fw/Dp/test/ut/TestMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ TEST(Header, BufferSet) {
container.invalidateBuffer();
// Check that the buffer is invalid
ASSERT_EQ(container.getBuffer(), Fw::Buffer());
// Check that the data size is zero
ASSERT_EQ(container.getDataSize(), 0);
}

TEST(Header, BadPacketDescriptor) {
Expand Down
1 change: 1 addition & 0 deletions Fw/Types/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ set(MOD_DEPS
register_fprime_module()
### UTs ###
set(UT_SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/test/ut/ExternalSerializeBufferTest.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/TypesTest.cpp"
)
set(UT_MOD_DEPS
Expand Down
Loading

0 comments on commit 4b379f8

Please sign in to comment.