1
0
forked from fsfw/fsfw

merge retval refactoring

This commit is contained in:
2022-08-16 01:08:26 +02:00
parent 9e064fe800
commit 1037102349
369 changed files with 2661 additions and 2668 deletions

View File

@ -13,11 +13,13 @@
#include "mocks/MessageQueueMock.h"
#include "tests/TestsConfig.h"
using namespace returnvalue;
TEST_CASE("DataSetTest", "[DataSetTest]") {
auto queue = MessageQueueMock(1);
LocalPoolOwnerBase poolOwner(queue, objects::TEST_LOCAL_POOL_OWNER_BASE);
REQUIRE(poolOwner.initializeHkManager() == result::OK);
REQUIRE(poolOwner.initializeHkManagerAfterTaskCreation() == result::OK);
REQUIRE(poolOwner.initializeHkManager() == OK);
REQUIRE(poolOwner.initializeHkManagerAfterTaskCreation() == OK);
LocalPoolStaticTestDataSet localSet;
SECTION("BasicTest") {
@ -36,7 +38,7 @@ TEST_CASE("DataSetTest", "[DataSetTest]") {
/* Test local pool ID serialization */
CHECK(localSet.serializeLocalPoolIds(&localPoolIdBuffPtr, &serSize, maxSize,
SerializeIF::Endianness::MACHINE) == result::OK);
SerializeIF::Endianness::MACHINE) == returnvalue::OK);
CHECK(serSize == maxSize);
CHECK(localPoolIdBuff[0] == 3);
CHECK(lpIds[0] == localSet.localPoolVarUint8.getDataPoolId());
@ -47,7 +49,7 @@ TEST_CASE("DataSetTest", "[DataSetTest]") {
localPoolIdBuffPtr = localPoolIdBuff;
serSize = 0;
CHECK(localSet.serializeLocalPoolIds(&localPoolIdBuffPtr, &serSize, maxSize,
SerializeIF::Endianness::MACHINE, false) == result::OK);
SerializeIF::Endianness::MACHINE, false) == OK);
CHECK(serSize == maxSize - sizeof(uint8_t));
CHECK(lpIds[0] == localSet.localPoolVarUint8.getDataPoolId());
CHECK(lpIds[1] == localSet.localPoolVarFloat.getDataPoolId());
@ -56,7 +58,7 @@ TEST_CASE("DataSetTest", "[DataSetTest]") {
{
/* Test read operation. Values should be all zeros */
PoolReadGuard readHelper(&localSet);
REQUIRE(readHelper.getReadResult() == result::OK);
REQUIRE(readHelper.getReadResult() == returnvalue::OK);
CHECK(not localSet.isValid());
CHECK(localSet.localPoolVarUint8.value == 0);
CHECK(not localSet.localPoolVarUint8.isValid());
@ -89,7 +91,7 @@ TEST_CASE("DataSetTest", "[DataSetTest]") {
/* Now we read again and check whether our zeroed values were overwritten with
the values in the pool */
PoolReadGuard readHelper(&localSet);
REQUIRE(readHelper.getReadResult() == result::OK);
REQUIRE(readHelper.getReadResult() == returnvalue::OK);
CHECK(localSet.isValid());
CHECK(localSet.localPoolVarUint8.value == 232);
CHECK(localSet.localPoolVarUint8.isValid());
@ -109,7 +111,7 @@ TEST_CASE("DataSetTest", "[DataSetTest]") {
uint8_t buffer[maxSize + 1];
uint8_t* buffPtr = buffer;
CHECK(localSet.serialize(&buffPtr, &serSize, maxSize, SerializeIF::Endianness::MACHINE) ==
result::OK);
returnvalue::OK);
uint8_t rawUint8 = buffer[0];
CHECK(rawUint8 == 232);
float rawFloat = 0.0;
@ -127,7 +129,7 @@ TEST_CASE("DataSetTest", "[DataSetTest]") {
std::memset(buffer, 0, sizeof(buffer));
const uint8_t* constBuffPtr = buffer;
CHECK(localSet.deSerialize(&constBuffPtr, &sizeToDeserialize,
SerializeIF::Endianness::MACHINE) == result::OK);
SerializeIF::Endianness::MACHINE) == returnvalue::OK);
/* Check whether deserialization was successfull */
CHECK(localSet.localPoolVarUint8.value == 0);
CHECK(localSet.localPoolVarFloat.value == Catch::Approx(0.0));
@ -155,7 +157,7 @@ TEST_CASE("DataSetTest", "[DataSetTest]") {
serSize = 0;
buffPtr = buffer;
CHECK(localSet.serialize(&buffPtr, &serSize, maxSize, SerializeIF::Endianness::MACHINE) ==
result::OK);
returnvalue::OK);
CHECK(rawUint8 == 232);
std::memcpy(&rawFloat, buffer + sizeof(uint8_t), sizeof(float));
CHECK(rawFloat == Catch::Approx(-2324.322));
@ -185,7 +187,7 @@ TEST_CASE("DataSetTest", "[DataSetTest]") {
sizeToDeserialize = maxSize;
constBuffPtr = buffer;
CHECK(localSet.deSerialize(&constBuffPtr, &sizeToDeserialize,
SerializeIF::Endianness::MACHINE) == result::OK);
SerializeIF::Endianness::MACHINE) == returnvalue::OK);
/* Check whether deserialization was successfull */
CHECK(localSet.localPoolVarUint8.value == 0);
CHECK(localSet.localPoolVarFloat.value == Catch::Approx(0.0));
@ -212,10 +214,10 @@ TEST_CASE("DataSetTest", "[DataSetTest]") {
/* Register same variables again to get more than 8 registered variables */
for (uint8_t idx = 0; idx < 8; idx++) {
REQUIRE(set.registerVariable(&localSet.localPoolVarUint8) == result::OK);
REQUIRE(set.registerVariable(&localSet.localPoolVarUint8) == returnvalue::OK);
}
REQUIRE(set.registerVariable(&localSet.localPoolVarUint8) == result::OK);
REQUIRE(set.registerVariable(&localSet.localPoolUint16Vec) == result::OK);
REQUIRE(set.registerVariable(&localSet.localPoolVarUint8) == returnvalue::OK);
REQUIRE(set.registerVariable(&localSet.localPoolUint16Vec) == returnvalue::OK);
set.setValidityBufferGeneration(true);
{
@ -231,8 +233,7 @@ TEST_CASE("DataSetTest", "[DataSetTest]") {
/* Already reserve additional space for validity buffer, will be needed later */
uint8_t buffer[maxSize + 1];
uint8_t* buffPtr = buffer;
CHECK(set.serialize(&buffPtr, &serSize, maxSize, SerializeIF::Endianness::MACHINE) ==
result::OK);
CHECK(set.serialize(&buffPtr, &serSize, maxSize, SerializeIF::Endianness::MACHINE) == OK);
std::array<uint8_t, 2> validityBuffer{};
std::memcpy(validityBuffer.data(), buffer + 9 + sizeof(uint16_t) * 3, 2);
/* The first 9 variables should be valid */
@ -250,7 +251,7 @@ TEST_CASE("DataSetTest", "[DataSetTest]") {
const uint8_t* constBuffPtr = buffer;
size_t sizeToDeSerialize = serSize;
CHECK(set.deSerialize(&constBuffPtr, &sizeToDeSerialize, SerializeIF::Endianness::MACHINE) ==
result::OK);
returnvalue::OK);
CHECK(localSet.localPoolVarUint8.isValid() == false);
CHECK(localSet.localPoolUint16Vec.isValid() == true);
}
@ -260,11 +261,11 @@ TEST_CASE("DataSetTest", "[DataSetTest]") {
SharedLocalDataSet sharedSet(sharedSetId, &poolOwner, lpool::testSetId, 5);
localSet.localPoolVarUint8.setReadWriteMode(pool_rwm_t::VAR_WRITE);
localSet.localPoolUint16Vec.setReadWriteMode(pool_rwm_t::VAR_WRITE);
CHECK(sharedSet.registerVariable(&localSet.localPoolVarUint8) == result::OK);
CHECK(sharedSet.registerVariable(&localSet.localPoolUint16Vec) == result::OK);
CHECK(sharedSet.initialize() == result::OK);
CHECK(sharedSet.lockDataset() == result::OK);
CHECK(sharedSet.unlockDataset() == result::OK);
CHECK(sharedSet.registerVariable(&localSet.localPoolVarUint8) == returnvalue::OK);
CHECK(sharedSet.registerVariable(&localSet.localPoolUint16Vec) == returnvalue::OK);
CHECK(sharedSet.initialize() == returnvalue::OK);
CHECK(sharedSet.lockDataset() == returnvalue::OK);
CHECK(sharedSet.unlockDataset() == returnvalue::OK);
{
// PoolReadGuard rg(&sharedSet);
@ -273,7 +274,7 @@ TEST_CASE("DataSetTest", "[DataSetTest]") {
localSet.localPoolUint16Vec.value[0] = 1;
localSet.localPoolUint16Vec.value[1] = 2;
localSet.localPoolUint16Vec.value[2] = 3;
CHECK(sharedSet.commit() == result::OK);
CHECK(sharedSet.commit() == returnvalue::OK);
}
sharedSet.setReadCommitProtectionBehaviour(true);

View File

@ -22,8 +22,8 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") {
auto hkReceiver = HkReceiverMock(hkDest);
auto queue = MessageQueueMock(3);
LocalPoolOwnerBase poolOwner(queue, objects::TEST_LOCAL_POOL_OWNER_BASE);
REQUIRE(poolOwner.initializeHkManager() == result::OK);
REQUIRE(poolOwner.initializeHkManagerAfterTaskCreation() == result::OK);
REQUIRE(poolOwner.initializeHkManager() == returnvalue::OK);
REQUIRE(poolOwner.initializeHkManagerAfterTaskCreation() == returnvalue::OK);
MessageQueueMock& poolOwnerMock = poolOwner.getMockQueueHandle();
@ -46,14 +46,14 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") {
CHECK(owner->getObjectId() == objects::TEST_LOCAL_POOL_OWNER_BASE);
/* Subscribe for message generation on update. */
REQUIRE(poolOwner.subscribeWrapperSetUpdate(subscriberId) == result::OK);
REQUIRE(poolOwner.subscribeWrapperSetUpdate(subscriberId) == returnvalue::OK);
/* Subscribe for an update message. */
poolOwner.dataset.setChanged(true);
/* Now the update message should be generated. */
REQUIRE(poolOwner.poolManager.performHkOperation() == result::OK);
REQUIRE(poolOwner.poolManager.performHkOperation() == returnvalue::OK);
REQUIRE(poolOwnerMock.wasMessageSent());
REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == result::OK);
REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == returnvalue::OK);
CHECK(messageSent.getCommand() ==
static_cast<int>(HousekeepingMessage::UPDATE_NOTIFICATION_SET));
@ -62,26 +62,26 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") {
poolOwnerMock.clearMessages(true);
/* Set changed again, result should be the same. */
poolOwner.dataset.setChanged(true);
REQUIRE(poolOwner.poolManager.performHkOperation() == result::OK);
REQUIRE(poolOwner.poolManager.performHkOperation() == returnvalue::OK);
REQUIRE(poolOwnerMock.wasMessageSent() == true);
CHECK(poolOwnerMock.numberOfSentMessages() == 1);
REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == result::OK);
REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == returnvalue::OK);
CHECK(messageSent.getCommand() ==
static_cast<int>(HousekeepingMessage::UPDATE_NOTIFICATION_SET));
poolOwnerMock.clearMessages(true);
/* Now subscribe for set update HK as well. */
REQUIRE(poolOwner.subscribeWrapperSetUpdateHk(false, &hkReceiver) == result::OK);
REQUIRE(poolOwner.subscribeWrapperSetUpdateHk(false, &hkReceiver) == returnvalue::OK);
poolOwner.dataset.setChanged(true);
REQUIRE(poolOwner.poolManager.performHkOperation() == result::OK);
REQUIRE(poolOwner.poolManager.performHkOperation() == returnvalue::OK);
REQUIRE(poolOwnerMock.wasMessageSent() == true);
CHECK(poolOwnerMock.numberOfSentMessages() == 2);
// first message sent should be the update notification
REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == result::OK);
REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == returnvalue::OK);
CHECK(messageSent.getCommand() ==
static_cast<int>(HousekeepingMessage::UPDATE_NOTIFICATION_SET));
REQUIRE(poolOwnerMock.getNextSentMessage(messageSent) == result::OK);
REQUIRE(poolOwnerMock.getNextSentMessage(messageSent) == returnvalue::OK);
CHECK(messageSent.getCommand() == static_cast<int>(HousekeepingMessage::HK_REPORT));
/* Clear message to avoid memory leak, our mock won't do it for us (yet) */
CommandMessageCleaner::clearCommandMessage(&messageSent);
@ -91,7 +91,7 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") {
/* Set the variables in the set to certain values. These are checked later. */
{
PoolReadGuard readHelper(&poolOwner.dataset);
REQUIRE(readHelper.getReadResult() == result::OK);
REQUIRE(readHelper.getReadResult() == returnvalue::OK);
poolOwner.dataset.localPoolVarUint8.value = 5;
poolOwner.dataset.localPoolVarFloat.value = -12.242;
poolOwner.dataset.localPoolUint16Vec.value[0] = 2;
@ -100,7 +100,7 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") {
}
/* Subscribe for snapshot generation on update. */
REQUIRE(poolOwner.subscribeWrapperSetUpdateSnapshot(subscriberId) == result::OK);
REQUIRE(poolOwner.subscribeWrapperSetUpdateSnapshot(subscriberId) == returnvalue::OK);
poolOwner.dataset.setChanged(true);
/* Store current time, we are going to check the (approximate) time equality later */
@ -108,10 +108,10 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") {
Clock::getClock_timeval(&now);
/* Trigger generation of snapshot */
REQUIRE(poolOwner.poolManager.performHkOperation() == result::OK);
REQUIRE(poolOwner.poolManager.performHkOperation() == returnvalue::OK);
REQUIRE(poolOwnerMock.wasMessageSent());
CHECK(poolOwnerMock.numberOfSentMessages() == 1);
REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == result::OK);
REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == returnvalue::OK);
/* Check that snapshot was generated */
CHECK(messageSent.getCommand() == static_cast<int>(HousekeepingMessage::UPDATE_SNAPSHOT_SET));
/* Now we deserialize the snapshot into a new dataset instance */
@ -121,7 +121,7 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") {
store_address_t storeId;
HousekeepingMessage::getUpdateSnapshotSetCommand(&messageSent, &storeId);
ConstAccessorPair accessorPair = tglob::getIpcStoreHandle()->getData(storeId);
REQUIRE(accessorPair.first == result::OK);
REQUIRE(accessorPair.first == returnvalue::OK);
const uint8_t* readOnlyPtr = accessorPair.second.data();
size_t sizeToDeserialize = accessorPair.second.size();
CHECK(newSet.localPoolVarFloat.value == 0);
@ -131,7 +131,7 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") {
CHECK(newSet.localPoolUint16Vec.value[2] == 0);
/* Fill the dataset and timestamp */
REQUIRE(snapshot.deSerialize(&readOnlyPtr, &sizeToDeserialize,
SerializeIF::Endianness::MACHINE) == result::OK);
SerializeIF::Endianness::MACHINE) == returnvalue::OK);
/* Now we check that the snapshot is actually correct */
CHECK(newSet.localPoolVarFloat.value == Catch::Approx(-12.242));
CHECK(newSet.localPoolVarUint8 == 5);
@ -142,7 +142,7 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") {
/* Now we check that both times are equal */
timeval timeFromHK{};
auto result = CCSDSTime::convertFromCDS(&timeFromHK, &cdsShort);
CHECK(result == HasReturnvaluesIF::RETURN_OK);
CHECK(result == returnvalue::OK);
timeval difference = timeFromHK - now;
CHECK(timevalOperations::toDouble(difference) < 1.0);
}
@ -154,14 +154,14 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") {
/* Subscribe for variable snapshot */
REQUIRE(poolOwner.subscribeWrapperVariableSnapshot(subscriberId, lpool::uint8VarId) ==
result::OK);
returnvalue::OK);
auto poolVar =
dynamic_cast<lp_var_t<uint8_t>*>(poolOwner.getPoolObjectHandle(lpool::uint8VarId));
REQUIRE(poolVar != nullptr);
{
PoolReadGuard rg(poolVar);
CHECK(rg.getReadResult() == result::OK);
CHECK(rg.getReadResult() == returnvalue::OK);
poolVar->value = 25;
}
@ -170,7 +170,7 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") {
CCSDSTime::CDS_short timeCdsNow{};
timeval now{};
Clock::getClock_timeval(&now);
REQUIRE(poolOwner.poolManager.performHkOperation() == result::OK);
REQUIRE(poolOwner.poolManager.performHkOperation() == returnvalue::OK);
/* Check update snapshot was sent. */
REQUIRE(poolOwnerMock.wasMessageSent());
@ -178,7 +178,7 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") {
/* Should have been reset. */
CHECK(poolVar->hasChanged() == false);
REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == result::OK);
REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == returnvalue::OK);
CHECK(messageSent.getCommand() ==
static_cast<int>(HousekeepingMessage::UPDATE_SNAPSHOT_VARIABLE));
/* Now we deserialize the snapshot into a new dataset instance */
@ -188,19 +188,19 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") {
store_address_t storeId;
HousekeepingMessage::getUpdateSnapshotVariableCommand(&messageSent, &storeId);
ConstAccessorPair accessorPair = tglob::getIpcStoreHandle()->getData(storeId);
REQUIRE(accessorPair.first == result::OK);
REQUIRE(accessorPair.first == returnvalue::OK);
const uint8_t* readOnlyPtr = accessorPair.second.data();
size_t sizeToDeserialize = accessorPair.second.size();
CHECK(varCopy.value == 0);
/* Fill the dataset and timestamp */
REQUIRE(snapshot.deSerialize(&readOnlyPtr, &sizeToDeserialize,
SerializeIF::Endianness::MACHINE) == result::OK);
SerializeIF::Endianness::MACHINE) == returnvalue::OK);
CHECK(varCopy.value == 25);
/* Now we check that both times are equal */
timeval timeFromHK{};
auto result = CCSDSTime::convertFromCDS(&timeFromHK, &cdsShort);
CHECK(result == HasReturnvaluesIF::RETURN_OK);
CHECK(result == returnvalue::OK);
timeval difference = timeFromHK - now;
CHECK(timevalOperations::toDouble(difference) < 1.0);
}
@ -212,30 +212,30 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") {
/* Subscribe for variable update */
REQUIRE(poolOwner.subscribeWrapperVariableUpdate(subscriberId, lpool::uint8VarId) ==
result::OK);
returnvalue::OK);
auto* poolVar =
dynamic_cast<lp_var_t<uint8_t>*>(poolOwner.getPoolObjectHandle(lpool::uint8VarId));
REQUIRE(poolVar != nullptr);
poolVar->setChanged(true);
REQUIRE(poolVar->hasChanged() == true);
REQUIRE(poolOwner.poolManager.performHkOperation() == result::OK);
REQUIRE(poolOwner.poolManager.performHkOperation() == returnvalue::OK);
/* Check update notification was sent. */
REQUIRE(poolOwnerMock.wasMessageSent());
CHECK(poolOwnerMock.numberOfSentMessages() == 1);
/* Should have been reset. */
CHECK(poolVar->hasChanged() == false);
REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == result::OK);
REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == returnvalue::OK);
CHECK(messageSent.getCommand() ==
static_cast<int>(HousekeepingMessage::UPDATE_NOTIFICATION_VARIABLE));
/* Now subscribe for the dataset update (HK and update) again with subscription interface */
REQUIRE(subscriptionIF->subscribeForSetUpdateMessage(lpool::testSetId, objects::NO_OBJECT,
subscriberId, false) == result::OK);
REQUIRE(poolOwner.subscribeWrapperSetUpdateHk(false, &hkReceiver) == result::OK);
subscriberId, false) == returnvalue::OK);
REQUIRE(poolOwner.subscribeWrapperSetUpdateHk(false, &hkReceiver) == returnvalue::OK);
poolOwner.dataset.setChanged(true);
poolOwnerMock.clearMessages();
REQUIRE(poolOwner.poolManager.performHkOperation() == result::OK);
REQUIRE(poolOwner.poolManager.performHkOperation() == returnvalue::OK);
/* Now two messages should be sent. */
REQUIRE(poolOwnerMock.wasMessageSent());
CHECK(poolOwnerMock.numberOfSentMessages() == 2);
@ -244,24 +244,23 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") {
poolOwner.dataset.setChanged(true);
poolOwnerMock.clearMessages(true);
poolVar->setChanged(true);
REQUIRE(poolOwner.poolManager.performHkOperation() == result::OK);
REQUIRE(poolOwner.poolManager.performHkOperation() == returnvalue::OK);
/* Now three messages should be sent. */
REQUIRE(poolOwnerMock.wasMessageSent());
CHECK(poolOwnerMock.numberOfSentMessages() == 3);
CHECK(poolOwnerMock.numberOfSentMessagesToDest(subscriberId) == 2);
CHECK(poolOwnerMock.numberOfSentMessagesToDest(hkDest) == 1);
REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == result::OK);
REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == returnvalue::OK);
CHECK(messageSent.getCommand() ==
static_cast<int>(HousekeepingMessage::UPDATE_NOTIFICATION_VARIABLE));
REQUIRE(poolOwnerMock.clearLastSentMessage(subscriberId) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) ==
HasReturnvaluesIF::RETURN_OK);
REQUIRE(poolOwnerMock.clearLastSentMessage(subscriberId) == returnvalue::OK);
REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == returnvalue::OK);
CHECK(messageSent.getCommand() ==
static_cast<int>(HousekeepingMessage::UPDATE_NOTIFICATION_SET));
REQUIRE(poolOwnerMock.clearLastSentMessage(subscriberId) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(poolOwnerMock.getNextSentMessage(messageSent) == result::OK);
REQUIRE(poolOwnerMock.clearLastSentMessage(subscriberId) == returnvalue::OK);
REQUIRE(poolOwnerMock.getNextSentMessage(messageSent) == returnvalue::OK);
CHECK(messageSent.getCommand() == static_cast<int>(HousekeepingMessage::HK_REPORT));
REQUIRE(poolOwnerMock.clearLastSentMessage() == HasReturnvaluesIF::RETURN_OK);
REQUIRE(poolOwnerMock.clearLastSentMessage() == returnvalue::OK);
REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == MessageQueueIF::EMPTY);
REQUIRE(poolOwnerMock.getNextSentMessage(messageSent) == MessageQueueIF::EMPTY);
}
@ -271,62 +270,62 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") {
the temporal behaviour correctly the HK manager should generate a HK packet
immediately and the periodic helper depends on HK op function calls anyway instead of
using the clock, so we could also just call performHkOperation multiple times */
REQUIRE(poolOwner.subscribePeriodicHk(true) == result::OK);
REQUIRE(poolOwner.poolManager.performHkOperation() == result::OK);
REQUIRE(poolOwner.subscribePeriodicHk(true) == returnvalue::OK);
REQUIRE(poolOwner.poolManager.performHkOperation() == returnvalue::OK);
/* Now HK packet should be sent as message immediately. */
REQUIRE(poolOwnerMock.wasMessageSent());
CHECK(poolOwnerMock.numberOfSentMessages() == 1);
CHECK(poolOwnerMock.clearLastSentMessage() == result::OK);
CHECK(poolOwnerMock.clearLastSentMessage() == returnvalue::OK);
LocalPoolDataSetBase* setHandle = poolOwner.getDataSetHandle(lpool::testSid);
REQUIRE(setHandle != nullptr);
CHECK(poolOwner.poolManager.generateHousekeepingPacket(lpool::testSid, setHandle, false) ==
result::OK);
returnvalue::OK);
REQUIRE(poolOwnerMock.wasMessageSent());
CHECK(poolOwnerMock.numberOfSentMessages() == 1);
CHECK(poolOwnerMock.clearLastSentMessage() == result::OK);
CHECK(poolOwnerMock.clearLastSentMessage() == returnvalue::OK);
CHECK(setHandle->getReportingEnabled() == true);
CommandMessage hkCmd;
HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid, false, false);
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == result::OK);
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
CHECK(setHandle->getReportingEnabled() == false);
REQUIRE(poolOwnerMock.wasMessageSent());
CHECK(poolOwnerMock.numberOfSentMessages() == 1);
CHECK(poolOwnerMock.clearLastSentMessage() == result::OK);
CHECK(poolOwnerMock.clearLastSentMessage() == returnvalue::OK);
HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid, true, false);
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == result::OK);
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
CHECK(setHandle->getReportingEnabled() == true);
REQUIRE(poolOwnerMock.wasMessageSent());
CHECK(poolOwnerMock.clearLastSentMessage() == result::OK);
CHECK(poolOwnerMock.clearLastSentMessage() == returnvalue::OK);
HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid, false, false);
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == result::OK);
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
CHECK(setHandle->getReportingEnabled() == false);
REQUIRE(poolOwnerMock.wasMessageSent());
CHECK(poolOwnerMock.clearLastSentMessage() == result::OK);
CHECK(poolOwnerMock.clearLastSentMessage() == returnvalue::OK);
HousekeepingMessage::setCollectionIntervalModificationCommand(&hkCmd, lpool::testSid, 0.4,
false);
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == result::OK);
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
/* For non-diagnostics and a specified minimum frequency of 0.2 seconds, the
resulting collection interval should be 1.0 second */
CHECK(poolOwner.dataset.getCollectionInterval() == 1.0);
REQUIRE(poolOwnerMock.wasMessageSent());
REQUIRE(poolOwnerMock.numberOfSentMessages() == 1);
CHECK(poolOwnerMock.clearLastSentMessage() == result::OK);
CHECK(poolOwnerMock.clearLastSentMessage() == returnvalue::OK);
HousekeepingMessage::setStructureReportingCommand(&hkCmd, lpool::testSid, false);
REQUIRE(poolOwner.poolManager.performHkOperation() == result::OK);
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == result::OK);
REQUIRE(poolOwner.poolManager.performHkOperation() == returnvalue::OK);
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
/* Now HK packet should be sent as message. */
REQUIRE(poolOwnerMock.wasMessageSent());
REQUIRE(poolOwnerMock.numberOfSentMessages() == 1);
poolOwnerMock.clearMessages();
HousekeepingMessage::setOneShotReportCommand(&hkCmd, lpool::testSid, false);
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == result::OK);
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
REQUIRE(poolOwnerMock.wasMessageSent());
REQUIRE(poolOwnerMock.numberOfSentMessages() == 1);
poolOwnerMock.clearMessages();
@ -334,7 +333,7 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") {
HousekeepingMessage::setUpdateNotificationSetCommand(&hkCmd, lpool::testSid);
sid_t sidToCheck;
store_address_t storeId;
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == result::OK);
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
CHECK(poolOwner.changedDataSetCallbackWasCalled(sidToCheck, storeId) == true);
CHECK(sidToCheck == lpool::testSid);
@ -347,7 +346,7 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") {
/* We still expect a failure message being sent */
REQUIRE(poolOwnerMock.wasMessageSent());
REQUIRE(poolOwnerMock.numberOfSentMessages() == 1);
CHECK(poolOwnerMock.clearLastSentMessage() == result::OK);
CHECK(poolOwnerMock.clearLastSentMessage() == returnvalue::OK);
HousekeepingMessage::setCollectionIntervalModificationCommand(&hkCmd, lpool::testSid, 0.4,
false);
@ -355,36 +354,36 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") {
static_cast<int>(LocalDataPoolManager::WRONG_HK_PACKET_TYPE));
REQUIRE(poolOwnerMock.wasMessageSent());
REQUIRE(poolOwnerMock.numberOfSentMessages() == 1);
CHECK(poolOwnerMock.clearLastSentMessage() == result::OK);
CHECK(poolOwnerMock.clearLastSentMessage() == returnvalue::OK);
HousekeepingMessage::setStructureReportingCommand(&hkCmd, lpool::testSid, false);
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) ==
static_cast<int>(LocalDataPoolManager::WRONG_HK_PACKET_TYPE));
REQUIRE(poolOwnerMock.wasMessageSent());
REQUIRE(poolOwnerMock.numberOfSentMessages() == 1);
CHECK(poolOwnerMock.clearLastSentMessage() == result::OK);
CHECK(poolOwnerMock.clearLastSentMessage() == returnvalue::OK);
HousekeepingMessage::setStructureReportingCommand(&hkCmd, lpool::testSid, true);
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == result::OK);
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
REQUIRE(poolOwnerMock.wasMessageSent());
REQUIRE(poolOwnerMock.numberOfSentMessages() == 1);
poolOwnerMock.clearMessages();
HousekeepingMessage::setCollectionIntervalModificationCommand(&hkCmd, lpool::testSid, 0.4,
true);
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == result::OK);
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
REQUIRE(poolOwnerMock.wasMessageSent());
REQUIRE(poolOwnerMock.numberOfSentMessages() == 1);
poolOwnerMock.clearMessages();
HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid, true, true);
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == result::OK);
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
REQUIRE(poolOwnerMock.wasMessageSent());
REQUIRE(poolOwnerMock.numberOfSentMessages() == 1);
poolOwnerMock.clearMessages();
HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid, false, true);
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == result::OK);
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
REQUIRE(poolOwnerMock.wasMessageSent());
REQUIRE(poolOwnerMock.numberOfSentMessages() == 1);
poolOwnerMock.clearMessages();
@ -397,26 +396,26 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") {
poolOwnerMock.clearMessages();
HousekeepingMessage::setOneShotReportCommand(&hkCmd, lpool::testSid, true);
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == result::OK);
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
REQUIRE(poolOwnerMock.wasMessageSent());
REQUIRE(poolOwnerMock.numberOfSentMessages() == 1);
poolOwnerMock.clearMessages();
HousekeepingMessage::setUpdateNotificationVariableCommand(&hkCmd, lpool::uint8VarGpid);
gp_id_t gpidToCheck;
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == result::OK);
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
CHECK(poolOwner.changedVariableCallbackWasCalled(gpidToCheck, storeId) == true);
CHECK(gpidToCheck == lpool::uint8VarGpid);
HousekeepingMessage::setUpdateSnapshotSetCommand(&hkCmd, lpool::testSid,
store_address_t::invalid());
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == result::OK);
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
CHECK(poolOwner.changedDataSetCallbackWasCalled(sidToCheck, storeId) == true);
CHECK(sidToCheck == lpool::testSid);
HousekeepingMessage::setUpdateSnapshotVariableCommand(&hkCmd, lpool::uint8VarGpid,
store_address_t::invalid());
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == result::OK);
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
CHECK(poolOwner.changedVariableCallbackWasCalled(gpidToCheck, storeId) == true);
CHECK(gpidToCheck == lpool::uint8VarGpid);
@ -425,6 +424,6 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") {
/* we need to reset the subscription list because the pool owner
is a global object. */
CHECK(poolOwner.reset() == result::OK);
CHECK(poolOwner.reset() == returnvalue::OK);
poolOwnerMock.clearMessages(true);
}

View File

@ -7,26 +7,28 @@
#include "mocks/LocalPoolOwnerBase.h"
#include "tests/TestsConfig.h"
using namespace returnvalue;
TEST_CASE("LocalPoolVariable", "[LocPoolVarTest]") {
auto queue = MessageQueueMock(1);
LocalPoolOwnerBase poolOwner(queue, objects::TEST_LOCAL_POOL_OWNER_BASE);
REQUIRE(poolOwner.initializeHkManager() == result::OK);
REQUIRE(poolOwner.initializeHkManagerAfterTaskCreation() == result::OK);
REQUIRE(poolOwner.initializeHkManager() == OK);
REQUIRE(poolOwner.initializeHkManagerAfterTaskCreation() == OK);
SECTION("Basic Tests") {
/* very basic test. */
lp_var_t<uint8_t> testVariable =
lp_var_t<uint8_t>(objects::TEST_LOCAL_POOL_OWNER_BASE, lpool::uint8VarId);
REQUIRE(testVariable.read() == result::OK);
REQUIRE(testVariable.read() == returnvalue::OK);
CHECK(testVariable.value == 0);
testVariable.value = 5;
REQUIRE(testVariable.commit() == result::OK);
REQUIRE(testVariable.read() == result::OK);
REQUIRE(testVariable.commit() == returnvalue::OK);
REQUIRE(testVariable.read() == returnvalue::OK);
REQUIRE(testVariable.value == 5);
CHECK(not testVariable.isValid());
testVariable.setValid(true);
CHECK(testVariable.isValid());
CHECK(testVariable.commit(true) == result::OK);
CHECK(testVariable.commit(true) == returnvalue::OK);
testVariable.setReadWriteMode(pool_rwm_t::VAR_READ);
CHECK(testVariable.getReadWriteMode() == pool_rwm_t::VAR_READ);
@ -42,7 +44,7 @@ TEST_CASE("LocalPoolVariable", "[LocPoolVarTest]") {
gp_id_t globPoolId(objects::TEST_LOCAL_POOL_OWNER_BASE, lpool::uint8VarId);
lp_var_t<uint8_t> testVariable2 = lp_var_t<uint8_t>(globPoolId);
REQUIRE(testVariable2.read() == result::OK);
REQUIRE(testVariable2.read() == returnvalue::OK);
CHECK(testVariable2 == 5);
CHECK(testVariable == testVariable2);
testVariable = 10;
@ -54,12 +56,12 @@ TEST_CASE("LocalPoolVariable", "[LocPoolVarTest]") {
CHECK(maxSize == 1);
size_t serSize = 0;
CHECK(testVariable.serialize(&varPtr, &serSize, maxSize, SerializeIF::Endianness::MACHINE) ==
result::OK);
returnvalue::OK);
CHECK(variableRaw == 10);
const uint8_t* varConstPtr = &variableRaw;
testVariable = 5;
CHECK(testVariable.deSerialize(&varConstPtr, &serSize, SerializeIF::Endianness::MACHINE) ==
result::OK);
returnvalue::OK);
CHECK(testVariable == 10);
CHECK(testVariable != testVariable2);
CHECK(testVariable2 < testVariable);

View File

@ -7,29 +7,31 @@
#include "mocks/LocalPoolOwnerBase.h"
#include "tests/TestsConfig.h"
using namespace returnvalue;
TEST_CASE("LocalPoolVector", "[LocPoolVecTest]") {
auto queue = MessageQueueMock(1);
LocalPoolOwnerBase poolOwner(queue, objects::TEST_LOCAL_POOL_OWNER_BASE);
REQUIRE(poolOwner.initializeHkManager() == result::OK);
REQUIRE(poolOwner.initializeHkManagerAfterTaskCreation() == result::OK);
REQUIRE(poolOwner.initializeHkManager() == OK);
REQUIRE(poolOwner.initializeHkManagerAfterTaskCreation() == OK);
SECTION("BasicTest") {
// very basic test.
lp_vec_t<uint16_t, 3> testVector =
lp_vec_t<uint16_t, 3>(objects::TEST_LOCAL_POOL_OWNER_BASE, lpool::uint16Vec3Id);
REQUIRE(testVector.read() == result::OK);
REQUIRE(testVector.read() == returnvalue::OK);
testVector.value[0] = 5;
testVector.value[1] = 232;
testVector.value[2] = 32023;
REQUIRE(testVector.commit(true) == result::OK);
REQUIRE(testVector.commit(true) == returnvalue::OK);
CHECK(testVector.isValid());
testVector.value[0] = 0;
testVector.value[1] = 0;
testVector.value[2] = 0;
CHECK(testVector.read() == result::OK);
CHECK(testVector.read() == returnvalue::OK);
CHECK(testVector.value[0] == 5);
CHECK(testVector.value[1] == 232);
CHECK(testVector.value[2] == 32023);
@ -40,7 +42,7 @@ TEST_CASE("LocalPoolVector", "[LocPoolVecTest]") {
(we can't throw exceptions) */
testVector[4] = 12;
CHECK(testVector[2] == 12);
CHECK(testVector.commit() == result::OK);
CHECK(testVector.commit() == returnvalue::OK);
/* Use read-only reference. */
const lp_vec_t<uint16_t, 3>& roTestVec = testVector;
@ -57,7 +59,7 @@ TEST_CASE("LocalPoolVector", "[LocPoolVecTest]") {
uint8_t* vecPtr = reinterpret_cast<uint8_t*>(serializedVector);
size_t serSize = 0;
REQUIRE(testVector.serialize(&vecPtr, &serSize, maxSize, SerializeIF::Endianness::MACHINE) ==
result::OK);
returnvalue::OK);
CHECK(serSize == 6);
CHECK(serializedVector[0] == 5);
@ -74,7 +76,7 @@ TEST_CASE("LocalPoolVector", "[LocPoolVecTest]") {
const uint8_t* constVecPtr = reinterpret_cast<const uint8_t*>(serializedVector);
REQUIRE(testVector.deSerialize(&constVecPtr, &serSize, SerializeIF::Endianness::MACHINE) ==
result::OK);
returnvalue::OK);
CHECK(testVector[0] == 16);
CHECK(testVector[1] == 7832);
CHECK(testVector[2] == 39232);