Search code examples
cmakevalgrindctest

cmake/ctest with valgrind output as xml


I am currently checking my unittests with valgrind by using

ctest -T memcheck

I would like to create an XML output by setting

MEMORYCHECK_COMMAND_OPTIONS="--xml=yes --xml-file=valgrind.xml

Now the problem is that i only get the logfile for the last testcase run. All others are overwritten.

What I need, but have not found in the documentation is to add the Testname or the Testnumber to the xml logfile name.

Any ideas how to get them?


Solution

  • Valgrind --log-file or --xml-file arguments can use %p to insert a pid nr or use %q{FOO} to insert the environment variable FOO value in the file name.

    So, if you can put the Testname or Testnumber in an environment variable, %q is the best. Otherwise, if you do not have too many tests, %p might help. if pid nr is not recycled too quickly when you run your tests.

    See https://www.valgrind.org/docs/manual/manual-core.html#opt.log-file for more info.