fnished PUS TC creator unittests
This commit is contained in:
@ -1,8 +1,4 @@
|
||||
target_sources(${FSFW_TEST_TGT} PRIVATE
|
||||
CookieIFMock.cpp
|
||||
ComIFMock.cpp
|
||||
DeviceHandlerCommander.cpp
|
||||
DeviceHandlerMock.cpp
|
||||
DeviceFdirMock.cpp
|
||||
TestDeviceHandlerBase.cpp
|
||||
)
|
||||
|
@ -1,46 +0,0 @@
|
||||
#include "ComIFMock.h"
|
||||
|
||||
#include "DeviceHandlerMock.h"
|
||||
|
||||
ComIFMock::ComIFMock(object_id_t objectId) : SystemObject(objectId) {}
|
||||
|
||||
ComIFMock::~ComIFMock() {}
|
||||
|
||||
ReturnValue_t ComIFMock::initializeInterface(CookieIF *cookie) { return RETURN_OK; }
|
||||
|
||||
ReturnValue_t ComIFMock::sendMessage(CookieIF *cookie, const uint8_t *sendData, size_t sendLen) {
|
||||
data = *sendData;
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t ComIFMock::getSendSuccess(CookieIF *cookie) { return RETURN_OK; }
|
||||
|
||||
ReturnValue_t ComIFMock::requestReceiveMessage(CookieIF *cookie, size_t requestLen) {
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t ComIFMock::readReceivedMessage(CookieIF *cookie, uint8_t **buffer, size_t *size) {
|
||||
switch (testCase) {
|
||||
case TestCase::MISSED_REPLY: {
|
||||
*size = 0;
|
||||
return RETURN_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 RETURN_OK;
|
||||
}
|
||||
|
||||
void ComIFMock::setTestCase(TestCase testCase_) { testCase = testCase_; }
|
@ -1,37 +0,0 @@
|
||||
#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_ */
|
@ -1,5 +0,0 @@
|
||||
#include "CookieIFMock.h"
|
||||
|
||||
CookieIFMock::CookieIFMock() {}
|
||||
|
||||
CookieIFMock::~CookieIFMock() {}
|
@ -1,12 +0,0 @@
|
||||
#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_ */
|
@ -1,18 +0,0 @@
|
||||
#include "DeviceFdirMock.h"
|
||||
|
||||
#include "devicehandler/DeviceFdirMock.h"
|
||||
|
||||
DeviceFdirMock::DeviceFdirMock(object_id_t owner, object_id_t parent)
|
||||
: DeviceHandlerFailureIsolation(owner, parent) {}
|
||||
|
||||
DeviceFdirMock::~DeviceFdirMock() {}
|
||||
|
||||
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;
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
#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_ */
|
@ -1,103 +0,0 @@
|
||||
#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) {
|
||||
mode = MODE_ON;
|
||||
}
|
||||
|
||||
DeviceHandlerMock::~DeviceHandlerMock() {}
|
||||
|
||||
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 RETURN_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 RETURN_OK;
|
||||
break;
|
||||
}
|
||||
case PERIODIC_REPLY_DATA: {
|
||||
*foundId = PERIODIC_REPLY;
|
||||
*foundLen = sizeof(PERIODIC_REPLY_DATA);
|
||||
return RETURN_OK;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return RETURN_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 RETURN_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() { return periodicReplyReceived; }
|
||||
|
||||
ReturnValue_t DeviceHandlerMock::enablePeriodicReply(DeviceCommandId_t replyId) {
|
||||
return updatePeriodicReply(true, replyId);
|
||||
}
|
||||
|
||||
ReturnValue_t DeviceHandlerMock::disablePeriodicReply(DeviceCommandId_t replyId) {
|
||||
return updatePeriodicReply(false, replyId);
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
#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 const DeviceCommandId_t SIMPLE_COMMAND = 1;
|
||||
static const DeviceCommandId_t PERIODIC_REPLY = 2;
|
||||
|
||||
static const uint8_t SIMPLE_COMMAND_DATA = 1;
|
||||
static const uint8_t PERIODIC_REPLY_DATA = 2;
|
||||
|
||||
DeviceHandlerMock(object_id_t objectId, object_id_t deviceCommunication, CookieIF *comCookie,
|
||||
FailureIsolationBase *fdirInstance);
|
||||
virtual ~DeviceHandlerMock();
|
||||
void changePeriodicReplyCountdown(uint32_t timeout);
|
||||
void changeSimpleCommandReplyCountdown(uint32_t timeout);
|
||||
void resetPeriodicReplyState();
|
||||
bool getPeriodicReplyReceived();
|
||||
ReturnValue_t enablePeriodicReply(DeviceCommandId_t replyId);
|
||||
ReturnValue_t disablePeriodicReply(DeviceCommandId_t replyId);
|
||||
|
||||
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_ */
|
@ -1,10 +1,10 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "ComIFMock.h"
|
||||
#include "DeviceFdirMock.h"
|
||||
#include "DeviceHandlerCommander.h"
|
||||
#include "DeviceHandlerMock.h"
|
||||
#include "devicehandler/CookieIFMock.h"
|
||||
#include "mocks/ComIFMock.h"
|
||||
#include "mocks/CookieIFMock.h"
|
||||
#include "mocks/DeviceFdirMock.h"
|
||||
#include "mocks/DeviceHandlerMock.h"
|
||||
#include "objects/systemObjectList.h"
|
||||
|
||||
TEST_CASE("Device Handler Base", "[DeviceHandlerBase]") {
|
||||
|
Reference in New Issue
Block a user