init dest handler unittests
This commit is contained in:
parent
52802f127b
commit
5ce1e76723
@ -37,12 +37,14 @@ ReturnValue_t cfdp::DestHandler::performStateMachine() {
|
|||||||
// Store data was deleted in PDU handler because a store guard is used
|
// Store data was deleted in PDU handler because a store guard is used
|
||||||
dp.packetListRef.erase(infoIter++);
|
dp.packetListRef.erase(infoIter++);
|
||||||
}
|
}
|
||||||
|
infoIter++;
|
||||||
}
|
}
|
||||||
if (step == TransactionStep::IDLE) {
|
if (step == TransactionStep::IDLE) {
|
||||||
// To decrease the already high complexity of the software, all packets arriving before
|
// To decrease the already high complexity of the software, all packets arriving before
|
||||||
// a metadata PDU are deleted.
|
// a metadata PDU are deleted.
|
||||||
for (auto infoIter = dp.packetListRef.begin(); infoIter != dp.packetListRef.end();) {
|
for (auto infoIter = dp.packetListRef.begin(); infoIter != dp.packetListRef.end();) {
|
||||||
fp.tcStore->deleteData(infoIter->storeId);
|
fp.tcStore->deleteData(infoIter->storeId);
|
||||||
|
infoIter++;
|
||||||
}
|
}
|
||||||
dp.packetListRef.clear();
|
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
|
// Store data was deleted in PDU handler because a store guard is used
|
||||||
dp.packetListRef.erase(infoIter++);
|
dp.packetListRef.erase(infoIter++);
|
||||||
}
|
}
|
||||||
|
infoIter++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (step == TransactionStep::TRANSFER_COMPLETION) {
|
if (step == TransactionStep::TRANSFER_COMPLETION) {
|
||||||
|
@ -103,8 +103,9 @@ class DestHandler {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
struct TransactionParams {
|
struct TransactionParams {
|
||||||
|
// Initialize char vectors with length + 1 for 0 termination
|
||||||
explicit TransactionParams(size_t maxFileNameLen)
|
explicit TransactionParams(size_t maxFileNameLen)
|
||||||
: sourceName(maxFileNameLen), destName(maxFileNameLen) {}
|
: sourceName(maxFileNameLen + 1), destName(maxFileNameLen + 1) {}
|
||||||
|
|
||||||
void reset() {
|
void reset() {
|
||||||
pduConf = PduConfig();
|
pduConf = PduConfig();
|
||||||
|
@ -35,3 +35,5 @@ void FileDirectiveCreator::setDirectiveDataFieldLen(size_t len) {
|
|||||||
// Set length of data field plus 1 byte for the directive octet
|
// Set length of data field plus 1 byte for the directive octet
|
||||||
HeaderCreator::setPduDataFieldLen(len + 1);
|
HeaderCreator::setPduDataFieldLen(len + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cfdp::FileDirectives FileDirectiveCreator::getDirectiveCode() const { return directiveCode; }
|
||||||
|
@ -8,6 +8,8 @@ class FileDirectiveCreator : public HeaderCreator {
|
|||||||
FileDirectiveCreator(PduConfig& pduConf, cfdp::FileDirectives directiveCode,
|
FileDirectiveCreator(PduConfig& pduConf, cfdp::FileDirectives directiveCode,
|
||||||
size_t directiveParamFieldLen);
|
size_t directiveParamFieldLen);
|
||||||
|
|
||||||
|
[[nodiscard]] cfdp::FileDirectives getDirectiveCode() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This only returns the size of the PDU header + 1 for the directive code octet.
|
* 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
|
* Use FileDirectiveCreator::getWholePduSize to get the full packet length, assuming
|
||||||
|
@ -14,6 +14,7 @@ class MetadataPduCreator : public FileDirectiveCreator {
|
|||||||
|
|
||||||
ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize,
|
ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize,
|
||||||
Endianness streamEndianness) const override;
|
Endianness streamEndianness) const override;
|
||||||
|
using FileDirectiveCreator::serialize;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MetadataInfo& info;
|
MetadataInfo& info;
|
||||||
|
@ -12,6 +12,9 @@ class StringLv : public Lv {
|
|||||||
StringLv();
|
StringLv();
|
||||||
explicit StringLv(const std::string& fileName);
|
explicit StringLv(const std::string& fileName);
|
||||||
explicit StringLv(const char* filename, size_t len);
|
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
|
} // namespace cfdp
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include <catch2/catch_test_macros.hpp>
|
#include <catch2/catch_test_macros.hpp>
|
||||||
|
|
||||||
#include "fsfw/cfdp.h"
|
#include "fsfw/cfdp.h"
|
||||||
|
#include "fsfw/cfdp/pdu/MetadataPduCreator.h"
|
||||||
#include "mocks/AcceptsTmMock.h"
|
#include "mocks/AcceptsTmMock.h"
|
||||||
#include "mocks/EventReportingProxyMock.h"
|
#include "mocks/EventReportingProxyMock.h"
|
||||||
#include "mocks/FilesystemMock.h"
|
#include "mocks/FilesystemMock.h"
|
||||||
@ -17,6 +18,7 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") {
|
|||||||
AcceptsTmMock tmReceiver(destQueueId);
|
AcceptsTmMock tmReceiver(destQueueId);
|
||||||
MessageQueueMock mqMock(destQueueId);
|
MessageQueueMock mqMock(destQueueId);
|
||||||
EntityId localId = EntityId(UnsignedByteField<uint16_t>(2));
|
EntityId localId = EntityId(UnsignedByteField<uint16_t>(2));
|
||||||
|
EntityId remoteId = EntityId(UnsignedByteField<uint16_t>(3));
|
||||||
auto fhMock = FaultHandlerMock();
|
auto fhMock = FaultHandlerMock();
|
||||||
auto localEntityCfg = LocalEntityCfg(localId, IndicationCfg(), fhMock);
|
auto localEntityCfg = LocalEntityCfg(localId, IndicationCfg(), fhMock);
|
||||||
auto fsMock = FilesystemMock();
|
auto fsMock = FilesystemMock();
|
||||||
@ -41,15 +43,34 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") {
|
|||||||
CHECK(destHandler.getTransactionStep() == DestHandler::TransactionStep::IDLE);
|
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") {
|
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") {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -32,6 +32,9 @@ class StorageManagerMock : public LocalPool {
|
|||||||
std::pair<bool, ReturnValue_t> nextModifyDataCallFails;
|
std::pair<bool, ReturnValue_t> nextModifyDataCallFails;
|
||||||
std::pair<bool, ReturnValue_t> nextDeleteDataCallFails;
|
std::pair<bool, ReturnValue_t> nextDeleteDataCallFails;
|
||||||
std::pair<bool, ReturnValue_t> nextFreeElementCallFails;
|
std::pair<bool, ReturnValue_t> nextFreeElementCallFails;
|
||||||
|
|
||||||
|
using LocalPool::getFreeElement;
|
||||||
|
|
||||||
void reset();
|
void reset();
|
||||||
};
|
};
|
||||||
#endif // FSFW_TESTS_STORAGEMANAGERMOCK_H
|
#endif // FSFW_TESTS_STORAGEMANAGERMOCK_H
|
||||||
|
Loading…
Reference in New Issue
Block a user