Skip to content

Commit 528c97b

Browse files
committed
Check for consistency between baseline coverage DB, current coverage
DB, and 'diff' file data: If file is present in both baseline and current coverage data: - if version is not the same: expect to find file in 'diff' data. - if version is the same: expect to NOT find in 'diff' data. If file is not in 'current' DB: then it is no longer part of the project - so we dont' care about differences. If file is not present in 'baseline': then it was recently added to the project - so we are not looking at differences. Checks motivated by report in issue #315. Signed-off-by: Henry Cox <[email protected]>
1 parent 08c7b2f commit 528c97b

File tree

5 files changed

+132
-34
lines changed

5 files changed

+132
-34
lines changed

bin/genhtml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3339,6 +3339,51 @@ sub dump_map
33393339
return $self;
33403340
}
33413341

3342+
sub check_version_match
3343+
{
3344+
my ($self, $baseline, $current) = @_;
3345+
return unless $lcovutil::versionCallback;
3346+
3347+
# skip files which were dropped (no longer in project) or were
3348+
# just added to the project (was not in the baseline - so we aren't
3349+
# looking for differences.
3350+
foreach my $curr ($current->files()) {
3351+
next unless $baseline->file_exists($curr);
3352+
my $currData = $current->data($curr);
3353+
my $curr_version = $currData->version();
3354+
my $baseData = $baseline->data($curr);
3355+
my $base_version = $baseData->version();
3356+
3357+
# silently compare version...
3358+
my $versionMatch =
3359+
lcovutil::checkVersionMatch($curr, $base_version, $curr_version,
3360+
"diff entry compare", 1);
3361+
if ($self->containsFile($curr)) {
3362+
# file is in 'diff' data: we expect the version to be different
3363+
# between baseline/current
3364+
if ($versionMatch) {
3365+
lcovutil::ignorable_error($lcovutil::ERROR_INCONSISTENT_DATA,
3366+
"File \"$curr\" appears in 'diff' data file '" .
3367+
$self->[DIFF_FILENAME] .
3368+
"' but 'baseline' and 'current' versions '" .
3369+
($curr_version ? $curr_version : '<undef>') .
3370+
"' match");
3371+
}
3372+
} else {
3373+
# not in 'diff': we expect the versions to be identical
3374+
if (!$versionMatch) {
3375+
lcovutil::ignorable_error($lcovutil::ERROR_INCONSISTENT_DATA,
3376+
"File \"$curr\" version changed from '" .
3377+
($base_version ? $base_version : '<undef') .
3378+
"' to '" .
3379+
($curr_version ? $curr_version : '<undef>') .
3380+
"' but file not found in 'diff' data file '" .
3381+
$self->[DIFF_FILENAME] . "'.");
3382+
}
3383+
}
3384+
}
3385+
}
3386+
33423387
sub check_path_consistency
33433388
{
33443389
# check that paths which appear in diff also appear in baseline or current
@@ -3350,6 +3395,11 @@ sub check_path_consistency
33503395
(ref($baseline) eq 'TraceFile' && ref($current) eq 'TraceFile') or
33513396
die("wrong arg types");
33523397

3398+
# check that files which are in both baseline and current and are NOT
3399+
# in the 'diff' data have the same version.
3400+
# That is: files whose version differs should appear in the diff data
3401+
$self->check_version_match($baseline, $current);
3402+
33533403
my %diffMap;
33543404
my %diffBaseMap;
33553405
foreach my $f ($self->files()) {

lib/lcovutil.pm

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6338,6 +6338,13 @@ sub _filterFile
63386338
my $path = ReadCurrentSource::resolve_path($source_file);
63396339
lcovutil::info(1, "extractVersion($path) for $source_file\n")
63406340
if $path ne $source_file;
6341+
# Note: this is checking the version of the 'current' file - even if
6342+
# we are actually reading the baseline version.
6343+
# - This is what we want, as the 'baseline read' is actually recovering/
6344+
# recreating the baseline source fromthe current source and the diff.
6345+
# - We already checked that the diff and the coverage DB baseline/current
6346+
# version data is consistent - so filtering will be accurate as long as
6347+
# we see the right 'current' source version.
63416348
my $fileVersion = lcovutil::extractFileVersion($path)
63426349
if $srcReader->notEmpty();
63436350
if (defined($fileVersion) &&

tests/gendiffcov/function/function.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,8 @@ fi
265265
for base in baseline_call baseline_nocall ; do
266266
for curr in current_call current_nocall ; do
267267
OUT=${base}_${curr}
268-
echo genhtml -o $OUT $DIFFCOV_OPTS --baseline-file ${base}.info --diff-file diff.txt ${curr}.info
269-
$COVER $GENHTML_TOOL -o $OUT $DIFFCOV_OPTS --baseline-file ${base}.info --diff-file diff.txt ${curr}.info --elide-path
268+
echo genhtml -o $OUT $DIFFCOV_OPTS --baseline-file ${base}.info --diff-file diff.txt ${curr}.info --ignore inconsistent
269+
$COVER $GENHTML_TOOL -o $OUT $DIFFCOV_OPTS --baseline-file ${base}.info --diff-file diff.txt ${curr}.info --elide-path --ignore inconsistent
270270
if [ $? != 0 ] ; then
271271
echo "genhtml $OUT failed"
272272
if [ 0 == $KEEP_GOING ] ; then

tests/gendiffcov/insensitive/insensitive.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,8 @@ ln -s ../simple/simple2.cpp.annotated TEst.cpp.annotated
233233
# need to not do the exiistence callback because the 'insensitive' name
234234
# won't be found but the version-check in the .info file already contains
235235
# a value - so we would get a version check error
236-
echo genhtml $DIFFCOV_OPTS --baseline-file ./baseline.info --diff-file diff.txt --annotate-script `pwd`/annotate.sh --show-owners all --show-noncode -o differential ./current.info --rc case_insensitive=1 --ignore-annotate,source $IGNORE --rc check_existence_before_callback=0
237-
$COVER $GENHTML_TOOL $DIFFCOV_OPTS --baseline-file ./baseline.info --diff-file diff.txt --annotate-script `pwd`/annotate.sh --show-owners all --show-noncode -o differential ./current.info --rc case_insensitive=1 $GENHTML_PORT --ignore annotate,source $IGNORE --rc check_existence_before_callback=0
236+
echo genhtml $DIFFCOV_OPTS --baseline-file ./baseline.info --diff-file diff.txt --annotate-script `pwd`/annotate.sh --show-owners all --show-noncode -o differential ./current.info --rc case_insensitive=1 --ignore-annotate,source $IGNORE --rc check_existence_before_callback=0 --ignore inconsistent
237+
$COVER $GENHTML_TOOL $DIFFCOV_OPTS --baseline-file ./baseline.info --diff-file diff.txt --annotate-script `pwd`/annotate.sh --show-owners all --show-noncode -o differential ./current.info --rc case_insensitive=1 $GENHTML_PORT --ignore annotate,source $IGNORE --rc check_existence_before_callback=0 --ignore inconsistent
238238
if [ 0 != $? ] ; then
239239
echo "ERROR: genhtml differential failed"
240240
if [ 0 == $KEEP_GOING ] ; then

0 commit comments

Comments
 (0)