Is there any documentation how to setup CTest with AddressSanitizer or any other sanitizer? I’ve searched for examples on GitHub, but none of them is really helpful. Most devs use just valgrind with ctest or set their on custom targets.
CMake version: 3.17
CTest command used: ctest --output-on-failure -D ExperimentalMemCheck
ASAN settings I’m using in CMakeLists.txt:
These only apply in CTest scripts; they have no effect in CMakeLists.txt. There, you need to use MEMORYCHECK_TYPE and MEMORYCHECK_SANITIZER_OPTIONS (as per the DartConfiguration.tcl.in template file).
Hmm. This seems like a defect in CMake. It shouldn’t require a memcheck command if an instrumented build is being used. It seems that I’m getting lucky where valgrind ends up being used as the command because it happens to be installed. Please file an issue (in the meantime, you can just set the command to /usr/bin/false or something.
To use one of the sanitizers, set MEMORYCHECK_TYPE to one of the following strings (MEMORYCHECK_COMMAND will then be ignored):
AddressSanitizer
LeakSanitizer
MemorySanitizer
ThreadSanitizer
UndefinedBehaviorSanitizer
I have some recollection that you may also need to add the -fno-omit-frame-pointer compiler flag as well (at least in some cases), but I don’t recall the details.
Edit: Just saw your earlier reply where you said you tried this. If it isn’t working for you, it would be interesting if you could try an earlier CMake version. It’s possible there has been a regression.
@craig.scott@ben.boeckel to allow better understanding of problem I’ve setup CI verifivation like you’ve asked. I’ve tested latest minor version of all cmake major version starting from 3.1.3. With unset MEMORYCHECK_COMMAND, MEMORYCHECK_COMMAND set to "" and MEMORYCHECK_COMMAND set to "/usr/bin/false". Each job prints DartConfiguration.tcl content and performs test if /usr/bin/false exists in file system. Results are the same in all cases:
Memory checker (MemoryCheckCommand) not set, or cannot find the specified program.
Errors while running CTest
Additionally I’ve check CTest sources and couldn’t find regression test validating CTest behaviour with sanitizers, so I guess there is some mistake in CTest source code. I’ve tried simple code analysis with grep and find and couldn’t find “CMakeCommand” defined from https://gitlab.kitware.com/cmake/cmake/-/blob/master/Source/CTest/cmCTestMemCheckHandler.cxx line 493. Also other handlers are obtaining ActualCommand using other methods.
I made mistake in tests with dummy app. /usr/bin/false was not present in CI vm. I’ve repeated test with /bin/false instead and added check for availability of passed application on filesystem.
Results are the same .
Changes made: hxxps://bitbucket.org/shaqmz/cmake_sanitizer/commits/6a0f6f7afb362fed27b3825d8a29a585cc37c806 (please change xx -> tt)
Since this currently looks like a bug, let’s keep discussion in the gitlab issue from this point rather than duplicating comments in both places. We can record any final outcome back here at the end once we resolve what’s happening.