Update and clean up HK and Local Pool Modules
This commit is contained in:
8
unittests/mock/AcceptsTcMock.cpp
Normal file
8
unittests/mock/AcceptsTcMock.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
#include "AcceptsTcMock.h"
|
||||
|
||||
AcceptsTcMock::AcceptsTcMock(const char* name, uint32_t id, MessageQueueId_t queueId)
|
||||
: name(name), id(id), queueId(queueId) {}
|
||||
|
||||
const char* AcceptsTcMock::getName() const { return name; }
|
||||
uint32_t AcceptsTcMock::getIdentifier() const { return id; }
|
||||
MessageQueueId_t AcceptsTcMock::getRequestQueue() const { return queueId; }
|
20
unittests/mock/AcceptsTcMock.h
Normal file
20
unittests/mock/AcceptsTcMock.h
Normal file
@ -0,0 +1,20 @@
|
||||
#ifndef FSFW_TESTS_ACCEPTSTCMOCK_H
|
||||
#define FSFW_TESTS_ACCEPTSTCMOCK_H
|
||||
|
||||
#include "fsfw/tmtcservices/AcceptsTelecommandsIF.h"
|
||||
|
||||
class AcceptsTcMock : public AcceptsTelecommandsIF {
|
||||
public:
|
||||
AcceptsTcMock(const char* name, uint32_t id, MessageQueueId_t queueId);
|
||||
[[nodiscard]] const char* getName() const override;
|
||||
[[nodiscard]] uint32_t getIdentifier() const override;
|
||||
[[nodiscard]] MessageQueueId_t getRequestQueue() const override;
|
||||
|
||||
const char* name;
|
||||
uint32_t id;
|
||||
MessageQueueId_t queueId;
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#endif // FSFW_TESTS_ACCEPTSTCMOCK_H
|
13
unittests/mock/AcceptsTmMock.cpp
Normal file
13
unittests/mock/AcceptsTmMock.cpp
Normal file
@ -0,0 +1,13 @@
|
||||
#include "AcceptsTmMock.h"
|
||||
|
||||
AcceptsTmMock::AcceptsTmMock(object_id_t registeredId, MessageQueueId_t queueToReturn)
|
||||
: SystemObject(registeredId), returnedQueue(queueToReturn) {}
|
||||
|
||||
AcceptsTmMock::AcceptsTmMock(MessageQueueId_t queueToReturn)
|
||||
: SystemObject(objects::NO_OBJECT, false), returnedQueue(queueToReturn) {}
|
||||
|
||||
MessageQueueId_t AcceptsTmMock::getReportReceptionQueue(uint8_t virtualChannel) const {
|
||||
return returnedQueue;
|
||||
}
|
||||
|
||||
const char* AcceptsTmMock::getName() const { return "TM Acceptor Mock"; }
|
17
unittests/mock/AcceptsTmMock.h
Normal file
17
unittests/mock/AcceptsTmMock.h
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef FSFW_TESTS_ACCEPTSTMMOCK_H
|
||||
#define FSFW_TESTS_ACCEPTSTMMOCK_H
|
||||
|
||||
#include "fsfw/objectmanager/SystemObject.h"
|
||||
#include "fsfw/tmtcservices/AcceptsTelemetryIF.h"
|
||||
|
||||
class AcceptsTmMock : public SystemObject, public AcceptsTelemetryIF {
|
||||
public:
|
||||
AcceptsTmMock(object_id_t registeredId, MessageQueueId_t queueToReturn);
|
||||
explicit AcceptsTmMock(MessageQueueId_t queueToReturn);
|
||||
|
||||
[[nodiscard]] MessageQueueId_t getReportReceptionQueue(uint8_t virtualChannel) const override;
|
||||
[[nodiscard]] const char* getName() const override;
|
||||
|
||||
MessageQueueId_t returnedQueue;
|
||||
};
|
||||
#endif // FSFW_TESTS_ACCEPTSTMMOCK_H
|
21
unittests/mock/CMakeLists.txt
Normal file
21
unittests/mock/CMakeLists.txt
Normal file
@ -0,0 +1,21 @@
|
||||
target_sources(
|
||||
${FSFW_TEST_TGT}
|
||||
PRIVATE PowerSwitcherMock.cpp
|
||||
DeviceHandlerMock.cpp
|
||||
DeviceFdirMock.cpp
|
||||
CookieIFMock.cpp
|
||||
ComIFMock.cpp
|
||||
MessageQueueMock.cpp
|
||||
InternalErrorReporterMock.cpp
|
||||
PusVerificationReporterMock.cpp
|
||||
PusServiceBaseMock.cpp
|
||||
AcceptsTmMock.cpp
|
||||
PusDistributorMock.cpp
|
||||
CcsdsCheckerMock.cpp
|
||||
AcceptsTcMock.cpp
|
||||
StorageManagerMock.cpp
|
||||
FilesystemMock.cpp
|
||||
TestPoolOwner.cpp
|
||||
EventReportingProxyMock.cpp)
|
||||
|
||||
add_subdirectory(cfdp)
|
10
unittests/mock/CcsdsCheckerMock.cpp
Normal file
10
unittests/mock/CcsdsCheckerMock.cpp
Normal file
@ -0,0 +1,10 @@
|
||||
#include "CcsdsCheckerMock.h"
|
||||
|
||||
CcsdsCheckerMock::CcsdsCheckerMock() = default;
|
||||
|
||||
ReturnValue_t CcsdsCheckerMock::checkPacket(const SpacePacketReader& currentPacket,
|
||||
size_t packetLen) {
|
||||
checkCallCount++;
|
||||
checkedPacketLen = packetLen;
|
||||
return nextResult;
|
||||
}
|
16
unittests/mock/CcsdsCheckerMock.h
Normal file
16
unittests/mock/CcsdsCheckerMock.h
Normal file
@ -0,0 +1,16 @@
|
||||
#ifndef FSFW_TESTS_CCSDSCHECKERMOCK_H
|
||||
#define FSFW_TESTS_CCSDSCHECKERMOCK_H
|
||||
|
||||
#include "fsfw/tcdistribution/CcsdsPacketCheckIF.h"
|
||||
class CcsdsCheckerMock : public CcsdsPacketCheckIF {
|
||||
public:
|
||||
CcsdsCheckerMock();
|
||||
unsigned int checkCallCount = 0;
|
||||
size_t checkedPacketLen = 0;
|
||||
ReturnValue_t nextResult = returnvalue::OK;
|
||||
ReturnValue_t checkPacket(const SpacePacketReader& currentPacket, size_t packetLen) override;
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#endif // FSFW_TESTS_CCSDSCHECKERMOCK_H
|
82
unittests/mock/CdsShortTimestamperMock.h
Normal file
82
unittests/mock/CdsShortTimestamperMock.h
Normal file
@ -0,0 +1,82 @@
|
||||
#ifndef FSFW_TESTS_CDSSHORTTIMESTAMPERMOCK_H
|
||||
#define FSFW_TESTS_CDSSHORTTIMESTAMPERMOCK_H
|
||||
|
||||
#include <array>
|
||||
|
||||
#include "fsfw/timemanager/TimeReaderIF.h"
|
||||
#include "fsfw/timemanager/TimeWriterIF.h"
|
||||
|
||||
class CdsShortTimestamperMock : public TimeWriterIF, public TimeReaderIF {
|
||||
public:
|
||||
unsigned int serializeCallCount = 0;
|
||||
unsigned int deserializeCallCount = 0;
|
||||
ReturnValue_t lastDeserializeResult = returnvalue::OK;
|
||||
ReturnValue_t lastSerializeResult = returnvalue::OK;
|
||||
unsigned int getSizeCallCount = 0;
|
||||
bool nextSerFails = false;
|
||||
ReturnValue_t serFailRetval = returnvalue::FAILED;
|
||||
bool nextDeserFails = false;
|
||||
ReturnValue_t deserFailRetval = returnvalue::FAILED;
|
||||
std::array<uint8_t, 7> valueToStamp{};
|
||||
|
||||
CdsShortTimestamperMock() = default;
|
||||
|
||||
explicit CdsShortTimestamperMock(std::array<uint8_t, 7> valueToStamp)
|
||||
: valueToStamp(valueToStamp) {}
|
||||
|
||||
ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize,
|
||||
Endianness streamEndianness) const override {
|
||||
auto &thisNonConst = const_cast<CdsShortTimestamperMock &>(*this);
|
||||
thisNonConst.serializeCallCount += 1;
|
||||
if (nextSerFails) {
|
||||
return serFailRetval;
|
||||
}
|
||||
if (*size + getSerializedSize() > maxSize) {
|
||||
thisNonConst.lastSerializeResult = SerializeIF::BUFFER_TOO_SHORT;
|
||||
return lastSerializeResult;
|
||||
}
|
||||
std::copy(valueToStamp.begin(), valueToStamp.end(), *buffer);
|
||||
thisNonConst.lastSerializeResult = returnvalue::OK;
|
||||
*buffer += getSerializedSize();
|
||||
*size += getSerializedSize();
|
||||
return lastSerializeResult;
|
||||
}
|
||||
[[nodiscard]] size_t getSerializedSize() const override {
|
||||
auto &thisNonConst = const_cast<CdsShortTimestamperMock &>(*this);
|
||||
thisNonConst.getSizeCallCount += 1;
|
||||
return valueToStamp.size();
|
||||
}
|
||||
ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size,
|
||||
Endianness streamEndianness) override {
|
||||
deserializeCallCount += 1;
|
||||
if (nextDeserFails) {
|
||||
return deserFailRetval;
|
||||
}
|
||||
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(); }
|
||||
|
||||
void reset() {
|
||||
serializeCallCount = 0;
|
||||
getSizeCallCount = 0;
|
||||
deserializeCallCount = 0;
|
||||
nextSerFails = false;
|
||||
nextDeserFails = false;
|
||||
lastSerializeResult = returnvalue::OK;
|
||||
lastDeserializeResult = returnvalue::OK;
|
||||
deserFailRetval = returnvalue::FAILED;
|
||||
serFailRetval = returnvalue::FAILED;
|
||||
}
|
||||
|
||||
timeval &getTime() override { return dummyTime; }
|
||||
|
||||
private:
|
||||
timeval dummyTime{};
|
||||
};
|
||||
#endif // FSFW_TESTS_CDSSHORTTIMESTAMPERMOCK_H
|
46
unittests/mock/ComIFMock.cpp
Normal file
46
unittests/mock/ComIFMock.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
#include "ComIFMock.h"
|
||||
|
||||
#include "DeviceHandlerMock.h"
|
||||
|
||||
ComIFMock::ComIFMock(object_id_t objectId) : SystemObject(objectId) {}
|
||||
|
||||
ComIFMock::~ComIFMock() {}
|
||||
|
||||
ReturnValue_t ComIFMock::initializeInterface(CookieIF *cookie) { return returnvalue::OK; }
|
||||
|
||||
ReturnValue_t ComIFMock::sendMessage(CookieIF *cookie, const uint8_t *sendData, size_t sendLen) {
|
||||
data = *sendData;
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t ComIFMock::getSendSuccess(CookieIF *cookie) { return returnvalue::OK; }
|
||||
|
||||
ReturnValue_t ComIFMock::requestReceiveMessage(CookieIF *cookie, size_t requestLen) {
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t ComIFMock::readReceivedMessage(CookieIF *cookie, uint8_t **buffer, size_t *size) {
|
||||
switch (testCase) {
|
||||
case TestCase::MISSED_REPLY: {
|
||||
*size = 0;
|
||||
return returnvalue::OK;
|
||||
}
|
||||
case TestCase::SIMPLE_COMMAND_NOMINAL: {
|
||||
*size = 1;
|
||||
data = DeviceHandlerMock::SIMPLE_COMMAND_DATA;
|
||||
*buffer = &data;
|
||||
break;
|
||||
}
|
||||
case TestCase::PERIODIC_REPLY_NOMINAL: {
|
||||
*size = 1;
|
||||
data = DeviceHandlerMock::PERIODIC_REPLY_DATA;
|
||||
*buffer = &data;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
void ComIFMock::setTestCase(TestCase testCase_) { testCase = testCase_; }
|
37
unittests/mock/ComIFMock.h
Normal file
37
unittests/mock/ComIFMock.h
Normal file
@ -0,0 +1,37 @@
|
||||
#ifndef TESTS_SRC_FSFW_TESTS_UNIT_DEVICEHANDLER_COMIFMOCK_H_
|
||||
#define TESTS_SRC_FSFW_TESTS_UNIT_DEVICEHANDLER_COMIFMOCK_H_
|
||||
|
||||
#include <fsfw/devicehandlers/DeviceCommunicationIF.h>
|
||||
#include <fsfw/objectmanager/SystemObject.h>
|
||||
|
||||
/**
|
||||
* @brief The ComIFMock supports the simulation of various device communication error cases
|
||||
* like incomplete or wrong replies and can be used to test the
|
||||
* DeviceHandlerBase.
|
||||
*/
|
||||
class ComIFMock : public DeviceCommunicationIF, public SystemObject {
|
||||
public:
|
||||
enum class TestCase { SIMPLE_COMMAND_NOMINAL, PERIODIC_REPLY_NOMINAL, MISSED_REPLY };
|
||||
|
||||
ComIFMock(object_id_t objectId);
|
||||
virtual ~ComIFMock();
|
||||
|
||||
virtual ReturnValue_t initializeInterface(CookieIF *cookie) override;
|
||||
virtual ReturnValue_t sendMessage(CookieIF *cookie, const uint8_t *sendData,
|
||||
size_t sendLen) override;
|
||||
virtual ReturnValue_t getSendSuccess(CookieIF *cookie) override;
|
||||
virtual ReturnValue_t requestReceiveMessage(CookieIF *cookie, size_t requestLen) override;
|
||||
virtual ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **buffer,
|
||||
size_t *size) override;
|
||||
void setTestCase(TestCase testCase_);
|
||||
|
||||
private:
|
||||
TestCase testCase = TestCase::SIMPLE_COMMAND_NOMINAL;
|
||||
|
||||
static const uint8_t SIMPLE_COMMAND_DATA = 1;
|
||||
static const uint8_t PERIODIC_REPLY_DATA = 2;
|
||||
|
||||
uint8_t data = 0;
|
||||
};
|
||||
|
||||
#endif /* TESTS_SRC_FSFW_TESTS_UNIT_DEVICEHANDLER_COMIFMOCK_H_ */
|
5
unittests/mock/CookieIFMock.cpp
Normal file
5
unittests/mock/CookieIFMock.cpp
Normal file
@ -0,0 +1,5 @@
|
||||
#include "CookieIFMock.h"
|
||||
|
||||
CookieIFMock::CookieIFMock() {}
|
||||
|
||||
CookieIFMock::~CookieIFMock() {}
|
12
unittests/mock/CookieIFMock.h
Normal file
12
unittests/mock/CookieIFMock.h
Normal file
@ -0,0 +1,12 @@
|
||||
#ifndef TESTS_SRC_FSFW_TESTS_UNIT_DEVICEHANDLER_COOKIEIFMOCK_H_
|
||||
#define TESTS_SRC_FSFW_TESTS_UNIT_DEVICEHANDLER_COOKIEIFMOCK_H_
|
||||
|
||||
#include "fsfw/devicehandlers/CookieIF.h"
|
||||
|
||||
class CookieIFMock : public CookieIF {
|
||||
public:
|
||||
CookieIFMock();
|
||||
virtual ~CookieIFMock();
|
||||
};
|
||||
|
||||
#endif /* TESTS_SRC_FSFW_TESTS_UNIT_DEVICEHANDLER_COOKIEIFMOCK_H_ */
|
16
unittests/mock/DeviceFdirMock.cpp
Normal file
16
unittests/mock/DeviceFdirMock.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
#include "DeviceFdirMock.h"
|
||||
|
||||
DeviceFdirMock::DeviceFdirMock(object_id_t owner, object_id_t parent)
|
||||
: DeviceHandlerFailureIsolation(owner, parent) {}
|
||||
|
||||
DeviceFdirMock::~DeviceFdirMock() = default;
|
||||
|
||||
uint32_t DeviceFdirMock::getMissedReplyCount() {
|
||||
ParameterWrapper parameterWrapper;
|
||||
this->getParameter(MISSED_REPLY_DOMAIN_ID,
|
||||
static_cast<uint8_t>(FaultCounter::ParameterIds::FAULT_COUNT),
|
||||
¶meterWrapper, nullptr, 0);
|
||||
uint32_t missedReplyCount = 0;
|
||||
parameterWrapper.getElement(&missedReplyCount);
|
||||
return missedReplyCount;
|
||||
}
|
18
unittests/mock/DeviceFdirMock.h
Normal file
18
unittests/mock/DeviceFdirMock.h
Normal file
@ -0,0 +1,18 @@
|
||||
#ifndef TESTS_SRC_FSFW_TESTS_UNIT_DEVICEHANDLER_DEVICEFDIRMOCK_H_
|
||||
#define TESTS_SRC_FSFW_TESTS_UNIT_DEVICEHANDLER_DEVICEFDIRMOCK_H_
|
||||
|
||||
#include "fsfw/devicehandlers/DeviceHandlerFailureIsolation.h"
|
||||
|
||||
class DeviceFdirMock : public DeviceHandlerFailureIsolation {
|
||||
public:
|
||||
DeviceFdirMock(object_id_t owner, object_id_t parent);
|
||||
virtual ~DeviceFdirMock();
|
||||
|
||||
uint32_t getMissedReplyCount();
|
||||
|
||||
private:
|
||||
static const uint8_t STRANGE_REPLY_DOMAIN_ID = 0xF0;
|
||||
static const uint8_t MISSED_REPLY_DOMAIN_ID = 0xF1;
|
||||
};
|
||||
|
||||
#endif /* TESTS_SRC_FSFW_TESTS_UNIT_DEVICEHANDLER_DEVICEFDIRMOCK_H_ */
|
121
unittests/mock/DeviceHandlerMock.cpp
Normal file
121
unittests/mock/DeviceHandlerMock.cpp
Normal file
@ -0,0 +1,121 @@
|
||||
#include "DeviceHandlerMock.h"
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
DeviceHandlerMock::DeviceHandlerMock(object_id_t objectId, object_id_t deviceCommunication,
|
||||
CookieIF *comCookie, FailureIsolationBase *fdirInstance)
|
||||
: DeviceHandlerBase(objectId, deviceCommunication, comCookie, fdirInstance) {}
|
||||
|
||||
DeviceHandlerMock::~DeviceHandlerMock() = default;
|
||||
|
||||
void DeviceHandlerMock::doStartUp() { setMode(_MODE_TO_ON); }
|
||||
|
||||
void DeviceHandlerMock::doShutDown() { setMode(_MODE_POWER_DOWN); }
|
||||
|
||||
ReturnValue_t DeviceHandlerMock::buildNormalDeviceCommand(DeviceCommandId_t *id) {
|
||||
return NOTHING_TO_SEND;
|
||||
}
|
||||
|
||||
ReturnValue_t DeviceHandlerMock::buildTransitionDeviceCommand(DeviceCommandId_t *id) {
|
||||
return NOTHING_TO_SEND;
|
||||
}
|
||||
|
||||
ReturnValue_t DeviceHandlerMock::buildCommandFromCommand(DeviceCommandId_t deviceCommand,
|
||||
const uint8_t *commandData,
|
||||
size_t commandDataLen) {
|
||||
switch (deviceCommand) {
|
||||
case SIMPLE_COMMAND: {
|
||||
commandBuffer[0] = SIMPLE_COMMAND_DATA;
|
||||
rawPacket = commandBuffer;
|
||||
rawPacketLen = sizeof(SIMPLE_COMMAND_DATA);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
WARN("DeviceHandlerMock::buildCommandFromCommand: Invalid device command");
|
||||
break;
|
||||
}
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t DeviceHandlerMock::scanForReply(const uint8_t *start, size_t len,
|
||||
DeviceCommandId_t *foundId, size_t *foundLen) {
|
||||
switch (*start) {
|
||||
case SIMPLE_COMMAND_DATA: {
|
||||
*foundId = SIMPLE_COMMAND;
|
||||
*foundLen = sizeof(SIMPLE_COMMAND_DATA);
|
||||
return returnvalue::OK;
|
||||
break;
|
||||
}
|
||||
case PERIODIC_REPLY_DATA: {
|
||||
*foundId = PERIODIC_REPLY;
|
||||
*foundLen = sizeof(PERIODIC_REPLY_DATA);
|
||||
return returnvalue::OK;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
|
||||
ReturnValue_t DeviceHandlerMock::interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) {
|
||||
switch (id) {
|
||||
case SIMPLE_COMMAND:
|
||||
case PERIODIC_REPLY: {
|
||||
periodicReplyReceived = true;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
void DeviceHandlerMock::fillCommandAndReplyMap() {
|
||||
insertInCommandAndReplyMap(SIMPLE_COMMAND, 0, nullptr, 0, false, false, 0,
|
||||
&simpleCommandReplyTimeout);
|
||||
insertInCommandAndReplyMap(PERIODIC_REPLY, 0, nullptr, 0, true, false, 0,
|
||||
&periodicReplyCountdown);
|
||||
}
|
||||
|
||||
uint32_t DeviceHandlerMock::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) { return 500; }
|
||||
|
||||
void DeviceHandlerMock::changePeriodicReplyCountdown(uint32_t timeout) {
|
||||
periodicReplyCountdown.setTimeout(timeout);
|
||||
}
|
||||
|
||||
void DeviceHandlerMock::changeSimpleCommandReplyCountdown(uint32_t timeout) {
|
||||
simpleCommandReplyTimeout.setTimeout(timeout);
|
||||
}
|
||||
|
||||
void DeviceHandlerMock::resetPeriodicReplyState() { periodicReplyReceived = false; }
|
||||
|
||||
bool DeviceHandlerMock::getPeriodicReplyReceived() const { return periodicReplyReceived; }
|
||||
|
||||
ReturnValue_t DeviceHandlerMock::enablePeriodicReply(DeviceCommandId_t replyId) {
|
||||
return updatePeriodicReply(true, replyId);
|
||||
}
|
||||
|
||||
ReturnValue_t DeviceHandlerMock::disablePeriodicReply(DeviceCommandId_t replyId) {
|
||||
return updatePeriodicReply(false, replyId);
|
||||
}
|
||||
|
||||
ReturnValue_t DeviceHandlerMock::initialize() {
|
||||
ReturnValue_t result = DeviceHandlerBase::initialize();
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
setMode(MODE_ON);
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t DeviceHandlerMock::serializeHkDataset(dp::structure_id_t structureId, uint8_t *buf,
|
||||
size_t maxSize) {
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t DeviceHandlerMock::specifyHkDatasets(std::vector<hk::SetSpecification> &setList) {
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
dp::SharedPool *DeviceHandlerMock::getOptionalSharedPool() { return nullptr; }
|
55
unittests/mock/DeviceHandlerMock.h
Normal file
55
unittests/mock/DeviceHandlerMock.h
Normal file
@ -0,0 +1,55 @@
|
||||
#ifndef TESTS_SRC_FSFW_TESTS_UNIT_DEVICEHANDLER_DEVICEHANDLERMOCK_H_
|
||||
#define TESTS_SRC_FSFW_TESTS_UNIT_DEVICEHANDLER_DEVICEHANDLERMOCK_H_
|
||||
|
||||
#include <fsfw/devicehandlers/DeviceHandlerBase.h>
|
||||
|
||||
class DeviceHandlerMock : public DeviceHandlerBase {
|
||||
public:
|
||||
static constexpr DeviceCommandId_t SIMPLE_COMMAND = 1;
|
||||
static constexpr DeviceCommandId_t PERIODIC_REPLY = 2;
|
||||
|
||||
static constexpr uint8_t SIMPLE_COMMAND_DATA = 1;
|
||||
static constexpr uint8_t PERIODIC_REPLY_DATA = 2;
|
||||
|
||||
DeviceHandlerMock(object_id_t objectId, object_id_t deviceCommunication, CookieIF *comCookie,
|
||||
FailureIsolationBase *fdirInstance);
|
||||
~DeviceHandlerMock() override;
|
||||
void changePeriodicReplyCountdown(uint32_t timeout);
|
||||
void changeSimpleCommandReplyCountdown(uint32_t timeout);
|
||||
void resetPeriodicReplyState();
|
||||
bool getPeriodicReplyReceived() const;
|
||||
ReturnValue_t enablePeriodicReply(DeviceCommandId_t replyId);
|
||||
ReturnValue_t disablePeriodicReply(DeviceCommandId_t replyId);
|
||||
|
||||
ReturnValue_t initialize() override;
|
||||
|
||||
ReturnValue_t serializeHkDataset(dp::structure_id_t structureId, uint8_t *buf,
|
||||
size_t maxSize) override;
|
||||
|
||||
ReturnValue_t specifyHkDatasets(std::vector<hk::SetSpecification> &setList) override;
|
||||
|
||||
dp::SharedPool *getOptionalSharedPool() override;
|
||||
|
||||
protected:
|
||||
void doStartUp() override;
|
||||
void doShutDown() override;
|
||||
ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t *id) override;
|
||||
ReturnValue_t buildTransitionDeviceCommand(DeviceCommandId_t *id) override;
|
||||
ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand, const uint8_t *commandData,
|
||||
size_t commandDataLen) override;
|
||||
ReturnValue_t scanForReply(const uint8_t *start, size_t len, DeviceCommandId_t *foundId,
|
||||
size_t *foundLen) override;
|
||||
ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) override;
|
||||
void fillCommandAndReplyMap() override;
|
||||
uint32_t getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) override;
|
||||
|
||||
private:
|
||||
Countdown simpleCommandReplyTimeout = Countdown(1000);
|
||||
Countdown periodicReplyCountdown = Countdown(1000);
|
||||
|
||||
uint8_t commandBuffer[1]{};
|
||||
|
||||
bool periodicReplyReceived = false;
|
||||
};
|
||||
|
||||
#endif /* TESTS_SRC_FSFW_TESTS_UNIT_DEVICEHANDLER_DEVICEHANDLERMOCK_H_ */
|
6
unittests/mock/EventReportingProxyMock.cpp
Normal file
6
unittests/mock/EventReportingProxyMock.cpp
Normal file
@ -0,0 +1,6 @@
|
||||
#include "EventReportingProxyMock.h"
|
||||
|
||||
void EventReportingProxyMock::forwardEvent(Event event, uint32_t parameter1,
|
||||
uint32_t parameter2) const {
|
||||
eventQueue.emplace(event, parameter1, parameter2);
|
||||
}
|
21
unittests/mock/EventReportingProxyMock.h
Normal file
21
unittests/mock/EventReportingProxyMock.h
Normal file
@ -0,0 +1,21 @@
|
||||
#ifndef FSFW_TESTS_EVENTREPORTPROXYMOCK_H
|
||||
#define FSFW_TESTS_EVENTREPORTPROXYMOCK_H
|
||||
|
||||
#include <queue>
|
||||
|
||||
#include "fsfw/events/EventReportingProxyIF.h"
|
||||
|
||||
class EventReportingProxyMock : public EventReportingProxyIF {
|
||||
public:
|
||||
void forwardEvent(Event event, uint32_t parameter1, uint32_t parameter2) const override;
|
||||
|
||||
struct EventInfo {
|
||||
EventInfo(Event event, uint32_t p1, uint32_t p2) : event(event), p1(p1), p2(p2) {}
|
||||
|
||||
Event event;
|
||||
uint32_t p1;
|
||||
uint32_t p2;
|
||||
};
|
||||
mutable std::queue<EventInfo> eventQueue;
|
||||
};
|
||||
#endif // FSFW_TESTS_EVENTREPORTPROXYMOCK_H
|
159
unittests/mock/FilesystemMock.cpp
Normal file
159
unittests/mock/FilesystemMock.cpp
Normal file
@ -0,0 +1,159 @@
|
||||
#include "FilesystemMock.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <filesystem>
|
||||
|
||||
#include "fsfw/serialize/SerializeIF.h"
|
||||
|
||||
ReturnValue_t FilesystemMock::feedFile(const std::string& filename, std::ifstream& file) {
|
||||
if (not std::filesystem::exists(filename)) {
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
size_t fileSize = std::filesystem::file_size(filename);
|
||||
FileOpParams params(filename.c_str(), fileSize);
|
||||
std::vector<uint8_t> rawData(fileSize);
|
||||
file.read(reinterpret_cast<char*>(rawData.data()), static_cast<unsigned int>(rawData.size()));
|
||||
createOrAddToFile(filename.data(), 0, rawData.data(), rawData.size());
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t FilesystemMock::writeToFile(const char* path, size_t offset, const uint8_t* data,
|
||||
size_t size) {
|
||||
createOrAddToFile(path, offset, data, size);
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t FilesystemMock::readFromFile(const char* path, size_t offset, size_t size,
|
||||
uint8_t* buffer, size_t& readSize, size_t maxSize) {
|
||||
const std::string filename(path);
|
||||
const auto iter = fileMap.find(filename);
|
||||
if (iter == fileMap.end()) {
|
||||
return HasFileSystemIF::FILE_DOES_NOT_EXIST;
|
||||
}
|
||||
auto& [fileSegQueue, fileRaw] = iter->second;
|
||||
size_t readLen = size;
|
||||
if (offset + size > fileRaw.size()) {
|
||||
if (offset > fileRaw.size()) {
|
||||
return returnvalue::OK;
|
||||
}
|
||||
readLen = fileRaw.size() - offset;
|
||||
}
|
||||
if (readSize + readLen > maxSize) {
|
||||
return SerializeIF::STREAM_TOO_SHORT;
|
||||
}
|
||||
// std::copy(info.fileRaw.data() + offset, info.fileRaw.data() + offset + readLen, *buffer);
|
||||
std::memcpy(buffer, fileRaw.data() + offset, readLen);
|
||||
readSize = readLen;
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t FilesystemMock::createFile(const char* path, const uint8_t* data, size_t size) {
|
||||
createOrAddToFile(path, 0, data, size);
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t FilesystemMock::removeFile(const char* path, FileSystemArgsIF* args) {
|
||||
std::string filename(path);
|
||||
auto iter = fileMap.find(filename);
|
||||
if (iter == fileMap.end()) {
|
||||
return HasFileSystemIF::FILE_DOES_NOT_EXIST;
|
||||
} else {
|
||||
fileMap.erase(iter);
|
||||
return returnvalue::OK;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t FilesystemMock::createDirectory(const char* path, bool createParentDirs,
|
||||
FileSystemArgsIF* args) {
|
||||
std::string dirPath = path;
|
||||
dirMap[dirPath].createCallCount++;
|
||||
dirMap[dirPath].wihParentDir.push(createParentDirs);
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t FilesystemMock::removeDirectory(const char* path, bool deleteRecurively,
|
||||
FileSystemArgsIF* args) {
|
||||
std::string dirPath = path;
|
||||
dirMap[dirPath].delCallCount++;
|
||||
dirMap[dirPath].recursiveDeletion.push(deleteRecurively);
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t FilesystemMock::rename(const char* oldPath, const char* newPath,
|
||||
FileSystemArgsIF* args) {
|
||||
renameQueue.emplace(oldPath, newPath);
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
void FilesystemMock::createOrAddToFile(const char* path, size_t offset, const uint8_t* data,
|
||||
size_t dataSize) {
|
||||
std::string filename(path);
|
||||
auto iter = fileMap.find(filename);
|
||||
if (iter == fileMap.end()) {
|
||||
FileSegmentQueue queue;
|
||||
if (dataSize > 0) {
|
||||
queue.emplace(filename, offset, data, dataSize);
|
||||
}
|
||||
FileInfo info;
|
||||
info.fileSegQueue = queue;
|
||||
if (data != nullptr) {
|
||||
info.fileRaw.insert(info.fileRaw.end(), data, data + dataSize);
|
||||
}
|
||||
fileMap.emplace(filename, info);
|
||||
} else {
|
||||
FileInfo& info = iter->second;
|
||||
info.fileSegQueue.emplace(filename, offset, data, dataSize);
|
||||
if (data == nullptr) {
|
||||
return;
|
||||
}
|
||||
// Easiest case: append data to the end
|
||||
if (offset == info.fileRaw.size()) {
|
||||
info.fileRaw.insert(info.fileRaw.end(), data, data + dataSize);
|
||||
} else {
|
||||
size_t totalNewLen = offset + dataSize;
|
||||
if (totalNewLen > info.fileRaw.size()) {
|
||||
info.fileRaw.resize(offset + dataSize);
|
||||
}
|
||||
std::copy(data, data + dataSize, info.fileRaw.begin() + static_cast<unsigned int>(offset));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FilesystemMock::reset() {
|
||||
fileMap.clear();
|
||||
dirMap.clear();
|
||||
std::queue<RenameInfo> empty;
|
||||
std::swap(renameQueue, empty);
|
||||
}
|
||||
|
||||
bool FilesystemMock::fileExists(const char* path, FileSystemArgsIF* args) {
|
||||
std::string filename(path);
|
||||
auto iter = fileMap.find(filename);
|
||||
if (iter == fileMap.end()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
ReturnValue_t FilesystemMock::truncateFile(const char* path, FileSystemArgsIF* args) {
|
||||
truncateCalledOnFile = path;
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t FilesystemMock::getBaseFilename(const char* path, char* nameBuf, size_t maxLen,
|
||||
size_t& baseNameLen) {
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t FilesystemMock::isDirectory(const char* path, bool& isDirectory) { return false; }
|
||||
|
||||
ReturnValue_t FilesystemMock::getFileSize(const char* path, uint64_t& fileSize,
|
||||
FileSystemArgsIF* args) {
|
||||
std::string filename(path);
|
||||
auto iter = fileMap.find(filename);
|
||||
if (iter != fileMap.end()) {
|
||||
fileSize = iter->second.fileRaw.size();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
96
unittests/mock/FilesystemMock.h
Normal file
96
unittests/mock/FilesystemMock.h
Normal file
@ -0,0 +1,96 @@
|
||||
#ifndef FSFW_MOCKS_FILESYSTEMMOCK_H
|
||||
#define FSFW_MOCKS_FILESYSTEMMOCK_H
|
||||
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
#include <queue>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "fsfw/filesystem.h"
|
||||
|
||||
/**
|
||||
* This mock models a filesystem in the RAM. It can be used to verify correct behaviour of
|
||||
* a component using a filesystem without relying on an actual OS filesystem implementation.
|
||||
*
|
||||
* Please note that this object does not actually check paths for validity. The file API was
|
||||
* built in a way to allow reading a file back after it was written while also remembering
|
||||
* the specific file segments which were inserted in write calls.
|
||||
*/
|
||||
class FilesystemMock : public HasFileSystemIF {
|
||||
public:
|
||||
struct FileWriteInfo {
|
||||
FileWriteInfo(std::string filename, size_t offset, const uint8_t* data, size_t len)
|
||||
: filename(std::move(filename)), offset(offset) {
|
||||
this->data.insert(this->data.end(), data, data + len);
|
||||
}
|
||||
std::string filename;
|
||||
size_t offset;
|
||||
std::vector<uint8_t> data;
|
||||
};
|
||||
using FileSegmentQueue = std::queue<FileWriteInfo>;
|
||||
|
||||
struct FileInfo {
|
||||
FileSegmentQueue fileSegQueue;
|
||||
std::vector<uint8_t> fileRaw;
|
||||
};
|
||||
|
||||
std::map<std::string, FileInfo> fileMap;
|
||||
|
||||
struct DirInfo {
|
||||
size_t createCallCount = 0;
|
||||
size_t delCallCount = 0;
|
||||
std::queue<bool> wihParentDir;
|
||||
std::queue<bool> recursiveDeletion;
|
||||
};
|
||||
std::map<std::string, DirInfo> dirMap;
|
||||
|
||||
struct RenameInfo {
|
||||
RenameInfo(std::string oldName, std::string newName)
|
||||
: oldName(std::move(oldName)), newName(std::move(newName)) {}
|
||||
|
||||
std::string oldName;
|
||||
std::string newName;
|
||||
};
|
||||
std::queue<RenameInfo> renameQueue;
|
||||
std::string truncateCalledOnFile;
|
||||
ReturnValue_t feedFile(const std::string& filename, std::ifstream& file);
|
||||
|
||||
ReturnValue_t getBaseFilename(const char* path, char* nameBuf, size_t maxLen,
|
||||
size_t& baseNameLen) override;
|
||||
|
||||
ReturnValue_t isDirectory(const char* path, bool& isDirectory) override;
|
||||
|
||||
bool fileExists(const char* path, FileSystemArgsIF* args) override;
|
||||
|
||||
ReturnValue_t truncateFile(const char* path, FileSystemArgsIF* args) override;
|
||||
|
||||
ReturnValue_t getFileSize(const char* path, uint64_t& fileSize, FileSystemArgsIF* args) override;
|
||||
|
||||
ReturnValue_t writeToFile(const char* path, size_t offset, const uint8_t* data,
|
||||
size_t size) override;
|
||||
|
||||
ReturnValue_t readFromFile(const char* path, size_t offset, size_t size, uint8_t* buffer,
|
||||
size_t& readSize, size_t maxSize) override;
|
||||
|
||||
ReturnValue_t createFile(const char* path, const uint8_t* data, size_t size) override;
|
||||
ReturnValue_t removeFile(const char* path, FileSystemArgsIF* args) override;
|
||||
|
||||
ReturnValue_t createDirectory(const char* path, bool createParentDirs,
|
||||
FileSystemArgsIF* args) override;
|
||||
|
||||
ReturnValue_t removeDirectory(const char* path, bool deleteRecurively,
|
||||
FileSystemArgsIF* args) override;
|
||||
ReturnValue_t rename(const char* oldPath, const char* newPath, FileSystemArgsIF* args) override;
|
||||
|
||||
void reset();
|
||||
|
||||
using HasFileSystemIF::createDirectory;
|
||||
using HasFileSystemIF::createFile;
|
||||
using HasFileSystemIF::readFromFile;
|
||||
|
||||
private:
|
||||
void createOrAddToFile(const char* path, size_t offset, const uint8_t* data, size_t dataSize);
|
||||
};
|
||||
|
||||
#endif // FSFW_MOCKS_FILESYSTEMMOCK_H
|
16
unittests/mock/HkReceiverMock.h
Normal file
16
unittests/mock/HkReceiverMock.h
Normal file
@ -0,0 +1,16 @@
|
||||
#ifndef FSFW_UNITTEST_TESTS_MOCKS_HKRECEIVERMOCK_H_
|
||||
#define FSFW_UNITTEST_TESTS_MOCKS_HKRECEIVERMOCK_H_
|
||||
|
||||
#include <fsfw/housekeeping/AcceptsHkPacketsIF.h>
|
||||
|
||||
class HkReceiverMock : public AcceptsHkPacketsIF {
|
||||
public:
|
||||
explicit HkReceiverMock(MessageQueueId_t queueId) : queueId(queueId) {}
|
||||
|
||||
[[nodiscard]] MessageQueueId_t getHkQueue() const override { return queueId; }
|
||||
|
||||
private:
|
||||
MessageQueueId_t queueId;
|
||||
};
|
||||
|
||||
#endif /* FSFW_UNITTEST_TESTS_MOCKS_HKRECEIVERMOCK_H_ */
|
13
unittests/mock/InternalErrorReporterMock.cpp
Normal file
13
unittests/mock/InternalErrorReporterMock.cpp
Normal file
@ -0,0 +1,13 @@
|
||||
#include "InternalErrorReporterMock.h"
|
||||
|
||||
InternalErrorReporterMock::InternalErrorReporterMock() = default;
|
||||
|
||||
void InternalErrorReporterMock::queueMessageNotSent() { queueMsgNotSentCallCnt++; }
|
||||
void InternalErrorReporterMock::lostTm() { lostTmCallCnt++; }
|
||||
void InternalErrorReporterMock::storeFull() { storeFullCallCnt++; }
|
||||
|
||||
void InternalErrorReporterMock::reset() {
|
||||
queueMsgNotSentCallCnt = 0;
|
||||
lostTmCallCnt = 0;
|
||||
storeFullCallCnt = 0;
|
||||
}
|
19
unittests/mock/InternalErrorReporterMock.h
Normal file
19
unittests/mock/InternalErrorReporterMock.h
Normal file
@ -0,0 +1,19 @@
|
||||
#ifndef FSFW_TESTS_INTERNALERRORREPORTERMOCK_H
|
||||
#define FSFW_TESTS_INTERNALERRORREPORTERMOCK_H
|
||||
|
||||
#include "fsfw/internalerror/InternalErrorReporterIF.h"
|
||||
|
||||
class InternalErrorReporterMock : public InternalErrorReporterIF {
|
||||
public:
|
||||
unsigned int queueMsgNotSentCallCnt = 0;
|
||||
unsigned int lostTmCallCnt = 0;
|
||||
unsigned int storeFullCallCnt = 0;
|
||||
InternalErrorReporterMock();
|
||||
void reset();
|
||||
|
||||
private:
|
||||
void queueMessageNotSent() override;
|
||||
void lostTm() override;
|
||||
void storeFull() override;
|
||||
};
|
||||
#endif // FSFW_TESTS_INTERNALERRORREPORTERMOCK_H
|
173
unittests/mock/MessageQueueMock.cpp
Normal file
173
unittests/mock/MessageQueueMock.cpp
Normal file
@ -0,0 +1,173 @@
|
||||
#include "MessageQueueMock.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <stdexcept>
|
||||
|
||||
MessageQueueMock::MessageQueueMock(MessageQueueId_t queueId, MessageQueueId_t defaultDest)
|
||||
: MessageQueueBase(queueId, defaultDest, nullptr) {}
|
||||
|
||||
bool MessageQueueMock::wasMessageSent() const {
|
||||
return std::any_of(
|
||||
sendMap.begin(), sendMap.end(),
|
||||
[](const std::pair<MessageQueueId_t, SendInfo>& pair) { return pair.second.callCount > 0; });
|
||||
}
|
||||
|
||||
size_t MessageQueueMock::numberOfSentMessages() const {
|
||||
size_t callCount = 0;
|
||||
for (auto& destInfo : sendMap) {
|
||||
callCount += destInfo.second.callCount;
|
||||
}
|
||||
return callCount;
|
||||
}
|
||||
|
||||
size_t MessageQueueMock::numberOfSentMessagesToDest(MessageQueueId_t id) const {
|
||||
auto iter = sendMap.find(id);
|
||||
if (iter == sendMap.end()) {
|
||||
return 0;
|
||||
}
|
||||
return iter->second.callCount;
|
||||
}
|
||||
|
||||
size_t MessageQueueMock::numberOfSentMessagesToDefault() const {
|
||||
return numberOfSentMessagesToDest(MessageQueueBase::getDefaultDestination());
|
||||
}
|
||||
|
||||
ReturnValue_t MessageQueueMock::clearLastReceivedMessage(bool clearCmdMsg) {
|
||||
if (receivedMsgs.empty()) {
|
||||
return MessageQueueIF::EMPTY;
|
||||
}
|
||||
if (clearCmdMsg) {
|
||||
CommandMessage message;
|
||||
std::memcpy(message.getBuffer(), receivedMsgs.front().getBuffer(), message.getMessageSize());
|
||||
message.clearCommandMessage();
|
||||
}
|
||||
receivedMsgs.pop();
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t MessageQueueMock::receiveMessage(MessageQueueMessageIF* message) {
|
||||
if (receivedMsgs.empty()) {
|
||||
return MessageQueueIF::EMPTY;
|
||||
}
|
||||
std::memcpy(message->getBuffer(), receivedMsgs.front().getBuffer(), message->getMessageSize());
|
||||
receivedMsgs.pop();
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t MessageQueueMock::flush(uint32_t* count) { return returnvalue::FAILED; }
|
||||
|
||||
ReturnValue_t MessageQueueMock::sendMessageFrom(MessageQueueId_t sendTo,
|
||||
MessageQueueMessageIF* message,
|
||||
MessageQueueId_t sentFrom, bool ignoreFault) {
|
||||
if (message == nullptr) {
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
if (nextSendFailsPair.first) {
|
||||
nextSendFailsPair.first = false;
|
||||
return nextSendFailsPair.second;
|
||||
}
|
||||
auto iter = sendMap.find(sendTo);
|
||||
MessageQueueMessage messageCopy;
|
||||
if (iter == sendMap.end()) {
|
||||
createMsgCopy(messageCopy, *message);
|
||||
sendMap.emplace(sendTo, SendInfo(messageCopy, 1));
|
||||
} else {
|
||||
iter->second.callCount += 1;
|
||||
createMsgCopy(messageCopy, *message);
|
||||
iter->second.msgs.push(messageCopy);
|
||||
}
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t MessageQueueMock::reply(MessageQueueMessageIF* message) {
|
||||
return sendMessageFrom(MessageQueueIF::NO_QUEUE, message, this->getId(), false);
|
||||
}
|
||||
|
||||
void MessageQueueMock::clearMessages(bool clearCommandMessages) {
|
||||
if (not clearCommandMessages) {
|
||||
sendMap.clear();
|
||||
return;
|
||||
}
|
||||
for (auto& destInfo : sendMap) {
|
||||
while (!destInfo.second.msgs.empty()) {
|
||||
CommandMessage message;
|
||||
std::memcpy(message.getBuffer(), destInfo.second.msgs.front().getBuffer(),
|
||||
message.getMessageSize());
|
||||
message.clear();
|
||||
destInfo.second.msgs.pop();
|
||||
destInfo.second.callCount--;
|
||||
}
|
||||
}
|
||||
sendMap.clear();
|
||||
}
|
||||
|
||||
void MessageQueueMock::addReceivedMessage(MessageQueueMessageIF& msg) {
|
||||
MessageQueueMessage messageCopy;
|
||||
createMsgCopy(messageCopy, msg);
|
||||
receivedMsgs.push(messageCopy);
|
||||
}
|
||||
|
||||
void MessageQueueMock::createMsgCopy(MessageQueueMessageIF& into, MessageQueueMessageIF& from) {
|
||||
if (from.getMessageSize() > into.getMaximumDataSize()) {
|
||||
throw std::invalid_argument("Passed message does not fit into message copy");
|
||||
}
|
||||
std::memcpy(into.getBuffer(), from.getBuffer(), from.getMaximumDataSize());
|
||||
}
|
||||
|
||||
ReturnValue_t MessageQueueMock::getNextSentMessage(MessageQueueId_t id,
|
||||
MessageQueueMessageIF& message) {
|
||||
auto iter = sendMap.find(id);
|
||||
if (iter == sendMap.end() or iter->second.callCount == 0) {
|
||||
return MessageQueueIF::EMPTY;
|
||||
}
|
||||
createMsgCopy(message, iter->second.msgs.front());
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t MessageQueueMock::getNextSentMessageToDefaultDest(MessageQueueMessageIF& message) {
|
||||
return getNextSentMessage(MessageQueueBase::getDefaultDestination(), message);
|
||||
}
|
||||
|
||||
ReturnValue_t MessageQueueMock::clearLastSentMessage(MessageQueueId_t destId, bool clearCmdMsg) {
|
||||
auto iter = sendMap.find(destId);
|
||||
if (iter == sendMap.end()) {
|
||||
return MessageQueueIF::EMPTY;
|
||||
}
|
||||
return clearLastSentMessage(iter, clearCmdMsg);
|
||||
}
|
||||
|
||||
ReturnValue_t MessageQueueMock::clearLastSentMessage(bool clearCmdMsg) {
|
||||
auto iter = sendMap.find(getDefaultDestination());
|
||||
if (iter == sendMap.end()) {
|
||||
return MessageQueueIF::EMPTY;
|
||||
}
|
||||
ReturnValue_t result = clearLastSentMessage(iter, clearCmdMsg);
|
||||
clearEmptyEntries();
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t MessageQueueMock::clearLastSentMessage(
|
||||
std::map<MessageQueueId_t, SendInfo>::iterator& iter, bool clearCmdMsg) {
|
||||
if (clearCmdMsg) {
|
||||
CommandMessage message;
|
||||
std::memcpy(message.getBuffer(), iter->second.msgs.front().getBuffer(),
|
||||
message.getMessageSize());
|
||||
message.clear();
|
||||
}
|
||||
iter->second.msgs.pop();
|
||||
iter->second.callCount--;
|
||||
return returnvalue::OK;
|
||||
}
|
||||
void MessageQueueMock::clearEmptyEntries() {
|
||||
for (auto it = sendMap.cbegin(); it != sendMap.cend();) {
|
||||
if (it->second.callCount == 0) {
|
||||
sendMap.erase(it++);
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
void MessageQueueMock::makeNextSendFail(ReturnValue_t retval) {
|
||||
nextSendFailsPair.first = true;
|
||||
nextSendFailsPair.second = retval;
|
||||
}
|
64
unittests/mock/MessageQueueMock.h
Normal file
64
unittests/mock/MessageQueueMock.h
Normal file
@ -0,0 +1,64 @@
|
||||
#ifndef FSFW_UNITTEST_TESTS_MOCKS_MESSAGEQUEUEMOCKBASE_H_
|
||||
#define FSFW_UNITTEST_TESTS_MOCKS_MESSAGEQUEUEMOCKBASE_H_
|
||||
|
||||
#include <cstring>
|
||||
#include <map>
|
||||
#include <queue>
|
||||
|
||||
#include "CatchDefinitions.h"
|
||||
#include "fsfw/ipc/CommandMessage.h"
|
||||
#include "fsfw/ipc/MessageQueueBase.h"
|
||||
#include "fsfw/ipc/MessageQueueIF.h"
|
||||
#include "fsfw/ipc/MessageQueueMessage.h"
|
||||
|
||||
struct SendInfo {
|
||||
explicit SendInfo(MessageQueueMessage& initMsg, unsigned int initCallCnt = 1)
|
||||
: callCount(initCallCnt) {
|
||||
msgs.push(initMsg);
|
||||
}
|
||||
unsigned int callCount = 0;
|
||||
std::queue<MessageQueueMessage> msgs;
|
||||
};
|
||||
|
||||
class MessageQueueMock : public MessageQueueBase {
|
||||
public:
|
||||
void addReceivedMessage(MessageQueueMessageIF& msg);
|
||||
explicit MessageQueueMock(MessageQueueId_t queueId, MessageQueueId_t defaultDest);
|
||||
|
||||
//! Get next message which was sent to the default destination
|
||||
ReturnValue_t getNextSentMessageToDefaultDest(MessageQueueMessageIF& message);
|
||||
//! Get message which was sent to a specific ID
|
||||
ReturnValue_t getNextSentMessage(MessageQueueId_t id, MessageQueueMessageIF& message);
|
||||
[[nodiscard]] bool wasMessageSent() const;
|
||||
void makeNextSendFail(ReturnValue_t retval);
|
||||
[[nodiscard]] size_t numberOfSentMessages() const;
|
||||
[[nodiscard]] size_t numberOfSentMessagesToDefault() const;
|
||||
[[nodiscard]] size_t numberOfSentMessagesToDest(MessageQueueId_t id) const;
|
||||
/**
|
||||
* Pop a message, clearing it in the process.
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t clearLastReceivedMessage(bool clearCmdMsg = true);
|
||||
|
||||
ReturnValue_t flush(uint32_t* count) override;
|
||||
ReturnValue_t sendMessageFrom(MessageQueueId_t sendTo, MessageQueueMessageIF* message,
|
||||
MessageQueueId_t sentFrom, bool ignoreFault = false) override;
|
||||
ReturnValue_t reply(MessageQueueMessageIF* message) override;
|
||||
|
||||
ReturnValue_t clearLastSentMessage(MessageQueueId_t destId, bool clearCmdMsg = true);
|
||||
ReturnValue_t clearLastSentMessage(bool clearCmdMsg = true);
|
||||
void clearMessages(bool clearCmdMsg = true);
|
||||
|
||||
private:
|
||||
using SendMap = std::map<MessageQueueId_t, SendInfo>;
|
||||
SendMap sendMap;
|
||||
std::queue<MessageQueueMessage> receivedMsgs;
|
||||
std::pair<bool, ReturnValue_t> nextSendFailsPair;
|
||||
|
||||
void clearEmptyEntries();
|
||||
ReturnValue_t receiveMessage(MessageQueueMessageIF* message) override;
|
||||
static ReturnValue_t clearLastSentMessage(SendMap::iterator& iter, bool clearCmdMsg = true);
|
||||
static void createMsgCopy(MessageQueueMessageIF& into, MessageQueueMessageIF& from);
|
||||
};
|
||||
|
||||
#endif /* FSFW_UNITTEST_TESTS_MOCKS_MESSAGEQUEUEMOCKBASE_H_ */
|
25
unittests/mock/PeriodicTaskIFMock.h
Normal file
25
unittests/mock/PeriodicTaskIFMock.h
Normal file
@ -0,0 +1,25 @@
|
||||
#ifndef FSFW_UNITTEST_TESTS_MOCKS_PERIODICTASKMOCK_H_
|
||||
#define FSFW_UNITTEST_TESTS_MOCKS_PERIODICTASKMOCK_H_
|
||||
|
||||
#include <fsfw/tasks/ExecutableObjectIF.h>
|
||||
#include <fsfw/tasks/PeriodicTaskBase.h>
|
||||
|
||||
class PeriodicTaskMock : public PeriodicTaskBase {
|
||||
public:
|
||||
PeriodicTaskMock(TaskPeriod period, TaskDeadlineMissedFunction dlmFunc)
|
||||
: PeriodicTaskBase(period, dlmFunc) {}
|
||||
|
||||
virtual ~PeriodicTaskMock() {}
|
||||
/**
|
||||
* @brief With the startTask method, a created task can be started
|
||||
* for the first time.
|
||||
*/
|
||||
virtual ReturnValue_t startTask() override {
|
||||
initObjsAfterTaskCreation();
|
||||
return returnvalue::OK;
|
||||
};
|
||||
|
||||
virtual ReturnValue_t sleepFor(uint32_t ms) override { return returnvalue::OK; };
|
||||
};
|
||||
|
||||
#endif // FSFW_UNITTEST_TESTS_MOCKS_PERIODICTASKMOCK_H_
|
77
unittests/mock/PowerSwitcherMock.cpp
Normal file
77
unittests/mock/PowerSwitcherMock.cpp
Normal file
@ -0,0 +1,77 @@
|
||||
#include "PowerSwitcherMock.h"
|
||||
|
||||
static uint32_t SWITCH_REQUEST_UPDATE_VALUE = 0;
|
||||
|
||||
PowerSwitcherMock::PowerSwitcherMock() {}
|
||||
|
||||
ReturnValue_t PowerSwitcherMock::sendSwitchCommand(power::Switch_t switchNr, ReturnValue_t onOff) {
|
||||
if (switchMap.count(switchNr) == 0) {
|
||||
switchMap.emplace(switchNr, SwitchInfo(switchNr, onOff));
|
||||
} else {
|
||||
SwitchInfo& info = switchMap.at(switchNr);
|
||||
info.currentState = onOff;
|
||||
if (onOff == PowerSwitchIF::SWITCH_ON) {
|
||||
info.timesCalledOn++;
|
||||
} else {
|
||||
info.timesCalledOff++;
|
||||
}
|
||||
}
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t PowerSwitcherMock::sendFuseOnCommand(uint8_t fuseNr) {
|
||||
if (fuseMap.count(fuseNr) == 0) {
|
||||
fuseMap.emplace(fuseNr, FuseInfo(fuseNr));
|
||||
} else {
|
||||
FuseInfo& info = fuseMap.at(fuseNr);
|
||||
info.timesCalled++;
|
||||
}
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t PowerSwitcherMock::getSwitchState(power::Switch_t switchNr) const {
|
||||
if (switchMap.count(switchNr) == 1) {
|
||||
auto& info = switchMap.at(switchNr);
|
||||
SWITCH_REQUEST_UPDATE_VALUE++;
|
||||
return info.currentState;
|
||||
}
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
|
||||
ReturnValue_t PowerSwitcherMock::getFuseState(uint8_t fuseNr) const {
|
||||
if (fuseMap.count(fuseNr) == 1) {
|
||||
return FUSE_ON;
|
||||
} else {
|
||||
return FUSE_OFF;
|
||||
}
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
|
||||
uint32_t PowerSwitcherMock::getSwitchDelayMs(void) const { return 5000; }
|
||||
|
||||
SwitchInfo::SwitchInfo() : switcher(0) {}
|
||||
|
||||
SwitchInfo::SwitchInfo(power::Switch_t switcher, ReturnValue_t initState)
|
||||
: switcher(switcher), currentState(initState) {}
|
||||
|
||||
FuseInfo::FuseInfo(uint8_t fuse) : fuse(fuse) {}
|
||||
|
||||
void PowerSwitcherMock::getSwitchInfo(power::Switch_t switcher, SwitchInfo& info) {
|
||||
if (switchMap.count(switcher) == 1) {
|
||||
info = switchMap.at(switcher);
|
||||
}
|
||||
}
|
||||
|
||||
void PowerSwitcherMock::getFuseInfo(uint8_t fuse, FuseInfo& info) {
|
||||
if (fuseMap.count(fuse) == 1) {
|
||||
info = fuseMap.at(fuse);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t PowerSwitcherMock::getAmountSwitchStatWasRequested() {
|
||||
return SWITCH_REQUEST_UPDATE_VALUE;
|
||||
}
|
||||
|
||||
void PowerSwitcherMock::initSwitch(power::Switch_t switchNr) {
|
||||
switchMap.emplace(switchNr, SwitchInfo(switchNr, PowerSwitchIF::SWITCH_OFF));
|
||||
}
|
52
unittests/mock/PowerSwitcherMock.h
Normal file
52
unittests/mock/PowerSwitcherMock.h
Normal file
@ -0,0 +1,52 @@
|
||||
#ifndef FSFW_TESTS_SRC_FSFW_TESTS_UNIT_MOCKS_POWERSWITCHERMOCK_H_
|
||||
#define FSFW_TESTS_SRC_FSFW_TESTS_UNIT_MOCKS_POWERSWITCHERMOCK_H_
|
||||
|
||||
#include <fsfw/power/PowerSwitchIF.h>
|
||||
|
||||
#include <map>
|
||||
#include <utility>
|
||||
|
||||
struct SwitchInfo {
|
||||
public:
|
||||
SwitchInfo();
|
||||
SwitchInfo(power::Switch_t switcher, ReturnValue_t initState);
|
||||
|
||||
power::Switch_t switcher;
|
||||
ReturnValue_t currentState = PowerSwitchIF::SWITCH_OFF;
|
||||
uint32_t timesCalledOn = 0;
|
||||
uint32_t timesCalledOff = 0;
|
||||
uint32_t timesStatusRequested = 0;
|
||||
};
|
||||
|
||||
struct FuseInfo {
|
||||
public:
|
||||
FuseInfo(uint8_t fuse);
|
||||
uint8_t fuse;
|
||||
uint32_t timesCalled = 0;
|
||||
};
|
||||
|
||||
class PowerSwitcherMock : public PowerSwitchIF {
|
||||
public:
|
||||
PowerSwitcherMock();
|
||||
|
||||
ReturnValue_t sendSwitchCommand(power::Switch_t switchNr, ReturnValue_t onOff) override;
|
||||
ReturnValue_t sendFuseOnCommand(uint8_t fuseNr) override;
|
||||
ReturnValue_t getSwitchState(power::Switch_t switchNr) const override;
|
||||
ReturnValue_t getFuseState(uint8_t fuseNr) const override;
|
||||
uint32_t getSwitchDelayMs(void) const override;
|
||||
|
||||
void getSwitchInfo(power::Switch_t switcher, SwitchInfo& info);
|
||||
void getFuseInfo(uint8_t fuse, FuseInfo& info);
|
||||
|
||||
uint32_t getAmountSwitchStatWasRequested();
|
||||
|
||||
void initSwitch(power::Switch_t switchNr);
|
||||
|
||||
private:
|
||||
using SwitchOnOffPair = std::pair<power::Switch_t, ReturnValue_t>;
|
||||
using FuseOnOffPair = std::pair<uint8_t, ReturnValue_t>;
|
||||
std::map<power::Switch_t, SwitchInfo> switchMap;
|
||||
std::map<uint8_t, FuseInfo> fuseMap;
|
||||
};
|
||||
|
||||
#endif /* FSFW_TESTS_SRC_FSFW_TESTS_UNIT_MOCKS_POWERSWITCHERMOCK_H_ */
|
12
unittests/mock/PusDistributorMock.cpp
Normal file
12
unittests/mock/PusDistributorMock.cpp
Normal file
@ -0,0 +1,12 @@
|
||||
#include "PusDistributorMock.h"
|
||||
|
||||
PusDistributorMock::PusDistributorMock() : SystemObject(objects::NO_OBJECT, false) {}
|
||||
|
||||
PusDistributorMock::PusDistributorMock(object_id_t registeredId)
|
||||
: SystemObject(registeredId, true) {}
|
||||
|
||||
ReturnValue_t PusDistributorMock::registerService(const AcceptsTelecommandsIF& service) {
|
||||
registerCallCount++;
|
||||
registeredServies.push_back(&service);
|
||||
return returnvalue::OK;
|
||||
}
|
18
unittests/mock/PusDistributorMock.h
Normal file
18
unittests/mock/PusDistributorMock.h
Normal file
@ -0,0 +1,18 @@
|
||||
#ifndef FSFW_TESTS_PUSDISTRIBUTORMOCK_H
|
||||
#define FSFW_TESTS_PUSDISTRIBUTORMOCK_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "fsfw/objectmanager/SystemObject.h"
|
||||
#include "fsfw/tcdistribution/PusDistributorIF.h"
|
||||
|
||||
class PusDistributorMock : public SystemObject, public PusDistributorIF {
|
||||
public:
|
||||
PusDistributorMock();
|
||||
explicit PusDistributorMock(object_id_t registeredId);
|
||||
unsigned int registerCallCount = 0;
|
||||
std::vector<const AcceptsTelecommandsIF*> registeredServies;
|
||||
ReturnValue_t registerService(const AcceptsTelecommandsIF& service) override;
|
||||
};
|
||||
|
||||
#endif // FSFW_TESTS_PUSDISTRIBUTORMOCK_H
|
53
unittests/mock/PusServiceBaseMock.cpp
Normal file
53
unittests/mock/PusServiceBaseMock.cpp
Normal file
@ -0,0 +1,53 @@
|
||||
#include "PusServiceBaseMock.h"
|
||||
|
||||
PsbMock::PsbMock(PsbParams params) : PusServiceBase(params) {}
|
||||
|
||||
ReturnValue_t PsbMock::handleRequest(uint8_t subservice) {
|
||||
handleRequestCallCnt++;
|
||||
subserviceQueue.push(subservice);
|
||||
if (handleReqFailPair.first) {
|
||||
handleReqFailPair.first = false;
|
||||
return handleReqFailPair.second;
|
||||
}
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t PsbMock::performService() {
|
||||
performServiceCallCnt++;
|
||||
if (performServiceFailPair.first) {
|
||||
performServiceFailPair.first = false;
|
||||
return performServiceFailPair.second;
|
||||
}
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
void PsbMock::reset() {
|
||||
handleRequestCallCnt = 0;
|
||||
performServiceCallCnt = 0;
|
||||
std::queue<uint8_t>().swap(subserviceQueue);
|
||||
}
|
||||
|
||||
void PsbMock::makeNextHandleReqCallFail(ReturnValue_t retval) {
|
||||
handleReqFailPair.first = true;
|
||||
handleReqFailPair.second = retval;
|
||||
}
|
||||
bool PsbMock::getAndPopNextSubservice(uint8_t& subservice) {
|
||||
if (subserviceQueue.empty()) {
|
||||
return false;
|
||||
}
|
||||
subservice = subserviceQueue.front();
|
||||
subserviceQueue.pop();
|
||||
return true;
|
||||
}
|
||||
|
||||
PsbParams& PsbMock::getParams() { return psbParams; }
|
||||
|
||||
void PsbMock::setStaticPusDistributor(object_id_t pusDistributor) {
|
||||
PUS_DISTRIBUTOR = pusDistributor;
|
||||
}
|
||||
|
||||
object_id_t PsbMock::getStaticPusDistributor() { return PUS_DISTRIBUTOR; }
|
||||
|
||||
void PsbMock::setStaticTmDest(object_id_t tmDest) { PACKET_DESTINATION = tmDest; }
|
||||
|
||||
object_id_t PsbMock::getStaticTmDest() { return PACKET_DESTINATION; }
|
32
unittests/mock/PusServiceBaseMock.h
Normal file
32
unittests/mock/PusServiceBaseMock.h
Normal file
@ -0,0 +1,32 @@
|
||||
#ifndef FSFW_TESTS_PUSSERVICEBASEMOCK_H
|
||||
#define FSFW_TESTS_PUSSERVICEBASEMOCK_H
|
||||
|
||||
#include <queue>
|
||||
|
||||
#include "fsfw/tmtcservices/PusServiceBase.h"
|
||||
|
||||
class PsbMock : public PusServiceBase {
|
||||
public:
|
||||
explicit PsbMock(PsbParams params);
|
||||
unsigned int handleRequestCallCnt = 0;
|
||||
std::queue<uint8_t> subserviceQueue;
|
||||
unsigned int performServiceCallCnt = 0;
|
||||
|
||||
static void setStaticPusDistributor(object_id_t pusDistributor);
|
||||
static object_id_t getStaticPusDistributor();
|
||||
static void setStaticTmDest(object_id_t tmDest);
|
||||
static object_id_t getStaticTmDest();
|
||||
|
||||
PsbParams& getParams();
|
||||
|
||||
std::pair<bool, ReturnValue_t> handleReqFailPair;
|
||||
std::pair<bool, ReturnValue_t> performServiceFailPair;
|
||||
ReturnValue_t handleRequest(uint8_t subservice) override;
|
||||
ReturnValue_t performService() override;
|
||||
|
||||
void makeNextHandleReqCallFail(ReturnValue_t retval);
|
||||
bool getAndPopNextSubservice(uint8_t& subservice);
|
||||
void reset();
|
||||
};
|
||||
|
||||
#endif // FSFW_TESTS_PUSSERVICEBASEMOCK_H
|
42
unittests/mock/PusVerificationReporterMock.cpp
Normal file
42
unittests/mock/PusVerificationReporterMock.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
#include "PusVerificationReporterMock.h"
|
||||
|
||||
#include "fsfw/objectmanager/frameworkObjects.h"
|
||||
|
||||
PusVerificationReporterMock::PusVerificationReporterMock()
|
||||
: SystemObject(objects::NO_OBJECT, false) {}
|
||||
|
||||
PusVerificationReporterMock::PusVerificationReporterMock(object_id_t registeredId)
|
||||
: SystemObject(registeredId) {}
|
||||
|
||||
size_t PusVerificationReporterMock::successCallCount() const { return successParams.size(); }
|
||||
size_t PusVerificationReporterMock::failCallCount() const { return failParams.size(); }
|
||||
|
||||
VerifSuccessParams& PusVerificationReporterMock::getNextSuccessCallParams() {
|
||||
return successParams.front();
|
||||
}
|
||||
|
||||
void PusVerificationReporterMock::popNextFailParams() {
|
||||
if (not failParams.empty()) {
|
||||
failParams.pop();
|
||||
}
|
||||
}
|
||||
|
||||
VerifFailureParams& PusVerificationReporterMock::getNextFailCallParams() {
|
||||
return failParams.front();
|
||||
}
|
||||
|
||||
void PusVerificationReporterMock::popNextSuccessParams() {
|
||||
if (not successParams.empty()) {
|
||||
successParams.pop();
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t PusVerificationReporterMock::sendSuccessReport(VerifSuccessParams params) {
|
||||
successParams.push(params);
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t PusVerificationReporterMock::sendFailureReport(VerifFailureParams params) {
|
||||
failParams.push(params);
|
||||
return returnvalue::OK;
|
||||
}
|
25
unittests/mock/PusVerificationReporterMock.h
Normal file
25
unittests/mock/PusVerificationReporterMock.h
Normal file
@ -0,0 +1,25 @@
|
||||
#ifndef FSFW_TESTS_PUSVERIFICATIONREPORTERMOCK_H
|
||||
#define FSFW_TESTS_PUSVERIFICATIONREPORTERMOCK_H
|
||||
|
||||
#include <queue>
|
||||
|
||||
#include "fsfw/objectmanager/SystemObject.h"
|
||||
#include "fsfw/tmtcservices/VerificationReporterIF.h"
|
||||
|
||||
class PusVerificationReporterMock : public SystemObject, public VerificationReporterIF {
|
||||
public:
|
||||
std::queue<VerifSuccessParams> successParams;
|
||||
std::queue<VerifFailureParams> failParams;
|
||||
PusVerificationReporterMock();
|
||||
explicit PusVerificationReporterMock(object_id_t registeredId);
|
||||
[[nodiscard]] size_t successCallCount() const;
|
||||
VerifSuccessParams& getNextSuccessCallParams();
|
||||
void popNextSuccessParams();
|
||||
[[nodiscard]] size_t failCallCount() const;
|
||||
VerifFailureParams& getNextFailCallParams();
|
||||
void popNextFailParams();
|
||||
|
||||
ReturnValue_t sendSuccessReport(VerifSuccessParams params) override;
|
||||
ReturnValue_t sendFailureReport(VerifFailureParams params) override;
|
||||
};
|
||||
#endif // FSFW_TESTS_PUSVERIFICATIONREPORTERMOCK_H
|
40
unittests/mock/SimpleSerializable.h
Normal file
40
unittests/mock/SimpleSerializable.h
Normal file
@ -0,0 +1,40 @@
|
||||
#ifndef FSFW_TESTS_SIMPLESERIALIZABLE_H
|
||||
#define FSFW_TESTS_SIMPLESERIALIZABLE_H
|
||||
|
||||
#include "fsfw/osal/Endiness.h"
|
||||
#include "fsfw/serialize.h"
|
||||
|
||||
class SimpleSerializable : public SerializeIF {
|
||||
public:
|
||||
ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize,
|
||||
Endianness streamEndianness) const override {
|
||||
if (*size + getSerializedSize() > maxSize) {
|
||||
return SerializeIF::BUFFER_TOO_SHORT;
|
||||
}
|
||||
**buffer = someU8;
|
||||
*buffer += 1;
|
||||
*size += 1;
|
||||
return SerializeAdapter::serialize(&someU16, buffer, size, maxSize, streamEndianness);
|
||||
}
|
||||
|
||||
[[nodiscard]] size_t getSerializedSize() const override { return 3; }
|
||||
ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size,
|
||||
Endianness streamEndianness) override {
|
||||
if (*size < getSerializedSize()) {
|
||||
return SerializeIF::STREAM_TOO_SHORT;
|
||||
}
|
||||
someU8 = **buffer;
|
||||
*size -= 1;
|
||||
*buffer += 1;
|
||||
return SerializeAdapter::deSerialize(&someU16, buffer, size, streamEndianness);
|
||||
}
|
||||
|
||||
[[nodiscard]] uint8_t getU8() const { return someU8; }
|
||||
[[nodiscard]] uint16_t getU16() const { return someU16; }
|
||||
|
||||
private:
|
||||
uint8_t someU8 = 1;
|
||||
uint16_t someU16 = 0x0203;
|
||||
};
|
||||
|
||||
#endif // FSFW_TESTS_SIMPLESERIALIZABLE_H
|
81
unittests/mock/StorageManagerMock.cpp
Normal file
81
unittests/mock/StorageManagerMock.cpp
Normal file
@ -0,0 +1,81 @@
|
||||
#include "StorageManagerMock.h"
|
||||
|
||||
ReturnValue_t StorageManagerMock::addData(store_address_t *storageId, const uint8_t *data,
|
||||
size_t size) {
|
||||
if (nextAddDataCallFails.first) {
|
||||
return nextAddDataCallFails.second;
|
||||
}
|
||||
return LocalPool::addData(storageId, data, size);
|
||||
}
|
||||
ReturnValue_t StorageManagerMock::deleteData(store_address_t packet_id) {
|
||||
if (nextDeleteDataCallFails.first) {
|
||||
return nextDeleteDataCallFails.second;
|
||||
}
|
||||
return LocalPool::deleteData(packet_id);
|
||||
}
|
||||
|
||||
ReturnValue_t StorageManagerMock::deleteData(uint8_t *buffer, size_t size,
|
||||
store_address_t *storeId) {
|
||||
if (nextDeleteDataCallFails.first) {
|
||||
return nextDeleteDataCallFails.second;
|
||||
}
|
||||
return LocalPool::deleteData(buffer, size, storeId);
|
||||
}
|
||||
|
||||
ReturnValue_t StorageManagerMock::getData(store_address_t packet_id, const uint8_t **packet_ptr,
|
||||
size_t *size) {
|
||||
return LocalPool::getData(packet_id, packet_ptr, size);
|
||||
}
|
||||
|
||||
ReturnValue_t StorageManagerMock::modifyData(store_address_t packet_id, uint8_t **packet_ptr,
|
||||
size_t *size) {
|
||||
if (nextModifyDataCallFails.first) {
|
||||
return nextModifyDataCallFails.second;
|
||||
}
|
||||
return LocalPool::modifyData(packet_id, packet_ptr, size);
|
||||
}
|
||||
|
||||
ReturnValue_t StorageManagerMock::getFreeElement(store_address_t *storageId, size_t size,
|
||||
uint8_t **p_data) {
|
||||
if (nextFreeElementCallFails.first) {
|
||||
return nextFreeElementCallFails.second;
|
||||
}
|
||||
return LocalPool::getFreeElement(storageId, size, p_data);
|
||||
}
|
||||
|
||||
bool StorageManagerMock::hasDataAtId(store_address_t storeId) const {
|
||||
return LocalPool::hasDataAtId(storeId);
|
||||
}
|
||||
void StorageManagerMock::clearStore() { return LocalPool::clearStore(); }
|
||||
|
||||
void StorageManagerMock::clearSubPool(uint8_t poolIndex) {
|
||||
return LocalPool::clearSubPool(poolIndex);
|
||||
}
|
||||
|
||||
void StorageManagerMock::getFillCount(uint8_t *buffer, uint8_t *bytesWritten) {
|
||||
return LocalPool::getFillCount(buffer, bytesWritten);
|
||||
}
|
||||
|
||||
size_t StorageManagerMock::getTotalSize(size_t *additionalSize) {
|
||||
return LocalPool::getTotalSize(additionalSize);
|
||||
}
|
||||
|
||||
StorageManagerIF::max_subpools_t StorageManagerMock::getNumberOfSubPools() const {
|
||||
return LocalPool::getNumberOfSubPools();
|
||||
}
|
||||
|
||||
void StorageManagerMock::reset() {
|
||||
clearStore();
|
||||
nextAddDataCallFails.first = false;
|
||||
nextAddDataCallFails.second = returnvalue::OK;
|
||||
nextModifyDataCallFails.first = false;
|
||||
nextModifyDataCallFails.second = returnvalue::OK;
|
||||
nextDeleteDataCallFails.first = false;
|
||||
nextDeleteDataCallFails.second = returnvalue::OK;
|
||||
nextFreeElementCallFails.first = false;
|
||||
nextFreeElementCallFails.second = returnvalue::OK;
|
||||
}
|
||||
|
||||
StorageManagerMock::StorageManagerMock(object_id_t setObjectId,
|
||||
const LocalPool::LocalPoolConfig &poolConfig)
|
||||
: LocalPool(setObjectId, poolConfig) {}
|
39
unittests/mock/StorageManagerMock.h
Normal file
39
unittests/mock/StorageManagerMock.h
Normal file
@ -0,0 +1,39 @@
|
||||
#ifndef FSFW_TESTS_STORAGEMANAGERMOCK_H
|
||||
#define FSFW_TESTS_STORAGEMANAGERMOCK_H
|
||||
|
||||
#include "fsfw/storagemanager/LocalPool.h"
|
||||
#include "fsfw/storagemanager/StorageManagerIF.h"
|
||||
|
||||
class StorageManagerMock : public LocalPool {
|
||||
public:
|
||||
StorageManagerMock(object_id_t setObjectId, const LocalPoolConfig &poolConfig);
|
||||
|
||||
ReturnValue_t addData(store_address_t *storageId, const uint8_t *data, size_t size) override;
|
||||
ReturnValue_t deleteData(store_address_t packet_id) override;
|
||||
ReturnValue_t deleteData(uint8_t *buffer, size_t size, store_address_t *storeId) override;
|
||||
ReturnValue_t getData(store_address_t packet_id, const uint8_t **packet_ptr,
|
||||
size_t *size) override;
|
||||
ReturnValue_t modifyData(store_address_t packet_id, uint8_t **packet_ptr, size_t *size) override;
|
||||
ReturnValue_t getFreeElement(store_address_t *storageId, size_t size, uint8_t **p_data) override;
|
||||
[[nodiscard]] bool hasDataAtId(store_address_t storeId) const override;
|
||||
void clearStore() override;
|
||||
void clearSubPool(uint8_t poolIndex) override;
|
||||
void getFillCount(uint8_t *buffer, uint8_t *bytesWritten) override;
|
||||
size_t getTotalSize(size_t *additionalSize) override;
|
||||
[[nodiscard]] max_subpools_t getNumberOfSubPools() const override;
|
||||
|
||||
std::pair<bool, ReturnValue_t> nextAddDataCallFails;
|
||||
/**
|
||||
* This can be used to make both the modify and get API call fail. This is because generally,
|
||||
* the pool implementation get functions will use the modify API internally.
|
||||
*/
|
||||
std::pair<bool, ReturnValue_t> nextModifyDataCallFails;
|
||||
std::pair<bool, ReturnValue_t> nextDeleteDataCallFails;
|
||||
std::pair<bool, ReturnValue_t> nextFreeElementCallFails;
|
||||
|
||||
using LocalPool::getFreeElement;
|
||||
using StorageManagerIF::getData;
|
||||
|
||||
void reset();
|
||||
};
|
||||
#endif // FSFW_TESTS_STORAGEMANAGERMOCK_H
|
90
unittests/mock/TestPoolOwner.cpp
Normal file
90
unittests/mock/TestPoolOwner.cpp
Normal file
@ -0,0 +1,90 @@
|
||||
#include "TestPoolOwner.h"
|
||||
|
||||
#include <fsfw/datapool/PoolReadGuard.h>
|
||||
|
||||
using namespace lpool;
|
||||
|
||||
TestPoolOwner::TestPoolOwner(MessageQueueIF &queue, MessageQueueId_t hkDestId, object_id_t objectId)
|
||||
: SystemObject(objectId),
|
||||
hkHelper(this, &queue, hkDestId),
|
||||
sharedPool(TestPoolOwner::getObjectId()),
|
||||
set1(sharedPool, lpool::testSetId1),
|
||||
set2(sharedPool, lpool::testSetId2),
|
||||
queue(queue) {}
|
||||
|
||||
TestPoolOwner::~TestPoolOwner() = default;
|
||||
|
||||
ReturnValue_t TestPoolOwner::initialize() {
|
||||
sharedPool.addPoolEntry(lpool::uint8VarId, &u8PoolEntry);
|
||||
sharedPool.addPoolEntry(lpool::floatVarId, &floatPoolEntry);
|
||||
sharedPool.addPoolEntry(lpool::uint32VarId, &u32PoolEntry);
|
||||
sharedPool.addPoolEntry(lpool::uint16Vec3Id, &u16VecPoolEntry);
|
||||
sharedPool.addPoolEntry(lpool::int64Vec2Id, &i64VecPoolEntry);
|
||||
ReturnValue_t result = hkHelper.initialize(&queue);
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
return SystemObject::initialize();
|
||||
}
|
||||
|
||||
SharedPool *TestPoolOwner::getOptionalSharedPool() { return &sharedPool; }
|
||||
|
||||
ReturnValue_t TestPoolOwner::serializeHkDataset(structure_id_t structureId, uint8_t *buf,
|
||||
size_t maxSize) {
|
||||
size_t dummy = 0;
|
||||
if (structureId == testSid0) {
|
||||
return set0.serialize(buf, dummy, maxSize, SerializeIF::Endianness::NETWORK);
|
||||
}
|
||||
if (structureId == testSid1) {
|
||||
return set1.serialize(buf, dummy, maxSize, SerializeIF::Endianness::NETWORK);
|
||||
}
|
||||
if (structureId == testSid2) {
|
||||
return set2.serialize(buf, dummy, maxSize, SerializeIF::Endianness::NETWORK);
|
||||
}
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
|
||||
ReturnValue_t TestPoolOwner::specifyHkDatasets(std::vector<hk::SetSpecification> &setList) {
|
||||
// For the first set, we explicitely associate a set with an ID ourselves.
|
||||
setList.emplace_back(testSid0, set0.getSerializedSize(), 50);
|
||||
// For the other sets, we can use getter functions of the same structure.
|
||||
setList.emplace_back(set1.getStructureId(), set1.getSerializedSize(), 50);
|
||||
setList.emplace_back(set2.getStructureId(), set2.getSerializedSize(), 50);
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t TestPoolOwner::reset() {
|
||||
ReturnValue_t status = returnvalue::OK;
|
||||
{
|
||||
PoolReadGuard readHelper(&set1);
|
||||
if (readHelper.getReadResult() != returnvalue::OK) {
|
||||
status = readHelper.getReadResult();
|
||||
}
|
||||
set1.localPoolVarUint8.value = 0;
|
||||
set1.localPoolVarFloat.value = 0.0;
|
||||
set1.localPoolUint16Vec.value[0] = 0;
|
||||
set1.localPoolUint16Vec.value[1] = 0;
|
||||
set1.localPoolUint16Vec.value[2] = 0;
|
||||
// dataset.setValidity(false, true);
|
||||
}
|
||||
|
||||
{
|
||||
PoolReadGuard readHelper(&testUint32);
|
||||
if (readHelper.getReadResult() != returnvalue::OK) {
|
||||
status = readHelper.getReadResult();
|
||||
}
|
||||
testUint32.value = 0;
|
||||
}
|
||||
|
||||
{
|
||||
PoolReadGuard readHelper(&testInt64Vec);
|
||||
if (readHelper.getReadResult() != returnvalue::OK) {
|
||||
status = readHelper.getReadResult();
|
||||
}
|
||||
testInt64Vec.value[0] = 0;
|
||||
testInt64Vec.value[1] = 0;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
void TestPoolOwner::setHkDestId(MessageQueueId_t id) { hkHelper.setHkDestinationId(id); }
|
66
unittests/mock/TestPoolOwner.h
Normal file
66
unittests/mock/TestPoolOwner.h
Normal file
@ -0,0 +1,66 @@
|
||||
#pragma once
|
||||
#include <fsfw/housekeeping/GeneratesPeriodicHkIF.h>
|
||||
#include <fsfw/housekeeping/PeriodicHkHelper.h>
|
||||
#include <fsfw/objectmanager/SystemObject.h>
|
||||
|
||||
#include "poolDefinitions.h"
|
||||
|
||||
namespace lpool {
|
||||
|
||||
class TestPoolOwner : public SystemObject, public hk::GeneratesPeriodicHkIF {
|
||||
public:
|
||||
explicit TestPoolOwner(MessageQueueIF& queue, MessageQueueId_t hkDestId,
|
||||
object_id_t objectId = objects::TEST_LOCAL_POOL_OWNER_BASE);
|
||||
|
||||
~TestPoolOwner() override;
|
||||
|
||||
[[nodiscard]] object_id_t getObjectId() const override { return SystemObject::getObjectId(); }
|
||||
|
||||
ReturnValue_t serializeHkDataset(structure_id_t structureId, uint8_t* buf,
|
||||
size_t maxSize) override;
|
||||
|
||||
ReturnValue_t specifyHkDatasets(std::vector<hk::SetSpecification>& setList) override;
|
||||
|
||||
SharedPool* getOptionalSharedPool() override;
|
||||
ReturnValue_t initialize() override;
|
||||
|
||||
void setHkDestId(MessageQueueId_t id);
|
||||
|
||||
/** Command queue for housekeeping messages. */
|
||||
[[nodiscard]] MessageQueueId_t getCommandQueue() const override { return queue.getId(); }
|
||||
|
||||
[[nodiscard]] MessageQueueMock& getMockQueueHandle() const {
|
||||
return dynamic_cast<MessageQueueMock&>(queue);
|
||||
}
|
||||
|
||||
ReturnValue_t enablePeriodicHk(dp::structure_id_t structureId, dur_millis_t frequencyMs) {
|
||||
return hkHelper.enablePeriodicPacket(structureId, frequencyMs);
|
||||
}
|
||||
|
||||
ReturnValue_t reset();
|
||||
|
||||
hk::PeriodicHelper hkHelper;
|
||||
SharedPool sharedPool;
|
||||
Dataset set0;
|
||||
StaticTestDataset set1;
|
||||
TestDataset set2;
|
||||
|
||||
private:
|
||||
PoolEntry<uint8_t> u8PoolEntry = PoolEntry<uint8_t>({0});
|
||||
PoolEntry<float> floatPoolEntry = PoolEntry<float>({0});
|
||||
PoolEntry<uint32_t> u32PoolEntry = PoolEntry<uint32_t>({0});
|
||||
PoolEntry<uint16_t> u16VecPoolEntry = PoolEntry<uint16_t>({0, 0, 0});
|
||||
PoolEntry<int64_t> i64VecPoolEntry = PoolEntry<int64_t>({0, 0});
|
||||
|
||||
dp::u8_t testUint8{sharedPool, lpool::uint8VarId};
|
||||
dp::f32_t testFloat{sharedPool, lpool::floatVarId};
|
||||
dp::u32_t testUint32{sharedPool, lpool::uint32VarId};
|
||||
vec_t<uint16_t, 3> testUint16Vec{sharedPool, lpool::uint16Vec3Id};
|
||||
vec_t<int64_t, 2> testInt64Vec{sharedPool, lpool::int64Vec2Id};
|
||||
|
||||
MessageQueueIF& queue;
|
||||
|
||||
bool initialized = false;
|
||||
bool initializedAfterTaskCreation = false;
|
||||
};
|
||||
} // namespace lpool
|
2
unittests/mock/cfdp/CMakeLists.txt
Normal file
2
unittests/mock/cfdp/CMakeLists.txt
Normal file
@ -0,0 +1,2 @@
|
||||
target_sources(${FSFW_TEST_TGT} PRIVATE FaultHandlerMock.cpp UserMock.cpp
|
||||
RemoteConfigTableMock.cpp)
|
42
unittests/mock/cfdp/FaultHandlerMock.cpp
Normal file
42
unittests/mock/cfdp/FaultHandlerMock.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
#include "FaultHandlerMock.h"
|
||||
|
||||
namespace cfdp {
|
||||
|
||||
void FaultHandlerMock::noticeOfSuspensionCb(TransactionId& id, cfdp::ConditionCode code) {
|
||||
auto& info = fhInfoMap.at(cfdp::FaultHandlerCode::NOTICE_OF_SUSPENSION);
|
||||
info.callCount++;
|
||||
info.condCodes.push(code);
|
||||
}
|
||||
|
||||
void FaultHandlerMock::noticeOfCancellationCb(TransactionId& id, cfdp::ConditionCode code) {
|
||||
auto& info = fhInfoMap.at(cfdp::FaultHandlerCode::NOTICE_OF_CANCELLATION);
|
||||
info.callCount++;
|
||||
info.condCodes.push(code);
|
||||
}
|
||||
|
||||
void FaultHandlerMock::abandonCb(TransactionId& id, cfdp::ConditionCode code) {
|
||||
auto& info = fhInfoMap.at(cfdp::FaultHandlerCode::ABANDON_TRANSACTION);
|
||||
info.callCount++;
|
||||
info.condCodes.push(code);
|
||||
}
|
||||
|
||||
void FaultHandlerMock::ignoreCb(TransactionId& id, cfdp::ConditionCode code) {
|
||||
auto& info = fhInfoMap.at(cfdp::FaultHandlerCode::IGNORE_ERROR);
|
||||
info.callCount++;
|
||||
info.condCodes.push(code);
|
||||
}
|
||||
|
||||
FaultHandlerMock::FaultInfo& FaultHandlerMock::getFhInfo(cfdp::FaultHandlerCode fhCode) {
|
||||
return fhInfoMap.at(fhCode);
|
||||
}
|
||||
|
||||
void FaultHandlerMock::reset() { fhInfoMap.clear(); }
|
||||
|
||||
bool FaultHandlerMock::faultCbWasCalled() const {
|
||||
return std::any_of(fhInfoMap.begin(), fhInfoMap.end(),
|
||||
[](const std::pair<cfdp::FaultHandlerCode, FaultInfo>& pair) {
|
||||
return pair.second.callCount > 0;
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace cfdp
|
37
unittests/mock/cfdp/FaultHandlerMock.h
Normal file
37
unittests/mock/cfdp/FaultHandlerMock.h
Normal file
@ -0,0 +1,37 @@
|
||||
#ifndef FSFW_TESTS_FAULTHANDLERMOCK_H
|
||||
#define FSFW_TESTS_FAULTHANDLERMOCK_H
|
||||
|
||||
#include <map>
|
||||
#include <queue>
|
||||
|
||||
#include "fsfw/cfdp/handler/FaultHandlerBase.h"
|
||||
|
||||
namespace cfdp {
|
||||
|
||||
class FaultHandlerMock : public FaultHandlerBase {
|
||||
public:
|
||||
struct FaultInfo {
|
||||
size_t callCount = 0;
|
||||
std::queue<cfdp::ConditionCode> condCodes;
|
||||
};
|
||||
|
||||
void noticeOfSuspensionCb(TransactionId& id, ConditionCode code) override;
|
||||
void noticeOfCancellationCb(TransactionId& id, ConditionCode code) override;
|
||||
void abandonCb(TransactionId& id, ConditionCode code) override;
|
||||
void ignoreCb(TransactionId& id, ConditionCode code) override;
|
||||
|
||||
FaultInfo& getFhInfo(FaultHandlerCode fhCode);
|
||||
[[nodiscard]] bool faultCbWasCalled() const;
|
||||
void reset();
|
||||
|
||||
private:
|
||||
std::map<cfdp::FaultHandlerCode, FaultInfo> fhInfoMap = {
|
||||
std::pair{cfdp::FaultHandlerCode::IGNORE_ERROR, FaultInfo()},
|
||||
std::pair{cfdp::FaultHandlerCode::NOTICE_OF_CANCELLATION, FaultInfo()},
|
||||
std::pair{cfdp::FaultHandlerCode::NOTICE_OF_SUSPENSION, FaultInfo()},
|
||||
std::pair{cfdp::FaultHandlerCode::ABANDON_TRANSACTION, FaultInfo()}};
|
||||
};
|
||||
|
||||
} // namespace cfdp
|
||||
|
||||
#endif // FSFW_TESTS_FAULTHANDLERMOCK_H
|
15
unittests/mock/cfdp/RemoteConfigTableMock.cpp
Normal file
15
unittests/mock/cfdp/RemoteConfigTableMock.cpp
Normal file
@ -0,0 +1,15 @@
|
||||
#include "RemoteConfigTableMock.h"
|
||||
|
||||
void cfdp::RemoteConfigTableMock::addRemoteConfig(const cfdp::RemoteEntityCfg& cfg) {
|
||||
remoteCfgTable.emplace(cfg.remoteId, cfg);
|
||||
}
|
||||
|
||||
bool cfdp::RemoteConfigTableMock::getRemoteCfg(const cfdp::EntityId& remoteId,
|
||||
cfdp::RemoteEntityCfg** cfg) {
|
||||
auto iter = remoteCfgTable.find(remoteId);
|
||||
if (iter == remoteCfgTable.end()) {
|
||||
return false;
|
||||
}
|
||||
*cfg = &iter->second;
|
||||
return true;
|
||||
}
|
20
unittests/mock/cfdp/RemoteConfigTableMock.h
Normal file
20
unittests/mock/cfdp/RemoteConfigTableMock.h
Normal file
@ -0,0 +1,20 @@
|
||||
#ifndef FSFW_TESTS_CFDP_REMOTCONFIGTABLEMOCK_H
|
||||
#define FSFW_TESTS_CFDP_REMOTCONFIGTABLEMOCK_H
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "fsfw/cfdp/handler/RemoteConfigTableIF.h"
|
||||
|
||||
namespace cfdp {
|
||||
|
||||
class RemoteConfigTableMock : public RemoteConfigTableIF {
|
||||
public:
|
||||
void addRemoteConfig(const RemoteEntityCfg& cfg);
|
||||
bool getRemoteCfg(const cfdp::EntityId& remoteId, cfdp::RemoteEntityCfg** cfg) override;
|
||||
|
||||
std::map<EntityId, RemoteEntityCfg> remoteCfgTable;
|
||||
};
|
||||
|
||||
} // namespace cfdp
|
||||
|
||||
#endif // FSFW_TESTS_CFDP_REMOTCONFIGTABLEMOCK_H
|
36
unittests/mock/cfdp/UserMock.cpp
Normal file
36
unittests/mock/cfdp/UserMock.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
#include "UserMock.h"
|
||||
|
||||
namespace cfdp {
|
||||
|
||||
cfdp::UserMock::UserMock(HasFileSystemIF& vfs) : UserBase(vfs) {}
|
||||
|
||||
void UserMock::transactionIndication(const TransactionId& id) { transactionIndicRecvd.emplace(id); }
|
||||
|
||||
void UserMock::eofSentIndication(const TransactionId& id) { eofSentRecvd.emplace(id); }
|
||||
void UserMock::abandonedIndication(const TransactionId& id, cfdp::ConditionCode code,
|
||||
uint64_t progress) {}
|
||||
|
||||
void UserMock::eofRecvIndication(const TransactionId& id) { eofRecvdRecvd.push(id); }
|
||||
|
||||
void UserMock::transactionFinishedIndication(const TransactionFinishedParams& finishedParams) {
|
||||
finishedRecvd.emplace(finishedParams.id, finishedParams);
|
||||
}
|
||||
|
||||
void UserMock::metadataRecvdIndication(const MetadataRecvdParams& params) {
|
||||
metadataRecvd.emplace(params.id, params);
|
||||
}
|
||||
|
||||
void UserMock::fileSegmentRecvdIndication(const FileSegmentRecvdParams& params) {}
|
||||
void UserMock::reportIndication(const TransactionId& id, StatusReportIF& report) {}
|
||||
void UserMock::suspendedIndication(const TransactionId& id, ConditionCode code) {}
|
||||
void UserMock::resumedIndication(const TransactionId& id, size_t progress) {}
|
||||
void UserMock::faultIndication(const TransactionId& id, cfdp::ConditionCode code, size_t progress) {
|
||||
}
|
||||
|
||||
void UserMock::reset() {
|
||||
std::queue<TransactionId>().swap(eofRecvdRecvd);
|
||||
std::queue<std::pair<TransactionId, cfdp::MetadataRecvdParams>>().swap(metadataRecvd);
|
||||
std::queue<std::pair<TransactionId, cfdp::TransactionFinishedParams>>().swap(finishedRecvd);
|
||||
}
|
||||
|
||||
} // namespace cfdp
|
36
unittests/mock/cfdp/UserMock.h
Normal file
36
unittests/mock/cfdp/UserMock.h
Normal file
@ -0,0 +1,36 @@
|
||||
#ifndef FSFW_TESTS_CFDP_USERMOCK_H
|
||||
#define FSFW_TESTS_CFDP_USERMOCK_H
|
||||
|
||||
#include <queue>
|
||||
|
||||
#include "fsfw/cfdp/handler/UserBase.h"
|
||||
|
||||
namespace cfdp {
|
||||
|
||||
class UserMock : public UserBase {
|
||||
public:
|
||||
explicit UserMock(HasFileSystemIF& vfs);
|
||||
|
||||
void transactionIndication(const TransactionId& id) override;
|
||||
void eofSentIndication(const TransactionId& id) override;
|
||||
void abandonedIndication(const TransactionId& id, ConditionCode code, size_t progress) override;
|
||||
void eofRecvIndication(const TransactionId& id) override;
|
||||
void transactionFinishedIndication(const TransactionFinishedParams& params) override;
|
||||
void metadataRecvdIndication(const MetadataRecvdParams& params) override;
|
||||
void fileSegmentRecvdIndication(const FileSegmentRecvdParams& params) override;
|
||||
void reportIndication(const TransactionId& id, StatusReportIF& report) override;
|
||||
void suspendedIndication(const TransactionId& id, ConditionCode code) override;
|
||||
void resumedIndication(const TransactionId& id, size_t progress) override;
|
||||
void faultIndication(const TransactionId& id, ConditionCode code, size_t progress) override;
|
||||
|
||||
std::queue<TransactionId> transactionIndicRecvd;
|
||||
std::queue<std::pair<TransactionId, MetadataRecvdParams>> metadataRecvd;
|
||||
std::queue<TransactionId> eofRecvdRecvd;
|
||||
std::queue<TransactionId> eofSentRecvd;
|
||||
std::queue<std::pair<TransactionId, TransactionFinishedParams>> finishedRecvd;
|
||||
void reset();
|
||||
};
|
||||
|
||||
} // namespace cfdp
|
||||
|
||||
#endif // FSFW_TESTS_CFDP_USERMOCK_H
|
74
unittests/mock/poolDefinitions.h
Normal file
74
unittests/mock/poolDefinitions.h
Normal file
@ -0,0 +1,74 @@
|
||||
#pragma once
|
||||
|
||||
#include <fsfw/datapool.h>
|
||||
#include <fsfw/ipc/QueueFactory.h>
|
||||
#include <fsfw/objectmanager/SystemObject.h>
|
||||
#include <fsfw/serialize/SerializableList.h>
|
||||
#include <fsfw/serialize/SerializableListElement.h>
|
||||
|
||||
#include "fsfw/datapool/PoolEntry.h"
|
||||
#include "mock/MessageQueueMock.h"
|
||||
#include "tests/TestsConfig.h"
|
||||
|
||||
namespace lpool {
|
||||
|
||||
using namespace dp;
|
||||
using namespace serialize;
|
||||
|
||||
static constexpr id_t uint8VarId = 0;
|
||||
static constexpr id_t floatVarId = 1;
|
||||
static constexpr id_t uint32VarId = 2;
|
||||
static constexpr id_t uint16Vec3Id = 3;
|
||||
static constexpr id_t int64Vec2Id = 4;
|
||||
|
||||
static constexpr uint32_t testSetId0 = 0;
|
||||
static constexpr uint32_t testSetId1 = 1;
|
||||
static constexpr uint32_t testSetId2 = 2;
|
||||
static constexpr uint8_t dataSetMaxVariables = 10;
|
||||
|
||||
static constexpr auto testSid0 = structure_id_t(objects::TEST_LOCAL_POOL_OWNER_BASE, testSetId0);
|
||||
static constexpr auto testSid1 = structure_id_t(objects::TEST_LOCAL_POOL_OWNER_BASE, testSetId1);
|
||||
static constexpr auto testSid2 = structure_id_t(objects::TEST_LOCAL_POOL_OWNER_BASE, testSetId2);
|
||||
|
||||
static const g_id_t uint8VarGpid = g_id_t(objects::TEST_LOCAL_POOL_OWNER_BASE, uint8VarId);
|
||||
static const g_id_t floatVarGpid = g_id_t(objects::TEST_LOCAL_POOL_OWNER_BASE, floatVarId);
|
||||
static const g_id_t uint32Gpid = g_id_t(objects::TEST_LOCAL_POOL_OWNER_BASE, uint32VarId);
|
||||
static const g_id_t uint16Vec3Gpid = g_id_t(objects::TEST_LOCAL_POOL_OWNER_BASE, uint16Vec3Id);
|
||||
static const g_id_t uint64Vec2Id = g_id_t(objects::TEST_LOCAL_POOL_OWNER_BASE, int64Vec2Id);
|
||||
|
||||
class Dataset : public List {
|
||||
public:
|
||||
LVar<uint8_t> u8Element{*this};
|
||||
LVar<uint16_t> u16Element{*this};
|
||||
LVec<float, 3> floatVec{*this};
|
||||
};
|
||||
|
||||
class StaticTestDataset : public StaticSharedSet<3> {
|
||||
public:
|
||||
StaticTestDataset() : StaticSharedSet(lpool::testSid1, false) {}
|
||||
|
||||
StaticTestDataset(SharedPool& sharedPool, uint32_t setId)
|
||||
: StaticSharedSet(sharedPool, setId, false) {}
|
||||
|
||||
u8_t localPoolVarUint8{lpool::uint8VarGpid, this};
|
||||
f32_t localPoolVarFloat{lpool::floatVarGpid, this};
|
||||
vec_t<uint16_t, 3> localPoolUint16Vec{lpool::uint16Vec3Gpid, this};
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
class TestDataset : public SharedSet {
|
||||
public:
|
||||
TestDataset() : SharedSet(lpool::testSid2, lpool::dataSetMaxVariables, false) {}
|
||||
|
||||
TestDataset(SharedPool& sharedPool, uint32_t setId)
|
||||
: SharedSet(sharedPool, setId, lpool::dataSetMaxVariables, false) {}
|
||||
|
||||
u8_t localPoolVarUint8{lpool::uint8VarGpid, this};
|
||||
f32_t localPoolVarFloat{lpool::floatVarGpid, this};
|
||||
vec_t<uint16_t, 3> localPoolUint16Vec{lpool::uint16Vec3Gpid, this};
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
} // namespace lpool
|
Reference in New Issue
Block a user