Skip to content

Commit 2e87217

Browse files
fahlgrenoberpar
authored andcommitted
geninfo: make line exclusion markers configurable
This patch exposes the variable $excl_line and $excl_br_line so they can be set in the configuration file. It is not always possible to add the exclusion markers to the code with reasons like third party code, company policy, legacy code, no commit access etc. One obvious use case is to exclude assert() from the branch coverage and abort() from line coverage. They are never meant to be triggered unless something is wrong. Other use cases can be custom error handling macros or macros that depend on endianness, like htons(). Signed-off-by: Daniel Fahlgren <[email protected]>
1 parent 10b11ea commit 2e87217

File tree

3 files changed

+37
-7
lines changed

3 files changed

+37
-7
lines changed

bin/geninfo

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,10 @@ our %ERROR_ID = (
8888

8989
our $EXCL_START = "LCOV_EXCL_START";
9090
our $EXCL_STOP = "LCOV_EXCL_STOP";
91-
our $EXCL_LINE = "LCOV_EXCL_LINE";
9291

9392
# Marker to exclude branch coverage but keep function and line coveage
9493
our $EXCL_BR_START = "LCOV_EXCL_BR_START";
9594
our $EXCL_BR_STOP = "LCOV_EXCL_BR_STOP";
96-
our $EXCL_BR_LINE = "LCOV_EXCL_BR_LINE";
9795

9896
# Compatibility mode values
9997
our $COMPAT_VALUE_OFF = 0;
@@ -258,6 +256,8 @@ our $gcno_split_crc;
258256
our $func_coverage = 1;
259257
our $br_coverage = 0;
260258
our $rc_auto_base = 1;
259+
our $excl_line = "LCOV_EXCL_LINE";
260+
our $excl_br_line = "LCOV_EXCL_BR_LINE";
261261

262262
our $cwd = `pwd`;
263263
chomp($cwd);
@@ -322,6 +322,8 @@ if ($config || %opt_rc)
322322
"geninfo_auto_base" => \$rc_auto_base,
323323
"lcov_function_coverage" => \$func_coverage,
324324
"lcov_branch_coverage" => \$br_coverage,
325+
"lcov_excl_line" => \$excl_line,
326+
"lcov_excl_br_line" => \$excl_br_line,
325327
});
326328

327329
# Merge options
@@ -351,6 +353,13 @@ if ($config || %opt_rc)
351353
$adjust_src_replace = $replace;
352354
}
353355
}
356+
for my $regexp (($excl_line, $excl_br_line)) {
357+
eval 'qr/'.$regexp.'/';
358+
my $error = $@;
359+
chomp($error);
360+
$error =~ s/at \(eval.*$//;
361+
die("ERROR: invalid exclude pattern: $error") if $error;
362+
}
354363
}
355364

356365
# Parse command line options
@@ -1731,7 +1740,7 @@ sub read_gcov_file($)
17311740
} elsif (/$EXCL_START/) {
17321741
$exclude_flag = 1;
17331742
}
1734-
if (/$EXCL_LINE/ || $exclude_flag) {
1743+
if (/$excl_line/ || $exclude_flag) {
17351744
$exclude_line = 1;
17361745
} else {
17371746
$exclude_line = 0;
@@ -1744,7 +1753,7 @@ sub read_gcov_file($)
17441753
} elsif (/$EXCL_BR_START/) {
17451754
$exclude_br_flag = 1;
17461755
}
1747-
if (/$EXCL_BR_LINE/ || $exclude_br_flag) {
1756+
if (/$excl_br_line/ || $exclude_br_flag) {
17481757
$exclude_branch = 1;
17491758
} else {
17501759
$exclude_branch = 0;
@@ -1830,7 +1839,7 @@ sub read_gcov_file($)
18301839
} elsif (/$EXCL_START/) {
18311840
$exclude_flag = 1;
18321841
}
1833-
if (/$EXCL_LINE/ || $exclude_flag) {
1842+
if (/$excl_line/ || $exclude_flag) {
18341843
$exclude_line = 1;
18351844
} else {
18361845
$exclude_line = 0;
@@ -1843,7 +1852,7 @@ sub read_gcov_file($)
18431852
} elsif (/$EXCL_BR_START/) {
18441853
$exclude_br_flag = 1;
18451854
}
1846-
if (/$EXCL_BR_LINE/ || $exclude_br_flag) {
1855+
if (/$excl_br_line/ || $exclude_br_flag) {
18471856
$exclude_branch = 1;
18481857
} else {
18491858
$exclude_branch = 0;
@@ -2129,7 +2138,7 @@ sub get_exclusion_data($)
21292138
} elsif (/$EXCL_START/) {
21302139
$flag = 1;
21312140
}
2132-
if (/$EXCL_LINE/ || $flag) {
2141+
if (/$excl_line/ || $flag) {
21332142
$list{$.} = 1;
21342143
}
21352144
}

man/geninfo.1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ markers to the source code. Additionally you can exclude specific branches from
7878
branch coverage without excluding the involved lines from line and function
7979
coverage. Exclusion markers are keywords which can for example be added in the
8080
form of a comment.
81+
See
82+
.BR lcovrc (5)
83+
how to override some of them.
8184

8285
The following markers are recognized by geninfo:
8386

man/lcovrc.5

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,24 @@ will override this option for HTML generation.
836836
Default is 0.
837837
.PP
838838

839+
.BR lcov_excl_line " ="
840+
.I expression
841+
.IP
842+
Specify the regular expression of lines to exclude.
843+
.br
844+
845+
Default is 'LCOV_EXCL_LINE'.
846+
.PP
847+
848+
.BR lcov_excl_br_line " ="
849+
.I expression
850+
.IP
851+
Specify the regular expression of lines to exclude from branch coverage.
852+
.br
853+
854+
Default is 'LCOV_EXCL_BR_LINE'.
855+
.PP
856+
839857
.SH FILES
840858

841859
.TP

0 commit comments

Comments
 (0)