IAP GITLAB

Skip to content
Snippets Groups Projects
Commit 622884af authored by Hans Dembinski's avatar Hans Dembinski
Browse files

Merge branch 'sanitizers' into 'master'

Adding sanitizers (temporarily disabled globally until bugs are fixed)

See merge request AirShowerPhysics/corsika!106
parents c6913f51 fb9cff3e
No related branches found
No related tags found
No related merge requests found
Showing
with 124 additions and 112 deletions
...@@ -2,6 +2,12 @@ image: corsika/devel:u-18.04 ...@@ -2,6 +2,12 @@ image: corsika/devel:u-18.04
variables: variables:
GIT_SSL_NO_VERIFY: "1" GIT_SSL_NO_VERIFY: "1"
## Runtime options for sanitizers
# (detect_leaks=0 because leak detection doesn't work in CI, but you can
# try to test with leak detection locally by using detect_leaks=1)
UBSAN_OPTIONS: "print_stacktrace=1"
LSAN_OPTIONS: "log_threads=1"
ASAN_OPTIONS: "detect_leaks=0:detect_stack_use_after_return=1"
build: build:
stage: build stage: build
...@@ -11,7 +17,7 @@ build: ...@@ -11,7 +17,7 @@ build:
- mkdir build - mkdir build
- cd build - cd build
- cmake .. - cmake ..
- cmake --build . -- -j 4 - cmake --build . -- -j 4
- ctest -j4 -V >& test.log - ctest -j4 -V >& test.log
after_script: after_script:
- cd build - cd build
......
...@@ -13,6 +13,9 @@ enable_language (Fortran) ...@@ -13,6 +13,9 @@ enable_language (Fortran)
# ignore many irrelevant Up-to-date messages during install # ignore many irrelevant Up-to-date messages during install
set (CMAKE_INSTALL_MESSAGE LAZY) set (CMAKE_INSTALL_MESSAGE LAZY)
# TEMPORARY: this should be removed, the sanitizers should be always enabled
option(CORSIKA_SANITIZERS_ENABLED "temporary way to globally disable sanitizers until the currently failing tests are fixed" OFF)
# directory for local cmake modules # directory for local cmake modules
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeModules) set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeModules)
include (CorsikaUtilities) # a few cmake function include (CorsikaUtilities) # a few cmake function
......
...@@ -95,11 +95,61 @@ endmacro(CORSIKA_ADD_FILES_ABSOLUTE) ...@@ -95,11 +95,61 @@ endmacro(CORSIKA_ADD_FILES_ABSOLUTE)
################################################# #################################################
# #
# central macro to activate unit tests in cmake # central macro to register unit tests in cmake
# #
# 1) Simple use:
# Pass the name of the test.cc file as the first
# argument, without the ".cc" extention.
#
# Example: CORSIKA_ADD_TEST (testSomething)
#
# This generates target testSomething from file testSomething.cc.
#
# 2) Customize sources:
# If 1) doesn't work, use the SOURCES keyword to explicitly
# specify the sources.
#
# Example: CORSIKA_ADD_TEST (testSomething
# SOURCES source1.cc source2.cc someheader.h)
#
# 3) Customize sanitizers:
# You can override which sanitizers are compiled into the
# test, but only do this if the defaults do not work.
#
# Example: CORSIKA_ADD_TEST (testSomething SANITIZE undefined)
#
# Only uses the sanitizer for undefined behavior.
#
# In all cases, you can further customize the target with
# target_link_libraries(testSomething ...) and so on.
#
# TEMPORARY: All sanitizers are currently globally disabled by default, to enable them,
# set CORSIKA_SANITIZERS_ENABLED to TRUE.
function (CORSIKA_ADD_TEST)
cmake_parse_arguments(PARSE_ARGV 1 _ "" "SANITIZE" "SOURCES")
set(name ${ARGV0})
if (NOT __SOURCES)
set(sources ${name}.cc)
else()
set(sources ${__SOURCES})
endif()
function (CORSIKA_ADD_TEST name) if (NOT __SANITIZE)
set(sanitize "address,undefined")
else()
set(sanitize ${__SANITIZE})
endif()
add_executable(${name} ${sources})
target_compile_options(${name} PRIVATE -g) # do not skip asserts
target_include_directories (${name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) target_include_directories (${name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
file (MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/test_outputs/) file (MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/test_outputs/)
if (CORSIKA_SANITIZERS_ENABLED)
# -O1 is suggested in clang docs to get reasonable performance
target_compile_options(${name} PRIVATE -O1 -fno-omit-frame-pointer -fsanitize=${sanitize} -fno-sanitize-recover=all)
set_target_properties(${name} PROPERTIES LINK_FLAGS "-fsanitize=${sanitize}")
endif()
add_test (NAME ${name} COMMAND ${name} -o ${PROJECT_BINARY_DIR}/test_outputs/junit-${name}.xml -r junit) add_test (NAME ${name} COMMAND ${name} -o ${PROJECT_BINARY_DIR}/test_outputs/junit-${name}.xml -r junit)
endfunction (CORSIKA_ADD_TEST) endfunction (CORSIKA_ADD_TEST)
add_executable (helix_example helix_example.cc)
target_compile_options(helix_example PRIVATE -g) # do not skip asserts
target_link_libraries(helix_example CORSIKAgeometry CORSIKAunits)
install (TARGETS helix_example DESTINATION share/examples)
CORSIKA_ADD_TEST (helix_example) CORSIKA_ADD_TEST (helix_example)
target_link_libraries (helix_example CORSIKAgeometry CORSIKAunits)
install (TARGETS helix_example DESTINATION share/examples)
add_executable (geometry_example geometry_example.cc) CORSIKA_ADD_TEST (geometry_example)
target_compile_options(geometry_example PRIVATE -g) # do not skip asserts
target_link_libraries (geometry_example CORSIKAgeometry CORSIKAunits) target_link_libraries (geometry_example CORSIKAgeometry CORSIKAunits)
install (TARGETS geometry_example DESTINATION share/examples) install (TARGETS geometry_example DESTINATION share/examples)
CORSIKA_ADD_TEST (geometry_example)
add_executable (logger_example logger_example.cc) CORSIKA_ADD_TEST (logger_example)
target_compile_options(logger_example PRIVATE -g) # do not skip asserts
target_link_libraries (logger_example CORSIKAunits CORSIKAlogging) target_link_libraries (logger_example CORSIKAunits CORSIKAlogging)
install (TARGETS logger_example DESTINATION share/examples) install (TARGETS logger_example DESTINATION share/examples)
CORSIKA_ADD_TEST (logger_example)
add_executable (stack_example stack_example.cc) CORSIKA_ADD_TEST (stack_example)
target_compile_options(stack_example PRIVATE -g) # do not skip asserts
target_link_libraries (stack_example SuperStupidStack CORSIKAunits target_link_libraries (stack_example SuperStupidStack CORSIKAunits
CORSIKAlogging) CORSIKAlogging)
CORSIKA_ADD_TEST (stack_example)
add_executable (cascade_example cascade_example.cc) # address sanitizer is making this example too slow, so we only do "undefined"
target_compile_options(cascade_example PRIVATE -g) # do not skip asserts CORSIKA_ADD_TEST (cascade_example SANITIZE "undefined")
target_link_libraries (cascade_example SuperStupidStack CORSIKAunits target_link_libraries (cascade_example
SuperStupidStack
CORSIKAunits
CORSIKAlogging CORSIKAlogging
CORSIKArandom CORSIKArandom
ProcessSibyll ProcessSibyll
...@@ -42,11 +36,12 @@ target_link_libraries (cascade_example SuperStupidStack CORSIKAunits ...@@ -42,11 +36,12 @@ target_link_libraries (cascade_example SuperStupidStack CORSIKAunits
CORSIKAprocesssequence CORSIKAprocesssequence
) )
install (TARGETS cascade_example DESTINATION share/examples) install (TARGETS cascade_example DESTINATION share/examples)
CORSIKA_ADD_TEST (cascade_example)
add_executable (boundary_example boundary_example.cc) CORSIKA_ADD_TEST (boundary_example)
target_compile_options(boundary_example PRIVATE -g) # do not skip asserts target_link_libraries (boundary_example
target_link_libraries (boundary_example SuperStupidStack CORSIKAunits CORSIKAlogging SuperStupidStack
CORSIKAunits
CORSIKAlogging
CORSIKArandom CORSIKArandom
ProcessSibyll ProcessSibyll
CORSIKAcascade CORSIKAcascade
...@@ -60,12 +55,12 @@ target_link_libraries (boundary_example SuperStupidStack CORSIKAunits CORSIKAlog ...@@ -60,12 +55,12 @@ target_link_libraries (boundary_example SuperStupidStack CORSIKAunits CORSIKAlog
CORSIKAprocesssequence CORSIKAprocesssequence
) )
install (TARGETS boundary_example DESTINATION share/examples) install (TARGETS boundary_example DESTINATION share/examples)
CORSIKA_ADD_TEST (boundary_example)
if (Pythia8_FOUND) if (Pythia8_FOUND)
add_executable (cascade_proton_example cascade_proton_example.cc) CORSIKA_ADD_TEST (cascade_proton_example)
target_compile_options(cascade_proton_example PRIVATE -g) # do not skip asserts target_link_libraries (cascade_proton_example
target_link_libraries (cascade_proton_example SuperStupidStack CORSIKAunits SuperStupidStack
CORSIKAunits
CORSIKAlogging CORSIKAlogging
CORSIKArandom CORSIKArandom
ProcessSibyll ProcessSibyll
...@@ -84,14 +79,13 @@ if (Pythia8_FOUND) ...@@ -84,14 +79,13 @@ if (Pythia8_FOUND)
CORSIKAenvironment CORSIKAenvironment
CORSIKAprocesssequence CORSIKAprocesssequence
) )
install (TARGETS cascade_proton_example DESTINATION share/examples) install (TARGETS cascade_proton_example DESTINATION share/examples)
CORSIKA_ADD_TEST (cascade_proton_example)
endif() endif()
add_executable (vertical_EAS vertical_EAS.cc) CORSIKA_ADD_TEST(vertical_EAS)
target_compile_options(vertical_EAS PRIVATE -g) # do not skip asserts target_link_libraries (vertical_EAS
target_link_libraries (vertical_EAS SuperStupidStack CORSIKAunits SuperStupidStack
CORSIKAunits
CORSIKAlogging CORSIKAlogging
CORSIKArandom CORSIKArandom
ProcessSibyll ProcessSibyll
...@@ -110,14 +104,11 @@ target_link_libraries (vertical_EAS SuperStupidStack CORSIKAunits ...@@ -110,14 +104,11 @@ target_link_libraries (vertical_EAS SuperStupidStack CORSIKAunits
CORSIKAprocesssequence CORSIKAprocesssequence
) )
install (TARGETS vertical_EAS DESTINATION share/examples) install (TARGETS vertical_EAS DESTINATION share/examples)
# CORSIKA_ADD_TEST (vertical_EAS) not yet...
add_executable (staticsequence_example staticsequence_example.cc) CORSIKA_ADD_TEST (staticsequence_example)
target_compile_options(staticsequence_example PRIVATE -g) # do not skip asserts
target_link_libraries (staticsequence_example target_link_libraries (staticsequence_example
CORSIKAprocesssequence CORSIKAprocesssequence
CORSIKAunits CORSIKAunits
CORSIKAgeometry CORSIKAgeometry
CORSIKAlogging) CORSIKAlogging)
install (TARGETS staticsequence_example DESTINATION share/examples) install (TARGETS staticsequence_example DESTINATION share/examples)
CORSIKA_ADD_TEST (staticsequence_example)
...@@ -49,12 +49,10 @@ install ( ...@@ -49,12 +49,10 @@ install (
# -------------------- # --------------------
# code unit testing # code unit testing
add_executable (testEnvironment testEnvironment.cc) CORSIKA_ADD_TEST(testEnvironment)
target_link_libraries ( target_link_libraries (
testEnvironment testEnvironment
CORSIKAsetup CORSIKAsetup
CORSIKAenvironment CORSIKAenvironment
CORSIKAthirdparty # for catch2 CORSIKAthirdparty # for catch2
) )
CORSIKA_ADD_TEST(testGeometry)
...@@ -32,11 +32,7 @@ install ( ...@@ -32,11 +32,7 @@ install (
# ---------------- # ----------------
# code unit testing # code unit testing
add_executable ( CORSIKA_ADD_TEST(testCascade)
testCascade
testCascade.cc
)
target_link_libraries ( target_link_libraries (
testCascade testCascade
# CORSIKAutls # CORSIKAutls
...@@ -55,4 +51,3 @@ target_link_libraries ( ...@@ -55,4 +51,3 @@ target_link_libraries (
CORSIKAunits CORSIKAunits
CORSIKAthirdparty # for catch2 CORSIKAthirdparty # for catch2
) )
CORSIKA_ADD_TEST(testCascade)
...@@ -67,20 +67,18 @@ install ( ...@@ -67,20 +67,18 @@ install (
# -------------------- # --------------------
# code unit testing # code unit testing
add_executable (testGeometry testGeometry.cc) CORSIKA_ADD_TEST(testGeometry)
target_link_libraries ( target_link_libraries (
testGeometry testGeometry
CORSIKAgeometry CORSIKAgeometry
CORSIKAunits CORSIKAunits
CORSIKAthirdparty # for catch2 CORSIKAthirdparty # for catch2
) )
CORSIKA_ADD_TEST(testGeometry)
add_executable (testFourVector testFourVector.cc) CORSIKA_ADD_TEST(testFourVector)
target_link_libraries ( target_link_libraries (
testFourVector testFourVector
CORSIKAgeometry CORSIKAgeometry
CORSIKAunits CORSIKAunits
CORSIKAthirdparty # for catch2 CORSIKAthirdparty # for catch2
) )
CORSIKA_ADD_TEST(testFourVector)
...@@ -38,15 +38,11 @@ install ( ...@@ -38,15 +38,11 @@ install (
# ---------------- # ----------------
# code unit testing # code unit testing
add_executable (
testLogging
testLogging.cc
)
CORSIKA_ADD_TEST (testLogging)
target_link_libraries ( target_link_libraries (
testLogging testLogging
CORSIKAlogging CORSIKAlogging
CORSIKAthirdparty # for catch2 CORSIKAthirdparty # for catch2
) )
CORSIKA_ADD_TEST (testLogging)
...@@ -82,16 +82,14 @@ install ( ...@@ -82,16 +82,14 @@ install (
# -------------------- # --------------------
# code unit testing # code unit testing
add_executable ( CORSIKA_ADD_TEST(testParticles
testParticles SOURCES
testParticles.cc testParticles.cc
${PROJECT_BINARY_DIR}/Framework/Particles/GeneratedParticleProperties.inc ${PROJECT_BINARY_DIR}/Framework/Particles/GeneratedParticleProperties.inc
) )
target_link_libraries ( target_link_libraries (
testParticles testParticles
CORSIKAparticles CORSIKAparticles
CORSIKAunits CORSIKAunits
CORSIKAthirdparty # for catch2 CORSIKAthirdparty # for catch2
) )
CORSIKA_ADD_TEST(testParticles)
...@@ -45,11 +45,7 @@ target_link_libraries ( ...@@ -45,11 +45,7 @@ target_link_libraries (
#-- -- -- -- -- -- -- -- #-- -- -- -- -- -- -- --
#code unit testing #code unit testing
add_executable ( CORSIKA_ADD_TEST(testProcessSequence)
testProcessSequence
testProcessSequence.cc
)
target_link_libraries ( target_link_libraries (
testProcessSequence testProcessSequence
CORSIKAsetup CORSIKAsetup
...@@ -57,4 +53,3 @@ target_link_libraries ( ...@@ -57,4 +53,3 @@ target_link_libraries (
CORSIKAprocesssequence CORSIKAprocesssequence
CORSIKAthirdparty # for catch2 CORSIKAthirdparty # for catch2
) )
CORSIKA_ADD_TEST(testProcessSequence)
...@@ -46,11 +46,9 @@ install ( ...@@ -46,11 +46,9 @@ install (
# -------------------- # --------------------
# code unit testing # code unit testing
add_executable (testRandom testRandom.cc) CORSIKA_ADD_TEST(testRandom)
target_link_libraries ( target_link_libraries (
testRandom testRandom
CORSIKArandom CORSIKArandom
CORSIKAthirdparty # for catch2 CORSIKAthirdparty # for catch2
) )
CORSIKA_ADD_TEST(testRandom)
...@@ -34,14 +34,11 @@ install ( ...@@ -34,14 +34,11 @@ install (
) )
#code testing #code testing
add_executable (testStackInterface testStackInterface.cc)
target_link_libraries (testStackInterface CORSIKAstackinterface CORSIKAthirdparty) # for catch2
CORSIKA_ADD_TEST(testStackInterface) CORSIKA_ADD_TEST(testStackInterface)
target_link_libraries (testStackInterface CORSIKAstackinterface CORSIKAthirdparty) # for catch2
add_executable (testSecondaryView testSecondaryView.cc)
target_link_libraries (testSecondaryView CORSIKAstackinterface CORSIKAthirdparty) # for catch2
CORSIKA_ADD_TEST(testSecondaryView) CORSIKA_ADD_TEST(testSecondaryView)
target_link_libraries (testSecondaryView CORSIKAstackinterface CORSIKAthirdparty) # for catch2
add_executable (testCombinedStack testCombinedStack.cc)
target_link_libraries (testCombinedStack CORSIKAstackinterface CORSIKAthirdparty) # for catch2
CORSIKA_ADD_TEST(testCombinedStack) CORSIKA_ADD_TEST(testCombinedStack)
target_link_libraries (testCombinedStack CORSIKAstackinterface CORSIKAthirdparty) # for catch2
...@@ -20,6 +20,5 @@ target_include_directories (CORSIKAunits ...@@ -20,6 +20,5 @@ target_include_directories (CORSIKAunits
install (FILES ${CORSIKAunits_HEADERS} DESTINATION include/${CORSIKAunits_NAMESPACE}) install (FILES ${CORSIKAunits_HEADERS} DESTINATION include/${CORSIKAunits_NAMESPACE})
# code testing # code testing
add_executable (testUnits testUnits.cc)
target_link_libraries (testUnits CORSIKAunits CORSIKAthirdparty) # for catch2
CORSIKA_ADD_TEST(testUnits) CORSIKA_ADD_TEST(testUnits)
target_link_libraries (testUnits CORSIKAunits CORSIKAthirdparty) # for catch2
...@@ -72,20 +72,16 @@ install ( ...@@ -72,20 +72,16 @@ install (
# -------------------- # --------------------
# code unit testing # code unit testing
add_executable (testCOMBoost testCOMBoost.cc) CORSIKA_ADD_TEST(testCOMBoost)
target_link_libraries ( target_link_libraries (
testCOMBoost testCOMBoost
CORSIKAutilities CORSIKAutilities
CORSIKAthirdparty # for catch2 CORSIKAthirdparty # for catch2
) )
add_executable (testCorsikaFenv testCorsikaFenv.cc) CORSIKA_ADD_TEST(testCorsikaFenv)
target_link_libraries ( target_link_libraries (
testCorsikaFenv testCorsikaFenv
CORSIKAutilities CORSIKAutilities
CORSIKAthirdparty # for catch2 CORSIKAthirdparty # for catch2
) )
CORSIKA_ADD_TEST(testCOMBoost)
add_test(testCorsikaFenv testCorsikaFenv)
...@@ -52,8 +52,7 @@ install ( ...@@ -52,8 +52,7 @@ install (
# -------------------- # --------------------
# code unit testing # code unit testing
#add_executable (testNullModel testNullModel.cc) #CORSIKA_ADD_TEST (testNullModel testNullModel.cc)
#target_link_libraries ( #target_link_libraries (
# testNullModel ProcessNullModel # testNullModel ProcessNullModel
# CORSIKAsetup # CORSIKAsetup
...@@ -61,5 +60,4 @@ install ( ...@@ -61,5 +60,4 @@ install (
# CORSIKAunits # CORSIKAunits
# CORSIKAthirdparty # for catch2 # CORSIKAthirdparty # for catch2
# ) # )
# CORSIKA_ADD_TEST(testNullModel)
...@@ -51,14 +51,12 @@ install ( ...@@ -51,14 +51,12 @@ install (
# -------------------- # --------------------
# code unit testing # code unit testing
#~ add_executable (ProcessHadronicElasticModel testProcessHadronicElasticModel.cc) # CORSIKA_ADD_TEST (testProcessHadronicElasticModel)
# target_link_libraries (
#~ target_link_libraries ( # testProcessHadronicElasticModel
#~ testProcessHadronicElasticModel # ProcessHadronicElasticModel
#~ ProcessHadronicElasticModel # CORSIKAsetup
#~ CORSIKAsetup # CORSIKAgeometry
#~ CORSIKAgeometry # CORSIKAunits
#~ CORSIKAunits # CORSIKAthirdparty # for catch2
#~ CORSIKAthirdparty # for catch2 # )
#~ )
#~ CORSIKA_ADD_TEST(testNullModel)
...@@ -50,8 +50,7 @@ install ( ...@@ -50,8 +50,7 @@ install (
# -------------------- # --------------------
# code unit testing # code unit testing
add_executable (testNullModel testNullModel.cc) CORSIKA_ADD_TEST(testNullModel)
target_link_libraries ( target_link_libraries (
testNullModel testNullModel
ProcessNullModel ProcessNullModel
...@@ -60,4 +59,3 @@ target_link_libraries ( ...@@ -60,4 +59,3 @@ target_link_libraries (
CORSIKAunits CORSIKAunits
CORSIKAthirdparty # for catch2 CORSIKAthirdparty # for catch2
) )
CORSIKA_ADD_TEST(testNullModel)
...@@ -48,10 +48,10 @@ install ( ...@@ -48,10 +48,10 @@ install (
# -------------------- # --------------------
# code unit testing # code unit testing
add_executable (testParticleCut CORSIKA_ADD_TEST(testParticleCut SOURCES
testParticleCut.cc testParticleCut.cc
${MODEL_HEADERS} ${MODEL_HEADERS}
) )
target_link_libraries ( target_link_libraries (
testParticleCut testParticleCut
...@@ -64,4 +64,3 @@ target_link_libraries ( ...@@ -64,4 +64,3 @@ target_link_libraries (
CORSIKAenvironment CORSIKAenvironment
CORSIKAthirdparty # for catch2 CORSIKAthirdparty # for catch2
) )
CORSIKA_ADD_TEST(testParticleCut)
...@@ -68,12 +68,12 @@ install ( ...@@ -68,12 +68,12 @@ install (
# -------------------- # --------------------
# code unit testing # code unit testing
add_executable (testPythia
CORSIKA_ADD_TEST(testPythia
SOURCES
testPythia.cc testPythia.cc
${MODEL_HEADERS} ${MODEL_HEADERS}
) )
target_link_libraries ( target_link_libraries (
testPythia testPythia
ProcessPythia ProcessPythia
...@@ -85,4 +85,3 @@ target_link_libraries ( ...@@ -85,4 +85,3 @@ target_link_libraries (
${PYTHIA8_LIBRARY} ${PYTHIA8_LIBRARY}
) )
CORSIKA_ADD_TEST(testPythia)
...@@ -100,10 +100,11 @@ install ( ...@@ -100,10 +100,11 @@ install (
# -------------------- # --------------------
# code unit testing # code unit testing
add_executable (testSibyll CORSIKA_ADD_TEST(testSibyll
SOURCES
testSibyll.cc testSibyll.cc
${MODEL_HEADERS} ${MODEL_HEADERS}
) )
target_link_libraries ( target_link_libraries (
testSibyll testSibyll
...@@ -114,4 +115,3 @@ target_link_libraries ( ...@@ -114,4 +115,3 @@ target_link_libraries (
CORSIKAunits CORSIKAunits
CORSIKAthirdparty # for catch2 CORSIKAthirdparty # for catch2
) )
CORSIKA_ADD_TEST(testSibyll)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment