开发者

Is there a best way to automate the memory leak test?

开发者 https://www.devze.com 2022-12-21 05:21 出处:网络
We are in a proces开发者_StackOverflow社区s of automating the most of known issues(for regression testing) that can be automated. However, we do find memory leaks through third party software. However

We are in a proces开发者_StackOverflow社区s of automating the most of known issues(for regression testing) that can be automated. However, we do find memory leaks through third party software. However, I do not know the way to automate the memory leak test that we found and fixed them.

Is there any advise on it?


Generally the best way is to only do the thing that you think causes the leak, and, well, watch the memory only go up.

But of course, you need to test that doing "nothing" over that period of time, doesn't also cause memory to go up.

Because of this, and the generally confusing complicated nature of tracking down leaks (especially in 3rd party software) it can be pretty hard to write an automated test for it.

It depends on your environment, really. Perhaps it is possible to build an environment where you always start from scratch (i.e. a virtual machine) but it may not be possible.

Personally, I'd have a seperate, but still partially-automated, system for detecting the leaks, and run it "every so often". If it's 3rd party, you'll only need to do it when you add a new version of the software.


Memory leaks become obvious when you run the program for a long time. Setup a test machine for long running tests, where the program is started once and then runs for several days without a restart. Have a defined set of regression tests, which is executed over and over again. When the memory consumption reaches some threshold the tests are considered as a failure.

Example: For a web application, you start it and then fire up regression tests (which simulates user input) over and over again for several days. Script these tests and add it to a continuous integration environment.

This is a different approach than usual regression tests, where you just start the program one time for each tests or test suite.


Some tools really make detecting memory leaks easy (like valgrind)

What you could do is simulate an "intensive" input on your program (via a script shell) and parse the result of valgrind to see if there were any memory leaks. You could also use it yourself intensively (and for a long time). Valgrind will tell you at the program's end if any memory leaked (and even approximately where it leaked !)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号