Is it overkill to run the unit test with Valgrind? Is it overkill to run the unit test with Valgrind? c c

Is it overkill to run the unit test with Valgrind?


We certainly do - it's much easier to run valgrind against the unit tests than with the full program.

Also any memory errors are localised to the area of code the unit test is testing which makes it easier to fix.

Plus checking that you've fixed it is easier - because you're running the unit test not a more complicated test against your full program.

If you're running valgrind in an automated fashion you probably want --error-exitcode=<number> [default: 0]

Specifies an alternative exit code to return if Valgrind reported any errors in the run. When set to the default value (zero), the return value from Valgrind will always be the return value of the process being simulated. When set to a nonzero value, that value is returned instead, if Valgrind detects any errors. This is useful for using Valgrind as part of an automated test suite, since it makes it easy to detect test cases for which Valgrind has reported errors, just by inspecting return codes.

http://valgrind.org/docs/manual/manual-core.html#manual-core.erropts


As Douglas Leeder said, it is well worth running your unit tests with any diagnostic software that you can lay hands that will ensure that it really does work as you expect. That includes not abusing memory, so using valgrind is a good idea.

You really want your unit tests to prove that your code works.

You don't have to run them under valgrind all the time - but it should be as trivial as possible to do so, and you should do so periodically (say after big changes).