2022-07-26 11:19:36 +02:00
|
|
|
#include <catch2/catch_test_macros.hpp>
|
|
|
|
|
|
|
|
#include "fsfw/storagemanager/LocalPool.h"
|
|
|
|
#include "fsfw/tmtcservices/TmSendHelper.h"
|
2022-07-26 13:59:09 +02:00
|
|
|
#include "fsfw/tmtcservices/TmStoreAndSendHelper.h"
|
2022-07-26 11:19:36 +02:00
|
|
|
#include "fsfw/tmtcservices/TmStoreHelper.h"
|
2024-12-12 16:15:02 +01:00
|
|
|
#include "mock/CdsShortTimestamperMock.h"
|
|
|
|
#include "mock/InternalErrorReporterMock.h"
|
|
|
|
#include "mock/MessageQueueMock.h"
|
|
|
|
#include "mock/SimpleSerializable.h"
|
2022-07-26 11:19:36 +02:00
|
|
|
|
|
|
|
TEST_CASE("TM Store And Send Helper", "[tm-store-send-helper]") {
|
|
|
|
auto timeStamper = CdsShortTimestamperMock();
|
|
|
|
LocalPool::LocalPoolConfig cfg = {{5, 32}, {2, 64}};
|
|
|
|
LocalPool pool(objects::NO_OBJECT, cfg);
|
|
|
|
auto storeHelper = TmStoreHelper(2, pool, timeStamper);
|
|
|
|
|
|
|
|
MessageQueueId_t destId = 1;
|
|
|
|
auto errReporter = InternalErrorReporterMock();
|
2024-12-12 16:15:02 +01:00
|
|
|
auto msgQueue = MessageQueueMock(2, destId);
|
2022-07-26 11:19:36 +02:00
|
|
|
TmSendHelper sendHelper(msgQueue, errReporter, destId);
|
2022-07-26 13:59:09 +02:00
|
|
|
TmStoreAndSendWrapper tmHelper(17, storeHelper, sendHelper);
|
|
|
|
|
|
|
|
SECTION("State") {
|
|
|
|
CHECK(tmHelper.sendCounter == 0);
|
|
|
|
CHECK(tmHelper.defaultService == 17);
|
|
|
|
CHECK(tmHelper.delOnFailure);
|
|
|
|
CHECK(tmHelper.incrementSendCounter);
|
|
|
|
CHECK(&tmHelper.sendHelper == &sendHelper);
|
|
|
|
CHECK(&tmHelper.storeHelper == &storeHelper);
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:42:34 +02:00
|
|
|
SECTION("Storage Fails") {
|
|
|
|
// Too large to fit in store
|
|
|
|
std::array<uint8_t, 80> data{};
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(storeHelper.setSourceDataRaw(data.data(), data.size()) == returnvalue::OK);
|
2022-07-28 13:42:34 +02:00
|
|
|
REQUIRE(tmHelper.storeAndSendTmPacket() == StorageManagerIF::DATA_TOO_LARGE);
|
|
|
|
}
|
|
|
|
|
2022-07-26 13:59:09 +02:00
|
|
|
SECTION("Base Test") {
|
|
|
|
tmHelper.prepareTmPacket(2);
|
|
|
|
auto& creator = storeHelper.getCreatorRef();
|
|
|
|
REQUIRE(creator.getSubService() == 2);
|
|
|
|
REQUIRE(creator.getService() == 17);
|
|
|
|
auto& params = creator.getParams();
|
2022-09-05 16:02:32 +02:00
|
|
|
REQUIRE(params.sourceData == nullptr);
|
2022-07-26 13:59:09 +02:00
|
|
|
REQUIRE(tmHelper.sendCounter == 0);
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(tmHelper.storeAndSendTmPacket() == returnvalue::OK);
|
2022-07-26 13:59:09 +02:00
|
|
|
REQUIRE(tmHelper.sendCounter == 1);
|
|
|
|
auto storeId = storeHelper.getCurrentAddr();
|
|
|
|
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-26 13:59:09 +02:00
|
|
|
REQUIRE(msg.getStorageId() == storeId);
|
|
|
|
REQUIRE(pool.hasDataAtId(msg.getStorageId()));
|
|
|
|
storeHelper.deletePacket();
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("Raw Data Helper") {
|
|
|
|
std::array<uint8_t, 3> data = {1, 2, 3};
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(tmHelper.prepareTmPacket(2, data.data(), data.size()) == returnvalue::OK);
|
2022-07-26 13:59:09 +02:00
|
|
|
auto& creator = storeHelper.getCreatorRef();
|
|
|
|
auto& params = creator.getParams();
|
2022-09-05 16:02:32 +02:00
|
|
|
REQUIRE(params.sourceData != nullptr);
|
|
|
|
REQUIRE(params.sourceData->getSerializedSize() == data.size());
|
|
|
|
REQUIRE(params.adapter.getConstBuffer() == data.data());
|
2022-07-26 13:59:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("Serializable Helper") {
|
|
|
|
auto simpleSer = SimpleSerializable();
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(tmHelper.prepareTmPacket(2, simpleSer) == returnvalue::OK);
|
2022-07-26 13:59:09 +02:00
|
|
|
auto& creator = storeHelper.getCreatorRef();
|
|
|
|
auto& params = creator.getParams();
|
2022-09-05 16:02:32 +02:00
|
|
|
REQUIRE(params.sourceData == &simpleSer);
|
2022-07-26 13:59:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("Object ID prefix Helper") {
|
|
|
|
uint32_t objectId = 0x01020304;
|
|
|
|
std::array<uint8_t, 3> data = {1, 2, 3};
|
|
|
|
telemetry::DataWithObjectIdPrefix dataWithObjId(objectId, data.data(), data.size());
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(tmHelper.prepareTmPacket(2, dataWithObjId) == returnvalue::OK);
|
2022-07-26 13:59:09 +02:00
|
|
|
auto& creator = storeHelper.getCreatorRef();
|
|
|
|
auto& params = creator.getParams();
|
2022-09-05 16:02:32 +02:00
|
|
|
REQUIRE(params.sourceData == &dataWithObjId);
|
2022-07-26 13:59:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Error handling
|
2022-07-26 11:19:36 +02:00
|
|
|
}
|