From a50b52df5137ecae86f0c2a8db21210ec507cece Mon Sep 17 00:00:00 2001 From: Steffen Gaisser Date: Tue, 22 Feb 2022 13:37:28 +0100 Subject: [PATCH] Fixed an issue in host OSAL and added more coverage to IER --- .../datapoollocal/LocalDataPoolManager.cpp | 2 +- src/fsfw/osal/host/MessageQueue.cpp | 7 +++++ .../TestInternalErrorReporter.cpp | 30 +++++++++++++++---- .../fsfw_tests/unit/osal/TestMessageQueue.cpp | 4 +-- 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/fsfw/datapoollocal/LocalDataPoolManager.cpp b/src/fsfw/datapoollocal/LocalDataPoolManager.cpp index 9057de31..cab13207 100644 --- a/src/fsfw/datapoollocal/LocalDataPoolManager.cpp +++ b/src/fsfw/datapoollocal/LocalDataPoolManager.cpp @@ -84,7 +84,7 @@ ReturnValue_t LocalDataPoolManager::initializeHousekeepingPoolEntriesOnce() { return result; } - printWarningOrError(sif::OutputTypes::OUT_WARNING, "initialize", HasReturnvaluesIF::RETURN_FAILED, + printWarningOrError(sif::OutputTypes::OUT_WARNING, "initializeHousekeepingPoolEntriesOnce", HasReturnvaluesIF::RETURN_FAILED, "The map should only be initialized once"); return HasReturnvaluesIF::RETURN_OK; } diff --git a/src/fsfw/osal/host/MessageQueue.cpp b/src/fsfw/osal/host/MessageQueue.cpp index db66b671..62151164 100644 --- a/src/fsfw/osal/host/MessageQueue.cpp +++ b/src/fsfw/osal/host/MessageQueue.cpp @@ -125,6 +125,13 @@ ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo, memcpy(targetQueue->messageQueue.back().data(), message->getBuffer(), message->getMaximumMessageSize()); } else { + if (not ignoreFault) { + InternalErrorReporterIF* internalErrorReporter = + ObjectManager::instance()->get(objects::INTERNAL_ERROR_REPORTER); + if (internalErrorReporter != nullptr) { + internalErrorReporter->queueMessageNotSent(); + } + } return MessageQueueIF::FULL; } return HasReturnvaluesIF::RETURN_OK; diff --git a/tests/src/fsfw_tests/unit/internalerror/TestInternalErrorReporter.cpp b/tests/src/fsfw_tests/unit/internalerror/TestInternalErrorReporter.cpp index 1103037d..1e63a57b 100644 --- a/tests/src/fsfw_tests/unit/internalerror/TestInternalErrorReporter.cpp +++ b/tests/src/fsfw_tests/unit/internalerror/TestInternalErrorReporter.cpp @@ -23,6 +23,9 @@ TEST_CASE("Internal Error Reporter", "[TestInternalError]") { } InternalErrorReporter* internalErrorReporter = dynamic_cast(ObjectManager::instance()->get(objects::INTERNAL_ERROR_REPORTER)); + if(internalErrorReporter == nullptr){ + FAIL(); + } task.addComponent(objects::INTERNAL_ERROR_REPORTER); MessageQueueIF* testQueue = QueueFactory::instance()->createMessageQueue(1); MessageQueueIF* hkQueue = QueueFactory::instance()->createMessageQueue(1); @@ -34,8 +37,13 @@ TEST_CASE("Internal Error Reporter", "[TestInternalError]") { ActionMessage::setCompletionReply(&message, 10, true); auto result = hkQueue->sendMessage(testQueue->getId(), &message); REQUIRE(result == retval::CATCH_OK); - internalErrorReporter->performOperation(0); uint32_t queueHits = 0; + uint32_t lostTm = 0; + uint32_t storeHits = 0; + /* We don't know if another test caused a queue Hit so we will enforce one, + then remeber the queueHit count and force another hit */ + internalErrorReporter->queueMessageNotSent(); + internalErrorReporter->performOperation(0); { CommandMessage hkMessage; result = hkQueue->receiveMessage(&hkMessage); @@ -44,7 +52,8 @@ TEST_CASE("Internal Error Reporter", "[TestInternalError]") { store_address_t storeAddress; gp_id_t gpid = HousekeepingMessage::getUpdateSnapshotVariableCommand(&hkMessage, &storeAddress); REQUIRE(gpid.objectId == objects::INTERNAL_ERROR_REPORTER); - InternalErrorDataset dataset(objects::NO_OBJECT); + // We need the object ID of the reporter here (NO_OBJECT) + InternalErrorDataset dataset(objects::INTERNAL_ERROR_REPORTER); CCSDSTime::CDS_short time; ConstAccessorPair data = ipcStore->getData(storeAddress); REQUIRE(data.first == HasReturnvaluesIF::RETURN_OK); @@ -53,10 +62,15 @@ TEST_CASE("Internal Error Reporter", "[TestInternalError]") { size_t size = data.second.size(); result = hkSnapshot.deSerialize(&buffer, &size, SerializeIF::Endianness::MACHINE); REQUIRE(result == HasReturnvaluesIF::RETURN_OK); + // Remember the amount of queueHits before to see the increase queueHits = dataset.queueHits.value; + lostTm = dataset.tmHits.value; + storeHits = dataset.storeHits.value; } result = hkQueue->sendMessage(testQueue->getId(), &message); REQUIRE(result == MessageQueueIF::FULL); + internalErrorReporter->lostTm(); + internalErrorReporter->storeFull(); { internalErrorReporter->performOperation(0); CommandMessage hkMessage; @@ -70,15 +84,19 @@ TEST_CASE("Internal Error Reporter", "[TestInternalError]") { ConstAccessorPair data = ipcStore->getData(storeAddress); REQUIRE(data.first == HasReturnvaluesIF::RETURN_OK); CCSDSTime::CDS_short time; - InternalErrorDataset dataset(objects::NO_OBJECT); + // We need the object ID of the reporter here (NO_OBJECT) + InternalErrorDataset dataset(objects::INTERNAL_ERROR_REPORTER); HousekeepingSnapshot hkSnapshot(&time, &dataset); const uint8_t* buffer = data.second.data(); size_t size = data.second.size(); result = hkSnapshot.deSerialize(&buffer, &size, SerializeIF::Endianness::MACHINE); REQUIRE(result == HasReturnvaluesIF::RETURN_OK); - REQUIRE(dataset.queueHits == (queueHits + 1)); + // Test that we had one more queueHit + REQUIRE(dataset.queueHits.value == (queueHits + 1)); + REQUIRE(dataset.tmHits.value == (lostTm + 1)); + REQUIRE(dataset.storeHits.value == (storeHits + 1)); } } - delete testQueue; - delete hkQueue; + QueueFactory::instance()->deleteMessageQueue(testQueue); + QueueFactory::instance()->deleteMessageQueue(hkQueue); } \ No newline at end of file diff --git a/tests/src/fsfw_tests/unit/osal/TestMessageQueue.cpp b/tests/src/fsfw_tests/unit/osal/TestMessageQueue.cpp index 365df379..11c0739b 100644 --- a/tests/src/fsfw_tests/unit/osal/TestMessageQueue.cpp +++ b/tests/src/fsfw_tests/unit/osal/TestMessageQueue.cpp @@ -54,6 +54,6 @@ TEST_CASE("MessageQueue Basic Test", "[TestMq]") { CHECK(recvMessage.getData()[0] == 42); } // We have to clear MQs ourself ATM - delete testSenderMq; - delete testReceiverMq; + QueueFactory::instance()->deleteMessageQueue(testSenderMq); + QueueFactory::instance()->deleteMessageQueue(testReceiverMq); }