Skip to content

Commit

Permalink
Fix 'exclude region' overlap error message.
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Cox <[email protected]>
  • Loading branch information
henry2cox committed Oct 4, 2024
1 parent d1f9d85 commit b7ebec0
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 27 deletions.
64 changes: 40 additions & 24 deletions lib/lcovutil.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5600,18 +5600,26 @@ sub parseLines
my @excludes;
if (defined($lcovutil::cov_filter[$lcovutil::FILTER_EXCLUDE_REGION])) {
push(@excludes,
[$excl_start, $excl_stop, \$exclude_region, 3 | EXCLUDE_REGION]);
[$excl_start, $excl_stop,
\$exclude_region, 3 | EXCLUDE_REGION,
$lcovutil::EXCL_START, $lcovutil::EXCL_STOP
]);
} else {
$excl_line = undef;
}

if (defined($lcovutil::cov_filter[$lcovutil::FILTER_EXCLUDE_BRANCH])) {
push(@excludes,
[$excl_ex_start, $excl_ex_stop,
\$exclude_exception_region, 4 | EXCLUDE_BRANCH_REGION
\$exclude_exception_region, 4 | EXCLUDE_BRANCH_REGION,
$lcovutil::EXCL_BR_START, $lcovutil::EXCL_BR_STOP,
],
[$excl_br_start, $excl_br_stop,
\$exclude_br_region, 2 | EXCLUDE_BRANCH_REGION
[$excl_br_start,
$excl_br_stop,
\$exclude_br_region,
2 | EXCLUDE_BRANCH_REGION,
$lcovutil::EXCL_EXCEPTION_BR_START,
$lcovutil::EXCL_EXCEPTION_BR_STOP,
]);
} else {
$excl_br_line = undef;
Expand All @@ -5632,18 +5640,24 @@ sub parseLines
}

foreach my $d (@excludes) {
# note: $d->[4] is the 'start' string (not converted to perl regexp)
# $d->[5] is the 'stop' string
my ($start, $stop, $ref, $reason) = @$d;
if ($_ =~ $start) {
lcovutil::ignorable_error($lcovutil::ERROR_MISMATCH,
"$filename: overlapping exclude directives. Found $start at line $line - but no matching $stop for $start at line "
. $ref->[0])
"$filename: overlapping exclude directives. Found " .
$d->[4] .
" at line $line - but no matching " . $d->[5] .
' for ' . $d->[4] . ' at line ' . $$ref->[0])
if $$ref;
$$ref = [$line, $reason];
last;
} elsif ($_ =~ $stop) {
lcovutil::ignorable_error($lcovutil::ERROR_MISMATCH,
"$filename: found $stop directive at line $line without matching $start directive"
) unless $$ref;
"$filename: found " . $d->[5] .
" directive at line $line without matching " .
$d->[4] . ' directive')
unless $$ref;
$$ref = undef;
last;
}
Expand Down Expand Up @@ -5675,22 +5689,24 @@ sub parseLines
$exclude_exception_region ? $exclude_exception_region->[1] : 0
) | $exclude_branch_line | $exclude_exception_branch_line);
}
lcovutil::ignorable_error($lcovutil::ERROR_MISMATCH,
"$filename: unmatched $lcovutil::EXCL_START at line " .
$exclude_region->[0] .
" - saw EOF while looking for matching $lcovutil::EXCL_STOP"
) if $exclude_region;
lcovutil::ignorable_error($lcovutil::ERROR_MISMATCH,
"$filename: unmatched $lcovutil::EXCL_BR_START at line " .
$exclude_br_region->[0] .
" - saw EOF while looking for matching $lcovutil::EXCL_BR_STOP"
) if $exclude_br_region;
lcovutil::ignorable_error($lcovutil::ERROR_MISMATCH,
"$filename: unmatched $lcovutil::EXCL_EXCEPTION_BR_START at line " .
$exclude_exception_region->[0] .
" - saw EOF while looking for matching $lcovutil::EXCL_EXCEPTION_BR_STOP"
) if $exclude_exception_region;

foreach my $t ([$exclude_region, $lcovutil::EXCL_START,
$lcovutil::EXCL_STOP
],
[$exclude_br_region, $lcovutil::EXCL_BR_START,
$lcovutil::EXCL_BR_STOP
],
[$exclude_exception_region,
$lcovutil::EXCL_EXCEPTION_BR_START,
$lcovutil::EXCL_EXCEPTION_BR_STOP
]
) {
my ($key, $start, $stop) = @$t;
lcovutil::ignorable_error($lcovutil::ERROR_MISMATCH,
"$filename: unmatched $start at line " .
$key->[0] .
" - saw EOF while looking for matching $stop"
) if ($key);
}
my $data = $self->[0];
$data->[FILENAME] = $filename;
$data->[SOURCE] = $sourceLines;
Expand Down
6 changes: 6 additions & 0 deletions tests/lcov/extract/extract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ int main(int argc, const char *argv[])
printf("Hai\n");
delete[] a;

// TEST_OVERLAP_START
// TEST_OVERLAP_START
std::string str("asdads");
str = "cd";
// TEST_OVERLAP_END

//TEST_DANGLING_START
//TEST_UNMATCHED_END

std::cout << str << std::endl;

Expand Down
55 changes: 52 additions & 3 deletions tests/lcov/extract/extract.sh
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ fi
# workaround: depending on compiler verision, we see a coverpoint on the
# close brace line (gcc/6 for example) or we don't (gcc/10 for example)
BRACE_LINE='^DA:28'
BRACE_LINE='^DA:34'
MARKER_LINES=`grep -v $BRACE_LINE internal.info | grep -c "^DA:"`
# check 'no-markers': is the excluded line back?
Expand All @@ -513,6 +513,55 @@ if [ $NOMARKER_LINES != '13' ] ; then
fi
fi
# override excl region start/stop and look for error
$COVER $CAPTURE . $LCOV_OPTS --no-external -o regionErr1.info --rc lcov_excl_start=TEST_OVERLAP_START --rc lcov_excl_stop=TEST_OVERLAP_END --msg-log
if [ $? == 0 ] ; then
echo "error expected overlap fail"
if [ $KEEP_GOING == 0 ] ; then
exit 1
fi
fi
grep -E 'overlapping exclude directives. Found TEST_OVERLAP_START at .+ but no matching TEST_OVERLAP_END for TEST_OVERLAP_START at line ' regionErr1.msg
if [ 0 != $? ] ; then
echo "error expected overlap message but didn't find"
if [ $KEEP_GOING == 0 ] ; then
exit 1
fi
fi
$COVER $CAPTURE . $LCOV_OPTS --no-external -o regionErr2.info --rc lcov_excl_start=TEST_DANGLING_START --rc lcov_excl_stop=TEST_DANGLING_END --msg-log
if [ $? == 0 ] ; then
echo "error expected dangling fail"
if [ $KEEP_GOING == 0 ] ; then
exit 1
fi
fi
grep -E 'unmatched TEST_DANGLING_START at line .+ saw EOF while looking for matching TEST_DANGLING_END' regionErr2.msg
if [ 0 != $? ] ; then
echo "error expected dangling message but didn't find"
if [ $KEEP_GOING == 0 ] ; then
exit 1
fi
fi
$COVER $CAPTURE . $LCOV_OPTS --no-external -o regionErr3.info --rc lcov_excl_start=TEST_UNMATCHED_START --rc lcov_excl_stop=TEST_UNMATCHED_END --msg-log
if [ $? == 0 ] ; then
echo "error expected unmatched fail"
if [ $KEEP_GOING == 0 ] ; then
exit 1
fi
fi
grep -E 'found TEST_UNMATCHED_END directive at line .+ without matching TEST_UNMATCHED_START' regionErr3.msg
if [ 0 != $? ] ; then
echo "error expected unmapted message but didn't find"
if [ $KEEP_GOING == 0 ] ; then
exit 1
fi
fi
# override excl_line start/stop - and make sure we didn't match
$COVER $CAPTURE . $LCOV_OPTS --no-external -o excl.info --rc lcov_excl_start=nomatch_start --rc lcov_excl_stop=nomatch_end
if [ $? != 0 ] ; then
Expand Down Expand Up @@ -573,7 +622,7 @@ if [ 0 != ${PIPESTATUS[0]} ] ; then
fi
fi
BRACE_LINE="DA:28"
BRACE_LINE="DA:34"
# a bit of a hack: gcc/10 doesn't put a DA entry on the closing brace
COUNT=`grep -v $BRACE_LINE omit.info | grep -c ^DA:`
if [ $COUNT != '11' ] ; then
Expand Down Expand Up @@ -650,7 +699,7 @@ if [ $? != 0 ] ; then
exit 1
fi
fi
#munge the checksum in the outpt file
#munge the checksum in the output file
perl -i -pe 's/DA:6,1.+/DA:6,1,abcde/g' < checksum.info > mismatch.info
$COVER $LCOV_TOOL $LCOV_OPTS --summary mismatch.info --checksum
if [ $? == 0 ] ; then
Expand Down

0 comments on commit b7ebec0

Please sign in to comment.