From d9badee18f2b206f27c84146a8e927ea4676de98 Mon Sep 17 00:00:00 2001 From: Ulrich Mohr Date: Thu, 10 Feb 2022 18:15:33 +0100 Subject: [PATCH] catch2 running --- CMakeLists.txt | 73 ++++++++++--------- unittest/CMakeLists.txt | 5 +- unittest/controller/CMakeLists.txt | 3 + unittest/controller/testThermalController.cpp | 7 ++ unittest/main.cpp | 14 +++- 5 files changed, 63 insertions(+), 39 deletions(-) create mode 100644 unittest/controller/CMakeLists.txt create mode 100644 unittest/controller/testThermalController.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index a3dd1d7c..9144f27d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ cmake_minimum_required(VERSION 3.13) set(CMAKE_SCRIPT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") -option(EIVE_BUILD_UNITTESTS "Build Catch2 unittests" OFF) + option(EIVE_ADD_ETL_LIB "Add ETL library" ON) option(EIVE_ADD_JSON_LIB "Add JSON library" ON) option(EIVE_SYSROOT_MAGIC "Perform sysroot magic which might not be necessary" OFF) @@ -45,6 +45,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED True) set(OBSW_NAME ${CMAKE_PROJECT_NAME}) set(WATCHDOG_NAME eive-watchdog) set(SIMPLE_OBSW_NAME eive-simple) +set(UNITTEST_NAME eive-unittest) set(LIB_FSFW_NAME fsfw) set(LIB_EIVE_MISSION eive-mission) set(LIB_ETL_NAME etl) @@ -78,13 +79,6 @@ set(LIB_JSON_PATH ${THIRD_PARTY_FOLDER}/json) set(FSFW_WARNING_SHADOW_LOCAL_GCC OFF) set(EIVE_ADD_LINUX_FILES False) -if(EIVE_BUILD_UNITTESTS) -endif() - -if(FSFW_ADD_UNITTESTS) - set(CATCH2_TARGET Catch2) -endif() - # Analyse different OS and architecture/target options, determine BSP_PATH, # display information about compiler etc. include (${CMAKE_SCRIPT_PATH}/HardwareOsPreConfig.cmake) @@ -122,10 +116,6 @@ else() set(FSFW_CONFIG_PATH "${BSP_PATH}/fsfwconfig") endif() -if(EIVE_BUILD_UNITTESTS) - # configure_file(${UNITTEST_CFG_PATH}/TestsConfig.h.in TestsConfig.h) - # set(FSFW_CONFIG_PATH ${UNITTEST_CFG_PATH}) -endif() # Configuration files configure_file(${COMMON_CONFIG_PATH}/commonConfig.h.in commonConfig.h) @@ -147,6 +137,23 @@ set(FSFW_ADDITIONAL_INC_PATHS ${CMAKE_CURRENT_BINARY_DIR} ) +# Check whether the user has already installed Catch2 first +find_package(Catch2 3) +# Not installed, so use FetchContent to download and provide Catch2 +if(NOT Catch2_FOUND) + include(FetchContent) + + FetchContent_Declare( + Catch2 + GIT_REPOSITORY https://github.com/catchorg/Catch2.git + GIT_TAG v3.0.0-preview4 + ) + + FetchContent_MakeAvailable(Catch2) + #fixes regression -preview4, to be confirmed in later releases + set_target_properties(Catch2 PROPERTIES DEBUG_POSTFIX "") +endif() + ################################################################################ # Executable and Sources ################################################################################ @@ -160,7 +167,6 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") "-Wno-unused-parameter" "-Wno-psabi" ) - message(STATUS "goes here") # Remove unused sections. add_compile_options( "-ffunction-sections" @@ -180,7 +186,7 @@ endif() add_library(${LIB_EIVE_MISSION}) -# Add executable +# Add main executable add_executable(${OBSW_NAME}) #watchdog @@ -189,11 +195,15 @@ add_subdirectory(${WATCHDOG_PATH}) target_link_libraries(${WATCHDOG_NAME} PUBLIC ${LIB_CXX_FS} ) - target_include_directories(${WATCHDOG_NAME} PUBLIC ${CMAKE_BINARY_DIR} ) +#unittests +add_executable(${UNITTEST_NAME} EXCLUDE_FROM_ALL) + + + if(EIVE_ADD_ETL_LIB) add_subdirectory(${LIB_ETL_PATH}) endif() @@ -203,16 +213,16 @@ if(EIVE_ADD_JSON_LIB) endif() -if(NOT EIVE_BUILD_UNITTESTS) - if(EIVE_ADD_LINUX_FILES) - add_subdirectory(${LIB_ARCSEC_PATH}) - add_subdirectory(${LINUX_PATH}) - endif() - add_subdirectory(${BSP_PATH}) - if(ADD_CSP_LIB) - add_subdirectory(${LIB_CSP_PATH}) - endif() + +if(EIVE_ADD_LINUX_FILES) + add_subdirectory(${LIB_ARCSEC_PATH}) + add_subdirectory(${LINUX_PATH}) endif() +add_subdirectory(${BSP_PATH}) +if(ADD_CSP_LIB) + add_subdirectory(${LIB_CSP_PATH}) +endif() + add_subdirectory(${COMMON_PATH}) @@ -224,10 +234,8 @@ add_subdirectory(${LIB_EIVE_MISSION_PATH}) add_subdirectory(${TEST_PATH}) -if(EIVE_BUILD_UNITTESTS) - # add_subdirectory(${LIB_CATCH2_PATH}) - add_subdirectory(${UNITTEST_PATH}) -endif() +add_subdirectory(${UNITTEST_PATH}) + ################################################################################ # Post-Sources preparation @@ -253,6 +261,9 @@ if(TGT_BSP MATCHES "arm/q7s") ) endif() +target_link_libraries(${UNITTEST_NAME} PRIVATE + Catch2 +) if(ADD_CSP_LIB) @@ -274,12 +285,6 @@ if(EIVE_ADD_JSON_LIB) ) endif() -if(EIVE_BUILD_UNITTESTS) - target_link_libraries(${TARGET_NAME} PRIVATE - ${CATCH2_TARGET} - ) -endif() - target_link_libraries(${LIB_EIVE_MISSION} PUBLIC ${LIB_CXX_FS} ) diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt index 0c799d45..b4c26ed6 100644 --- a/unittest/CMakeLists.txt +++ b/unittest/CMakeLists.txt @@ -1,5 +1,6 @@ -add_subdirectory(testcfg) +add_subdirectory(controller) -target_sources(${TARGET_NAME} PRIVATE + +target_sources(${UNITTEST_NAME} PRIVATE main.cpp ) \ No newline at end of file diff --git a/unittest/controller/CMakeLists.txt b/unittest/controller/CMakeLists.txt new file mode 100644 index 00000000..ee9b1a8b --- /dev/null +++ b/unittest/controller/CMakeLists.txt @@ -0,0 +1,3 @@ +target_sources(${UNITTEST_NAME} PRIVATE + testThermalController.cpp +) \ No newline at end of file diff --git a/unittest/controller/testThermalController.cpp b/unittest/controller/testThermalController.cpp new file mode 100644 index 00000000..c7a5953f --- /dev/null +++ b/unittest/controller/testThermalController.cpp @@ -0,0 +1,7 @@ +#include + +TEST_CASE( "Thermal Controller" , "[ThermalController]") { + bool test = true; + REQUIRE( test == true); + +} \ No newline at end of file diff --git a/unittest/main.cpp b/unittest/main.cpp index 811df98e..fecfaf75 100644 --- a/unittest/main.cpp +++ b/unittest/main.cpp @@ -1,7 +1,15 @@ -#include "fsfw/serviceinterface/ServiceInterfaceStream.h" -#include "fsfw_tests/unit/CatchRunner.h" +#include + +#include int main(int argc, char* argv[]) { - // fsfwtest::customMain(argc, argv); + puts("unittests"); + + + // Catch internal function call + int result = Catch::Session().run(argc, argv); + + // global clean-up + return result; }