fsfw/unittests/cfdp/handler/testDestHandler.cpp

127 lines
5.5 KiB
C++
Raw Normal View History

2022-08-08 12:41:05 +02:00
#include <catch2/catch_test_macros.hpp>
2022-08-09 15:46:42 +02:00
#include "fsfw/cfdp.h"
2022-09-06 11:56:05 +02:00
#include "fsfw/cfdp/pdu/EofPduCreator.h"
2022-09-06 13:16:00 +02:00
#include "fsfw/cfdp/pdu/MetadataPduCreator.h"
2022-09-05 11:19:23 +02:00
#include "mocks/AcceptsTmMock.h"
#include "mocks/EventReportingProxyMock.h"
2022-08-17 17:09:39 +02:00
#include "mocks/FilesystemMock.h"
2022-09-05 11:19:23 +02:00
#include "mocks/MessageQueueMock.h"
#include "mocks/StorageManagerMock.h"
#include "mocks/cfdp/FaultHandlerMock.h"
2022-08-17 17:09:39 +02:00
#include "mocks/cfdp/RemoteConfigTableMock.h"
#include "mocks/cfdp/UserMock.h"
2022-08-10 15:03:53 +02:00
2022-08-09 15:46:42 +02:00
TEST_CASE("CFDP Dest Handler", "[cfdp]") {
using namespace cfdp;
using namespace returnvalue;
2022-09-05 11:19:23 +02:00
MessageQueueId_t destQueueId = 2;
AcceptsTmMock tmReceiver(destQueueId);
MessageQueueMock mqMock(destQueueId);
2022-08-09 16:36:35 +02:00
EntityId localId = EntityId(UnsignedByteField<uint16_t>(2));
2022-09-05 14:20:01 +02:00
EntityId remoteId = EntityId(UnsignedByteField<uint16_t>(3));
2022-09-06 13:16:00 +02:00
FaultHandlerMock fhMock;
LocalEntityCfg localEntityCfg(localId, IndicationCfg(), fhMock);
FilesystemMock fsMock;
UserMock userMock(fsMock);
RemoteConfigTableMock remoteCfgTableMock;
2022-09-05 11:19:23 +02:00
PacketInfoList<64> packetInfoList;
LostSegmentsList<128> lostSegmentsList;
DestHandlerParams dp(localEntityCfg, userMock, remoteCfgTableMock, packetInfoList,
lostSegmentsList);
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);
2022-09-05 17:20:29 +02:00
RemoteEntityCfg cfg;
cfg.remoteId = remoteId;
remoteCfgTableMock.addRemoteConfig(cfg);
fp.tcStore = &tcStore;
fp.tmStore = &tmStore;
auto destHandler = DestHandler(dp, fp);
CHECK(destHandler.initialize() == OK);
2022-08-09 15:46:42 +02:00
SECTION("State") {
CHECK(destHandler.getCfdpState() == CfdpStates::IDLE);
CHECK(destHandler.getTransactionStep() == DestHandler::TransactionStep::IDLE);
}
2022-09-05 11:40:22 +02:00
2022-09-05 14:20:01 +02:00
SECTION("Idle State Machine Iteration") {
2022-09-05 17:20:29 +02:00
auto res = destHandler.performStateMachine();
CHECK(res.result == OK);
CHECK(res.callStatus == CallStatus::CALL_AFTER_DELAY);
CHECK(res.errors == 0);
2022-09-05 14:20:01 +02:00
CHECK(destHandler.getCfdpState() == CfdpStates::IDLE);
CHECK(destHandler.getTransactionStep() == DestHandler::TransactionStep::IDLE);
2022-09-05 11:40:22 +02:00
}
2022-09-05 14:20:01 +02:00
SECTION("Empty File Transfer") {
2022-09-05 17:42:56 +02:00
const DestHandler::FsmResult& res = destHandler.performStateMachine();
2022-09-05 17:20:29 +02:00
CHECK(res.result == OK);
2022-09-05 14:20:01 +02:00
FileSize size(0);
std::string srcNameString = "hello.txt";
std::string destNameString = "hello-cpy.txt";
StringLv srcName(srcNameString);
StringLv destName(destNameString);
2022-09-06 11:56:05 +02:00
FileSize cfdpFileSize(0);
2022-09-05 14:20:01 +02:00
MetadataInfo info(false, cfdp::ChecksumTypes::NULL_CHECKSUM, size, srcName, destName);
TransactionSeqNum seqNum(UnsignedByteField<uint16_t>(1));
2022-09-05 14:20:01 +02:00
PduConfig conf(remoteId, localId, TransmissionModes::UNACKNOWLEDGED, seqNum);
2022-09-06 11:56:05 +02:00
MetadataPduCreator metadataCreator(conf, info);
2022-09-05 14:20:01 +02:00
store_address_t storeId;
uint8_t* ptr;
2022-09-06 11:56:05 +02:00
REQUIRE(tcStore.getFreeElement(&storeId, metadataCreator.getSerializedSize(), &ptr) == OK);
2022-09-05 14:20:01 +02:00
size_t serLen = 0;
2022-09-06 11:56:05 +02:00
REQUIRE(metadataCreator.serialize(ptr, serLen, metadataCreator.getSerializedSize()) == OK);
2022-09-06 13:16:00 +02:00
PacketInfo packetInfo(metadataCreator.getPduType(), metadataCreator.getDirectiveCode(),
storeId);
2022-09-05 14:20:01 +02:00
packetInfoList.push_back(packetInfo);
2022-09-05 17:20:29 +02:00
destHandler.performStateMachine();
2022-09-06 11:56:05 +02:00
REQUIRE(res.result == OK);
REQUIRE(res.callStatus == CallStatus::CALL_AGAIN);
// Assert that the packet was deleted after handling
REQUIRE(not tcStore.hasDataAtId(storeId));
REQUIRE(packetInfoList.empty());
2022-09-05 17:42:56 +02:00
destHandler.performStateMachine();
2022-09-06 13:16:00 +02:00
REQUIRE(userMock.metadataRecvd.size() == 1);
2022-09-06 14:06:22 +02:00
auto& idMetadataPair = userMock.metadataRecvd.back();
REQUIRE(idMetadataPair.first == destHandler.getTransactionId());
REQUIRE(idMetadataPair.second.sourceId.getValue() == 3);
REQUIRE(idMetadataPair.second.fileSize == 0);
REQUIRE(strcmp(idMetadataPair.second.destFileName, "hello-cpy.txt") == 0);
REQUIRE(strcmp(idMetadataPair.second.sourceFileName, "hello.txt") == 0);
userMock.metadataRecvd.pop();
2022-09-06 11:56:05 +02:00
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);
packetInfo = PacketInfo(eofCreator.getPduType(), eofCreator.getDirectiveCode(), storeId);
packetInfoList.push_back(packetInfo);
auto transactionId = destHandler.getTransactionId();
// After EOF, operation is done because no closure was requested
destHandler.performStateMachine();
REQUIRE(res.result == OK);
REQUIRE(res.state == CfdpStates::IDLE);
REQUIRE(res.step == DestHandler::TransactionStep::IDLE);
// Assert that the packet was deleted after handling
REQUIRE(not tcStore.hasDataAtId(storeId));
REQUIRE(packetInfoList.empty());
REQUIRE(userMock.eofsRevd.size() == 1);
auto& eofId = userMock.eofsRevd.back();
CHECK(eofId == transactionId);
2022-09-06 14:06:22 +02:00
REQUIRE(userMock.finishedRecvd.size() == 1);
auto& idParamPair = userMock.finishedRecvd.back();
CHECK(idParamPair.first == transactionId);
CHECK(idParamPair.second.condCode == ConditionCode::NO_ERROR);
2022-09-05 11:40:22 +02:00
}
2022-09-05 14:20:01 +02:00
SECTION("Small File Transfer") {}
SECTION("Segmented File Transfer") {}
2022-08-09 15:46:42 +02:00
}