From 7b97c8a1823a5acd1813769d2b0e8116edc2e913 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 6 Sep 2022 11:56:05 +0200 Subject: [PATCH] continue tests --- src/fsfw/cfdp/handler/DestHandler.cpp | 7 ++++++ src/fsfw/cfdp/pdu/EofPduCreator.h | 2 ++ unittests/cfdp/handler/testDestHandler.cpp | 25 ++++++++++++++++------ 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/fsfw/cfdp/handler/DestHandler.cpp b/src/fsfw/cfdp/handler/DestHandler.cpp index 23852272..ed529cc0 100644 --- a/src/fsfw/cfdp/handler/DestHandler.cpp +++ b/src/fsfw/cfdp/handler/DestHandler.cpp @@ -319,6 +319,13 @@ ReturnValue_t cfdp::DestHandler::startTransaction(MetadataPduReader& reader, Met params.sourceFileName = tp.sourceName.data(); params.msgsToUserArray = dynamic_cast(userTlvVec.data()); params.msgsToUserLen = info.getOptionsLen(); + FilesystemParams fparams(tp.destName.data()); + // TODO: Filesystem errors? + if (dp.user.vfs.fileExists(fparams)) { + dp.user.vfs.truncateFile(fparams); + } else { + dp.user.vfs.createFile(fparams); + } dp.user.metadataRecvdIndication(params); return OK; } diff --git a/src/fsfw/cfdp/pdu/EofPduCreator.h b/src/fsfw/cfdp/pdu/EofPduCreator.h index 7f7a25ab..f098a5d2 100644 --- a/src/fsfw/cfdp/pdu/EofPduCreator.h +++ b/src/fsfw/cfdp/pdu/EofPduCreator.h @@ -14,6 +14,8 @@ class EofPduCreator : public FileDirectiveCreator { ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, Endianness streamEndianness) const override; + using FileDirectiveCreator::serialize; + private: EofInfo& info; }; diff --git a/unittests/cfdp/handler/testDestHandler.cpp b/unittests/cfdp/handler/testDestHandler.cpp index 3fc8f472..82f6db45 100644 --- a/unittests/cfdp/handler/testDestHandler.cpp +++ b/unittests/cfdp/handler/testDestHandler.cpp @@ -2,6 +2,7 @@ #include "fsfw/cfdp.h" #include "fsfw/cfdp/pdu/MetadataPduCreator.h" +#include "fsfw/cfdp/pdu/EofPduCreator.h" #include "mocks/AcceptsTmMock.h" #include "mocks/EventReportingProxyMock.h" #include "mocks/FilesystemMock.h" @@ -63,21 +64,33 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { std::string destNameString = "hello-cpy.txt"; StringLv srcName(srcNameString); StringLv destName(destNameString); + FileSize cfdpFileSize(0); MetadataInfo info(false, cfdp::ChecksumTypes::NULL_CHECKSUM, size, srcName, destName); auto seqNum = TransactionSeqNum(UnsignedByteField(1)); PduConfig conf(remoteId, localId, TransmissionModes::UNACKNOWLEDGED, seqNum); - MetadataPduCreator metadataPdu(conf, info); + MetadataPduCreator metadataCreator(conf, info); store_address_t storeId; uint8_t* ptr; - CHECK(tcStore.getFreeElement(&storeId, metadataPdu.getSerializedSize(), &ptr) == OK); + REQUIRE(tcStore.getFreeElement(&storeId, metadataCreator.getSerializedSize(), &ptr) == OK); size_t serLen = 0; - CHECK(metadataPdu.serialize(ptr, serLen, metadataPdu.getSerializedSize()) == OK); - PacketInfo packetInfo(metadataPdu.getPduType(), metadataPdu.getDirectiveCode(), storeId); + REQUIRE(metadataCreator.serialize(ptr, serLen, metadataCreator.getSerializedSize()) == OK); + PacketInfo packetInfo(metadataCreator.getPduType(), metadataCreator.getDirectiveCode(), storeId); packetInfoList.push_back(packetInfo); destHandler.performStateMachine(); - CHECK(res.result == OK); - CHECK(res.callStatus == CallStatus::CALL_AGAIN); + REQUIRE(res.result == OK); + REQUIRE(res.callStatus == CallStatus::CALL_AGAIN); + // Assert that the packet was deleted after handling + REQUIRE(not tcStore.hasDataAtId(storeId)); destHandler.performStateMachine(); + REQUIRE(fsMock.fileMap.find("hello-cpy.txt") != fsMock.fileMap.end()); + REQUIRE(res.result == OK); + REQUIRE(res.callStatus == CallStatus::CALL_AFTER_DELAY); + REQUIRE(res.state == CfdpStates::BUSY_CLASS_1_NACKED); + REQUIRE(res.step == DestHandler::TransactionStep::RECEIVING_FILE_DATA_PDUS); + EofInfo eofInfo(cfdp::ConditionCode::NO_ERROR, 0, cfdpFileSize); + EofPduCreator eofCreator(conf, eofInfo); + REQUIRE(tcStore.getFreeElement(&storeId, eofCreator.getSerializedSize(), &ptr) == OK); + REQUIRE(eofCreator.serialize(ptr, serLen, eofCreator.getSerializedSize()) == OK); } SECTION("Small File Transfer") {}