пятница, 21 августа 2015 г.

Death tests in GTest and Visual Leak Detector

If you've ever tried to employ automatic memory leaks tracking in GTest using VLD , then, it must be, you've already faced problems with Death Tests.

A short explanation of what happens with Death Tests - your process if forked and a child process starts to execute only the test, that contained death checks. If death condition is met, child process is killed and it's parent reads it's exit code - 0 means, completed successfully, other values - failure.

If you've done any memory allocations in your death test prior to a child process crash, VLD will treat them as memory leaks. So we have to completely disable VLD for child processes. I found, that the best way to achieve this would be to modify VLD, so it can read it's configuration from environment variables as well as from it's config file - vld.ini. Note, that you'll have to build VLD by yourself, since there were no releases since my contribution was accepted. You can find those changes here.

So now, when you initialize your tests, you'll have to disable VLD through environment variables, and the easiest way to do that is to call this:
SetEnvironmentVariable("VLD", "Off");
That's it! Child process will inherit environment variables of it's parent and wouldn't start any leaks monitoring in VLD.

Комментариев нет:

Отправить комментарий