Skip to content

fobos intrinsic rules gcov analyzer

Stefano Zaghi edited this page Mar 12, 2015 · 1 revision

This intrinsic rule parses (by means of a parser builtin into FoBiS.py) all .gcov files found into the root directory where FoBiS.py is executed and produces a pretty markdown file (for each .gcov file) containing a curated report of the coverage analysis. Obviously, the gcov tool must be executed before running this intrinsic rule. Let us consider an example. The tree of our example looks like

src
├── cumbersome.f90
└── nested-1
    ├── first_dep.f90
    └── nested-2
        └── second_dep.inc

In order to obtain the coverage reports we must follow the steps below

Compile with coverage enabling flags

The project must be compiled with the coverage flags:

FoBiS.py build -compiler gnu -coverage --target src/cumbersome.f90 -o cumbersome

This instruments the code with coverage tools for analysing the sources.

Run the instrumented code

The instrumented code must be run in order to collect coverage data.

./cumbersome
Run gcov tool

Running the gcov tool will produce the .gcov files

gcov -o obj/ src/cumbersome.f90 src/nested-1/first_dep.f90

This generates two files into the root directory:

  • cumbersome.f90.gcov
  • first_dep.f90.gcov You can place these files everywhere into the root directory.
Run FoBiS.py analyzer

The produced .gcov files are not simple to read, thus a pretty-printed report can be very useful. FoBiS.py has its own analyzer able to generate a pretty-printed report in markdown format. The syntax of this intrinsic rule is the following:

FoBiS.py rule -gcov_analyzer GCOV_REPORTS_DIR [REPORT_SUMMARY_FILE_NAME]

the GCOV_REPORTS_DIR is required and indicates the directory where the reports are placed. The REPORT_SUMMARY_FILE_NAME is optional and indicated the title and also the file name (without extension and without path) of summary file containing a summary of all the analyzed files. In the present example we can run

FoBiS.py rule -gcov_analyzer coverage-reports/ Coverage-Analysis

The generated files are:

  • coverage-reports/Coverage-Analysis.md
  • coverage-reports/cumbersome.f90.gcov-report.md
  • coverage-reports/first_dep.f90.gcov-report.md

An example of a FoBiS.py summary report can be seen here and a report of single file here.

All the above steps can be conveniently packed into a standard fobos rule defined inside a fobos file:

[rule-coverage-analysis]
help   = Perform coverage analysis
rule_1 = FoBiS.py build -compiler gnu -coverage --target src/cumbersome.f90 -o cumbersome
rule_2 = ./cumbersome
rule_3 = gcov -o obj/ src/cumbersome.f90 src/nested-1/first_dep.f90
rule_4 = mkdir -p coverage-reports
rule_5 = FoBiS.py rule -gcov_analyzer coverage-reports Coverage-Analysis
rule_6 = rm -f *.gcov

A note on the coverage pie charts

In the examples linked above you can see nice pie charts representing the covered and uncovered parts of the code. This charts are generated by means of the google chart API through the pygooglechart python module, see the Requirements.

Clone this wiki locally