Using valgrind with cmake and jenkins

This post will explain how to use valgrind memcheck in cmake/ctest and publish the result in jenkins.

Jenkins requirements: Hudson CMake plugin and Vagrind plugin

First, you have to setup cmake to use valgrind when launching tests; the valgrind jenkins plugin requires the XML output format, so you have to told valgrind to use it:

option(MYPROJECT_ENABLE_MEMCHECK "enable valgrind memcheck report" false)

if(MYPROJECT_ENABLE_MEMCHECK)

find_program( CTEST_MEMORYCHECK_COMMAND valgrind )
set( CTEST_MEMORYCHECK_COMMAND_OPTIONS
  "--trace-children=yes --leak-check=full --xml=yes --xml-file=valgrind-%p.xml" )

function(add_test name binary)
set(memcheck_command "${CTEST_MEMORYCHECK_COMMAND} ${CTEST_MEMORYCHECK_COMMAND_OPTIONS}")
separate_arguments(memcheck_command)
_add_test(${name}_memcheck ${memcheck_command} ${binary} ${ARGN})
endfunction(add_test)

function(set_memcheck_test_properties name)
set_tests_properties(${name}_memcheck ${ARGN})
endfunction(set_memcheck_test_properties)

endif(MYPROJECT_ENABLE_MEMCHECK)

enable_testing()

Now, in your jenkins project, you should configure cmake to use the memcheck variable: -DMYPROJECT_ENABLE_MEMCHECK=ON

Then add a Publish valgrind results action in the post build action section. Configure the Report Pattern to **/valgrind-*.xml

That’s all. Now each build will include a Valgrind results section.

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload the CAPTCHA.