2021-01-10 12:53:01 +01:00
|
|
|
#include "LocalPoolOwnerBase.h"
|
|
|
|
|
|
|
|
#include <catch2/catch_test_macros.hpp>
|
|
|
|
#include <fsfw/datapoollocal/HasLocalDataPoolIF.h>
|
|
|
|
#include <fsfw/datapoollocal/StaticLocalDataSet.h>
|
2021-01-10 13:58:33 +01:00
|
|
|
#include <fsfw/ipc/CommandMessageCleaner.h>
|
2021-01-10 12:53:01 +01:00
|
|
|
#include <unittest/core/CatchDefinitions.h>
|
|
|
|
|
|
|
|
|
|
|
|
TEST_CASE("LocalPoolManagerTest" , "[LocManTest]") {
|
|
|
|
LocalPoolOwnerBase* poolOwner = objectManager->
|
|
|
|
get<LocalPoolOwnerBase>(objects::TEST_LOCAL_POOL_OWNER_BASE);
|
|
|
|
REQUIRE(poolOwner != nullptr);
|
|
|
|
REQUIRE(poolOwner->initializeHkManager() == retval::CATCH_OK);
|
|
|
|
REQUIRE(poolOwner->initializeHkManagerAfterTaskCreation()
|
|
|
|
== retval::CATCH_OK);
|
|
|
|
REQUIRE(poolOwner->dataset.assignPointers() == retval::CATCH_OK);
|
|
|
|
MessageQueueMockBase* mqMock = poolOwner->getMockQueueHandle();
|
|
|
|
REQUIRE(mqMock != nullptr);
|
2021-01-10 14:33:02 +01:00
|
|
|
CommandMessage messageSent;
|
|
|
|
uint8_t messagesSent = 0;
|
2021-01-10 12:53:01 +01:00
|
|
|
|
2021-01-10 13:58:33 +01:00
|
|
|
|
2021-01-10 12:53:01 +01:00
|
|
|
SECTION("BasicTest") {
|
2021-01-10 13:58:33 +01:00
|
|
|
// Subscribe for message generation on update.
|
|
|
|
REQUIRE(poolOwner->subscribeWrapperSetUpdate() == retval::CATCH_OK);
|
|
|
|
// Subscribe for an update message.
|
2021-01-10 12:53:01 +01:00
|
|
|
poolOwner->dataset.setChanged(true);
|
2021-01-10 13:58:33 +01:00
|
|
|
// Now the update message should be generated.
|
2021-01-12 20:59:15 +01:00
|
|
|
REQUIRE(poolOwner->poolManager.performHkOperation() == retval::CATCH_OK);
|
2021-01-10 12:53:01 +01:00
|
|
|
REQUIRE(mqMock->wasMessageSent() == true);
|
2021-01-10 14:33:02 +01:00
|
|
|
|
2021-01-10 13:58:33 +01:00
|
|
|
REQUIRE(mqMock->receiveMessage(&messageSent) == retval::CATCH_OK);
|
|
|
|
CHECK(messageSent.getCommand() == static_cast<int>(
|
|
|
|
HousekeepingMessage::UPDATE_NOTIFICATION_SET));
|
|
|
|
|
|
|
|
// Should have been reset.
|
|
|
|
CHECK(poolOwner->dataset.hasChanged() == false);
|
|
|
|
// Set changed again, result should be the same.
|
|
|
|
poolOwner->dataset.setChanged(true);
|
2021-01-12 20:59:15 +01:00
|
|
|
REQUIRE(poolOwner->poolManager.performHkOperation() == retval::CATCH_OK);
|
2021-01-10 13:58:33 +01:00
|
|
|
|
|
|
|
REQUIRE(mqMock->wasMessageSent(&messagesSent) == true);
|
|
|
|
CHECK(messagesSent == 1);
|
|
|
|
REQUIRE(mqMock->receiveMessage(&messageSent) == retval::CATCH_OK);
|
|
|
|
CHECK(messageSent.getCommand() == static_cast<int>(
|
|
|
|
HousekeepingMessage::UPDATE_NOTIFICATION_SET));
|
|
|
|
|
|
|
|
// now subscribe for set update HK as well.
|
|
|
|
REQUIRE(poolOwner->subscribeWrapperSetUpdateHk() == retval::CATCH_OK);
|
|
|
|
poolOwner->dataset.setChanged(true);
|
2021-01-12 20:59:15 +01:00
|
|
|
REQUIRE(poolOwner->poolManager.performHkOperation() == retval::CATCH_OK);
|
2021-01-10 13:58:33 +01:00
|
|
|
REQUIRE(mqMock->wasMessageSent(&messagesSent) == true);
|
|
|
|
CHECK(messagesSent == 2);
|
|
|
|
// first message sent should be the update notification, considering
|
|
|
|
// the internal list is a vector checked in insertion order.
|
|
|
|
REQUIRE(mqMock->receiveMessage(&messageSent) == retval::CATCH_OK);
|
|
|
|
CHECK(messageSent.getCommand() == static_cast<int>(
|
|
|
|
HousekeepingMessage::UPDATE_NOTIFICATION_SET));
|
2021-01-10 12:53:01 +01:00
|
|
|
|
2021-01-10 13:58:33 +01:00
|
|
|
REQUIRE(mqMock->receiveMessage(&messageSent) == retval::CATCH_OK);
|
|
|
|
CHECK(messageSent.getCommand() == static_cast<int>(
|
|
|
|
HousekeepingMessage::HK_REPORT));
|
2021-01-10 14:27:57 +01:00
|
|
|
// clear message to avoid memory leak, our mock won't do it for us (yet)
|
2021-01-10 13:58:33 +01:00
|
|
|
CommandMessageCleaner::clearCommandMessage(&messageSent);
|
2021-01-10 14:33:02 +01:00
|
|
|
}
|
2021-01-10 14:27:57 +01:00
|
|
|
|
2021-01-10 14:33:02 +01:00
|
|
|
SECTION("AdvancedTests") {
|
2021-01-10 15:04:47 +01:00
|
|
|
// we need to reset the subscription list because the pool owner
|
|
|
|
// is a global object.
|
2021-01-10 14:54:05 +01:00
|
|
|
poolOwner->resetSubscriptionList();
|
2021-01-10 14:33:02 +01:00
|
|
|
// Subscribe for variable update as well
|
2021-01-10 14:27:57 +01:00
|
|
|
REQUIRE(not poolOwner->dataset.hasChanged());
|
|
|
|
REQUIRE(poolOwner->subscribeWrapperVariableUpdate(lpool::uint8VarId) ==
|
|
|
|
retval::CATCH_OK);
|
|
|
|
lp_var_t<uint8_t>* poolVar = dynamic_cast<lp_var_t<uint8_t>*>(
|
|
|
|
poolOwner->getPoolObjectHandle(lpool::uint8VarId));
|
|
|
|
REQUIRE(poolVar != nullptr);
|
|
|
|
poolVar->setChanged(true);
|
2021-01-12 20:59:15 +01:00
|
|
|
REQUIRE(poolOwner->poolManager.performHkOperation() == retval::CATCH_OK);
|
2021-01-10 14:27:57 +01:00
|
|
|
|
2021-01-10 14:33:02 +01:00
|
|
|
// Check update notification was sent.
|
2021-01-10 14:27:57 +01:00
|
|
|
REQUIRE(mqMock->wasMessageSent(&messagesSent) == true);
|
|
|
|
CHECK(messagesSent == 1);
|
2021-01-10 14:33:02 +01:00
|
|
|
// Should have been reset.
|
|
|
|
CHECK(poolVar->hasChanged() == false);
|
2021-01-10 14:27:57 +01:00
|
|
|
REQUIRE(mqMock->receiveMessage(&messageSent) == retval::CATCH_OK);
|
|
|
|
CHECK(messageSent.getCommand() == static_cast<int>(
|
|
|
|
HousekeepingMessage::UPDATE_NOTIFICATION_VARIABLE));
|
|
|
|
|
2021-01-10 14:33:02 +01:00
|
|
|
// now subscribe for the dataset update (HK and update) again
|
|
|
|
REQUIRE(poolOwner->subscribeWrapperSetUpdate() == retval::CATCH_OK);
|
|
|
|
REQUIRE(poolOwner->subscribeWrapperSetUpdateHk() == retval::CATCH_OK);
|
|
|
|
|
2021-01-10 14:54:05 +01:00
|
|
|
poolOwner->dataset.setChanged(true);
|
2021-01-12 20:59:15 +01:00
|
|
|
REQUIRE(poolOwner->poolManager.performHkOperation() == retval::CATCH_OK);
|
2021-01-10 14:54:05 +01:00
|
|
|
// now two messages should be sent.
|
|
|
|
REQUIRE(mqMock->wasMessageSent(&messagesSent) == true);
|
|
|
|
CHECK(messagesSent == 2);
|
|
|
|
mqMock->clearMessages(true);
|
2021-01-10 14:33:02 +01:00
|
|
|
|
2021-01-10 14:54:05 +01:00
|
|
|
poolOwner->dataset.setChanged(true);
|
|
|
|
poolVar->setChanged(true);
|
2021-01-12 20:59:15 +01:00
|
|
|
REQUIRE(poolOwner->poolManager.performHkOperation() == retval::CATCH_OK);
|
2021-01-10 14:54:05 +01:00
|
|
|
// now three messages should be sent.
|
|
|
|
REQUIRE(mqMock->wasMessageSent(&messagesSent) == true);
|
|
|
|
CHECK(messagesSent == 3);
|
|
|
|
REQUIRE(mqMock->receiveMessage(&messageSent) == retval::CATCH_OK);
|
|
|
|
CHECK(messageSent.getCommand() == static_cast<int>(
|
|
|
|
HousekeepingMessage::UPDATE_NOTIFICATION_VARIABLE));
|
|
|
|
REQUIRE(mqMock->receiveMessage(&messageSent) == retval::CATCH_OK);
|
|
|
|
CHECK(messageSent.getCommand() == static_cast<int>(
|
|
|
|
HousekeepingMessage::UPDATE_NOTIFICATION_SET));
|
|
|
|
REQUIRE(mqMock->receiveMessage(&messageSent) == retval::CATCH_OK);
|
|
|
|
CHECK(messageSent.getCommand() == static_cast<int>(
|
|
|
|
HousekeepingMessage::HK_REPORT));
|
|
|
|
CommandMessageCleaner::clearCommandMessage(&messageSent);
|
|
|
|
REQUIRE(mqMock->receiveMessage(&messageSent) ==
|
|
|
|
static_cast<int>(MessageQueueIF::EMPTY));
|
2021-01-10 12:53:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|