Code coverage testing

When testing a program, it’s often useful to know which parts of the code have actually been used. Coverage testing collects statistics about a running program.

First the program needs to be compiled and linked with some extra options. This will generate a .gcno coverage files for each object.

For NeoMutt, simply add an option to configure, then build as normal. The results will be in coverage/index.html

./configure --coverage
make coverage

For other projects, add these to your Makefile:

CFLAGS  += -fprofile-arcs -ftest-coverage
LDFLAGS += -fprofile-arcs -ftest-coverage

When the program is run, every function will write data to a .gcda file. lcov can convert the saved data into an html table.

lcov -t "result" -o -c -d config
genhtml -o lcov

Coveralls performs the same function, but it has a much prettier website.

# Install the coveralls helper programm
pip install --user cpp-coveralls


# Update the stats, excluding (-e) certain files/dirs
coveralls -e mutt -e test -e dump -e main.c -e config/dump.c

NeoMutt has coverage of several libraries: address, compress, config, core, email, mutt, store.

Search by Algolia