From 8e3aef5df05669d686d1ec0a6a899e3c6a369d7a Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 4 Jan 2021 00:21:44 +0100 Subject: [PATCH] adding new tests for local pool variable --- unittest/tests/CMakeLists.txt | 1 + unittest/tests/datapoollocal/CMakeLists.txt | 3 + .../tests/datapoollocal/LocalPoolOwnerBase.h | 75 +++++++++++++++++++ .../datapoollocal/LocalPoolVariableTest.cpp | 37 +++++++++ .../user/testcfg/objects/systemObjectList.h | 14 +++- 5 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 unittest/tests/datapoollocal/CMakeLists.txt create mode 100644 unittest/tests/datapoollocal/LocalPoolVariableTest.cpp diff --git a/unittest/tests/CMakeLists.txt b/unittest/tests/CMakeLists.txt index 97074417..180e1a51 100644 --- a/unittest/tests/CMakeLists.txt +++ b/unittest/tests/CMakeLists.txt @@ -2,5 +2,6 @@ add_subdirectory(action) add_subdirectory(container) add_subdirectory(osal) add_subdirectory(serialize) +add_subdirectory(datapoollocal) add_subdirectory(storagemanager) diff --git a/unittest/tests/datapoollocal/CMakeLists.txt b/unittest/tests/datapoollocal/CMakeLists.txt new file mode 100644 index 00000000..569a8d5f --- /dev/null +++ b/unittest/tests/datapoollocal/CMakeLists.txt @@ -0,0 +1,3 @@ +target_sources(${TARGET_NAME} PRIVATE + LocalPoolVariableTest.cpp +) diff --git a/unittest/tests/datapoollocal/LocalPoolOwnerBase.h b/unittest/tests/datapoollocal/LocalPoolOwnerBase.h index 5e62234b..b73c5299 100644 --- a/unittest/tests/datapoollocal/LocalPoolOwnerBase.h +++ b/unittest/tests/datapoollocal/LocalPoolOwnerBase.h @@ -1,8 +1,83 @@ #ifndef FSFW_UNITTEST_TESTS_DATAPOOLLOCAL_LOCALPOOLOWNERBASE_H_ #define FSFW_UNITTEST_TESTS_DATAPOOLLOCAL_LOCALPOOLOWNERBASE_H_ +#include +#include +#include +#include +#include + +namespace lpool { +static constexpr lp_id_t uint8VarId = 0; +static constexpr lp_id_t floatVarId = 1; +} +class LocalPoolOwnerBase: public SystemObject, public HasLocalDataPoolIF { +public: + LocalPoolOwnerBase( + object_id_t objectId = objects::TEST_LOCAL_POOL_OWNER_BASE): + SystemObject(objectId), hkManager(this, messageQueue) { + messageQueue = QueueFactory::instance()->createMessageQueue(10); + } + ~LocalPoolOwnerBase() { + QueueFactory::instance()->deleteMessageQueue(messageQueue); + } + + object_id_t getObjectId() const override { + return SystemObject::getObjectId(); + } + + ReturnValue_t initializeHkManager() { + return hkManager.initialize(messageQueue); + + } + + ReturnValue_t initializeHkManagerAfterTaskCreation() { + return hkManager.initializeAfterTaskCreation(); + } + + /** Command queue for housekeeping messages. */ + MessageQueueId_t getCommandQueue() const override { + return messageQueue->getId(); + } + + virtual ReturnValue_t initializeLocalDataPool( + LocalDataPool& localDataPoolMap, + LocalDataPoolManager& poolManager) { + // Default initialization empty for now. + localDataPoolMap.emplace(lpool::uint8VarId, new PoolEntry({0})); + localDataPoolMap.emplace(lpool::floatVarId, new PoolEntry({0})); + return HasReturnvaluesIF::RETURN_OK; + } + + LocalDataPoolManager* getHkManagerHandle() override { + return &hkManager; + } + + uint32_t getPeriodicOperationFrequency() const override { + return 0; + } + + /** + * This function is used by the pool manager to get a valid dataset + * from a SID + * @param sid Corresponding structure ID + * @return + */ + virtual LocalPoolDataSetBase* getDataSetHandle(sid_t sid) override { + // empty for now + return nullptr; + } +private: + + lp_var_t testUint8 = lp_var_t(this, lpool::uint8VarId); + lp_var_t testFloat = lp_var_t(this, lpool::floatVarId); + + MessageQueueIF* messageQueue = nullptr; + LocalDataPoolManager hkManager; + +}; #endif /* FSFW_UNITTEST_TESTS_DATAPOOLLOCAL_LOCALPOOLOWNERBASE_H_ */ diff --git a/unittest/tests/datapoollocal/LocalPoolVariableTest.cpp b/unittest/tests/datapoollocal/LocalPoolVariableTest.cpp new file mode 100644 index 00000000..0c233193 --- /dev/null +++ b/unittest/tests/datapoollocal/LocalPoolVariableTest.cpp @@ -0,0 +1,37 @@ +#include "LocalPoolOwnerBase.h" + +#include +#include +#include + + +TEST_CASE("LocalPoolVariable" , "[LocPoolVarTest]") { + LocalPoolOwnerBase poolOwner(objects::TEST_LOCAL_POOL_OWNER_BASE); + REQUIRE(poolOwner.initializeHkManager() == retval::CATCH_OK); + REQUIRE(poolOwner.initializeHkManagerAfterTaskCreation() + == retval::CATCH_OK); + + // very basic test. + lp_var_t testVariable = lp_var_t( + objects::TEST_LOCAL_POOL_OWNER_BASE, lpool::uint8VarId); + REQUIRE(testVariable.read() == retval::CATCH_OK); + CHECK(testVariable.value == 0); + testVariable.value = 5; + REQUIRE(testVariable.commit() == retval::CATCH_OK); + REQUIRE(testVariable.read() == retval::CATCH_OK); + REQUIRE(testVariable.value == 5); + + // not try to use a local pool variable which does not exist + lp_var_t invalidVariable = lp_var_t( + objects::TEST_LOCAL_POOL_OWNER_BASE, 0xffffffff); + REQUIRE(invalidVariable.read() == + static_cast(HasLocalDataPoolIF::POOL_ENTRY_NOT_FOUND)); + + // now try to access with wrong type + lp_var_t invalidVariable2 = lp_var_t( + objects::TEST_LOCAL_POOL_OWNER_BASE, lpool::uint8VarId); + REQUIRE(invalidVariable2.read() == + static_cast(HasLocalDataPoolIF::POOL_ENTRY_TYPE_CONFLICT)); +} + + diff --git a/unittest/user/testcfg/objects/systemObjectList.h b/unittest/user/testcfg/objects/systemObjectList.h index 0e034aff..da95617c 100644 --- a/unittest/user/testcfg/objects/systemObjectList.h +++ b/unittest/user/testcfg/objects/systemObjectList.h @@ -9,7 +9,19 @@ namespace objects { enum sourceObjects: uint32_t { /* All addresses between start and end are reserved for the FSFW */ FSFW_CONFIG_RESERVED_START = PUS_SERVICE_1_VERIFICATION, - FSFW_CONFIG_RESERVED_END = TM_STORE + FSFW_CONFIG_RESERVED_END = TM_STORE, + + CCSDS_DISTRIBUTOR = 10, + PUS_DISTRIBUTOR = 11, + TM_FUNNEL = 12, + + UDP_BRIDGE = 15, + UDP_POLLING_TASK = 16, + + TEST_ECHO_COM_IF = 20, + TEST_DEVICE = 21, + + TEST_LOCAL_POOL_OWNER_BASE = 25 }; }