diff --git a/CMakeLists.txt b/CMakeLists.txt index 41be31e0c..b22ffe464 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -174,7 +174,7 @@ if(FSFW_BUILD_TESTS) configure_file(unittests/testcfg/FSFWConfig.h.in FSFWConfig.h) configure_file(unittests/testcfg/TestsConfig.h.in tests/TestsConfig.h) - if(FSFW_OSAL MATCHES "freertos") + if(FSFW_OSAL MATCHES "freertos") message( STATUS "${MSG_PREFIX} Downloading FreeRTOS with FetchContent" @@ -193,7 +193,6 @@ if(FSFW_BUILD_TESTS) set(LIB_OS_NAME FreeRTOS) target_include_directories(FreeRTOS PUBLIC unittests/testcfg/freertos) - endif() project(${FSFW_TEST_TGT} CXX C) @@ -385,6 +384,9 @@ if(FSFW_BUILD_TESTS) endif() target_link_libraries(${FSFW_TEST_TGT} PRIVATE Catch2::Catch2 ${LIB_FSFW_NAME}) + if(FSFW_OSAL MATCHES "freertos") + target_link_libraries(${FSFW_TEST_TGT} PRIVATE FreeRTOS) + endif() endif() # The project CMakeLists file has to set the FSFW_CONFIG_PATH and add it. If diff --git a/unittests/CatchRunner.cpp b/unittests/CatchRunner.cpp index 9bdcb676a..5149f8b53 100644 --- a/unittests/CatchRunner.cpp +++ b/unittests/CatchRunner.cpp @@ -11,15 +11,55 @@ #define CATCH_CONFIG_COLOUR_WINDOWS #include +#include + +#ifdef FSFW_OSAL_FREERTOS + #include + #include "task.h" +#endif extern int customSetup(); extern int customTeardown(); + +#ifdef FSFW_OSAL_FREERTOS +struct Taskparameters { + int argc; char** argv; +} taskParameters; + +void unittestTaskFunction( void *pvParameters ) { + puts("go"); + Taskparameters* parameters = (Taskparameters*)pvParameters; + int result = Catch::Session().run(parameters->argc, parameters->argv); + puts("gone"); + vTaskDelete( NULL ); +} +#endif + + int main(int argc, char* argv[]) { customSetup(); + int result = 0; + + puts("pre"); + + #ifdef FSFW_OSAL_FREERTOS + puts("task"); + xTaskCreate( unittestTaskFunction, /* The function that implements the task. */ + "Unittests", /* The text name assigned to the task - for debug only as it is not used by the kernel. */ + configMINIMAL_STACK_SIZE, /* The size of the stack to allocate to the task. */ + &taskParameters, /* The parameter passed to the task - not used in this simple case. */ + 1, /* The priority assigned to the task. */ + NULL ); /* The task handle is not required, so NULL is passed. */ + taskParameters.argc = argc; + taskParameters.argv = argv; + vTaskStartScheduler(); + #else + puts("nom"); // Catch internal function call - int result = Catch::Session().run(argc, argv); + result = Catch::Session().run(argc, argv); + #endif // global clean-up customTeardown(); diff --git a/unittests/CatchSetup.cpp b/unittests/CatchSetup.cpp index fc5bb3f57..cbed8029e 100644 --- a/unittests/CatchSetup.cpp +++ b/unittests/CatchSetup.cpp @@ -6,6 +6,8 @@ #include #endif + + #include "fsfw/objectmanager/ObjectManager.h" #include "fsfw/serviceinterface/ServiceInterface.h" #include "fsfw/storagemanager/StorageManagerIF.h" diff --git a/unittests/osal/TestSemaphore.cpp b/unittests/osal/TestSemaphore.cpp index 1d8758b18..6bf63f6a8 100644 --- a/unittests/osal/TestSemaphore.cpp +++ b/unittests/osal/TestSemaphore.cpp @@ -5,7 +5,7 @@ #include // binary semaphores currently only supported on linux -#ifdef FSFW_OSAL_LINUX +#if defined(FSFW_OSAL_LINUX) || defined(FSFW_OSAL_FREERTOS) TEST_CASE("Binary Semaphore Test", "[BinSemaphore]") { // perform set-up here diff --git a/unittests/testcfg/freertos/FreeRTOSConfig.h b/unittests/testcfg/freertos/FreeRTOSConfig.h index ca470db0c..0c4d78f8a 100644 --- a/unittests/testcfg/freertos/FreeRTOSConfig.h +++ b/unittests/testcfg/freertos/FreeRTOSConfig.h @@ -16,7 +16,7 @@ #define configTASK_NOTIFICATION_ARRAY_ENTRIES 3 #define configUSE_MUTEXES 1 #define configUSE_RECURSIVE_MUTEXES 0 -#define configUSE_COUNTING_SEMAPHORES 0 +#define configUSE_COUNTING_SEMAPHORES 1 #define configUSE_ALTERNATIVE_API 0 /* Deprecated! */ #define configQUEUE_REGISTRY_SIZE 10 #define configUSE_QUEUE_SETS 0