fsfw/unittests/tmtcpacket/testPusTmReader.cpp

109 lines
4.2 KiB
C++
Raw Normal View History

2022-07-21 19:16:44 +02:00
#include <catch2/catch_test_macros.hpp>
2022-07-22 17:11:55 +02:00
#include "fsfw/tmtcpacket/pus/tm/PusTmCreator.h"
2022-07-22 18:22:35 +02:00
#include "fsfw/tmtcpacket/pus/tm/PusTmReader.h"
2024-11-07 12:26:00 +01:00
#include "mock/CdsShortTimestamperMock.h"
2022-07-22 17:11:55 +02:00
TEST_CASE("PUS TM Reader", "[pus-tm-reader]") {
auto packetId = PacketId(ccsds::PacketType::TC, true, 0xef);
auto spParams =
SpacePacketParams(packetId, PacketSeqCtrl(ccsds::SequenceFlags::UNSEGMENTED, 22), 0x00);
2022-07-22 18:22:35 +02:00
auto timeStamperAndReader = CdsShortTimestamperMock();
auto pusTmParams = PusTmParams(17, 2, &timeStamperAndReader);
timeStamperAndReader.valueToStamp = {1, 2, 3, 4, 5, 6, 7};
2022-07-22 17:11:55 +02:00
PusTmCreator creator(spParams, pusTmParams);
2022-07-22 18:22:35 +02:00
PusTmReader reader(&timeStamperAndReader);
std::array<uint8_t, 32> buf{};
uint8_t* dataPtr = buf.data();
size_t serLen = 0;
2022-07-22 17:11:55 +02:00
2022-07-22 18:22:35 +02:00
SECTION("Basic") {
PusTmReader* readerPtr = &reader;
bool deleteReader = false;
dataPtr = buf.data();
serLen = 0;
2022-08-16 01:08:26 +02:00
REQUIRE(creator.serializeBe(&dataPtr, &serLen, buf.size()) == returnvalue::OK);
2022-07-22 18:22:35 +02:00
REQUIRE(not(*readerPtr));
REQUIRE(readerPtr->isNull());
SECTION("Setter") {
2022-08-16 01:08:26 +02:00
REQUIRE(readerPtr->setReadOnlyData(buf.data(), serLen) == returnvalue::OK);
2022-07-22 18:22:35 +02:00
}
SECTION("Full Construction") {
readerPtr = new PusTmReader(&timeStamperAndReader, buf.data(), serLen);
deleteReader = true;
}
SECTION("Time Stamper set manually") {
readerPtr = new PusTmReader(buf.data(), serLen);
readerPtr->setTimeReader(&timeStamperAndReader);
deleteReader = true;
}
2022-07-28 13:37:07 +02:00
REQUIRE(not *readerPtr);
REQUIRE(readerPtr->isNull());
2022-08-16 01:08:26 +02:00
REQUIRE(readerPtr->parseDataWithCrcCheck() == returnvalue::OK);
2022-07-28 13:37:07 +02:00
REQUIRE(not readerPtr->isNull());
2022-07-22 18:22:35 +02:00
REQUIRE(readerPtr->getService() == 17);
REQUIRE(readerPtr->getSubService() == 2);
REQUIRE(readerPtr->getApid() == 0xef);
REQUIRE(readerPtr->getSequenceFlags() == ccsds::SequenceFlags::UNSEGMENTED);
REQUIRE(readerPtr->getScTimeRefStatus() == 0);
REQUIRE(readerPtr->getDestId() == 0);
REQUIRE(readerPtr->getMessageTypeCounter() == 0);
REQUIRE(readerPtr->getTimeReader() == &timeStamperAndReader);
REQUIRE(readerPtr->getPusVersion() == 2);
REQUIRE(readerPtr->getPacketDataLen() == 15);
REQUIRE(readerPtr->getFullPacketLen() == 22);
REQUIRE(readerPtr->getUserDataLen() == 0);
REQUIRE(readerPtr->getUserData() == nullptr);
REQUIRE(readerPtr->getFullData() == buf.data());
if (deleteReader) {
delete readerPtr;
}
}
SECTION("Invalid CRC") {
2022-08-16 01:08:26 +02:00
REQUIRE(creator.serializeBe(&dataPtr, &serLen, buf.size()) == returnvalue::OK);
2022-07-22 18:22:35 +02:00
buf[20] = 0;
2022-08-16 01:08:26 +02:00
REQUIRE(reader.setReadOnlyData(buf.data(), serLen) == returnvalue::OK);
2022-07-22 18:22:35 +02:00
REQUIRE(reader.parseDataWithCrcCheck() == PusIF::INVALID_CRC_16);
}
SECTION("Set Time Reader") {
reader.setTimeReader(nullptr);
REQUIRE(reader.getTimeReader() == nullptr);
}
SECTION("Invalid CRC ignored") {
2022-08-16 01:08:26 +02:00
REQUIRE(creator.serializeBe(&dataPtr, &serLen, buf.size()) == returnvalue::OK);
2022-07-22 18:22:35 +02:00
buf[20] = 0;
2022-08-16 01:08:26 +02:00
REQUIRE(reader.setReadOnlyData(buf.data(), serLen) == returnvalue::OK);
REQUIRE(reader.parseDataWithoutCrcCheck() == returnvalue::OK);
2022-07-22 18:22:35 +02:00
}
SECTION("Read with source data") {
std::array<uint8_t, 3> data{1, 2, 3};
creator.setRawUserData(data.data(), data.size());
2022-08-16 01:08:26 +02:00
REQUIRE(creator.serializeBe(&dataPtr, &serLen, buf.size()) == returnvalue::OK);
REQUIRE(reader.setReadOnlyData(buf.data(), serLen) == returnvalue::OK);
REQUIRE(reader.parseDataWithCrcCheck() == returnvalue::OK);
2022-07-22 18:22:35 +02:00
REQUIRE(reader.getUserDataLen() == 3);
const uint8_t* roData = reader.getUserData();
REQUIRE(roData[0] == 1);
REQUIRE(roData[1] == 2);
REQUIRE(roData[2] == 3);
2022-07-22 17:11:55 +02:00
}
2022-07-22 18:31:00 +02:00
SECTION("Invalid stream lengths") {
2022-08-16 01:08:26 +02:00
REQUIRE(creator.serializeBe(&dataPtr, &serLen, buf.size()) == returnvalue::OK);
2022-07-22 18:31:00 +02:00
for (size_t i = 0; i < serLen - 1; i++) {
REQUIRE(reader.setReadOnlyData(buf.data(), i) == SerializeIF::STREAM_TOO_SHORT);
}
}
SECTION("Reading timestamp fails") {
timeStamperAndReader.nextDeserFails = true;
2022-08-16 01:08:26 +02:00
REQUIRE(creator.serializeBe(&dataPtr, &serLen, buf.size()) == returnvalue::OK);
REQUIRE(reader.setReadOnlyData(buf.data(), serLen) == returnvalue::OK);
REQUIRE(reader.parseDataWithCrcCheck() == returnvalue::FAILED);
2022-07-22 18:31:00 +02:00
}
2022-07-22 17:11:55 +02:00
}