adapt PSB so it can be unittested properly

This commit is contained in:
Robin Müller 2022-07-26 16:49:46 +02:00
parent f14c812aff
commit d98b79cf5e
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
27 changed files with 205 additions and 131 deletions

View File

@ -5,10 +5,10 @@
#include "fsfw/objectmanager/SystemObject.h" #include "fsfw/objectmanager/SystemObject.h"
#include "fsfw/tmtcservices/tmHelpers.h" #include "fsfw/tmtcservices/tmHelpers.h"
Service17Test::Service17Test(object_id_t objectId, uint16_t apid, uint8_t serviceId) Service17Test::Service17Test(PsbParams params)
: PusServiceBase(objectId, apid, serviceId), : PusServiceBase(params),
storeHelper(apid), storeHelper(params.apid),
tmHelper(serviceId, storeHelper, sendHelper) {} tmHelper(params.serviceId, storeHelper, sendHelper) {}
Service17Test::~Service17Test() = default; Service17Test::~Service17Test() = default;

View File

@ -34,7 +34,7 @@ class Service17Test : public PusServiceBase {
EVENT_TRIGGER_TEST = 128, EVENT_TRIGGER_TEST = 128,
}; };
Service17Test(object_id_t objectId, uint16_t apid, uint8_t serviceId); explicit Service17Test(PsbParams params);
void setCustomTmStore(StorageManagerIF& tmStore); void setCustomTmStore(StorageManagerIF& tmStore);

View File

@ -7,12 +7,11 @@
#include "fsfw/serviceinterface/ServiceInterface.h" #include "fsfw/serviceinterface/ServiceInterface.h"
#include "fsfw/tmtcservices/tmHelpers.h" #include "fsfw/tmtcservices/tmHelpers.h"
Service5EventReporting::Service5EventReporting(object_id_t objectId, uint16_t apid, Service5EventReporting::Service5EventReporting(PsbParams params, size_t maxNumberReportsPerCycle,
uint8_t serviceId, size_t maxNumberReportsPerCycle,
uint32_t messageQueueDepth) uint32_t messageQueueDepth)
: PusServiceBase(objectId, apid, serviceId), : PusServiceBase(params),
storeHelper(apid), storeHelper(params.apid),
tmHelper(serviceId, storeHelper, sendHelper), tmHelper(params.serviceId, storeHelper, sendHelper),
maxNumberReportsPerCycle(maxNumberReportsPerCycle) { maxNumberReportsPerCycle(maxNumberReportsPerCycle) {
eventQueue = QueueFactory::instance()->createMessageQueue(messageQueueDepth); eventQueue = QueueFactory::instance()->createMessageQueue(messageQueueDepth);
} }
@ -47,7 +46,7 @@ ReturnValue_t Service5EventReporting::performService() {
ReturnValue_t Service5EventReporting::generateEventReport(EventMessage message) { ReturnValue_t Service5EventReporting::generateEventReport(EventMessage message) {
EventReport report(message.getEventId(), message.getReporter(), message.getParameter1(), EventReport report(message.getEventId(), message.getReporter(), message.getParameter1(),
message.getParameter2()); message.getParameter2());
storeHelper.preparePacket(serviceId, message.getSeverity(), tmHelper.sendCounter); storeHelper.preparePacket(psbParams.serviceId, message.getSeverity(), tmHelper.sendCounter);
storeHelper.setSourceDataSerializable(report); storeHelper.setSourceDataSerializable(report);
ReturnValue_t result = tmHelper.storeAndSendTmPacket(); ReturnValue_t result = tmHelper.storeAndSendTmPacket();
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {

View File

@ -41,8 +41,8 @@
*/ */
class Service5EventReporting : public PusServiceBase { class Service5EventReporting : public PusServiceBase {
public: public:
Service5EventReporting(object_id_t objectId, uint16_t apid, uint8_t serviceId, Service5EventReporting(PsbParams params, size_t maxNumberReportsPerCycle = 10,
size_t maxNumberReportsPerCycle = 10, uint32_t messageQueueDepth = 10); uint32_t messageQueueDepth = 10);
~Service5EventReporting() override; ~Service5EventReporting() override;
/*** /***

View File

@ -5,9 +5,7 @@
#include "fsfw/serviceinterface/ServiceInterface.h" #include "fsfw/serviceinterface/ServiceInterface.h"
#include "fsfw/timemanager/CCSDSTime.h" #include "fsfw/timemanager/CCSDSTime.h"
Service9TimeManagement::Service9TimeManagement(object_id_t objectId, uint16_t apid, Service9TimeManagement::Service9TimeManagement(PsbParams params) : PusServiceBase(params) {}
uint8_t serviceId)
: PusServiceBase(objectId, apid, serviceId) {}
Service9TimeManagement::~Service9TimeManagement() = default; Service9TimeManagement::~Service9TimeManagement() = default;

View File

@ -16,16 +16,16 @@ class Service9TimeManagement : public PusServiceBase {
/** /**
* @brief This service provides the capability to set the on-board time. * @brief This service provides the capability to set the on-board time.
*/ */
Service9TimeManagement(object_id_t objectId, uint16_t apid, uint8_t serviceId); explicit Service9TimeManagement(PsbParams params);
virtual ~Service9TimeManagement(); ~Service9TimeManagement() override;
virtual ReturnValue_t performService() override; ReturnValue_t performService() override;
/** /**
* @brief Sets the onboard-time by retrieving the time to set from TC[9,128]. * @brief Sets the onboard-time by retrieving the time to set from TC[9,128].
*/ */
virtual ReturnValue_t handleRequest(uint8_t subservice) override; ReturnValue_t handleRequest(uint8_t subservice) override;
virtual ReturnValue_t setTime(); virtual ReturnValue_t setTime();

View File

@ -1,7 +1,7 @@
#ifndef FSFW_TMTCSERVICES_ACCEPTSTELEMETRYIF_H_ #ifndef FSFW_TMTCSERVICES_ACCEPTSTELEMETRYIF_H_
#define FSFW_TMTCSERVICES_ACCEPTSTELEMETRYIF_H_ #define FSFW_TMTCSERVICES_ACCEPTSTELEMETRYIF_H_
#include "../ipc/MessageQueueSenderIF.h" #include "fsfw/ipc/MessageQueueSenderIF.h"
/** /**
* @brief This interface is implemented by classes that are sinks for * @brief This interface is implemented by classes that are sinks for
* Telemetry. * Telemetry.
@ -13,13 +13,15 @@ class AcceptsTelemetryIF {
/** /**
* @brief The virtual destructor as it is mandatory for C++ interfaces. * @brief The virtual destructor as it is mandatory for C++ interfaces.
*/ */
virtual ~AcceptsTelemetryIF() {} virtual ~AcceptsTelemetryIF() = default;
/** /**
* @brief This method returns the message queue id of the telemetry * @brief This method returns the message queue id of the telemetry
* receiving message queue. * receiving message queue.
* @return The telemetry reception message queue id. * @return The telemetry reception message queue id.
*/ */
virtual MessageQueueId_t getReportReceptionQueue(uint8_t virtualChannel = 0) = 0; virtual MessageQueueId_t getReportReceptionQueue(uint8_t virtualChannel) = 0;
virtual MessageQueueId_t getReportReceptionQueue() { return getReportReceptionQueue(0); }
}; };
#endif /* FSFW_TMTCSERVICES_ACCEPTSTELEMETRYIF_H_ */ #endif /* FSFW_TMTCSERVICES_ACCEPTSTELEMETRYIF_H_ */

View File

@ -9,19 +9,16 @@
#include "fsfw/tmtcservices/TmTcMessage.h" #include "fsfw/tmtcservices/TmTcMessage.h"
#include "fsfw/tmtcservices/tcHelpers.h" #include "fsfw/tmtcservices/tcHelpers.h"
object_id_t PusServiceBase::packetSource = 0;
object_id_t PusServiceBase::packetDestination = 0; object_id_t PusServiceBase::packetDestination = 0;
PusServiceBase::PusServiceBase(object_id_t setObjectId, uint16_t setApid, uint8_t setServiceId, PusServiceBase::PusServiceBase(PsbParams params)
VerificationReporterIF* verifyReporter) : SystemObject(params.objectId), psbParams(params) {}
: SystemObject(setObjectId),
apid(setApid),
serviceId(setServiceId),
verifyReporter(verifyReporter) {
requestQueue = QueueFactory::instance()->createMessageQueue(PUS_SERVICE_MAX_RECEPTION);
}
PusServiceBase::~PusServiceBase() { QueueFactory::instance()->deleteMessageQueue(requestQueue); } PusServiceBase::~PusServiceBase() {
if (ownedQueue) {
QueueFactory::instance()->deleteMessageQueue(psbParams.reqQueue);
}
}
ReturnValue_t PusServiceBase::performOperation(uint8_t opCode) { ReturnValue_t PusServiceBase::performOperation(uint8_t opCode) {
handleRequestQueue(); handleRequestQueue();
@ -42,7 +39,7 @@ void PusServiceBase::handleRequestQueue() {
TmTcMessage message; TmTcMessage message;
ReturnValue_t result; ReturnValue_t result;
for (uint8_t count = 0; count < PUS_SERVICE_MAX_RECEPTION; count++) { for (uint8_t count = 0; count < PUS_SERVICE_MAX_RECEPTION; count++) {
ReturnValue_t status = this->requestQueue->receiveMessage(&message); ReturnValue_t status = psbParams.reqQueue->receiveMessage(&message);
if (status == MessageQueueIF::EMPTY) { if (status == MessageQueueIF::EMPTY) {
break; break;
} else if (status != HasReturnvaluesIF::RETURN_OK) { } else if (status != HasReturnvaluesIF::RETURN_OK) {
@ -53,27 +50,27 @@ void PusServiceBase::handleRequestQueue() {
#else #else
sif::printError( sif::printError(
"PusServiceBase::performOperation: Service %d. Error receiving packet. Code: %04x\n", "PusServiceBase::performOperation: Service %d. Error receiving packet. Code: %04x\n",
serviceId, status); psbParams.serviceId, status);
#endif #endif
break; break;
} }
result = tc::prepareTcReader(tcStore, message.getStorageId(), currentPacket); result = tc::prepareTcReader(tcStore, message.getStorageId(), currentPacket);
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
auto params = VerifFailureParams(tcverif::START_FAILURE, currentPacket, result); auto verifParams = VerifFailureParams(tcverif::START_FAILURE, currentPacket, result);
params.errorParam1 = errorParameter1; verifParams.errorParam1 = errorParameter1;
params.errorParam2 = errorParameter2; verifParams.errorParam2 = errorParameter2;
verifyReporter->sendFailureReport(params); psbParams.verifReporter->sendFailureReport(verifParams);
continue; continue;
} }
result = handleRequest(currentPacket.getSubService()); result = handleRequest(currentPacket.getSubService());
if (result == RETURN_OK) { if (result == RETURN_OK) {
verifyReporter->sendSuccessReport( psbParams.verifReporter->sendSuccessReport(
VerifSuccessParams(tcverif::COMPLETION_SUCCESS, currentPacket)); VerifSuccessParams(tcverif::COMPLETION_SUCCESS, currentPacket));
} else { } else {
auto params = VerifFailureParams(tcverif::COMPLETION_FAILURE, currentPacket, result); auto failParams = VerifFailureParams(tcverif::COMPLETION_FAILURE, currentPacket, result);
params.errorParam1 = errorParameter1; failParams.errorParam1 = errorParameter1;
params.errorParam2 = errorParameter2; failParams.errorParam2 = errorParameter2;
verifyReporter->sendFailureReport(params); psbParams.verifReporter->sendFailureReport(failParams);
} }
tcStore->deleteData(message.getStorageId()); tcStore->deleteData(message.getStorageId());
errorParameter1 = 0; errorParameter1 = 0;
@ -81,37 +78,39 @@ void PusServiceBase::handleRequestQueue() {
} }
} }
uint16_t PusServiceBase::getIdentifier() { return this->serviceId; } uint16_t PusServiceBase::getIdentifier() { return psbParams.serviceId; }
MessageQueueId_t PusServiceBase::getRequestQueue() { return this->requestQueue->getId(); } MessageQueueId_t PusServiceBase::getRequestQueue() { return psbParams.reqQueue->getId(); }
ReturnValue_t PusServiceBase::initialize() { ReturnValue_t PusServiceBase::initialize() {
ReturnValue_t result = SystemObject::initialize(); ReturnValue_t result = SystemObject::initialize();
if (result != RETURN_OK) { if (result != RETURN_OK) {
return result; return result;
} }
auto* destService = ObjectManager::instance()->get<AcceptsTelemetryIF>(packetDestination); if (psbParams.reqQueue == nullptr) {
auto* distributor = ObjectManager::instance()->get<PUSDistributorIF>(packetSource); ownedQueue = true;
if (destService == nullptr or distributor == nullptr) { psbParams.reqQueue = QueueFactory::instance()->createMessageQueue(PSB_DEFAULT_QUEUE_DEPTH);
#if FSFW_CPP_OSTREAM_ENABLED == 1 } else {
sif::error << "PusServiceBase::PusServiceBase: Service " << this->serviceId ownedQueue = false;
<< ": Configuration error. Make sure "
<< "packetSource and packetDestination are defined correctly" << std::endl;
#endif
return ObjectManagerIF::CHILD_INIT_FAILED;
} }
this->requestQueue->setDefaultDestination(destService->getReportReceptionQueue()); if (psbParams.tmReceiver == nullptr) {
distributor->registerService(this); psbParams.tmReceiver = ObjectManager::instance()->get<AcceptsTelemetryIF>(packetDestination);
if (psbParams.tmReceiver != nullptr) {
psbParams.reqQueue->setDefaultDestination(psbParams.tmReceiver->getReportReceptionQueue());
}
}
if (tcStore == nullptr) { if (tcStore == nullptr) {
tcStore = ObjectManager::instance()->get<StorageManagerIF>(objects::IPC_STORE); tcStore = ObjectManager::instance()->get<StorageManagerIF>(objects::TC_STORE);
if (tcStore == nullptr) { if (tcStore == nullptr) {
return ObjectManagerIF::CHILD_INIT_FAILED; return ObjectManagerIF::CHILD_INIT_FAILED;
} }
} }
if (verifyReporter == nullptr) {
verifyReporter = if (psbParams.verifReporter == nullptr) {
psbParams.verifReporter =
ObjectManager::instance()->get<VerificationReporterIF>(objects::TC_VERIFICATOR); ObjectManager::instance()->get<VerificationReporterIF>(objects::TC_VERIFICATOR);
if (verifyReporter == nullptr) { if (psbParams.verifReporter == nullptr) {
return ObjectManagerIF::CHILD_INIT_FAILED; return ObjectManagerIF::CHILD_INIT_FAILED;
} }
} }
@ -128,7 +127,7 @@ ReturnValue_t PusServiceBase::initializeAfterTaskCreation() {
void PusServiceBase::setCustomTcStore(StorageManagerIF* tcStore_) { tcStore = tcStore_; } void PusServiceBase::setCustomTcStore(StorageManagerIF* tcStore_) { tcStore = tcStore_; }
void PusServiceBase::setCustomErrorReporter(InternalErrorReporterIF* errReporter_) { void PusServiceBase::setCustomErrorReporter(InternalErrorReporterIF* errReporter_) {
errReporter = errReporter_; psbParams.errReporter = errReporter_;
} }
void PusServiceBase::initializeTmHelpers(TmSendHelper& tmSendHelper, TmStoreHelper& tmStoreHelper) { void PusServiceBase::initializeTmHelpers(TmSendHelper& tmSendHelper, TmStoreHelper& tmStoreHelper) {
@ -137,21 +136,34 @@ void PusServiceBase::initializeTmHelpers(TmSendHelper& tmSendHelper, TmStoreHelp
} }
void PusServiceBase::initializeTmSendHelper(TmSendHelper& tmSendHelper) { void PusServiceBase::initializeTmSendHelper(TmSendHelper& tmSendHelper) {
tmSendHelper.setMsgQueue(*requestQueue); if (psbParams.reqQueue != nullptr) {
tmSendHelper.setDefaultDestination(requestQueue->getDefaultDestination()); tmSendHelper.setMsgQueue(*psbParams.reqQueue);
if (errReporter == nullptr) { tmSendHelper.setDefaultDestination(psbParams.reqQueue->getDefaultDestination());
errReporter = }
if (psbParams.errReporter == nullptr) {
psbParams.errReporter =
ObjectManager::instance()->get<InternalErrorReporterIF>(objects::INTERNAL_ERROR_REPORTER); ObjectManager::instance()->get<InternalErrorReporterIF>(objects::INTERNAL_ERROR_REPORTER);
if (errReporter != nullptr) { if (psbParams.errReporter != nullptr) {
tmSendHelper.setInternalErrorReporter(errReporter); tmSendHelper.setInternalErrorReporter(psbParams.errReporter);
} }
} }
} }
void PusServiceBase::initializeTmStoreHelper(TmStoreHelper& tmStoreHelper) const { void PusServiceBase::initializeTmStoreHelper(TmStoreHelper& tmStoreHelper) const {
tmStoreHelper.setApid(apid); tmStoreHelper.setApid(psbParams.apid);
} }
void PusServiceBase::setVerificationReporter(VerificationReporterIF* reporter) { void PusServiceBase::setVerificationReporter(VerificationReporterIF* reporter) {
verifyReporter = reporter; psbParams.verifReporter = reporter;
} }
ReturnValue_t PusServiceBase::registerService(PUSDistributorIF& distributor) {
return distributor.registerService(this);
}
void PusServiceBase::setTmReceiver(AcceptsTelemetryIF* tmReceiver_) {
psbParams.tmReceiver = tmReceiver_;
}
void PusServiceBase::setRequestQueue(MessageQueueIF* reqQueue) { psbParams.reqQueue = reqQueue; }

View File

@ -2,6 +2,7 @@
#define FSFW_TMTCSERVICES_PUSSERVICEBASE_H_ #define FSFW_TMTCSERVICES_PUSSERVICEBASE_H_
#include "AcceptsTelecommandsIF.h" #include "AcceptsTelecommandsIF.h"
#include "AcceptsTelemetryIF.h"
#include "TmSendHelper.h" #include "TmSendHelper.h"
#include "TmStoreHelper.h" #include "TmStoreHelper.h"
#include "VerificationCodes.h" #include "VerificationCodes.h"
@ -11,6 +12,7 @@
#include "fsfw/objectmanager/SystemObject.h" #include "fsfw/objectmanager/SystemObject.h"
#include "fsfw/returnvalues/HasReturnvaluesIF.h" #include "fsfw/returnvalues/HasReturnvaluesIF.h"
#include "fsfw/tasks/ExecutableObjectIF.h" #include "fsfw/tasks/ExecutableObjectIF.h"
#include "fsfw/tcdistribution/PUSDistributorIF.h"
namespace Factory { namespace Factory {
void setStaticFrameworkObjectIds(); void setStaticFrameworkObjectIds();
@ -18,6 +20,44 @@ void setStaticFrameworkObjectIds();
class StorageManagerIF; class StorageManagerIF;
/**
* Configuration parameters for the PUS Service Base
*/
struct PsbParams {
PsbParams() = default;
PsbParams(uint16_t apid, AcceptsTelemetryIF* tmReceiver) : apid(apid), tmReceiver(tmReceiver) {}
PsbParams(object_id_t objectId, uint16_t apid, uint8_t serviceId)
: objectId(objectId), apid(apid), serviceId(serviceId) {}
object_id_t objectId = objects::NO_OBJECT;
uint16_t apid = 0;
uint8_t serviceId = 0;
/**
* The default destination ID for generated telemetry. If this is not set, @initialize of PSB
* will attempt to find a suitable object with the object ID @PusServiceBase::packetDestination
*/
AcceptsTelemetryIF* tmReceiver = nullptr;
/**
* An instance of the VerificationReporter class, that simplifies
* sending any kind of verification message to the TC Verification Service. If this is not set,
* @initialize of PSB will attempt to find a suitable global object with the ID
* @objects::TC_VERIFICATOR
*/
VerificationReporterIF* verifReporter = nullptr;
/**
* This is a complete instance of the telecommand reception queue
* of the class. It is initialized on construction of the class.
*/
MessageQueueIF* reqQueue = nullptr;
/**
* The internal error reporter which will be used if there are issues sending telemetry.
* If this is not set, and the TM send or store helpers are initialized with the PSB,
* the class will attempt to find a suitable global object with the ID
* @objects::INTERNAL_ERROR_REPORTER
*/
InternalErrorReporterIF* errReporter = nullptr;
};
/** /**
* @defgroup pus_services PUS Service Framework * @defgroup pus_services PUS Service Framework
* These group contains all implementations of PUS Services in the OBSW. * These group contains all implementations of PUS Services in the OBSW.
@ -43,23 +83,33 @@ class PusServiceBase : public ExecutableObjectIF,
friend void(Factory::setStaticFrameworkObjectIds)(); friend void(Factory::setStaticFrameworkObjectIds)();
public: public:
/**
* This constant sets the maximum number of packets accepted per call.
* Remember that one packet must be completely handled in one
* #handleRequest call.
*/
static constexpr uint8_t PUS_SERVICE_MAX_RECEPTION = 10;
static constexpr uint8_t PSB_DEFAULT_QUEUE_DEPTH = 10;
/** /**
* @brief The passed values are set, but inter-object initialization is * @brief The passed values are set, but inter-object initialization is
* done in the initialize method. * done in the initialize method.
* @param setObjectId * @param params All configuration parameters for the PUS Service Base
* The system object identifier of this Service instance.
* @param setApid
* The APID the Service is instantiated for.
* @param setServiceId
* The Service Identifier as specified in ECSS PUS.
*/ */
PusServiceBase(object_id_t setObjectId, uint16_t setApid, uint8_t setServiceId, explicit PusServiceBase(PsbParams params);
VerificationReporterIF* reporter = nullptr);
/** /**
* The destructor is empty. * The destructor is empty.
*/ */
~PusServiceBase() override; ~PusServiceBase() override;
ReturnValue_t registerService(PUSDistributorIF& distributor);
/**
* Set the request queue which is used to receive requests. If none is set, the initialize
* function will create one
* @param reqQueue
*/
void setRequestQueue(MessageQueueIF* reqQueue);
void setTmReceiver(AcceptsTelemetryIF* tmReceiver);
void setCustomTcStore(StorageManagerIF* tcStore); void setCustomTcStore(StorageManagerIF* tcStore);
void setVerificationReporter(VerificationReporterIF* reporter); void setVerificationReporter(VerificationReporterIF* reporter);
void setCustomErrorReporter(InternalErrorReporterIF* errReporter); void setCustomErrorReporter(InternalErrorReporterIF* errReporter);
@ -136,14 +186,6 @@ class PusServiceBase : public ExecutableObjectIF,
* Will be set by setTaskIF(), which is called on task creation. * Will be set by setTaskIF(), which is called on task creation.
*/ */
PeriodicTaskIF* taskHandle = nullptr; PeriodicTaskIF* taskHandle = nullptr;
/**
* The APID of this instance of the Service.
*/
uint16_t apid;
/**
* The Service Identifier.
*/
uint8_t serviceId;
/** /**
* One of two error parameters for additional error information. * One of two error parameters for additional error information.
*/ */
@ -152,38 +194,19 @@ class PusServiceBase : public ExecutableObjectIF,
* One of two error parameters for additional error information. * One of two error parameters for additional error information.
*/ */
uint32_t errorParameter2 = 0; uint32_t errorParameter2 = 0;
/** PsbParams psbParams;
* This is a complete instance of the telecommand reception queue
* of the class. It is initialized on construction of the class.
*/
MessageQueueIF* requestQueue = nullptr;
/**
* An instance of the VerificationReporter class, that simplifies
* sending any kind of verification message to the TC Verification Service.
*/
VerificationReporterIF* verifyReporter;
/** /**
* The current Telecommand to be processed. * The current Telecommand to be processed.
* It is deleted after handleRequest was executed. * It is deleted after handleRequest was executed.
*/ */
PusTcReader currentPacket; PusTcReader currentPacket;
StorageManagerIF* tcStore = nullptr; StorageManagerIF* tcStore = nullptr;
InternalErrorReporterIF* errReporter = nullptr; bool ownedQueue = true;
static object_id_t packetSource;
static object_id_t packetDestination; static object_id_t packetDestination;
VerifSuccessParams successParams; VerifSuccessParams successParams;
private: private:
/**
* This constant sets the maximum number of packets accepted per call.
* Remember that one packet must be completely handled in one
* #handleRequest call.
*/
static const uint8_t PUS_SERVICE_MAX_RECEPTION = 10;
void handleRequestQueue(); void handleRequestQueue();
}; };

View File

@ -4,7 +4,7 @@
TmTcMessage::TmTcMessage() { this->messageSize += sizeof(store_address_t); } TmTcMessage::TmTcMessage() { this->messageSize += sizeof(store_address_t); }
TmTcMessage::~TmTcMessage() {} TmTcMessage::~TmTcMessage() = default;
store_address_t TmTcMessage::getStorageId() { store_address_t TmTcMessage::getStorageId() {
store_address_t temp_id; store_address_t temp_id;
@ -18,9 +18,9 @@ TmTcMessage::TmTcMessage(store_address_t storeId) {
} }
size_t TmTcMessage::getMinimumMessageSize() const { size_t TmTcMessage::getMinimumMessageSize() const {
return this->HEADER_SIZE + sizeof(store_address_t); return TmTcMessage::HEADER_SIZE + sizeof(store_address_t);
} }
void TmTcMessage::setStorageId(store_address_t storeId) { void TmTcMessage::setStorageId(store_address_t storeId) {
memcpy(this->getData(), &storeId, sizeof(store_address_t)); std::memcpy(this->getData(), &storeId, sizeof(store_address_t));
} }

View File

@ -18,7 +18,7 @@ class TmTcMessage : public MessageQueueMessage {
* @brief This call always returns the same fixed size of the message. * @brief This call always returns the same fixed size of the message.
* @return Returns HEADER_SIZE + @c sizeof(store_address_t). * @return Returns HEADER_SIZE + @c sizeof(store_address_t).
*/ */
size_t getMinimumMessageSize() const override; [[nodiscard]] size_t getMinimumMessageSize() const override;
public: public:
/** /**
@ -30,11 +30,11 @@ class TmTcMessage : public MessageQueueMessage {
* into the message. * into the message.
* @param packet_id The packet id to put into the message. * @param packet_id The packet id to put into the message.
*/ */
TmTcMessage(store_address_t packetId); explicit TmTcMessage(store_address_t packetId);
/** /**
* @brief The class's destructor is empty. * @brief The class's destructor is empty.
*/ */
~TmTcMessage(); ~TmTcMessage() override;
/** /**
* @brief This getter returns the packet id in the correct format. * @brief This getter returns the packet id in the correct format.
* @return Returns the packet id. * @return Returns the packet id.

View File

@ -54,7 +54,6 @@ void Factory::produceFrameworkObjects(void* args) {
// like this. Instead, this should be more like a general struct containing all important // like this. Instead, this should be more like a general struct containing all important
// object IDs which are then explicitely passed in the object constructor // object IDs which are then explicitely passed in the object constructor
void Factory::setStaticFrameworkObjectIds() { void Factory::setStaticFrameworkObjectIds() {
PusServiceBase::packetSource = objects::NO_OBJECT;
PusServiceBase::packetDestination = objects::NO_OBJECT; PusServiceBase::packetDestination = objects::NO_OBJECT;
CommandingServiceBase::defaultPacketSource = objects::NO_OBJECT; CommandingServiceBase::defaultPacketSource = objects::NO_OBJECT;

View File

@ -10,7 +10,8 @@
TEST_CASE("Action Helper", "[ActionHelper]") { TEST_CASE("Action Helper", "[ActionHelper]") {
ActionHelperOwnerMockBase testDhMock; ActionHelperOwnerMockBase testDhMock;
MessageQueueMock testMqMock; // TODO: Setting another number here breaks the test. Find out why
MessageQueueMock testMqMock(MessageQueueIF::NO_QUEUE);
ActionHelper actionHelper = ActionHelper(&testDhMock, dynamic_cast<MessageQueueIF*>(&testMqMock)); ActionHelper actionHelper = ActionHelper(&testDhMock, dynamic_cast<MessageQueueIF*>(&testMqMock));
CommandMessage actionMessage; CommandMessage actionMessage;
ActionId_t testActionId = 777; ActionId_t testActionId = 777;

View File

@ -14,7 +14,7 @@
#include "tests/TestsConfig.h" #include "tests/TestsConfig.h"
TEST_CASE("DataSetTest", "[DataSetTest]") { TEST_CASE("DataSetTest", "[DataSetTest]") {
auto queue = MessageQueueMock(); auto queue = MessageQueueMock(1);
LocalPoolOwnerBase poolOwner(queue, objects::TEST_LOCAL_POOL_OWNER_BASE); LocalPoolOwnerBase poolOwner(queue, objects::TEST_LOCAL_POOL_OWNER_BASE);
REQUIRE(poolOwner.initializeHkManager() == retval::CATCH_OK); REQUIRE(poolOwner.initializeHkManager() == retval::CATCH_OK);
REQUIRE(poolOwner.initializeHkManagerAfterTaskCreation() == retval::CATCH_OK); REQUIRE(poolOwner.initializeHkManagerAfterTaskCreation() == retval::CATCH_OK);

View File

@ -20,7 +20,7 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") {
const MessageQueueId_t hkDest = defaultDestId; const MessageQueueId_t hkDest = defaultDestId;
const MessageQueueId_t subscriberId = 2; const MessageQueueId_t subscriberId = 2;
auto hkReceiver = HkReceiverMock(hkDest); auto hkReceiver = HkReceiverMock(hkDest);
auto queue = MessageQueueMock(); auto queue = MessageQueueMock(3);
LocalPoolOwnerBase poolOwner(queue, objects::TEST_LOCAL_POOL_OWNER_BASE); LocalPoolOwnerBase poolOwner(queue, objects::TEST_LOCAL_POOL_OWNER_BASE);
REQUIRE(poolOwner.initializeHkManager() == retval::CATCH_OK); REQUIRE(poolOwner.initializeHkManager() == retval::CATCH_OK);
REQUIRE(poolOwner.initializeHkManagerAfterTaskCreation() == retval::CATCH_OK); REQUIRE(poolOwner.initializeHkManagerAfterTaskCreation() == retval::CATCH_OK);

View File

@ -8,7 +8,7 @@
#include "tests/TestsConfig.h" #include "tests/TestsConfig.h"
TEST_CASE("LocalPoolVariable", "[LocPoolVarTest]") { TEST_CASE("LocalPoolVariable", "[LocPoolVarTest]") {
auto queue = MessageQueueMock(); auto queue = MessageQueueMock(1);
LocalPoolOwnerBase poolOwner(queue, objects::TEST_LOCAL_POOL_OWNER_BASE); LocalPoolOwnerBase poolOwner(queue, objects::TEST_LOCAL_POOL_OWNER_BASE);
REQUIRE(poolOwner.initializeHkManager() == retval::CATCH_OK); REQUIRE(poolOwner.initializeHkManager() == retval::CATCH_OK);
REQUIRE(poolOwner.initializeHkManagerAfterTaskCreation() == retval::CATCH_OK); REQUIRE(poolOwner.initializeHkManagerAfterTaskCreation() == retval::CATCH_OK);

View File

@ -8,7 +8,7 @@
#include "tests/TestsConfig.h" #include "tests/TestsConfig.h"
TEST_CASE("LocalPoolVector", "[LocPoolVecTest]") { TEST_CASE("LocalPoolVector", "[LocPoolVecTest]") {
auto queue = MessageQueueMock(); auto queue = MessageQueueMock(1);
LocalPoolOwnerBase poolOwner(queue, objects::TEST_LOCAL_POOL_OWNER_BASE); LocalPoolOwnerBase poolOwner(queue, objects::TEST_LOCAL_POOL_OWNER_BASE);
REQUIRE(poolOwner.initializeHkManager() == retval::CATCH_OK); REQUIRE(poolOwner.initializeHkManager() == retval::CATCH_OK);
REQUIRE(poolOwner.initializeHkManagerAfterTaskCreation() == retval::CATCH_OK); REQUIRE(poolOwner.initializeHkManagerAfterTaskCreation() == retval::CATCH_OK);

View File

@ -0,0 +1,7 @@
#include "AcceptsTmMock.h"
AcceptsTmMock::AcceptsTmMock(MessageQueueId_t queueToReturn) : returnedQueue(queueToReturn) {}
MessageQueueId_t AcceptsTmMock::getReportReceptionQueue(uint8_t virtualChannel) {
return returnedQueue;
}

View File

@ -0,0 +1,14 @@
#ifndef FSFW_TESTS_ACCEPTSTMMOCK_H
#define FSFW_TESTS_ACCEPTSTMMOCK_H
#include "fsfw/tmtcservices/AcceptsTelemetryIF.h"
class AcceptsTmMock : public AcceptsTelemetryIF {
public:
explicit AcceptsTmMock(MessageQueueId_t queueToReturn);
MessageQueueId_t getReportReceptionQueue(uint8_t virtualChannel) override;
MessageQueueId_t returnedQueue;
};
#endif // FSFW_TESTS_ACCEPTSTMMOCK_H

View File

@ -9,4 +9,5 @@ target_sources(${FSFW_TEST_TGT} PRIVATE
LocalPoolOwnerBase.cpp LocalPoolOwnerBase.cpp
PusVerificationReporterMock.cpp PusVerificationReporterMock.cpp
PusServiceBaseMock.cpp PusServiceBaseMock.cpp
AcceptsTmMock.cpp
) )

View File

@ -3,9 +3,6 @@
#include <algorithm> #include <algorithm>
#include <stdexcept> #include <stdexcept>
MessageQueueMock::MessageQueueMock()
: MessageQueueBase(MessageQueueIF::NO_QUEUE, MessageQueueIF::NO_QUEUE, nullptr) {}
MessageQueueMock::MessageQueueMock(MessageQueueId_t queueId) MessageQueueMock::MessageQueueMock(MessageQueueId_t queueId)
: MessageQueueBase(queueId, MessageQueueIF::NO_QUEUE, nullptr) {} : MessageQueueBase(queueId, MessageQueueIF::NO_QUEUE, nullptr) {}

View File

@ -22,8 +22,6 @@ struct SendInfo {
class MessageQueueMock : public MessageQueueBase { class MessageQueueMock : public MessageQueueBase {
public: public:
MessageQueueMock();
void addReceivedMessage(MessageQueueMessageIF& msg); void addReceivedMessage(MessageQueueMessageIF& msg);
explicit MessageQueueMock(MessageQueueId_t queueId); explicit MessageQueueMock(MessageQueueId_t queueId);

View File

@ -1,7 +1,6 @@
#include "PusServiceBaseMock.h" #include "PusServiceBaseMock.h"
PsbMock::PsbMock(uint8_t service, uint16_t apid, VerificationReporterIF& verifyReporter) PsbMock::PsbMock(PsbParams params) : PusServiceBase(params) {}
: PusServiceBase(0, service, apid, &verifyReporter) {}
ReturnValue_t PsbMock::handleRequest(uint8_t subservice) { ReturnValue_t PsbMock::handleRequest(uint8_t subservice) {
handleRequestCallCnt++; handleRequestCallCnt++;
@ -27,6 +26,7 @@ void PsbMock::reset() {
performServiceCallCnt = 0; performServiceCallCnt = 0;
std::queue<uint8_t>().swap(subserviceQueue); std::queue<uint8_t>().swap(subserviceQueue);
} }
void PsbMock::makeNextHandleReqCallFail(ReturnValue_t retval) { void PsbMock::makeNextHandleReqCallFail(ReturnValue_t retval) {
handleReqFailPair.first = true; handleReqFailPair.first = true;
handleReqFailPair.second = retval; handleReqFailPair.second = retval;

View File

@ -7,7 +7,7 @@
class PsbMock : public PusServiceBase { class PsbMock : public PusServiceBase {
public: public:
PsbMock(uint8_t service, uint16_t apid, VerificationReporterIF& verifyReporter); explicit PsbMock(PsbParams params);
unsigned int handleRequestCallCnt = 0; unsigned int handleRequestCallCnt = 0;
std::queue<uint8_t> subserviceQueue; std::queue<uint8_t> subserviceQueue;
unsigned int performServiceCallCnt = 0; unsigned int performServiceCallCnt = 0;

View File

@ -1,9 +1,32 @@
#include <catch2/catch_test_macros.hpp> #include <catch2/catch_test_macros.hpp>
#include "fsfw/ipc/QueueFactory.h"
#include "mocks/AcceptsTmMock.h"
#include "mocks/MessageQueueMock.h"
#include "mocks/PusServiceBaseMock.h" #include "mocks/PusServiceBaseMock.h"
#include "mocks/PusVerificationReporterMock.h" #include "mocks/PusVerificationReporterMock.h"
TEST_CASE("Pus Service Base", "[pus-service-base]") { TEST_CASE("Pus Service Base", "[pus-service-base]") {
auto verificationReporter = PusVerificationReporterMock(); auto verificationReporter = PusVerificationReporterMock();
auto psb = PsbMock(17, 0x02, verificationReporter); auto msgQueue = MessageQueueMock(1);
auto tmReceiver = AcceptsTmMock(2);
auto psbParams = PsbParams(0, 0x02, 17);
psbParams.verifReporter = &verificationReporter;
psbParams.reqQueue = &msgQueue;
psbParams.tmReceiver = &tmReceiver;
auto psb = PsbMock(psbParams);
store_address_t dummyId(1);
auto reqQueue = psb.getRequestQueue();
TmTcMessage tmtcMsg(dummyId);
REQUIRE(psb.initialize() == HasReturnvaluesIF::RETURN_OK);
SECTION("State") {
REQUIRE(psb.getIdentifier() == 17);
REQUIRE(psb.getObjectId() == 0);
}
SECTION("Send Request") {
msgQueue.addReceivedMessage(tmtcMsg);
REQUIRE(psb.performOperation(0) == retval::OK);
}
} }

View File

@ -8,9 +8,9 @@
#include "mocks/MessageQueueMock.h" #include "mocks/MessageQueueMock.h"
TEST_CASE("TM Send Helper", "[tm-send-helper]") { TEST_CASE("TM Send Helper", "[tm-send-helper]") {
MessageQueueId_t destId = 1; MessageQueueId_t destId = 2;
auto errReporter = InternalErrorReporterMock(); auto errReporter = InternalErrorReporterMock();
auto msgQueue = MessageQueueMock(); auto msgQueue = MessageQueueMock(1);
msgQueue.setDefaultDestination(destId); msgQueue.setDefaultDestination(destId);
TmSendHelper sendHelper(msgQueue, errReporter, destId); TmSendHelper sendHelper(msgQueue, errReporter, destId);
auto timeStamper = CdsShortTimestamperMock(); auto timeStamper = CdsShortTimestamperMock();

View File

@ -17,7 +17,7 @@ TEST_CASE("TM Store And Send Helper", "[tm-store-send-helper]") {
MessageQueueId_t destId = 1; MessageQueueId_t destId = 1;
auto errReporter = InternalErrorReporterMock(); auto errReporter = InternalErrorReporterMock();
auto msgQueue = MessageQueueMock(); auto msgQueue = MessageQueueMock(2);
msgQueue.setDefaultDestination(destId); msgQueue.setDefaultDestination(destId);
TmSendHelper sendHelper(msgQueue, errReporter, destId); TmSendHelper sendHelper(msgQueue, errReporter, destId);
TmStoreAndSendWrapper tmHelper(17, storeHelper, sendHelper); TmStoreAndSendWrapper tmHelper(17, storeHelper, sendHelper);