diff --git a/datapoollocal/LocalDataPoolManager.cpp b/datapoollocal/LocalDataPoolManager.cpp index 564604cd8..c12203f72 100644 --- a/datapoollocal/LocalDataPoolManager.cpp +++ b/datapoollocal/LocalDataPoolManager.cpp @@ -322,12 +322,16 @@ void LocalDataPoolManager::handleChangeResetLogic( continue; } + // only one update recipient, we can reset changes status immediately. if(changeInfo.updateCounter <= 1) { toReset->setChanged(false); } - if(changeInfo.currentUpdateCounter == 0) { + // All recipients have been notified, reset the changed flag. + if(changeInfo.currentUpdateCounter <= 1) { toReset->setChanged(false); + changeInfo.currentUpdateCounter = 0; } + // Not all recipiens have been notified yet, decrement. else { changeInfo.currentUpdateCounter--; } diff --git a/unittest/tests/datapoollocal/LocalPoolManagerTest.cpp b/unittest/tests/datapoollocal/LocalPoolManagerTest.cpp index 2c797505e..bc07c9d97 100644 --- a/unittest/tests/datapoollocal/LocalPoolManagerTest.cpp +++ b/unittest/tests/datapoollocal/LocalPoolManagerTest.cpp @@ -60,7 +60,25 @@ TEST_CASE("LocalPoolManagerTest" , "[LocManTest]") { REQUIRE(mqMock->receiveMessage(&messageSent) == retval::CATCH_OK); CHECK(messageSent.getCommand() == static_cast( HousekeepingMessage::HK_REPORT)); + // clear message to avoid memory leak, our mock won't do it for us (yet) CommandMessageCleaner::clearCommandMessage(&messageSent); + + // now subscribe for variable update as well + REQUIRE(not poolOwner->dataset.hasChanged()); + REQUIRE(poolOwner->subscribeWrapperVariableUpdate(lpool::uint8VarId) == + retval::CATCH_OK); + lp_var_t* poolVar = dynamic_cast*>( + poolOwner->getPoolObjectHandle(lpool::uint8VarId)); + REQUIRE(poolVar != nullptr); + poolVar->setChanged(true); + REQUIRE(poolOwner->hkManager.performHkOperation() == retval::CATCH_OK); + + REQUIRE(mqMock->wasMessageSent(&messagesSent) == true); + CHECK(messagesSent == 1); + REQUIRE(mqMock->receiveMessage(&messageSent) == retval::CATCH_OK); + CHECK(messageSent.getCommand() == static_cast( + HousekeepingMessage::UPDATE_NOTIFICATION_VARIABLE)); + } } diff --git a/unittest/tests/datapoollocal/LocalPoolOwnerBase.h b/unittest/tests/datapoollocal/LocalPoolOwnerBase.h index 5ff146983..430c8b07f 100644 --- a/unittest/tests/datapoollocal/LocalPoolOwnerBase.h +++ b/unittest/tests/datapoollocal/LocalPoolOwnerBase.h @@ -2,6 +2,7 @@ #define FSFW_UNITTEST_TESTS_DATAPOOLLOCAL_LOCALPOOLOWNERBASE_H_ #include +#include #include #include #include @@ -18,15 +19,16 @@ static constexpr lp_id_t uint16Vec3Id = 3; static constexpr lp_id_t int64Vec2Id = 4; static constexpr uint32_t testSetId = 0; +static constexpr uint8_t dataSetMaxVariables = 10; static const sid_t testSid = sid_t(objects::TEST_LOCAL_POOL_OWNER_BASE, testSetId); } -class LocalPoolTestDataSet: public StaticLocalDataSet<3> { +class LocalPoolTestDataSet: public LocalDataSet { public: LocalPoolTestDataSet(HasLocalDataPoolIF* owner, uint32_t setId): - StaticLocalDataSet(owner, setId) { + LocalDataSet(owner, setId, lpool::dataSetMaxVariables) { } ReturnValue_t assignPointers() { @@ -127,7 +129,24 @@ public: virtual LocalPoolObjectBase* getPoolObjectHandle( lp_id_t localPoolId) override { - return &testUint8; + if(localPoolId == lpool::uint8VarId) { + return &testUint8; + } + else if(localPoolId == lpool::uint16Vec3Id) { + return &testUint16Vec; + } + else if(localPoolId == lpool::floatVarId) { + return &testFloat; + } + else if(localPoolId == lpool::int64Vec2Id) { + return &testInt64Vec; + } + else if(localPoolId == lpool::uint32VarId) { + return &testUint32; + } + else { + return &testUint8; + } } MessageQueueMockBase* getMockQueueHandle() const { @@ -144,9 +163,9 @@ public: false, objects::HK_RECEIVER_MOCK); } - ReturnValue_t subscribeWrapperVariableUpdate() { - return hkManager.subscribeForSetUpdateMessages(lpool::testSetId, - objects::NO_OBJECT, MessageQueueIF::NO_QUEUE, false); + ReturnValue_t subscribeWrapperVariableUpdate(lp_id_t localPoolId) { + return hkManager.subscribeForVariableUpdateMessages(localPoolId, + MessageQueueIF::NO_QUEUE, objects::NO_OBJECT, false); } LocalDataPoolManager hkManager;