How to do code coverage with Gcovr tool
1. Prerequisites
Install Gcovr tool with sudo apt install gcovr
2. Sample code
3. Compile source with --coverage
or -fprofile-arcs -ftest-coverage
flags
--coverage
or -fprofile-arcs -ftest-coverage
flagsThe .gcno
record file is generated after adding the GCC compile option -ftest-coverage
, which contains information for reconstructing the base block map and assigning source line numbers to blocks during the compilation process.
4. Run the user program
Run the user program to generate the .gcda
file that contains the coverage data counts.
5. Run gcovr
command to print a tabular report on the console
gcovr
command to print a tabular report on the console6. Generating HTML reports
7. Open coverage.html
file to browse the coverage report
coverage.html
file to browse the coverage reportLast updated