fsfw/unittests/tmtcservices/testSendHelper.cpp

106 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"
#include "mocks/CdsShortTimestamperMock.h"
2022-07-25 14:31:57 +02:00
#include "mocks/InternalErrorReporterMock.h"
2022-07-25 19:42:05 +02:00
#include "mocks/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();
auto msgQueue = MessageQueueMock(1);
2022-07-25 20:31:06 +02:00
msgQueue.setDefaultDestination(destId);
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;
2022-08-16 01:08:26 +02:00
REQUIRE(msgQueue.getNextSentMessage(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
}