diff --git a/CMakeModules/testing_cpp.cmake b/CMakeModules/testing_cpp.cmake index d5f7519ba3bea7e220dd813c2b8849e506719f80..d3b2ed02357436b8bb3adacd2eb6bb82694ab455 100644 --- a/CMakeModules/testing_cpp.cmake +++ b/CMakeModules/testing_cpp.cmake @@ -2,6 +2,8 @@ if (BUILD_TESTS) enable_testing() set(HIDRA2_MINIMUM_COVERAGE 70) find_package(Threads) + find_program(MEMORYCHECK_COMMAND valgrind) + set( MEMORYCHECK_COMMAND_OPTIONS "--trace-children=yes --leak-check=full --error-exitcode=1" ) endif () function(gtest target test_source_files test_libraries) @@ -20,7 +22,7 @@ function(gtest target test_source_files test_libraries) if (CMAKE_COMPILER_IS_GNUCXX) include(CodeCoverage) APPEND_COVERAGE_COMPILER_FLAGS() - set(COVERAGE_EXCLUDES '*/unittests/*') + set (COVERAGE_EXCLUDES '*/unittests/*') SETUP_TARGET_FOR_COVERAGE(NAME coverage-${target} EXECUTABLE test-${target} ${target}) add_test(NAME coveragetest-${target} COMMAND ${CMAKE_MODULE_PATH}/check_test.sh @@ -30,8 +32,16 @@ function(gtest target test_source_files test_libraries) set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} PARENT_SCOPE) set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} PARENT_SCOPE) endif () + + if (MEMORYCHECK_COMMAND) + set(memcheck_args ${MEMORYCHECK_COMMAND_OPTIONS}) + separate_arguments(memcheck_args) + add_test(NAME memcheck-${target} COMMAND ${MEMORYCHECK_COMMAND} ${memcheck_args} + ${CMAKE_CURRENT_BINARY_DIR}/test-${target}) + set_tests_properties(memcheck-${target} PROPERTIES LABELS "memcheck;all") + endif() endif () -endfunction() + endfunction() function(add_test_setup_cleanup exename) @@ -52,6 +62,5 @@ function(add_integration_test exename testname commandargs) LABELS "integration;all" FIXTURES_REQUIRED test-${exename}-fixture ) - endif () endfunction() diff --git a/producer/api/unittests/test_producer.cpp b/producer/api/unittests/test_producer.cpp index ea06e427054fb2d85c69b4c3714ec00e83d89026..6522702215d4ce9f78a110dba4983c71c9e1dc69 100644 --- a/producer/api/unittests/test_producer.cpp +++ b/producer/api/unittests/test_producer.cpp @@ -9,5 +9,6 @@ TEST(VERSION, VersionAboveZero) { TEST(CreateProducer, PointerIsNotNullptr) { hidra2::Producer* prod = hidra2::Producer::CreateProducer("127.0.0.1"); EXPECT_NE(prod, nullptr); + delete prod; } }