added some user checks

This commit is contained in:
Robin Müller 2023-08-14 13:40:25 +02:00
parent cd8d64830c
commit 5ff464252f
Signed by: muellerr
GPG Key ID: 407F9B00F858F270
4 changed files with 20 additions and 12 deletions

View File

@ -108,8 +108,8 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") {
// Assert that the packet was deleted after handling // Assert that the packet was deleted after handling
REQUIRE(not tcStore.hasDataAtId(storeId)); REQUIRE(not tcStore.hasDataAtId(storeId));
REQUIRE(packetInfoList.empty()); REQUIRE(packetInfoList.empty());
REQUIRE(userMock.eofsRevd.size() == 1); REQUIRE(userMock.eofRecvdRecvd.size() == 1);
auto& eofId = userMock.eofsRevd.back(); auto& eofId = userMock.eofRecvdRecvd.back();
CHECK(eofId == id); CHECK(eofId == id);
REQUIRE(userMock.finishedRecvd.size() == 1); REQUIRE(userMock.finishedRecvd.size() == 1);
auto& idParamPair = userMock.finishedRecvd.back(); auto& idParamPair = userMock.finishedRecvd.back();

View File

@ -109,7 +109,7 @@ TEST_CASE("CFDP Source Handler", "[cfdp]") {
mqMock.clearMessages(); mqMock.clearMessages();
}; };
auto genericEofCheck = [&](SourceHandler::FsmResult& fsmResult, size_t expectedFileSize, auto genericEofCheck = [&](SourceHandler::FsmResult& fsmResult, size_t expectedFileSize,
uint32_t expectedChecksum) { uint32_t expectedChecksum, uint16_t expectedSeqNum) {
CHECK(fsmResult.errors == 0); CHECK(fsmResult.errors == 0);
TmTcMessage tmtcMessage; TmTcMessage tmtcMessage;
const uint8_t* pduPtr; const uint8_t* pduPtr;
@ -120,6 +120,11 @@ TEST_CASE("CFDP Source Handler", "[cfdp]") {
EofInfo eofInfo; EofInfo eofInfo;
EofPduReader eofReader(pduPtr, accessor.second.size(), eofInfo); EofPduReader eofReader(pduPtr, accessor.second.size(), eofInfo);
REQUIRE(eofReader.parseData() == OK); REQUIRE(eofReader.parseData() == OK);
TransactionSeqNum seqNum;
eofReader.getTransactionSeqNum(seqNum);
CHECK(seqNum.getValue() == expectedSeqNum);
CHECK(userMock.eofSentRecvd.size() == 1);
CHECK(userMock.eofSentRecvd.back() == TransactionId(localId, seqNum));
CHECK(eofInfo.getChecksum() == expectedChecksum); CHECK(eofInfo.getChecksum() == expectedChecksum);
CHECK(eofInfo.getConditionCode() == ConditionCode::NO_ERROR); CHECK(eofInfo.getConditionCode() == ConditionCode::NO_ERROR);
CHECK(eofInfo.getFileSize().value() == expectedFileSize); CHECK(eofInfo.getFileSize().value() == expectedFileSize);
@ -139,13 +144,14 @@ TEST_CASE("CFDP Source Handler", "[cfdp]") {
fsmResult = sourceHandler.stateMachine(); fsmResult = sourceHandler.stateMachine();
// Verify EOF PDU was sent. No file data PDU is sent for an empty file and the checksum is 0. // Verify EOF PDU was sent. No file data PDU is sent for an empty file and the checksum is 0.
genericEofCheck(fsmResult, expectedFileSize, 0); genericEofCheck(fsmResult, expectedFileSize, 0, 0);
CHECK(sourceHandler.getStep() == SourceHandler::TransactionStep::IDLE); CHECK(sourceHandler.getStep() == SourceHandler::TransactionStep::IDLE);
CHECK(sourceHandler.getState() == CfdpState::IDLE); CHECK(sourceHandler.getState() == CfdpState::IDLE);
} }
SECTION("Transfer small file") { SECTION("Transfer small file") {
uint16_t expectedSeqNum = 0;
fsMock.createFile(srcFileNameFs); fsMock.createFile(srcFileNameFs);
std::string fileContent = "hello world\n"; std::string fileContent = "hello world\n";
size_t expectedFileSize = fileContent.size(); size_t expectedFileSize = fileContent.size();
@ -155,7 +161,7 @@ TEST_CASE("CFDP Source Handler", "[cfdp]") {
SourceHandler::FsmResult& fsmResult = sourceHandler.stateMachine(); SourceHandler::FsmResult& fsmResult = sourceHandler.stateMachine();
// Verify metadata PDU was sent. // Verify metadata PDU was sent.
genericMetadataCheck(fsmResult, expectedFileSize, 0); genericMetadataCheck(fsmResult, expectedFileSize, expectedSeqNum);
// Verify that a small file data PDU was sent. // Verify that a small file data PDU was sent.
fsmResult = sourceHandler.stateMachine(); fsmResult = sourceHandler.stateMachine();
@ -181,13 +187,14 @@ TEST_CASE("CFDP Source Handler", "[cfdp]") {
etl::crc32 crcCalc; etl::crc32 crcCalc;
crcCalc.add(fileContent.data(), fileContent.data() + fileContent.size()); crcCalc.add(fileContent.data(), fileContent.data() + fileContent.size());
// Verify EOF PDU was sent. // Verify EOF PDU was sent.
genericEofCheck(fsmResult, expectedFileSize, crcCalc.value()); genericEofCheck(fsmResult, expectedFileSize, crcCalc.value(), expectedSeqNum);
CHECK(sourceHandler.getStep() == SourceHandler::TransactionStep::IDLE); CHECK(sourceHandler.getStep() == SourceHandler::TransactionStep::IDLE);
CHECK(sourceHandler.getState() == CfdpState::IDLE); CHECK(sourceHandler.getState() == CfdpState::IDLE);
} }
SECTION("Transfer two segment file") { SECTION("Transfer two segment file") {
uint16_t expectedSeqNum = 0;
// Create 400 bytes of random data. This should result in two file segments, with one // Create 400 bytes of random data. This should result in two file segments, with one
// having the maximum size. // having the maximum size.
std::random_device dev; std::random_device dev;
@ -204,7 +211,7 @@ TEST_CASE("CFDP Source Handler", "[cfdp]") {
CHECK(sourceHandler.transactionStart(putRequest, cfg) == OK); CHECK(sourceHandler.transactionStart(putRequest, cfg) == OK);
SourceHandler::FsmResult& fsmResult = sourceHandler.stateMachine(); SourceHandler::FsmResult& fsmResult = sourceHandler.stateMachine();
// Verify metadata PDU was sent. // Verify metadata PDU was sent.
genericMetadataCheck(fsmResult, expectedFileSize, 0); genericMetadataCheck(fsmResult, expectedFileSize, expectedSeqNum);
// Check first file data PDU. It should have the maximum file segment size. // Check first file data PDU. It should have the maximum file segment size.
fsmResult = sourceHandler.stateMachine(); fsmResult = sourceHandler.stateMachine();
@ -251,7 +258,7 @@ TEST_CASE("CFDP Source Handler", "[cfdp]") {
etl::crc32 crcCalc; etl::crc32 crcCalc;
crcCalc.add(largerFileData.data(), largerFileData.data() + largerFileData.size()); crcCalc.add(largerFileData.data(), largerFileData.data() + largerFileData.size());
// Verify EOF PDU was sent. // Verify EOF PDU was sent.
genericEofCheck(fsmResult, expectedFileSize, crcCalc.value()); genericEofCheck(fsmResult, expectedFileSize, crcCalc.value(), expectedSeqNum);
CHECK(sourceHandler.getStep() == SourceHandler::TransactionStep::IDLE); CHECK(sourceHandler.getStep() == SourceHandler::TransactionStep::IDLE);
CHECK(sourceHandler.getState() == CfdpState::IDLE); CHECK(sourceHandler.getState() == CfdpState::IDLE);

View File

@ -6,11 +6,11 @@ cfdp::UserMock::UserMock(HasFileSystemIF& vfs) : UserBase(vfs) {}
void UserMock::transactionIndication(const TransactionId& id) { transactionIndicRecvd.emplace(id); } void UserMock::transactionIndication(const TransactionId& id) { transactionIndicRecvd.emplace(id); }
void UserMock::eofSentIndication(const TransactionId& id) {} void UserMock::eofSentIndication(const TransactionId& id) { eofSentRecvd.emplace(id); }
void UserMock::abandonedIndication(const TransactionId& id, cfdp::ConditionCode code, void UserMock::abandonedIndication(const TransactionId& id, cfdp::ConditionCode code,
uint64_t progress) {} uint64_t progress) {}
void UserMock::eofRecvIndication(const TransactionId& id) { eofsRevd.push(id); } void UserMock::eofRecvIndication(const TransactionId& id) { eofRecvdRecvd.push(id); }
void UserMock::transactionFinishedIndication(const TransactionFinishedParams& finishedParams) { void UserMock::transactionFinishedIndication(const TransactionFinishedParams& finishedParams) {
finishedRecvd.emplace(finishedParams.id, finishedParams); finishedRecvd.emplace(finishedParams.id, finishedParams);
@ -28,7 +28,7 @@ void UserMock::faultIndication(const TransactionId& id, cfdp::ConditionCode code
} }
void UserMock::reset() { void UserMock::reset() {
std::queue<TransactionId>().swap(eofsRevd); std::queue<TransactionId>().swap(eofRecvdRecvd);
std::queue<std::pair<TransactionId, cfdp::MetadataRecvdParams>>().swap(metadataRecvd); std::queue<std::pair<TransactionId, cfdp::MetadataRecvdParams>>().swap(metadataRecvd);
std::queue<std::pair<TransactionId, cfdp::TransactionFinishedParams>>().swap(finishedRecvd); std::queue<std::pair<TransactionId, cfdp::TransactionFinishedParams>>().swap(finishedRecvd);
} }

View File

@ -25,7 +25,8 @@ class UserMock : public UserBase {
std::queue<TransactionId> transactionIndicRecvd; std::queue<TransactionId> transactionIndicRecvd;
std::queue<std::pair<TransactionId, MetadataRecvdParams>> metadataRecvd; std::queue<std::pair<TransactionId, MetadataRecvdParams>> metadataRecvd;
std::queue<TransactionId> eofsRevd; std::queue<TransactionId> eofRecvdRecvd;
std::queue<TransactionId> eofSentRecvd;
std::queue<std::pair<TransactionId, TransactionFinishedParams>> finishedRecvd; std::queue<std::pair<TransactionId, TransactionFinishedParams>> finishedRecvd;
void reset(); void reset();
}; };