Opened 5 years ago

Last modified 4 years ago

#3819 new enhancement

Add test coverage of C files

Reported by: pmav99 Owned by: grass-dev@…
Priority: normal Milestone: 7.8.3
Component: Compiling Version: svn-trunk
Keywords: Cc:
CPU: Unspecified Platform: Unspecified

Description

Disclaimer: I've only tested with gcc.

Using the info from these links I managed to get test coverage for the C codebase:

  1. install gcov
  2. Compile with these options:
    export CFLAGS='-O0 -fPIC -march=native -std=gnu99 -fprofile-arcs -ftest-coverage -g'
    export LDFLAGS='-s -lgcov --coverage'
    
  3. Run tests
  4. Generate test coverage reports (there may be warning/errors):
    mkdir -p coverage
    gcovr -r . --filter="" --html --html-details -o coverage/coverage.html
    
  5. Inspect coverage:
    firefox coverage/coverage.html
    

If possible, this should be added to fatra and once #3771 is resolved, on travis too.

I guess that it would also make sense to add a configure option like e.g. libspatialite:

#-----------------------------------------------------------------------
#    --enable-gcov
#
# Check whether --enable-gcov was given.
if test "${enable_gcov+set}" = set; then :
  enableval=$enable_gcov;
fi

if test "x$enable_gcov" = "xyes"; then
        CFLAGS=$CFLAGS" -fprofile-arcs -ftest-coverage -g"
    GCOV_FLAGS="-lgcov"
fi
#-----------------------------------------------------------------------

Change History (3)

comment:1 by pmav99, 5 years ago

For the record, GDAL is already using gcov/lcov, too, so it might make sense to see how they have integrated them: https://gdalautotest-coverage-results.github.io/coverage_html/index.html

comment:2 by rouault, 5 years ago

GDAL is already using gcov/lcov, too, so it might make sense to see how they have integrated them

This is quite messy to be honest. Partly because I didn't try to make this better :-) So basically, I've a job that forks the GDAL master branch and re-applies the following changes on top of it : https://github.com/rouault/gdal_coverage/commit/3b63c70890a0897dcbe1cbd49f36b76e0a5e704a But the gist is build with lcov, run the tests, run lcov, filter some stuff in its output to have a clean report, run genhtml and then push this to a github repo. The interesting part that could be more or less reused by GRASS is in https://github.com/rouault/gdal_coverage/commit/3b63c70890a0897dcbe1cbd49f36b76e0a5e704a#diff-46c965c7db8bedae7518f42e783c44dd

comment:3 by neteler, 4 years ago

Milestone: 7.8.3
Note: See TracTickets for help on using tickets.