Commit 62149342 authored by David Frank's avatar David Frank
Browse files

Fixed Sanitizers

parent ac62bc74
...@@ -20,10 +20,14 @@ option(ELSA_TESTING "Enable the unit tests of elsa" ${ELSA_MASTER_PROJECT}) ...@@ -20,10 +20,14 @@ option(ELSA_TESTING "Enable the unit tests of elsa" ${ELSA_MASTER_PROJECT})
option(ELSA_INSTALL "Generate the install target" ${ELSA_MASTER_PROJECT}) option(ELSA_INSTALL "Generate the install target" ${ELSA_MASTER_PROJECT})
option(GIT_SUBMODULE "Check submodules during build" ${ELSA_MASTER_PROJECT}) option(GIT_SUBMODULE "Check submodules during build" ${ELSA_MASTER_PROJECT})
option(ELSA_BUILD_EXAMPLES "Build examples" ${ELSA_MASTER_PROJECT}) option(ELSA_BUILD_EXAMPLES "Build examples" ${ELSA_MASTER_PROJECT})
option(ELSA_COVERAGE "Enables test coverage reporting" OFF)
option(ELSA_BUILD_CUDA_PROJECTORS "Attempts to build CUDA projectors if set" ON) option(ELSA_BUILD_CUDA_PROJECTORS "Attempts to build CUDA projectors if set" ON)
option(ELSA_BUILD_WITH_MORE_WARNINGS "Reduce noise of warnings, but make chaning fast and easy" OFF) option(ELSA_BUILD_WITH_MORE_WARNINGS "Reduce noise of warnings, but make chaning fast and easy" OFF)
option(ELSA_BUILD_WITH_SANITIZERS "Build with Sanitizers. Pass ELSA_SANITIZE_THREAD or ELSA_SANITIZE_ADDRESS" ON) option(ELSA_CREATE_JUNIT_REPORTS "Create JUnit style reports while running tests" ON)
option(ELSA_SANITIZE_THREAD "Build with TSAN" OFF)
option(ELSA_SANITIZE_ADDRESS "Build with ASAN and UBSAN" OFF)
# ------------ general setup ----------- # ------------ general setup -----------
# ------------ # ------------
...@@ -83,6 +87,20 @@ else(ELSA_TESTING) ...@@ -83,6 +87,20 @@ else(ELSA_TESTING)
endif(ELSA_TESTING) endif(ELSA_TESTING)
# ------------ setup coverage test -----------
# ------------
if(ELSA_COVERAGE)
message(STATUS "elsa coverage is enabled")
include(CodeCoverage)
APPEND_COVERAGE_COMPILER_FLAGS()
set(COVERAGE_LCOV_EXCLUDES '${PROJECT_SOURCE_DIR}/thirdparty/*' '/usr/*')
SETUP_TARGET_FOR_COVERAGE_LCOV(NAME test_coverage EXECUTABLE ctest)
endif(ELSA_COVERAGE)
# ------------ add code/docs ----------- # ------------ add code/docs -----------
# ------------ # ------------
......
...@@ -4,19 +4,16 @@ if(ELSA_SANITIZE_THREAD AND ELSA_SANITIZE_ADDRESS) ...@@ -4,19 +4,16 @@ if(ELSA_SANITIZE_THREAD AND ELSA_SANITIZE_ADDRESS)
endif() endif()
if(ELSA_SANITIZE_ADDRESS) if(ELSA_SANITIZE_ADDRESS)
message(STATUS "AddressSanitizer enabled") message(STATUS "Address and undefiened-behavior sanitizer enabled")
set(SANITIZER_FLAGS "-fsanitize=address,undefined") set(SANITIZERS "leak,address,undefined,shift,integer-divide-by-zero,unreachable,vla-bound,null,return,signed-integer-overflow")
add_compile_options("-fno-sanitize=signed-integer-overflow") set(SANITIZER_FLAGS "-ggdb -O1 -fno-sanitize-recover=all -fno-omit-frame-pointer -fsanitize=${SANITIZERS}")
endif() endif()
if(ELSA_SANITIZE_THREAD) if(ELSA_SANITIZE_THREAD)
message(STATUS "ThreadSanitizer enabled") message(STATUS "Thread sanitizer enabled")
set(SANITIZER_FLAGS "-fsanitize=thread") set(SANITIZER_FLAGS "-ggdb -O1 -fno-sanitize-recover=all -fno-omit-frame-pointer -fsanitize=thread")
endif() endif()
if(ELSA_SANITIZE_THREAD OR ELSA_SANITIZE_ADDRESS) set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${SANITIZER_FLAGS}")
add_compile_options(${SANITIZER_FLAGS}) set(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} ${SANITIZER_FLAGS}")
add_compile_options("-fno-sanitize-recover=all") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_LINKER_FLAGS_DEBUG}")
add_compile_options("-fno-omit-frame-pointer") \ No newline at end of file
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${SANITIZER_FLAGS} -fuse-ld=gold")
endif()
...@@ -6,6 +6,31 @@ macro(registerComponent name) ...@@ -6,6 +6,31 @@ macro(registerComponent name)
set(ELSA_REGISTERED_COMPONENTS "${ELSA_REGISTERED_COMPONENTS};${name}" PARENT_SCOPE) set(ELSA_REGISTERED_COMPONENTS "${ELSA_REGISTERED_COMPONENTS};${name}" PARENT_SCOPE)
endmacro() endmacro()
# macro for the unit tests
MACRO (ELSA_TEST NAME)
# create the test executable
add_executable(test_${NAME} test_${NAME}.cpp test_main.cpp)
# add catch and the corresponding elsa library
target_link_libraries(test_${NAME} PRIVATE Catch2::Catch2 ${ELSA_MODULE_TARGET_NAME})
# enable C++17
target_compile_features(test_${NAME} PUBLIC cxx_std_17)
# if we use JUnit reporter handle arguments
if(${ELSA_CREATE_JUNIT_REPORTS})
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/test_reports)
set(ELSA_JUNIT_ARGUMENTS "-r junit" "-o ${PROJECT_BINARY_DIR}/test_reports/test_${NAME}.xml")
endif(${ELSA_CREATE_JUNIT_REPORTS})
# let Catch discover and register all the test cases
catch_discover_tests(test_${NAME} TEST_SPEC ${ELSA_JUNIT_ARGUMENTS})
ENDMACRO (ELSA_TEST)
# add sanitizers if in debug mode
if(${CMAKE_BUILD_TYPE} MATCHES "Debug")
include(${PROJECT_SOURCE_DIR}/cmake/Sanitizers.cmake)
endif()
# add the elsa modules # add the elsa modules
add_subdirectory(core) add_subdirectory(core)
add_subdirectory(logging) add_subdirectory(logging)
...@@ -36,11 +61,6 @@ if(${ELSA_MASTER_PROJECT}) ...@@ -36,11 +61,6 @@ if(${ELSA_MASTER_PROJECT})
endif() endif()
endif(${ELSA_BUILD_WITH_MORE_WARNINGS}) endif(${ELSA_BUILD_WITH_MORE_WARNINGS})
endforeach (_component ELSA_REGISTERED_COMPONENTS) endforeach (_component ELSA_REGISTERED_COMPONENTS)
# add sanitizers if enabled
if(${ELSA_BUILD_WITH_SANITIZERS})
include(${PROJECT_SOURCE_DIR}/cmake/Sanitizers.cmake)
endif(${ELSA_BUILD_WITH_SANITIZERS})
endif(${ELSA_MASTER_PROJECT}) endif(${ELSA_MASTER_PROJECT})
# propogate the variable to the parent scope # propogate the variable to the parent scope
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment