Skip to content

Commit 3eb59e3

Browse files
committed
Bugfix: MC/DC filtering.
Signed-off-by: Henry Cox <[email protected]>
1 parent 398d2a0 commit 3eb59e3

File tree

3 files changed

+51
-22
lines changed

3 files changed

+51
-22
lines changed

bin/genhtml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11280,7 +11280,9 @@ sub write_source_line(*$$$$$$$)
1128011280
my $mc = @mcdc_html ? shift(@mcdc_html) : '';
1128111281
if ($mc) {
1128211282
# space over far enough to line up with MC/DC extension column
11283-
$br .= ' ' x ($br_field_width - length($br)) . ' ';
11283+
# remove the span and other HTML
11284+
(my $s = $br) =~ s/(<\/span>|<span.+?>)//g;
11285+
$br .= ' ' x ($br_field_width - length($s)) . ' ';
1128411286
}
1128511287
write_html($handle,
1128611288
"$html_continuation_leader$lineNumSpan" .

lib/lcovutil.pm

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2579,11 +2579,10 @@ sub balancedParens
25792579
++$close;
25802580
}
25812581
}
2582-
# lambda code may have trailing parens after the function...
2583-
#$close <= $open or die("malformed code in '$line'");
2584-
2585-
#return $close == $open;
2586-
return $close >= $open;
2582+
return ($open == $close ||
2583+
# lambda code may have trailing parens after the function...
2584+
($close > $open && $line =~ /{lambda\(/)
2585+
); # this is a C++-specific check
25872586
}
25882587

25892588
#
@@ -6407,7 +6406,6 @@ sub containsConditional
64076406
my $src = $self->getLine($line);
64086407
return 1
64096408
unless defined($src);
6410-
my $foundCond = 1;
64116409

64126410
my $code = "";
64136411
for (my $next = $line + 1;
@@ -6419,25 +6417,25 @@ sub containsConditional
64196417
my $bitwiseOperators =
64206418
$lcovutil::source_filter_bitwise_are_conditional ? '&|~' : '';
64216419

6422-
last
6420+
return 1
64236421
if ($src =~
64246422
/([?!><$bitwiseOperators]|&&|\|\||==|!=|\b(if|switch|case|while|for)\b)/
64256423
);
6426-
64276424
$code = $code . $src;
64286425

6429-
if (lcovutil::balancedParens($code) ||
6426+
if (lcovutil::balancedParens($code)) {
6427+
return 0; # got to the end and didn't see conditional
6428+
} elsif ($src =~ /[{;]\s*$/) {
64306429
# assume we got to the end of the statement if we see semicolon
64316430
# or brace.
6432-
$src =~ /[{;]\s*$/
6433-
) {
6434-
$foundCond = 0;
6435-
last;
6431+
# parens weren't balanced though - so assume this might be
6432+
# a conditional
6433+
return 1;
64366434
}
64376435
$src = $self->getLine($next);
64386436
$src = '' unless defined($src);
64396437
}
6440-
return $foundCond;
6438+
return 1; # not sure - so err on side of caution
64416439
}
64426440

64436441
sub containsTrivialFunction
@@ -7501,7 +7499,7 @@ sub _filterFile
75017499
my $filterExceptionBranches = FilterBranchExceptions->new();
75027500

75037501
my ($testdata, $sumcount, $funcdata, $checkdata, $testfncdata,
7504-
$testbrdata, $sumbrcount, $testmcdc, $mcdc) = $traceInfo->get_info();
7502+
$testbrdata, $sumbrcount, $mcdc, $testmcdc) = $traceInfo->get_info();
75057503

75067504
foreach my $testname (sort($testdata->keylist())) {
75077505
my $testcount = $testdata->value($testname);
@@ -7553,16 +7551,24 @@ sub _filterFile
75537551
} # foreach function
75547552
} # if func_coverage
75557553
# $testbrcount is undef if there are no branches in the scope
7556-
if ($lcovutil::br_coverage &&
7557-
defined($testbrcount) &&
7554+
if (($lcovutil::br_coverage || $lcovutil::mcdc_coverage) &&
7555+
(defined($testbrcount) ||
7556+
defined($mcdc_count)) &&
75587557
($branch_histogram ||
75597558
$region ||
75607559
$branch_region ||
75617560
$range ||
75627561
$filterExceptionBranches ||
75637562
$omit)
75647563
) {
7565-
foreach my $line ($testbrcount->keylist()) {
7564+
my %uniq;
7565+
# check MC/DC lines which are not also branch lines
7566+
foreach
7567+
my $line (defined($mcdc_count) ? $mcdc_count->keylist() : (),
7568+
defined($testbrcount) ? $testbrcount->keylist() : ()) {
7569+
next if exists($uniq{$line});
7570+
$uniq{$line} = 1;
7571+
75667572
# for counting: keep track filter which triggered exclusion -
75677573
my $remove;
75687574
# omit if line excluded or branches excluded on this line
@@ -7596,6 +7602,7 @@ sub _filterFile
75967602
foreach my $t ([$testbrdata, $sumbrcount, 'BRDA'],
75977603
[$testmcdc, $mcdc, 'MCDC']) {
75987604
my ($testCount, $sumCount, $str) = @$t;
7605+
next unless $sumCount;
75997606
my $brdata = $sumCount->value($line);
76007607
# might not be MCDC here, even if there is a branch
76017608
next unless $brdata;
@@ -7617,7 +7624,9 @@ sub _filterFile
76177624
$sumCount->remove($line);
76187625
$modified = 1;
76197626
}
7620-
} elsif (defined($filterExceptionBranches)) {
7627+
} elsif (defined($filterExceptionBranches) &&
7628+
defined($sumbrcount) &&
7629+
defined($sumbrcount->value($line))) {
76217630
# exclude exception branches here
76227631
my $m =
76237632
$filterExceptionBranches->filter($line, $srcReader,
@@ -7638,8 +7647,12 @@ sub _filterFile
76387647

76397648
my %initializerListRange;
76407649
foreach my $line ($testcount->keylist()) {
7641-
# don't suppresss if this line has associated branch data
7642-
next if (defined($sumbrcount->value($line)));
7650+
# don't suppresss if this line has associated branch or MC/DC data
7651+
next
7652+
if (
7653+
(defined($sumbrcount) && defined($sumbrcount->value($line))) ||
7654+
(defined($mcdc_count) &&
7655+
defined($mcdc_count->value($line))));
76437656

76447657
my $is_initializer;
76457658
my $is_filtered = undef;

man/genhtml.1

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2158,6 +2158,15 @@ sections of man
21582158
.B lcovrc(5)
21592159
for a description of the default associations and how they can be changed.
21602160

2161+
Note that filters are applied to both 'branch' and 'MC/DC' coverpoints,
2162+
where appropriate: if a particular filter would remove some branch,
2163+
then it will also remove corresponding MC/DC coverpoints - for example,
2164+
.I "\-\-filter branch"
2165+
will remove MC/DC coverpoints if there is no conditional expression on the
2166+
corresponding line, and
2167+
.I "\-\-filter branch_region"
2168+
will remove both branch and MC/DC coverpoints in the marked region.
2169+
21612170
Most filters need the source code; filters are not applied if the source file is not available. Similarly, for each source file, if the version recorded in the coverage data (the '.info' file)
21622171
does not match the version found on the filesystem, then a
21632172
.I version
@@ -2749,6 +2758,11 @@ a simple expression -
27492758
if (enable) ...
27502759
.RE
27512760

2761+
Note that, where appropriate, filters are applied to both 'branch' and 'MC/DC' coverpoints: if a particular filter would remove some branch,
2762+
then it will also remove corresponding MC/DC coverpoints. See the
2763+
.I \-\-filter
2764+
section, above.
2765+
27522766
This option can also be configured permanently using the configuration file
27532767
option
27542768
.IR mcdc_coverage .

0 commit comments

Comments
 (0)