diff --git a/cmake/GTestHelper.cmake b/cmake/GTestHelper.cmake index 26cc3ad8f..7cbbca96e 100644 --- a/cmake/GTestHelper.cmake +++ b/cmake/GTestHelper.cmake @@ -1,5 +1,5 @@ ################################################################################ -# Copyright (C) 2017-2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH # +# Copyright (C) 2017-2023 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH # # # # This software is distributed under the terms of the # # GNU Lesser General Public Licence (LGPL) version 3, # @@ -20,6 +20,7 @@ # [DEPENDS dep1 [dep2 ...]] # [LINKS linklib1 [linklib2 ...] # [INCLUDES dir1 [dir2 ...] +# [ENVIRONMENT var1=op:val1[;var2=op:val2 ...]] # [TIMEOUT seconds] # [RUN_SERIAL ON/OFF]) # @@ -56,7 +57,7 @@ function(add_testsuite suitename) cmake_parse_arguments(testsuite "" "TIMEOUT;RUN_SERIAL" - "SOURCES;LINKS;DEPENDS;INCLUDES;DEFINITIONS" + "SOURCES;LINKS;DEPENDS;INCLUDES;DEFINITIONS;ENVIRONMENT" ${ARGN} ) @@ -77,6 +78,9 @@ function(add_testsuite suitename) if(testsuite_DEFINITIONS) target_compile_definitions("${target}" PUBLIC ${testsuite_DEFINITIONS}) endif() + if(testsuite_ENVIRONMENT AND CMAKE_VERSION VERSION_GREATER_EQUAL 3.22) + set(env "ENVIRONMENT_MODIFICATION" ${testsuite_ENVIRONMENT}) + endif() if(BUILD_TIDY_TOOL AND RUN_FAIRMQ_TIDY) fairmq_target_tidy(TARGET ${target}) endif() @@ -97,6 +101,7 @@ function(add_testsuite suitename) TEST_PREFIX ${suitename}. PROPERTIES RUN_SERIAL ${testsuite_RUN_SERIAL} TIMEOUT ${testsuite_TIMEOUT} + ${env} ) list(APPEND ALL_TEST_TARGETS ${target}) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 11b7de359..629cc4de3 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -20,7 +20,7 @@ function(add_example) ) if(ARG_UNPARSED_ARGUMENTS) - message(FATAL_ERROR "Unexpected unparsed arguments: ${A_UNPARSED_ARGUMENTS}") + message(FATAL_ERROR "Unexpected unparsed arguments: ${ARG_UNPARSED_ARGUMENTS}") endif() if(ARG_NAME) @@ -29,9 +29,14 @@ function(add_example) message(FATAL_ERROR "NAME arg is required") endif() - if(ARG_DEVICES) + if(ENABLE_SANITIZER_LEAK AND CMAKE_VERSION VERSION_GREATER_EQUAL 3.22) + get_filename_component(lsan_supps "${CMAKE_SOURCE_DIR}/test/leak_sanitizer_suppressions.txt" ABSOLUTE) + set(lsan_options "LSAN_OPTIONS=set:suppressions=${lsan_supps}") + endif() + + if(ARG_DEVICE) set(exe_targets) - foreach(device IN LISTS ARG_DEVICES) + foreach(device IN LISTS ARG_DEVICE) set(exe "${exe_prefix}-${name}-${device}") list(APPEND exe_targets ${exe}) add_executable(${exe} "${device}.cxx") @@ -73,6 +78,9 @@ function(add_example) set(test "${testsuite}.${name}.${transport}") add_test(NAME ${test} COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${test_script} ${transport}) set_tests_properties(${test} PROPERTIES TIMEOUT "30") + if(lsan_options) + set_tests_properties(${test} PROPERTIES ENVIRONMENT_MODIFICATION ${lsan_options}) + endif() else() foreach(transport IN LISTS transports) if(ARG_VARIANT) @@ -80,11 +88,17 @@ function(add_example) set(test "${testsuite}.${name}.${variant}.${transport}") add_test(NAME ${test} COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${test_script} ${transport} ${variant}) set_tests_properties(${test} PROPERTIES TIMEOUT "30") + if(lsan_options) + set_tests_properties(${test} PROPERTIES ENVIRONMENT_MODIFICATION ${lsan_options}) + endif() endforeach() else() set(test "${testsuite}.${name}.${transport}") add_test(NAME ${test} COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${test_script} ${transport}) set_tests_properties(${test} PROPERTIES TIMEOUT "30") + if(lsan_options) + set_tests_properties(${test} PROPERTIES ENVIRONMENT_MODIFICATION ${lsan_options}) + endif() endif() endforeach() endif() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index d02ddef87..a306dcae8 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -20,6 +20,11 @@ if(definitions) set(definitions DEFINITIONS ${definitions}) endif() +if(ENABLE_SANITIZER_LEAK) + get_filename_component(lsan_supps "${CMAKE_CURRENT_SOURCE_DIR}/leak_sanitizer_suppressions.txt" ABSOLUTE) + set(environment ENVIRONMENT "LSAN_OPTIONS=set:suppressions=${lsan_supps}") +endif() + add_testhelper(runTestDevice SOURCES helper/runTestDevice.cxx @@ -63,6 +68,7 @@ add_testsuite(Protocols ${CMAKE_CURRENT_BINARY_DIR} TIMEOUT 20 ${definitions} + ${environment} ) add_testsuite(Parts @@ -76,6 +82,7 @@ add_testsuite(Parts ${CMAKE_CURRENT_SOURCE_DIR}/parts ${CMAKE_CURRENT_BINARY_DIR} TIMEOUT 20 + ${environment} ) add_testsuite(Message @@ -89,6 +96,7 @@ add_testsuite(Message ${CMAKE_CURRENT_BINARY_DIR} TIMEOUT 20 ${definitions} + ${environment} ) add_testsuite(Region @@ -103,6 +111,7 @@ add_testsuite(Region ${CMAKE_CURRENT_BINARY_DIR} TIMEOUT 20 ${definitions} + ${environment} ) add_testsuite(Device @@ -125,6 +134,7 @@ add_testsuite(Device ${CMAKE_CURRENT_SOURCE_DIR}/device ${CMAKE_CURRENT_BINARY_DIR} TIMEOUT 20 + ${environment} ) set(VERSION_MAJOR 1) @@ -170,6 +180,7 @@ add_testsuite(Plugins ${CMAKE_CURRENT_BINARY_DIR} DEPENDS FairMQPlugin_test_dummy fairmq-plugin-test_dummy2 TIMEOUT 20 + ${environment} ) add_testsuite(PluginsPrelinked @@ -181,6 +192,7 @@ add_testsuite(PluginsPrelinked INCLUDES ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} TIMEOUT 20 + ${environment} ) add_testsuite(PluginServices @@ -194,6 +206,7 @@ add_testsuite(PluginServices INCLUDES ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} TIMEOUT 20 + ${environment} ) add_testsuite(EventManager @@ -205,6 +218,7 @@ add_testsuite(EventManager INCLUDES ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} TIMEOUT 20 + ${environment} ) add_testsuite(Properties @@ -217,6 +231,7 @@ add_testsuite(Properties INCLUDES ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} TIMEOUT 20 + ${environment} ) # add_testsuite(StateMachine @@ -239,6 +254,7 @@ add_testsuite(Tools INCLUDES ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} TIMEOUT 20 + ${environment} ) add_testsuite(Channel @@ -250,6 +266,7 @@ add_testsuite(Channel INCLUDES ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} TIMEOUT 20 + ${environment} ) add_testsuite(Transport @@ -264,6 +281,7 @@ add_testsuite(Transport ${CMAKE_CURRENT_BINARY_DIR} TIMEOUT 20 ${definitions} + ${environment} ) add_testsuite(Poller @@ -276,6 +294,7 @@ add_testsuite(Poller ${CMAKE_CURRENT_BINARY_DIR} TIMEOUT 20 ${definitions} + ${environment} ) add_testsuite(MemoryResources @@ -288,4 +307,5 @@ add_testsuite(MemoryResources ${CMAKE_CURRENT_BINARY_DIR} TIMEOUT 20 ${definitions} + ${environment} ) diff --git a/test/leak_sanitizer_suppressions.txt b/test/leak_sanitizer_suppressions.txt new file mode 100644 index 000000000..00dee9dea --- /dev/null +++ b/test/leak_sanitizer_suppressions.txt @@ -0,0 +1 @@ +leak:zmq_msg_init_size