Skip to content

Commit 0bde873

Browse files
sebastianstigleroberpar
authored andcommitted
geninfo: add exclude marker for branch coverage
Sometimes it can be helpful to generally use branch coverage but to disable it for some lines of code without excluding the line or function coverage too. For example if you make heavily use of assertions in your code (which is generally a good idea) you will see that for each 'assert(...)' exist one branch which is taken and one that is not. Similarly you can see the same phenomenon for 'delete' in C++ code. If you use the 'LCOV_EXCL_LINE' marker in such a situation both of these branches will be omitted from the output. But in doing so, you loose the ability to determine if this peace of code is genuine 'dead code' or not because the line coverage is omitted too. The newly introduces 'LCOV_EXCL_BR_LINE', 'LCOV_EXCL_BR_START' and 'LCOV_EXCL_BR_STOP' marker address this problem. The usage is similar to the 'LCOV_EXCL_LINE' etc. markers. Signed-off-by: Sebastian Stigler <[email protected]>
1 parent 119be72 commit 0bde873

File tree

2 files changed

+61
-4
lines changed

2 files changed

+61
-4
lines changed

bin/geninfo

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ if( $^O eq "msys" )
6161
}
6262

6363
# Constants
64-
our $lcov_version = 'LCOV version 1.11 pre (CVS $Revision: 1.123 $)';
64+
our $lcov_version = 'LCOV version 1.11 pre (CVS $Revision: 1.124 $)';
6565
our $lcov_url = "http://ltp.sourceforge.net/coverage/lcov.php";
6666
our $gcov_tool = "gcov";
6767
our $tool_name = basename($0);
@@ -88,6 +88,11 @@ our $EXCL_START = "LCOV_EXCL_START";
8888
our $EXCL_STOP = "LCOV_EXCL_STOP";
8989
our $EXCL_LINE = "LCOV_EXCL_LINE";
9090

91+
# Marker to exclude branch coverage but keep function and line coveage
92+
our $EXCL_BR_START = "LCOV_EXCL_BR_START";
93+
our $EXCL_BR_STOP = "LCOV_EXCL_BR_STOP";
94+
our $EXCL_BR_LINE = "LCOV_EXCL_BR_LINE";
95+
9196
# Compatibility mode values
9297
our $COMPAT_VALUE_OFF = 0;
9398
our $COMPAT_VALUE_ON = 1;
@@ -1667,6 +1672,8 @@ sub read_gcov_file($)
16671672
my $number;
16681673
my $exclude_flag = 0;
16691674
my $exclude_line = 0;
1675+
my $exclude_br_flag = 0;
1676+
my $exclude_branch = 0;
16701677
my $last_block = $UNNAMED_BLOCK;
16711678
my $last_line = 0;
16721679
local *INPUT;
@@ -1693,11 +1700,13 @@ sub read_gcov_file($)
16931700
if (/^branch\s+(\d+)\s+taken\s+=\s+(\d+)/) {
16941701
next if (!$br_coverage);
16951702
next if ($exclude_line);
1703+
next if ($exclude_branch);
16961704
$branches = br_gvec_push($branches, $last_line,
16971705
$last_block, $1, $2);
16981706
} elsif (/^branch\s+(\d+)\s+never\s+executed/) {
16991707
next if (!$br_coverage);
17001708
next if ($exclude_line);
1709+
next if ($exclude_branch);
17011710
$branches = br_gvec_push($branches, $last_line,
17021711
$last_block, $1, '-');
17031712
}
@@ -1721,6 +1730,19 @@ sub read_gcov_file($)
17211730
$exclude_line = 0;
17221731
}
17231732
}
1733+
# Check for exclusion markers (branch exclude)
1734+
if (!$no_markers) {
1735+
if (/$EXCL_BR_STOP/) {
1736+
$exclude_br_flag = 0;
1737+
} elsif (/$EXCL_BR_START/) {
1738+
$exclude_br_flag = 1;
1739+
}
1740+
if (/$EXCL_BR_LINE/ || $exclude_br_flag) {
1741+
$exclude_branch = 1;
1742+
} else {
1743+
$exclude_branch = 0;
1744+
}
1745+
}
17241746
# Source code execution data
17251747
if (/^\t\t(.*)$/)
17261748
{
@@ -1766,11 +1788,13 @@ sub read_gcov_file($)
17661788
} elsif (/^branch\s+(\d+)\s+taken\s+(\d+)/) {
17671789
next if (!$br_coverage);
17681790
next if ($exclude_line);
1791+
next if ($exclude_branch);
17691792
$branches = br_gvec_push($branches, $last_line,
17701793
$last_block, $1, $2);
17711794
} elsif (/^branch\s+(\d+)\s+never\s+executed/) {
17721795
next if (!$br_coverage);
17731796
next if ($exclude_line);
1797+
next if ($exclude_branch);
17741798
$branches = br_gvec_push($branches, $last_line,
17751799
$last_block, $1, '-');
17761800
}
@@ -1805,6 +1829,20 @@ sub read_gcov_file($)
18051829
$exclude_line = 0;
18061830
}
18071831
}
1832+
# Check for exclusion markers (branch exclude)
1833+
if (!$no_markers) {
1834+
if (/$EXCL_BR_STOP/) {
1835+
$exclude_br_flag = 0;
1836+
} elsif (/$EXCL_BR_START/) {
1837+
$exclude_br_flag = 1;
1838+
}
1839+
if (/$EXCL_BR_LINE/ || $exclude_br_flag) {
1840+
$exclude_branch = 1;
1841+
} else {
1842+
$exclude_branch = 0;
1843+
}
1844+
}
1845+
18081846
# <exec count>:<line number>:<source code>
18091847
if ($line eq "0")
18101848
{
@@ -1837,7 +1875,7 @@ sub read_gcov_file($)
18371875
}
18381876

18391877
close(INPUT);
1840-
if ($exclude_flag) {
1878+
if ($exclude_flag || $exclude_br_flag) {
18411879
warn("WARNING: unterminated exclusion section in $filename\n");
18421880
}
18431881
return(\@result, $branches, \@functions);

man/geninfo.1

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,10 @@ so that there is usually no need to call it directly.
7474
.B Exclusion markers
7575

7676
To exclude specific lines of code from a tracefile, you can add exclusion
77-
markers to the source code. Exclusion markers are keywords which can for
78-
example be added in the form of a comment.
77+
markers to the source code. Additionally you can exclude specific branches from
78+
branch coverage without excluding the involved lines from line and function
79+
coverage. Exclusion markers are keywords which can for example be added in the
80+
form of a comment.
7981

8082
The following markers are recognized by geninfo:
8183

@@ -96,6 +98,23 @@ Marks the end of an excluded section. The current line not part of this
9698
section.
9799
.RE
98100
.br
101+
LCOV_EXCL_BR_LINE
102+
.RS
103+
Lines containing this marker will be excluded from branch coverage.
104+
.br
105+
.RE
106+
LCOV_EXCL_BR_START
107+
.RS
108+
Marks the beginning of a section which is excluded from branch coverage. The
109+
current line is part of this section.
110+
.br
111+
.RE
112+
LCOV_EXCL_BR_STOP
113+
.RS
114+
Marks the end of a section which is excluded from branch coverage. The current
115+
line not part of this section.
116+
.RE
117+
.br
99118

100119
.SH OPTIONS
101120

0 commit comments

Comments
 (0)