completed basic test set

This commit is contained in:
Robin Müller 2022-07-22 18:22:35 +02:00
parent 2dfbce6174
commit b350018cad
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
9 changed files with 117 additions and 19 deletions

View File

@ -8,7 +8,7 @@
class TimeReaderIF { class TimeReaderIF {
public: public:
virtual ~TimeReaderIF() = default; virtual ~TimeReaderIF() = default;
virtual ReturnValue_t readTimeStamp(const uint8_t* buffer, uint8_t maxSize) = 0; virtual ReturnValue_t readTimeStamp(const uint8_t* buffer, size_t maxSize) = 0;
// Would be nice to have this, but the clock backend needs to be redesigned // Would be nice to have this, but the clock backend needs to be redesigned
// virtual ReturnValue_t readTimestampLen(const uint8_t* buffer, uint8_t maxSize, size_t& // virtual ReturnValue_t readTimestampLen(const uint8_t* buffer, uint8_t maxSize, size_t&
// timestampLen) = 0; // timestampLen) = 0;

View File

@ -82,3 +82,5 @@ const uint8_t* PusTcReader::getUserData() const { return pointers.userDataStart;
size_t PusTcReader::getUserDataLen() const { return appDataSize; } size_t PusTcReader::getUserDataLen() const { return appDataSize; }
bool PusTcReader::isNull() const { return spReader.isNull(); } bool PusTcReader::isNull() const { return spReader.isNull(); }
PusTcReader::operator bool() const { return not isNull(); }

View File

@ -33,16 +33,13 @@ class PusTcReader : public PusTcIF,
* @param setData The position where the packet data lies. * @param setData The position where the packet data lies.
*/ */
PusTcReader(const uint8_t* setData, size_t size); PusTcReader(const uint8_t* setData, size_t size);
~PusTcReader() override;
explicit operator bool() const;
[[nodiscard]] bool isNull() const; [[nodiscard]] bool isNull() const;
ReturnValue_t parseDataWithCrcCheck(); ReturnValue_t parseDataWithCrcCheck();
ReturnValue_t parseDataWithoutCrcCheck(); ReturnValue_t parseDataWithoutCrcCheck();
/**
* This is the empty default destructor.
*/
~PusTcReader() override;
/** /**
* This is a debugging helper method that prints the whole packet content * This is a debugging helper method that prints the whole packet content
* to the screen. * to the screen.

View File

@ -71,8 +71,11 @@ ReturnValue_t PusTmReader::parseData(bool crcCheck) {
return SerializeIF::STREAM_TOO_SHORT; return SerializeIF::STREAM_TOO_SHORT;
} }
currentOffset += timestampLen; currentOffset += timestampLen;
pointers.userDataStart = pointers.spHeaderStart + currentOffset;
sourceDataLen = spReader.getFullPacketLen() - currentOffset - sizeof(ecss::PusChecksumT); sourceDataLen = spReader.getFullPacketLen() - currentOffset - sizeof(ecss::PusChecksumT);
pointers.userDataStart = nullptr;
if (sourceDataLen > 0) {
pointers.userDataStart = pointers.spHeaderStart + currentOffset;
}
currentOffset += sourceDataLen; currentOffset += sourceDataLen;
pointers.crcStart = pointers.spHeaderStart + currentOffset; pointers.crcStart = pointers.spHeaderStart + currentOffset;
if (crcCheck) { if (crcCheck) {
@ -84,3 +87,6 @@ ReturnValue_t PusTmReader::parseData(bool crcCheck) {
} }
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
bool PusTmReader::isNull() const { return spReader.isNull(); }
PusTmReader::operator bool() const { return not isNull(); }

View File

@ -21,6 +21,8 @@ class PusTmReader : public PusTmIF,
ReturnValue_t parseDataWithCrcCheck(); ReturnValue_t parseDataWithCrcCheck();
const uint8_t* getFullData() override; const uint8_t* getFullData() override;
explicit operator bool() const;
[[nodiscard]] bool isNull() const;
void setTimeReader(TimeReaderIF* timeReader); void setTimeReader(TimeReaderIF* timeReader);
TimeReaderIF* getTimeReader(); TimeReaderIF* getTimeReader();
ReturnValue_t setReadOnlyData(const uint8_t* data, size_t size); ReturnValue_t setReadOnlyData(const uint8_t* data, size_t size);
@ -30,8 +32,8 @@ class PusTmReader : public PusTmIF,
[[nodiscard]] uint8_t getPusVersion() const override; [[nodiscard]] uint8_t getPusVersion() const override;
[[nodiscard]] uint8_t getService() const override; [[nodiscard]] uint8_t getService() const override;
[[nodiscard]] uint8_t getSubService() const override; [[nodiscard]] uint8_t getSubService() const override;
const uint8_t* getUserData() const override; [[nodiscard]] const uint8_t* getUserData() const override;
size_t getUserDataLen() const override; [[nodiscard]] size_t getUserDataLen() const override;
uint8_t getScTimeRefStatus() override; uint8_t getScTimeRefStatus() override;
uint16_t getMessageTypeCounter() override; uint16_t getMessageTypeCounter() override;
uint16_t getDestId() override; uint16_t getDestId() override;

View File

@ -5,9 +5,11 @@
#include "fsfw/timemanager/TimeStamperIF.h" #include "fsfw/timemanager/TimeStamperIF.h"
class CdsShortTimestamperMock : public TimeStamperIF { class CdsShortTimestamperMock : public TimeStamperIF, public TimeReaderIF {
public: public:
unsigned int serializeCallCount = 0; unsigned int serializeCallCount = 0;
unsigned int deserializeCallCount = 0;
ReturnValue_t lastDeserializeResult = HasReturnvaluesIF::RETURN_OK;
ReturnValue_t lastSerializeResult = HasReturnvaluesIF::RETURN_OK; ReturnValue_t lastSerializeResult = HasReturnvaluesIF::RETURN_OK;
unsigned int getSizeCallCount = 0; unsigned int getSizeCallCount = 0;
std::array<uint8_t, 7> valueToStamp{}; std::array<uint8_t, 7> valueToStamp{};
@ -38,8 +40,15 @@ class CdsShortTimestamperMock : public TimeStamperIF {
} }
ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size, ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size,
Endianness streamEndianness) override { Endianness streamEndianness) override {
return HasReturnvaluesIF::RETURN_FAILED; deserializeCallCount += 1;
if (*size < 7) {
lastDeserializeResult = SerializeIF::STREAM_TOO_SHORT;
return lastDeserializeResult;
}
std::copy(*buffer, *buffer + getSerializedSize(), valueToStamp.begin());
return lastDeserializeResult;
} }
[[nodiscard]] size_t getTimestampSize() const override { return getSerializedSize(); } [[nodiscard]] size_t getTimestampSize() const override { return getSerializedSize(); }
ReturnValue_t addTimeStamp(uint8_t *buffer, uint8_t maxSize) override { return 0; } ReturnValue_t addTimeStamp(uint8_t *buffer, uint8_t maxSize) override { return 0; }
@ -47,7 +56,13 @@ class CdsShortTimestamperMock : public TimeStamperIF {
serializeCallCount = 0; serializeCallCount = 0;
getSizeCallCount = 0; getSizeCallCount = 0;
} }
ReturnValue_t readTimeStamp(const uint8_t *buffer, size_t maxSize) override {
return deSerialize(&buffer, &maxSize, SerializeIF::Endianness::NETWORK);
}
size_t getTimestampLen() override { return getSerializedSize(); }
timeval &getTime() override { return dummyTime; }
private: private:
timeval dummyTime{};
}; };
#endif // FSFW_TESTS_CDSSHORTTIMESTAMPERMOCK_H #endif // FSFW_TESTS_CDSSHORTTIMESTAMPERMOCK_H

View File

@ -14,13 +14,11 @@ TEST_CASE("PUS TC Reader", "[pus-tc-reader]") {
uint8_t* dataPtr = buf.data(); uint8_t* dataPtr = buf.data();
size_t serLen = 0; size_t serLen = 0;
PusTcReader reader; PusTcReader reader;
auto checkReaderFields = [&](PusTcReader& reader) {
};
SECTION("State") { SECTION("State") {
REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(reader.isNull()); REQUIRE(reader.isNull());
REQUIRE(not reader);
PusTcReader* readerPtr = nullptr; PusTcReader* readerPtr = nullptr;
bool callDelete = false; bool callDelete = false;
SECTION("Setter") { SECTION("Setter") {
@ -35,6 +33,7 @@ TEST_CASE("PUS TC Reader", "[pus-tc-reader]") {
REQUIRE(readerPtr->parseDataWithCrcCheck() == HasReturnvaluesIF::RETURN_OK); REQUIRE(readerPtr->parseDataWithCrcCheck() == HasReturnvaluesIF::RETURN_OK);
} }
REQUIRE(not readerPtr->isNull()); REQUIRE(not readerPtr->isNull());
REQUIRE(*readerPtr);
REQUIRE(readerPtr->getPacketType() == ccsds::PacketType::TC); REQUIRE(readerPtr->getPacketType() == ccsds::PacketType::TC);
REQUIRE(readerPtr->getApid() == 0x02); REQUIRE(readerPtr->getApid() == 0x02);
REQUIRE(readerPtr->getService() == 17); REQUIRE(readerPtr->getService() == 17);

View File

@ -70,6 +70,7 @@ TEST_CASE("PUS TM Creator", "[pus-tm-creator]") {
REQUIRE(CRC::crc16ccitt(buf.data(), serLen) == 0); REQUIRE(CRC::crc16ccitt(buf.data(), serLen) == 0);
REQUIRE(buf[20] == 0x03); REQUIRE(buf[20] == 0x03);
REQUIRE(buf[21] == 0x79); REQUIRE(buf[21] == 0x79);
REQUIRE(timeStamper.serializeCallCount == 1);
} }
SECTION("Custom Fields") { SECTION("Custom Fields") {

View File

@ -1,18 +1,94 @@
#include <catch2/catch_test_macros.hpp> #include <catch2/catch_test_macros.hpp>
#include "fsfw/tmtcpacket/pus/tm/PusTmCreator.h" #include "fsfw/tmtcpacket/pus/tm/PusTmCreator.h"
#include "fsfw/tmtcpacket/pus/tm/PusTmReader.h"
#include "mocks/CdsShortTimestamperMock.h" #include "mocks/CdsShortTimestamperMock.h"
TEST_CASE("PUS TM Reader", "[pus-tm-reader]") { TEST_CASE("PUS TM Reader", "[pus-tm-reader]") {
auto packetId = PacketId(ccsds::PacketType::TC, true, 0xef); auto packetId = PacketId(ccsds::PacketType::TC, true, 0xef);
auto spParams = auto spParams =
SpacePacketParams(packetId, PacketSeqCtrl(ccsds::SequenceFlags::UNSEGMENTED, 22), 0x00); SpacePacketParams(packetId, PacketSeqCtrl(ccsds::SequenceFlags::UNSEGMENTED, 22), 0x00);
auto timeStamper = CdsShortTimestamperMock(); auto timeStamperAndReader = CdsShortTimestamperMock();
auto pusTmParams = PusTmParams(17, 2, &timeStamper); auto pusTmParams = PusTmParams(17, 2, &timeStamperAndReader);
timeStamper.valueToStamp = {1, 2, 3, 4, 5, 6, 7}; timeStamperAndReader.valueToStamp = {1, 2, 3, 4, 5, 6, 7};
PusTmCreator creator(spParams, pusTmParams); PusTmCreator creator(spParams, pusTmParams);
PusTmReader reader(&timeStamperAndReader);
std::array<uint8_t, 32> buf{};
uint8_t* dataPtr = buf.data();
size_t serLen = 0;
SECTION("State") { SECTION("Basic") {
PusTmReader* readerPtr = &reader;
bool deleteReader = false;
dataPtr = buf.data();
serLen = 0;
REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(not(*readerPtr));
REQUIRE(readerPtr->isNull());
SECTION("Setter") {
REQUIRE(readerPtr->setReadOnlyData(buf.data(), serLen) == HasReturnvaluesIF::RETURN_OK);
}
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;
}
REQUIRE(readerPtr);
REQUIRE(not readerPtr->isNull());
REQUIRE(readerPtr->parseDataWithCrcCheck() == HasReturnvaluesIF::RETURN_OK);
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") {
REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
buf[20] = 0;
REQUIRE(reader.setReadOnlyData(buf.data(), serLen) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(reader.parseDataWithCrcCheck() == PusIF::INVALID_CRC_16);
}
SECTION("Set Time Reader") {
reader.setTimeReader(nullptr);
REQUIRE(reader.getTimeReader() == nullptr);
}
SECTION("Invalid CRC ignored") {
REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
buf[20] = 0;
REQUIRE(reader.setReadOnlyData(buf.data(), serLen) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(reader.parseDataWithoutCrcCheck() == HasReturnvaluesIF::RETURN_OK);
}
SECTION("Read with source data") {
std::array<uint8_t, 3> data{1, 2, 3};
creator.setRawUserData(data.data(), data.size());
REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(reader.setReadOnlyData(buf.data(), serLen) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(reader.parseDataWithCrcCheck() == HasReturnvaluesIF::RETURN_OK);
REQUIRE(reader.getUserDataLen() == 3);
const uint8_t* roData = reader.getUserData();
REQUIRE(roData[0] == 1);
REQUIRE(roData[1] == 2);
REQUIRE(roData[2] == 3);
} }
} }