Update and clean up HK and Local Pool Modules

This commit is contained in:
2024-12-12 16:15:02 +01:00
parent 5dfeee08b3
commit 842a3b1b03
213 changed files with 4125 additions and 4972 deletions

View File

@ -0,0 +1,4 @@
target_sources(
${FSFW_TEST_TGT}
PRIVATE testLocalPoolVariable.cpp testLocalPoolVector.cpp testSharedSet.cpp
testPeriodicHkHelper.cpp testDataset.cpp)

View File

@ -0,0 +1,85 @@
#include <fsfw/housekeeping/Dataset.h>
#include <fsfw/housekeeping/DatasetElement.h>
#include <fsfw/serialize/SerializeElement.h>
#include <catch2/catch_test_macros.hpp>
constexpr auto TEST_ID = dp::structure_id_t(1, 2);
class TestDatasetSmall : public hk::Dataset {
public:
TestDatasetSmall() : hk::Dataset(TEST_ID, false) {}
hk::lvar_u8 test0{*this};
hk::lvar_u32 test1{*this};
};
class TestDatasetLarger : public hk::Dataset {
public:
TestDatasetLarger() : hk::Dataset(TEST_ID, false) {}
hk::lvar_u8 test0{*this};
hk::lvar_u32 test1{*this};
hk::lvar_u16 test2{*this};
hk::lvar_i32 test3{*this};
hk::lvar_f32 test4{*this};
hk::lvar_f64 test5{*this};
hk::lvar_u8 test6{*this};
hk::lvar_i16 test7{*this};
hk::lvec_u16<2> test8{*this};
};
TEST_CASE("Pool Dataset Test", "[datapool]") {
TestDatasetSmall dataset;
CHECK(dataset.getStructureId() == TEST_ID);
CHECK(!dataset.test0.isValid());
dataset.test0.setValid(true);
CHECK(dataset.test0.isValid());
SECTION("Pool Dataset Serialization Test 1") {
uint8_t buf[64]{};
dataset.test0 = 55;
dataset.test1 = 502392;
size_t serLen = 0;
CHECK(dataset.serialize(buf, serLen, sizeof(buf), SerializeIF::Endianness::NETWORK) ==
returnvalue::OK);
CHECK(buf[0] == 55);
CHECK(serLen == 5);
uint32_t readBack = 0;
size_t dummy = 0;
CHECK(SerializeAdapter::deSerialize(&readBack, buf + 1, &dummy,
SerializeIF::Endianness::NETWORK) == returnvalue::OK);
CHECK(readBack == 502392);
CHECK(buf[5] == 0);
}
SECTION("Pool Dataset Serialization With Validity") {
uint8_t buf[64]{};
dataset.test0 = 55;
dataset.test1 = 502392;
dataset.test0.setValid(true);
dataset.test1.setValid(true);
size_t serLen = 0;
uint8_t* dataPtr = buf;
dataset.serializeWithValidityBlob = true;
CHECK(dataset.getSerializedSize() == 6);
CHECK(dataset.serialize(&dataPtr, &serLen, sizeof(buf), SerializeIF::Endianness::NETWORK) ==
returnvalue::OK);
CHECK(buf[5] == 0b11000000);
}
SECTION("Larger Pool Dataset Serialization With Validity") {
uint8_t buf[64]{};
TestDatasetLarger datasetLarge;
datasetLarge.setChildrenValidity(true);
size_t serLen = 0;
uint8_t* dataPtr = buf;
datasetLarge.serializeWithValidityBlob = true;
CHECK(datasetLarge.serialize(&dataPtr, &serLen, sizeof(buf),
SerializeIF::Endianness::NETWORK) == returnvalue::OK);
CHECK(serLen == 32);
CHECK(buf[30] == 0b11111111);
CHECK(buf[31] == 0b10000000);
CHECK(buf[32] == 0);
}
}

View File

@ -0,0 +1,100 @@
#include <fsfw/housekeeping/PeriodicHkHelper.h>
#include <fsfw/objectmanager/ObjectManager.h>
#include <catch2/catch_test_macros.hpp>
#include "CatchDefinitions.h"
#include "mock/TestPoolOwner.h"
#include "tests/TestsConfig.h"
using namespace returnvalue;
using namespace lpool;
using namespace dp;
TEST_CASE("LocalPoolVariable", "[LocPoolVarTest]") {
auto queue = MessageQueueMock(1, MessageQueueIF::NO_QUEUE);
lpool::TestPoolOwner poolOwner(queue, objects::TEST_LOCAL_POOL_OWNER_BASE);
REQUIRE(poolOwner.initialize() == OK);
SECTION("Basic Tests") {
/* very basic test. */
u8_t testVariable{objects::TEST_LOCAL_POOL_OWNER_BASE, lpool::uint8VarId};
REQUIRE(testVariable.read() == returnvalue::OK);
CHECK(testVariable.value == 0);
testVariable.value = 5;
REQUIRE(testVariable.commit() == returnvalue::OK);
REQUIRE(testVariable.read() == returnvalue::OK);
REQUIRE(testVariable.value == 5);
CHECK(testVariable.commit() == returnvalue::OK);
testVariable.setReadWriteMode(pool_rwm_t::VAR_READ);
CHECK(testVariable.getReadWriteMode() == pool_rwm_t::VAR_READ);
testVariable.setReadWriteMode(pool_rwm_t::VAR_READ_WRITE);
testVariable.setDataPoolId(22);
CHECK(testVariable.getDataPoolId() == 22);
testVariable.setDataPoolId(lpool::uint8VarId);
g_id_t globPoolId(objects::TEST_LOCAL_POOL_OWNER_BASE, lpool::uint8VarId);
u8_t testVariable2{globPoolId};
REQUIRE(testVariable2.read() == returnvalue::OK);
CHECK(testVariable2 == 5);
CHECK(testVariable == testVariable2);
testVariable = 10;
CHECK(testVariable != 5);
// CHECK(not testVariable != testVariable2);
uint8_t variableRaw = 0;
uint8_t* varPtr = &variableRaw;
size_t maxSize = testVariable.getSerializedSize();
CHECK(maxSize == 1);
size_t serSize = 0;
CHECK(testVariable.serialize(&varPtr, &serSize, maxSize, SerializeIF::Endianness::MACHINE) ==
returnvalue::OK);
CHECK(variableRaw == 10);
const uint8_t* varConstPtr = &variableRaw;
testVariable = 5;
CHECK(testVariable.deSerialize(&varConstPtr, &serSize, SerializeIF::Endianness::MACHINE) ==
returnvalue::OK);
CHECK(testVariable == 10);
CHECK(testVariable != testVariable2);
CHECK(testVariable2 < testVariable);
CHECK(testVariable2 < 10);
CHECK(testVariable > 5);
CHECK(testVariable > testVariable2);
variableRaw = static_cast<uint8_t>(testVariable2);
CHECK(variableRaw == 5);
CHECK(testVariable == 10);
testVariable = testVariable2;
CHECK(testVariable == 5);
}
SECTION("ErrorHandling") {
/* now try to use a local pool variable which does not exist */
dp::u8_t invalidVariable{objects::TEST_LOCAL_POOL_OWNER_BASE, 0xffffffff};
REQUIRE(invalidVariable.read() == static_cast<int>(POOL_ENTRY_NOT_FOUND));
REQUIRE(invalidVariable.commit() == static_cast<int>(POOL_ENTRY_NOT_FOUND));
/* now try to access with wrong type */
dp::i8_t invalidVariable2 = dp::i8_t(objects::TEST_LOCAL_POOL_OWNER_BASE, lpool::uint8VarId);
REQUIRE(invalidVariable2.read() == static_cast<int>(POOL_ENTRY_TYPE_CONFLICT));
dp::var_t<uint8_t> readOnlyVar = dp::var_t<uint8_t>(
objects::TEST_LOCAL_POOL_OWNER_BASE, lpool::uint8VarId, nullptr, pool_rwm_t::VAR_READ);
REQUIRE(readOnlyVar.commit() == static_cast<int>(PoolVariableIF::INVALID_READ_WRITE_MODE));
dp::var_t<uint8_t> writeOnlyVar = dp::var_t<uint8_t>(
objects::TEST_LOCAL_POOL_OWNER_BASE, lpool::uint8VarId, nullptr, pool_rwm_t::VAR_WRITE);
REQUIRE(writeOnlyVar.read() == static_cast<int>(PoolVariableIF::INVALID_READ_WRITE_MODE));
dp::var_t<uint32_t> uint32tVar =
dp::var_t<uint32_t>(objects::TEST_LOCAL_POOL_OWNER_BASE, lpool::uint32VarId);
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::info << "LocalPoolVariable printout: " << uint32tVar << std::endl;
#endif
/* for code coverage. If program does not crash -> OK */
dp::var_t<uint8_t> invalidObjectVar = dp::var_t<uint8_t>(0xffffffff, lpool::uint8VarId);
dp::g_id_t globPoolId(0xffffffff, lpool::uint8VarId);
dp::var_t<uint8_t> invalidObjectVar2 = dp::var_t<uint8_t>(globPoolId);
}
}

View File

@ -0,0 +1,106 @@
#include <fsfw/objectmanager/ObjectManager.h>
#include <catch2/catch_test_macros.hpp>
#include "CatchDefinitions.h"
#include "mock/TestPoolOwner.h"
#include "tests/TestsConfig.h"
using namespace returnvalue;
using namespace dp;
using namespace lpool;
TEST_CASE("LocalPoolVector", "[LocPoolVecTest]") {
auto queue = MessageQueueMock(1, MessageQueueIF::NO_QUEUE);
lpool::TestPoolOwner poolOwner(queue, objects::TEST_LOCAL_POOL_OWNER_BASE);
REQUIRE(poolOwner.initialize() == OK);
SECTION("BasicTest") {
// very basic test.
auto testVector = vec_t<uint16_t, 3>(objects::TEST_LOCAL_POOL_OWNER_BASE, lpool::uint16Vec3Id);
REQUIRE(testVector.read() == returnvalue::OK);
testVector.value[0] = 5;
testVector.value[1] = 232;
testVector.value[2] = 32023;
REQUIRE(testVector.commit() == returnvalue::OK);
testVector.value[0] = 0;
testVector.value[1] = 0;
testVector.value[2] = 0;
CHECK(testVector.read() == returnvalue::OK);
CHECK(testVector.value[0] == 5);
CHECK(testVector.value[1] == 232);
CHECK(testVector.value[2] == 32023);
CHECK(testVector[0] == 5);
/* This is invalid access, so the last value will be set instead.
(we can't throw exceptions) */
testVector[4] = 12;
CHECK(testVector[2] == 12);
CHECK(testVector.commit() == returnvalue::OK);
/* Use read-only reference. */
const dp::vec_t<uint16_t, 3>& roTestVec = testVector;
uint16_t valueOne = roTestVec[0];
CHECK(valueOne == 5);
uint16_t lastVal = roTestVec[25];
CHECK(lastVal == 12);
size_t maxSize = testVector.getSerializedSize();
CHECK(maxSize == 6);
uint16_t serializedVector[3];
auto* vecPtr = reinterpret_cast<uint8_t*>(serializedVector);
size_t serSize = 0;
REQUIRE(testVector.serialize(&vecPtr, &serSize, maxSize, SerializeIF::Endianness::MACHINE) ==
returnvalue::OK);
CHECK(serSize == 6);
CHECK(serializedVector[0] == 5);
CHECK(serializedVector[1] == 232);
CHECK(serializedVector[2] == 12);
maxSize = 1;
REQUIRE(testVector.serialize(&vecPtr, &serSize, maxSize, SerializeIF::Endianness::MACHINE) ==
static_cast<int>(SerializeIF::BUFFER_TOO_SHORT));
serializedVector[0] = 16;
serializedVector[1] = 7832;
serializedVector[2] = 39232;
const auto* constVecPtr = reinterpret_cast<const uint8_t*>(serializedVector);
REQUIRE(testVector.deSerialize(&constVecPtr, &serSize, SerializeIF::Endianness::MACHINE) ==
returnvalue::OK);
CHECK(testVector[0] == 16);
CHECK(testVector[1] == 7832);
CHECK(testVector[2] == 39232);
serSize = 1;
REQUIRE(testVector.deSerialize(&constVecPtr, &serSize, SerializeIF::Endianness::MACHINE) ==
static_cast<int>(SerializeIF::STREAM_TOO_SHORT));
}
SECTION("ErrorHandling") {
/* Now try to use a local pool variable which does not exist */
dp::vec_t<uint16_t, 3> invalidVector{objects::TEST_LOCAL_POOL_OWNER_BASE, 0xffffffff};
REQUIRE(invalidVector.read() == static_cast<int>(POOL_ENTRY_NOT_FOUND));
REQUIRE(invalidVector.commit() == static_cast<int>(POOL_ENTRY_NOT_FOUND));
/* Now try to access with wrong type */
dp::vec_t<uint32_t, 3> invalidVector2{objects::TEST_LOCAL_POOL_OWNER_BASE, lpool::uint16Vec3Id};
REQUIRE(invalidVector2.read() == static_cast<int>(POOL_ENTRY_TYPE_CONFLICT));
REQUIRE(invalidVector2.commit() == static_cast<int>(POOL_ENTRY_TYPE_CONFLICT));
dp::vec_t<uint16_t, 3> writeOnlyVec{objects::TEST_LOCAL_POOL_OWNER_BASE, lpool::uint16Vec3Id,
nullptr, pool_rwm_t::VAR_WRITE};
REQUIRE(writeOnlyVec.read() == static_cast<int>(PoolVariableIF::INVALID_READ_WRITE_MODE));
dp::vec_t<uint16_t, 3> readOnlyVec = {objects::TEST_LOCAL_POOL_OWNER_BASE, lpool::uint16Vec3Id,
nullptr, pool_rwm_t::VAR_READ};
REQUIRE(readOnlyVec.commit() == static_cast<int>(PoolVariableIF::INVALID_READ_WRITE_MODE));
}
}

View File

@ -0,0 +1,159 @@
#include <fsfw/datapool/PoolReadGuard.h>
#include <fsfw/globalfunctions/timevalOperations.h>
#include <fsfw/ipc/CommandMessageCleaner.h>
#include <fsfw/objectmanager/ObjectManager.h>
#include <fsfw/tasks/TaskFactory.h>
#include <fsfw/timemanager/CCSDSTime.h>
#include <catch2/catch_approx.hpp>
#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_floating_point.hpp>
#include <iostream>
#include "CatchDefinitions.h"
#include "mock/HkReceiverMock.h"
#include "mock/TestPoolOwner.h"
using namespace lpool;
TEST_CASE("Pool Owner and Periodic HK", "[datapool]") {
constexpr MessageQueueId_t DEFAULT_DEST_ID = 1;
constexpr MessageQueueId_t HK_DEST = DEFAULT_DEST_ID;
auto hkReceiver = HkReceiverMock(HK_DEST);
auto queue = MessageQueueMock(3, HK_DEST);
CommandMessage msg;
TestPoolOwner poolOwner(queue, HK_DEST, objects::TEST_LOCAL_POOL_OWNER_BASE);
REQUIRE(poolOwner.initialize() == returnvalue::OK);
MessageQueueMock& poolOwnerMock = poolOwner.getMockQueueHandle();
CommandMessage messageSent;
// TODO: Fix
SECTION("Basic Test") {
{
// For code coverage, should not crash
hk::PeriodicHelper manager(nullptr, nullptr);
}
auto owner = poolOwner.hkHelper.getOwner();
REQUIRE(owner != nullptr);
CHECK(owner->getObjectId() == objects::TEST_LOCAL_POOL_OWNER_BASE);
// Clear message to avoid memory leak, our mock won't do it for us (yet)
CommandMessageCleaner::clearCommandMessage(&messageSent);
}
SECTION("Periodic HK And Messaging") {
// Now we subcribe for a HK periodic generation. Even when it's difficult to simulate
// 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.enablePeriodicHk(testSid0, 50) == returnvalue::OK);
REQUIRE(poolOwner.hkHelper.performHkOperation() == returnvalue::OK);
// Now HK packet should be sent as message immediately.
REQUIRE(poolOwnerMock.wasMessageSent());
CHECK(poolOwnerMock.numberOfSentMessages() == 1);
CHECK(poolOwnerMock.getNextSentMessageToDefaultDest(msg) == returnvalue::OK);
CHECK(msg.getCommand() == HousekeepingMessage::HK_REPORT);
auto structureId = HousekeepingMessage::getStructureId(&msg);
CHECK(structureId == testSid0);
CHECK(poolOwnerMock.clearLastSentMessage() == returnvalue::OK);
REQUIRE(poolOwner.hkHelper.performHkOperation() == returnvalue::OK);
// No packet should be generated now.
REQUIRE(!poolOwnerMock.wasMessageSent());
CHECK(poolOwnerMock.numberOfSentMessages() == 0);
TaskFactory::delayTask(50);
// Should be generated again now.
REQUIRE(poolOwner.hkHelper.performHkOperation() == returnvalue::OK);
// No packet should be generated now.
REQUIRE(poolOwnerMock.wasMessageSent());
CHECK(poolOwnerMock.numberOfSentMessages() == 1);
CHECK(poolOwnerMock.getNextSentMessageToDefaultDest(msg) == returnvalue::OK);
CHECK(msg.getCommand() == HousekeepingMessage::HK_REPORT);
structureId = HousekeepingMessage::getStructureId(&msg);
CHECK(structureId == testSid0);
}
SECTION("Manual generation with API") {
// We can always generate a packet ourselves.
CHECK(poolOwner.hkHelper.generateHousekeepingPacket(lpool::testSid0) == returnvalue::OK);
REQUIRE(poolOwnerMock.wasMessageSent());
CHECK(poolOwnerMock.numberOfSentMessages() == 1);
CHECK(poolOwnerMock.getNextSentMessageToDefaultDest(msg) == returnvalue::OK);
auto structureId = HousekeepingMessage::getStructureId(&msg);
CHECK(structureId == testSid0);
CHECK(poolOwnerMock.clearLastSentMessage() == returnvalue::OK);
}
SECTION("Generation with Message") {
HousekeepingMessage::setOneShotReportCommand(&msg, lpool::testSid0);
CHECK(poolOwner.hkHelper.handleHousekeepingMessage(&msg) == returnvalue::OK);
REQUIRE(poolOwnerMock.wasMessageSent());
REQUIRE(poolOwnerMock.numberOfSentMessages() == 1);
CHECK(poolOwnerMock.getNextSentMessageToDefaultDest(msg) == returnvalue::OK);
auto structureId = HousekeepingMessage::getStructureId(&msg);
CHECK(structureId == testSid0);
poolOwnerMock.clearMessages();
}
SECTION("Toggle generation with message") {
HousekeepingMessage::setToggleReportingCommand(&msg, lpool::testSid0, false);
CHECK(poolOwner.hkHelper.handleHousekeepingMessage(&msg) == returnvalue::OK);
REQUIRE(poolOwnerMock.wasMessageSent());
CHECK(poolOwnerMock.numberOfSentMessages() == 1);
CHECK(poolOwnerMock.getNextSentMessageToDefaultDest(msg) == returnvalue::OK);
CHECK(msg.getCommand() == HousekeepingMessage::HK_REQUEST_SUCCESS);
auto structureId = HousekeepingMessage::getStructureId(&msg);
CHECK(structureId == testSid0);
CHECK(poolOwnerMock.clearLastSentMessage() == returnvalue::OK);
auto optSetSpec = poolOwner.hkHelper.getSetSpecification(testSid0);
REQUIRE(optSetSpec.has_value());
REQUIRE(!optSetSpec.value().get().collectionEnabled());
HousekeepingMessage::setToggleReportingCommand(&msg, lpool::testSid0, true);
CHECK(poolOwner.hkHelper.handleHousekeepingMessage(&msg) == returnvalue::OK);
REQUIRE(poolOwnerMock.wasMessageSent());
CHECK(poolOwnerMock.getNextSentMessageToDefaultDest(msg) == returnvalue::OK);
CHECK(msg.getCommand() == HousekeepingMessage::HK_REQUEST_SUCCESS);
structureId = HousekeepingMessage::getStructureId(&msg);
CHECK(structureId == testSid0);
CHECK(poolOwnerMock.clearLastSentMessage() == returnvalue::OK);
REQUIRE(optSetSpec.has_value());
REQUIRE(optSetSpec.value().get().collectionEnabled());
}
SECTION("Modify collection interval with message") {
HousekeepingMessage::setCollectionIntervalModificationCommand(&msg, lpool::testSid0, 400);
CHECK(poolOwner.hkHelper.handleHousekeepingMessage(&msg) == returnvalue::OK);
REQUIRE(poolOwnerMock.wasMessageSent());
REQUIRE(poolOwnerMock.numberOfSentMessages() == 1);
CHECK(poolOwnerMock.getNextSentMessageToDefaultDest(msg) == returnvalue::OK);
CHECK(msg.getCommand() == HousekeepingMessage::HK_REQUEST_SUCCESS);
auto structureId = HousekeepingMessage::getStructureId(&msg);
CHECK(structureId == testSid0);
auto optSetSpec = poolOwner.hkHelper.getSetSpecification(testSid0);
REQUIRE(optSetSpec.has_value());
CHECK(optSetSpec.value().get().getCollectionFrequency() == 400);
CHECK(poolOwnerMock.clearLastSentMessage() == returnvalue::OK);
}
SECTION("Structure reporting command") {
HousekeepingMessage::setStructureReportingCommand(&msg, lpool::testSid0);
REQUIRE(poolOwner.hkHelper.performHkOperation() == returnvalue::OK);
CHECK(poolOwner.hkHelper.handleHousekeepingMessage(&msg) == returnvalue::OK);
// Now HK packet should be sent as message.
REQUIRE(poolOwnerMock.wasMessageSent());
REQUIRE(poolOwnerMock.numberOfSentMessages() == 1);
poolOwnerMock.clearMessages();
}
// we need to reset the subscription list because the pool owner
// is a global object.
CHECK(poolOwner.reset() == returnvalue::OK);
poolOwnerMock.clearMessages(true);
}

View File

@ -0,0 +1,178 @@
#include <fsfw/datapool/PoolReadGuard.h>
#include <fsfw/datapool/SharedSet.h>
#include <fsfw/globalfunctions/bitutility.h>
#include <fsfw/objectmanager/ObjectManager.h>
#include <catch2/catch_approx.hpp>
#include <catch2/catch_test_macros.hpp>
#include "CatchDefinitions.h"
#include "mock/MessageQueueMock.h"
#include "mock/TestPoolOwner.h"
#include "tests/TestsConfig.h"
using namespace returnvalue;
using namespace lpool;
TEST_CASE("DataSetTest", "[datapool]") {
auto queue = MessageQueueMock(1, MessageQueueIF::NO_QUEUE);
TestPoolOwner poolOwner(queue, objects::TEST_LOCAL_POOL_OWNER_BASE);
poolOwner.initialize();
StaticTestDataset localSet;
SECTION("BasicTest") {
/* Test some basic functions */
CHECK(localSet.getReportingEnabled() == false);
CHECK(localSet.getSerializedSize() == 11);
CHECK(localSet.getLocalPoolIdsSerializedSize() == 3 * sizeof(dp::id_t));
CHECK(localSet.getStructureId() == lpool::testSid1);
CHECK(localSet.getCreatorObjectId() == objects::TEST_LOCAL_POOL_OWNER_BASE);
size_t maxSize = localSet.getLocalPoolIdsSerializedSize();
uint8_t localPoolIdBuff[maxSize];
// Skip size field
auto* lpIds = reinterpret_cast<id_t*>(localPoolIdBuff);
size_t serSize = 0;
auto* localPoolIdBuffPtr = reinterpret_cast<uint8_t*>(localPoolIdBuff);
// Test local pool ID serialization
CHECK(localSet.serializeLocalPoolIds(&localPoolIdBuffPtr, &serSize, maxSize,
SerializeIF::Endianness::MACHINE) == returnvalue::OK);
CHECK(serSize == maxSize);
// CHECK(localPoolIdBuff[0] == 3);
CHECK(lpIds[0] == localSet.localPoolVarUint8.getDataPoolId());
CHECK(lpIds[1] == localSet.localPoolVarFloat.getDataPoolId());
CHECK(lpIds[2] == localSet.localPoolUint16Vec.getDataPoolId());
// Now serialize without fill count
lpIds = reinterpret_cast<dp::id_t*>(localPoolIdBuff);
localPoolIdBuffPtr = localPoolIdBuff;
serSize = 0;
CHECK(localSet.serializeLocalPoolIds(&localPoolIdBuffPtr, &serSize, maxSize,
SerializeIF::Endianness::MACHINE) == OK);
CHECK(serSize == maxSize);
CHECK(lpIds[0] == localSet.localPoolVarUint8.getDataPoolId());
CHECK(lpIds[1] == localSet.localPoolVarFloat.getDataPoolId());
CHECK(lpIds[2] == localSet.localPoolUint16Vec.getDataPoolId());
{
// Test read operation. Values should be all zeros
PoolReadGuard readHelper(&localSet);
REQUIRE(readHelper.getReadResult() == returnvalue::OK);
CHECK(localSet.localPoolVarUint8.value == 0);
CHECK(!localSet.localPoolVarUint8.isValid());
CHECK(localSet.localPoolVarFloat.value == Catch::Approx(0.0));
CHECK(!localSet.localPoolVarFloat.isValid());
CHECK(localSet.localPoolUint16Vec.value[0] == 0);
CHECK(localSet.localPoolUint16Vec.value[1] == 0);
CHECK(localSet.localPoolUint16Vec.value[2] == 0);
CHECK(!localSet.localPoolUint16Vec.isValid());
// Now set new values, commit should be done by read helper automatically
localSet.localPoolVarUint8 = 232;
localSet.localPoolVarUint8.setValid(true);
localSet.localPoolVarFloat = -2324.322;
localSet.localPoolVarFloat.setValid(true);
localSet.localPoolUint16Vec.value[0] = 232;
localSet.localPoolUint16Vec.value[1] = 23923;
localSet.localPoolUint16Vec.value[2] = 1;
localSet.localPoolUint16Vec.setValid(true);
}
// Zero out some values for next test
localSet.localPoolVarUint8 = 0;
localSet.localPoolVarFloat = 0;
localSet.setAllVariablesReadOnly();
CHECK(localSet.localPoolUint16Vec.getReadWriteMode() == pool_rwm_t::VAR_READ);
CHECK(localSet.localPoolVarUint8.getReadWriteMode() == pool_rwm_t::VAR_READ);
CHECK(localSet.localPoolVarFloat.getReadWriteMode() == pool_rwm_t::VAR_READ);
{
// Now we read again and check whether our zeroed values were overwritten with
// the values in the pool
PoolReadGuard readHelper(&localSet);
REQUIRE(readHelper.getReadResult() == returnvalue::OK);
CHECK(localSet.localPoolVarUint8.value == 232);
CHECK(localSet.localPoolVarUint8.isValid());
CHECK(localSet.localPoolVarFloat.value == Catch::Approx(-2324.322));
CHECK(localSet.localPoolVarFloat.isValid());
CHECK(localSet.localPoolUint16Vec.value[0] == 232);
CHECK(localSet.localPoolUint16Vec.value[1] == 23923);
CHECK(localSet.localPoolUint16Vec.value[2] == 1);
CHECK(localSet.localPoolUint16Vec.isValid());
// Now we serialize these values into a buffer without the validity buffer
maxSize = localSet.getSerializedSize();
CHECK(maxSize == sizeof(uint8_t) + sizeof(uint16_t) * 3 + sizeof(float));
serSize = 0;
// Already reserve additional space for validity buffer, will be needed later
uint8_t buffer[maxSize + 1];
uint8_t* buffPtr = buffer;
CHECK(localSet.serialize(&buffPtr, &serSize, maxSize, SerializeIF::Endianness::MACHINE) ==
returnvalue::OK);
uint8_t rawUint8 = buffer[0];
CHECK(rawUint8 == 232);
float rawFloat = 0.0;
std::memcpy(&rawFloat, buffer + sizeof(uint8_t), sizeof(float));
CHECK(rawFloat == Catch::Approx(-2324.322));
uint16_t rawUint16Vec[3];
std::memcpy(&rawUint16Vec, buffer + sizeof(uint8_t) + sizeof(float), 3 * sizeof(uint16_t));
CHECK(rawUint16Vec[0] == 232);
CHECK(rawUint16Vec[1] == 23923);
CHECK(rawUint16Vec[2] == 1);
size_t sizeToDeserialize = maxSize;
// Now we zeros out the raw entries and deserialize back into the dataset
std::memset(buffer, 0, sizeof(buffer));
const uint8_t* constBuffPtr = buffer;
CHECK(localSet.deSerialize(&constBuffPtr, &sizeToDeserialize,
SerializeIF::Endianness::MACHINE) == returnvalue::OK);
// Check whether deserialization was successfull
CHECK(localSet.localPoolVarUint8.value == 0);
CHECK(localSet.localPoolVarFloat.value == Catch::Approx(0.0));
CHECK(localSet.localPoolVarUint8.value == 0);
CHECK(localSet.localPoolUint16Vec.value[0] == 0);
CHECK(localSet.localPoolUint16Vec.value[1] == 0);
CHECK(localSet.localPoolUint16Vec.value[2] == 0);
}
}
SECTION("SharedDataSet") {
object_id_t sharedSetId = objects::SHARED_SET_ID;
SharedSet sharedSet(poolOwner.sharedPool, sharedSetId, 5, false);
localSet.localPoolVarUint8.setReadWriteMode(pool_rwm_t::VAR_WRITE);
localSet.localPoolUint16Vec.setReadWriteMode(pool_rwm_t::VAR_WRITE);
CHECK(sharedSet.registerVariable(&localSet.localPoolVarUint8) == returnvalue::OK);
CHECK(sharedSet.registerVariable(&localSet.localPoolUint16Vec) == returnvalue::OK);
{
PoolReadGuard rg(&sharedSet);
CHECK(rg.getReadResult() == returnvalue::OK);
localSet.localPoolVarUint8.value = 5;
localSet.localPoolUint16Vec.value[0] = 1;
localSet.localPoolUint16Vec.value[1] = 2;
localSet.localPoolUint16Vec.value[2] = 3;
CHECK(sharedSet.commit() == returnvalue::OK);
}
}
SECTION("Serialize with Validity Blob") {
localSet.updateValidityBlobSerialization(true);
CHECK(!localSet.localPoolVarUint8.isValid());
CHECK(!localSet.localPoolUint16Vec.isValid());
CHECK(!localSet.localPoolVarFloat.isValid());
localSet.setChildrenValidity(true);
CHECK(localSet.localPoolVarUint8.isValid());
CHECK(localSet.localPoolUint16Vec.isValid());
CHECK(localSet.localPoolVarFloat.isValid());
size_t serSize = 0;
// Already reserve additional space for validity buffer, will be needed later
uint8_t buffer[128]{};
uint8_t* buffPtr = buffer;
CHECK(localSet.getSerializedSize() == 12);
CHECK(localSet.serialize(&buffPtr, &serSize, sizeof(buffer),
SerializeIF::Endianness::MACHINE) == returnvalue::OK);
CHECK(serSize == 12);
CHECK(buffer[11] == 0b11100000);
}
}