catch2 running

This commit is contained in:
Ulrich Mohr 2022-02-10 18:15:33 +01:00
parent 50cf01376f
commit d9badee18f
5 changed files with 63 additions and 39 deletions

View File

@ -13,7 +13,7 @@ cmake_minimum_required(VERSION 3.13)
set(CMAKE_SCRIPT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") 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_ETL_LIB "Add ETL library" ON)
option(EIVE_ADD_JSON_LIB "Add JSON library" ON) option(EIVE_ADD_JSON_LIB "Add JSON library" ON)
option(EIVE_SYSROOT_MAGIC "Perform sysroot magic which might not be necessary" OFF) 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(OBSW_NAME ${CMAKE_PROJECT_NAME})
set(WATCHDOG_NAME eive-watchdog) set(WATCHDOG_NAME eive-watchdog)
set(SIMPLE_OBSW_NAME eive-simple) set(SIMPLE_OBSW_NAME eive-simple)
set(UNITTEST_NAME eive-unittest)
set(LIB_FSFW_NAME fsfw) set(LIB_FSFW_NAME fsfw)
set(LIB_EIVE_MISSION eive-mission) set(LIB_EIVE_MISSION eive-mission)
set(LIB_ETL_NAME etl) 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(FSFW_WARNING_SHADOW_LOCAL_GCC OFF)
set(EIVE_ADD_LINUX_FILES False) 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, # Analyse different OS and architecture/target options, determine BSP_PATH,
# display information about compiler etc. # display information about compiler etc.
include (${CMAKE_SCRIPT_PATH}/HardwareOsPreConfig.cmake) include (${CMAKE_SCRIPT_PATH}/HardwareOsPreConfig.cmake)
@ -122,10 +116,6 @@ else()
set(FSFW_CONFIG_PATH "${BSP_PATH}/fsfwconfig") set(FSFW_CONFIG_PATH "${BSP_PATH}/fsfwconfig")
endif() 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 # Configuration files
configure_file(${COMMON_CONFIG_PATH}/commonConfig.h.in commonConfig.h) configure_file(${COMMON_CONFIG_PATH}/commonConfig.h.in commonConfig.h)
@ -147,6 +137,23 @@ set(FSFW_ADDITIONAL_INC_PATHS
${CMAKE_CURRENT_BINARY_DIR} ${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 # Executable and Sources
################################################################################ ################################################################################
@ -160,7 +167,6 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
"-Wno-unused-parameter" "-Wno-unused-parameter"
"-Wno-psabi" "-Wno-psabi"
) )
message(STATUS "goes here")
# Remove unused sections. # Remove unused sections.
add_compile_options( add_compile_options(
"-ffunction-sections" "-ffunction-sections"
@ -180,7 +186,7 @@ endif()
add_library(${LIB_EIVE_MISSION}) add_library(${LIB_EIVE_MISSION})
# Add executable # Add main executable
add_executable(${OBSW_NAME}) add_executable(${OBSW_NAME})
#watchdog #watchdog
@ -189,11 +195,15 @@ add_subdirectory(${WATCHDOG_PATH})
target_link_libraries(${WATCHDOG_NAME} PUBLIC target_link_libraries(${WATCHDOG_NAME} PUBLIC
${LIB_CXX_FS} ${LIB_CXX_FS}
) )
target_include_directories(${WATCHDOG_NAME} PUBLIC target_include_directories(${WATCHDOG_NAME} PUBLIC
${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}
) )
#unittests
add_executable(${UNITTEST_NAME} EXCLUDE_FROM_ALL)
if(EIVE_ADD_ETL_LIB) if(EIVE_ADD_ETL_LIB)
add_subdirectory(${LIB_ETL_PATH}) add_subdirectory(${LIB_ETL_PATH})
endif() endif()
@ -203,16 +213,16 @@ if(EIVE_ADD_JSON_LIB)
endif() endif()
if(NOT EIVE_BUILD_UNITTESTS)
if(EIVE_ADD_LINUX_FILES) if(EIVE_ADD_LINUX_FILES)
add_subdirectory(${LIB_ARCSEC_PATH}) add_subdirectory(${LIB_ARCSEC_PATH})
add_subdirectory(${LINUX_PATH}) add_subdirectory(${LINUX_PATH})
endif()
add_subdirectory(${BSP_PATH})
if(ADD_CSP_LIB)
add_subdirectory(${LIB_CSP_PATH})
endif()
endif() endif()
add_subdirectory(${BSP_PATH})
if(ADD_CSP_LIB)
add_subdirectory(${LIB_CSP_PATH})
endif()
add_subdirectory(${COMMON_PATH}) add_subdirectory(${COMMON_PATH})
@ -224,10 +234,8 @@ add_subdirectory(${LIB_EIVE_MISSION_PATH})
add_subdirectory(${TEST_PATH}) add_subdirectory(${TEST_PATH})
if(EIVE_BUILD_UNITTESTS) add_subdirectory(${UNITTEST_PATH})
# add_subdirectory(${LIB_CATCH2_PATH})
add_subdirectory(${UNITTEST_PATH})
endif()
################################################################################ ################################################################################
# Post-Sources preparation # Post-Sources preparation
@ -253,6 +261,9 @@ if(TGT_BSP MATCHES "arm/q7s")
) )
endif() endif()
target_link_libraries(${UNITTEST_NAME} PRIVATE
Catch2
)
if(ADD_CSP_LIB) if(ADD_CSP_LIB)
@ -274,12 +285,6 @@ if(EIVE_ADD_JSON_LIB)
) )
endif() endif()
if(EIVE_BUILD_UNITTESTS)
target_link_libraries(${TARGET_NAME} PRIVATE
${CATCH2_TARGET}
)
endif()
target_link_libraries(${LIB_EIVE_MISSION} PUBLIC target_link_libraries(${LIB_EIVE_MISSION} PUBLIC
${LIB_CXX_FS} ${LIB_CXX_FS}
) )

View File

@ -1,5 +1,6 @@
add_subdirectory(testcfg) add_subdirectory(controller)
target_sources(${TARGET_NAME} PRIVATE
target_sources(${UNITTEST_NAME} PRIVATE
main.cpp main.cpp
) )

View File

@ -0,0 +1,3 @@
target_sources(${UNITTEST_NAME} PRIVATE
testThermalController.cpp
)

View File

@ -0,0 +1,7 @@
#include <catch2/catch_test_macros.hpp>
TEST_CASE( "Thermal Controller" , "[ThermalController]") {
bool test = true;
REQUIRE( test == true);
}

View File

@ -1,7 +1,15 @@
#include "fsfw/serviceinterface/ServiceInterfaceStream.h" #include <stdio.h>
#include "fsfw_tests/unit/CatchRunner.h"
#include <catch2/catch_session.hpp>
int main(int argc, char* argv[]) { 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;
} }