From 6ba7d035e8222c56521aa5161279009ba727d976 Mon Sep 17 00:00:00 2001 From: Hans Dembinski <hans.dembinski@gmail.com> Date: Thu, 25 Apr 2019 18:27:08 +0200 Subject: [PATCH] CORSIKA_ADD_TEST with configurable sanitizers, no address sanitizer on cascade_example --- CMakeModules/CorsikaUtilities.cmake | 27 ++++-- Documentation/Examples/CMakeLists.txt | 101 +++++++++++---------- Environment/CMakeLists.txt | 4 +- Framework/Cascade/CMakeLists.txt | 7 +- Framework/Geometry/CMakeLists.txt | 6 +- Framework/Logging/CMakeLists.txt | 6 +- Framework/Particles/CMakeLists.txt | 12 +-- Framework/ProcessSequence/CMakeLists.txt | 7 +- Framework/Random/CMakeLists.txt | 4 +- Framework/StackInterface/CMakeLists.txt | 9 +- Framework/Units/CMakeLists.txt | 3 +- Framework/Utilities/CMakeLists.txt | 8 +- Processes/NullModel/CMakeLists.txt | 4 +- Processes/Pythia/CMakeLists.txt | 9 +- Processes/Sibyll/CMakeLists.txt | 6 +- Processes/StackInspector/CMakeLists.txt | 4 +- Processes/TrackingLine/CMakeLists.txt | 4 +- Stack/NuclearStackExtension/CMakeLists.txt | 7 +- Stack/SuperStupidStack/CMakeLists.txt | 7 +- 19 files changed, 103 insertions(+), 132 deletions(-) diff --git a/CMakeModules/CorsikaUtilities.cmake b/CMakeModules/CorsikaUtilities.cmake index abd7bfcd..ece233ed 100644 --- a/CMakeModules/CorsikaUtilities.cmake +++ b/CMakeModules/CorsikaUtilities.cmake @@ -98,15 +98,28 @@ endmacro(CORSIKA_ADD_FILES_ABSOLUTE) # central macro to activate unit tests in cmake # -function (CORSIKA_ADD_TEST name) +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() + + 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}) file (MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/test_outputs/) - add_test (NAME ${name} COMMAND ${name} -o ${PROJECT_BINARY_DIR}/test_outputs/junit-${name}.xml -r junit) - # set(sanitize "address,implicit-integer-truncation,implicit-conversion,integer,alignment,bool,builtin,bounds,enum,float-cast-overflow,function,pointer-overflow,return,shift,shift-base,shift-exponent,unreachable,vla-bound,vptr") - # standard options not ideal, because we want to allow divide-by-zero for floats, - # but gcc-7 doesn't support all the detailed flags - set(sanitize "address,undefined") target_compile_options(${name} PRIVATE -fno-omit-frame-pointer -fsanitize=${sanitize} -fno-sanitize-recover=all) set_target_properties(${name} PROPERTIES LINK_FLAGS "-fsanitize=${sanitize}") - + add_test (NAME ${name} COMMAND ${name} -o ${PROJECT_BINARY_DIR}/test_outputs/junit-${name}.xml -r junit) endfunction (CORSIKA_ADD_TEST) diff --git a/Documentation/Examples/CMakeLists.txt b/Documentation/Examples/CMakeLists.txt index c677f3ab..80855d59 100644 --- a/Documentation/Examples/CMakeLists.txt +++ b/Documentation/Examples/CMakeLists.txt @@ -1,29 +1,20 @@ -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) +target_link_libraries (helix_example CORSIKAgeometry CORSIKAunits) +install (TARGETS helix_example DESTINATION share/examples) -add_executable (geometry_example geometry_example.cc) -target_compile_options(geometry_example PRIVATE -g) # do not skip asserts +CORSIKA_ADD_TEST (geometry_example) target_link_libraries (geometry_example CORSIKAgeometry CORSIKAunits) install (TARGETS geometry_example DESTINATION share/examples) -CORSIKA_ADD_TEST (geometry_example) -add_executable (logger_example logger_example.cc) -target_compile_options(logger_example PRIVATE -g) # do not skip asserts +CORSIKA_ADD_TEST (logger_example) target_link_libraries (logger_example CORSIKAunits CORSIKAlogging) install (TARGETS logger_example DESTINATION share/examples) -CORSIKA_ADD_TEST (logger_example) -add_executable (stack_example stack_example.cc) -target_compile_options(stack_example PRIVATE -g) # do not skip asserts +CORSIKA_ADD_TEST (stack_example) target_link_libraries (stack_example SuperStupidStack CORSIKAunits CORSIKAlogging) -CORSIKA_ADD_TEST (stack_example) -add_executable (cascade_example cascade_example.cc) -target_compile_options(cascade_example PRIVATE -g) # do not skip asserts +CORSIKA_ADD_TEST (cascade_example) target_link_libraries (cascade_example SuperStupidStack CORSIKAunits CORSIKAlogging CORSIKArandom @@ -42,10 +33,30 @@ target_link_libraries (cascade_example SuperStupidStack CORSIKAunits CORSIKAprocesssequence ) install (TARGETS cascade_example DESTINATION share/examples) -CORSIKA_ADD_TEST (cascade_example) -add_executable (boundary_example boundary_example.cc) -target_compile_options(boundary_example PRIVATE -g) # do not skip asserts +if (Pythia8_FOUND) + # address sanitizer is making this example too slow, so we only do "undefined" + CORSIKA_ADD_TEST (cascade_example SANITIZE "undefined") + target_link_libraries (cascade_example SuperStupidStack CORSIKAunits + CORSIKAlogging + CORSIKArandom + ProcessSibyll + CORSIKAcascade + ProcessEnergyLoss + ProcessStackInspector + ProcessTrackWriter + ProcessTrackingLine + CORSIKAprocesses + CORSIKAcascade + CORSIKAparticles + CORSIKAgeometry + CORSIKAenvironment + CORSIKAprocesssequence + ) + install (TARGETS cascade_example DESTINATION share/examples) +endif() + +CORSIKA_ADD_TEST (boundary_example) target_link_libraries (boundary_example SuperStupidStack CORSIKAunits CORSIKAlogging CORSIKArandom ProcessSibyll @@ -60,11 +71,9 @@ target_link_libraries (boundary_example SuperStupidStack CORSIKAunits CORSIKAlog CORSIKAprocesssequence ) install (TARGETS boundary_example DESTINATION share/examples) -CORSIKA_ADD_TEST (boundary_example) if (Pythia8_FOUND) - add_executable (cascade_proton_example cascade_proton_example.cc) - target_compile_options(cascade_proton_example PRIVATE -g) # do not skip asserts + CORSIKA_ADD_TEST (cascade_proton_example) target_link_libraries (cascade_proton_example SuperStupidStack CORSIKAunits CORSIKAlogging CORSIKArandom @@ -84,40 +93,36 @@ if (Pythia8_FOUND) CORSIKAenvironment CORSIKAprocesssequence ) - install (TARGETS cascade_proton_example DESTINATION share/examples) - CORSIKA_ADD_TEST (cascade_proton_example) endif() -add_executable (vertical_EAS vertical_EAS.cc) -target_compile_options(vertical_EAS PRIVATE -g) # do not skip asserts -target_link_libraries (vertical_EAS SuperStupidStack CORSIKAunits - CORSIKAlogging - CORSIKArandom - ProcessSibyll - CORSIKAcascade - ProcessEnergyLoss - ProcessTrackWriter - ProcessTrackingLine - ProcessHadronicElasticModel - ProcessParticleCut - ProcessStackInspector - CORSIKAprocesses - CORSIKAcascade - CORSIKAparticles - CORSIKAgeometry - CORSIKAenvironment - CORSIKAprocesssequence - ) -install (TARGETS vertical_EAS DESTINATION share/examples) -# CORSIKA_ADD_TEST (vertical_EAS) not yet... +if (Pythia8_FOUND) + # CORSIKA_ADD_TEST (vertical_EAS) not yet... + CORSIKA_ADD_TEST(vertical_EAS) + target_link_libraries (vertical_EAS SuperStupidStack CORSIKAunits + CORSIKAlogging + CORSIKArandom + ProcessSibyll + CORSIKAcascade + ProcessEnergyLoss + ProcessTrackWriter + ProcessTrackingLine + ProcessHadronicElasticModel + ProcessStackInspector + CORSIKAprocesses + CORSIKAcascade + CORSIKAparticles + CORSIKAgeometry + CORSIKAenvironment + CORSIKAprocesssequence + ) + install (TARGETS vertical_EAS DESTINATION share/examples) +endif() -add_executable (staticsequence_example staticsequence_example.cc) -target_compile_options(staticsequence_example PRIVATE -g) # do not skip asserts +CORSIKA_ADD_TEST (staticsequence_example) target_link_libraries (staticsequence_example CORSIKAprocesssequence CORSIKAunits CORSIKAgeometry CORSIKAlogging) install (TARGETS staticsequence_example DESTINATION share/examples) -CORSIKA_ADD_TEST (staticsequence_example) diff --git a/Environment/CMakeLists.txt b/Environment/CMakeLists.txt index 13fd4f1e..f32254e6 100644 --- a/Environment/CMakeLists.txt +++ b/Environment/CMakeLists.txt @@ -49,12 +49,10 @@ install ( # -------------------- # code unit testing -add_executable (testEnvironment testEnvironment.cc) - +CORSIKA_ADD_TEST(testEnvironment) target_link_libraries ( testEnvironment CORSIKAsetup CORSIKAenvironment CORSIKAthirdparty # for catch2 ) -CORSIKA_ADD_TEST(testGeometry) diff --git a/Framework/Cascade/CMakeLists.txt b/Framework/Cascade/CMakeLists.txt index cce17863..e4890d87 100644 --- a/Framework/Cascade/CMakeLists.txt +++ b/Framework/Cascade/CMakeLists.txt @@ -32,11 +32,7 @@ install ( # ---------------- # code unit testing -add_executable ( - testCascade - testCascade.cc - ) - +CORSIKA_ADD_TEST(testCascade) target_link_libraries ( testCascade # CORSIKAutls @@ -55,4 +51,3 @@ target_link_libraries ( CORSIKAunits CORSIKAthirdparty # for catch2 ) -CORSIKA_ADD_TEST(testCascade) diff --git a/Framework/Geometry/CMakeLists.txt b/Framework/Geometry/CMakeLists.txt index 510d8e39..6cda1a6f 100644 --- a/Framework/Geometry/CMakeLists.txt +++ b/Framework/Geometry/CMakeLists.txt @@ -67,20 +67,18 @@ install ( # -------------------- # code unit testing -add_executable (testGeometry testGeometry.cc) +CORSIKA_ADD_TEST(testGeometry) target_link_libraries ( testGeometry CORSIKAgeometry CORSIKAunits CORSIKAthirdparty # for catch2 ) -CORSIKA_ADD_TEST(testGeometry) -add_executable (testFourVector testFourVector.cc) +CORSIKA_ADD_TEST(testFourVector) target_link_libraries ( testFourVector CORSIKAgeometry CORSIKAunits CORSIKAthirdparty # for catch2 ) -CORSIKA_ADD_TEST(testFourVector) diff --git a/Framework/Logging/CMakeLists.txt b/Framework/Logging/CMakeLists.txt index 056aaad3..0926ad65 100644 --- a/Framework/Logging/CMakeLists.txt +++ b/Framework/Logging/CMakeLists.txt @@ -38,15 +38,11 @@ install ( # ---------------- # code unit testing -add_executable ( - testLogging - testLogging.cc - ) +CORSIKA_ADD_TEST (testLogging) target_link_libraries ( testLogging CORSIKAlogging CORSIKAthirdparty # for catch2 ) -CORSIKA_ADD_TEST (testLogging) diff --git a/Framework/Particles/CMakeLists.txt b/Framework/Particles/CMakeLists.txt index cde894b0..48f1b769 100644 --- a/Framework/Particles/CMakeLists.txt +++ b/Framework/Particles/CMakeLists.txt @@ -82,16 +82,14 @@ install ( # -------------------- # code unit testing -add_executable ( - testParticles - testParticles.cc - ${PROJECT_BINARY_DIR}/Framework/Particles/GeneratedParticleProperties.inc - ) - +CORSIKA_ADD_TEST(testParticles + SOURCES + testParticles.cc + ${PROJECT_BINARY_DIR}/Framework/Particles/GeneratedParticleProperties.inc +) target_link_libraries ( testParticles CORSIKAparticles CORSIKAunits CORSIKAthirdparty # for catch2 ) -CORSIKA_ADD_TEST(testParticles) diff --git a/Framework/ProcessSequence/CMakeLists.txt b/Framework/ProcessSequence/CMakeLists.txt index 33aad823..c1a4c778 100644 --- a/Framework/ProcessSequence/CMakeLists.txt +++ b/Framework/ProcessSequence/CMakeLists.txt @@ -45,11 +45,7 @@ target_link_libraries ( #-- -- -- -- -- -- -- -- #code unit testing -add_executable ( - testProcessSequence - testProcessSequence.cc - ) - +CORSIKA_ADD_TEST(testProcessSequence) target_link_libraries ( testProcessSequence CORSIKAsetup @@ -57,4 +53,3 @@ target_link_libraries ( CORSIKAprocesssequence CORSIKAthirdparty # for catch2 ) -CORSIKA_ADD_TEST(testProcessSequence) diff --git a/Framework/Random/CMakeLists.txt b/Framework/Random/CMakeLists.txt index bbbe8d32..b553d8c4 100644 --- a/Framework/Random/CMakeLists.txt +++ b/Framework/Random/CMakeLists.txt @@ -46,11 +46,9 @@ install ( # -------------------- # code unit testing -add_executable (testRandom testRandom.cc) - +CORSIKA_ADD_TEST(testRandom) target_link_libraries ( testRandom CORSIKArandom CORSIKAthirdparty # for catch2 ) -CORSIKA_ADD_TEST(testRandom) diff --git a/Framework/StackInterface/CMakeLists.txt b/Framework/StackInterface/CMakeLists.txt index fa0edbef..91b09a2e 100644 --- a/Framework/StackInterface/CMakeLists.txt +++ b/Framework/StackInterface/CMakeLists.txt @@ -34,14 +34,11 @@ install ( ) #code testing -add_executable (testStackInterface testStackInterface.cc) -target_link_libraries (testStackInterface CORSIKAstackinterface CORSIKAthirdparty) # for catch2 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) +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) +target_link_libraries (testCombinedStack CORSIKAstackinterface CORSIKAthirdparty) # for catch2 diff --git a/Framework/Units/CMakeLists.txt b/Framework/Units/CMakeLists.txt index 639c5cbd..226396ea 100644 --- a/Framework/Units/CMakeLists.txt +++ b/Framework/Units/CMakeLists.txt @@ -20,6 +20,5 @@ target_include_directories (CORSIKAunits install (FILES ${CORSIKAunits_HEADERS} DESTINATION include/${CORSIKAunits_NAMESPACE}) # code testing -add_executable (testUnits testUnits.cc) -target_link_libraries (testUnits CORSIKAunits CORSIKAthirdparty) # for catch2 CORSIKA_ADD_TEST(testUnits) +target_link_libraries (testUnits CORSIKAunits CORSIKAthirdparty) # for catch2 diff --git a/Framework/Utilities/CMakeLists.txt b/Framework/Utilities/CMakeLists.txt index 763c534f..5624ea4f 100644 --- a/Framework/Utilities/CMakeLists.txt +++ b/Framework/Utilities/CMakeLists.txt @@ -72,20 +72,16 @@ install ( # -------------------- # code unit testing -add_executable (testCOMBoost testCOMBoost.cc) - +CORSIKA_ADD_TEST(testCOMBoost) target_link_libraries ( testCOMBoost CORSIKAutilities CORSIKAthirdparty # for catch2 ) -add_executable (testCorsikaFenv testCorsikaFenv.cc) - +CORSIKA_ADD_TEST(testCorsikaFenv) target_link_libraries ( testCorsikaFenv CORSIKAutilities CORSIKAthirdparty # for catch2 ) -CORSIKA_ADD_TEST(testCOMBoost) -add_test(testCorsikaFenv testCorsikaFenv) diff --git a/Processes/NullModel/CMakeLists.txt b/Processes/NullModel/CMakeLists.txt index c3355c77..e84d6d92 100644 --- a/Processes/NullModel/CMakeLists.txt +++ b/Processes/NullModel/CMakeLists.txt @@ -50,8 +50,7 @@ install ( # -------------------- # code unit testing -add_executable (testNullModel testNullModel.cc) - +CORSIKA_ADD_TEST(testNullModel) target_link_libraries ( testNullModel ProcessNullModel @@ -60,4 +59,3 @@ target_link_libraries ( CORSIKAunits CORSIKAthirdparty # for catch2 ) -CORSIKA_ADD_TEST(testNullModel) diff --git a/Processes/Pythia/CMakeLists.txt b/Processes/Pythia/CMakeLists.txt index adc95309..ae646710 100644 --- a/Processes/Pythia/CMakeLists.txt +++ b/Processes/Pythia/CMakeLists.txt @@ -68,12 +68,12 @@ install ( # -------------------- # code unit testing -add_executable (testPythia + +CORSIKA_ADD_TEST(testPythia + SOURCES testPythia.cc ${MODEL_HEADERS} - ) - - +) target_link_libraries ( testPythia ProcessPythia @@ -85,4 +85,3 @@ target_link_libraries ( ${PYTHIA8_LIBRARY} ) -CORSIKA_ADD_TEST(testPythia) diff --git a/Processes/Sibyll/CMakeLists.txt b/Processes/Sibyll/CMakeLists.txt index 58b83f9b..46b19c50 100644 --- a/Processes/Sibyll/CMakeLists.txt +++ b/Processes/Sibyll/CMakeLists.txt @@ -100,10 +100,11 @@ install ( # -------------------- # code unit testing -add_executable (testSibyll +CORSIKA_ADD_TEST(testSibyll + SOURCES testSibyll.cc ${MODEL_HEADERS} - ) +) target_link_libraries ( testSibyll @@ -114,4 +115,3 @@ target_link_libraries ( CORSIKAunits CORSIKAthirdparty # for catch2 ) -CORSIKA_ADD_TEST(testSibyll) diff --git a/Processes/StackInspector/CMakeLists.txt b/Processes/StackInspector/CMakeLists.txt index f8297639..cbf216ca 100644 --- a/Processes/StackInspector/CMakeLists.txt +++ b/Processes/StackInspector/CMakeLists.txt @@ -52,8 +52,7 @@ install ( # -------------------- # code unit testing -add_executable (testStackInspector testStackInspector.cc) - +CORSIKA_ADD_TEST(testStackInspector) target_link_libraries ( testStackInspector ProcessStackInspector @@ -61,4 +60,3 @@ target_link_libraries ( CORSIKAunits CORSIKAthirdparty # for catch2 ) -CORSIKA_ADD_TEST(testStackInspector) diff --git a/Processes/TrackingLine/CMakeLists.txt b/Processes/TrackingLine/CMakeLists.txt index c8b95053..24dcabc8 100644 --- a/Processes/TrackingLine/CMakeLists.txt +++ b/Processes/TrackingLine/CMakeLists.txt @@ -47,11 +47,9 @@ install (FILES ${MODEL_HEADERS} DESTINATION include/${MODEL_NAMESPACE}) # #-- -- -- -- -- -- -- -- -- -- # #code unit testing -add_executable (testTrackingLine testTrackingLine.cc) - +CORSIKA_ADD_TEST(testTrackingLine) target_link_libraries ( testTrackingLine ProcessTrackingLine CORSIKAthirdparty # for catch2 ) -CORSIKA_ADD_TEST(testTrackingLine) diff --git a/Stack/NuclearStackExtension/CMakeLists.txt b/Stack/NuclearStackExtension/CMakeLists.txt index 6032c0b9..6a035375 100644 --- a/Stack/NuclearStackExtension/CMakeLists.txt +++ b/Stack/NuclearStackExtension/CMakeLists.txt @@ -31,11 +31,7 @@ install ( # ---------------- # code unit testing -add_executable ( - testNuclearStackExtension - testNuclearStackExtension.cc - ) - +CORSIKA_ADD_TEST(testNuclearStackExtension) target_link_libraries ( testNuclearStackExtension SuperStupidStack @@ -45,4 +41,3 @@ target_link_libraries ( CORSIKAunits CORSIKAthirdparty # for catch2 ) -CORSIKA_ADD_TEST(testNuclearStackExtension) diff --git a/Stack/SuperStupidStack/CMakeLists.txt b/Stack/SuperStupidStack/CMakeLists.txt index d787f0d0..777e65a3 100644 --- a/Stack/SuperStupidStack/CMakeLists.txt +++ b/Stack/SuperStupidStack/CMakeLists.txt @@ -31,11 +31,7 @@ install ( # ---------------- # code unit testing -add_executable ( - testSuperStupidStack - testSuperStupidStack.cc - ) - +CORSIKA_ADD_TEST(testSuperStupidStack) target_link_libraries ( testSuperStupidStack CORSIKAgeometry @@ -43,4 +39,3 @@ target_link_libraries ( CORSIKAunits CORSIKAthirdparty # for catch2 ) -CORSIKA_ADD_TEST(testSuperStupidStack) -- GitLab