set up new internal error reporter mock

This commit is contained in:
Robin Müller 2022-07-25 14:04:06 +02:00
parent 36e3956efb
commit 1a7d7b172b
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
14 changed files with 140 additions and 94 deletions

View File

@ -8,7 +8,7 @@ MessageQueueBase::MessageQueueBase(MessageQueueId_t id, MessageQueueId_t default
} }
} }
MessageQueueBase::~MessageQueueBase() {} MessageQueueBase::~MessageQueueBase() = default;
ReturnValue_t MessageQueueBase::sendToDefault(MessageQueueMessageIF* message) { ReturnValue_t MessageQueueBase::sendToDefault(MessageQueueMessageIF* message) {
return sendToDefaultFrom(message, this->getId(), false); return sendToDefaultFrom(message, this->getId(), false);

View File

@ -7,28 +7,28 @@
class MessageQueueBase : public MessageQueueIF { class MessageQueueBase : public MessageQueueIF {
public: public:
MessageQueueBase(MessageQueueId_t id, MessageQueueId_t defaultDest, MqArgs* mqArgs); MessageQueueBase(MessageQueueId_t id, MessageQueueId_t defaultDest, MqArgs* mqArgs);
virtual ~MessageQueueBase(); ~MessageQueueBase() override;
// Default implementations for MessageQueueIF where possible // Default implementations for MessageQueueIF where possible
virtual MessageQueueId_t getLastPartner() const override; [[nodiscard]] MessageQueueId_t getLastPartner() const override;
virtual MessageQueueId_t getId() const override; [[nodiscard]] MessageQueueId_t getId() const override;
virtual MqArgs& getMqArgs() override; MqArgs& getMqArgs() override;
virtual void setDefaultDestination(MessageQueueId_t defaultDestination) override; void setDefaultDestination(MessageQueueId_t defaultDestination) override;
virtual MessageQueueId_t getDefaultDestination() const override; [[nodiscard]] MessageQueueId_t getDefaultDestination() const override;
virtual bool isDefaultDestinationSet() const override; [[nodiscard]] bool isDefaultDestinationSet() const override;
virtual ReturnValue_t sendMessage(MessageQueueId_t sendTo, MessageQueueMessageIF* message, ReturnValue_t sendMessage(MessageQueueId_t sendTo, MessageQueueMessageIF* message,
bool ignoreFault) override; bool ignoreFault) override;
virtual ReturnValue_t sendToDefault(MessageQueueMessageIF* message) override; ReturnValue_t sendToDefault(MessageQueueMessageIF* message) override;
virtual ReturnValue_t reply(MessageQueueMessageIF* message) override; ReturnValue_t reply(MessageQueueMessageIF* message) override;
virtual ReturnValue_t receiveMessage(MessageQueueMessageIF* message, ReturnValue_t receiveMessage(MessageQueueMessageIF* message,
MessageQueueId_t* receivedFrom) override; MessageQueueId_t* receivedFrom) override;
virtual ReturnValue_t sendToDefaultFrom(MessageQueueMessageIF* message, MessageQueueId_t sentFrom, ReturnValue_t sendToDefaultFrom(MessageQueueMessageIF* message, MessageQueueId_t sentFrom,
bool ignoreFault = false) override; bool ignoreFault = false) override;
// OSAL specific, forward the abstract function // OSAL specific, forward the abstract function
virtual ReturnValue_t receiveMessage(MessageQueueMessageIF* message) = 0; ReturnValue_t receiveMessage(MessageQueueMessageIF* message) override = 0;
virtual ReturnValue_t sendMessageFrom(MessageQueueId_t sendTo, MessageQueueMessageIF* message, ReturnValue_t sendMessageFrom(MessageQueueId_t sendTo, MessageQueueMessageIF* message,
MessageQueueId_t sentFrom, bool ignoreFault = false) = 0; MessageQueueId_t sentFrom, bool ignoreFault = false) override = 0;
protected: protected:
MessageQueueId_t id = MessageQueueIF::NO_QUEUE; MessageQueueId_t id = MessageQueueIF::NO_QUEUE;

View File

@ -30,7 +30,7 @@ class MessageQueueIF {
//! [EXPORT] : [COMMENT] Returned if the target destination is invalid. //! [EXPORT] : [COMMENT] Returned if the target destination is invalid.
static constexpr ReturnValue_t DESTINATION_INVALID = MAKE_RETURN_CODE(4); static constexpr ReturnValue_t DESTINATION_INVALID = MAKE_RETURN_CODE(4);
virtual ~MessageQueueIF() {} virtual ~MessageQueueIF() = default;
/** /**
* @brief This operation sends a message to the last communication partner. * @brief This operation sends a message to the last communication partner.
* @details * @details
@ -82,11 +82,11 @@ class MessageQueueIF {
/** /**
* @brief This method returns the message queue ID of the last communication partner. * @brief This method returns the message queue ID of the last communication partner.
*/ */
virtual MessageQueueId_t getLastPartner() const = 0; [[nodiscard]] virtual MessageQueueId_t getLastPartner() const = 0;
/** /**
* @brief This method returns the message queue ID of this class's message queue. * @brief This method returns the message queue ID of this class's message queue.
*/ */
virtual MessageQueueId_t getId() const = 0; [[nodiscard]] virtual MessageQueueId_t getId() const = 0;
/** /**
* @brief With the sendMessage call, a queue message is sent to a receiving queue. * @brief With the sendMessage call, a queue message is sent to a receiving queue.
@ -159,9 +159,9 @@ class MessageQueueIF {
/** /**
* @brief This method is a simple getter for the default destination. * @brief This method is a simple getter for the default destination.
*/ */
virtual MessageQueueId_t getDefaultDestination() const = 0; [[nodiscard]] virtual MessageQueueId_t getDefaultDestination() const = 0;
virtual bool isDefaultDestinationSet() const = 0; [[nodiscard]] virtual bool isDefaultDestinationSet() const = 0;
virtual MqArgs& getMqArgs() = 0; virtual MqArgs& getMqArgs() = 0;
}; };

View File

@ -65,11 +65,11 @@ ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo,
// But I will still return a failure here. // But I will still return a failure here.
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
MessageQueue* targetQueue = auto* targetQueue =
dynamic_cast<MessageQueue*>(QueueMapManager::instance()->getMessageQueue(sendTo)); dynamic_cast<MessageQueue*>(QueueMapManager::instance()->getMessageQueue(sendTo));
if (targetQueue == nullptr) { if (targetQueue == nullptr) {
if (not ignoreFault) { if (not ignoreFault) {
InternalErrorReporterIF* internalErrorReporter = auto* internalErrorReporter =
ObjectManager::instance()->get<InternalErrorReporterIF>(objects::INTERNAL_ERROR_REPORTER); ObjectManager::instance()->get<InternalErrorReporterIF>(objects::INTERNAL_ERROR_REPORTER);
if (internalErrorReporter != nullptr) { if (internalErrorReporter != nullptr) {
internalErrorReporter->queueMessageNotSent(); internalErrorReporter->queueMessageNotSent();

View File

@ -13,7 +13,6 @@ ReturnValue_t MessageQueueSenderIF::sendMessage(MessageQueueId_t sendTo,
MessageQueueMessageIF* message, MessageQueueMessageIF* message,
MessageQueueId_t sentFrom, bool ignoreFault) { MessageQueueId_t sentFrom, bool ignoreFault) {
return MessageQueue::sendMessageFromMessageQueue(sendTo, message, sentFrom, ignoreFault); return MessageQueue::sendMessageFromMessageQueue(sendTo, message, sentFrom, ignoreFault);
return HasReturnvaluesIF::RETURN_OK;
} }
QueueFactory* QueueFactory::instance() { QueueFactory* QueueFactory::instance() {
@ -23,9 +22,9 @@ QueueFactory* QueueFactory::instance() {
return factoryInstance; return factoryInstance;
} }
QueueFactory::QueueFactory() {} QueueFactory::QueueFactory() = default;
QueueFactory::~QueueFactory() {} QueueFactory::~QueueFactory() = default;
MessageQueueIF* QueueFactory::createMessageQueue(uint32_t messageDepth, size_t maxMessageSize, MessageQueueIF* QueueFactory::createMessageQueue(uint32_t messageDepth, size_t maxMessageSize,
MqArgs* args) { MqArgs* args) {

View File

@ -131,7 +131,7 @@ void PusServiceBase::initializeTmHelpers(TmSendHelper& tmSendHelper, TmStoreHelp
} }
void PusServiceBase::initializeTmSendHelper(TmSendHelper& tmSendHelper) { void PusServiceBase::initializeTmSendHelper(TmSendHelper& tmSendHelper) {
tmSendHelper.setMsgSource(requestQueue->getId()); tmSendHelper.setMsgQueue(requestQueue);
tmSendHelper.setMsgDestination(requestQueue->getDefaultDestination()); tmSendHelper.setMsgDestination(requestQueue->getDefaultDestination());
if (errReporter == nullptr) { if (errReporter == nullptr) {
errReporter = errReporter =

View File

@ -2,15 +2,21 @@
#include "fsfw/ipc/MessageQueueSenderIF.h" #include "fsfw/ipc/MessageQueueSenderIF.h"
TmSendHelper::TmSendHelper(MessageQueueId_t tmtcMsgDest, MessageQueueId_t tmtcMsgSrc, TmSendHelper::TmSendHelper(MessageQueueIF* queue, MessageQueueId_t tmtcMsgDest,
InternalErrorReporterIF *reporter) InternalErrorReporterIF *reporter)
: tmtcMsgDest(tmtcMsgDest), tmtcMsgSrc(tmtcMsgSrc), errReporter(reporter) {} : tmtcMsgDest(tmtcMsgDest), queue(queue), errReporter(reporter) {}
TmSendHelper::TmSendHelper(MessageQueueIF *queue, InternalErrorReporterIF *reporter)
: queue(queue), errReporter(reporter) {}
TmSendHelper::TmSendHelper(InternalErrorReporterIF *reporter) : errReporter(reporter) {} TmSendHelper::TmSendHelper(InternalErrorReporterIF *reporter) : errReporter(reporter) {}
ReturnValue_t TmSendHelper::sendPacket(const store_address_t &storeId) { ReturnValue_t TmSendHelper::sendPacket(const store_address_t &storeId) {
if(queue == nullptr) {
return HasReturnvaluesIF::RETURN_FAILED;
}
TmTcMessage message(storeId); TmTcMessage message(storeId);
ReturnValue_t result = MessageQueueSenderIF::sendMessage(tmtcMsgDest, &message, tmtcMsgSrc); ReturnValue_t result = queue->sendMessage(tmtcMsgDest, &message, ignoreFault);
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
if (errReporter != nullptr) { if (errReporter != nullptr) {
errReporter->lostTm(); errReporter->lostTm();
@ -22,8 +28,7 @@ ReturnValue_t TmSendHelper::sendPacket(const store_address_t &storeId) {
void TmSendHelper::setMsgDestination(MessageQueueId_t msgDest) { tmtcMsgDest = msgDest; } void TmSendHelper::setMsgDestination(MessageQueueId_t msgDest) { tmtcMsgDest = msgDest; }
void TmSendHelper::setMsgSource(MessageQueueId_t msgSrc) { tmtcMsgSrc = msgSrc; }
void TmSendHelper::setInternalErrorReporter(InternalErrorReporterIF *reporter) { void TmSendHelper::setInternalErrorReporter(InternalErrorReporterIF *reporter) {
errReporter = reporter; errReporter = reporter;
} }
void TmSendHelper::setMsgQueue(MessageQueueIF *queue_) { queue = queue_; }

View File

@ -10,16 +10,18 @@
class TmSendHelper { class TmSendHelper {
public: public:
explicit TmSendHelper(InternalErrorReporterIF* reporter); explicit TmSendHelper(InternalErrorReporterIF* reporter);
TmSendHelper(MessageQueueId_t tmtcMsgDest, MessageQueueId_t tmtcMsgSrc, TmSendHelper(MessageQueueIF* queue, InternalErrorReporterIF* reporter);
TmSendHelper(MessageQueueIF* queue, MessageQueueId_t tmtcMsgDest,
InternalErrorReporterIF* reporter); InternalErrorReporterIF* reporter);
void setMsgQueue(MessageQueueIF* queue);
void setMsgDestination(MessageQueueId_t msgDest); void setMsgDestination(MessageQueueId_t msgDest);
void setMsgSource(MessageQueueId_t msgSrc);
void setInternalErrorReporter(InternalErrorReporterIF* reporter); void setInternalErrorReporter(InternalErrorReporterIF* reporter);
ReturnValue_t sendPacket(const store_address_t& storeId); ReturnValue_t sendPacket(const store_address_t& storeId);
private: private:
MessageQueueId_t tmtcMsgDest = MessageQueueIF::NO_QUEUE; MessageQueueId_t tmtcMsgDest = MessageQueueIF::NO_QUEUE;
MessageQueueId_t tmtcMsgSrc = MessageQueueIF::NO_QUEUE; bool ignoreFault = false;
MessageQueueIF* queue = nullptr;
InternalErrorReporterIF* errReporter; InternalErrorReporterIF* errReporter;
}; };

View File

@ -33,7 +33,7 @@ TEST_CASE("Internal Error Reporter", "[TestInternalError]") {
MessageQueueIF* hkQueue = QueueFactory::instance()->createMessageQueue(1); MessageQueueIF* hkQueue = QueueFactory::instance()->createMessageQueue(1);
internalErrorReporter->getSubscriptionInterface()->subscribeForSetUpdateMessage( internalErrorReporter->getSubscriptionInterface()->subscribeForSetUpdateMessage(
InternalErrorDataset::ERROR_SET_ID, objects::NO_OBJECT, hkQueue->getId(), true); InternalErrorDataset::ERROR_SET_ID, objects::NO_OBJECT, hkQueue->getId(), true);
StorageManagerIF* ipcStore = ObjectManager::instance()->get<StorageManagerIF>(objects::IPC_STORE); auto* ipcStore = ObjectManager::instance()->get<StorageManagerIF>(objects::IPC_STORE);
SECTION("MessageQueueFull") { SECTION("MessageQueueFull") {
CommandMessage message; CommandMessage message;
ActionMessage::setCompletionReply(&message, 10, true); ActionMessage::setCompletionReply(&message, 10, true);
@ -57,7 +57,7 @@ TEST_CASE("Internal Error Reporter", "[TestInternalError]") {
REQUIRE(gpid.objectId == objects::INTERNAL_ERROR_REPORTER); REQUIRE(gpid.objectId == objects::INTERNAL_ERROR_REPORTER);
// We need the object ID of the reporter here (NO_OBJECT) // We need the object ID of the reporter here (NO_OBJECT)
InternalErrorDataset dataset(objects::INTERNAL_ERROR_REPORTER); InternalErrorDataset dataset(objects::INTERNAL_ERROR_REPORTER);
CCSDSTime::CDS_short time; CCSDSTime::CDS_short time{};
ConstAccessorPair data = ipcStore->getData(storeAddress); ConstAccessorPair data = ipcStore->getData(storeAddress);
REQUIRE(data.first == HasReturnvaluesIF::RETURN_OK); REQUIRE(data.first == HasReturnvaluesIF::RETURN_OK);
HousekeepingSnapshot hkSnapshot(&time, &dataset); HousekeepingSnapshot hkSnapshot(&time, &dataset);
@ -87,7 +87,7 @@ TEST_CASE("Internal Error Reporter", "[TestInternalError]") {
ConstAccessorPair data = ipcStore->getData(storeAddress); ConstAccessorPair data = ipcStore->getData(storeAddress);
REQUIRE(data.first == HasReturnvaluesIF::RETURN_OK); REQUIRE(data.first == HasReturnvaluesIF::RETURN_OK);
CCSDSTime::CDS_short time; CCSDSTime::CDS_short time{};
// We need the object ID of the reporter here (NO_OBJECT) // We need the object ID of the reporter here (NO_OBJECT)
InternalErrorDataset dataset(objects::INTERNAL_ERROR_REPORTER); InternalErrorDataset dataset(objects::INTERNAL_ERROR_REPORTER);
HousekeepingSnapshot hkSnapshot(&time, &dataset); HousekeepingSnapshot hkSnapshot(&time, &dataset);
@ -107,10 +107,10 @@ TEST_CASE("Internal Error Reporter", "[TestInternalError]") {
// Message Queue Id // Message Queue Id
MessageQueueId_t id = internalErrorReporter->getCommandQueue(); MessageQueueId_t id = internalErrorReporter->getCommandQueue();
REQUIRE(id != MessageQueueIF::NO_QUEUE); REQUIRE(id != MessageQueueIF::NO_QUEUE);
CommandMessage message; CommandMessage message2;
sid_t sid(objects::INTERNAL_ERROR_REPORTER, InternalErrorDataset::ERROR_SET_ID); sid_t sid(objects::INTERNAL_ERROR_REPORTER, InternalErrorDataset::ERROR_SET_ID);
HousekeepingMessage::setToggleReportingCommand(&message, sid, true, false); HousekeepingMessage::setToggleReportingCommand(&message2, sid, true, false);
result = hkQueue->sendMessage(id, &message); result = hkQueue->sendMessage(id, &message2);
REQUIRE(result == HasReturnvaluesIF::RETURN_OK); REQUIRE(result == HasReturnvaluesIF::RETURN_OK);
internalErrorReporter->performOperation(0); internalErrorReporter->performOperation(0);
} }

View File

@ -4,4 +4,5 @@ target_sources(${FSFW_TEST_TGT} PRIVATE
DeviceFdirMock.cpp DeviceFdirMock.cpp
CookieIFMock.cpp CookieIFMock.cpp
ComIFMock.cpp ComIFMock.cpp
MessageQueueMockBase.cpp
) )

View File

@ -0,0 +1,11 @@
#ifndef FSFW_TESTS_INTERNALERRORREPORTERMOCK_H
#define FSFW_TESTS_INTERNALERRORREPORTERMOCK_H
#include "fsfw/internalerror/InternalErrorReporterIF.h"
class InternalErrorReporterMock: public InternalErrorReporterIF {
public:
InternalErrorReporterMock();
private:
};
#endif // FSFW_TESTS_INTERNALERRORREPORTERMOCK_H

View File

@ -0,0 +1,67 @@
#include "MessageQueueMockBase.h"
MessageQueueMockBase::MessageQueueMockBase()
: MessageQueueBase(MessageQueueIF::NO_QUEUE, MessageQueueIF::NO_QUEUE, nullptr) {}
MessageQueueMockBase::MessageQueueMockBase(MessageQueueId_t queueId)
: MessageQueueBase(queueId, MessageQueueIF::NO_QUEUE, nullptr) {}
bool MessageQueueMockBase::wasMessageSent(uint8_t* messageSentCounter_, bool resetCounter) {
bool tempMessageSent = messageSent;
messageSent = false;
if (messageSentCounter_ != nullptr) {
*messageSentCounter_ = this->messageSentCounter;
}
if (resetCounter) {
this->messageSentCounter = 0;
}
return tempMessageSent;
}
ReturnValue_t MessageQueueMockBase::popMessage() {
CommandMessage message;
message.clear();
return receiveMessage(&message);
}
ReturnValue_t MessageQueueMockBase::receiveMessage(MessageQueueMessageIF* message) {
if (messagesSentQueue.empty()) {
return MessageQueueIF::EMPTY;
}
this->last = message->getSender();
std::memcpy(message->getBuffer(), messagesSentQueue.front().getBuffer(),
message->getMessageSize());
messagesSentQueue.pop();
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t MessageQueueMockBase::flush(uint32_t* count) {
return HasReturnvaluesIF::RETURN_FAILED;
}
ReturnValue_t MessageQueueMockBase::sendMessageFrom(MessageQueueId_t sendTo,
MessageQueueMessageIF* message,
MessageQueueId_t sentFrom, bool ignoreFault) {
messageSent = true;
messageSentCounter++;
MessageQueueMessage& messageRef = *(dynamic_cast<MessageQueueMessage*>(message));
messagesSentQueue.push(messageRef);
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t MessageQueueMockBase::reply(MessageQueueMessageIF* message) {
return sendMessageFrom(MessageQueueIF::NO_QUEUE, message, this->getId(), false);
}
void MessageQueueMockBase::clearMessages(bool clearCommandMessages) {
while (not messagesSentQueue.empty()) {
if (clearCommandMessages) {
CommandMessage message;
std::memcpy(message.getBuffer(), messagesSentQueue.front().getBuffer(),
message.getMessageSize());
message.clear();
}
messagesSentQueue.pop();
}
}

View File

@ -12,71 +12,30 @@
class MessageQueueMockBase : public MessageQueueBase { class MessageQueueMockBase : public MessageQueueBase {
public: public:
MessageQueueMockBase() MessageQueueMockBase();
: MessageQueueBase(MessageQueueIF::NO_QUEUE, MessageQueueIF::NO_QUEUE, nullptr) {}
explicit MessageQueueMockBase(MessageQueueId_t queueId);
uint8_t messageSentCounter = 0; uint8_t messageSentCounter = 0;
bool messageSent = false; bool messageSent = false;
bool wasMessageSent(uint8_t* messageSentCounter_ = nullptr, bool resetCounter = true) { bool wasMessageSent(uint8_t* messageSentCounter_ = nullptr, bool resetCounter = true);
bool tempMessageSent = messageSent;
messageSent = false;
if (messageSentCounter_ != nullptr) {
*messageSentCounter_ = this->messageSentCounter;
}
if (resetCounter) {
this->messageSentCounter = 0;
}
return tempMessageSent;
}
/** /**
* Pop a message, clearing it in the process. * Pop a message, clearing it in the process.
* @return * @return
*/ */
ReturnValue_t popMessage() { ReturnValue_t popMessage();
CommandMessage message;
message.clear();
return receiveMessage(&message);
}
ReturnValue_t receiveMessage(MessageQueueMessageIF* message) override { ReturnValue_t receiveMessage(MessageQueueMessageIF* message) override;
if (messagesSentQueue.empty()) {
return MessageQueueIF::EMPTY; ReturnValue_t flush(uint32_t* count) override;
}
this->last = message->getSender();
std::memcpy(message->getBuffer(), messagesSentQueue.front().getBuffer(),
message->getMessageSize());
messagesSentQueue.pop();
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t flush(uint32_t* count) override { return HasReturnvaluesIF::RETURN_OK; }
ReturnValue_t sendMessageFrom(MessageQueueId_t sendTo, MessageQueueMessageIF* message, ReturnValue_t sendMessageFrom(MessageQueueId_t sendTo, MessageQueueMessageIF* message,
MessageQueueId_t sentFrom, MessageQueueId_t sentFrom,
bool ignoreFault = false) override { bool ignoreFault = false) override;
messageSent = true; ReturnValue_t reply(MessageQueueMessageIF* message) override;
messageSentCounter++;
MessageQueueMessage& messageRef = *(dynamic_cast<MessageQueueMessage*>(message));
messagesSentQueue.push(messageRef);
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t reply(MessageQueueMessageIF* message) override {
return sendMessageFrom(MessageQueueIF::NO_QUEUE, message, this->getId(), false);
}
void clearMessages(bool clearCommandMessages = true) {
while (not messagesSentQueue.empty()) {
if (clearCommandMessages) {
CommandMessage message;
std::memcpy(message.getBuffer(), messagesSentQueue.front().getBuffer(),
message.getMessageSize());
message.clear();
}
messagesSentQueue.pop();
}
}
void clearMessages(bool clearCommandMessages = true);
private: private:
std::queue<MessageQueueMessage> messagesSentQueue; std::queue<MessageQueueMessage> messagesSentQueue;
}; };

View File

@ -1,5 +1,7 @@
#include <catch2/catch_test_macros.hpp> #include <catch2/catch_test_macros.hpp>
TEST_CASE("TM Send Helper", "[tm-send-helper]") { #include "fsfw/tmtcservices/TmSendHelper.h"
TEST_CASE("TM Send Helper", "[tm-send-helper]") {
TmSendHelper sendHelper(nullptr);
} }