2022-07-25 19:36:56 +02:00
|
|
|
#include <fsfw/datapool/PoolReadGuard.h>
|
|
|
|
#include <fsfw/datapoollocal/HasLocalDataPoolIF.h>
|
|
|
|
#include <fsfw/datapoollocal/StaticLocalDataSet.h>
|
|
|
|
#include <fsfw/globalfunctions/timevalOperations.h>
|
|
|
|
#include <fsfw/housekeeping/HousekeepingSnapshot.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>
|
2022-07-25 19:36:56 +02:00
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include "CatchDefinitions.h"
|
|
|
|
#include "mocks/HkReceiverMock.h"
|
2022-07-25 20:31:06 +02:00
|
|
|
#include "mocks/LocalPoolOwnerBase.h"
|
2022-07-25 19:36:56 +02:00
|
|
|
|
|
|
|
TEST_CASE("Local Pool Manager Tests", "[LocManTest]") {
|
|
|
|
const MessageQueueId_t defaultDestId = 1;
|
|
|
|
const MessageQueueId_t hkDest = defaultDestId;
|
|
|
|
const MessageQueueId_t subscriberId = 2;
|
|
|
|
auto hkReceiver = HkReceiverMock(hkDest);
|
2022-07-26 16:49:46 +02:00
|
|
|
auto queue = MessageQueueMock(3);
|
2022-07-25 19:36:56 +02:00
|
|
|
LocalPoolOwnerBase poolOwner(queue, objects::TEST_LOCAL_POOL_OWNER_BASE);
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(poolOwner.initializeHkManager() == returnvalue::OK);
|
|
|
|
REQUIRE(poolOwner.initializeHkManagerAfterTaskCreation() == returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
|
2022-07-25 19:49:19 +02:00
|
|
|
MessageQueueMock& poolOwnerMock = poolOwner.getMockQueueHandle();
|
2022-07-25 19:36:56 +02:00
|
|
|
|
|
|
|
// TODO: This is ugly. This should be an arbitrary ctor argument. Fix this in the pool
|
|
|
|
// manager
|
|
|
|
poolOwnerMock.setDefaultDestination(defaultDestId);
|
|
|
|
poolOwner.setHkDestId(hkDest);
|
|
|
|
|
|
|
|
auto* hkMan = poolOwner.getHkManagerHandle();
|
|
|
|
|
|
|
|
CommandMessage messageSent;
|
|
|
|
|
|
|
|
SECTION("Basic Test") {
|
|
|
|
{
|
|
|
|
/* For code coverage, should not crash */
|
2024-11-04 17:32:21 +01:00
|
|
|
PeriodicHkGenerationHelper manager(nullptr, nullptr);
|
2022-07-25 19:36:56 +02:00
|
|
|
}
|
|
|
|
auto owner = poolOwner.poolManager.getOwner();
|
|
|
|
REQUIRE(owner != nullptr);
|
|
|
|
CHECK(owner->getObjectId() == objects::TEST_LOCAL_POOL_OWNER_BASE);
|
|
|
|
|
|
|
|
/* Subscribe for message generation on update. */
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(poolOwner.subscribeWrapperSetUpdate(subscriberId) == returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
/* Subscribe for an update message. */
|
|
|
|
poolOwner.dataset.setChanged(true);
|
|
|
|
/* Now the update message should be generated. */
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(poolOwner.poolManager.performHkOperation() == returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
REQUIRE(poolOwnerMock.wasMessageSent());
|
|
|
|
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
CHECK(messageSent.getCommand() ==
|
|
|
|
static_cast<int>(HousekeepingMessage::UPDATE_NOTIFICATION_SET));
|
|
|
|
|
|
|
|
/* Should have been reset. */
|
|
|
|
CHECK(poolOwner.dataset.hasChanged() == false);
|
|
|
|
poolOwnerMock.clearMessages(true);
|
|
|
|
/* Set changed again, result should be the same. */
|
|
|
|
poolOwner.dataset.setChanged(true);
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(poolOwner.poolManager.performHkOperation() == returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
|
|
|
|
REQUIRE(poolOwnerMock.wasMessageSent() == true);
|
2022-07-25 20:31:06 +02:00
|
|
|
CHECK(poolOwnerMock.numberOfSentMessages() == 1);
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
CHECK(messageSent.getCommand() ==
|
|
|
|
static_cast<int>(HousekeepingMessage::UPDATE_NOTIFICATION_SET));
|
|
|
|
|
|
|
|
poolOwnerMock.clearMessages(true);
|
|
|
|
/* Now subscribe for set update HK as well. */
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(poolOwner.subscribeWrapperSetUpdateHk(false, &hkReceiver) == returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
poolOwner.dataset.setChanged(true);
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(poolOwner.poolManager.performHkOperation() == returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
REQUIRE(poolOwnerMock.wasMessageSent() == true);
|
2022-07-25 20:31:06 +02:00
|
|
|
CHECK(poolOwnerMock.numberOfSentMessages() == 2);
|
2022-07-25 19:36:56 +02:00
|
|
|
// first message sent should be the update notification
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
CHECK(messageSent.getCommand() ==
|
|
|
|
static_cast<int>(HousekeepingMessage::UPDATE_NOTIFICATION_SET));
|
2023-08-03 13:03:58 +02:00
|
|
|
REQUIRE(poolOwnerMock.getNextSentMessageToDefaultDest(messageSent) == returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
CHECK(messageSent.getCommand() == static_cast<int>(HousekeepingMessage::HK_REPORT));
|
|
|
|
/* Clear message to avoid memory leak, our mock won't do it for us (yet) */
|
|
|
|
CommandMessageCleaner::clearCommandMessage(&messageSent);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("SetSnapshotUpdateTest") {
|
|
|
|
/* Set the variables in the set to certain values. These are checked later. */
|
|
|
|
{
|
|
|
|
PoolReadGuard readHelper(&poolOwner.dataset);
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(readHelper.getReadResult() == returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
poolOwner.dataset.localPoolVarUint8.value = 5;
|
|
|
|
poolOwner.dataset.localPoolVarFloat.value = -12.242;
|
|
|
|
poolOwner.dataset.localPoolUint16Vec.value[0] = 2;
|
|
|
|
poolOwner.dataset.localPoolUint16Vec.value[1] = 32;
|
|
|
|
poolOwner.dataset.localPoolUint16Vec.value[2] = 42932;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Subscribe for snapshot generation on update. */
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(poolOwner.subscribeWrapperSetUpdateSnapshot(subscriberId) == returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
poolOwner.dataset.setChanged(true);
|
|
|
|
|
|
|
|
/* Store current time, we are going to check the (approximate) time equality later */
|
|
|
|
timeval now{};
|
|
|
|
Clock::getClock_timeval(&now);
|
|
|
|
|
|
|
|
/* Trigger generation of snapshot */
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(poolOwner.poolManager.performHkOperation() == returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
REQUIRE(poolOwnerMock.wasMessageSent());
|
2022-07-25 20:31:06 +02:00
|
|
|
CHECK(poolOwnerMock.numberOfSentMessages() == 1);
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
/* Check that snapshot was generated */
|
|
|
|
CHECK(messageSent.getCommand() == static_cast<int>(HousekeepingMessage::UPDATE_SNAPSHOT_SET));
|
|
|
|
/* Now we deserialize the snapshot into a new dataset instance */
|
|
|
|
CCSDSTime::CDS_short cdsShort{};
|
|
|
|
LocalPoolTestDataSet newSet;
|
|
|
|
HousekeepingSnapshot snapshot(&cdsShort, &newSet);
|
|
|
|
store_address_t storeId;
|
|
|
|
HousekeepingMessage::getUpdateSnapshotSetCommand(&messageSent, &storeId);
|
|
|
|
ConstAccessorPair accessorPair = tglob::getIpcStoreHandle()->getData(storeId);
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(accessorPair.first == returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
const uint8_t* readOnlyPtr = accessorPair.second.data();
|
|
|
|
size_t sizeToDeserialize = accessorPair.second.size();
|
|
|
|
CHECK(newSet.localPoolVarFloat.value == 0);
|
|
|
|
CHECK(newSet.localPoolVarUint8 == 0);
|
|
|
|
CHECK(newSet.localPoolUint16Vec.value[0] == 0);
|
|
|
|
CHECK(newSet.localPoolUint16Vec.value[1] == 0);
|
|
|
|
CHECK(newSet.localPoolUint16Vec.value[2] == 0);
|
|
|
|
/* Fill the dataset and timestamp */
|
|
|
|
REQUIRE(snapshot.deSerialize(&readOnlyPtr, &sizeToDeserialize,
|
2022-08-16 01:08:26 +02:00
|
|
|
SerializeIF::Endianness::MACHINE) == returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
/* Now we check that the snapshot is actually correct */
|
|
|
|
CHECK(newSet.localPoolVarFloat.value == Catch::Approx(-12.242));
|
|
|
|
CHECK(newSet.localPoolVarUint8 == 5);
|
|
|
|
CHECK(newSet.localPoolUint16Vec.value[0] == 2);
|
|
|
|
CHECK(newSet.localPoolUint16Vec.value[1] == 32);
|
|
|
|
CHECK(newSet.localPoolUint16Vec.value[2] == 42932);
|
|
|
|
|
|
|
|
/* Now we check that both times are equal */
|
|
|
|
timeval timeFromHK{};
|
|
|
|
auto result = CCSDSTime::convertFromCDS(&timeFromHK, &cdsShort);
|
2022-08-16 01:08:26 +02:00
|
|
|
CHECK(result == returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
timeval difference = timeFromHK - now;
|
|
|
|
CHECK(timevalOperations::toDouble(difference) < 1.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("VariableSnapshotTest") {
|
|
|
|
/* Acquire subscription interface */
|
2024-11-04 17:32:21 +01:00
|
|
|
PeriodicHkGenerationProviderIF* subscriptionIF = poolOwner.getSubscriptionInterface();
|
2022-07-25 19:36:56 +02:00
|
|
|
REQUIRE(subscriptionIF != nullptr);
|
|
|
|
|
|
|
|
/* Subscribe for variable snapshot */
|
|
|
|
REQUIRE(poolOwner.subscribeWrapperVariableSnapshot(subscriberId, lpool::uint8VarId) ==
|
2022-08-16 01:08:26 +02:00
|
|
|
returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
auto poolVar =
|
|
|
|
dynamic_cast<lp_var_t<uint8_t>*>(poolOwner.getPoolObjectHandle(lpool::uint8VarId));
|
|
|
|
REQUIRE(poolVar != nullptr);
|
|
|
|
|
|
|
|
{
|
|
|
|
PoolReadGuard rg(poolVar);
|
2022-08-16 01:08:26 +02:00
|
|
|
CHECK(rg.getReadResult() == returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
poolVar->value = 25;
|
|
|
|
}
|
|
|
|
|
|
|
|
poolVar->setChanged(true);
|
|
|
|
/* Store current time, we are going to check the (approximate) time equality later */
|
|
|
|
CCSDSTime::CDS_short timeCdsNow{};
|
|
|
|
timeval now{};
|
|
|
|
Clock::getClock_timeval(&now);
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(poolOwner.poolManager.performHkOperation() == returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
|
|
|
|
/* Check update snapshot was sent. */
|
|
|
|
REQUIRE(poolOwnerMock.wasMessageSent());
|
2022-07-25 20:31:06 +02:00
|
|
|
CHECK(poolOwnerMock.numberOfSentMessages() == 1);
|
2022-07-25 19:36:56 +02:00
|
|
|
|
|
|
|
/* Should have been reset. */
|
|
|
|
CHECK(poolVar->hasChanged() == false);
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
CHECK(messageSent.getCommand() ==
|
|
|
|
static_cast<int>(HousekeepingMessage::UPDATE_SNAPSHOT_VARIABLE));
|
|
|
|
/* Now we deserialize the snapshot into a new dataset instance */
|
|
|
|
CCSDSTime::CDS_short cdsShort{};
|
|
|
|
lp_var_t<uint8_t> varCopy = lp_var_t<uint8_t>(lpool::uint8VarGpid);
|
|
|
|
HousekeepingSnapshot snapshot(&cdsShort, &varCopy);
|
|
|
|
store_address_t storeId;
|
|
|
|
HousekeepingMessage::getUpdateSnapshotVariableCommand(&messageSent, &storeId);
|
|
|
|
ConstAccessorPair accessorPair = tglob::getIpcStoreHandle()->getData(storeId);
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(accessorPair.first == returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
const uint8_t* readOnlyPtr = accessorPair.second.data();
|
|
|
|
size_t sizeToDeserialize = accessorPair.second.size();
|
|
|
|
CHECK(varCopy.value == 0);
|
|
|
|
/* Fill the dataset and timestamp */
|
|
|
|
REQUIRE(snapshot.deSerialize(&readOnlyPtr, &sizeToDeserialize,
|
2022-08-16 01:08:26 +02:00
|
|
|
SerializeIF::Endianness::MACHINE) == returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
CHECK(varCopy.value == 25);
|
|
|
|
|
|
|
|
/* Now we check that both times are equal */
|
|
|
|
timeval timeFromHK{};
|
|
|
|
auto result = CCSDSTime::convertFromCDS(&timeFromHK, &cdsShort);
|
2022-08-16 01:08:26 +02:00
|
|
|
CHECK(result == returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
timeval difference = timeFromHK - now;
|
|
|
|
CHECK(timevalOperations::toDouble(difference) < 1.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("VariableNotificationTest") {
|
|
|
|
/* Acquire subscription interface */
|
2024-11-04 17:32:21 +01:00
|
|
|
PeriodicHkGenerationProviderIF* subscriptionIF = poolOwner.getSubscriptionInterface();
|
2022-07-25 19:36:56 +02:00
|
|
|
REQUIRE(subscriptionIF != nullptr);
|
|
|
|
|
|
|
|
/* Subscribe for variable update */
|
|
|
|
REQUIRE(poolOwner.subscribeWrapperVariableUpdate(subscriberId, lpool::uint8VarId) ==
|
2022-08-16 01:08:26 +02:00
|
|
|
returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
auto* poolVar =
|
|
|
|
dynamic_cast<lp_var_t<uint8_t>*>(poolOwner.getPoolObjectHandle(lpool::uint8VarId));
|
|
|
|
REQUIRE(poolVar != nullptr);
|
|
|
|
poolVar->setChanged(true);
|
|
|
|
REQUIRE(poolVar->hasChanged() == true);
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(poolOwner.poolManager.performHkOperation() == returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
|
|
|
|
/* Check update notification was sent. */
|
|
|
|
REQUIRE(poolOwnerMock.wasMessageSent());
|
2022-07-25 20:31:06 +02:00
|
|
|
CHECK(poolOwnerMock.numberOfSentMessages() == 1);
|
2022-07-25 19:36:56 +02:00
|
|
|
/* Should have been reset. */
|
|
|
|
CHECK(poolVar->hasChanged() == false);
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
CHECK(messageSent.getCommand() ==
|
|
|
|
static_cast<int>(HousekeepingMessage::UPDATE_NOTIFICATION_VARIABLE));
|
|
|
|
/* Now subscribe for the dataset update (HK and update) again with subscription interface */
|
|
|
|
REQUIRE(subscriptionIF->subscribeForSetUpdateMessage(lpool::testSetId, objects::NO_OBJECT,
|
2022-08-16 01:08:26 +02:00
|
|
|
subscriberId, false) == returnvalue::OK);
|
|
|
|
REQUIRE(poolOwner.subscribeWrapperSetUpdateHk(false, &hkReceiver) == returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
|
|
|
|
poolOwner.dataset.setChanged(true);
|
|
|
|
poolOwnerMock.clearMessages();
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(poolOwner.poolManager.performHkOperation() == returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
/* Now two messages should be sent. */
|
|
|
|
REQUIRE(poolOwnerMock.wasMessageSent());
|
2022-07-25 20:31:06 +02:00
|
|
|
CHECK(poolOwnerMock.numberOfSentMessages() == 2);
|
2022-07-25 19:36:56 +02:00
|
|
|
poolOwnerMock.clearMessages(true);
|
|
|
|
|
|
|
|
poolOwner.dataset.setChanged(true);
|
|
|
|
poolOwnerMock.clearMessages(true);
|
|
|
|
poolVar->setChanged(true);
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(poolOwner.poolManager.performHkOperation() == returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
/* Now three messages should be sent. */
|
|
|
|
REQUIRE(poolOwnerMock.wasMessageSent());
|
2022-07-25 20:31:06 +02:00
|
|
|
CHECK(poolOwnerMock.numberOfSentMessages() == 3);
|
|
|
|
CHECK(poolOwnerMock.numberOfSentMessagesToDest(subscriberId) == 2);
|
|
|
|
CHECK(poolOwnerMock.numberOfSentMessagesToDest(hkDest) == 1);
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
CHECK(messageSent.getCommand() ==
|
|
|
|
static_cast<int>(HousekeepingMessage::UPDATE_NOTIFICATION_VARIABLE));
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(poolOwnerMock.clearLastSentMessage(subscriberId) == returnvalue::OK);
|
|
|
|
REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
CHECK(messageSent.getCommand() ==
|
|
|
|
static_cast<int>(HousekeepingMessage::UPDATE_NOTIFICATION_SET));
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(poolOwnerMock.clearLastSentMessage(subscriberId) == returnvalue::OK);
|
2023-08-03 13:03:58 +02:00
|
|
|
REQUIRE(poolOwnerMock.getNextSentMessageToDefaultDest(messageSent) == returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
CHECK(messageSent.getCommand() == static_cast<int>(HousekeepingMessage::HK_REPORT));
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(poolOwnerMock.clearLastSentMessage() == returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == MessageQueueIF::EMPTY);
|
2023-08-03 13:03:58 +02:00
|
|
|
REQUIRE(poolOwnerMock.getNextSentMessageToDefaultDest(messageSent) == MessageQueueIF::EMPTY);
|
2022-07-25 19:36:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("PeriodicHKAndMessaging") {
|
|
|
|
/* 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 */
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(poolOwner.subscribePeriodicHk(true) == returnvalue::OK);
|
|
|
|
REQUIRE(poolOwner.poolManager.performHkOperation() == returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
/* 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);
|
2022-07-25 19:36:56 +02:00
|
|
|
|
|
|
|
LocalPoolDataSetBase* setHandle = poolOwner.getDataSetHandle(lpool::testSid);
|
|
|
|
REQUIRE(setHandle != nullptr);
|
|
|
|
CHECK(poolOwner.poolManager.generateHousekeepingPacket(lpool::testSid, setHandle, false) ==
|
2022-08-16 01:08:26 +02:00
|
|
|
returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
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);
|
2022-07-25 19:36:56 +02:00
|
|
|
|
|
|
|
CHECK(setHandle->getReportingEnabled() == true);
|
|
|
|
CommandMessage hkCmd;
|
2023-08-15 18:06:50 +02:00
|
|
|
HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid, false);
|
2022-08-16 01:08:26 +02:00
|
|
|
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
|
2022-07-25 19:36:56 +02: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);
|
2022-07-25 19:36:56 +02:00
|
|
|
|
2023-08-15 18:06:50 +02:00
|
|
|
HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid, true);
|
2022-08-16 01:08:26 +02:00
|
|
|
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
CHECK(setHandle->getReportingEnabled() == true);
|
|
|
|
REQUIRE(poolOwnerMock.wasMessageSent());
|
2022-08-16 01:08:26 +02:00
|
|
|
CHECK(poolOwnerMock.clearLastSentMessage() == returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
|
2023-08-15 18:06:50 +02:00
|
|
|
HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid, false);
|
2022-08-16 01:08:26 +02:00
|
|
|
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
CHECK(setHandle->getReportingEnabled() == false);
|
|
|
|
REQUIRE(poolOwnerMock.wasMessageSent());
|
2022-08-16 01:08:26 +02:00
|
|
|
CHECK(poolOwnerMock.clearLastSentMessage() == returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
|
2023-08-15 18:06:50 +02:00
|
|
|
HousekeepingMessage::setCollectionIntervalModificationCommand(&hkCmd, lpool::testSid, 0.4);
|
2022-08-16 01:08:26 +02:00
|
|
|
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
|
2023-05-15 16:13:05 +02:00
|
|
|
CHECK_THAT(poolOwner.dataset.getCollectionInterval(), Catch::Matchers::WithinAbs(0.4, 0.01));
|
2022-07-25 19:36:56 +02:00
|
|
|
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);
|
2022-07-25 19:36:56 +02:00
|
|
|
|
2023-08-15 18:06:50 +02:00
|
|
|
HousekeepingMessage::setStructureReportingCommand(&hkCmd, lpool::testSid);
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(poolOwner.poolManager.performHkOperation() == returnvalue::OK);
|
|
|
|
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
/* Now HK packet should be sent as message. */
|
|
|
|
REQUIRE(poolOwnerMock.wasMessageSent());
|
2022-07-25 20:31:06 +02:00
|
|
|
REQUIRE(poolOwnerMock.numberOfSentMessages() == 1);
|
2022-07-25 19:36:56 +02:00
|
|
|
poolOwnerMock.clearMessages();
|
|
|
|
|
2023-08-15 18:06:50 +02:00
|
|
|
HousekeepingMessage::setOneShotReportCommand(&hkCmd, lpool::testSid);
|
2022-08-16 01:08:26 +02:00
|
|
|
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
REQUIRE(poolOwnerMock.wasMessageSent());
|
2022-07-25 20:31:06 +02:00
|
|
|
REQUIRE(poolOwnerMock.numberOfSentMessages() == 1);
|
2022-07-25 19:36:56 +02:00
|
|
|
poolOwnerMock.clearMessages();
|
|
|
|
|
|
|
|
HousekeepingMessage::setUpdateNotificationSetCommand(&hkCmd, lpool::testSid);
|
|
|
|
sid_t sidToCheck;
|
|
|
|
store_address_t storeId;
|
2022-08-16 01:08:26 +02:00
|
|
|
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
CHECK(poolOwner.changedDataSetCallbackWasCalled(sidToCheck, storeId) == true);
|
|
|
|
CHECK(sidToCheck == lpool::testSid);
|
|
|
|
|
2023-08-15 18:06:50 +02:00
|
|
|
HousekeepingMessage::setStructureReportingCommand(&hkCmd, lpool::testSid);
|
2022-08-16 01:08:26 +02:00
|
|
|
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
REQUIRE(poolOwnerMock.wasMessageSent());
|
2022-07-25 20:31:06 +02:00
|
|
|
REQUIRE(poolOwnerMock.numberOfSentMessages() == 1);
|
2022-07-25 19:36:56 +02:00
|
|
|
poolOwnerMock.clearMessages();
|
|
|
|
|
2023-08-15 18:06:50 +02:00
|
|
|
HousekeepingMessage::setCollectionIntervalModificationCommand(&hkCmd, lpool::testSid, 0.4);
|
2022-08-16 01:08:26 +02:00
|
|
|
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
REQUIRE(poolOwnerMock.wasMessageSent());
|
2022-07-25 20:31:06 +02:00
|
|
|
REQUIRE(poolOwnerMock.numberOfSentMessages() == 1);
|
2022-07-25 19:36:56 +02:00
|
|
|
poolOwnerMock.clearMessages();
|
|
|
|
|
2023-08-15 18:06:50 +02:00
|
|
|
HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid, true);
|
2022-08-16 01:08:26 +02:00
|
|
|
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
REQUIRE(poolOwnerMock.wasMessageSent());
|
2022-07-25 20:31:06 +02:00
|
|
|
REQUIRE(poolOwnerMock.numberOfSentMessages() == 1);
|
2022-07-25 19:36:56 +02:00
|
|
|
poolOwnerMock.clearMessages();
|
|
|
|
|
2023-08-15 18:06:50 +02:00
|
|
|
HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid, false);
|
2022-08-16 01:08:26 +02:00
|
|
|
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
REQUIRE(poolOwnerMock.wasMessageSent());
|
2022-07-25 20:31:06 +02:00
|
|
|
REQUIRE(poolOwnerMock.numberOfSentMessages() == 1);
|
2022-07-25 19:36:56 +02:00
|
|
|
poolOwnerMock.clearMessages();
|
|
|
|
|
2023-08-15 18:06:50 +02:00
|
|
|
HousekeepingMessage::setOneShotReportCommand(&hkCmd, lpool::testSid);
|
2022-08-16 01:08:26 +02:00
|
|
|
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
REQUIRE(poolOwnerMock.wasMessageSent());
|
2022-07-25 20:31:06 +02:00
|
|
|
REQUIRE(poolOwnerMock.numberOfSentMessages() == 1);
|
2022-07-25 19:36:56 +02:00
|
|
|
poolOwnerMock.clearMessages();
|
|
|
|
|
|
|
|
HousekeepingMessage::setUpdateNotificationVariableCommand(&hkCmd, lpool::uint8VarGpid);
|
|
|
|
gp_id_t gpidToCheck;
|
2022-08-16 01:08:26 +02:00
|
|
|
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
CHECK(poolOwner.changedVariableCallbackWasCalled(gpidToCheck, storeId) == true);
|
|
|
|
CHECK(gpidToCheck == lpool::uint8VarGpid);
|
|
|
|
|
|
|
|
HousekeepingMessage::setUpdateSnapshotSetCommand(&hkCmd, lpool::testSid,
|
|
|
|
store_address_t::invalid());
|
2022-08-16 01:08:26 +02:00
|
|
|
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
CHECK(poolOwner.changedDataSetCallbackWasCalled(sidToCheck, storeId) == true);
|
|
|
|
CHECK(sidToCheck == lpool::testSid);
|
|
|
|
|
|
|
|
HousekeepingMessage::setUpdateSnapshotVariableCommand(&hkCmd, lpool::uint8VarGpid,
|
|
|
|
store_address_t::invalid());
|
2022-08-16 01:08:26 +02:00
|
|
|
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
CHECK(poolOwner.changedVariableCallbackWasCalled(gpidToCheck, storeId) == true);
|
|
|
|
CHECK(gpidToCheck == lpool::uint8VarGpid);
|
|
|
|
|
|
|
|
poolOwner.poolManager.printPoolEntry(lpool::uint8VarId);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we need to reset the subscription list because the pool owner
|
|
|
|
is a global object. */
|
2022-08-16 01:08:26 +02:00
|
|
|
CHECK(poolOwner.reset() == returnvalue::OK);
|
2022-07-25 19:36:56 +02:00
|
|
|
poolOwnerMock.clearMessages(true);
|
|
|
|
}
|