adding new tests for local pool variable
This commit is contained in:
parent
49c6cd9473
commit
8e3aef5df0
@ -2,5 +2,6 @@ add_subdirectory(action)
|
||||
add_subdirectory(container)
|
||||
add_subdirectory(osal)
|
||||
add_subdirectory(serialize)
|
||||
add_subdirectory(datapoollocal)
|
||||
add_subdirectory(storagemanager)
|
||||
|
||||
|
3
unittest/tests/datapoollocal/CMakeLists.txt
Normal file
3
unittest/tests/datapoollocal/CMakeLists.txt
Normal file
@ -0,0 +1,3 @@
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
LocalPoolVariableTest.cpp
|
||||
)
|
@ -1,8 +1,83 @@
|
||||
#ifndef FSFW_UNITTEST_TESTS_DATAPOOLLOCAL_LOCALPOOLOWNERBASE_H_
|
||||
#define FSFW_UNITTEST_TESTS_DATAPOOLLOCAL_LOCALPOOLOWNERBASE_H_
|
||||
|
||||
#include <fsfw/datapoollocal/HasLocalDataPoolIF.h>
|
||||
#include <fsfw/objectmanager/SystemObject.h>
|
||||
#include <fsfw/datapoollocal/LocalPoolVariable.h>
|
||||
#include <fsfw/ipc/QueueFactory.h>
|
||||
#include <testcfg/objects/systemObjectList.h>
|
||||
|
||||
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<uint8_t>({0}));
|
||||
localDataPoolMap.emplace(lpool::floatVarId, new PoolEntry<float>({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<uint8_t> testUint8 = lp_var_t<uint8_t>(this, lpool::uint8VarId);
|
||||
lp_var_t<float> testFloat = lp_var_t<float>(this, lpool::floatVarId);
|
||||
|
||||
MessageQueueIF* messageQueue = nullptr;
|
||||
LocalDataPoolManager hkManager;
|
||||
|
||||
};
|
||||
|
||||
#endif /* FSFW_UNITTEST_TESTS_DATAPOOLLOCAL_LOCALPOOLOWNERBASE_H_ */
|
||||
|
37
unittest/tests/datapoollocal/LocalPoolVariableTest.cpp
Normal file
37
unittest/tests/datapoollocal/LocalPoolVariableTest.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
#include "LocalPoolOwnerBase.h"
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <fsfw/datapoollocal/HasLocalDataPoolIF.h>
|
||||
#include <unittest/core/CatchDefinitions.h>
|
||||
|
||||
|
||||
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<uint8_t> testVariable = lp_var_t<uint8_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<uint8_t> invalidVariable = lp_var_t<uint8_t>(
|
||||
objects::TEST_LOCAL_POOL_OWNER_BASE, 0xffffffff);
|
||||
REQUIRE(invalidVariable.read() ==
|
||||
static_cast<int>(HasLocalDataPoolIF::POOL_ENTRY_NOT_FOUND));
|
||||
|
||||
// now try to access with wrong type
|
||||
lp_var_t<int8_t> invalidVariable2 = lp_var_t<int8_t>(
|
||||
objects::TEST_LOCAL_POOL_OWNER_BASE, lpool::uint8VarId);
|
||||
REQUIRE(invalidVariable2.read() ==
|
||||
static_cast<int>(HasLocalDataPoolIF::POOL_ENTRY_TYPE_CONFLICT));
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user