Hi~
Hi~
文章目录
  1. What is Branch Coverage
    1. Format of lcov.info
    2. How to Calculate Branch Coverage
      1. Example

How to Use *.info File Calculate Branch Coverage

What is Branch Coverage

Branch coverage is a requirement that, for each branch in the program (e.g., if statements, loops), each branch have been executed at least once during testing. (It is sometimes also described as saying that each branch condition must have been true at least once and false at least once during testing.)
From https://www.cs.odu.edu/~cs252/Book/branchcov.html

Format of lcov.info

Following  is  a  quick  description of the tracefile format as used by
genhtml, geninfo and lcov.

A tracefile is made up of several human-readable lines of text, divided
into sections. If available, a tracefile begins with the testname which
is stored in the following format:

TN:<test name>

For each source file referenced in the .da file, there is a section
containing filename and coverage data:

SF:<absolute path to the source file>

Following is a list of line numbers for each function name found in the
source file:

FN:<line number of function start>,<function name>

Next, there is a list of execution counts for each instrumented func‐
tion:

FNDA:<execution count>,<function name>

This list is followed by two lines containing the number of functions
found and hit:

FNF:<number of functions found>
FNH:<number of function hit>

Branch coverage information is stored which one line per branch:

BRDA:<line number>,<block number>,<branch number>,<taken>

Block number and branch number are gcc internal IDs for the branch.
Taken is either '-' if the basic block containing the branch was never
executed or a number indicating how often that branch was taken.

Branch coverage summaries are stored in two lines:

BRF:<number of branches found>
BRH:<number of branches hit>

Then there is a list of execution counts for each instrumented line
(i.e. a line which resulted in executable code):

DA:<line number>,<execution count>[,<checksum>]

Note that there may be an optional checksum present for each instru‐
mented line. The current geninfo implementation uses an MD5 hash as
checksumming algorithm.

At the end of a section, there is a summary about how many lines were
found and how many were actually instrumented:

LH:<number of lines with a non-zero execution count>
LF:<number of instrumented lines>

Each sections ends with:

end_of_record

In addition to the main source code file there are sections for all
#included files which also contain executable code.

Note that the absolute path of a source file is generated by interpret‐
ing the contents of the respective .bb file (see gcov (1) for more
information on this file type). Relative filenames are prefixed with
the directory in which the .bb file is found.

Note also that symbolic links to the .bb file will be resolved so that
the actual file path is used instead of the path to a link. This
approach is necessary for the mechanism to work with the /proc/gcov
files.

How to Calculate Branch Coverage

BRDA:,,,

Branch Coverage = Hit Branch Count/(Hit Branch Count + Not Hit Branch Count)

Example

If the lcov.info ClassA is as follow.

BRDA:16,0,0,0
BRDA:16,0,1,2
BRDA:24,0,0,1
BRDA:24,0,1,1
BRDA:27,0,0,0
BRDA:27,0,1,2
BRDA:30,0,0,0
BRDA:30,0,1,2
BRDA:33,0,0,1
BRDA:33,0,1,1

The incremental branch covers 10 lines of Branch, and the hit results are BRDA:16,0,1,2 BRDA:24,0,0,1 BRDA:24,0,1,1 BRDA:27,0,1,2 BRDA:30,0,1,2 BRDA:33,0,0,1 BRDA:33,0,1,1 For these branches, the branch coverage rate is 7/10 = 70%

If the lcov.info ClassB is as follow.

BRDA:278,0,0,1
BRDA:278,0,1,0
BRDA:280,0,0,-
BRDA:280,0,1,-

The incremental branch covers 4 lines of Branch, and the hit result is the branch BRDA:278,0,0,1, then the branch coverage rate is 1/4 = 25%

BRDA:16,0,0,0
BRDA:16,0,1,2
BRDA:24,0,0,1
BRDA:24,0,1,1
BRDA:27,0,0,0
BRDA:27,0,1,2
BRDA:30,0,0,0
BRDA:30,0,1,2
BRDA:33,0,0,1
BRDA:33,0,1,1
BRDA:278,0,0,1
BRDA:278,0,1,0
BRDA:280,0,0,-
BRDA:280,0,1,-

The Branch Coverage Rate of ClassA and ClassB is not ~0.7+0.25~.

(7+1)/ (10+4)= 8/14 = 57.14%

支持一下
扫一扫,支持forsigner
  • 微信扫一扫
  • 支付宝扫一扫