Linux c/c++ coverage testing tool

gcov & lcov

  • Reference
  • step 1: add optional in Makefile, and build with make coverage=yes
    ifeq ($(coverage), yes)
    CXXFLAGS += -fprofile-arcs -ftest-coverage
    LINKERCXX += -fprofile-arcs -ftest-coverage
    OPT_FLAGS = -g3
  • step 2: run test files
  • step 3: generate text result by gcov, see result with vim
  • step 4: generate html result by lcov -c -d ./ -o and genhtml -o cc_result