fsfw/unittests/datapoollocal/testLocalPoolManager.cpp

142 lines
6.4 KiB
C++
Raw Normal View History

#include <fsfw/datapool/PoolReadGuard.h>
#include <fsfw/globalfunctions/timevalOperations.h>
#include <fsfw/ipc/CommandMessageCleaner.h>
#include <fsfw/objectmanager/ObjectManager.h>
#include <fsfw/timemanager/CCSDSTime.h>
#include <catch2/catch_approx.hpp>
#include <catch2/catch_test_macros.hpp>
2023-05-15 16:13:05 +02:00
#include <catch2/matchers/catch_matchers_floating_point.hpp>
#include <iostream>
#include "CatchDefinitions.h"
2024-11-07 12:26:00 +01:00
#include "mock/HkReceiverMock.h"
#include "mock/TestPoolOwner.h"
using namespace lpool;
2024-11-07 13:18:47 +01:00
TEST_CASE("Pool Owner and Periodic HK", "[datapool]") {
constexpr MessageQueueId_t defaultDestId = 1;
constexpr MessageQueueId_t hkDest = defaultDestId;
const MessageQueueId_t subscriberId = 2;
auto hkReceiver = HkReceiverMock(hkDest);
auto queue = MessageQueueMock(3);
2024-11-07 12:26:00 +01:00
TestPoolOwner poolOwner(queue, hkDest, objects::TEST_LOCAL_POOL_OWNER_BASE);
2024-11-05 17:02:45 +01:00
REQUIRE(poolOwner.initialize() == returnvalue::OK);
2022-07-25 19:49:19 +02:00
MessageQueueMock& poolOwnerMock = poolOwner.getMockQueueHandle();
CommandMessage messageSent;
2024-11-05 17:02:45 +01:00
// TODO: Fix
SECTION("Basic Test") {
{
2024-11-05 17:02:45 +01:00
// For code coverage, should not crash
2024-11-07 12:26:00 +01:00
hk::PeriodicHelper manager(nullptr, nullptr);
}
2024-11-05 17:02:45 +01:00
auto owner = poolOwner.hkHelper.getOwner();
REQUIRE(owner != nullptr);
CHECK(owner->getObjectId() == objects::TEST_LOCAL_POOL_OWNER_BASE);
2024-11-05 17:02:45 +01:00
// Clear message to avoid memory leak, our mock won't do it for us (yet)
CommandMessageCleaner::clearCommandMessage(&messageSent);
}
SECTION("PeriodicHKAndMessaging") {
2024-11-06 14:18:32 +01:00
// Now we subcribe for a HK periodic generation. Even when it's difficult to simulate
// the temporal behaviour correctly the HK manager should generate a HK packet
// immediately and the periodic helper depends on HK op function calls anyway instead of
// using the clock, so we could also just call performHkOperation multiple times
2024-11-07 13:18:47 +01:00
REQUIRE(poolOwner.enablePeriodicHk(lpool::testSid0, 30) == returnvalue::OK);
2024-11-05 17:02:45 +01:00
REQUIRE(poolOwner.hkHelper.performHkOperation() == returnvalue::OK);
// Now HK packet should be sent as message immediately.
REQUIRE(poolOwnerMock.wasMessageSent());
2022-07-25 20:31:06 +02:00
CHECK(poolOwnerMock.numberOfSentMessages() == 1);
2022-08-16 01:08:26 +02:00
CHECK(poolOwnerMock.clearLastSentMessage() == returnvalue::OK);
2024-11-06 14:18:32 +01:00
CHECK(poolOwner.hkHelper.generateHousekeepingPacket(lpool::testSid0) == returnvalue::OK);
REQUIRE(poolOwnerMock.wasMessageSent());
2022-07-25 20:31:06 +02:00
CHECK(poolOwnerMock.numberOfSentMessages() == 1);
2022-08-16 01:08:26 +02:00
CHECK(poolOwnerMock.clearLastSentMessage() == returnvalue::OK);
2024-11-06 14:18:32 +01:00
// CHECK(setHandle->getReportingEnabled() == true);
CommandMessage hkCmd;
2024-11-06 14:18:32 +01:00
HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid0, false);
2024-11-05 17:02:45 +01:00
CHECK(poolOwner.hkHelper.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
2024-11-06 14:18:32 +01:00
// CHECK(setHandle->getReportingEnabled() == false);
REQUIRE(poolOwnerMock.wasMessageSent());
2022-07-25 20:31:06 +02:00
CHECK(poolOwnerMock.numberOfSentMessages() == 1);
2022-08-16 01:08:26 +02:00
CHECK(poolOwnerMock.clearLastSentMessage() == returnvalue::OK);
2024-11-06 14:18:32 +01:00
HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid0, true);
2024-11-05 17:02:45 +01:00
CHECK(poolOwner.hkHelper.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
2024-11-06 14:18:32 +01:00
// CHECK(setHandle->getReportingEnabled() == true);
REQUIRE(poolOwnerMock.wasMessageSent());
2022-08-16 01:08:26 +02:00
CHECK(poolOwnerMock.clearLastSentMessage() == returnvalue::OK);
2024-11-06 14:18:32 +01:00
HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid0, false);
2024-11-05 17:02:45 +01:00
CHECK(poolOwner.hkHelper.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
2024-11-06 14:18:32 +01:00
// CHECK(setHandle->getReportingEnabled() == false);
REQUIRE(poolOwnerMock.wasMessageSent());
2022-08-16 01:08:26 +02:00
CHECK(poolOwnerMock.clearLastSentMessage() == returnvalue::OK);
2024-11-06 14:18:32 +01:00
HousekeepingMessage::setCollectionIntervalModificationCommand(&hkCmd, lpool::testSid0, 0.4);
2024-11-05 17:02:45 +01:00
CHECK(poolOwner.hkHelper.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
2024-11-06 14:18:32 +01:00
// CHECK_THAT(poolOwner.dataset.getCollectionInterval(), Catch::Matchers::WithinAbs(0.4, 0.01));
REQUIRE(poolOwnerMock.wasMessageSent());
2022-07-25 20:31:06 +02:00
REQUIRE(poolOwnerMock.numberOfSentMessages() == 1);
2022-08-16 01:08:26 +02:00
CHECK(poolOwnerMock.clearLastSentMessage() == returnvalue::OK);
2024-11-06 14:18:32 +01:00
HousekeepingMessage::setStructureReportingCommand(&hkCmd, lpool::testSid0);
2024-11-05 17:02:45 +01:00
REQUIRE(poolOwner.hkHelper.performHkOperation() == returnvalue::OK);
CHECK(poolOwner.hkHelper.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
// Now HK packet should be sent as message.
REQUIRE(poolOwnerMock.wasMessageSent());
2022-07-25 20:31:06 +02:00
REQUIRE(poolOwnerMock.numberOfSentMessages() == 1);
poolOwnerMock.clearMessages();
2024-11-06 14:18:32 +01:00
HousekeepingMessage::setOneShotReportCommand(&hkCmd, lpool::testSid0);
2024-11-05 17:02:45 +01:00
CHECK(poolOwner.hkHelper.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
REQUIRE(poolOwnerMock.wasMessageSent());
2022-07-25 20:31:06 +02:00
REQUIRE(poolOwnerMock.numberOfSentMessages() == 1);
poolOwnerMock.clearMessages();
2024-11-06 14:18:32 +01:00
HousekeepingMessage::setStructureReportingCommand(&hkCmd, lpool::testSid0);
2024-11-05 17:02:45 +01:00
CHECK(poolOwner.hkHelper.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
REQUIRE(poolOwnerMock.wasMessageSent());
2022-07-25 20:31:06 +02:00
REQUIRE(poolOwnerMock.numberOfSentMessages() == 1);
poolOwnerMock.clearMessages();
2024-11-06 14:18:32 +01:00
HousekeepingMessage::setCollectionIntervalModificationCommand(&hkCmd, lpool::testSid0, 0.4);
2024-11-05 17:02:45 +01:00
CHECK(poolOwner.hkHelper.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
REQUIRE(poolOwnerMock.wasMessageSent());
2022-07-25 20:31:06 +02:00
REQUIRE(poolOwnerMock.numberOfSentMessages() == 1);
poolOwnerMock.clearMessages();
2024-11-06 14:18:32 +01:00
HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid0, true);
2024-11-05 17:02:45 +01:00
CHECK(poolOwner.hkHelper.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
REQUIRE(poolOwnerMock.wasMessageSent());
2022-07-25 20:31:06 +02:00
REQUIRE(poolOwnerMock.numberOfSentMessages() == 1);
poolOwnerMock.clearMessages();
2024-11-06 14:18:32 +01:00
HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid0, false);
2024-11-05 17:02:45 +01:00
CHECK(poolOwner.hkHelper.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
REQUIRE(poolOwnerMock.wasMessageSent());
2022-07-25 20:31:06 +02:00
REQUIRE(poolOwnerMock.numberOfSentMessages() == 1);
poolOwnerMock.clearMessages();
2024-11-06 14:18:32 +01:00
HousekeepingMessage::setOneShotReportCommand(&hkCmd, lpool::testSid0);
2024-11-05 17:02:45 +01:00
CHECK(poolOwner.hkHelper.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
REQUIRE(poolOwnerMock.wasMessageSent());
2022-07-25 20:31:06 +02:00
REQUIRE(poolOwnerMock.numberOfSentMessages() == 1);
poolOwnerMock.clearMessages();
2024-11-06 14:18:32 +01:00
// poolOwner.hkHelper.printPoolEntry(lpool::uint8VarId);
}
2024-11-05 17:02:45 +01:00
// we need to reset the subscription list because the pool owner
2024-11-06 14:18:32 +01:00
// is a global object.
2022-08-16 01:08:26 +02:00
CHECK(poolOwner.reset() == returnvalue::OK);
poolOwnerMock.clearMessages(true);
}