HowTo: Using gcov (the GNU coverage tool) with LMDZ

De LMDZPedia
Aller à : navigation, rechercher


If you want a summary of the lines (and branches) in your code that are actually executed, you can use the GNU [coverage tool]. This entails the following three steps:

  1. compiling your code with the right options
  2. running the code to output the statistics that gcov will analyze
  3. running gcov on the data files created in the previous step to analyze the code coverage

Running gcov on LMDZ

We will be using [gcovr] a utility using gcov and providing different types of outputs

Compiling LMDZ

You will need to add the following flags to your compilation flags in the arch.fcm.file:

 %BASE_FFLAGS          -cpp -ffree-line-length-0 -fdefault-real-8 -DNC_DOUBLE -pg --coverage -fprofile-arcs -ftest-coverage -fprofile-abs-path
 ....
 %BASE_LD              -Wl,-rpath=/data/fairhead/Test_coverage/LMDZ20211102.trunk/netcdf-4.0.1/lib  -pg -lgcov

Running LMDZ

You just run gcm.e as you usually do. This will create a bunch of gcda and gcno files that are used by gcov in the following step

Running gcovr

You then launch the gcovr command as

gcovr -r . -v --html-details gcm_details libo/local_32x32x39_phylmd_seq.e/.config/tmp/
                                         ^
                                         this is where the gcda and gcno files are saved by the compiler. They're created where the source files were actually compiled.
           

to create html files with the prefix gcm_details and the name of the routine included in the file. Each file in your code will have a corresponding html file giving the usage for each line of the routine included in that file.

You'll find [here] an example of the output for the actual LMDZ code.