DOCUMENTATION AND METHODOLOGY
2022-07-07
Chapter 1 About kcov
Kcov is a code coverage tool which analyzes which lines of code are executing and which are not executed when the test suite (e.g: test-unit or test-kat) runs. In other words, it helps us to measure the efficiency of tests implementations. Noticing that a function is not covered as expected can be a signal check if there is a test implementation for this function in the test-suite. If the coverage of a function implemented in the source code is high, it more likely has a corresponding test function. But kcov is not really a tool to tell us which function has a test function or not (Our tool does).
1.1 Difference between kcov and gcov+lcov
kcov is an evolution of Bcov which itself is an evolution of gcov+lcov https://simonkagstrom.livejournal.com/50380.html
kcov and bcov are not using the same method as gcov+lcov for coverage info collection. Some problems with gcov+lcov:
- gcov+lcov is a multi-step process
- gcov leaves droppings (some more files are created) after compilation/running
- A program which crashes will not generate coverage data
Kcov fixes all these limitations .It collects coverage data without special compiler options, reports without leaving droppings around and everything is done with a single tool and a single step: kcov /path/to/outdir executable [args for the executable] Eg: Users/olivieradjonyo/Desktop/Crypt_lib/tii-cryptolib/cmake-build-debug/tests 2:00 kcov output_file ./tests/test_tii_cryptolib /test-unit kcov output_file ./tests/test_tii_cryptolib /test-kat
1.2 statement coverage tool
kcov is a statement coverage tool. A statement coverage is a white box testing technique in which all the executable statements in the source code are executed at least once. It’s used for calculation of the number of statements in source code which have been executed when the test suite runs. The main purpose of statement coverage is to cover all the possible paths, lines and statements in source code.
I checked that it’s a statement coverage by verifying that the coverage percentage is computed by the following:
\[\text{}statement\ coverage\ =\ \frac{number\ of\ executed\ \ statement\ \times100}{total\ number\ of\ statement}\]
Also, the other type of code coverage methods are more likely to give us low coverage percentage. So, regarding the high value of the percentage we got for a well-covered lib, the code coverage method here is statement wise.
1.3 Some details on kcov tool output
Instrumented lines: hited lines (at least one time) in yellow or green + not hited lines in red
Executed lines: hited lines in yellow or green
Hits column in green: 1 / 2 for example on a line means that there are 2 locations where the task on this particular lines is instrumented and then only one is executed.
1.4 Links
How gcov works https://github.com/shenxianpeng/gcov-example
https://www.youtube.com/watch?v=1QMHbp5LUKg https://simonkagstrom.github.io/kcov/
https://simonkagstrom.livejournal.com/50380.html
CI integration of kcov: https://github.com/SimonKagstrom/kcov https://github.com/SimonKagstrom/kcov/blob/master/doc/sonarqube.md