[Insight-developers] code coverage and memory leak scripts
Matt McCormick
matt.mccormick at kitware.com
Tue Aug 9 12:17:28 EDT 2011
Hi Brian,
Thanks for the great explanation. Any suggestions you have are welcome.
One thing people might not understand, is that the analysis requires
using GCC (with those specific flags) and installing the 'lcov'
package.
Here is a patch to improve the help output:
http://review.source.kitware.com/#change,2415
Thanks,
Matt
On Mon, Aug 8, 2011 at 8:33 PM, brian avants <stnava at gmail.com> wrote:
> hi matt
>
> i tried that script a while back and couldn't get it work ... below
> are the instructions i put together. not sure if it's still an issue,
> though.
>
> Instructions for computing a graphical summary of code coverage.
>
> Prerequisites: you need gcov & its genhtml + geninfo
>
> First, make sure you get rid of old coverage files:
>
> find ./ -name '*.gcda*' -delete
> find ./ -name '*.gcno' -delete
>
> From documentation: "The .gcno file is generated when the source file
> is compiled with the GCC -ftest-coverage option. It contains
> information to reconstruct the basic block graphs and assign source
> line numbers to blocks.
>
> The .gcda file is generated when a program
> containing object files built with the GCC -fprofile-arcs option is
> executed. A separate .gcda file is created for each object file
> compiled with this option. It contains arc transition counts, and some
> summary information."
>
> In cmake, add these options to CMAKE_C_FLAGS_DEBUG and CMAKE_CXX_FLAGS_DEBUG
>
> -O0 -fprofile-arcs -ftest-coverage
>
> then compile in DEBUG mode.
>
> make ITK-RegistrationRefactoringTestDriver
>
> you may want to, at this point, clear your execution files:
>
> find ./ -name '*.gcda*' -delete
>
> now run one of your tests. e.g. from the build directory to get new
> gcda files :
>
> ./bin/ITK-RegistrationRefactoringTestDriver
> itkDemonsImageToImageObjectRegistrationTest r62slice.nii.gz
> r85slice.nii.gz XXX.nii.gz 100 1 100
>
> for me this is next to ITK/ so my directories are as so:
>
> Brian-Avantss-MacBook-Pro:RegistrationRefactoring brianavants$ pwd
> /Users/brianavants/code/RegistrationRefactoring
> Brian-Avantss-MacBook-Pro:RegistrationRefactoring brianavants$ ls
> ITK4_topics bin
>
> and I call the test from within bin.
>
> Now we are ready to compute the code coverage.
>
> 1. generate info files.
>
> geninfo --compat-libtool --no-checksum .
>
> 2. now focus on the test you want ... here, i look for the demons
> gcda info file (where the coverage data lives) and focus on that.
>
> find ./ -name *emons**gcda.info
>
> F=.//Modules/Registration/Refactoring/test/CMakeFiles/ITK-RegistrationRefactoringTestDriver.dir/itkDemonsImageToImageObjectRegistrationTest.cxx.gcda.info
> F=.//Modules/Registration/Refactoring/test/CMakeFiles/ITK-RegistrationRefactoringTestDriver.dir/itkDemonsImageToImageObjectMetricTest.cxx.gcda.info
>
> # make a directory for output and generate the html view:
> mkdir lcov-output/
> genhtml -o lcov-output/ $F
>
> now go into the lcov-output directory and open index.html.
>
> or for everything (didnt check this command)
>
> all=` find ./ -iname '*\.gcda\.info' `
> genhtml -o lcov-output/ $all
>
> # done!
>
>
> Please let me know if this does/does not work for you.
>
> b.a.
>
>
>
> brian
>
>
>
>
> On Mon, Aug 8, 2011 at 2:49 PM, Matt McCormick
> <matt.mccormick at kitware.com> wrote:
>> Hi all,
>>
>> Some recently added scripts to the source tree may be useful in your
>> development adventures.
>>
>> They are:
>>
>> ./Utilities/Maintenance/computeCodeCoverageLocallyForOneTest.sh
>> ./Utilities/Maintenance/runValgrind.sh
>>
>> They allow you to run code coverage or memory leak coverage on a
>> single test or a set of tests specified with a ctest regular
>> expression (-R). The output is easily digested HTML. Usage for these
>> scripts can be found by passing '--help'.
>>
>> ./Utilities/Maintenance/runValgrind.sh --help
>>
>> How to use this script:
>>
>> 0) Use Linux or Mac, install
>> - valgrind
>> - xsltproc
>>
>> 1) Compile ITK with RelWithDebInfo CMAKE_BUILD_TYPE
>>
>> 2) cd into the ITK binary build directory
>>
>> 3) From the TOP of the binary directory type the "ctest" expression that
>> set(DOC "
>> selects the tests that you want to perform memory checking on.
>>
>> For example:
>>
>> ctest -R itkHDF5ImageIOTest -N
>>
>> This will print the tests selected by the regular expression but not run the
>> tests (-N option).
>>
>> 4) Type the path to this script in the ITK source tree and add the
>> select expression
>> from step 3 above.
>>
>> For example:
>>
>> ~/src/ITK/Utilities/Maintenance/runValgrind.sh -R itkHDF5ImageIOTest
>>
>> This will run the selected tests under valgrind and generate HTML that can be
>> opened with your favorite browser. The HTML is written to ./memcheck_index.html
>> To open:
>>
>> In Linux, you can do firefox ./memcheck_index.html
>> In Mac, you can do open ./memcheck_index.html
>>
>> These tools should augment the dashboard output, and help us reach our
>> goals of 84% or better test coverage, and zero memory leaks.
>>
>> Happy hacking,
>> Matt
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Kitware offers ITK Training Courses, for more information visit:
>> http://kitware.com/products/protraining.html
>>
>> Please keep messages on-topic and check the ITK FAQ at:
>> http://www.itk.org/Wiki/ITK_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.itk.org/mailman/listinfo/insight-developers
>>
>
More information about the Insight-developers
mailing list