Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to let CMake / CTest memcheck exit with status code 1 on failure?

I want to use ctest to run my tests with valgrind. Thus I have written the following in my cmake file:

include(CTest)

find_program(MEMORYCHECK_COMMAND valgrind)
set(MEMORYCHECK_COMMAND_OPTIONS "--leak-check=full --error-exitcode=1")
set(MEMORYCHECK_SUPPRESSIONS_FILE "${PROJECT_SOURCE_DIR}/.valgrind-suppressions")

This seems to work. When I run ctest -D ExperimentalMemCheck . on a leaking program it shows me that it has found memory leaks, however does not exit with status != 0.

How can I get a exit code 1 on failure?

like image 222
Arwed Mett Avatar asked Mar 24 '19 08:03

Arwed Mett


1 Answers

The critical thing is that you put set(MEMORYCHECK_COMMAND_OPTIONS "--error-exitcode=1") ABOVE the include(CTest) call. The variable is apparently only taken into account when first including CTest and has no effect when setting it after including CTest.

When then calling ctest -T memcheck, the command correctly exits with a non-zero exit status.

Also see this questions for reference: How to pass arguments to memcheck with ctest?

like image 65
nioncode Avatar answered Sep 18 '22 05:09

nioncode