How to test using CMake that a C++ application has no memory errors?
Asked Answered
M

1

10

I have a C++ project in CMake and I have implemented unit tests (using GoogleTest) as well as integration tests i.e. executing applications and checking the results using regexp e.g.

add_test(NAME MyAppIntegration.testRefitRunMse COMMAND my_application "--refit=true")
set_tests_properties(MyAppIntegration.testRefitRunMse PROPERTIES PASS_REGULAR_EXPRESSION "mse\\=1\\.53611e\\-05")

Now I would like to do the same as above but running the application to detect memory errors e.g. simply run ./my_application and check for memory errors with valgrind. How can I do that? Note that I am aware of ctest -D ExperimentalMemCheck and ctest -T memcheck but here I end up with the error Cannot find file DartConfiguration.tcl which seems related to the Dashboard configuration that I don't need.

Marvin answered 23/10, 2013 at 12:46 Comment(0)
M
4

OK I found a possible solution. Adding these lines to my CMakeLists.txt:

## valgrind
find_program(CTEST_MEMORYCHECK_COMMAND NAMES valgrind)
INCLUDE(Dart)

generates the needed DartConfiguration.tcl whatever that is, and then re-invoking:

ctest -T memcheck

runs all tests also checking for memory errors.

Marvin answered 23/10, 2013 at 12:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.