Skip to content

Instantly share code, notes, and snippets.

@flounderK
Last active April 11, 2025 02:28
Show Gist options
  • Save flounderK/aa8181351777c8056bb056f8285287a5 to your computer and use it in GitHub Desktop.
Save flounderK/aa8181351777c8056bb056f8285287a5 to your computer and use it in GitHub Desktop.
gather code coverage information with gcov in gcc
# build targets with code coverage, CFLAGS bit only works if `+=` is used in the make file
CFLAGS="-fprofile-arcs -ftest-coverage" make CC=gcc
# <run test case>
# create files for all coverage reached by test case (don't use if using lcov)
find . -type f -iname '*.gcda' |xargs gcov
# generate coverage file for gcda files under this directory
lcov -c -d . -o coverage.info
# generate html report of all coverage
genhtml coverage.info -o coverage_report
# view coverage info in browser
firefox coverage_report/index.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment