test auto-initializers
This commit is contained in:
@ -54,7 +54,7 @@ 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::packetDestination = objects::NO_OBJECT;
|
||||
PusServiceBase::PACKET_DESTINATION = objects::NO_OBJECT;
|
||||
|
||||
CommandingServiceBase::defaultPacketSource = objects::NO_OBJECT;
|
||||
CommandingServiceBase::defaultPacketDestination = objects::NO_OBJECT;
|
||||
@ -62,9 +62,7 @@ void Factory::setStaticFrameworkObjectIds() {
|
||||
DeviceHandlerBase::powerSwitcherId = objects::NO_OBJECT;
|
||||
DeviceHandlerBase::rawDataReceiverId = objects::NO_OBJECT;
|
||||
|
||||
// TODO: Incredibly ugly, get rid of it
|
||||
LocalDataPoolManager::defaultHkDestination = objects::NO_OBJECT;
|
||||
|
||||
DeviceHandlerFailureIsolation::powerConfirmationId = objects::NO_OBJECT;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,10 @@
|
||||
#include "AcceptsTmMock.h"
|
||||
|
||||
AcceptsTmMock::AcceptsTmMock(MessageQueueId_t queueToReturn) : returnedQueue(queueToReturn) {}
|
||||
AcceptsTmMock::AcceptsTmMock(object_id_t registeredId, MessageQueueId_t queueToReturn)
|
||||
: SystemObject(registeredId), returnedQueue(queueToReturn) {}
|
||||
|
||||
AcceptsTmMock::AcceptsTmMock(MessageQueueId_t queueToReturn)
|
||||
: SystemObject(objects::NO_OBJECT, false), returnedQueue(queueToReturn) {}
|
||||
|
||||
MessageQueueId_t AcceptsTmMock::getReportReceptionQueue(uint8_t virtualChannel) {
|
||||
return returnedQueue;
|
||||
|
@ -1,10 +1,12 @@
|
||||
#ifndef FSFW_TESTS_ACCEPTSTMMOCK_H
|
||||
#define FSFW_TESTS_ACCEPTSTMMOCK_H
|
||||
|
||||
#include "fsfw/objectmanager/SystemObject.h"
|
||||
#include "fsfw/tmtcservices/AcceptsTelemetryIF.h"
|
||||
|
||||
class AcceptsTmMock : public AcceptsTelemetryIF {
|
||||
class AcceptsTmMock : public SystemObject, public AcceptsTelemetryIF {
|
||||
public:
|
||||
AcceptsTmMock(object_id_t registeredId, MessageQueueId_t queueToReturn);
|
||||
explicit AcceptsTmMock(MessageQueueId_t queueToReturn);
|
||||
|
||||
MessageQueueId_t getReportReceptionQueue(uint8_t virtualChannel) override;
|
||||
|
@ -10,4 +10,5 @@ target_sources(${FSFW_TEST_TGT} PRIVATE
|
||||
PusVerificationReporterMock.cpp
|
||||
PusServiceBaseMock.cpp
|
||||
AcceptsTmMock.cpp
|
||||
PusDistributorMock.cpp
|
||||
)
|
||||
|
@ -8,7 +8,7 @@ DeviceHandlerMock::DeviceHandlerMock(object_id_t objectId, object_id_t deviceCom
|
||||
mode = MODE_ON;
|
||||
}
|
||||
|
||||
DeviceHandlerMock::~DeviceHandlerMock() {}
|
||||
DeviceHandlerMock::~DeviceHandlerMock() = default;
|
||||
|
||||
void DeviceHandlerMock::doStartUp() { setMode(_MODE_TO_ON); }
|
||||
|
||||
|
12
unittests/mocks/PusDistributorMock.cpp
Normal file
12
unittests/mocks/PusDistributorMock.cpp
Normal file
@ -0,0 +1,12 @@
|
||||
#include "PusDistributorMock.h"
|
||||
|
||||
PusDistributorMock::PusDistributorMock() : SystemObject(objects::NO_OBJECT, false) {}
|
||||
|
||||
PusDistributorMock::PusDistributorMock(object_id_t registeredId)
|
||||
: SystemObject(registeredId, true) {}
|
||||
|
||||
ReturnValue_t PusDistributorMock::registerService(AcceptsTelecommandsIF *service) {
|
||||
registerCallCount++;
|
||||
lastServiceArg = service;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
16
unittests/mocks/PusDistributorMock.h
Normal file
16
unittests/mocks/PusDistributorMock.h
Normal file
@ -0,0 +1,16 @@
|
||||
#ifndef FSFW_TESTS_PUSDISTRIBUTORMOCK_H
|
||||
#define FSFW_TESTS_PUSDISTRIBUTORMOCK_H
|
||||
|
||||
#include "fsfw/objectmanager/SystemObject.h"
|
||||
#include "fsfw/tcdistribution/PUSDistributorIF.h"
|
||||
|
||||
class PusDistributorMock : public SystemObject, public PUSDistributorIF {
|
||||
public:
|
||||
PusDistributorMock();
|
||||
explicit PusDistributorMock(object_id_t registeredId);
|
||||
unsigned int registerCallCount = 0;
|
||||
AcceptsTelecommandsIF* lastServiceArg = nullptr;
|
||||
ReturnValue_t registerService(AcceptsTelecommandsIF* service) override;
|
||||
};
|
||||
|
||||
#endif // FSFW_TESTS_PUSDISTRIBUTORMOCK_H
|
@ -39,3 +39,15 @@ bool PsbMock::getAndPopNextSubservice(uint8_t& subservice) {
|
||||
subserviceQueue.pop();
|
||||
return true;
|
||||
}
|
||||
|
||||
PsbParams& PsbMock::getParams() { return psbParams; }
|
||||
|
||||
void PsbMock::setStaticPusDistributor(object_id_t pusDistributor) {
|
||||
PUS_DISTRIBUTOR = pusDistributor;
|
||||
}
|
||||
|
||||
object_id_t PsbMock::getStaticPusDistributor() { return PUS_DISTRIBUTOR; }
|
||||
|
||||
void PsbMock::setStaticTmDest(object_id_t tmDest) { PACKET_DESTINATION = tmDest; }
|
||||
|
||||
object_id_t PsbMock::getStaticTmDest() { return PACKET_DESTINATION; }
|
||||
|
@ -12,6 +12,13 @@ class PsbMock : public PusServiceBase {
|
||||
std::queue<uint8_t> subserviceQueue;
|
||||
unsigned int performServiceCallCnt = 0;
|
||||
|
||||
static void setStaticPusDistributor(object_id_t pusDistributor);
|
||||
static object_id_t getStaticPusDistributor();
|
||||
static void setStaticTmDest(object_id_t tmDest);
|
||||
static object_id_t getStaticTmDest();
|
||||
|
||||
PsbParams& getParams();
|
||||
|
||||
std::pair<bool, ReturnValue_t> handleReqFailPair;
|
||||
std::pair<bool, ReturnValue_t> performServiceFailPair;
|
||||
ReturnValue_t handleRequest(uint8_t subservice) override;
|
||||
|
@ -4,15 +4,18 @@
|
||||
#include "fsfw/storagemanager/LocalPool.h"
|
||||
#include "mocks/AcceptsTmMock.h"
|
||||
#include "mocks/CdsShortTimestamperMock.h"
|
||||
#include "mocks/InternalErrorReporterMock.h"
|
||||
#include "mocks/MessageQueueMock.h"
|
||||
#include "mocks/PusDistributorMock.h"
|
||||
#include "mocks/PusServiceBaseMock.h"
|
||||
#include "mocks/PusVerificationReporterMock.h"
|
||||
|
||||
TEST_CASE("Pus Service Base", "[pus-service-base]") {
|
||||
uint16_t apid = 2;
|
||||
auto verificationReporter = PusVerificationReporterMock();
|
||||
auto msgQueue = MessageQueueMock(1);
|
||||
auto tmReceiver = AcceptsTmMock(2);
|
||||
auto psbParams = PsbParams(0, 0x02, 17);
|
||||
auto psbParams = PsbParams(0, apid, 17);
|
||||
|
||||
LocalPool::LocalPoolConfig cfg = {{5, 32}, {2, 64}};
|
||||
LocalPool pool(objects::NO_OBJECT, cfg);
|
||||
@ -38,6 +41,9 @@ TEST_CASE("Pus Service Base", "[pus-service-base]") {
|
||||
SECTION("State") {
|
||||
REQUIRE(psb.getIdentifier() == 17);
|
||||
REQUIRE(psb.getObjectId() == 0);
|
||||
REQUIRE(psb.getRequestQueue() == msgQueue.getId());
|
||||
auto psbParamsLocal = psb.getParams();
|
||||
REQUIRE(psbParamsLocal.errReporter == nullptr);
|
||||
}
|
||||
|
||||
SECTION("Perform Service") {
|
||||
@ -87,4 +93,106 @@ TEST_CASE("Pus Service Base", "[pus-service-base]") {
|
||||
REQUIRE(verifParams.tcPacketId == creator.getPacketIdRaw());
|
||||
REQUIRE(verifParams.tcPsc == creator.getPacketSeqCtrlRaw());
|
||||
}
|
||||
|
||||
SECTION("Invalid Packet Sent") {
|
||||
tmtcMsg.setStorageId(store_address_t::invalid());
|
||||
msgQueue.addReceivedMessage(tmtcMsg);
|
||||
REQUIRE(psb.performOperation(0) == retval::OK);
|
||||
REQUIRE(verificationReporter.failCallCount() == 1);
|
||||
auto verifParams = verificationReporter.getNextFailCallParams();
|
||||
REQUIRE(verifParams.tcPacketId == 0);
|
||||
REQUIRE(verifParams.tcPsc == 0);
|
||||
}
|
||||
|
||||
SECTION("Set Verif Reporter") {
|
||||
auto verificationReporter2 = PusVerificationReporterMock();
|
||||
psb.setVerificationReporter(verificationReporter2);
|
||||
auto& p = psb.getParams();
|
||||
REQUIRE(p.verifReporter == &verificationReporter2);
|
||||
}
|
||||
|
||||
SECTION("Set Request Queue") {
|
||||
auto msgQueueMock = MessageQueueMock(2);
|
||||
psb.setRequestQueue(msgQueueMock);
|
||||
auto& p = psb.getParams();
|
||||
REQUIRE(p.reqQueue == &msgQueueMock);
|
||||
}
|
||||
|
||||
SECTION("Set TM Receiver") {
|
||||
auto tmReceiver2 = AcceptsTmMock(3);
|
||||
psb.setTmReceiver(tmReceiver2);
|
||||
auto& p = psb.getParams();
|
||||
REQUIRE(p.tmReceiver == &tmReceiver2);
|
||||
}
|
||||
|
||||
SECTION("Set TC Store") {
|
||||
LocalPool tcStore2(5, cfg);
|
||||
psb.setTcPool(tcStore2);
|
||||
auto& p = psb.getParams();
|
||||
REQUIRE(p.tcPool == &tcStore2);
|
||||
}
|
||||
|
||||
SECTION("Set error reporter") {
|
||||
auto errReporter = InternalErrorReporterMock();
|
||||
psb.setErrorReporter(errReporter);
|
||||
auto& p = psb.getParams();
|
||||
REQUIRE(p.errReporter == &errReporter);
|
||||
}
|
||||
SECTION("Owner Queue") {
|
||||
// This will cause the initialize function to create a new owner queue
|
||||
psbParams.reqQueue = nullptr;
|
||||
psbParams.objectId = 1;
|
||||
auto mockWithOwnerQueue = PsbMock(psbParams);
|
||||
REQUIRE(mockWithOwnerQueue.getRequestQueue() == MessageQueueIF::NO_QUEUE);
|
||||
REQUIRE(mockWithOwnerQueue.initialize() == retval::OK);
|
||||
REQUIRE(mockWithOwnerQueue.getRequestQueue() != MessageQueueIF::NO_QUEUE);
|
||||
}
|
||||
|
||||
SECTION("TM Store Helper Initializer") {
|
||||
TmStoreHelper storeHelper(0);
|
||||
psb.initializeTmStoreHelper(storeHelper);
|
||||
REQUIRE(storeHelper.getApid() == apid);
|
||||
}
|
||||
|
||||
SECTION("TM Send Helper Initializer") {
|
||||
TmSendHelper sendHelper;
|
||||
psb.initializeTmSendHelper(sendHelper);
|
||||
REQUIRE(sendHelper.getMsgQueue() == &msgQueue);
|
||||
REQUIRE(sendHelper.getDefaultDestination() == msgQueue.getDefaultDestination());
|
||||
}
|
||||
|
||||
SECTION("TM Send Helper Initializer With Error Reporter") {
|
||||
TmSendHelper sendHelper;
|
||||
auto errReporter = InternalErrorReporterMock();
|
||||
psb.setErrorReporter(errReporter);
|
||||
psb.initializeTmSendHelper(sendHelper);
|
||||
REQUIRE(sendHelper.getMsgQueue() == &msgQueue);
|
||||
REQUIRE(sendHelper.getDefaultDestination() == msgQueue.getDefaultDestination());
|
||||
REQUIRE(sendHelper.getInternalErrorReporter() == &errReporter);
|
||||
}
|
||||
|
||||
SECTION("Auto Initialize PUS Distributor") {
|
||||
psbParams.objectId = 1;
|
||||
object_id_t distributorId = 3;
|
||||
auto psb2 = PsbMock(psbParams);
|
||||
auto pusDistrib = PusDistributorMock(distributorId);
|
||||
PsbMock::setStaticPusDistributor(distributorId);
|
||||
REQUIRE(PsbMock::getStaticPusDistributor() == distributorId);
|
||||
REQUIRE(psb2.initialize() == retval::OK);
|
||||
REQUIRE(pusDistrib.registerCallCount == 1);
|
||||
REQUIRE(pusDistrib.lastServiceArg == &psb2);
|
||||
}
|
||||
|
||||
SECTION("Auto Initialize Packet Destination") {
|
||||
psbParams.tmReceiver = nullptr;
|
||||
psbParams.objectId = 1;
|
||||
object_id_t destId = 3;
|
||||
auto psb2 = PsbMock(psbParams);
|
||||
auto packetDest = AcceptsTmMock(destId, 2);
|
||||
PsbMock::setStaticTmDest(destId);
|
||||
REQUIRE(PsbMock::getStaticTmDest() == destId);
|
||||
REQUIRE(psb2.initialize() == retval::OK);
|
||||
auto& p = psb2.getParams();
|
||||
REQUIRE(p.tmReceiver == &packetDest);
|
||||
}
|
||||
}
|
||||
|
@ -33,8 +33,9 @@ TEST_CASE("TM Send Helper", "[tm-send-helper]") {
|
||||
REQUIRE(sendHelper.getDefaultDestination() == destId);
|
||||
sendHelper.setDefaultDestination(destId + 1);
|
||||
REQUIRE(sendHelper.getDefaultDestination() == destId + 1);
|
||||
sendHelper.setInternalErrorReporter(nullptr);
|
||||
REQUIRE(sendHelper.getInternalErrorReporter() == nullptr);
|
||||
auto errReporter2 = InternalErrorReporterMock();
|
||||
sendHelper.setInternalErrorReporter(errReporter2);
|
||||
REQUIRE(sendHelper.getInternalErrorReporter() == &errReporter2);
|
||||
}
|
||||
|
||||
SECTION("Default CTOR") {
|
||||
|
Reference in New Issue
Block a user