more tests

This commit is contained in:
Robin Müller 2021-01-10 14:54:05 +01:00
parent 4fa9a1fe19
commit 6993415873
5 changed files with 52 additions and 1 deletions

View File

@ -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) {

View File

@ -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

View File

@ -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<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));
}
}

View File

@ -168,6 +168,10 @@ public:
MessageQueueIF::NO_QUEUE, objects::NO_OBJECT, false);
}
void resetSubscriptionList() {
hkManager.clearReceiversList();
}
LocalDataPoolManager hkManager;
LocalPoolTestDataSet dataset;
private:

View File

@ -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();
}
}