From b2ce6e0167b4e1b9c7b970081e0938184d953782 Mon Sep 17 00:00:00 2001 From: Sergey Yakubov <sergey.yakubov@desy.de> Date: Fri, 8 Dec 2017 10:33:01 +0100 Subject: [PATCH] added valgrind memory check --- CMakeModules/testing_cpp.cmake | 10 ++++++++++ common/cpp/src/system_io.cpp | 8 ++++---- producer/api/unittests/test_producer.cpp | 1 + 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CMakeModules/testing_cpp.cmake b/CMakeModules/testing_cpp.cmake index 7310ec827..c0d74248b 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) @@ -30,5 +32,13 @@ 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() diff --git a/common/cpp/src/system_io.cpp b/common/cpp/src/system_io.cpp index 4d9166497..96bee7116 100644 --- a/common/cpp/src/system_io.cpp +++ b/common/cpp/src/system_io.cpp @@ -3,17 +3,17 @@ #include <system_wrappers/system_io.h> int hidra2::SystemIO::open(const char *__file, int __oflag) { - return ::open(__file, __oflag); + return ::open(__file, __oflag); } int hidra2::SystemIO::close(int __fd) { - return ::close(__fd); + return ::close(__fd); } ssize_t hidra2::SystemIO::read(int __fd, void *buf, size_t count) { - return ::read(__fd, buf, count); + return ::read(__fd, buf, count); } ssize_t hidra2::SystemIO::write(int __fd, const void *__buf, size_t __n) { - return ::write(__fd, __buf, __n); + return ::write(__fd, __buf, __n); } diff --git a/producer/api/unittests/test_producer.cpp b/producer/api/unittests/test_producer.cpp index ea06e4270..652270221 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; } } -- GitLab