2022-09-14 19:29:43 +02:00
|
|
|
#include <catch2/catch_test_macros.hpp>
|
2023-07-27 17:15:01 +02:00
|
|
|
#include <filesystem>
|
2022-09-14 19:29:43 +02:00
|
|
|
|
2023-07-17 11:37:20 +02:00
|
|
|
#include "fsfw/cfdp.h"
|
2023-07-27 17:15:01 +02:00
|
|
|
#include "fsfw/cfdp/handler/PutRequest.h"
|
2023-07-17 11:37:20 +02:00
|
|
|
#include "fsfw/cfdp/handler/SourceHandler.h"
|
|
|
|
#include "fsfw/cfdp/pdu/EofPduCreator.h"
|
2023-08-03 15:49:23 +02:00
|
|
|
#include "fsfw/cfdp/pdu/EofPduReader.h"
|
2023-07-17 11:37:20 +02:00
|
|
|
#include "fsfw/cfdp/pdu/MetadataPduCreator.h"
|
2023-08-03 13:57:55 +02:00
|
|
|
#include "fsfw/cfdp/pdu/MetadataPduReader.h"
|
2023-08-03 14:34:21 +02:00
|
|
|
#include "fsfw/tmtcservices/TmTcMessage.h"
|
2023-07-19 23:22:55 +02:00
|
|
|
#include "fsfw/util/SeqCountProvider.h"
|
2023-07-17 11:37:20 +02:00
|
|
|
#include "mocks/AcceptsTmMock.h"
|
|
|
|
#include "mocks/EventReportingProxyMock.h"
|
|
|
|
#include "mocks/FilesystemMock.h"
|
|
|
|
#include "mocks/MessageQueueMock.h"
|
|
|
|
#include "mocks/StorageManagerMock.h"
|
|
|
|
#include "mocks/cfdp/FaultHandlerMock.h"
|
|
|
|
#include "mocks/cfdp/RemoteConfigTableMock.h"
|
|
|
|
#include "mocks/cfdp/UserMock.h"
|
|
|
|
|
|
|
|
TEST_CASE("CFDP Source Handler", "[cfdp]") {
|
|
|
|
using namespace cfdp;
|
|
|
|
using namespace returnvalue;
|
2023-07-27 17:15:01 +02:00
|
|
|
using namespace std::filesystem;
|
2023-07-17 11:37:20 +02:00
|
|
|
MessageQueueId_t destQueueId = 2;
|
|
|
|
AcceptsTmMock tmReceiver(destQueueId);
|
|
|
|
MessageQueueMock mqMock(destQueueId);
|
|
|
|
EntityId localId = EntityId(UnsignedByteField<uint16_t>(2));
|
|
|
|
EntityId remoteId = EntityId(UnsignedByteField<uint16_t>(3));
|
|
|
|
FaultHandlerMock fhMock;
|
|
|
|
LocalEntityCfg localEntityCfg(localId, IndicationCfg(), fhMock);
|
|
|
|
FilesystemMock fsMock;
|
|
|
|
UserMock userMock(fsMock);
|
2023-07-19 23:22:55 +02:00
|
|
|
SeqCountProviderU16 seqCountProvider;
|
|
|
|
SourceHandlerParams dp(localEntityCfg, userMock, seqCountProvider);
|
2023-07-17 11:37:20 +02:00
|
|
|
|
|
|
|
EventReportingProxyMock eventReporterMock;
|
|
|
|
LocalPool::LocalPoolConfig storeCfg = {{10, 32}, {10, 64}, {10, 128}, {10, 1024}};
|
|
|
|
StorageManagerMock tcStore(2, storeCfg);
|
|
|
|
StorageManagerMock tmStore(3, storeCfg);
|
|
|
|
FsfwParams fp(tmReceiver, &mqMock, &eventReporterMock);
|
2023-08-03 13:03:58 +02:00
|
|
|
fp.tcStore = &tcStore;
|
|
|
|
fp.tmStore = &tmStore;
|
2023-07-17 11:37:20 +02:00
|
|
|
auto sourceHandler = SourceHandler(dp, fp);
|
2023-08-03 13:03:58 +02:00
|
|
|
CHECK(sourceHandler.initialize() == OK);
|
2023-07-27 17:15:01 +02:00
|
|
|
|
|
|
|
SECTION("Test Basic") {
|
|
|
|
CHECK(sourceHandler.getState() == CfdpState::IDLE);
|
|
|
|
CHECK(sourceHandler.getStep() == SourceHandler::TransactionStep::IDLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("Transfer empty file") {
|
|
|
|
RemoteEntityCfg cfg;
|
2023-08-03 15:30:38 +02:00
|
|
|
EntityId id(cfdp::WidthInBytes::TWO_BYTES, 5);
|
2023-07-27 17:15:01 +02:00
|
|
|
cfg.remoteId = id;
|
2023-08-03 15:30:38 +02:00
|
|
|
std::string srcFileName = "/tmp/cfdp-test.txt";
|
|
|
|
std::string destFileName = "/tmp/cfdp-test2.txt";
|
|
|
|
FilesystemParams srcFileNameFs(srcFileName.c_str());
|
|
|
|
fsMock.createFile(srcFileNameFs);
|
|
|
|
cfdp::StringLv srcNameLv(srcFileNameFs.path, std::strlen(srcFileNameFs.path));
|
|
|
|
FilesystemParams destFileNameFs(destFileName.c_str());
|
|
|
|
cfdp::StringLv destNameLv(destFileNameFs.path, std::strlen(destFileNameFs.path));
|
2023-07-27 17:15:01 +02:00
|
|
|
PutRequest putRequest(id, srcNameLv, destNameLv);
|
|
|
|
CHECK(sourceHandler.transactionStart(putRequest, cfg) == OK);
|
2023-08-03 13:03:58 +02:00
|
|
|
SourceHandler::FsmResult& fsmResult = sourceHandler.stateMachine();
|
2023-08-03 15:30:38 +02:00
|
|
|
|
2023-08-03 14:34:21 +02:00
|
|
|
TmTcMessage tmtcMessage;
|
2023-08-03 15:49:23 +02:00
|
|
|
const uint8_t* pduPtr;
|
|
|
|
// Verify metadata PDU was sent.
|
|
|
|
{
|
|
|
|
CHECK(fsmResult.packetsSent == 1);
|
|
|
|
CHECK(mqMock.numberOfSentMessages() == 1);
|
|
|
|
REQUIRE(mqMock.getNextSentMessage(destQueueId, tmtcMessage) == OK);
|
|
|
|
auto accessor = tmStore.getData(tmtcMessage.getStorageId());
|
|
|
|
REQUIRE(accessor.first == OK);
|
|
|
|
pduPtr = accessor.second.data();
|
|
|
|
CHECK(accessor.second.size() == 55);
|
|
|
|
MetadataGenericInfo metadataInfo;
|
|
|
|
MetadataPduReader metadataReader(pduPtr, accessor.second.size(), metadataInfo, nullptr, 0);
|
|
|
|
REQUIRE(metadataReader.parseData() == OK);
|
|
|
|
std::string srcNameRead = metadataReader.getSourceFileName().getString();
|
|
|
|
CHECK(srcNameRead == srcFileName);
|
|
|
|
std::string destNameRead = metadataReader.getDestFileName().getString();
|
|
|
|
CHECK(destNameRead == destFileName);
|
|
|
|
CHECK(metadataInfo.getChecksumType() == ChecksumType::NULL_CHECKSUM);
|
|
|
|
CHECK(metadataInfo.getFileSize().value() == 0);
|
|
|
|
CHECK(!metadataInfo.isClosureRequested());
|
|
|
|
}
|
2023-08-03 15:30:38 +02:00
|
|
|
|
|
|
|
// Verify EOF PDU was sent. No file data PDU is sent for an empty file.
|
2023-08-03 15:49:23 +02:00
|
|
|
{
|
|
|
|
mqMock.clearMessages();
|
|
|
|
fsmResult = sourceHandler.stateMachine();
|
|
|
|
CHECK(fsmResult.packetsSent == 1);
|
|
|
|
CHECK(mqMock.numberOfSentMessages() == 1);
|
|
|
|
REQUIRE(mqMock.getNextSentMessage(destQueueId, tmtcMessage) == OK);
|
|
|
|
auto accessor = tmStore.getData(tmtcMessage.getStorageId());
|
|
|
|
REQUIRE(accessor.first == OK);
|
|
|
|
pduPtr = accessor.second.data();
|
|
|
|
// 10 byte PDU header, 1 byte directive field, 1 byte condition code, 4 byte checksum,
|
|
|
|
// 4 byte FSS
|
|
|
|
CHECK(accessor.second.size() == 20);
|
|
|
|
EofInfo eofInfo;
|
|
|
|
EofPduReader eofReader(pduPtr, accessor.second.size(), eofInfo);
|
|
|
|
REQUIRE(eofReader.parseData() == OK);
|
|
|
|
CHECK(eofInfo.getChecksum() == 0);
|
|
|
|
CHECK(eofInfo.getConditionCode() == ConditionCode::NO_ERROR);
|
|
|
|
CHECK(eofInfo.getFileSize().value() == 0);
|
|
|
|
}
|
|
|
|
CHECK(sourceHandler.getStep() == SourceHandler::TransactionStep::IDLE);
|
|
|
|
CHECK(sourceHandler.getState() == CfdpState::IDLE);
|
2023-07-27 17:15:01 +02:00
|
|
|
}
|
2023-07-17 11:37:20 +02:00
|
|
|
}
|