Skip to content

Commit c1b16a6

Browse files
committed
Fix function data merge bug - see #327.
Signed-off-by: Henry Cox <[email protected]>
1 parent 8f4d783 commit c1b16a6

File tree

4 files changed

+58
-21
lines changed

4 files changed

+58
-21
lines changed

bin/genhtml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2430,12 +2430,15 @@ sub differential_mcdc
24302430
sub _mergeFunctionData
24312431
{
24322432
my ($self, $loc, $functionData) = @_;
2433+
die('expected FunctionEntry found ' . ref($functionData))
2434+
unless 'FunctionEntry' eq ref($functionData);
24332435
my $function = $self->[FUNCTION_DATA];
24342436
if (defined($function->[$loc])) {
24352437
my $current = $function->[$loc];
24362438
$current->merge($functionData);
24372439
} else {
2438-
$function->[$loc] = Storable::dclone($functionData);
2440+
# also clone hit count data
2441+
$function->[$loc] = $functionData->cloneWithEndLine(1, 1);
24392442
}
24402443
}
24412444

@@ -3253,10 +3256,13 @@ sub _categorizeFunctionCov
32533256
my $base = $data->baseline_function();
32543257
my $categorized;
32553258
if (defined($curr)) {
3256-
$categorized = $curr->cloneWithEndLine(1); # also copy the end lien
3259+
# also copy the end line
3260+
$categorized = $curr->cloneWithEndLine(1);
32573261
} else {
3258-
$categorized = $base->cloneWithEndLine(0)
3259-
; # not in current - don't copy end line
3262+
# not in current - don't copy end line
3263+
# @todo if needed, could compute where the end line of the deleted
3264+
# function is now
3265+
$categorized = $base->cloneWithEndLine(0);
32603266
}
32613267
my $name = $categorized->name();
32623268
$differentialMap->{$name} = $categorized;
@@ -4842,8 +4848,9 @@ sub _countLineTlaData
48424848

48434849
if (!exists($SummaryInfo::tlaLocation{$tla})) {
48444850
# this case can happen if the line number annotations are
4845-
# wrong in the .info file - so the branch coverage line
4846-
# number turns out not to be an executable source code line
4851+
# wrong in the .info file - so the first line of some function
4852+
# or some branch coverage line number turns out not to be an
4853+
# executable source code line
48474854
lcovutil::ignorable_error($lcovutil::ERROR_UNKNOWN_CATEGORY,
48484855
"unexpected category $tla for line " . $self->path() . ":$line");
48494856
return;

lib/lcovutil.pm

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4331,10 +4331,18 @@ sub new
43314331

43324332
sub cloneWithEndLine
43334333
{
4334-
my ($self, $withEnd) = @_;
4335-
return
4336-
FunctionEntry->new($self->[NAME], $self->[MAP], $self->[FIRST],
4337-
$withEnd ? $self->[LAST] : undef);
4334+
my ($self, $withEnd, $cloneAliases) = @_;
4335+
my $fn = FunctionEntry->new($self->[NAME], $self->[MAP], $self->[FIRST],
4336+
$withEnd ? $self->[LAST] : undef);
4337+
if ($cloneAliases) {
4338+
my $count = 0;
4339+
while (my ($alias, $hit) = each(%{$self->aliases()})) {
4340+
$fn->[ALIASES]->{$alias} = $hit;
4341+
$count += $hit;
4342+
}
4343+
$fn->[COUNT] = $count;
4344+
}
4345+
return $fn;
43384346
}
43394347

43404348
sub name
@@ -6775,7 +6783,7 @@ sub data
67756783

67766784
my $key = $lcovutil::case_insensitive ? lc($file) : $file;
67776785
my $files = $self->[FILES];
6778-
if (!defined($files->{$key})) {
6786+
if (!exists($files->{$key})) {
67796787
if (defined $checkMatchingBasename) {
67806788
# check if there is a file in the map that has the same basename
67816789
# as the lone we are looking for.
@@ -6802,6 +6810,13 @@ sub data
68026810
return $files->{$key};
68036811
}
68046812

6813+
sub contains
6814+
{
6815+
my ($self, $file) = @_;
6816+
my $key = $lcovutil::case_insensitive ? lc($file) : $file;
6817+
my $files = $self->[FILES];
6818+
return exists($files->{$key});
6819+
}
68056820

68066821
sub remove
68076822
{
@@ -6966,8 +6981,9 @@ sub _deriveFunctionEndLines
69666981
my $traceInfo = shift;
69676982
my $modified = 0;
69686983

6969-
my $start = Time::HiRes::gettimeofday();
6970-
my @lines = sort { $a <=> $b } $traceInfo->sum()->keylist();
6984+
my $start = Time::HiRes::gettimeofday();
6985+
my $lineData = $traceInfo->sum();
6986+
my @lines = sort { $a <=> $b } $lineData->keylist();
69716987
# sort functions by start line number
69726988
# ignore lambdas - which we don't process correctly at the moment
69736989
# (would need to do syntactic search for the end line)
@@ -6980,6 +6996,12 @@ sub _deriveFunctionEndLines
69806996
my $func = shift(@functions);
69816997
my $first = $func->line();
69826998
my $end = $func->end_line();
6999+
#unless (defined($lineData->value($first))) {
7000+
# lcovutil::ignorable_error($lcovutil::ERROR_INCONSISTENT_DATA,
7001+
# '"' . $func->filename() .
7002+
# "\":$first: first line of function has no linecov.");
7003+
# $lineData->append($first, $func->hit());
7004+
#}
69837005
while ($first < $currentLine) {
69847006
if (@lines) {
69857007
$currentLine = shift @lines;
@@ -7143,7 +7165,7 @@ sub _checkConsistency
71437165
my $hit = $lineData->value($currentLine);
71447166
$lineHit = 1 if $hit;
71457167
if ($hit && !$imHit) {
7146-
# don't wan about the first line of a lambda:
7168+
# don't warn about the first line of a lambda:
71477169
# - the decl may executed even if the lambda function itself is
71487170
# not called
71497171
# - if no other lines are hit, then then the function is not
@@ -8240,6 +8262,12 @@ sub _read_info
82408262
$skipCurrentFile = 1;
82418263
next;
82428264
}
8265+
#if ($self->contains($filename)) {
8266+
# # we expect there to be only one entry for each source file in each section
8267+
# lcovutil::ignorable_warning($lcovutil::ERROR_FORMAT,
8268+
# "Duplicate entries for \"$filename\""
8269+
# . ($testname ? " in testcase '$testname'" : '') . '.');
8270+
#}
82438271
$filename = ReadCurrentSource::resolve_path($1, 1);
82448272
# should this one be skipped?
82458273
$skipCurrentFile = skipCurrentFile($filename);
@@ -8272,20 +8300,18 @@ sub _read_info
82728300
($testdata, $sumcount, $funcdata,
82738301
$checkdata, $testfncdata, $testbrdata,
82748302
$sumbrcount, $mcdcCount, $testMcdc) = $fileData->get_info();
8275-
$functionMap =
8276-
defined($testname) ? FunctionMap->new($filename) : $funcdata;
82778303

82788304
if (defined($testname)) {
8279-
$testcount = $fileData->test($testname);
8280-
$testfnccount = $fileData->testfnc($testname);
8281-
$testbrcount = $fileData->testbr($testname);
8305+
$testcount = $fileData->test($testname);
8306+
$functionMap = $fileData->testfnc($testname);
82828307
$testbrcount = $fileData->testbr($testname);
82838308
$testcase_mcdc = $fileData->testcase_mcdc($testname);
82848309
} else {
82858310
$testcount = CountData->new($filename, 1);
82868311
$testfnccount = CountData->new($filename, 0);
82878312
$testbrcount = BranchData->new();
82888313
$testcase_mcdc = MCDC_Data->new();
8314+
$functionMap = FunctionMap->new($filename);
82898315
}
82908316
next;
82918317
}

tests/perl2lcov/perltest1.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,8 @@ if [ 0 != $? ] ; then
266266
fi
267267
cover cover_genhtml -silent 1
268268
269-
$COVER ${EXEC_COVER} $PERL2LCOV_TOOL --output genhtml.info --testname genhtml_test ./cover_genhtml
269+
# ignore inconsistency: line hit but no branch on line is hit
270+
$COVER ${EXEC_COVER} $PERL2LCOV_TOOL --output genhtml.info --testname genhtml_test ./cover_genhtml --ignore inconsistent
270271
if [ 0 != $? ] ; then
271272
echo "perl2lcov genhtml"
272273
if [ 0 == $KEEP_GOING ] ; then

tests/xml2lcov/xml2lcov.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,10 @@ if [ 0 == $? ] ; then
247247
fi
248248

249249
# aggregate the files - as a syntax check
250-
$COVER $LCOV_TOOL $LCOV_OPTS -o aggregate.info -a test.info
250+
# the file contains inconsistent data for 'org/jasig/portal/EntityTypes.java'
251+
# function 'mapRow' is declared twice at different locations and
252+
# overlaps with a previous decl
253+
$COVER $LCOV_TOOL $LCOV_OPTS -o aggregate.info -a test.info --ignore inconsistent
251254
if [ 0 != $? ] ; then
252255
echo "lcov aggregate failed"
253256
if [ 0 == $KEEP_GOING ] ; then

0 commit comments

Comments
 (0)