insidious bug

This commit is contained in:
Robin Müller 2023-08-03 15:13:26 +02:00
parent 0cccf26021
commit daf75547a4
Signed by: muellerr
GPG Key ID: 407F9B00F858F270
6 changed files with 21 additions and 9 deletions

View File

@ -153,3 +153,5 @@ bool cfdp::VarLenField::operator==(const cfdp::VarLenField &other) const {
bool cfdp::VarLenField::operator!=(const cfdp::VarLenField &other) const {
return not(*this == other);
}
void cfdp::VarLenField::setWidth(cfdp::WidthInBytes width_) { this->width = width_; }

View File

@ -32,6 +32,7 @@ class VarLenField : public SerializeIF {
bool operator<(const VarLenField &other) const;
ReturnValue_t setValueAndWidth(cfdp::WidthInBytes width, uint64_t value);
void setWidth(cfdp::WidthInBytes width);
ReturnValue_t setValue(uint64_t value);
ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize,

View File

@ -19,12 +19,15 @@ cfdp::SourceHandler::SourceHandler(SourceHandlerParams params, FsfwParams fsfwPa
: sourceParams(std::move(params)), fsfwParams(fsfwParams) {
// The entity ID portion of the transaction ID will always remain fixed.
transactionParams.id.entityId = sourceParams.cfg.localId;
transactionParams.pduConf.sourceId = sourceParams.cfg.localId;
if (sourceParams.seqCountProvider.bitWidth() == 8) {
transactionParams.seqCountWidth = cfdp::WidthInBytes::ONE_BYTE;
transactionParams.pduConf.seqNum.setWidth(cfdp::WidthInBytes::ONE_BYTE);
} else if (sourceParams.seqCountProvider.bitWidth() == 16) {
transactionParams.seqCountWidth = cfdp::WidthInBytes::TWO_BYTES;
transactionParams.pduConf.seqNum.setWidth(cfdp::WidthInBytes::TWO_BYTES);
} else if (sourceParams.seqCountProvider.bitWidth() == 32) {
transactionParams.seqCountWidth = cfdp::WidthInBytes::FOUR_BYTES;
transactionParams.pduConf.seqNum.setWidth(cfdp::WidthInBytes::FOUR_BYTES);
} else if (sourceParams.seqCountProvider.bitWidth() == 64) {
transactionParams.pduConf.seqNum.setWidth(cfdp::WidthInBytes::EIGHT_BYTES);
} else {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "cfdp::SourceHandler: Seq count provider bit width "
@ -34,7 +37,7 @@ cfdp::SourceHandler::SourceHandler(SourceHandlerParams params, FsfwParams fsfwPa
sourceParams.seqCountProvider.bitWidth());
#endif
// Yeah, what am I supposed to do here? Can't throw an exception in the FSFW..
transactionParams.seqCountWidth = cfdp::WidthInBytes::ONE_BYTE;
transactionParams.pduConf.seqNum.setWidth(cfdp::WidthInBytes::ONE_BYTE);
}
}
@ -172,10 +175,13 @@ ReturnValue_t cfdp::SourceHandler::transactionStart(PutRequest& putRequest, Remo
if (not putRequest.getClosureRequested(transactionParams.closureRequested)) {
transactionParams.closureRequested = cfg.closureRequested;
}
transactionParams.pduConf.destId = putRequest.getDestId();
const EntityId& destId = putRequest.getDestId();
transactionParams.pduConf.destId = destId;
// Adapt source ID width to necessary width. The width of the source and destination ID must be
// the same.
transactionParams.pduConf.sourceId.setWidth(destId.getWidth());
// Only used for PDU forwarding, file is sent to file receiver regularly here.
transactionParams.pduConf.direction = Direction::TOWARDS_RECEIVER;
transactionParams.pduConf.sourceId = sourceParams.cfg.localId;
transactionParams.id.seqNum.setValue(sourceParams.seqCountProvider.getAndIncrement());
if (transactionParams.pduConf.mode == TransmissionMode::ACKNOWLEDGED) {

View File

@ -76,7 +76,7 @@ class SourceHandler {
RemoteEntityCfg remoteCfg;
PduConfig pduConf;
cfdp::TransactionId id{};
cfdp::WidthInBytes seqCountWidth{};
// cfdp::WidthInBytes seqCountWidth{};
void reset() {
sourceNameSize = 0;

View File

@ -61,7 +61,7 @@ TEST_CASE("CFDP Source Handler", "[cfdp]") {
FilesystemParams srcFileName("/tmp/cfdp-test.txt");
fsMock.createFile(srcFileName);
cfdp::StringLv srcNameLv(srcFileName.path, std::strlen(srcFileName.path));
FilesystemParams destFileName("/tmp/cfdp-test.txt");
FilesystemParams destFileName("/tmp/cfdp-test2.txt");
cfdp::StringLv destNameLv(destFileName.path, std::strlen(destFileName.path));
PutRequest putRequest(id, srcNameLv, destNameLv);
CHECK(sourceHandler.transactionStart(putRequest, cfg) == OK);
@ -73,6 +73,7 @@ TEST_CASE("CFDP Source Handler", "[cfdp]") {
auto accessor = tmStore.getData(tmtcMessage.getStorageId());
REQUIRE(accessor.first == OK);
const uint8_t* pduPtr = accessor.second.data();
CHECK(accessor.second.size() == 55);
MetadataGenericInfo metadataInfo;
MetadataPduReader metadataReader(pduPtr, accessor.second.size(), metadataInfo, nullptr, 0);
size_t srcFileSize = 0;

View File

@ -56,10 +56,12 @@ TEST_CASE("Metadata PDU", "[cfdp][pdu]") {
REQUIRE(mdBuffer[24] == 'x');
REQUIRE(mdBuffer[25] == 't');
};
SECTION("Serialize with empty dest name") {
MetadataPduCreator serializer(pduConf, info, sourceFileName, destFileName, nullptr, 0);
result = serializer.serialize(&buffer, &sz, mdBuffer.size(), SerializeIF::Endianness::NETWORK);
REQUIRE(result == returnvalue::OK);
CHECK(sz == serializer.getSerializedSize());
// 10 byte heater + 1 byte PDU directive field + 1 byte PDU content + FSS field (4) + source
// name field (10) + dest name field (1).
REQUIRE(serializer.getWholePduSize() == 27);
@ -81,6 +83,7 @@ TEST_CASE("Metadata PDU", "[cfdp][pdu]") {
// 10 byte heater + 1 byte PDU directive field + 1 byte PDU content + FSS field (4) + source
// name field (10) + dest name field (11).
REQUIRE(serializer.getWholePduSize() == 37);
CHECK(sz == serializer.getSerializedSize());
REQUIRE((mdBuffer[1] << 8 | mdBuffer[2]) == 27);
REQUIRE(serializer.getSerializedSize() == serializer.getWholePduSize());
metadataCheckPartOne();
@ -161,7 +164,6 @@ TEST_CASE("Metadata PDU", "[cfdp][pdu]") {
info.setClosureRequested(true);
serializer.updateDirectiveFieldLen();
// info.setSourceFileName(sourceFileName);
result = serializer.serialize(&buffer, &sz, mdBuffer.size(), SerializeIF::Endianness::NETWORK);
REQUIRE(result == returnvalue::OK);