2022-07-26 13:59:09 +02:00
|
|
|
#include <catch2/catch_test_macros.hpp>
|
|
|
|
|
2022-07-26 16:49:46 +02:00
|
|
|
#include "fsfw/ipc/QueueFactory.h"
|
2022-07-26 17:41:10 +02:00
|
|
|
#include "fsfw/storagemanager/LocalPool.h"
|
2022-07-26 16:49:46 +02:00
|
|
|
#include "mocks/AcceptsTmMock.h"
|
2022-07-26 17:41:10 +02:00
|
|
|
#include "mocks/CdsShortTimestamperMock.h"
|
2022-07-26 16:49:46 +02:00
|
|
|
#include "mocks/MessageQueueMock.h"
|
2022-07-26 14:10:24 +02:00
|
|
|
#include "mocks/PusServiceBaseMock.h"
|
|
|
|
#include "mocks/PusVerificationReporterMock.h"
|
2022-07-26 13:59:09 +02:00
|
|
|
|
2022-07-26 14:10:24 +02:00
|
|
|
TEST_CASE("Pus Service Base", "[pus-service-base]") {
|
|
|
|
auto verificationReporter = PusVerificationReporterMock();
|
2022-07-26 16:49:46 +02:00
|
|
|
auto msgQueue = MessageQueueMock(1);
|
|
|
|
auto tmReceiver = AcceptsTmMock(2);
|
|
|
|
auto psbParams = PsbParams(0, 0x02, 17);
|
2022-07-26 17:41:10 +02:00
|
|
|
|
|
|
|
LocalPool::LocalPoolConfig cfg = {{5, 32}, {2, 64}};
|
|
|
|
LocalPool pool(objects::NO_OBJECT, cfg);
|
|
|
|
|
2022-07-26 16:49:46 +02:00
|
|
|
psbParams.verifReporter = &verificationReporter;
|
|
|
|
psbParams.reqQueue = &msgQueue;
|
|
|
|
psbParams.tmReceiver = &tmReceiver;
|
2022-07-26 17:41:10 +02:00
|
|
|
psbParams.tcPool = &pool;
|
2022-07-26 16:49:46 +02:00
|
|
|
auto psb = PsbMock(psbParams);
|
2022-07-26 17:41:10 +02:00
|
|
|
|
|
|
|
store_address_t storeId;
|
|
|
|
TmTcMessage tmtcMsg;
|
|
|
|
|
|
|
|
// Components to create valid PUS packets
|
|
|
|
auto packetId = PacketId(ccsds::PacketType::TC, true, 0x02);
|
|
|
|
auto spParams =
|
|
|
|
SpacePacketParams(packetId, PacketSeqCtrl(ccsds::SequenceFlags::UNSEGMENTED, 0x34), 0x00);
|
|
|
|
auto pusParams = PusTcParams(17, 1);
|
|
|
|
PusTcCreator creator(spParams, pusParams);
|
|
|
|
|
2022-07-26 16:49:46 +02:00
|
|
|
REQUIRE(psb.initialize() == HasReturnvaluesIF::RETURN_OK);
|
|
|
|
|
|
|
|
SECTION("State") {
|
|
|
|
REQUIRE(psb.getIdentifier() == 17);
|
|
|
|
REQUIRE(psb.getObjectId() == 0);
|
|
|
|
}
|
|
|
|
|
2022-07-26 17:41:10 +02:00
|
|
|
SECTION("Perform Service") {
|
|
|
|
REQUIRE(psb.performServiceCallCnt == 0);
|
|
|
|
REQUIRE(psb.performOperation(0) == retval::OK);
|
|
|
|
REQUIRE(psb.performServiceCallCnt == 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("Send Request with Successful Handling") {
|
|
|
|
REQUIRE(psb.performServiceCallCnt == 0);
|
|
|
|
uint8_t* dataPtr;
|
|
|
|
REQUIRE(pool.getFreeElement(&storeId, creator.getSerializedSize(), &dataPtr) == retval::OK);
|
|
|
|
REQUIRE(creator.serializeBe(dataPtr, creator.getSerializedSize()) == retval::OK);
|
|
|
|
tmtcMsg.setStorageId(storeId);
|
|
|
|
msgQueue.addReceivedMessage(tmtcMsg);
|
|
|
|
REQUIRE(psb.performOperation(0) == retval::OK);
|
|
|
|
uint8_t subservice = 0;
|
|
|
|
REQUIRE(psb.getAndPopNextSubservice(subservice));
|
|
|
|
REQUIRE(subservice == 1);
|
|
|
|
REQUIRE(psb.performServiceCallCnt == 1);
|
|
|
|
// PSB should take care of freeing the pool slot
|
|
|
|
REQUIRE(not pool.hasDataAtId(storeId));
|
|
|
|
REQUIRE(verificationReporter.successCallCount() == 1);
|
|
|
|
REQUIRE(verificationReporter.failCallCount() == 0);
|
|
|
|
auto verifParams = verificationReporter.getNextSuccessCallParams();
|
|
|
|
REQUIRE(verifParams.tcPacketId == creator.getPacketIdRaw());
|
|
|
|
REQUIRE(verifParams.tcPsc == creator.getPacketSeqCtrlRaw());
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("Send Request with Failed Handling") {
|
|
|
|
uint8_t* dataPtr;
|
|
|
|
REQUIRE(pool.getFreeElement(&storeId, creator.getSerializedSize(), &dataPtr) == retval::OK);
|
|
|
|
REQUIRE(creator.serializeBe(dataPtr, creator.getSerializedSize()) == retval::OK);
|
|
|
|
tmtcMsg.setStorageId(storeId);
|
2022-07-26 16:49:46 +02:00
|
|
|
msgQueue.addReceivedMessage(tmtcMsg);
|
2022-07-26 17:41:10 +02:00
|
|
|
psb.makeNextHandleReqCallFail(3);
|
2022-07-26 16:49:46 +02:00
|
|
|
REQUIRE(psb.performOperation(0) == retval::OK);
|
2022-07-26 17:41:10 +02:00
|
|
|
uint8_t subservice = 0;
|
|
|
|
REQUIRE(psb.getAndPopNextSubservice(subservice));
|
|
|
|
REQUIRE(subservice == 1);
|
|
|
|
REQUIRE(psb.performServiceCallCnt == 1);
|
|
|
|
// PSB should take care of freeing the pool slot
|
|
|
|
REQUIRE(not pool.hasDataAtId(storeId));
|
|
|
|
REQUIRE(verificationReporter.successCallCount() == 0);
|
|
|
|
REQUIRE(verificationReporter.failCallCount() == 1);
|
|
|
|
auto verifParams = verificationReporter.getNextFailCallParams();
|
|
|
|
REQUIRE(verifParams.tcPacketId == creator.getPacketIdRaw());
|
|
|
|
REQUIRE(verifParams.tcPsc == creator.getPacketSeqCtrlRaw());
|
2022-07-26 16:49:46 +02:00
|
|
|
}
|
2022-07-26 17:41:10 +02:00
|
|
|
}
|