Ignoring exit code of child process with ctest memcheck run using valgrind
I'm using memcheck in ctest to run valgrind on a test binary which may sometimes return a non-zero exit code. Valgrind will always return the exit code of its child process if it doesn't find any problems. (This occurs even with --error-exitcode=1.) This means that valgrind will return a non-zero exit code if the child process does, which our CI system is interpreting as a valgrind error. I have gotten around this in the past by using either an environment variable or argument to the child process that makes the child process always return 0.
Now that I am using ctest and memcheck instead of calling valgrind explicitly, I'm finding it difficult to set the environment variable or pass an argument to the child process only for memcheck tests. Is there a way of setting an environment variable or adding arguments to a test for just memcheck tests, while not affecting a normal test run?
Example usage of ctest:
ctest -D ExperimentalMemCheck
With MEMORYCHECK_OPTIONS = "--error-exitcode=1 --leak-check=full"