unit test for dhb
This commit is contained in:
parent
1611a4e1f0
commit
bf673c56c6
@ -65,7 +65,9 @@ void DeviceHandlerBase::setThermalStateRequestPoolIds(lp_id_t thermalStatePoolId
|
||||
}
|
||||
|
||||
DeviceHandlerBase::~DeviceHandlerBase() {
|
||||
delete comCookie;
|
||||
if (comCookie != nullptr) {
|
||||
delete comCookie;
|
||||
}
|
||||
if (defaultFDIRUsed) {
|
||||
delete fdirInstance;
|
||||
}
|
||||
@ -253,7 +255,9 @@ void DeviceHandlerBase::decrementDeviceReplyMap() {
|
||||
replyToReply(replyPair.first, replyPair.second, TIMEOUT);
|
||||
missedReply(replyPair.first);
|
||||
timedOut = false;
|
||||
replyPair.second.active = false;
|
||||
if (not replyPair.second.periodic) {
|
||||
replyPair.second.active = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -88,6 +88,11 @@ ReturnValue_t EventManager::subscribeToEventRange(MessageQueueId_t listener, Eve
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t EventManager::unsubscribeFromAllEvents(MessageQueueId_t listener,
|
||||
object_id_t object) {
|
||||
return unsubscribeFromEventRange(listener, 0, 0, true, object);
|
||||
}
|
||||
|
||||
ReturnValue_t EventManager::unsubscribeFromEventRange(MessageQueueId_t listener, EventId_t idFrom,
|
||||
EventId_t idTo, bool idInverted,
|
||||
object_id_t reporterFrom,
|
||||
|
@ -37,6 +37,8 @@ class EventManager : public EventManagerIF, public ExecutableObjectIF, public Sy
|
||||
EventId_t idTo = 0, bool idInverted = false,
|
||||
object_id_t reporterFrom = 0, object_id_t reporterTo = 0,
|
||||
bool reporterInverted = false);
|
||||
ReturnValue_t unsubscribeFromAllEvents(MessageQueueId_t listener,
|
||||
object_id_t object);
|
||||
ReturnValue_t unsubscribeFromEventRange(MessageQueueId_t listener, EventId_t idFrom = 0,
|
||||
EventId_t idTo = 0, bool idInverted = false,
|
||||
object_id_t reporterFrom = 0, object_id_t reporterTo = 0,
|
||||
|
@ -20,6 +20,8 @@ class EventManagerIF {
|
||||
bool forwardAllButSelected = false) = 0;
|
||||
virtual ReturnValue_t subscribeToEvent(MessageQueueId_t listener, EventId_t event) = 0;
|
||||
virtual ReturnValue_t subscribeToAllEventsFrom(MessageQueueId_t listener, object_id_t object) = 0;
|
||||
virtual ReturnValue_t unsubscribeFromAllEvents(MessageQueueId_t listener,
|
||||
object_id_t object) = 0;
|
||||
virtual ReturnValue_t subscribeToEventRange(MessageQueueId_t listener, EventId_t idFrom = 0,
|
||||
EventId_t idTo = 0, bool idInverted = false,
|
||||
object_id_t reporterFrom = 0,
|
||||
|
@ -14,7 +14,17 @@ FailureIsolationBase::FailureIsolationBase(object_id_t owner, object_id_t parent
|
||||
}
|
||||
|
||||
FailureIsolationBase::~FailureIsolationBase() {
|
||||
QueueFactory::instance()->deleteMessageQueue(eventQueue);
|
||||
EventManagerIF* manager = ObjectManager::instance()->get<EventManagerIF>(objects::EVENT_MANAGER);
|
||||
if (manager == nullptr) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "FailureIsolationBase::~FailureIsolationBase: Event Manager has not"
|
||||
" been initialized!"
|
||||
<< std::endl;
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
manager->unsubscribeFromAllEvents(eventQueue->getId(), ownerId);
|
||||
QueueFactory::instance()->deleteMessageQueue(eventQueue);
|
||||
}
|
||||
|
||||
ReturnValue_t FailureIsolationBase::initialize() {
|
||||
|
@ -60,14 +60,14 @@ ReturnValue_t FaultCounter::getParameter(uint8_t domainId, uint8_t uniqueId,
|
||||
return INVALID_DOMAIN_ID;
|
||||
}
|
||||
|
||||
switch (uniqueId) {
|
||||
case 0:
|
||||
switch (static_cast<ParameterIds>(uniqueId)) {
|
||||
case ParameterIds::FAILURE_THRESHOLD:
|
||||
parameterWrapper->set(failureThreshold);
|
||||
break;
|
||||
case 1:
|
||||
case ParameterIds::FAULT_COUNT:
|
||||
parameterWrapper->set(faultCount);
|
||||
break;
|
||||
case 2:
|
||||
case ParameterIds::TIMEOUT:
|
||||
parameterWrapper->set(timer.timeout);
|
||||
break;
|
||||
default:
|
||||
|
@ -6,6 +6,13 @@
|
||||
|
||||
class FaultCounter : public HasParametersIF {
|
||||
public:
|
||||
|
||||
enum class ParameterIds {
|
||||
FAILURE_THRESHOLD,
|
||||
FAULT_COUNT,
|
||||
TIMEOUT
|
||||
};
|
||||
|
||||
FaultCounter();
|
||||
FaultCounter(uint32_t failureThreshold, uint32_t decrementAfterMs,
|
||||
uint8_t setParameterDomain = 0);
|
||||
@ -23,9 +30,10 @@ class FaultCounter : public HasParametersIF {
|
||||
void setFailureThreshold(uint32_t failureThreshold);
|
||||
void setFaultDecrementTimeMs(uint32_t timeMs);
|
||||
|
||||
virtual ReturnValue_t getParameter(uint8_t domainId, uint8_t uniqueId,
|
||||
ParameterWrapper *parameterWrapper,
|
||||
const ParameterWrapper *newValues, uint16_t startAtIndex);
|
||||
virtual ReturnValue_t getParameter(uint8_t domainId, uint8_t uniqueId,
|
||||
ParameterWrapper *parameterWrapper,
|
||||
const ParameterWrapper *newValues = nullptr, uint16_t startAtIndex =
|
||||
0);
|
||||
|
||||
void setParameterDomain(uint8_t domain);
|
||||
|
||||
|
@ -5,7 +5,9 @@
|
||||
HealthHelper::HealthHelper(HasHealthIF* owner, object_id_t objectId)
|
||||
: objectId(objectId), owner(owner) {}
|
||||
|
||||
HealthHelper::~HealthHelper() {}
|
||||
HealthHelper::~HealthHelper() {
|
||||
healthTable->removeObject(objectId);
|
||||
}
|
||||
|
||||
ReturnValue_t HealthHelper::handleHealthCommand(CommandMessage* message) {
|
||||
switch (message->getCommand()) {
|
||||
|
@ -27,6 +27,15 @@ ReturnValue_t HealthTable::registerObject(object_id_t object,
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t HealthTable::removeObject(object_id_t object) {
|
||||
mapIterator = healthMap.find(object);
|
||||
if (mapIterator == healthMap.end()) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
healthMap.erase(mapIterator);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void HealthTable::setHealth(object_id_t object, HasHealthIF::HealthState newState) {
|
||||
MutexGuard(mutex, timeoutType, mutexTimeoutMs);
|
||||
HealthMap::iterator iter = healthMap.find(object);
|
||||
|
@ -17,6 +17,7 @@ class HealthTable : public HealthTableIF, public SystemObject {
|
||||
/** HealthTableIF overrides */
|
||||
virtual ReturnValue_t registerObject(
|
||||
object_id_t object, HasHealthIF::HealthState initilialState = HasHealthIF::HEALTHY) override;
|
||||
ReturnValue_t removeObject(object_id_t object) override;
|
||||
virtual size_t getPrintSize() override;
|
||||
virtual void printAll(uint8_t* pointer, size_t maxSize) override;
|
||||
|
||||
|
@ -14,6 +14,8 @@ class HealthTableIF : public ManagesHealthIF {
|
||||
virtual ReturnValue_t registerObject(
|
||||
object_id_t object, HasHealthIF::HealthState initilialState = HasHealthIF::HEALTHY) = 0;
|
||||
|
||||
virtual ReturnValue_t removeObject(object_id_t objectId) = 0;
|
||||
|
||||
virtual size_t getPrintSize() = 0;
|
||||
virtual void printAll(uint8_t *pointer, size_t maxSize) = 0;
|
||||
|
||||
|
@ -23,3 +23,4 @@ add_subdirectory(tmtcpacket)
|
||||
add_subdirectory(cfdp)
|
||||
add_subdirectory(hal)
|
||||
add_subdirectory(internalerror)
|
||||
add_subdirectory(devicehandler)
|
||||
|
@ -65,7 +65,7 @@ void Factory::setStaticFrameworkObjectIds() {
|
||||
VerificationReporter::messageReceiver = objects::PUS_SERVICE_1_VERIFICATION;
|
||||
|
||||
DeviceHandlerBase::powerSwitcherId = objects::NO_OBJECT;
|
||||
DeviceHandlerBase::rawDataReceiverId = objects::PUS_SERVICE_2_DEVICE_ACCESS;
|
||||
DeviceHandlerBase::rawDataReceiverId = objects::NO_OBJECT;
|
||||
|
||||
LocalDataPoolManager::defaultHkDestination = objects::HK_RECEIVER_MOCK;
|
||||
|
||||
|
@ -1,13 +1,14 @@
|
||||
#include "ComIFMock.h"
|
||||
#include "DeviceHandlerMock.h"
|
||||
|
||||
ComIFMock::ComIFMock(obejct_id_t objectId) {}
|
||||
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) {
|
||||
rememberSentByte = *sendData;
|
||||
data = *sendData;
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
@ -18,7 +19,29 @@ ReturnValue_t ComIFMock::requestReceiveMessage(CookieIF *cookie, size_t requestL
|
||||
}
|
||||
|
||||
ReturnValue_t ComIFMock::readReceivedMessage(CookieIF *cookie, uint8_t **buffer, size_t *size) {
|
||||
*size = sizeof(rememberSentByte);
|
||||
*buffer = &rememberSentByte;
|
||||
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_;
|
||||
}
|
||||
|
@ -2,14 +2,17 @@
|
||||
#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.
|
||||
* like incomplete or wrong replies and can be used to test the DeviceHandlerBase.
|
||||
*/
|
||||
class ComIFMock : public DeviceCommunicationIF, public SystemObject {
|
||||
public:
|
||||
ComIFMock(obejct_id_t objectId);
|
||||
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;
|
||||
@ -19,9 +22,15 @@ class ComIFMock : public DeviceCommunicationIF, public SystemObject {
|
||||
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:
|
||||
uint8_t rememberSentByte = 0;
|
||||
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_ */
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
#include "fsfw/devicehandlers/CookieIF.h"
|
||||
|
||||
class CookieIFMock {
|
||||
class CookieIFMock : public CookieIF {
|
||||
public:
|
||||
CookieIFMock();
|
||||
virtual ~CookieIFMock();
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "DeviceHandlerCommander.h"
|
||||
#include <fsfw/ipc/QueueFactory.h>
|
||||
|
||||
DeviceHandlerCommander::DeviceHandlerCommander(object_id_t objectId)
|
||||
: SystemObject(objectId), commandActionHelper(this) {
|
||||
@ -11,6 +12,7 @@ DeviceHandlerCommander::~DeviceHandlerCommander() {}
|
||||
|
||||
ReturnValue_t DeviceHandlerCommander::performOperation(uint8_t operationCode) {
|
||||
readCommandQueue();
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t DeviceHandlerCommander::initialize() {
|
||||
@ -18,10 +20,6 @@ ReturnValue_t DeviceHandlerCommander::initialize() {
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
result = actionHelper.initialize(commandQueue);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
@ -49,9 +47,6 @@ void DeviceHandlerCommander::readCommandQueue() {
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
for (result = commandQueue->receiveMessage(&message); result == HasReturnvaluesIF::RETURN_OK;
|
||||
result = commandQueue->receiveMessage(&message)) {
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
continue;
|
||||
}
|
||||
result = commandActionHelper.handleReply(&message);
|
||||
if (result == HasReturnvaluesIF::RETURN_OK) {
|
||||
continue;
|
||||
|
@ -37,6 +37,8 @@ class DeviceHandlerCommander : public ExecutableObjectIF,
|
||||
|
||||
private:
|
||||
|
||||
static const uint32_t QUEUE_SIZE = 20;
|
||||
|
||||
MessageQueueIF* commandQueue = nullptr;
|
||||
|
||||
CommandActionHelper commandActionHelper;
|
||||
|
@ -1,18 +1,18 @@
|
||||
#include "DeviceHandlerMock.h"
|
||||
|
||||
DeviceHandlerMock::DeviceHandlerMock(object_id_t objectId, object_id_t deviceCommunication)
|
||||
: DeviceHandlerBase(objetcId, deviceCommunication, nullptr) {}
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
DeviceHandlerMock::~DeviceHandlerMock() {
|
||||
DeviceHandlerMock::DeviceHandlerMock(object_id_t objectId, object_id_t deviceCommunication,
|
||||
CookieIF *comCookie, FailureIsolationBase *fdirInstance)
|
||||
: DeviceHandlerBase(objectId, deviceCommunication, comCookie, fdirInstance) {
|
||||
mode = MODE_ON;
|
||||
}
|
||||
|
||||
void DeviceHandlerMock::doStartup() {
|
||||
setMode(_MODE_TO_ON);
|
||||
}
|
||||
DeviceHandlerMock::~DeviceHandlerMock() {}
|
||||
|
||||
void DeviceHandlerMock::doShutdown() {
|
||||
setMode(_MODE_POWER_DOWN);
|
||||
}
|
||||
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;
|
||||
@ -25,22 +25,32 @@ ReturnValue_t DeviceHandlerMock::buildTransitionDeviceCommand(DeviceCommandId_t
|
||||
ReturnValue_t DeviceHandlerMock::buildCommandFromCommand(DeviceCommandId_t deviceCommand,
|
||||
const uint8_t *commandData,
|
||||
size_t commandDataLen) {
|
||||
switch(deviceCommand) {
|
||||
case PERIODIC_REPLY_TEST_COMMAND: {
|
||||
commandBuffer[0] = periodicReplyTestData;
|
||||
switch (deviceCommand) {
|
||||
case SIMPLE_COMMAND: {
|
||||
commandBuffer[0] = SIMPLE_COMMAND_DATA;
|
||||
rawPacket = commandBuffer;
|
||||
rawPacketLen = sizeof(periodicReplyTestData);
|
||||
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 periodicReplyTestData: {
|
||||
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;
|
||||
}
|
||||
@ -51,20 +61,35 @@ ReturnValue_t DeviceHandlerMock::scanForReply(const uint8_t *start, size_t len,
|
||||
}
|
||||
|
||||
ReturnValue_t DeviceHandlerMock::interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) {
|
||||
switch(id){
|
||||
case PERIODIC_REPLY_TEST_COMMAND:
|
||||
switch (id) {
|
||||
case SIMPLE_COMMAND:
|
||||
case PERIODIC_REPLY: {
|
||||
periodicReplyReceived = true;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
void DeviceHandlerMock::fillCommandAndReplyMap() {
|
||||
insertInCommandAndReplyMap(PERIODIC_REPLY_TEST_COMMAND, 2, nullptr, 0, true, false, 0,
|
||||
periodicReplyCountdown);
|
||||
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;
|
||||
uint32_t DeviceHandlerMock::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) { return 500; }
|
||||
|
||||
void DeviceHandlerMock::changePeriodicReplyCountdown(uint32_t timeout) {
|
||||
periodicReplyCountdown.setTimeout(0);
|
||||
}
|
||||
|
||||
void DeviceHandlerMock::resetPeriodicReplyState() {
|
||||
periodicReplyReceived = false;
|
||||
}
|
||||
|
||||
bool DeviceHandlerMock::getPeriodicReplyReceived() {
|
||||
return periodicReplyReceived;
|
||||
}
|
||||
|
@ -3,34 +3,44 @@
|
||||
|
||||
#include <fsfw/devicehandlers/DeviceHandlerBase.h>
|
||||
|
||||
class DeviceHandlerMock : public DeviceHandlerBase {
|
||||
public:
|
||||
class DeviceHandlerMock: public DeviceHandlerBase {
|
||||
public:
|
||||
|
||||
static const DeviceCommandId_t PERIODIC_REPLY_TEST_COMMAND = 1;
|
||||
static const DeviceCommandId_t SIMPLE_COMMAND = 1;
|
||||
static const DeviceCommandId_t PERIODIC_REPLY = 2;
|
||||
|
||||
DeviceHandlerMock(object_id_t objectId, object_id_t deviceCommunication);
|
||||
virtual ~DeviceHandlerMock();
|
||||
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 resetPeriodicReplyState();
|
||||
bool getPeriodicReplyReceived();
|
||||
|
||||
protected:
|
||||
void doStartUp() override;
|
||||
void doStartShutdown() 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;
|
||||
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:
|
||||
|
||||
uint8_t periodicReplyTestData = 1;
|
||||
Countdown simpleCommandReplyTimeout = Countdown(50);
|
||||
Countdown periodicReplyCountdown = Countdown(10);
|
||||
|
||||
Countdown periodicReplyCountdown = Countdown(10);
|
||||
uint8_t commandBuffer[1];
|
||||
|
||||
uint8_t commandBuffer[1];
|
||||
bool periodicReplyReceived = false;
|
||||
};
|
||||
|
||||
#endif /* TESTS_SRC_FSFW_TESTS_UNIT_DEVICEHANDLER_DEVICEHANDLERMOCK_H_ */
|
||||
|
@ -1,36 +1,61 @@
|
||||
#include "TestDeviceHandlerBase.h"
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include "ComIFMock.h"
|
||||
|
||||
#include "fsfw_tests/unit/devicehandler/DeviceHandlerMock.h"
|
||||
#include "fsfw_tests/unit/devicehandler/DeviceHandlerCommander.h"
|
||||
#include "ComIFMock.h"
|
||||
#include "DeviceFdirMock.h"
|
||||
#include "fsfw_tests/unit/devicehandler/CookieIFMock.h"
|
||||
#include "fsfw_tests/unit/devicehandler/DeviceHandlerCommander.h"
|
||||
#include "fsfw_tests/unit/devicehandler/DeviceHandlerMock.h"
|
||||
#include "fsfw_tests/unit/testcfg/objects/systemObjectList.h"
|
||||
|
||||
TEST_CASE("Device Handler Base", "[DeviceHandlerBase]") {
|
||||
|
||||
SECTION("Periodic reply with countdown based timeout success") {
|
||||
CookieIFMock cookieIFMock;
|
||||
ComIFperiodicMock comIFperiodic(objects::COM_IF_MOCK);
|
||||
DeviceHandlerMock deviceHandlerMock(objects::DEVICE_HANDLER_MOCK, objects::COM_IF_MOCK,
|
||||
&cookieIFMock);
|
||||
ReturnValue_t result = deviceHandlerMock.initialize();
|
||||
REQUIRE(result == RETURN_OK);
|
||||
DeviceHandlerCommander deviceHandlerCommander(objects::DEVICE_HANDLER_COMMANDER);
|
||||
result = deviceHandlerCommander.initialize();
|
||||
REQUIRE(result == RETURN_OK);
|
||||
// Will be deleted with DHB destructor
|
||||
CookieIFMock* cookieIFMock = new CookieIFMock;
|
||||
ComIFMock comIF(objects::COM_IF_MOCK);
|
||||
DeviceFdirMock deviceFdirMock(objects::DEVICE_HANDLER_MOCK, objects::NO_OBJECT);
|
||||
DeviceHandlerMock deviceHandlerMock(objects::DEVICE_HANDLER_MOCK, objects::COM_IF_MOCK,
|
||||
cookieIFMock, &deviceFdirMock);
|
||||
ReturnValue_t result = deviceHandlerMock.initialize();
|
||||
REQUIRE(result == HasReturnvaluesIF::RETURN_OK);
|
||||
DeviceHandlerCommander deviceHandlerCommander(objects::DEVICE_HANDLER_COMMANDER);
|
||||
result = deviceHandlerCommander.initialize();
|
||||
REQUIRE(result == HasReturnvaluesIF::RETURN_OK);
|
||||
|
||||
SECTION("Commanding") {
|
||||
comIF.setTestCase(ComIFMock::TestCase::SIMPLE_COMMAND_NOMINAL);
|
||||
result = deviceHandlerCommander.sendCommand(objects::DEVICE_HANDLER_MOCK,
|
||||
DeviceHandlerMock::PERIODIC_REPLY_TEST_COMMAND);
|
||||
DeviceHandlerMock::SIMPLE_COMMAND);
|
||||
REQUIRE(result == HasReturnvaluesIF::RETURN_OK);
|
||||
deviceHandlerMock.performOperation(DeviceHandlerIF::PERFORM_OPERATION);
|
||||
deviceHandlerMock.performOperation(DeviceHandlerIF::SEND_WRITE);
|
||||
deviceHandlerMock.performOperation(DeviceHandlerIF::GET_WRITE);
|
||||
deviceHandlerMock.performOperation(DeviceHandlerIF::SEND_READ);
|
||||
deviceHandlerMock.performOperation(DeviceHandlerIF::GET_READ);
|
||||
deviceHandlerCommander.performOperation();
|
||||
result = deviceHandlerCommander.getReplyReturnCode();
|
||||
REQUIRE(result == RETURN_OK);
|
||||
REQUIRE(result == HasReturnvaluesIF::RETURN_OK);
|
||||
}
|
||||
|
||||
SECTION("Periodic reply") {
|
||||
comIF.setTestCase(ComIFMock::TestCase::PERIODIC_REPLY_NOMINAL);
|
||||
deviceHandlerMock.performOperation(DeviceHandlerIF::PERFORM_OPERATION);
|
||||
deviceHandlerMock.performOperation(DeviceHandlerIF::SEND_WRITE);
|
||||
deviceHandlerMock.performOperation(DeviceHandlerIF::GET_WRITE);
|
||||
deviceHandlerMock.performOperation(DeviceHandlerIF::SEND_READ);
|
||||
deviceHandlerMock.performOperation(DeviceHandlerIF::GET_READ);
|
||||
REQUIRE(deviceHandlerMock.getPeriodicReplyReceived() == true);
|
||||
}
|
||||
|
||||
SECTION("Missed periodic reply") {
|
||||
comIF.setTestCase(ComIFMock::TestCase::MISSED_REPLY);
|
||||
// Set the timeout to 0 to immediately timeout the reply
|
||||
deviceHandlerMock.changePeriodicReplyCountdown(0);
|
||||
deviceHandlerMock.performOperation(DeviceHandlerIF::PERFORM_OPERATION);
|
||||
deviceHandlerMock.performOperation(DeviceHandlerIF::SEND_WRITE);
|
||||
deviceHandlerMock.performOperation(DeviceHandlerIF::GET_WRITE);
|
||||
deviceHandlerMock.performOperation(DeviceHandlerIF::SEND_READ);
|
||||
deviceHandlerMock.performOperation(DeviceHandlerIF::GET_READ);
|
||||
uint32_t missedReplies = deviceFdirMock.getMissedReplyCount();
|
||||
REQUIRE(missedReplies == 1);
|
||||
}
|
||||
// SECTION("Periodic reply with countdown based timeout failed") {
|
||||
//
|
||||
// }
|
||||
}
|
||||
|
@ -1,49 +0,0 @@
|
||||
#ifndef UNITTEST_HOSTED_TESTACTIONHELPER_H_
|
||||
#define UNITTEST_HOSTED_TESTACTIONHELPER_H_
|
||||
|
||||
#include <fsfw/action/HasActionsIF.h>
|
||||
#include <fsfw/ipc/MessageQueueIF.h>
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "fsfw_tests/unit/CatchDefinitions.h"
|
||||
|
||||
class ActionHelperOwnerMockBase : public HasActionsIF {
|
||||
public:
|
||||
bool getCommandQueueCalled = false;
|
||||
bool executeActionCalled = false;
|
||||
static const size_t MAX_SIZE = 3;
|
||||
uint8_t buffer[MAX_SIZE] = {0, 0, 0};
|
||||
size_t size = 0;
|
||||
|
||||
MessageQueueId_t getCommandQueue() const override { return tconst::testQueueId; }
|
||||
|
||||
ReturnValue_t executeAction(ActionId_t actionId, MessageQueueId_t commandedBy,
|
||||
const uint8_t* data, size_t size) override {
|
||||
executeActionCalled = true;
|
||||
if (size > MAX_SIZE) {
|
||||
return 0xAFFE;
|
||||
}
|
||||
this->size = size;
|
||||
memcpy(buffer, data, size);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void clearBuffer() {
|
||||
this->size = 0;
|
||||
for (size_t i = 0; i < MAX_SIZE; i++) {
|
||||
buffer[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void getBuffer(const uint8_t** ptr, size_t* size) {
|
||||
if (size != nullptr) {
|
||||
*size = this->size;
|
||||
}
|
||||
if (ptr != nullptr) {
|
||||
*ptr = buffer;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* UNITTEST_TESTFW_NEWTESTS_TESTACTIONHELPER_H_ */
|
Loading…
Reference in New Issue
Block a user