From 6993415873b88b68e987ef7796e5f371a21fbef4 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sun, 10 Jan 2021 14:54:05 +0100 Subject: [PATCH] more tests --- datapoollocal/LocalDataPoolManager.cpp | 5 ++++ datapoollocal/LocalDataPoolManager.h | 6 +++++ .../datapoollocal/LocalPoolManagerTest.cpp | 25 +++++++++++++++++++ .../tests/datapoollocal/LocalPoolOwnerBase.h | 4 +++ unittest/tests/mocks/MessageQueueMockBase.h | 13 +++++++++- 5 files changed, 52 insertions(+), 1 deletion(-) diff --git a/datapoollocal/LocalDataPoolManager.cpp b/datapoollocal/LocalDataPoolManager.cpp index c12203f7..da6e91a8 100644 --- a/datapoollocal/LocalDataPoolManager.cpp +++ b/datapoollocal/LocalDataPoolManager.cpp @@ -820,6 +820,11 @@ ReturnValue_t LocalDataPoolManager::generateSetStructurePacket(sid_t sid, return result; } +void LocalDataPoolManager::clearReceiversList() { + // clear the vector completely and releases allocated memory. + HkReceivers().swap(hkReceiversMap); +} + void LocalDataPoolManager::printWarningOrError(fsfw::OutputTypes outputType, const char* functionName, ReturnValue_t error, const char* errorPrint) { if(errorPrint == nullptr) { diff --git a/datapoollocal/LocalDataPoolManager.h b/datapoollocal/LocalDataPoolManager.h index eee4c593..2ced2efd 100644 --- a/datapoollocal/LocalDataPoolManager.h +++ b/datapoollocal/LocalDataPoolManager.h @@ -250,6 +250,12 @@ public: LocalDataPoolManager(const LocalDataPoolManager &) = delete; LocalDataPoolManager operator=(const LocalDataPoolManager&) = delete; + /** + * This function can be used to clear the receivers list. This is + * intended for test functions and not for regular operations, because + * the insertion operations allocate dynamically. + */ + void clearReceiversList(); private: LocalDataPool localPoolMap; //! Every housekeeping data manager has a mutex to protect access diff --git a/unittest/tests/datapoollocal/LocalPoolManagerTest.cpp b/unittest/tests/datapoollocal/LocalPoolManagerTest.cpp index ef8f7f33..2ea169b2 100644 --- a/unittest/tests/datapoollocal/LocalPoolManagerTest.cpp +++ b/unittest/tests/datapoollocal/LocalPoolManagerTest.cpp @@ -66,6 +66,7 @@ TEST_CASE("LocalPoolManagerTest" , "[LocManTest]") { } SECTION("AdvancedTests") { + poolOwner->resetSubscriptionList(); // Subscribe for variable update as well REQUIRE(not poolOwner->dataset.hasChanged()); REQUIRE(poolOwner->subscribeWrapperVariableUpdate(lpool::uint8VarId) == @@ -89,7 +90,31 @@ TEST_CASE("LocalPoolManagerTest" , "[LocManTest]") { REQUIRE(poolOwner->subscribeWrapperSetUpdate() == retval::CATCH_OK); REQUIRE(poolOwner->subscribeWrapperSetUpdateHk() == retval::CATCH_OK); + poolOwner->dataset.setChanged(true); + REQUIRE(poolOwner->hkManager.performHkOperation() == retval::CATCH_OK); + // now two messages should be sent. + REQUIRE(mqMock->wasMessageSent(&messagesSent) == true); + CHECK(messagesSent == 2); + mqMock->clearMessages(true); + poolOwner->dataset.setChanged(true); + poolVar->setChanged(true); + REQUIRE(poolOwner->hkManager.performHkOperation() == retval::CATCH_OK); + // 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( + HousekeepingMessage::UPDATE_NOTIFICATION_VARIABLE)); + REQUIRE(mqMock->receiveMessage(&messageSent) == retval::CATCH_OK); + CHECK(messageSent.getCommand() == static_cast( + HousekeepingMessage::UPDATE_NOTIFICATION_SET)); + REQUIRE(mqMock->receiveMessage(&messageSent) == retval::CATCH_OK); + CHECK(messageSent.getCommand() == static_cast( + HousekeepingMessage::HK_REPORT)); + CommandMessageCleaner::clearCommandMessage(&messageSent); + REQUIRE(mqMock->receiveMessage(&messageSent) == + static_cast(MessageQueueIF::EMPTY)); } } diff --git a/unittest/tests/datapoollocal/LocalPoolOwnerBase.h b/unittest/tests/datapoollocal/LocalPoolOwnerBase.h index 430c8b07..a5389812 100644 --- a/unittest/tests/datapoollocal/LocalPoolOwnerBase.h +++ b/unittest/tests/datapoollocal/LocalPoolOwnerBase.h @@ -168,6 +168,10 @@ public: MessageQueueIF::NO_QUEUE, objects::NO_OBJECT, false); } + void resetSubscriptionList() { + hkManager.clearReceiversList(); + } + LocalDataPoolManager hkManager; LocalPoolTestDataSet dataset; private: diff --git a/unittest/tests/mocks/MessageQueueMockBase.h b/unittest/tests/mocks/MessageQueueMockBase.h index 4792772f..7b810b41 100644 --- a/unittest/tests/mocks/MessageQueueMockBase.h +++ b/unittest/tests/mocks/MessageQueueMockBase.h @@ -40,6 +40,10 @@ public: return receiveMessage(message); } virtual ReturnValue_t receiveMessage(MessageQueueMessageIF* message) { + if(messagesSentQueue.empty()) { + return MessageQueueIF::EMPTY; + } + std::memcpy(message->getBuffer(), messagesSentQueue.front().getBuffer(), message->getMessageSize()); messagesSentQueue.pop(); @@ -95,8 +99,15 @@ public: return defaultDestSet; } - void clearMessages() { + void clearMessages(bool clearCommandMessages = true) { while(not messagesSentQueue.empty()) { + if(clearCommandMessages) { + CommandMessage message; + std::memcpy(message.getBuffer(), + messagesSentQueue.front().getBuffer(), + message.getMessageSize()); + message.clear(); + } messagesSentQueue.pop(); } }