init dest handler unittests

This commit is contained in:
Robin Müller 2022-09-05 14:20:01 +02:00
parent 52802f127b
commit 5ce1e76723
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
8 changed files with 44 additions and 8 deletions

View File

@ -37,12 +37,14 @@ ReturnValue_t cfdp::DestHandler::performStateMachine() {
// Store data was deleted in PDU handler because a store guard is used
dp.packetListRef.erase(infoIter++);
}
infoIter++;
}
if (step == TransactionStep::IDLE) {
// To decrease the already high complexity of the software, all packets arriving before
// a metadata PDU are deleted.
for (auto infoIter = dp.packetListRef.begin(); infoIter != dp.packetListRef.end();) {
fp.tcStore->deleteData(infoIter->storeId);
infoIter++;
}
dp.packetListRef.clear();
}
@ -73,6 +75,7 @@ ReturnValue_t cfdp::DestHandler::performStateMachine() {
// Store data was deleted in PDU handler because a store guard is used
dp.packetListRef.erase(infoIter++);
}
infoIter++;
}
}
if (step == TransactionStep::TRANSFER_COMPLETION) {

View File

@ -103,8 +103,9 @@ class DestHandler {
private:
struct TransactionParams {
// Initialize char vectors with length + 1 for 0 termination
explicit TransactionParams(size_t maxFileNameLen)
: sourceName(maxFileNameLen), destName(maxFileNameLen) {}
: sourceName(maxFileNameLen + 1), destName(maxFileNameLen + 1) {}
void reset() {
pduConf = PduConfig();

View File

@ -35,3 +35,5 @@ void FileDirectiveCreator::setDirectiveDataFieldLen(size_t len) {
// Set length of data field plus 1 byte for the directive octet
HeaderCreator::setPduDataFieldLen(len + 1);
}
cfdp::FileDirectives FileDirectiveCreator::getDirectiveCode() const { return directiveCode; }

View File

@ -8,6 +8,8 @@ class FileDirectiveCreator : public HeaderCreator {
FileDirectiveCreator(PduConfig& pduConf, cfdp::FileDirectives directiveCode,
size_t directiveParamFieldLen);
[[nodiscard]] cfdp::FileDirectives getDirectiveCode() const;
/**
* This only returns the size of the PDU header + 1 for the directive code octet.
* Use FileDirectiveCreator::getWholePduSize to get the full packet length, assuming

View File

@ -14,6 +14,7 @@ class MetadataPduCreator : public FileDirectiveCreator {
ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize,
Endianness streamEndianness) const override;
using FileDirectiveCreator::serialize;
private:
MetadataInfo& info;

View File

@ -12,6 +12,9 @@ class StringLv : public Lv {
StringLv();
explicit StringLv(const std::string& fileName);
explicit StringLv(const char* filename, size_t len);
// Delete the move constructor to avoid passing in a temporary
StringLv(const std::string&&) = delete;
};
} // namespace cfdp

View File

@ -1,6 +1,7 @@
#include <catch2/catch_test_macros.hpp>
#include "fsfw/cfdp.h"
#include "fsfw/cfdp/pdu/MetadataPduCreator.h"
#include "mocks/AcceptsTmMock.h"
#include "mocks/EventReportingProxyMock.h"
#include "mocks/FilesystemMock.h"
@ -17,6 +18,7 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") {
AcceptsTmMock tmReceiver(destQueueId);
MessageQueueMock mqMock(destQueueId);
EntityId localId = EntityId(UnsignedByteField<uint16_t>(2));
EntityId remoteId = EntityId(UnsignedByteField<uint16_t>(3));
auto fhMock = FaultHandlerMock();
auto localEntityCfg = LocalEntityCfg(localId, IndicationCfg(), fhMock);
auto fsMock = FilesystemMock();
@ -41,15 +43,34 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") {
CHECK(destHandler.getTransactionStep() == DestHandler::TransactionStep::IDLE);
}
SECTION("Idle State Machine Iteration") {
CHECK(destHandler.performStateMachine() == OK);
CHECK(destHandler.getCfdpState() == CfdpStates::IDLE);
CHECK(destHandler.getTransactionStep() == DestHandler::TransactionStep::IDLE);
}
SECTION("Empty File Transfer") {
CHECK(destHandler.performStateMachine() == OK);
FileSize size(0);
std::string srcNameString = "hello.txt";
std::string destNameString = "hello-cpy.txt";
StringLv srcName(srcNameString);
StringLv destName(destNameString);
MetadataInfo info(false, cfdp::ChecksumTypes::NULL_CHECKSUM, size, srcName, destName);
auto seqNum = TransactionSeqNum(UnsignedByteField<uint16_t>(1));
PduConfig conf(remoteId, localId, TransmissionModes::UNACKNOWLEDGED, seqNum);
MetadataPduCreator metadataPdu(conf, info);
store_address_t storeId;
uint8_t* ptr;
CHECK(tcStore.getFreeElement(&storeId, metadataPdu.getSerializedSize(), &ptr) == OK);
size_t serLen = 0;
CHECK(metadataPdu.serialize(ptr, serLen, metadataPdu.getSerializedSize()) == OK);
PacketInfo packetInfo(metadataPdu.getPduType(), metadataPdu.getDirectiveCode(), storeId);
packetInfoList.push_back(packetInfo);
CHECK(destHandler.performStateMachine() == OK);
}
SECTION("Small File Transfer") {
SECTION("Small File Transfer") {}
}
SECTION("Segmented File Transfer") {
}
SECTION("Segmented File Transfer") {}
}

View File

@ -32,6 +32,9 @@ class StorageManagerMock : public LocalPool {
std::pair<bool, ReturnValue_t> nextModifyDataCallFails;
std::pair<bool, ReturnValue_t> nextDeleteDataCallFails;
std::pair<bool, ReturnValue_t> nextFreeElementCallFails;
using LocalPool::getFreeElement;
void reset();
};
#endif // FSFW_TESTS_STORAGEMANAGERMOCK_H