From d98b79cf5e639abbe66420eeca42c47593b58a85 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 26 Jul 2022 16:49:46 +0200 Subject: [PATCH] adapt PSB so it can be unittested properly --- src/fsfw/pus/Service17Test.cpp | 8 +- src/fsfw/pus/Service17Test.h | 2 +- src/fsfw/pus/Service5EventReporting.cpp | 11 +- src/fsfw/pus/Service5EventReporting.h | 4 +- src/fsfw/pus/Service9TimeManagement.cpp | 4 +- src/fsfw/pus/Service9TimeManagement.h | 8 +- src/fsfw/tmtcservices/AcceptsTelemetryIF.h | 8 +- src/fsfw/tmtcservices/PusServiceBase.cpp | 106 ++++++++++-------- src/fsfw/tmtcservices/PusServiceBase.h | 97 ++++++++++------ src/fsfw/tmtcservices/TmTcMessage.cpp | 6 +- src/fsfw/tmtcservices/TmTcMessage.h | 6 +- unittests/CatchFactory.cpp | 1 - unittests/action/TestActionHelper.cpp | 3 +- unittests/datapoollocal/testDataSet.cpp | 2 +- .../datapoollocal/testLocalPoolManager.cpp | 2 +- .../datapoollocal/testLocalPoolVariable.cpp | 2 +- .../datapoollocal/testLocalPoolVector.cpp | 2 +- unittests/mocks/AcceptsTmMock.cpp | 7 ++ unittests/mocks/AcceptsTmMock.h | 14 +++ unittests/mocks/CMakeLists.txt | 1 + unittests/mocks/MessageQueueMock.cpp | 3 - unittests/mocks/MessageQueueMock.h | 2 - unittests/mocks/PusServiceBaseMock.cpp | 4 +- unittests/mocks/PusServiceBaseMock.h | 2 +- unittests/tmtcservices/testPsb.cpp | 25 ++++- unittests/tmtcservices/testSendHelper.cpp | 4 +- .../tmtcservices/testStoreAndSendHelper.cpp | 2 +- 27 files changed, 205 insertions(+), 131 deletions(-) create mode 100644 unittests/mocks/AcceptsTmMock.cpp create mode 100644 unittests/mocks/AcceptsTmMock.h diff --git a/src/fsfw/pus/Service17Test.cpp b/src/fsfw/pus/Service17Test.cpp index d526e055b..14257334e 100644 --- a/src/fsfw/pus/Service17Test.cpp +++ b/src/fsfw/pus/Service17Test.cpp @@ -5,10 +5,10 @@ #include "fsfw/objectmanager/SystemObject.h" #include "fsfw/tmtcservices/tmHelpers.h" -Service17Test::Service17Test(object_id_t objectId, uint16_t apid, uint8_t serviceId) - : PusServiceBase(objectId, apid, serviceId), - storeHelper(apid), - tmHelper(serviceId, storeHelper, sendHelper) {} +Service17Test::Service17Test(PsbParams params) + : PusServiceBase(params), + storeHelper(params.apid), + tmHelper(params.serviceId, storeHelper, sendHelper) {} Service17Test::~Service17Test() = default; diff --git a/src/fsfw/pus/Service17Test.h b/src/fsfw/pus/Service17Test.h index 7e2db98bd..f2ec6e4f5 100644 --- a/src/fsfw/pus/Service17Test.h +++ b/src/fsfw/pus/Service17Test.h @@ -34,7 +34,7 @@ class Service17Test : public PusServiceBase { EVENT_TRIGGER_TEST = 128, }; - Service17Test(object_id_t objectId, uint16_t apid, uint8_t serviceId); + explicit Service17Test(PsbParams params); void setCustomTmStore(StorageManagerIF& tmStore); diff --git a/src/fsfw/pus/Service5EventReporting.cpp b/src/fsfw/pus/Service5EventReporting.cpp index a895ad0d4..fa518d0fc 100644 --- a/src/fsfw/pus/Service5EventReporting.cpp +++ b/src/fsfw/pus/Service5EventReporting.cpp @@ -7,12 +7,11 @@ #include "fsfw/serviceinterface/ServiceInterface.h" #include "fsfw/tmtcservices/tmHelpers.h" -Service5EventReporting::Service5EventReporting(object_id_t objectId, uint16_t apid, - uint8_t serviceId, size_t maxNumberReportsPerCycle, +Service5EventReporting::Service5EventReporting(PsbParams params, size_t maxNumberReportsPerCycle, uint32_t messageQueueDepth) - : PusServiceBase(objectId, apid, serviceId), - storeHelper(apid), - tmHelper(serviceId, storeHelper, sendHelper), + : PusServiceBase(params), + storeHelper(params.apid), + tmHelper(params.serviceId, storeHelper, sendHelper), maxNumberReportsPerCycle(maxNumberReportsPerCycle) { eventQueue = QueueFactory::instance()->createMessageQueue(messageQueueDepth); } @@ -47,7 +46,7 @@ ReturnValue_t Service5EventReporting::performService() { ReturnValue_t Service5EventReporting::generateEventReport(EventMessage message) { EventReport report(message.getEventId(), message.getReporter(), message.getParameter1(), message.getParameter2()); - storeHelper.preparePacket(serviceId, message.getSeverity(), tmHelper.sendCounter); + storeHelper.preparePacket(psbParams.serviceId, message.getSeverity(), tmHelper.sendCounter); storeHelper.setSourceDataSerializable(report); ReturnValue_t result = tmHelper.storeAndSendTmPacket(); if (result != HasReturnvaluesIF::RETURN_OK) { diff --git a/src/fsfw/pus/Service5EventReporting.h b/src/fsfw/pus/Service5EventReporting.h index e6f67bfde..1f4e5a3ae 100644 --- a/src/fsfw/pus/Service5EventReporting.h +++ b/src/fsfw/pus/Service5EventReporting.h @@ -41,8 +41,8 @@ */ class Service5EventReporting : public PusServiceBase { public: - Service5EventReporting(object_id_t objectId, uint16_t apid, uint8_t serviceId, - size_t maxNumberReportsPerCycle = 10, uint32_t messageQueueDepth = 10); + Service5EventReporting(PsbParams params, size_t maxNumberReportsPerCycle = 10, + uint32_t messageQueueDepth = 10); ~Service5EventReporting() override; /*** diff --git a/src/fsfw/pus/Service9TimeManagement.cpp b/src/fsfw/pus/Service9TimeManagement.cpp index 4abbd5d2e..4a26f9933 100644 --- a/src/fsfw/pus/Service9TimeManagement.cpp +++ b/src/fsfw/pus/Service9TimeManagement.cpp @@ -5,9 +5,7 @@ #include "fsfw/serviceinterface/ServiceInterface.h" #include "fsfw/timemanager/CCSDSTime.h" -Service9TimeManagement::Service9TimeManagement(object_id_t objectId, uint16_t apid, - uint8_t serviceId) - : PusServiceBase(objectId, apid, serviceId) {} +Service9TimeManagement::Service9TimeManagement(PsbParams params) : PusServiceBase(params) {} Service9TimeManagement::~Service9TimeManagement() = default; diff --git a/src/fsfw/pus/Service9TimeManagement.h b/src/fsfw/pus/Service9TimeManagement.h index 9369e207e..b4886bb0d 100644 --- a/src/fsfw/pus/Service9TimeManagement.h +++ b/src/fsfw/pus/Service9TimeManagement.h @@ -16,16 +16,16 @@ class Service9TimeManagement : public PusServiceBase { /** * @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]. */ - virtual ReturnValue_t handleRequest(uint8_t subservice) override; + ReturnValue_t handleRequest(uint8_t subservice) override; virtual ReturnValue_t setTime(); diff --git a/src/fsfw/tmtcservices/AcceptsTelemetryIF.h b/src/fsfw/tmtcservices/AcceptsTelemetryIF.h index 0e7151301..6f8a6226c 100644 --- a/src/fsfw/tmtcservices/AcceptsTelemetryIF.h +++ b/src/fsfw/tmtcservices/AcceptsTelemetryIF.h @@ -1,7 +1,7 @@ #ifndef 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 * Telemetry. @@ -13,13 +13,15 @@ class AcceptsTelemetryIF { /** * @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 * receiving message queue. * @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_ */ diff --git a/src/fsfw/tmtcservices/PusServiceBase.cpp b/src/fsfw/tmtcservices/PusServiceBase.cpp index 7ee5f8c6d..8d250a0f7 100644 --- a/src/fsfw/tmtcservices/PusServiceBase.cpp +++ b/src/fsfw/tmtcservices/PusServiceBase.cpp @@ -9,19 +9,16 @@ #include "fsfw/tmtcservices/TmTcMessage.h" #include "fsfw/tmtcservices/tcHelpers.h" -object_id_t PusServiceBase::packetSource = 0; object_id_t PusServiceBase::packetDestination = 0; -PusServiceBase::PusServiceBase(object_id_t setObjectId, uint16_t setApid, uint8_t setServiceId, - VerificationReporterIF* verifyReporter) - : SystemObject(setObjectId), - apid(setApid), - serviceId(setServiceId), - verifyReporter(verifyReporter) { - requestQueue = QueueFactory::instance()->createMessageQueue(PUS_SERVICE_MAX_RECEPTION); -} +PusServiceBase::PusServiceBase(PsbParams params) + : SystemObject(params.objectId), psbParams(params) {} -PusServiceBase::~PusServiceBase() { QueueFactory::instance()->deleteMessageQueue(requestQueue); } +PusServiceBase::~PusServiceBase() { + if (ownedQueue) { + QueueFactory::instance()->deleteMessageQueue(psbParams.reqQueue); + } +} ReturnValue_t PusServiceBase::performOperation(uint8_t opCode) { handleRequestQueue(); @@ -42,7 +39,7 @@ void PusServiceBase::handleRequestQueue() { TmTcMessage message; ReturnValue_t result; 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) { break; } else if (status != HasReturnvaluesIF::RETURN_OK) { @@ -53,27 +50,27 @@ void PusServiceBase::handleRequestQueue() { #else sif::printError( "PusServiceBase::performOperation: Service %d. Error receiving packet. Code: %04x\n", - serviceId, status); + psbParams.serviceId, status); #endif break; } result = tc::prepareTcReader(tcStore, message.getStorageId(), currentPacket); if (result != HasReturnvaluesIF::RETURN_OK) { - auto params = VerifFailureParams(tcverif::START_FAILURE, currentPacket, result); - params.errorParam1 = errorParameter1; - params.errorParam2 = errorParameter2; - verifyReporter->sendFailureReport(params); + auto verifParams = VerifFailureParams(tcverif::START_FAILURE, currentPacket, result); + verifParams.errorParam1 = errorParameter1; + verifParams.errorParam2 = errorParameter2; + psbParams.verifReporter->sendFailureReport(verifParams); continue; } result = handleRequest(currentPacket.getSubService()); if (result == RETURN_OK) { - verifyReporter->sendSuccessReport( + psbParams.verifReporter->sendSuccessReport( VerifSuccessParams(tcverif::COMPLETION_SUCCESS, currentPacket)); } else { - auto params = VerifFailureParams(tcverif::COMPLETION_FAILURE, currentPacket, result); - params.errorParam1 = errorParameter1; - params.errorParam2 = errorParameter2; - verifyReporter->sendFailureReport(params); + auto failParams = VerifFailureParams(tcverif::COMPLETION_FAILURE, currentPacket, result); + failParams.errorParam1 = errorParameter1; + failParams.errorParam2 = errorParameter2; + psbParams.verifReporter->sendFailureReport(failParams); } tcStore->deleteData(message.getStorageId()); 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 result = SystemObject::initialize(); if (result != RETURN_OK) { return result; } - auto* destService = ObjectManager::instance()->get(packetDestination); - auto* distributor = ObjectManager::instance()->get(packetSource); - if (destService == nullptr or distributor == nullptr) { -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "PusServiceBase::PusServiceBase: Service " << this->serviceId - << ": Configuration error. Make sure " - << "packetSource and packetDestination are defined correctly" << std::endl; -#endif - return ObjectManagerIF::CHILD_INIT_FAILED; + if (psbParams.reqQueue == nullptr) { + ownedQueue = true; + psbParams.reqQueue = QueueFactory::instance()->createMessageQueue(PSB_DEFAULT_QUEUE_DEPTH); + } else { + ownedQueue = false; } - this->requestQueue->setDefaultDestination(destService->getReportReceptionQueue()); - distributor->registerService(this); + if (psbParams.tmReceiver == nullptr) { + psbParams.tmReceiver = ObjectManager::instance()->get(packetDestination); + if (psbParams.tmReceiver != nullptr) { + psbParams.reqQueue->setDefaultDestination(psbParams.tmReceiver->getReportReceptionQueue()); + } + } + if (tcStore == nullptr) { - tcStore = ObjectManager::instance()->get(objects::IPC_STORE); + tcStore = ObjectManager::instance()->get(objects::TC_STORE); if (tcStore == nullptr) { return ObjectManagerIF::CHILD_INIT_FAILED; } } - if (verifyReporter == nullptr) { - verifyReporter = + + if (psbParams.verifReporter == nullptr) { + psbParams.verifReporter = ObjectManager::instance()->get(objects::TC_VERIFICATOR); - if (verifyReporter == nullptr) { + if (psbParams.verifReporter == nullptr) { return ObjectManagerIF::CHILD_INIT_FAILED; } } @@ -128,7 +127,7 @@ ReturnValue_t PusServiceBase::initializeAfterTaskCreation() { void PusServiceBase::setCustomTcStore(StorageManagerIF* tcStore_) { tcStore = tcStore_; } void PusServiceBase::setCustomErrorReporter(InternalErrorReporterIF* errReporter_) { - errReporter = errReporter_; + psbParams.errReporter = errReporter_; } void PusServiceBase::initializeTmHelpers(TmSendHelper& tmSendHelper, TmStoreHelper& tmStoreHelper) { @@ -137,21 +136,34 @@ void PusServiceBase::initializeTmHelpers(TmSendHelper& tmSendHelper, TmStoreHelp } void PusServiceBase::initializeTmSendHelper(TmSendHelper& tmSendHelper) { - tmSendHelper.setMsgQueue(*requestQueue); - tmSendHelper.setDefaultDestination(requestQueue->getDefaultDestination()); - if (errReporter == nullptr) { - errReporter = + if (psbParams.reqQueue != nullptr) { + tmSendHelper.setMsgQueue(*psbParams.reqQueue); + tmSendHelper.setDefaultDestination(psbParams.reqQueue->getDefaultDestination()); + } + + if (psbParams.errReporter == nullptr) { + psbParams.errReporter = ObjectManager::instance()->get(objects::INTERNAL_ERROR_REPORTER); - if (errReporter != nullptr) { - tmSendHelper.setInternalErrorReporter(errReporter); + if (psbParams.errReporter != nullptr) { + tmSendHelper.setInternalErrorReporter(psbParams.errReporter); } } } void PusServiceBase::initializeTmStoreHelper(TmStoreHelper& tmStoreHelper) const { - tmStoreHelper.setApid(apid); + tmStoreHelper.setApid(psbParams.apid); } 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; } diff --git a/src/fsfw/tmtcservices/PusServiceBase.h b/src/fsfw/tmtcservices/PusServiceBase.h index 4aa6fadec..fabe61412 100644 --- a/src/fsfw/tmtcservices/PusServiceBase.h +++ b/src/fsfw/tmtcservices/PusServiceBase.h @@ -2,6 +2,7 @@ #define FSFW_TMTCSERVICES_PUSSERVICEBASE_H_ #include "AcceptsTelecommandsIF.h" +#include "AcceptsTelemetryIF.h" #include "TmSendHelper.h" #include "TmStoreHelper.h" #include "VerificationCodes.h" @@ -11,6 +12,7 @@ #include "fsfw/objectmanager/SystemObject.h" #include "fsfw/returnvalues/HasReturnvaluesIF.h" #include "fsfw/tasks/ExecutableObjectIF.h" +#include "fsfw/tcdistribution/PUSDistributorIF.h" namespace Factory { void setStaticFrameworkObjectIds(); @@ -18,6 +20,44 @@ void setStaticFrameworkObjectIds(); 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 * These group contains all implementations of PUS Services in the OBSW. @@ -43,23 +83,33 @@ class PusServiceBase : public ExecutableObjectIF, friend void(Factory::setStaticFrameworkObjectIds)(); 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 * done in the initialize method. - * @param setObjectId - * 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. + * @param params All configuration parameters for the PUS Service Base */ - PusServiceBase(object_id_t setObjectId, uint16_t setApid, uint8_t setServiceId, - VerificationReporterIF* reporter = nullptr); + explicit PusServiceBase(PsbParams params); /** * The destructor is empty. */ ~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 setVerificationReporter(VerificationReporterIF* reporter); void setCustomErrorReporter(InternalErrorReporterIF* errReporter); @@ -136,14 +186,6 @@ class PusServiceBase : public ExecutableObjectIF, * Will be set by setTaskIF(), which is called on task creation. */ 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. */ @@ -152,38 +194,19 @@ class PusServiceBase : public ExecutableObjectIF, * One of two error parameters for additional error information. */ uint32_t errorParameter2 = 0; - /** - * 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; - + PsbParams psbParams; /** * The current Telecommand to be processed. * It is deleted after handleRequest was executed. */ PusTcReader currentPacket; StorageManagerIF* tcStore = nullptr; - InternalErrorReporterIF* errReporter = nullptr; - - static object_id_t packetSource; + bool ownedQueue = true; static object_id_t packetDestination; VerifSuccessParams successParams; 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(); }; diff --git a/src/fsfw/tmtcservices/TmTcMessage.cpp b/src/fsfw/tmtcservices/TmTcMessage.cpp index ca76760f3..bd071b5bb 100644 --- a/src/fsfw/tmtcservices/TmTcMessage.cpp +++ b/src/fsfw/tmtcservices/TmTcMessage.cpp @@ -4,7 +4,7 @@ TmTcMessage::TmTcMessage() { this->messageSize += sizeof(store_address_t); } -TmTcMessage::~TmTcMessage() {} +TmTcMessage::~TmTcMessage() = default; store_address_t TmTcMessage::getStorageId() { store_address_t temp_id; @@ -18,9 +18,9 @@ TmTcMessage::TmTcMessage(store_address_t storeId) { } 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) { - memcpy(this->getData(), &storeId, sizeof(store_address_t)); + std::memcpy(this->getData(), &storeId, sizeof(store_address_t)); } diff --git a/src/fsfw/tmtcservices/TmTcMessage.h b/src/fsfw/tmtcservices/TmTcMessage.h index a0f67894b..3fba6d7a9 100644 --- a/src/fsfw/tmtcservices/TmTcMessage.h +++ b/src/fsfw/tmtcservices/TmTcMessage.h @@ -18,7 +18,7 @@ class TmTcMessage : public MessageQueueMessage { * @brief This call always returns the same fixed size of the message. * @return Returns HEADER_SIZE + @c sizeof(store_address_t). */ - size_t getMinimumMessageSize() const override; + [[nodiscard]] size_t getMinimumMessageSize() const override; public: /** @@ -30,11 +30,11 @@ class TmTcMessage : public MessageQueueMessage { * 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. */ - ~TmTcMessage(); + ~TmTcMessage() override; /** * @brief This getter returns the packet id in the correct format. * @return Returns the packet id. diff --git a/unittests/CatchFactory.cpp b/unittests/CatchFactory.cpp index 5ae5a9fb3..1d10c5829 100644 --- a/unittests/CatchFactory.cpp +++ b/unittests/CatchFactory.cpp @@ -54,7 +54,6 @@ void Factory::produceFrameworkObjects(void* args) { // 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 void Factory::setStaticFrameworkObjectIds() { - PusServiceBase::packetSource = objects::NO_OBJECT; PusServiceBase::packetDestination = objects::NO_OBJECT; CommandingServiceBase::defaultPacketSource = objects::NO_OBJECT; diff --git a/unittests/action/TestActionHelper.cpp b/unittests/action/TestActionHelper.cpp index bf5589abb..849e57d22 100644 --- a/unittests/action/TestActionHelper.cpp +++ b/unittests/action/TestActionHelper.cpp @@ -10,7 +10,8 @@ TEST_CASE("Action Helper", "[ActionHelper]") { 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(&testMqMock)); CommandMessage actionMessage; ActionId_t testActionId = 777; diff --git a/unittests/datapoollocal/testDataSet.cpp b/unittests/datapoollocal/testDataSet.cpp index 0ef5a77f8..532208f5f 100644 --- a/unittests/datapoollocal/testDataSet.cpp +++ b/unittests/datapoollocal/testDataSet.cpp @@ -14,7 +14,7 @@ #include "tests/TestsConfig.h" TEST_CASE("DataSetTest", "[DataSetTest]") { - auto queue = MessageQueueMock(); + auto queue = MessageQueueMock(1); LocalPoolOwnerBase poolOwner(queue, objects::TEST_LOCAL_POOL_OWNER_BASE); REQUIRE(poolOwner.initializeHkManager() == retval::CATCH_OK); REQUIRE(poolOwner.initializeHkManagerAfterTaskCreation() == retval::CATCH_OK); diff --git a/unittests/datapoollocal/testLocalPoolManager.cpp b/unittests/datapoollocal/testLocalPoolManager.cpp index e5282c16f..bdeec8c0d 100644 --- a/unittests/datapoollocal/testLocalPoolManager.cpp +++ b/unittests/datapoollocal/testLocalPoolManager.cpp @@ -20,7 +20,7 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") { const MessageQueueId_t hkDest = defaultDestId; const MessageQueueId_t subscriberId = 2; auto hkReceiver = HkReceiverMock(hkDest); - auto queue = MessageQueueMock(); + auto queue = MessageQueueMock(3); LocalPoolOwnerBase poolOwner(queue, objects::TEST_LOCAL_POOL_OWNER_BASE); REQUIRE(poolOwner.initializeHkManager() == retval::CATCH_OK); REQUIRE(poolOwner.initializeHkManagerAfterTaskCreation() == retval::CATCH_OK); diff --git a/unittests/datapoollocal/testLocalPoolVariable.cpp b/unittests/datapoollocal/testLocalPoolVariable.cpp index dda5aca64..b3ae07e0b 100644 --- a/unittests/datapoollocal/testLocalPoolVariable.cpp +++ b/unittests/datapoollocal/testLocalPoolVariable.cpp @@ -8,7 +8,7 @@ #include "tests/TestsConfig.h" TEST_CASE("LocalPoolVariable", "[LocPoolVarTest]") { - auto queue = MessageQueueMock(); + auto queue = MessageQueueMock(1); LocalPoolOwnerBase poolOwner(queue, objects::TEST_LOCAL_POOL_OWNER_BASE); REQUIRE(poolOwner.initializeHkManager() == retval::CATCH_OK); REQUIRE(poolOwner.initializeHkManagerAfterTaskCreation() == retval::CATCH_OK); diff --git a/unittests/datapoollocal/testLocalPoolVector.cpp b/unittests/datapoollocal/testLocalPoolVector.cpp index dc91fa7e7..e04bf6437 100644 --- a/unittests/datapoollocal/testLocalPoolVector.cpp +++ b/unittests/datapoollocal/testLocalPoolVector.cpp @@ -8,7 +8,7 @@ #include "tests/TestsConfig.h" TEST_CASE("LocalPoolVector", "[LocPoolVecTest]") { - auto queue = MessageQueueMock(); + auto queue = MessageQueueMock(1); LocalPoolOwnerBase poolOwner(queue, objects::TEST_LOCAL_POOL_OWNER_BASE); REQUIRE(poolOwner.initializeHkManager() == retval::CATCH_OK); REQUIRE(poolOwner.initializeHkManagerAfterTaskCreation() == retval::CATCH_OK); diff --git a/unittests/mocks/AcceptsTmMock.cpp b/unittests/mocks/AcceptsTmMock.cpp new file mode 100644 index 000000000..9142308d3 --- /dev/null +++ b/unittests/mocks/AcceptsTmMock.cpp @@ -0,0 +1,7 @@ +#include "AcceptsTmMock.h" + +AcceptsTmMock::AcceptsTmMock(MessageQueueId_t queueToReturn) : returnedQueue(queueToReturn) {} + +MessageQueueId_t AcceptsTmMock::getReportReceptionQueue(uint8_t virtualChannel) { + return returnedQueue; +} diff --git a/unittests/mocks/AcceptsTmMock.h b/unittests/mocks/AcceptsTmMock.h new file mode 100644 index 000000000..b0ccc9a7b --- /dev/null +++ b/unittests/mocks/AcceptsTmMock.h @@ -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 diff --git a/unittests/mocks/CMakeLists.txt b/unittests/mocks/CMakeLists.txt index 00732c80a..5bb37db48 100644 --- a/unittests/mocks/CMakeLists.txt +++ b/unittests/mocks/CMakeLists.txt @@ -9,4 +9,5 @@ target_sources(${FSFW_TEST_TGT} PRIVATE LocalPoolOwnerBase.cpp PusVerificationReporterMock.cpp PusServiceBaseMock.cpp + AcceptsTmMock.cpp ) diff --git a/unittests/mocks/MessageQueueMock.cpp b/unittests/mocks/MessageQueueMock.cpp index c514cc2eb..215a7830d 100644 --- a/unittests/mocks/MessageQueueMock.cpp +++ b/unittests/mocks/MessageQueueMock.cpp @@ -3,9 +3,6 @@ #include #include -MessageQueueMock::MessageQueueMock() - : MessageQueueBase(MessageQueueIF::NO_QUEUE, MessageQueueIF::NO_QUEUE, nullptr) {} - MessageQueueMock::MessageQueueMock(MessageQueueId_t queueId) : MessageQueueBase(queueId, MessageQueueIF::NO_QUEUE, nullptr) {} diff --git a/unittests/mocks/MessageQueueMock.h b/unittests/mocks/MessageQueueMock.h index 0be682233..52ba5dfec 100644 --- a/unittests/mocks/MessageQueueMock.h +++ b/unittests/mocks/MessageQueueMock.h @@ -22,8 +22,6 @@ struct SendInfo { class MessageQueueMock : public MessageQueueBase { public: - MessageQueueMock(); - void addReceivedMessage(MessageQueueMessageIF& msg); explicit MessageQueueMock(MessageQueueId_t queueId); diff --git a/unittests/mocks/PusServiceBaseMock.cpp b/unittests/mocks/PusServiceBaseMock.cpp index 4eb51fa49..ef36d09e6 100644 --- a/unittests/mocks/PusServiceBaseMock.cpp +++ b/unittests/mocks/PusServiceBaseMock.cpp @@ -1,7 +1,6 @@ #include "PusServiceBaseMock.h" -PsbMock::PsbMock(uint8_t service, uint16_t apid, VerificationReporterIF& verifyReporter) - : PusServiceBase(0, service, apid, &verifyReporter) {} +PsbMock::PsbMock(PsbParams params) : PusServiceBase(params) {} ReturnValue_t PsbMock::handleRequest(uint8_t subservice) { handleRequestCallCnt++; @@ -27,6 +26,7 @@ void PsbMock::reset() { performServiceCallCnt = 0; std::queue().swap(subserviceQueue); } + void PsbMock::makeNextHandleReqCallFail(ReturnValue_t retval) { handleReqFailPair.first = true; handleReqFailPair.second = retval; diff --git a/unittests/mocks/PusServiceBaseMock.h b/unittests/mocks/PusServiceBaseMock.h index 9d1bac5d5..42620662e 100644 --- a/unittests/mocks/PusServiceBaseMock.h +++ b/unittests/mocks/PusServiceBaseMock.h @@ -7,7 +7,7 @@ class PsbMock : public PusServiceBase { public: - PsbMock(uint8_t service, uint16_t apid, VerificationReporterIF& verifyReporter); + explicit PsbMock(PsbParams params); unsigned int handleRequestCallCnt = 0; std::queue subserviceQueue; unsigned int performServiceCallCnt = 0; diff --git a/unittests/tmtcservices/testPsb.cpp b/unittests/tmtcservices/testPsb.cpp index ea4aee617..53fe763dd 100644 --- a/unittests/tmtcservices/testPsb.cpp +++ b/unittests/tmtcservices/testPsb.cpp @@ -1,9 +1,32 @@ #include +#include "fsfw/ipc/QueueFactory.h" +#include "mocks/AcceptsTmMock.h" +#include "mocks/MessageQueueMock.h" #include "mocks/PusServiceBaseMock.h" #include "mocks/PusVerificationReporterMock.h" TEST_CASE("Pus Service Base", "[pus-service-base]") { 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); + } } \ No newline at end of file diff --git a/unittests/tmtcservices/testSendHelper.cpp b/unittests/tmtcservices/testSendHelper.cpp index 786fe0738..82adc04bf 100644 --- a/unittests/tmtcservices/testSendHelper.cpp +++ b/unittests/tmtcservices/testSendHelper.cpp @@ -8,9 +8,9 @@ #include "mocks/MessageQueueMock.h" TEST_CASE("TM Send Helper", "[tm-send-helper]") { - MessageQueueId_t destId = 1; + MessageQueueId_t destId = 2; auto errReporter = InternalErrorReporterMock(); - auto msgQueue = MessageQueueMock(); + auto msgQueue = MessageQueueMock(1); msgQueue.setDefaultDestination(destId); TmSendHelper sendHelper(msgQueue, errReporter, destId); auto timeStamper = CdsShortTimestamperMock(); diff --git a/unittests/tmtcservices/testStoreAndSendHelper.cpp b/unittests/tmtcservices/testStoreAndSendHelper.cpp index 2a5226002..73051f8e1 100644 --- a/unittests/tmtcservices/testStoreAndSendHelper.cpp +++ b/unittests/tmtcservices/testStoreAndSendHelper.cpp @@ -17,7 +17,7 @@ TEST_CASE("TM Store And Send Helper", "[tm-store-send-helper]") { MessageQueueId_t destId = 1; auto errReporter = InternalErrorReporterMock(); - auto msgQueue = MessageQueueMock(); + auto msgQueue = MessageQueueMock(2); msgQueue.setDefaultDestination(destId); TmSendHelper sendHelper(msgQueue, errReporter, destId); TmStoreAndSendWrapper tmHelper(17, storeHelper, sendHelper);