Is there anyway to merge two gcov files into one

jimwan picture jimwan · Mar 25, 2013 · Viewed 7.1k times · Source

I am using gcov for coverage test in macosx platform. I finish the configuration for xcode by set:

1. Build Settings ==> Generate Test Coverage Files == Yes
2. Build Settings ==> Instrument Progaram Flow == Yes
3. Build Phases ==> Link Binary with library ==> add "libprofile_rt.dylib"

Then generate the files "Test.d, Test.dia, Test.gcno, Test.gcda, Test.o" Then i use gcov-4.2 -b Test.gcno command to generate the Test.m.gcov file (this is what i want), but next time when i run test cases again, the files "Test.d, Test.dia, Test.gcno, Test.gcda, Test.o" will be generated again, and the data will be reset.

So I have two questions:

  1. Is there any way for me to make the data in these coverage files accumulated so that i can run so many times of my project and then generate files at the end.
  2. If the #1 is hopeless, could you tell me how to merge two Test.gcno files (generated by two times' running) into one. I try gcov in terminal, below are the options for gcov command:

    gcov-4.2 -help
    Usage: gcov [OPTION]... SOURCEFILE
    
    Print code coverage information.
    
      -h, --help                      Print this help, then exit
      -v, --version                   Print version number, then exit
      -a, --all-blocks                Show information for every basic block
      -b, --branch-probabilities      Include branch probabilities in output
      -c, --branch-counts             Given counts of branches taken
                                        rather than percentages
      -n, --no-output                 Do not create an output file
      -l, --long-file-names           Use long output file names for included
                                        source files
      -f, --function-summaries        Output summaries for each function
      -o, --object-directory DIR|FILE Search for object files in DIR or called FILE
      -p, --preserve-paths            Preserve all pathname components
      -u, --unconditional-branches    Show unconditional branch counts too
    
    For bug reporting instructions, please see:
    <URL:http://developer.apple.com/bugreporter>.
    

Thanks for all your help in advance

Answer

hberndt picture hberndt · Apr 27, 2013

The usual workflow for gcov is

  1. Compile and link with coverage support (-fprofile-arcs -ftest-coverage)
  2. Run your executables, possibly multiple times, possibly with different parameters / settings. This will create accumulative usage information in the .gcda files
  3. Invoke gcov to get coverage statistics in a human-readable format (.gcov)

So basically, successive runs of the application will result in accumulated coverage statistics. It's just that these accumulations will take place in the .gcda files, not the .gcov files, so you have to re-run gcov each time you want to see updated statistics.