Skip to content

Commit

Permalink
Fix function data merge bug - see #327.
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Cox <[email protected]>
  • Loading branch information
henry2cox committed Nov 18, 2024
1 parent 8f4d783 commit c1b16a6
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 21 deletions.
19 changes: 13 additions & 6 deletions bin/genhtml
Original file line number Diff line number Diff line change
Expand Up @@ -2430,12 +2430,15 @@ sub differential_mcdc
sub _mergeFunctionData
{
my ($self, $loc, $functionData) = @_;
die('expected FunctionEntry found ' . ref($functionData))
unless 'FunctionEntry' eq ref($functionData);
my $function = $self->[FUNCTION_DATA];
if (defined($function->[$loc])) {
my $current = $function->[$loc];
$current->merge($functionData);
} else {
$function->[$loc] = Storable::dclone($functionData);
# also clone hit count data
$function->[$loc] = $functionData->cloneWithEndLine(1, 1);
}
}

Expand Down Expand Up @@ -3253,10 +3256,13 @@ sub _categorizeFunctionCov
my $base = $data->baseline_function();
my $categorized;
if (defined($curr)) {
$categorized = $curr->cloneWithEndLine(1); # also copy the end lien
# also copy the end line
$categorized = $curr->cloneWithEndLine(1);
} else {
$categorized = $base->cloneWithEndLine(0)
; # not in current - don't copy end line
# not in current - don't copy end line
# @todo if needed, could compute where the end line of the deleted
# function is now
$categorized = $base->cloneWithEndLine(0);
}
my $name = $categorized->name();
$differentialMap->{$name} = $categorized;
Expand Down Expand Up @@ -4842,8 +4848,9 @@ sub _countLineTlaData

if (!exists($SummaryInfo::tlaLocation{$tla})) {
# this case can happen if the line number annotations are
# wrong in the .info file - so the branch coverage line
# number turns out not to be an executable source code line
# wrong in the .info file - so the first line of some function
# or some branch coverage line number turns out not to be an
# executable source code line
lcovutil::ignorable_error($lcovutil::ERROR_UNKNOWN_CATEGORY,
"unexpected category $tla for line " . $self->path() . ":$line");
return;
Expand Down
52 changes: 39 additions & 13 deletions lib/lcovutil.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4331,10 +4331,18 @@ sub new

sub cloneWithEndLine
{
my ($self, $withEnd) = @_;
return
FunctionEntry->new($self->[NAME], $self->[MAP], $self->[FIRST],
$withEnd ? $self->[LAST] : undef);
my ($self, $withEnd, $cloneAliases) = @_;
my $fn = FunctionEntry->new($self->[NAME], $self->[MAP], $self->[FIRST],
$withEnd ? $self->[LAST] : undef);
if ($cloneAliases) {
my $count = 0;
while (my ($alias, $hit) = each(%{$self->aliases()})) {
$fn->[ALIASES]->{$alias} = $hit;
$count += $hit;
}
$fn->[COUNT] = $count;
}
return $fn;
}

sub name
Expand Down Expand Up @@ -6775,7 +6783,7 @@ sub data

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

sub contains
{
my ($self, $file) = @_;
my $key = $lcovutil::case_insensitive ? lc($file) : $file;
my $files = $self->[FILES];
return exists($files->{$key});
}

sub remove
{
Expand Down Expand Up @@ -6966,8 +6981,9 @@ sub _deriveFunctionEndLines
my $traceInfo = shift;
my $modified = 0;

my $start = Time::HiRes::gettimeofday();
my @lines = sort { $a <=> $b } $traceInfo->sum()->keylist();
my $start = Time::HiRes::gettimeofday();
my $lineData = $traceInfo->sum();
my @lines = sort { $a <=> $b } $lineData->keylist();
# sort functions by start line number
# ignore lambdas - which we don't process correctly at the moment
# (would need to do syntactic search for the end line)
Expand All @@ -6980,6 +6996,12 @@ sub _deriveFunctionEndLines
my $func = shift(@functions);
my $first = $func->line();
my $end = $func->end_line();
#unless (defined($lineData->value($first))) {
# lcovutil::ignorable_error($lcovutil::ERROR_INCONSISTENT_DATA,
# '"' . $func->filename() .
# "\":$first: first line of function has no linecov.");
# $lineData->append($first, $func->hit());
#}
while ($first < $currentLine) {
if (@lines) {
$currentLine = shift @lines;
Expand Down Expand Up @@ -7143,7 +7165,7 @@ sub _checkConsistency
my $hit = $lineData->value($currentLine);
$lineHit = 1 if $hit;
if ($hit && !$imHit) {
# don't wan about the first line of a lambda:
# don't warn about the first line of a lambda:
# - the decl may executed even if the lambda function itself is
# not called
# - if no other lines are hit, then then the function is not
Expand Down Expand Up @@ -8240,6 +8262,12 @@ sub _read_info
$skipCurrentFile = 1;
next;
}
#if ($self->contains($filename)) {
# # we expect there to be only one entry for each source file in each section
# lcovutil::ignorable_warning($lcovutil::ERROR_FORMAT,
# "Duplicate entries for \"$filename\""
# . ($testname ? " in testcase '$testname'" : '') . '.');
#}
$filename = ReadCurrentSource::resolve_path($1, 1);
# should this one be skipped?
$skipCurrentFile = skipCurrentFile($filename);
Expand Down Expand Up @@ -8272,20 +8300,18 @@ sub _read_info
($testdata, $sumcount, $funcdata,
$checkdata, $testfncdata, $testbrdata,
$sumbrcount, $mcdcCount, $testMcdc) = $fileData->get_info();
$functionMap =
defined($testname) ? FunctionMap->new($filename) : $funcdata;

if (defined($testname)) {
$testcount = $fileData->test($testname);
$testfnccount = $fileData->testfnc($testname);
$testbrcount = $fileData->testbr($testname);
$testcount = $fileData->test($testname);
$functionMap = $fileData->testfnc($testname);
$testbrcount = $fileData->testbr($testname);
$testcase_mcdc = $fileData->testcase_mcdc($testname);
} else {
$testcount = CountData->new($filename, 1);
$testfnccount = CountData->new($filename, 0);
$testbrcount = BranchData->new();
$testcase_mcdc = MCDC_Data->new();
$functionMap = FunctionMap->new($filename);
}
next;
}
Expand Down
3 changes: 2 additions & 1 deletion tests/perl2lcov/perltest1.sh
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,8 @@ if [ 0 != $? ] ; then
fi
cover cover_genhtml -silent 1
$COVER ${EXEC_COVER} $PERL2LCOV_TOOL --output genhtml.info --testname genhtml_test ./cover_genhtml
# ignore inconsistency: line hit but no branch on line is hit
$COVER ${EXEC_COVER} $PERL2LCOV_TOOL --output genhtml.info --testname genhtml_test ./cover_genhtml --ignore inconsistent
if [ 0 != $? ] ; then
echo "perl2lcov genhtml"
if [ 0 == $KEEP_GOING ] ; then
Expand Down
5 changes: 4 additions & 1 deletion tests/xml2lcov/xml2lcov.sh
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,10 @@ if [ 0 == $? ] ; then
fi

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

0 comments on commit c1b16a6

Please sign in to comment.