Hi, I've written an experimental Valgrind coverage tool, called VCov. To try it out, do this:
svn co svn://svn.valgrind.org/valgrind/branches/VCOV Then build in the usual way (see the README file). To run it, use 'valgrind --tool=exp-vcov <program>'. It's pretty simple. It just records, for each line of source code, how many instructions that were derived from that line were executed. It aggregates data from multiple executions. It all goes in a file called "vcov.out". To interpret the data, run this command: perl exp-vcov/vc_annotate vcov.out The output gives total, per-file and per-line coverage. An example: -------------------------------------------------------------------------------- Total coverage -------------------------------------------------------------------------------- 100.0% ( 9 of 9 lines) -------------------------------------------------------------------------------- Per-file coverage (files with the most unexecuted lines are shown first) -------------------------------------------------------------------------------- 100.0% ( 3 of 3 lines): /home/njn/grind/trunk9/b.h 100.0% ( 6 of 6 lines): /home/njn/grind/trunk9/a.c -------------------------------------------------------------------------------- /home/njn/grind/trunk9/b.h -------------------------------------------------------------------------------- -: 1:__inline__ int foo(void) 4: 2:{ 2: 3: return 0; 4: 4:} -------------------------------------------------------------------------------- /home/njn/grind/trunk9/a.c -------------------------------------------------------------------------------- -: 1:#include <stdio.h> -: 2:#include "b.h" -: 3: -: 4:int main(int argc, char* argv[]) 20: 5:{ 4: 6: if (argc < 2) 5: 7: printf("hello, world\n"); -: 8: else 4: 9: printf("hello, extended world\n"); -: 10: 2: 11: return foo(); 4: 12:} -------------------------------------------------------------------------------- Total coverage -------------------------------------------------------------------------------- 88.9% ( 8 of 9 lines) -------------------------------------------------------------------------------- Per-file coverage (files with the most unexecuted lines are shown first) -------------------------------------------------------------------------------- 83.3% ( 5 of 6 lines): /home/njn/grind/trunk9/a.c 100.0% ( 3 of 3 lines): /home/njn/grind/trunk9/b.h -------------------------------------------------------------------------------- /home/njn/grind/trunk9/b.h -------------------------------------------------------------------------------- -: 1:__inline__ int foo(void) 2: 2:{ 1: 3: return 0; 2: 4:} -------------------------------------------------------------------------------- /home/njn/grind/trunk9/a.c -------------------------------------------------------------------------------- -: 1:#include <stdio.h> -: 2:#include "b.h" -: 3: -: 4:int main(int argc, char* argv[]) 10: 5:{ 2: 6: if (argc < 2) 5: 7: printf("hello, world\n"); -: 8: else #####: 9: printf("hello, extended world\n"); -: 10: 1: 11: return foo(); 2: 12:} Non-executable lines are preceded with '-'. Lines that are executable but not executed are preceded with '######', so they are obvious. There are lots of shortcomings, but it gets the general idea across. Some things worth noting: - Files not compiled with -g won't have any results. - You can use the --fresh=yes option to overwrite any prior coverage data. - I plan to add the ability to change the name of the output file. - Results with --trace-children will be suspect, as there is no file locking done yet on the output file. - I hope to add some kind of branch coverage info, at least for the encountered branches. - If your program has a file for which no code is executed, it won't get included in the output. - I plan to add the ability to be more selective about which files get annotated (currently every file that has been executed and that can be found is annotated). Any comments are welcome. Nick ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Valgrind-developers mailing list Valgrind-developers@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/valgrind-developers