adapt PSB so it can be unittested properly
fsfw/fsfw/pipeline/pr-development There was a failure building this commit Details

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/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;

View File

@ -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);

View File

@ -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) {

View File

@ -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;
/***

View File

@ -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;

View File

@ -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();

View File

@ -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_ */

View File

@ -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<AcceptsTelemetryIF>(packetDestination);
auto* distributor = ObjectManager::instance()->get<PUSDistributorIF>(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<AcceptsTelemetryIF>(packetDestination);
if (psbParams.tmReceiver != nullptr) {
psbParams.reqQueue->setDefaultDestination(psbParams.tmReceiver->getReportReceptionQueue());
}
}
if (tcStore == nullptr) {
tcStore = ObjectManager::instance()->get<StorageManagerIF>(objects::IPC_STORE);
tcStore = ObjectManager::instance()->get<StorageManagerIF>(objects::TC_STORE);
if (tcStore == nullptr) {
return ObjectManagerIF::CHILD_INIT_FAILED;
}
}
if (verifyReporter == nullptr) {
verifyReporter =
if (psbParams.verifReporter == nullptr) {
psbParams.verifReporter =
ObjectManager::instance()->get<VerificationReporterIF>(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<InternalErrorReporterIF>(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; }

View File

@ -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();
};

View File

@ -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));
}

View File

@ -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.

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
// 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;

View File

@ -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<MessageQueueIF*>(&testMqMock));
CommandMessage actionMessage;
ActionId_t testActionId = 777;

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

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
PusVerificationReporterMock.cpp
PusServiceBaseMock.cpp
AcceptsTmMock.cpp
)

View File

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

View File

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

View File

@ -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<uint8_t>().swap(subserviceQueue);
}
void PsbMock::makeNextHandleReqCallFail(ReturnValue_t retval) {
handleReqFailPair.first = true;
handleReqFailPair.second = retval;

View File

@ -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<uint8_t> subserviceQueue;
unsigned int performServiceCallCnt = 0;

View File

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

View File

@ -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();

View File

@ -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);