set up new internal error reporter mock
Some checks failed
fsfw/fsfw/pipeline/pr-development There was a failure building this commit

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) {
return sendToDefaultFrom(message, this->getId(), false);

View File

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

View File

@ -30,7 +30,7 @@ class MessageQueueIF {
//! [EXPORT] : [COMMENT] Returned if the target destination is invalid.
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.
* @details
@ -82,11 +82,11 @@ class MessageQueueIF {
/**
* @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.
*/
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.
@ -159,9 +159,9 @@ class MessageQueueIF {
/**
* @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;
};

View File

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

View File

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

View File

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

View File

@ -2,15 +2,21 @@
#include "fsfw/ipc/MessageQueueSenderIF.h"
TmSendHelper::TmSendHelper(MessageQueueId_t tmtcMsgDest, MessageQueueId_t tmtcMsgSrc,
TmSendHelper::TmSendHelper(MessageQueueIF* queue, MessageQueueId_t tmtcMsgDest,
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) {}
ReturnValue_t TmSendHelper::sendPacket(const store_address_t &storeId) {
if(queue == nullptr) {
return HasReturnvaluesIF::RETURN_FAILED;
}
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 (errReporter != nullptr) {
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::setMsgSource(MessageQueueId_t msgSrc) { tmtcMsgSrc = msgSrc; }
void TmSendHelper::setInternalErrorReporter(InternalErrorReporterIF *reporter) {
errReporter = reporter;
}
void TmSendHelper::setMsgQueue(MessageQueueIF *queue_) { queue = queue_; }

View File

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

View File

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

View File

@ -4,4 +4,5 @@ target_sources(${FSFW_TEST_TGT} PRIVATE
DeviceFdirMock.cpp
CookieIFMock.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 {
public:
MessageQueueMockBase()
: MessageQueueBase(MessageQueueIF::NO_QUEUE, MessageQueueIF::NO_QUEUE, nullptr) {}
MessageQueueMockBase();
explicit MessageQueueMockBase(MessageQueueId_t queueId);
uint8_t messageSentCounter = 0;
bool messageSent = false;
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;
}
bool wasMessageSent(uint8_t* messageSentCounter_ = nullptr, bool resetCounter = true);
/**
* Pop a message, clearing it in the process.
* @return
*/
ReturnValue_t popMessage() {
CommandMessage message;
message.clear();
return receiveMessage(&message);
}
ReturnValue_t popMessage();
ReturnValue_t receiveMessage(MessageQueueMessageIF* message) override {
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 flush(uint32_t* count) override { return HasReturnvaluesIF::RETURN_OK; }
ReturnValue_t receiveMessage(MessageQueueMessageIF* message) override;
ReturnValue_t flush(uint32_t* count) override;
ReturnValue_t sendMessageFrom(MessageQueueId_t sendTo, MessageQueueMessageIF* message,
MessageQueueId_t sentFrom,
bool ignoreFault = false) override {
messageSent = true;
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();
}
}
bool ignoreFault = false) override;
ReturnValue_t reply(MessageQueueMessageIF* message) override;
void clearMessages(bool clearCommandMessages = true);
private:
std::queue<MessageQueueMessage> messagesSentQueue;
};

View File

@ -1,5 +1,7 @@
#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);
}