From a18706ec5351db0ae638380ba806cbce44c8ece3 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 16 Aug 2021 10:49:07 +0200 Subject: [PATCH 1/7] Make FSFW tests accessible from outside 1. Further reduces the amount of code the user needs to copy and paste 2. Makes FSFW tests more accessible. This can be used to simplify moving mission unit tests to the FSFW 3. A lot of include improvements --- CMakeLists.txt | 3 ++- tests/src/fsfw_tests/unit/CMakeLists.txt | 13 ++++++++++ .../fsfw_tests/unit}/CatchDefinitions.cpp | 0 .../fsfw_tests/unit}/CatchDefinitions.h | 0 .../fsfw_tests/unit}/CatchFactory.cpp | 16 +++++++------ tests/src/fsfw_tests/unit/CatchFactory.h | 24 +++++++++++++++++++ .../fsfw_tests/unit}/CatchRunner.cpp | 6 ++--- tests/src/fsfw_tests/unit/CatchRunner.h | 14 +++++++++++ .../fsfw_tests/unit}/CatchSetup.cpp | 15 +++++------- .../unit/action/TestActionHelper.cpp | 5 +--- .../fsfw_tests/unit/action/TestActionHelper.h | 3 +-- .../unit/container/RingBufferTest.cpp | 2 +- .../unit/container/TestArrayList.cpp | 3 ++- .../unit/container/TestDynamicFifo.cpp | 3 ++- .../fsfw_tests/unit/container/TestFifo.cpp | 3 ++- .../unit/container/TestFixedArrayList.cpp | 3 ++- .../unit/container/TestFixedMap.cpp | 3 ++- .../container/TestFixedOrderedMultimap.cpp | 3 ++- .../unit/container/TestPlacementFactory.cpp | 3 ++- .../unit/datapoollocal/DataSetTest.cpp | 7 +++--- .../datapoollocal/LocalPoolManagerTest.cpp | 9 +++---- .../unit/datapoollocal/LocalPoolOwnerBase.h | 2 +- .../datapoollocal/LocalPoolVariableTest.cpp | 4 ++-- .../datapoollocal/LocalPoolVectorTest.cpp | 3 ++- .../unit/mocks/MessageQueueMockBase.h | 9 ++++--- .../fsfw_tests/unit/osal/TestMessageQueue.cpp | 3 ++- .../fsfw_tests/unit}/printChar.cpp | 0 .../core => src/fsfw_tests/unit}/printChar.h | 0 .../serialize/TestSerialBufferAdapter.cpp | 4 +++- .../unit/serialize/TestSerialLinkedPacket.cpp | 3 +-- .../unit/serialize/TestSerialization.cpp | 2 +- .../unit/storagemanager/TestNewAccessor.cpp | 5 +++- .../unit/storagemanager/TestPool.cpp | 3 ++- tests/user/CMakeLists.txt | 4 ++-- tests/user/testcfg/TestsConfig.h.in | 2 ++ tests/user/unittest/CMakeLists.txt | 1 - tests/user/unittest/core/CMakeLists.txt | 13 ---------- tests/user/unittest/core/CatchFactory.h | 16 ------------- tests/user/unittest/core/core.mk | 3 --- 39 files changed, 124 insertions(+), 91 deletions(-) rename tests/{user/unittest/core => src/fsfw_tests/unit}/CatchDefinitions.cpp (100%) rename tests/{user/unittest/core => src/fsfw_tests/unit}/CatchDefinitions.h (100%) rename tests/{user/unittest/core => src/fsfw_tests/unit}/CatchFactory.cpp (91%) create mode 100644 tests/src/fsfw_tests/unit/CatchFactory.h rename tests/{user/unittest/core => src/fsfw_tests/unit}/CatchRunner.cpp (78%) create mode 100644 tests/src/fsfw_tests/unit/CatchRunner.h rename tests/{user/unittest/core => src/fsfw_tests/unit}/CatchSetup.cpp (57%) rename tests/{user/unittest/core => src/fsfw_tests/unit}/printChar.cpp (100%) rename tests/{user/unittest/core => src/fsfw_tests/unit}/printChar.h (100%) delete mode 100644 tests/user/unittest/CMakeLists.txt delete mode 100644 tests/user/unittest/core/CMakeLists.txt delete mode 100644 tests/user/unittest/core/CatchFactory.h delete mode 100644 tests/user/unittest/core/core.mk diff --git a/CMakeLists.txt b/CMakeLists.txt index b7865300..feaa4b81 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,7 @@ endif() option(FSFW_WARNING_SHADOW_LOCAL_GCC "Enable -Wshadow=local warning in GCC" ON) # Options to exclude parts of the FSFW from compilation. option(FSFW_ADD_INTERNAL_TESTS "Add internal unit tests" ON) +option(FSFW_ADD_UNITTESTS "Add regular unittests. Requires Catch2" OFF) option(FSFW_ADD_HAL "Add Hardware Abstraction Layer" ON) # Optional sources @@ -38,7 +39,7 @@ elseif(${CMAKE_CXX_STANDARD} LESS 11) endif() # Backwards comptability -if(OS_FSFW) +if(OS_FSFW AND NOT FSFW_OSAL) message(WARNING "Please pass the FSFW OSAL as FSFW_OSAL instead of OS_FSFW") set(FSFW_OSAL OS_FSFW) endif() diff --git a/tests/src/fsfw_tests/unit/CMakeLists.txt b/tests/src/fsfw_tests/unit/CMakeLists.txt index 255063f3..01e4d19c 100644 --- a/tests/src/fsfw_tests/unit/CMakeLists.txt +++ b/tests/src/fsfw_tests/unit/CMakeLists.txt @@ -1,3 +1,16 @@ +target_sources(${TARGET_NAME} PRIVATE + CatchDefinitions.cpp + CatchFactory.cpp + printChar.cpp +) + +if(FSFW_CUSTOM_UNITTEST_RUNNER) + target_sources(${TARGET_NAME} PRIVATE + CatchRunner.cpp + CatchSetup.cpp + ) +endif() + add_subdirectory(action) add_subdirectory(container) add_subdirectory(osal) diff --git a/tests/user/unittest/core/CatchDefinitions.cpp b/tests/src/fsfw_tests/unit/CatchDefinitions.cpp similarity index 100% rename from tests/user/unittest/core/CatchDefinitions.cpp rename to tests/src/fsfw_tests/unit/CatchDefinitions.cpp diff --git a/tests/user/unittest/core/CatchDefinitions.h b/tests/src/fsfw_tests/unit/CatchDefinitions.h similarity index 100% rename from tests/user/unittest/core/CatchDefinitions.h rename to tests/src/fsfw_tests/unit/CatchDefinitions.h diff --git a/tests/user/unittest/core/CatchFactory.cpp b/tests/src/fsfw_tests/unit/CatchFactory.cpp similarity index 91% rename from tests/user/unittest/core/CatchFactory.cpp rename to tests/src/fsfw_tests/unit/CatchFactory.cpp index ff591b8e..010ab5dd 100644 --- a/tests/user/unittest/core/CatchFactory.cpp +++ b/tests/src/fsfw_tests/unit/CatchFactory.cpp @@ -1,17 +1,21 @@ #include "CatchFactory.h" +#include "datapoollocal/LocalPoolOwnerBase.h" +#include "mocks/HkReceiverMock.h" + #include #include #include #include -#include +#include #include #include #include #include #include -#include -#include + + +#if FSFW_ADD_DEFAULT_FACTORY_FUNCTIONS == 1 /** * @brief Produces system objects. @@ -26,7 +30,7 @@ * * @ingroup init */ -void Factory::produce(void) { +void Factory::produceFrameworkObjects(void* args) { setStaticFrameworkObjectIds(); new EventManager(objects::EVENT_MANAGER); new HealthTable(objects::HEALTH_TABLE); @@ -55,7 +59,6 @@ void Factory::produce(void) { }; new PoolManager(objects::IPC_STORE, poolCfg); } - } void Factory::setStaticFrameworkObjectIds() { @@ -77,5 +80,4 @@ void Factory::setStaticFrameworkObjectIds() { TmPacketBase::timeStamperId = objects::NO_OBJECT; } - - +#endif diff --git a/tests/src/fsfw_tests/unit/CatchFactory.h b/tests/src/fsfw_tests/unit/CatchFactory.h new file mode 100644 index 00000000..ae0629e5 --- /dev/null +++ b/tests/src/fsfw_tests/unit/CatchFactory.h @@ -0,0 +1,24 @@ +#ifndef FSFW_CATCHFACTORY_H_ +#define FSFW_CATCHFACTORY_H_ + +#include "TestConfig.h" +#include "fsfw/objectmanager/SystemObjectIF.h" +#include "fsfw/objectmanager/ObjectManager.h" + +// TODO: It is possible to solve this more cleanly using a special class which +// is allowed to set the object IDs and has virtual functions. +#if FSFW_ADD_DEFAULT_FACTORY_FUNCTIONS == 1 + +namespace Factory { + /** + * @brief Creates all SystemObject elements which are persistent + * during execution. + */ + void produceFrameworkObjects(void* args); + void setStaticFrameworkObjectIds(); + +} + +#endif /* FSFW_ADD_DEFAULT_FSFW_FACTORY == 1 */ + +#endif /* FSFW_CATCHFACTORY_H_ */ diff --git a/tests/user/unittest/core/CatchRunner.cpp b/tests/src/fsfw_tests/unit/CatchRunner.cpp similarity index 78% rename from tests/user/unittest/core/CatchRunner.cpp rename to tests/src/fsfw_tests/unit/CatchRunner.cpp index 886d641f..c96db7f4 100644 --- a/tests/user/unittest/core/CatchRunner.cpp +++ b/tests/src/fsfw_tests/unit/CatchRunner.cpp @@ -6,7 +6,7 @@ * from the eclipse market place to get colored characters. */ -#include +#include "CatchRunner.h" #define CATCH_CONFIG_COLOUR_WINDOWS @@ -14,11 +14,11 @@ extern int customSetup(); -int main( int argc, char* argv[] ) { +int fsfwtest::customMain(int argc, char* argv[]) { customSetup(); // Catch internal function call - int result = Catch::Session().run( argc, argv ); + int result = Catch::Session().run(argc, argv); // global clean-up return result; diff --git a/tests/src/fsfw_tests/unit/CatchRunner.h b/tests/src/fsfw_tests/unit/CatchRunner.h new file mode 100644 index 00000000..720625c6 --- /dev/null +++ b/tests/src/fsfw_tests/unit/CatchRunner.h @@ -0,0 +1,14 @@ +#ifndef FSFW_TESTS_USER_UNITTEST_CORE_CATCHRUNNER_H_ +#define FSFW_TESTS_USER_UNITTEST_CORE_CATCHRUNNER_H_ + +namespace fsfwtest { + +/** + * Can be called by upper level main() if default Catch2 main is overriden + * @return + */ +int customMain(int argc, char* argv[]); + +} + +#endif /* FSFW_TESTS_USER_UNITTEST_CORE_CATCHRUNNER_H_ */ diff --git a/tests/user/unittest/core/CatchSetup.cpp b/tests/src/fsfw_tests/unit/CatchSetup.cpp similarity index 57% rename from tests/user/unittest/core/CatchSetup.cpp rename to tests/src/fsfw_tests/unit/CatchSetup.cpp index bda31400..a0791bc9 100644 --- a/tests/user/unittest/core/CatchSetup.cpp +++ b/tests/src/fsfw_tests/unit/CatchSetup.cpp @@ -5,10 +5,9 @@ #include #endif -#include -#include -#include -#include +#include "fsfw/objectmanager/ObjectManager.h" +#include "fsfw/storagemanager/StorageManagerIF.h" +#include "fsfw/serviceinterface/ServiceInterface.h" /* Global instantiations normally done in main.cpp */ @@ -24,13 +23,11 @@ ServiceInterfaceStream warning("WARNING"); } #endif -/* Global object manager */ -ObjectManagerIF *objectManager; - int customSetup() { // global setup - objectManager = new ObjectManager(Factory::produce); - objectManager -> initialize(); + ObjectManager* objMan = ObjectManager::instance(); + objMan->setObjectFactoryFunction(Factory::produceFrameworkObjects, nullptr); + objMan->initialize(); return 0; } diff --git a/tests/src/fsfw_tests/unit/action/TestActionHelper.cpp b/tests/src/fsfw_tests/unit/action/TestActionHelper.cpp index 126979f6..3129b001 100644 --- a/tests/src/fsfw_tests/unit/action/TestActionHelper.cpp +++ b/tests/src/fsfw_tests/unit/action/TestActionHelper.cpp @@ -1,13 +1,10 @@ #include "TestActionHelper.h" - -#include +#include "fsfw_tests/unit/mocks/MessageQueueMockBase.h" #include #include -#include #include - #include diff --git a/tests/src/fsfw_tests/unit/action/TestActionHelper.h b/tests/src/fsfw_tests/unit/action/TestActionHelper.h index 641ea2c6..34b228c0 100644 --- a/tests/src/fsfw_tests/unit/action/TestActionHelper.h +++ b/tests/src/fsfw_tests/unit/action/TestActionHelper.h @@ -1,12 +1,11 @@ #ifndef UNITTEST_HOSTED_TESTACTIONHELPER_H_ #define UNITTEST_HOSTED_TESTACTIONHELPER_H_ +#include "fsfw_tests/unit/CatchDefinitions.h" #include #include -#include #include - class ActionHelperOwnerMockBase: public HasActionsIF { public: bool getCommandQueueCalled = false; diff --git a/tests/src/fsfw_tests/unit/container/RingBufferTest.cpp b/tests/src/fsfw_tests/unit/container/RingBufferTest.cpp index 32a2502d..819401ab 100644 --- a/tests/src/fsfw_tests/unit/container/RingBufferTest.cpp +++ b/tests/src/fsfw_tests/unit/container/RingBufferTest.cpp @@ -1,4 +1,4 @@ -#include +#include "fsfw_tests/unit/CatchDefinitions.h" #include #include diff --git a/tests/src/fsfw_tests/unit/container/TestArrayList.cpp b/tests/src/fsfw_tests/unit/container/TestArrayList.cpp index 1fd330b6..9417144c 100644 --- a/tests/src/fsfw_tests/unit/container/TestArrayList.cpp +++ b/tests/src/fsfw_tests/unit/container/TestArrayList.cpp @@ -1,8 +1,9 @@ +#include "fsfw_tests/unit/CatchDefinitions.h" + #include #include #include -#include /** * @brief Array List test diff --git a/tests/src/fsfw_tests/unit/container/TestDynamicFifo.cpp b/tests/src/fsfw_tests/unit/container/TestDynamicFifo.cpp index 2b572d52..a1bab3ba 100644 --- a/tests/src/fsfw_tests/unit/container/TestDynamicFifo.cpp +++ b/tests/src/fsfw_tests/unit/container/TestDynamicFifo.cpp @@ -1,9 +1,10 @@ +#include "fsfw_tests/unit/CatchDefinitions.h" + #include #include #include #include -#include TEST_CASE( "Dynamic Fifo Tests", "[TestDynamicFifo]") { INFO("Dynamic Fifo Tests"); diff --git a/tests/src/fsfw_tests/unit/container/TestFifo.cpp b/tests/src/fsfw_tests/unit/container/TestFifo.cpp index fbcd40cc..311dd8fd 100644 --- a/tests/src/fsfw_tests/unit/container/TestFifo.cpp +++ b/tests/src/fsfw_tests/unit/container/TestFifo.cpp @@ -1,9 +1,10 @@ +#include "fsfw_tests/unit/CatchDefinitions.h" + #include #include #include #include -#include TEST_CASE( "Static Fifo Tests", "[TestFifo]") { INFO("Fifo Tests"); diff --git a/tests/src/fsfw_tests/unit/container/TestFixedArrayList.cpp b/tests/src/fsfw_tests/unit/container/TestFixedArrayList.cpp index 1a85f30d..ed597f73 100644 --- a/tests/src/fsfw_tests/unit/container/TestFixedArrayList.cpp +++ b/tests/src/fsfw_tests/unit/container/TestFixedArrayList.cpp @@ -1,8 +1,9 @@ +#include "fsfw_tests/unit/CatchDefinitions.h" + #include #include #include -#include TEST_CASE( "FixedArrayList Tests", "[TestFixedArrayList]") { diff --git a/tests/src/fsfw_tests/unit/container/TestFixedMap.cpp b/tests/src/fsfw_tests/unit/container/TestFixedMap.cpp index 297171ca..488418b9 100644 --- a/tests/src/fsfw_tests/unit/container/TestFixedMap.cpp +++ b/tests/src/fsfw_tests/unit/container/TestFixedMap.cpp @@ -1,8 +1,9 @@ +#include "fsfw_tests/unit/CatchDefinitions.h" + #include #include #include -#include template class FixedMap; diff --git a/tests/src/fsfw_tests/unit/container/TestFixedOrderedMultimap.cpp b/tests/src/fsfw_tests/unit/container/TestFixedOrderedMultimap.cpp index a47d6efb..23d91744 100644 --- a/tests/src/fsfw_tests/unit/container/TestFixedOrderedMultimap.cpp +++ b/tests/src/fsfw_tests/unit/container/TestFixedOrderedMultimap.cpp @@ -1,8 +1,9 @@ +#include "fsfw_tests/unit/CatchDefinitions.h" + #include #include #include -#include TEST_CASE( "FixedOrderedMultimap Tests", "[TestFixedOrderedMultimap]") { INFO("FixedOrderedMultimap Tests"); diff --git a/tests/src/fsfw_tests/unit/container/TestPlacementFactory.cpp b/tests/src/fsfw_tests/unit/container/TestPlacementFactory.cpp index 14cf8eb4..1e328fc7 100644 --- a/tests/src/fsfw_tests/unit/container/TestPlacementFactory.cpp +++ b/tests/src/fsfw_tests/unit/container/TestPlacementFactory.cpp @@ -1,10 +1,11 @@ +#include "fsfw_tests/unit/CatchDefinitions.h" + #include #include #include #include #include -#include TEST_CASE( "PlacementFactory Tests", "[TestPlacementFactory]") { INFO("PlacementFactory Tests"); diff --git a/tests/src/fsfw_tests/unit/datapoollocal/DataSetTest.cpp b/tests/src/fsfw_tests/unit/datapoollocal/DataSetTest.cpp index b8748eb4..94b13f2f 100644 --- a/tests/src/fsfw_tests/unit/datapoollocal/DataSetTest.cpp +++ b/tests/src/fsfw_tests/unit/datapoollocal/DataSetTest.cpp @@ -1,7 +1,5 @@ #include "LocalPoolOwnerBase.h" - -#include -#include +#include "fsfw_tests/unit/CatchDefinitions.h" #include #include @@ -10,7 +8,8 @@ #include #include -#include +#include +#include TEST_CASE("DataSetTest" , "[DataSetTest]") { LocalPoolOwnerBase* poolOwner = ObjectManager::instance()-> diff --git a/tests/src/fsfw_tests/unit/datapoollocal/LocalPoolManagerTest.cpp b/tests/src/fsfw_tests/unit/datapoollocal/LocalPoolManagerTest.cpp index 4a4d08fb..7b2f9412 100644 --- a/tests/src/fsfw_tests/unit/datapoollocal/LocalPoolManagerTest.cpp +++ b/tests/src/fsfw_tests/unit/datapoollocal/LocalPoolManagerTest.cpp @@ -1,7 +1,5 @@ #include "LocalPoolOwnerBase.h" - -#include -#include +#include "fsfw_tests/unit/CatchDefinitions.h" #include #include @@ -10,7 +8,10 @@ #include #include #include -#include + +#include +#include + #include diff --git a/tests/src/fsfw_tests/unit/datapoollocal/LocalPoolOwnerBase.h b/tests/src/fsfw_tests/unit/datapoollocal/LocalPoolOwnerBase.h index c0e41ddf..ea5bb7e0 100644 --- a/tests/src/fsfw_tests/unit/datapoollocal/LocalPoolOwnerBase.h +++ b/tests/src/fsfw_tests/unit/datapoollocal/LocalPoolOwnerBase.h @@ -2,6 +2,7 @@ #define FSFW_UNITTEST_TESTS_DATAPOOLLOCAL_LOCALPOOLOWNERBASE_H_ #include "objects/systemObjectList.h" +#include "../mocks/MessageQueueMockBase.h" #include #include @@ -10,7 +11,6 @@ #include #include #include -#include #include namespace lpool { diff --git a/tests/src/fsfw_tests/unit/datapoollocal/LocalPoolVariableTest.cpp b/tests/src/fsfw_tests/unit/datapoollocal/LocalPoolVariableTest.cpp index 514d8125..648a76e2 100644 --- a/tests/src/fsfw_tests/unit/datapoollocal/LocalPoolVariableTest.cpp +++ b/tests/src/fsfw_tests/unit/datapoollocal/LocalPoolVariableTest.cpp @@ -1,10 +1,10 @@ #include "LocalPoolOwnerBase.h" +#include "fsfw_tests/unit/CatchDefinitions.h" -#include #include #include -#include +#include TEST_CASE("LocalPoolVariable" , "[LocPoolVarTest]") { LocalPoolOwnerBase* poolOwner = ObjectManager::instance()-> diff --git a/tests/src/fsfw_tests/unit/datapoollocal/LocalPoolVectorTest.cpp b/tests/src/fsfw_tests/unit/datapoollocal/LocalPoolVectorTest.cpp index 5b3dd105..3f846dec 100644 --- a/tests/src/fsfw_tests/unit/datapoollocal/LocalPoolVectorTest.cpp +++ b/tests/src/fsfw_tests/unit/datapoollocal/LocalPoolVectorTest.cpp @@ -1,9 +1,10 @@ #include "LocalPoolOwnerBase.h" +#include "fsfw_tests/unit/CatchDefinitions.h" #include #include #include -#include + TEST_CASE("LocalPoolVector" , "[LocPoolVecTest]") { LocalPoolOwnerBase* poolOwner = ObjectManager::instance()-> diff --git a/tests/src/fsfw_tests/unit/mocks/MessageQueueMockBase.h b/tests/src/fsfw_tests/unit/mocks/MessageQueueMockBase.h index 3000f7fb..93a00b7a 100644 --- a/tests/src/fsfw_tests/unit/mocks/MessageQueueMockBase.h +++ b/tests/src/fsfw_tests/unit/mocks/MessageQueueMockBase.h @@ -1,9 +1,12 @@ #ifndef FSFW_UNITTEST_TESTS_MOCKS_MESSAGEQUEUEMOCKBASE_H_ #define FSFW_UNITTEST_TESTS_MOCKS_MESSAGEQUEUEMOCKBASE_H_ -#include -#include -#include +#include "fsfw_tests/unit/CatchDefinitions.h" + +#include "fsfw/ipc/CommandMessage.h" +#include "fsfw/ipc/MessageQueueIF.h" +#include "fsfw/ipc/MessageQueueMessage.h" + #include #include diff --git a/tests/src/fsfw_tests/unit/osal/TestMessageQueue.cpp b/tests/src/fsfw_tests/unit/osal/TestMessageQueue.cpp index e33b7240..07197bf7 100644 --- a/tests/src/fsfw_tests/unit/osal/TestMessageQueue.cpp +++ b/tests/src/fsfw_tests/unit/osal/TestMessageQueue.cpp @@ -1,8 +1,9 @@ +#include "fsfw_tests/unit/CatchDefinitions.h" + #include #include #include -#include #include diff --git a/tests/user/unittest/core/printChar.cpp b/tests/src/fsfw_tests/unit/printChar.cpp similarity index 100% rename from tests/user/unittest/core/printChar.cpp rename to tests/src/fsfw_tests/unit/printChar.cpp diff --git a/tests/user/unittest/core/printChar.h b/tests/src/fsfw_tests/unit/printChar.h similarity index 100% rename from tests/user/unittest/core/printChar.h rename to tests/src/fsfw_tests/unit/printChar.h diff --git a/tests/src/fsfw_tests/unit/serialize/TestSerialBufferAdapter.cpp b/tests/src/fsfw_tests/unit/serialize/TestSerialBufferAdapter.cpp index 1938746d..01d75881 100644 --- a/tests/src/fsfw_tests/unit/serialize/TestSerialBufferAdapter.cpp +++ b/tests/src/fsfw_tests/unit/serialize/TestSerialBufferAdapter.cpp @@ -1,7 +1,9 @@ +#include "fsfw_tests/unit/CatchDefinitions.h" + #include #include -#include + #include diff --git a/tests/src/fsfw_tests/unit/serialize/TestSerialLinkedPacket.cpp b/tests/src/fsfw_tests/unit/serialize/TestSerialLinkedPacket.cpp index b90ae9f8..b6bb214d 100644 --- a/tests/src/fsfw_tests/unit/serialize/TestSerialLinkedPacket.cpp +++ b/tests/src/fsfw_tests/unit/serialize/TestSerialLinkedPacket.cpp @@ -1,10 +1,9 @@ #include "TestSerialLinkedPacket.h" -#include +#include "fsfw_tests/unit/CatchDefinitions.h" #include #include -#include #include diff --git a/tests/src/fsfw_tests/unit/serialize/TestSerialization.cpp b/tests/src/fsfw_tests/unit/serialize/TestSerialization.cpp index 3de581ec..64deae3b 100644 --- a/tests/src/fsfw_tests/unit/serialize/TestSerialization.cpp +++ b/tests/src/fsfw_tests/unit/serialize/TestSerialization.cpp @@ -1,8 +1,8 @@ +#include "fsfw_tests/unit/CatchDefinitions.h" #include #include #include -#include #include diff --git a/tests/src/fsfw_tests/unit/storagemanager/TestNewAccessor.cpp b/tests/src/fsfw_tests/unit/storagemanager/TestNewAccessor.cpp index 10d05c6b..bd1634b7 100644 --- a/tests/src/fsfw_tests/unit/storagemanager/TestNewAccessor.cpp +++ b/tests/src/fsfw_tests/unit/storagemanager/TestNewAccessor.cpp @@ -1,6 +1,9 @@ +#include "fsfw_tests/unit/CatchDefinitions.h" + #include + #include -#include + #include #include diff --git a/tests/src/fsfw_tests/unit/storagemanager/TestPool.cpp b/tests/src/fsfw_tests/unit/storagemanager/TestPool.cpp index d05a3dd6..013ecf86 100644 --- a/tests/src/fsfw_tests/unit/storagemanager/TestPool.cpp +++ b/tests/src/fsfw_tests/unit/storagemanager/TestPool.cpp @@ -1,8 +1,9 @@ +#include "fsfw_tests/unit/CatchDefinitions.h" + #include #include #include -#include #include diff --git a/tests/user/CMakeLists.txt b/tests/user/CMakeLists.txt index df16c756..2e1fdee3 100644 --- a/tests/user/CMakeLists.txt +++ b/tests/user/CMakeLists.txt @@ -32,7 +32,7 @@ if(NOT FSFW_OSAL) set(FSFW_OSAL host CACHE STRING "OS for the FSFW.") endif() -option(CUSTOM_UNITTEST_RUNNER +option(FSFW_CUSTOM_UNITTEST_RUNNER "Specify whether custom main or Catch2 main is used" TRUE ) @@ -49,7 +49,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED True) # Set names and variables set(TARGET_NAME ${CMAKE_PROJECT_NAME}) -if(CUSTOM_UNITTEST_RUNNER) +if(FSFW_CUSTOM_UNITTEST_RUNNER) set(CATCH2_TARGET Catch2) else() set(CATCH2_TARGET Catch2WithMain) diff --git a/tests/user/testcfg/TestsConfig.h.in b/tests/user/testcfg/TestsConfig.h.in index 0341583d..7d950070 100644 --- a/tests/user/testcfg/TestsConfig.h.in +++ b/tests/user/testcfg/TestsConfig.h.in @@ -1,6 +1,8 @@ #ifndef FSFW_UNITTEST_CONFIG_TESTSCONFIG_H_ #define FSFW_UNITTEST_CONFIG_TESTSCONFIG_H_ +#define FSFW_ADD_DEFAULT_FACTORY_FUNCTIONS 1 + #ifdef __cplusplus #include "objects/systemObjectList.h" diff --git a/tests/user/unittest/CMakeLists.txt b/tests/user/unittest/CMakeLists.txt deleted file mode 100644 index ad6d4787..00000000 --- a/tests/user/unittest/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -add_subdirectory(core) diff --git a/tests/user/unittest/core/CMakeLists.txt b/tests/user/unittest/core/CMakeLists.txt deleted file mode 100644 index 0989926c..00000000 --- a/tests/user/unittest/core/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -target_sources(${TARGET_NAME} PRIVATE - CatchDefinitions.cpp - CatchFactory.cpp - CatchRunner.cpp - CatchSetup.cpp - printChar.cpp -) - -if(CUSTOM_UNITTEST_RUNNER) - target_sources(${TARGET_NAME} PRIVATE - CatchRunner.cpp - ) -endif() \ No newline at end of file diff --git a/tests/user/unittest/core/CatchFactory.h b/tests/user/unittest/core/CatchFactory.h deleted file mode 100644 index 024f762e..00000000 --- a/tests/user/unittest/core/CatchFactory.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef FSFW_CATCHFACTORY_H_ -#define FSFW_CATCHFACTORY_H_ - -#include - -namespace Factory { - /** - * @brief Creates all SystemObject elements which are persistent - * during execution. - */ - void produce(void* args); - void setStaticFrameworkObjectIds(); - -} - -#endif /* FSFW_CATCHFACTORY_H_ */ diff --git a/tests/user/unittest/core/core.mk b/tests/user/unittest/core/core.mk deleted file mode 100644 index 3e5626d3..00000000 --- a/tests/user/unittest/core/core.mk +++ /dev/null @@ -1,3 +0,0 @@ -CXXSRC += $(wildcard $(CURRENTPATH)/*.cpp) - -INCLUDES += $(CURRENTPATH) \ No newline at end of file From 92d3f0743b3b765e8da028b4aba712f751eda201 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 16 Aug 2021 15:26:28 +0200 Subject: [PATCH 2/7] moved change to another PR --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index feaa4b81..4882db54 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,7 +39,7 @@ elseif(${CMAKE_CXX_STANDARD} LESS 11) endif() # Backwards comptability -if(OS_FSFW AND NOT FSFW_OSAL) +if(OS_FSFW) message(WARNING "Please pass the FSFW OSAL as FSFW_OSAL instead of OS_FSFW") set(FSFW_OSAL OS_FSFW) endif() From a6d744c9c8df4e2cd69c170a4bd6806f54b835f9 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 6 Sep 2021 12:05:30 +0200 Subject: [PATCH 3/7] Possible bugfix in DHB The delayCycles variables needs to be initialized differently for periodic replies. It is initialized to the maxDelayCycles value now --- devicehandlers/DeviceHandlerBase.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/devicehandlers/DeviceHandlerBase.cpp b/devicehandlers/DeviceHandlerBase.cpp index 5665b101..733701b2 100644 --- a/devicehandlers/DeviceHandlerBase.cpp +++ b/devicehandlers/DeviceHandlerBase.cpp @@ -430,7 +430,12 @@ ReturnValue_t DeviceHandlerBase::insertInReplyMap(DeviceCommandId_t replyId, DeviceReplyInfo info; info.maxDelayCycles = maxDelayCycles; info.periodic = periodic; - info.delayCycles = 0; + if(info.periodic) { + info.delayCycles = info.maxDelayCycles; + } + else { + info.delayCycles = 0; + } info.replyLen = replyLen; info.dataSet = dataSet; info.command = deviceCommandMap.end(); From c42eb59d2e6947c51dcc6e952e7e626e5a1531ea Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 8 Sep 2021 16:10:18 +0200 Subject: [PATCH 4/7] UART bugfixes and improvements --- hal/src/fsfw_hal/linux/uart/UartComIF.cpp | 42 ++++++++++++++++------ hal/src/fsfw_hal/linux/uart/UartCookie.cpp | 4 +-- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/hal/src/fsfw_hal/linux/uart/UartComIF.cpp b/hal/src/fsfw_hal/linux/uart/UartComIF.cpp index f52b6b1e..f5754c6e 100644 --- a/hal/src/fsfw_hal/linux/uart/UartComIF.cpp +++ b/hal/src/fsfw_hal/linux/uart/UartComIF.cpp @@ -1,6 +1,7 @@ -#include "fsfw_hal/linux/uart/UartComIF.h" +#include "UartComIF.h" #include "OBSWConfig.h" +#include "fsfw_hal/linux/utility.h" #include "fsfw/serviceinterface/ServiceInterface.h" #include @@ -60,7 +61,13 @@ int UartComIF::configureUartPort(UartCookie* uartCookie) { struct termios options = {}; std::string deviceFile = uartCookie->getDeviceFile(); - int fd = open(deviceFile.c_str(), O_RDWR); + int flags = O_RDWR; + if(uartCookie->getUartMode() == UartModes::CANONICAL) { + // In non-canonical mode, don't specify O_NONBLOCK because these properties will be + // controlled by the VTIME and VMIN parameters and O_NONBLOCK would override this + flags |= O_NONBLOCK; + } + int fd = open(deviceFile.c_str(), flags); if (fd < 0) { sif::warning << "UartComIF::configureUartPort: Failed to open uart " << deviceFile << @@ -259,23 +266,22 @@ void UartComIF::configureBaudrate(struct termios* options, UartCookie* uartCooki ReturnValue_t UartComIF::sendMessage(CookieIF *cookie, const uint8_t *sendData, size_t sendLen) { - int fd = 0; std::string deviceFile; UartDeviceMapIter uartDeviceMapIter; - if(sendData == nullptr) { - sif::debug << "UartComIF::sendMessage: Send Data is nullptr" << std::endl; - return RETURN_FAILED; - } - if(sendLen == 0) { return RETURN_OK; } + if(sendData == nullptr) { + sif::warning << "UartComIF::sendMessage: Send data is nullptr" << std::endl; + return RETURN_FAILED; + } + UartCookie* uartCookie = dynamic_cast(cookie); if(uartCookie == nullptr) { - sif::debug << "UartComIF::sendMessasge: Invalid UART Cookie!" << std::endl; + sif::warning << "UartComIF::sendMessasge: Invalid UART Cookie!" << std::endl; return NULLPOINTER; } @@ -347,12 +353,13 @@ ReturnValue_t UartComIF::handleCanonicalRead(UartCookie& uartCookie, UartDeviceM size_t maxReplySize = uartCookie.getMaxReplyLen(); int fd = iter->second.fileDescriptor; auto bufferPtr = iter->second.replyBuffer.data(); + iter->second.replyLen = 0; do { size_t allowedReadSize = 0; if(currentBytesRead >= maxReplySize) { // Overflow risk. Emit warning, trigger event and break. If this happens, // the reception buffer is not large enough or data is not polled often enough. -#if OBSW_VERBOSE_LEVEL >= 1 +#if FSFW_VERBOSE_LEVEL >= 1 #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::warning << "UartComIF::requestReceiveMessage: Next read would cause overflow!" << std::endl; @@ -370,7 +377,20 @@ ReturnValue_t UartComIF::handleCanonicalRead(UartCookie& uartCookie, UartDeviceM bytesRead = read(fd, bufferPtr, allowedReadSize); if (bytesRead < 0) { - return RETURN_FAILED; + // EAGAIN: No data available in non-blocking mode + if(errno != EAGAIN) { +#if FSFW_VERBOSE_LEVEL >= 1 +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "UartComIF::handleCanonicalRead: read failed with code" << + errno << ": " << strerror(errno) << std::endl; +#else + sif::printWarning("UartComIF::handleCanonicalRead: read failed with code %d: %s\n", + errno, strerror(errno)); +#endif +#endif + return RETURN_FAILED; + } + } else if(bytesRead > 0) { iter->second.replyLen += bytesRead; diff --git a/hal/src/fsfw_hal/linux/uart/UartCookie.cpp b/hal/src/fsfw_hal/linux/uart/UartCookie.cpp index 339c7451..1c52e9cd 100644 --- a/hal/src/fsfw_hal/linux/uart/UartCookie.cpp +++ b/hal/src/fsfw_hal/linux/uart/UartCookie.cpp @@ -4,8 +4,8 @@ UartCookie::UartCookie(object_id_t handlerId, std::string deviceFile, UartModes uartMode, uint32_t baudrate, size_t maxReplyLen): - handlerId(handlerId), deviceFile(deviceFile), uartMode(uartMode), baudrate(baudrate), - maxReplyLen(maxReplyLen) { + handlerId(handlerId), deviceFile(deviceFile), uartMode(uartMode), + baudrate(baudrate), maxReplyLen(maxReplyLen) { } UartCookie::~UartCookie() {} From c9bfc8464aede0f79c167e18c5c0c79ded2444ce Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sat, 11 Sep 2021 17:39:42 +0200 Subject: [PATCH 5/7] added function to enable periodic reply --- src/fsfw/devicehandlers/DeviceHandlerBase.cpp | 23 +++++++++++------ src/fsfw/devicehandlers/DeviceHandlerBase.h | 25 +++++++++++++------ 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/src/fsfw/devicehandlers/DeviceHandlerBase.cpp b/src/fsfw/devicehandlers/DeviceHandlerBase.cpp index 1a7fbc91..95e25b74 100644 --- a/src/fsfw/devicehandlers/DeviceHandlerBase.cpp +++ b/src/fsfw/devicehandlers/DeviceHandlerBase.cpp @@ -430,12 +430,7 @@ ReturnValue_t DeviceHandlerBase::insertInReplyMap(DeviceCommandId_t replyId, DeviceReplyInfo info; info.maxDelayCycles = maxDelayCycles; info.periodic = periodic; - if(info.periodic) { - info.delayCycles = info.maxDelayCycles; - } - else { - info.delayCycles = 0; - } + info.delayCycles = 0; info.replyLen = replyLen; info.dataSet = dataSet; info.command = deviceCommandMap.end(); @@ -474,7 +469,7 @@ ReturnValue_t DeviceHandlerBase::updateReplyMapEntry(DeviceCommandId_t deviceRep auto replyIter = deviceReplyMap.find(deviceReply); if (replyIter == deviceReplyMap.end()) { triggerEvent(INVALID_DEVICE_COMMAND, deviceReply); - return RETURN_FAILED; + return COMMAND_NOT_SUPPORTED; } else { DeviceReplyInfo *info = &(replyIter->second); if (maxDelayCycles != 0) { @@ -486,6 +481,20 @@ ReturnValue_t DeviceHandlerBase::updateReplyMapEntry(DeviceCommandId_t deviceRep } } +ReturnValue_t DeviceHandlerBase::enablePeriodicReply(DeviceCommandId_t deviceReply) { + auto replyIter = deviceReplyMap.find(deviceReply); + if (replyIter == deviceReplyMap.end()) { + triggerEvent(INVALID_DEVICE_COMMAND, deviceReply); + return COMMAND_NOT_SUPPORTED; + } else { + DeviceReplyInfo *info = &(replyIter->second); + if(not info->periodic) { + return COMMAND_NOT_SUPPORTED; + } + info->delayCycles = info->maxDelayCycles; + } + return HasReturnvaluesIF::RETURN_OK; +} ReturnValue_t DeviceHandlerBase::setReplyDataset(DeviceCommandId_t replyId, LocalPoolDataSetBase *dataSet) { diff --git a/src/fsfw/devicehandlers/DeviceHandlerBase.h b/src/fsfw/devicehandlers/DeviceHandlerBase.h index 53bd1e65..d478b0fa 100644 --- a/src/fsfw/devicehandlers/DeviceHandlerBase.h +++ b/src/fsfw/devicehandlers/DeviceHandlerBase.h @@ -449,7 +449,9 @@ protected: * @param replyLen Will be supplied to the requestReceiveMessage call of * the communication interface. * @param periodic Indicates if the command is periodic (i.e. it is sent - * by the device repeatedly without request) or not. Default is aperiodic (0) + * by the device repeatedly without request) or not. Default is aperiodic (0). + * Please note that periodic replies are disabled by default. You can enable them with + * #enablePeriodicReplies * @return - @c RETURN_OK when the command was successfully inserted, * - @c RETURN_FAILED else. */ @@ -464,7 +466,9 @@ protected: * @param maxDelayCycles The maximum number of delay cycles the reply waits * until it times out. * @param periodic Indicates if the command is periodic (i.e. it is sent - * by the device repeatedly without request) or not. Default is aperiodic (0) + * by the device repeatedly without request) or not. Default is aperiodic (0). + * Please note that periodic replies are disabled by default. You can enable them with + * #enablePeriodicReplies * @return - @c RETURN_OK when the command was successfully inserted, * - @c RETURN_FAILED else. */ @@ -480,6 +484,13 @@ protected: */ ReturnValue_t insertInCommandMap(DeviceCommandId_t deviceCommand); + /** + * Enables a periodic reply for a given command. It sets to delay cycles to the specified + * maximum delay cycles for a given reply ID. + * @return + */ + ReturnValue_t enablePeriodicReply(DeviceCommandId_t deviceReply); + /** * @brief This function returns the reply length of the next reply to read. * @@ -493,16 +504,14 @@ protected: virtual size_t getNextReplyLength(DeviceCommandId_t deviceCommand); /** - * @brief This is a helper method to facilitate updating entries - * in the reply map. + * @brief This is a helper method to facilitate updating entries in the reply map. * @param deviceCommand Identifier of the reply to update. - * @param delayCycles The current number of delay cycles to wait. - * As stated in #fillCommandAndCookieMap, to disable periodic commands, - * this is set to zero. + * @param delayCycles The current number of delay cycles to wait. As stated in + * #fillCommandAndReplyMap, to disable periodic commands, this is set to zero. * @param maxDelayCycles The maximum number of delay cycles the reply waits * until it times out. By passing 0 the entry remains untouched. * @param periodic Indicates if the command is periodic (i.e. it is sent - * by the device repeatedly without request) or not.Default is aperiodic (0). + * by the device repeatedly without request) or not. Default is aperiodic (0). * Warning: The setting always overrides the value that was entered in the map. * @return - @c RETURN_OK when the command was successfully inserted, * - @c RETURN_FAILED else. From 11a3c8c21f8a80d5c0872e99e39bd655f18acfa7 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sat, 11 Sep 2021 17:42:29 +0200 Subject: [PATCH 6/7] added option to disable it as well --- src/fsfw/devicehandlers/DeviceHandlerBase.cpp | 9 +++++++-- src/fsfw/devicehandlers/DeviceHandlerBase.h | 5 +++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/fsfw/devicehandlers/DeviceHandlerBase.cpp b/src/fsfw/devicehandlers/DeviceHandlerBase.cpp index 95e25b74..aab3aa16 100644 --- a/src/fsfw/devicehandlers/DeviceHandlerBase.cpp +++ b/src/fsfw/devicehandlers/DeviceHandlerBase.cpp @@ -481,7 +481,7 @@ ReturnValue_t DeviceHandlerBase::updateReplyMapEntry(DeviceCommandId_t deviceRep } } -ReturnValue_t DeviceHandlerBase::enablePeriodicReply(DeviceCommandId_t deviceReply) { +ReturnValue_t DeviceHandlerBase::enablePeriodicReply(bool enable, DeviceCommandId_t deviceReply) { auto replyIter = deviceReplyMap.find(deviceReply); if (replyIter == deviceReplyMap.end()) { triggerEvent(INVALID_DEVICE_COMMAND, deviceReply); @@ -491,7 +491,12 @@ ReturnValue_t DeviceHandlerBase::enablePeriodicReply(DeviceCommandId_t deviceRep if(not info->periodic) { return COMMAND_NOT_SUPPORTED; } - info->delayCycles = info->maxDelayCycles; + if(enable) { + info->delayCycles = info->maxDelayCycles; + } + else { + info->delayCycles = 0; + } } return HasReturnvaluesIF::RETURN_OK; } diff --git a/src/fsfw/devicehandlers/DeviceHandlerBase.h b/src/fsfw/devicehandlers/DeviceHandlerBase.h index d478b0fa..138b429e 100644 --- a/src/fsfw/devicehandlers/DeviceHandlerBase.h +++ b/src/fsfw/devicehandlers/DeviceHandlerBase.h @@ -486,10 +486,11 @@ protected: /** * Enables a periodic reply for a given command. It sets to delay cycles to the specified - * maximum delay cycles for a given reply ID. + * maximum delay cycles for a given reply ID if enabled or to 0 if disabled. + * @param enable Specify whether to enable or disable a given periodic reply * @return */ - ReturnValue_t enablePeriodicReply(DeviceCommandId_t deviceReply); + ReturnValue_t enablePeriodicReply(bool enable, DeviceCommandId_t deviceReply); /** * @brief This function returns the reply length of the next reply to read. From 134deb3f433988513617a0d510fbbf8629b34fbc Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sat, 11 Sep 2021 17:43:58 +0200 Subject: [PATCH 7/7] renamed function --- src/fsfw/devicehandlers/DeviceHandlerBase.cpp | 2 +- src/fsfw/devicehandlers/DeviceHandlerBase.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/fsfw/devicehandlers/DeviceHandlerBase.cpp b/src/fsfw/devicehandlers/DeviceHandlerBase.cpp index aab3aa16..c3fc023e 100644 --- a/src/fsfw/devicehandlers/DeviceHandlerBase.cpp +++ b/src/fsfw/devicehandlers/DeviceHandlerBase.cpp @@ -481,7 +481,7 @@ ReturnValue_t DeviceHandlerBase::updateReplyMapEntry(DeviceCommandId_t deviceRep } } -ReturnValue_t DeviceHandlerBase::enablePeriodicReply(bool enable, DeviceCommandId_t deviceReply) { +ReturnValue_t DeviceHandlerBase::updatePeriodicReply(bool enable, DeviceCommandId_t deviceReply) { auto replyIter = deviceReplyMap.find(deviceReply); if (replyIter == deviceReplyMap.end()) { triggerEvent(INVALID_DEVICE_COMMAND, deviceReply); diff --git a/src/fsfw/devicehandlers/DeviceHandlerBase.h b/src/fsfw/devicehandlers/DeviceHandlerBase.h index 138b429e..30d36ef0 100644 --- a/src/fsfw/devicehandlers/DeviceHandlerBase.h +++ b/src/fsfw/devicehandlers/DeviceHandlerBase.h @@ -451,7 +451,7 @@ protected: * @param periodic Indicates if the command is periodic (i.e. it is sent * by the device repeatedly without request) or not. Default is aperiodic (0). * Please note that periodic replies are disabled by default. You can enable them with - * #enablePeriodicReplies + * #updatePeriodicReply * @return - @c RETURN_OK when the command was successfully inserted, * - @c RETURN_FAILED else. */ @@ -468,7 +468,7 @@ protected: * @param periodic Indicates if the command is periodic (i.e. it is sent * by the device repeatedly without request) or not. Default is aperiodic (0). * Please note that periodic replies are disabled by default. You can enable them with - * #enablePeriodicReplies + * #updatePeriodicReply * @return - @c RETURN_OK when the command was successfully inserted, * - @c RETURN_FAILED else. */ @@ -490,7 +490,7 @@ protected: * @param enable Specify whether to enable or disable a given periodic reply * @return */ - ReturnValue_t enablePeriodicReply(bool enable, DeviceCommandId_t deviceReply); + ReturnValue_t updatePeriodicReply(bool enable, DeviceCommandId_t deviceReply); /** * @brief This function returns the reply length of the next reply to read.