fsfw/unittests/tmtcservices/testSendHelper.cpp

105 lines
4.1 KiB
C++
Raw Normal View History

2022-07-25 13:39:07 +02:00
#include <catch2/catch_test_macros.hpp>
2022-07-25 20:31:06 +02:00
#include "fsfw/storagemanager/LocalPool.h"
#include "fsfw/tmtcservices/TmSendHelper.h"
2022-07-25 20:31:06 +02:00
#include "fsfw/tmtcservices/TmStoreHelper.h"
2024-11-07 12:26:00 +01:00
#include "mock/CdsShortTimestamperMock.h"
#include "mock/InternalErrorReporterMock.h"
#include "mock/MessageQueueMock.h"
2022-07-25 13:39:07 +02:00
TEST_CASE("TM Send Helper", "[tm-send-helper]") {
MessageQueueId_t destId = 2;
2022-07-25 14:31:57 +02:00
auto errReporter = InternalErrorReporterMock();
2024-11-07 13:32:09 +01:00
auto msgQueue = MessageQueueMock(1, destId);
2022-07-25 20:31:06 +02:00
TmSendHelper sendHelper(msgQueue, errReporter, destId);
auto timeStamper = CdsShortTimestamperMock();
LocalPool::LocalPoolConfig cfg = {{5, 32}, {2, 64}};
LocalPool pool(objects::NO_OBJECT, cfg);
auto storeHelper = TmStoreHelper(2, pool, timeStamper);
2022-07-25 14:31:57 +02:00
2022-07-25 20:31:06 +02:00
SECTION("State and Setters") {
REQUIRE(sendHelper.getInternalErrorReporter() == &errReporter);
REQUIRE(sendHelper.getDefaultDestination() == destId);
REQUIRE(sendHelper.getMsgQueue() == &msgQueue);
}
SECTION("Setters") {
REQUIRE(not sendHelper.areFaultsIgnored());
sendHelper.ignoreFaults();
REQUIRE(sendHelper.areFaultsIgnored());
sendHelper.dontIgnoreFaults();
REQUIRE(not sendHelper.areFaultsIgnored());
REQUIRE(sendHelper.getDefaultDestination() == destId);
sendHelper.setDefaultDestination(destId + 1);
REQUIRE(sendHelper.getDefaultDestination() == destId + 1);
2022-07-26 18:46:28 +02:00
auto errReporter2 = InternalErrorReporterMock();
sendHelper.setInternalErrorReporter(errReporter2);
REQUIRE(sendHelper.getInternalErrorReporter() == &errReporter2);
2022-07-25 20:31:06 +02:00
}
SECTION("Default CTOR") {
TmSendHelper emptyHelper;
REQUIRE(emptyHelper.getInternalErrorReporter() == nullptr);
REQUIRE(emptyHelper.getDefaultDestination() == MessageQueueIF::NO_QUEUE);
store_address_t dummy;
// basic robustness
2022-08-16 01:08:26 +02:00
REQUIRE(emptyHelper.sendPacket(dummy) == returnvalue::FAILED);
2022-07-25 20:31:06 +02:00
}
SECTION("One Arg CTOR") {
TmSendHelper helper(errReporter);
REQUIRE(helper.getInternalErrorReporter() == &errReporter);
REQUIRE(helper.getDefaultDestination() == MessageQueueIF::NO_QUEUE);
REQUIRE(helper.getMsgQueue() == nullptr);
}
SECTION("Two Arg CTOR") {
TmSendHelper helper(msgQueue, errReporter);
REQUIRE(helper.getInternalErrorReporter() == &errReporter);
2022-07-27 21:06:23 +02:00
REQUIRE(helper.getDefaultDestination() == 2);
2022-07-25 20:31:06 +02:00
REQUIRE(helper.getMsgQueue() == &msgQueue);
}
SECTION("Send") {
2022-08-16 01:08:26 +02:00
REQUIRE(storeHelper.preparePacket(17, 2, 0) == returnvalue::OK);
2022-07-25 20:41:01 +02:00
store_address_t storeId;
SECTION("Separate Helpers") {
2022-08-16 01:08:26 +02:00
REQUIRE(storeHelper.addPacketToStore() == returnvalue::OK);
2022-07-25 20:41:01 +02:00
storeId = storeHelper.getCurrentAddr();
2022-08-16 01:08:26 +02:00
REQUIRE(sendHelper.sendPacket(storeId) == returnvalue::OK);
2022-07-25 20:41:01 +02:00
}
2022-07-25 20:31:06 +02:00
REQUIRE(msgQueue.wasMessageSent());
REQUIRE(msgQueue.numberOfSentMessagesToDefault() == 1);
TmTcMessage msg;
2023-08-03 13:03:58 +02:00
REQUIRE(msgQueue.getNextSentMessageToDefaultDest(msg) == returnvalue::OK);
2022-07-25 20:31:06 +02:00
REQUIRE(msg.getStorageId() == storeId);
REQUIRE(pool.hasDataAtId(msg.getStorageId()));
}
SECTION("Send to Non-Default") {
storeHelper.preparePacket(17, 2, 0);
2022-08-16 01:08:26 +02:00
REQUIRE(storeHelper.addPacketToStore() == returnvalue::OK);
2022-07-25 20:31:06 +02:00
store_address_t storeId = storeHelper.getCurrentAddr();
2022-08-16 01:08:26 +02:00
REQUIRE(sendHelper.sendPacket(destId + 1, storeId) == returnvalue::OK);
2022-07-25 20:31:06 +02:00
REQUIRE(msgQueue.wasMessageSent());
REQUIRE(msgQueue.numberOfSentMessagesToDest(destId + 1) == 1);
}
SECTION("Sending fails, errors not ignored") {
2022-08-16 01:08:26 +02:00
msgQueue.makeNextSendFail(returnvalue::FAILED);
2022-07-25 20:31:06 +02:00
storeHelper.preparePacket(17, 2, 0);
2022-08-16 01:08:26 +02:00
REQUIRE(storeHelper.addPacketToStore() == returnvalue::OK);
2022-07-25 20:31:06 +02:00
store_address_t storeId = storeHelper.getCurrentAddr();
2022-08-16 01:08:26 +02:00
REQUIRE(sendHelper.sendPacket(destId + 1, storeId) == returnvalue::FAILED);
2022-07-25 20:31:06 +02:00
REQUIRE(errReporter.lostTmCallCnt == 1);
}
SECTION("Sending fails, errors ignored") {
2022-08-16 01:08:26 +02:00
msgQueue.makeNextSendFail(returnvalue::FAILED);
2022-07-25 20:31:06 +02:00
storeHelper.preparePacket(17, 2, 0);
sendHelper.ignoreFaults();
2022-08-16 01:08:26 +02:00
REQUIRE(storeHelper.addPacketToStore() == returnvalue::OK);
2022-07-25 20:31:06 +02:00
store_address_t storeId = storeHelper.getCurrentAddr();
2022-08-16 01:08:26 +02:00
REQUIRE(sendHelper.sendPacket(destId + 1, storeId) == returnvalue::FAILED);
2022-07-25 20:31:06 +02:00
REQUIRE(errReporter.lostTmCallCnt == 0);
2022-07-25 19:49:19 +02:00
}
2022-07-25 13:39:07 +02:00
}