How to generate code coverage report - Cidana-Developers/Cidana-Task-Manager GitHub Wiki
Code coverage is an important requirement for our unit test project, here we will introduce the step briefly. We will take libaom as an example.
-
compile:
- using gcc and g++:
cmake ../aom_mod/ -DCMAKE_C_COMPILER=/usr/bin/gcc -DCMAKE_CXX_COMPILER=/usr/bin/g++
- add following flags
-fprofile-arcs -ftest-coverage
- add link flags:
-fprofile-arcs -ftest-coverage
- build debug mode
- total command:
cmake ../aom_mod/ -DCMAKE_C_COMPILER=/usr/bin/gcc -DCMAKE_CXX_COMPILER=/usr/bin/g++ '-DAOM_EXTRA_C_FLAGS=-fprofile-arcs -ftest-coverage' '-DAOM_EXTRA_CXX_FLAGS=-fprofile-arcs -ftest-coverage' '-DAOM_EXTRA_EXE_LINKER_FLAGS=-fprofile-arcs -ftest-coverage' -DCMAKE_BUILD_TYPE=Debug
- check the files generated: find name with suffix gcno or gcda, usually they are generated in the same folder with obj files.
- using gcc and g++:
-
clean up from previous run
$ lcov --zerocounters --directory .
- create baseline
$ lcov --no-external --capture --initial --base-directory ../aom_mode --directory . --output-file
libaom_base.info
- run test
$ ./test --gtest_filter="test.*"
- run lcov again after tests
$ lcov --no-external --capture --base-directory ../aom_mode
--directory . --output-file libaom_test.info
- combine lcove tracefiles
$ lcov --add-tracefile ./libaom_base.info --add-tracefile
./libaom_test.info --output-file ./libaom_total.info
- remove/filter out remaining unwanted stuff
$ lcov -r libaom_total.info "*third_party*" -o
libaom_total_reduced.info
- Generate html
$ genhtml decoder.info --output-directory ./
- Generate report for jenkins Install lcov_cobertura.py
$ pip install lcov_cobertura.py
Find where is lcov_cobertura, open python console
In [0]: import lcov_cobertura
In [1]: lcov_cobertura.__file__ # will output the location of lcov_cobertura.pyc
create cobertura report:
$ python /home/wenyao/.local/lib/python2.7/site-packages/lcov_cobertura.pyc ./libaom_total_slim.info -b ../aom_mod -o coverage.xml
- Issue: gcov expect "xxx.o" while cmake produce "xxx.c.o"
Fix: add CMake flag, like:
cmake -DCMAKE_C_OUTPUT_EXTENSION_REPLACE=1 -DCMAKE_CXX_OUTPUT_EXTENSION_REPLACE=1