Skip to content

Commit 55e826c

Browse files
committed
If directory found anywhere that tracefile is expected, then find
all the tracefiles in the indicated subdirectory (aggregating them). This feature makes it much easier to find and reuse baseline and/or current coverage data which was is held in a per-testsuite DB. Signed-off-by: Henry Cox <[email protected]>
1 parent c85db9d commit 55e826c

File tree

5 files changed

+112
-7
lines changed

5 files changed

+112
-7
lines changed

bin/geninfo

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -942,19 +942,23 @@ sub find_files
942942
lcovutil::info("Scanning $directory for $ext files ...\n");
943943

944944
my $now = Time::HiRes::gettimeofday();
945-
my @found =
946-
`find "$directory" $maxdepth $follow -name \\*$ext -type f -o -name \\*$ext -type l 2>$lcovutil::devnull`;
945+
my ($stdout, $stderr, $code) = Capture::Tiny::capture {
946+
system(
947+
"find '$directory' $maxdepth $follow -name \\*$ext -type f -o -name \\*$ext -type l"
948+
);
949+
};
947950
lcovutil::ignorable_error($lcovutil::ERROR_UTILITY,
948-
"error in 'find \"$directory\" ...': $!")
949-
if ($?);
951+
"error in 'find \"$directory\" ...': $stderr")
952+
if ($code);
953+
950954
my $time = Time::HiRes::gettimeofday() - $now;
951955
if (exists($lcovutil::profileData{find}) &&
952956
exists($lcovutil::profileData{find}{$directory})) {
953957
$lcovutil::profileData{find}{$directory} += $time;
954958
} else {
955959
$lcovutil::profileData{find}{$directory} = $time;
956960
}
957-
chomp(@found);
961+
my @found = split(' ', $stdout);
958962
if (!@found) {
959963
if (!defined($processGcno) || $processGcno != 2) {
960964
$self->[2]->{$directory} = [

lib/lcovutil.pm

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,8 @@ our %languageExtensions = ('c' => 'c|h|i||C|H|I|icc|cpp|cc|cxx|hh|hpp|hxx',
311311
'python' => 'py',
312312
'java' => 'java');
313313

314+
our $info_file_pattern = '*.info';
315+
314316
# don't look more than 10 lines ahead when filtering (default)
315317
our $source_filter_lookahead = 10;
316318
# by default, don't treat expressions containing bitwise operators '|', '&', '~'
@@ -1079,6 +1081,7 @@ my %rc_common = (
10791081
"perl_file_extensions" => \$perlExtensions,
10801082
"python_file_extensions" => \$pythonExtensions,
10811083
"java_file_extensions" => \$javaExtensions,
1084+
'info_file_pattern' => \$info_file_pattern,
10821085
"filter_lookahead" => \$lcovutil::source_filter_lookahead,
10831086
"filter_bitwise_conditional" =>
10841087
\$lcovutil::source_filter_bitwise_are_conditional,
@@ -7127,6 +7130,7 @@ our $segmentIdx = 0;
71277130
sub find_from_glob
71287131
{
71297132
my @merge;
7133+
die("no files specified") unless (@_);
71307134
foreach my $pattern (@_) {
71317135

71327136
if (-f $pattern) {
@@ -7138,11 +7142,32 @@ sub find_from_glob
71387142
unless $^O =~ /Win/;
71397143

71407144
my @files = glob($pattern); # perl returns files in ASCII sorted order
7145+
71417146
lcovutil::ignorable_error($lcovutil::ERROR_EMPTY,
71427147
"no files matching pattern $pattern")
71437148
unless scalar(@files);
7144-
foreach my $f (@files) {
7145-
if (!(-r $f || -f $f)) {
7149+
for (my $i = 0; $i <= $#files; ++$i) {
7150+
my $f = $files[$i];
7151+
if (-d $f) {
7152+
my $cmd =
7153+
"find '$f' -name '$lcovutil::info_file_pattern' -type f";
7154+
my ($stdout, $stderr, $code) = Capture::Tiny::capture {
7155+
system($cmd);
7156+
};
7157+
# can fail due to unreadable entry - but might still
7158+
# have returned data to process
7159+
lcovutil::ignorable_error($lcovutil::ERROR_UTILITY,
7160+
"error in \"$cmd\": $stderr")
7161+
if $code;
7162+
my @found = split(' ', $stdout);
7163+
lcovutil::ignorable_error($lcovutil::ERROR_EMPTY,
7164+
"no files matching '$lcovutil::info_file_pattern' found in $f"
7165+
) unless (@found);
7166+
push(@files, @found);
7167+
next;
7168+
}
7169+
7170+
unless (-r $f || -f $f) {
71467171
lcovutil::ignorable_error($lcovutil::ERROR_MISSING,
71477172
"'$f' found from pattern '$pattern' is not a readable file"
71487173
);
@@ -7151,6 +7176,10 @@ sub find_from_glob
71517176
push(@merge, $f);
71527177
}
71537178
}
7179+
lcovutil::ignorable_error($lcovutil::ERROR_EMPTY,
7180+
"no matching file found in '['" . join(', ', @_) . "]'")
7181+
unless (@merge);
7182+
71547183
return @merge;
71557184
}
71567185

man/genhtml.1

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,14 @@ The coverage data files specified by
938938
.I baseline\-file\-pattern
939939
is read and used as the baseline for classifying the change in coverage represented by the coverage counts in
940940
.IR tracefile\-patterns .
941+
If
942+
.I baseline\-file\-pattern
943+
is a directory, then genhtml will search the directory for all files ending in '.info'.
944+
See the
945+
.I info_file_extension
946+
section in
947+
.B man(5) lcovrc
948+
for how to change this pattern.
941949

942950
In general, you should specify a diff file in unified diff format via
943951
.B \-\-diff\-file

man/lcovrc.5

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,11 @@ max_message_count = 100
198198
.br
199199
#warn_once_per_file = 1
200200

201+
# extension associated with lcov trce files
202+
.br
203+
#info_file_pattern = *.info
204+
.br
205+
201206
# list of file extensions which should be treated as C/C++ code
202207
.br
203208
# (comma-separated list)
@@ -799,6 +804,14 @@ This option is used by genhtml and lcov.
799804

800805
.PP
801806

807+
.BR info_file_pattern " ="
808+
.IR str
809+
.IP
810+
Specify a glob-match pattern associated with lcov trace files (suitable as an argument to 'find'.
811+
If not specified, the default is '*.info'.
812+
813+
.PP
814+
802815
.BR c_file_extensions " ="
803816
.IR str[,str]+
804817
.IP

tests/lcov/errs/errs.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ if [ "${VER[0]}" -lt 5 ] ; then
9797
fi
9898
9999
rm -f *.log *.json dumper*
100+
rm -rf emptyDir
100101
101102
if [ "x$COVER" != 'x' ] && [ 0 != $LOCAL_COVERAGE ] ; then
102103
cover -delete
@@ -242,6 +243,56 @@ for f in exceptionBranch ; do
242243
fi
243244
done
244245
246+
mkdir -p emptyDir
247+
248+
echo lcov $LCOV_OPTS -a emptyDir -a exceptionBranch1.info -o emptyDir.info
249+
$COVER $LCOV_TOOL $LCOV_OPTS -a emptyDir -a exceptionBranch1.info -o emptyDir.info 2>&1 | tee emptyDir.log
250+
if [ 0 == ${PIPESTATUS[0]} ] ; then
251+
echo "failed to notice empty dir"
252+
status=1
253+
if [ 0 == $KEEP_GOING ] ; then
254+
exit $status
255+
fi
256+
fi
257+
grep 'no files matching' emptyDir.log
258+
if [ 0 != $? ] ; then
259+
echo "did not find expected empty dir message"
260+
fi
261+
echo lcov $LCOV_OPTS -a emptyDir -a exceptionBranch1.info -o emptyDir.info --ignore empty
262+
$COVER $LCOV_TOOL $LCOV_OPTS -a emptyDir -a exceptionBranch1.info -o emptyDir.info --ignore empty 2>&1 | tee emptyDir2.log
263+
if [ 0 != ${PIPESTATUS[0]} ] ; then
264+
echo "failed to ignore empty dir"
265+
status=1
266+
if [ 0 == $KEEP_GOING ] ; then
267+
exit $status
268+
fi
269+
fi
270+
271+
# trigger error from unreadable directory
272+
chmod ugo-rx emptyDir
273+
echo lcov $LCOV_OPTS -a emptyDir -a exceptionBranch1.info -o emptyDir.info
274+
$COVER $LCOV_TOOL $LCOV_OPTS -a emptyDir -a exceptionBranch1.info -o emptyDir.info 2>&1 | tee noRead.log
275+
if [ 0 == ${PIPESTATUS[0]} ] ; then
276+
echo "failed to notice unreadable"
277+
status=1
278+
if [ 0 == $KEEP_GOING ] ; then
279+
exit $status
280+
fi
281+
fi
282+
grep 'error in "find' noRead.log
283+
if [ 0 != $? ] ; then
284+
echo "did not find expected unreadable dir message"
285+
fi
286+
echo lcov $LCOV_OPTS -a emptyDir -a exceptionBranch1.info -o emptyDir.info --ignore utility,empty
287+
$COVER $LCOV_TOOL $LCOV_OPTS -a emptyDir -a exceptionBranch1.info -o emptyDir.info --ignore utility,empty 2>&1 | tee noRead2.log
288+
if [ 0 != ${PIPESTATUS[0]} ] ; then
289+
echo "failed to ignore unreadable dir"
290+
status=1
291+
if [ 0 == $KEEP_GOING ] ; then
292+
exit $status
293+
fi
294+
fi
295+
245296
246297
if [ 0 == $status ] ; then
247298
echo "Tests passed"

0 commit comments

Comments
 (0)