Code Coverage

tags: III DevOps Testing CI/CD

Code Coverage

It allows you to find the areas of a program which is not exercised by a set of test cases, then it allows you to create extra test cases to increase coverage.


gcovr

  • gcovr will manage the use of gcov to output code coverage report.
  • Add logic to let g++ generate output files (*.gcno from -ftest-coverage and *.gcda from -fprofile-arcs) that can be processed by the gcov command.
  • *.gcno files are generated after compilation.
  • *.gcda files are generated after execution.

待測 shared (dynamic) library

source code 要被編譯成.o時,要加

GITLAB_GCOV_LDFLAGS += -fprofile-arcs -ftest-coverage -O0 -fPIC

.o要連結成.so時,要加

GITLAB_GCOV_FLAGS += -fprofile-arcs -O0 -fPIC -shared

Useful Commands

列出執行檔相依的動態函式庫

$ ldd unit-test/authTest/authTest.exe

搜索某檔名的路徑

$ find . -name 'libauth.so'

搜索含有某內容的檔案路徑

$ grep -rnw '\-lauth' .

展開 Makefile

$ make -nprR -C ulibs/auth | less

# makefile (from 'Makefile', line 7)
LIB_NAME = libauth.so