From 0cccf260210aff7db9a4aa0c4dee386203be96be Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 3 Aug 2023 14:34:21 +0200 Subject: [PATCH] should not be problematic but somehow is.. --- src/fsfw/cfdp/handler/SourceHandler.cpp | 2 + unittests/cfdp/handler/testSourceHandler.cpp | 10 ++-- unittests/cfdp/pdu/testMetadataPdu.cpp | 50 ++++++++++++++++---- 3 files changed, 49 insertions(+), 13 deletions(-) diff --git a/src/fsfw/cfdp/handler/SourceHandler.cpp b/src/fsfw/cfdp/handler/SourceHandler.cpp index 05c17617..4365b824 100644 --- a/src/fsfw/cfdp/handler/SourceHandler.cpp +++ b/src/fsfw/cfdp/handler/SourceHandler.cpp @@ -8,6 +8,7 @@ #include "fsfw/cfdp/pdu/FileDataCreator.h" #include "fsfw/cfdp/pdu/MetadataPduCreator.h" #include "fsfw/filesystem/HasFileSystemIF.h" +#include "fsfw/globalfunctions/arrayprinter.h" #include "fsfw/objectmanager.h" #include "fsfw/serviceinterface.h" #include "fsfw/tmtcservices/TmTcMessage.h" @@ -294,6 +295,7 @@ ReturnValue_t cfdp::SourceHandler::sendGenericPdu(const SerializeIF& pdu) const if (result != OK) { return result; } + arrayprinter::print(dataPtr, serializedLen); TmTcMessage tmMsg(storeId); return fsfwParams.msgQueue->sendMessage(fsfwParams.packetDest.getReportReceptionQueue(), &tmMsg); } diff --git a/unittests/cfdp/handler/testSourceHandler.cpp b/unittests/cfdp/handler/testSourceHandler.cpp index 0055dc54..e0c3a7a7 100644 --- a/unittests/cfdp/handler/testSourceHandler.cpp +++ b/unittests/cfdp/handler/testSourceHandler.cpp @@ -9,7 +9,9 @@ #include "fsfw/cfdp/pdu/FileDataCreator.h" #include "fsfw/cfdp/pdu/MetadataPduCreator.h" #include "fsfw/cfdp/pdu/MetadataPduReader.h" +#include "fsfw/globalfunctions/arrayprinter.h" #include "fsfw/storagemanager/StorageManagerIF.h" +#include "fsfw/tmtcservices/TmTcMessage.h" #include "fsfw/util/SeqCountProvider.h" #include "mocks/AcceptsTmMock.h" #include "mocks/EventReportingProxyMock.h" @@ -66,15 +68,15 @@ TEST_CASE("CFDP Source Handler", "[cfdp]") { SourceHandler::FsmResult& fsmResult = sourceHandler.stateMachine(); CHECK(fsmResult.packetsSent == 1); CHECK(mqMock.numberOfSentMessages() == 1); - CommandMessage msg; - REQUIRE(mqMock.getNextSentMessage(destQueueId, msg) == OK); - store_address_t storeId = CfdpMessage::getStoreId(&msg); - auto accessor = tmStore.getData(storeId); + TmTcMessage tmtcMessage; + REQUIRE(mqMock.getNextSentMessage(destQueueId, tmtcMessage) == OK); + auto accessor = tmStore.getData(tmtcMessage.getStorageId()); REQUIRE(accessor.first == OK); const uint8_t* pduPtr = accessor.second.data(); MetadataGenericInfo metadataInfo; MetadataPduReader metadataReader(pduPtr, accessor.second.size(), metadataInfo, nullptr, 0); size_t srcFileSize = 0; + arrayprinter::print(pduPtr, accessor.second.size()); REQUIRE(metadataReader.parseData() == OK); const char* srcNameRead = metadataReader.getSourceFileName().getString(srcFileSize); REQUIRE(srcNameRead != nullptr); diff --git a/unittests/cfdp/pdu/testMetadataPdu.cpp b/unittests/cfdp/pdu/testMetadataPdu.cpp index 38b5c11e..fbf3da08 100644 --- a/unittests/cfdp/pdu/testMetadataPdu.cpp +++ b/unittests/cfdp/pdu/testMetadataPdu.cpp @@ -36,15 +36,7 @@ TEST_CASE("Metadata PDU", "[cfdp][pdu]") { REQUIRE(options[0]->getSerializedSize() == 2 + 1 + 10 + 1); REQUIRE(options[1]->getSerializedSize() == 5); - SECTION("Serialize") { - MetadataPduCreator serializer(pduConf, info, sourceFileName, destFileName, nullptr, 0); - result = serializer.serialize(&buffer, &sz, mdBuffer.size(), SerializeIF::Endianness::NETWORK); - REQUIRE(result == returnvalue::OK); - REQUIRE(serializer.getWholePduSize() == 27); - REQUIRE(serializer.getSourceFileName().getSerializedSize() == 10); - REQUIRE(serializer.getDestFileName().getSerializedSize() == 1); - REQUIRE(info.getSerializedSize() == 5); - REQUIRE((mdBuffer[1] << 8 | mdBuffer[2]) == 17); + auto metadataCheckPartOne = [&]() { REQUIRE(mdBuffer[10] == FileDirective::METADATA); // no closure requested and checksum type is modular => 0x00 REQUIRE(mdBuffer[11] == 0x00); @@ -63,9 +55,49 @@ TEST_CASE("Metadata PDU", "[cfdp][pdu]") { REQUIRE(mdBuffer[23] == 't'); REQUIRE(mdBuffer[24] == 'x'); REQUIRE(mdBuffer[25] == 't'); + }; + SECTION("Serialize with empty dest name") { + MetadataPduCreator serializer(pduConf, info, sourceFileName, destFileName, nullptr, 0); + result = serializer.serialize(&buffer, &sz, mdBuffer.size(), SerializeIF::Endianness::NETWORK); + REQUIRE(result == returnvalue::OK); + // 10 byte heater + 1 byte PDU directive field + 1 byte PDU content + FSS field (4) + source + // name field (10) + dest name field (1). + REQUIRE(serializer.getWholePduSize() == 27); + REQUIRE(serializer.getSourceFileName().getSerializedSize() == 10); + REQUIRE(serializer.getDestFileName().getSerializedSize() == 1); + REQUIRE(info.getSerializedSize() == 5); + REQUIRE((mdBuffer[1] << 8 | mdBuffer[2]) == 17); + REQUIRE(serializer.getSerializedSize() == serializer.getWholePduSize()); + metadataCheckPartOne(); REQUIRE(mdBuffer[26] == 0); } + SECTION("Serialize with dest name") { + std::string secondFileName = "hello2.txt"; + cfdp::StringLv destFileName2(secondFileName); + MetadataPduCreator serializer(pduConf, info, sourceFileName, destFileName2, nullptr, 0); + result = serializer.serialize(&buffer, &sz, mdBuffer.size(), SerializeIF::Endianness::NETWORK); + REQUIRE(result == returnvalue::OK); + // 10 byte heater + 1 byte PDU directive field + 1 byte PDU content + FSS field (4) + source + // name field (10) + dest name field (11). + REQUIRE(serializer.getWholePduSize() == 37); + REQUIRE((mdBuffer[1] << 8 | mdBuffer[2]) == 27); + REQUIRE(serializer.getSerializedSize() == serializer.getWholePduSize()); + metadataCheckPartOne(); + // Size of destination name field + REQUIRE(mdBuffer[26] == 10); + REQUIRE(mdBuffer[27] == 'h'); + REQUIRE(mdBuffer[28] == 'e'); + REQUIRE(mdBuffer[29] == 'l'); + REQUIRE(mdBuffer[30] == 'l'); + REQUIRE(mdBuffer[31] == 'o'); + REQUIRE(mdBuffer[32] == '2'); + REQUIRE(mdBuffer[33] == '.'); + REQUIRE(mdBuffer[34] == 't'); + REQUIRE(mdBuffer[35] == 'x'); + REQUIRE(mdBuffer[36] == 't'); + } + SECTION("Serialize with 2 options") { std::string otherFileName = "hello2.txt"; cfdp::StringLv otherFileNameLv(otherFileName.data(), otherFileName.size());