Search code examples
cmakevalgrind

Why I cannot get Valgrind diagnostic information with CMake?


I am now running CTest with or without Valgrind in Ubuntu Linux. Firstly, I set up a CMakeLists.txt script to enable testing:

enable_testing()
include(CTest)
if(UNIX)
  set(CTEST_MEMORYCHECK_COMMAND, "usr/bin/valgrind")
  set(CTEST_MEMORYCHECK_COMMAND_OPTIONS, "--trace-children=yes --leak-check=full")
endif()

add_test(NAME test
        WORKING_DIRECTORY ${my_outputdirectory}
        COMMAND test_exe)

When I run the test without valgrind, I use the following command:

cmake -G "CodeBlocks - Unix Makefiles"
ctest -D ExperimentalBuild  
ctest -R test -D ExperimentalTest  

That works fine. However, when I run the following command to invoke valgrind:

 cmake -G "CodeBlocks - Unix Makefiles"
    ctest -D ExperimentalBuild  
    ctest -R test -D ExperimentalMemChec

the following message appear:

--Processing memory checking output:
Memory checking results:

This is definitely not the diagnostic information I expect. I was wondering what I should do next. Thanks!

EDIT: Later on, I find that the diagnostic information can be available only in the case where the memory leak happens. However, the diagnostic information is very vague in the sense that the location where the error occurs is not given. How could I obtain more detailed information?


Solution

  • I use a python script which parses my memory leaks from valgrind it is available here.

    In CMake I use the following command to add a memory test:

    ADD_TEST(testName ${Test_Dir}/memtest.py ${CMAKE_CURRENT_BINARY_DIR}/testExecutable ${CMAKE_BINARY_DIR})
    

    Such that I do not need to parse the memory leak errors direct in cmake. The python script simply executes a memory check with valgrind on the executable and returns an error if a leak was found. If a leak was found the test then fails otherwise it passes. Hope this might help you.