add CFDP fault handler mock
This commit is contained in:
1
unittests/cfdp/handler/CMakeLists.txt
Normal file
1
unittests/cfdp/handler/CMakeLists.txt
Normal file
@ -0,0 +1 @@
|
||||
target_sources(${FSFW_TEST_TGT} PRIVATE testDistributor.cpp testDestHandler.cpp)
|
3
unittests/cfdp/handler/testDestHandler.cpp
Normal file
3
unittests/cfdp/handler/testDestHandler.cpp
Normal file
@ -0,0 +1,3 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
TEST_CASE("CFDP Dest Handler", "[cfdp]") {}
|
98
unittests/cfdp/handler/testDistributor.cpp
Normal file
98
unittests/cfdp/handler/testDistributor.cpp
Normal file
@ -0,0 +1,98 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "fsfw/cfdp/CfdpDistributor.h"
|
||||
#include "fsfw/cfdp/pdu/MetadataPduCreator.h"
|
||||
#include "fsfw/storagemanager/LocalPool.h"
|
||||
#include "fsfw/tcdistribution/definitions.h"
|
||||
#include "mocks/AcceptsTcMock.h"
|
||||
#include "mocks/MessageQueueMock.h"
|
||||
#include "mocks/StorageManagerMock.h"
|
||||
|
||||
TEST_CASE("CFDP Distributor", "[cfdp][distributor]") {
|
||||
LocalPool::LocalPoolConfig cfg = {{5, 32}, {2, 64}};
|
||||
StorageManagerMock pool(objects::NO_OBJECT, cfg);
|
||||
auto queue = MessageQueueMock(1);
|
||||
CfdpDistribCfg distribCfg(1, pool, &queue);
|
||||
auto distributor = CfdpDistributor(distribCfg);
|
||||
auto obswEntityId = cfdp::EntityId(UnsignedByteField<uint16_t>(2));
|
||||
auto groundEntityId = cfdp::EntityId(UnsignedByteField<uint16_t>(1));
|
||||
MessageQueueId_t receiverQueueId = 3;
|
||||
auto tcAcceptor = AcceptsTcMock("CFDP Receiver", 0, receiverQueueId);
|
||||
|
||||
// Set up Metadata PDU for generate test data.
|
||||
cfdp::FileSize fileSize(12);
|
||||
const cfdp::EntityId& sourceId(groundEntityId);
|
||||
const cfdp::EntityId& destId(obswEntityId);
|
||||
cfdp::TransactionSeqNum seqNum(UnsignedByteField<uint16_t>(12));
|
||||
auto pduConf = PduConfig(sourceId, destId, cfdp::TransmissionModes::UNACKNOWLEDGED, seqNum);
|
||||
std::string sourceFileString = "hello.txt";
|
||||
cfdp::Lv sourceFileName(sourceFileString.c_str(), sourceFileString.size());
|
||||
std::string destFileString = "hello2.txt";
|
||||
cfdp::Lv destFileName(destFileString.c_str(), sourceFileString.size());
|
||||
MetadataInfo metadataInfo(false, cfdp::ChecksumType::CRC_32, fileSize, sourceFileName,
|
||||
destFileName);
|
||||
MetadataPduCreator creator(pduConf, metadataInfo);
|
||||
uint8_t* dataPtr = nullptr;
|
||||
|
||||
SECTION("State") {
|
||||
CHECK(distributor.initialize() == result::OK);
|
||||
CHECK(std::strcmp(distributor.getName(), "CFDP Distributor") == 0);
|
||||
CHECK(distributor.getIdentifier() == 0);
|
||||
CHECK(distributor.getRequestQueue() == queue.getId());
|
||||
}
|
||||
|
||||
SECTION("Packet Forwarding") {
|
||||
CHECK(distributor.initialize() == result::OK);
|
||||
CHECK(distributor.registerTcDestination(obswEntityId, tcAcceptor) == result::OK);
|
||||
size_t serLen = 0;
|
||||
store_address_t storeId;
|
||||
CHECK(pool.LocalPool::getFreeElement(&storeId, creator.getSerializedSize(), &dataPtr) ==
|
||||
result::OK);
|
||||
REQUIRE(creator.SerializeIF::serializeBe(dataPtr, serLen, creator.getSerializedSize()) ==
|
||||
result::OK);
|
||||
TmTcMessage msg(storeId);
|
||||
queue.addReceivedMessage(msg);
|
||||
CHECK(distributor.performOperation(0) == result::OK);
|
||||
CHECK(queue.wasMessageSent());
|
||||
CHECK(queue.numberOfSentMessages() == 1);
|
||||
// The packet is forwarded, with no need to delete the data
|
||||
CHECK(pool.hasDataAtId(storeId));
|
||||
TmTcMessage sentMsg;
|
||||
CHECK(queue.getNextSentMessage(receiverQueueId, sentMsg) == result::OK);
|
||||
CHECK(sentMsg.getStorageId() == storeId);
|
||||
}
|
||||
|
||||
SECTION("No Destination found") {
|
||||
CHECK(distributor.initialize() == result::OK);
|
||||
size_t serLen = 0;
|
||||
store_address_t storeId;
|
||||
CHECK(pool.LocalPool::getFreeElement(&storeId, creator.getSerializedSize(), &dataPtr) ==
|
||||
result::OK);
|
||||
REQUIRE(creator.SerializeIF::serializeBe(dataPtr, serLen, creator.getSerializedSize()) ==
|
||||
result::OK);
|
||||
TmTcMessage msg(storeId);
|
||||
queue.addReceivedMessage(msg);
|
||||
CHECK(distributor.performOperation(0) == tmtcdistrib::NO_DESTINATION_FOUND);
|
||||
}
|
||||
|
||||
SECTION("Getting data fails") {
|
||||
pool.nextModifyDataCallFails.first = true;
|
||||
pool.nextModifyDataCallFails.second = StorageManagerIF::DATA_DOES_NOT_EXIST;
|
||||
size_t serLen = 0;
|
||||
store_address_t storeId;
|
||||
CHECK(distributor.registerTcDestination(obswEntityId, tcAcceptor) == result::OK);
|
||||
CHECK(pool.LocalPool::getFreeElement(&storeId, creator.getSerializedSize(), &dataPtr) ==
|
||||
result::OK);
|
||||
REQUIRE(creator.SerializeIF::serializeBe(dataPtr, serLen, creator.getSerializedSize()) ==
|
||||
result::OK);
|
||||
TmTcMessage msg(storeId);
|
||||
queue.addReceivedMessage(msg);
|
||||
CHECK(distributor.performOperation(0) == StorageManagerIF::DATA_DOES_NOT_EXIST);
|
||||
}
|
||||
|
||||
SECTION("Duplicate registration") {
|
||||
CHECK(distributor.initialize() == result::OK);
|
||||
CHECK(distributor.registerTcDestination(obswEntityId, tcAcceptor) == result::OK);
|
||||
CHECK(distributor.registerTcDestination(obswEntityId, tcAcceptor) == result::FAILED);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user