Skip to content

Commit ce02b59

Browse files
committed
Add some error checking to 'select.pm' callback:
check that annotation and diff prerequisites are present. Signed-off-by: Henry Cox <henry.cox@mediatek.com>
1 parent 5d08038 commit ce02b59

File tree

5 files changed

+154
-38
lines changed

5 files changed

+154
-38
lines changed

Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,7 @@ test: check
267267
# once without - so we can merge the result
268268
check:
269269
if [ "x$(COVERAGE)" != 'x' ] ; then \
270-
if [ ! -d $(COVER_DB) ]; then \
271-
mkdir $(COVER_DB) ; \
272-
fi ; \
270+
mkdir -p $(COVER_DB) ; \
273271
echo "*** Run once, force parallel ***" ; \
274272
LCOV_FORCE_PARALLEL=1 $(MAKE) -s -C tests check LCOV_HOME=`pwd` ; \
275273
echo "*** Run again, no force ***" ; \
@@ -279,6 +277,10 @@ check:
279277
$(MAKE) -s -C example LCOV_HOME=`pwd`; \
280278
$(MAKE) -s -C tests report ; \
281279
fi
280+
grep uninitialized tests/test.log ; \
281+
@if [ 1 != $$? ] ; then \
282+
echo "found 'uninitialized'" ; \
283+
fi
282284

283285
# Files to be checked for coding style issue issues -
284286
# - anything containing "#!/usr/bin/env perl" or the like

man/genhtml.1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,12 @@ to a shell interpreter to be executed.
639639
The command line includes the script path followed by optional additional parameters
640640
separated by spaces. Care must be taken to provide proper quoting if script
641641
path or any parameter contains spaces or shell special characters.
642+
.br
643+
Note that module callbacks must be called via the 'list' method: they cannot be called as an executable with a space-separated set of arguments.
644+
.br
645+
For convenience: your callback module may need to implement its own
646+
'split_char' so that you can pass multiple parameters to your callback
647+
without interacting with genhtml's split mechanism.
642648
.PP
643649

644650
.IP 3. 3

scripts/criteria.pm

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ use Getopt::Long qw(GetOptionsFromArray);
4747
our @ISA = qw(Exporter);
4848
our @EXPORT_OK = qw(new);
4949

50-
use constant {SIGNOFF => 0,
51-
TYPES =>1,};
50+
use constant {
51+
SIGNOFF => 0,
52+
TYPES => 1,
53+
};
5254

5355
sub new
5456
{
@@ -57,27 +59,28 @@ sub new
5759
my $script = shift;
5860
my $standalone = $script eq $0;
5961
my @options = @_;
60-
my $function = 0;
61-
my $branch = 0;
62-
my $mcdc = 0;
62+
my $function = 0;
63+
my $branch = 0;
64+
my $mcdc = 0;
6365

64-
if (!GetOptionsFromArray(\@_, ('signoff' => \$signoff,
65-
'function' => \$function,
66-
'branch' => \$branch,
67-
'mcdc' => \$mcdc,
68-
)) ||
69-
(!$standalone && @_)) {
66+
if (!GetOptionsFromArray(\@_,
67+
('signoff' => \$signoff,
68+
'function' => \$function,
69+
'branch' => \$branch,
70+
'mcdc' => \$mcdc,)) ||
71+
(!$standalone && @_)
72+
) {
7073
print(STDERR "Error: unexpected option:\n " .
71-
join(' ', @options) .
72-
"\nusage: name type json-string [--signoff] [--branch] [--mcdc] [--function]\n");
74+
join(' ', @options) .
75+
"\nusage: name type json-string [--signoff] [--branch] [--mcdc] [--function]\n"
76+
);
7377
exit(1) if $standalone;
7478
return undef;
7579
}
7680
my @types = ('line');
77-
foreach my $t (['function', $function],
78-
['MC/DC', $mcdc],
79-
['branch', $branch]) {
80-
push(@types, $t->[0]) if $t->[1];
81+
foreach
82+
my $t (['function', $function], ['MC/DC', $mcdc], ['branch', $branch]) {
83+
push(@types, $t->[0]) if $t->[1];
8184
}
8285
my $self = [$signoff, \@types];
8386
return bless $self, $class;
@@ -92,20 +95,20 @@ sub check_criteria
9295
if ($type eq 'top') {
9396
# for the moment - only worry about the top-level coverage
9497

95-
my $s = '';
96-
foreach my $t (@{$self->[TYPES]}) {
97-
next unless exists($db->{$t});
98+
my $s = '';
99+
foreach my $t (@{$self->[TYPES]}) {
100+
next unless exists($db->{$t});
98101

99102
# our criteria is LBC + UNC + UIC == 0
100103
my $sep = '';
101104
my $sum = 0;
102105
my $msg = '';
103106
my $counts = '';
104-
my $data = $db->{$t};
105-
# say which type - if there is more than one
106-
$msg .= "$s$t: " if 1 <= $#{$self->[TYPES]};
107-
$s = ' ';
108-
107+
my $data = $db->{$t};
108+
# say which type - if there is more than one
109+
$msg .= "$s$t: " if 1 <= $#{$self->[TYPES]};
110+
$s = ' ';
111+
109112
foreach my $tla ('UNC', 'LBC', 'UIC') {
110113
$msg .= $sep . $tla;
111114
$counts .= $sep;

scripts/select.pm

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@
4242
# --owner: is a regular expression. A coverpoint is retained if its
4343
# "full name" field matches the regexp.
4444
#
45+
# --separator: is a character/regexp used to split 'list' arguments
46+
# (such as '--tla ..', '--sha ...', etc.
47+
# This may be useful to pass a delimited list to select.pm arguments
48+
# in a comma-separated list of genhaml arguments - for example:
49+
# genhtml ... --select-script select,pm,--sep,;,--tla,LBC;UNC
50+
#
4551
# When multiple selection criteria are applied (e.g., both age and owner),
4652
# then The coverpoint is retained if any of criteria match.
4753
#
@@ -67,6 +73,17 @@ use constant {
6773
SHA => 3,
6874
};
6975

76+
sub intersect
77+
{
78+
my $l = shift;
79+
my $m = shift;
80+
81+
my %contains;
82+
@contains{@$l} = (1) x @$l;
83+
84+
return grep { $contains{$_} } @$m;
85+
}
86+
7087
sub new
7188
{
7289
my $class = shift;
@@ -77,12 +94,14 @@ sub new
7794
my $exe = basename($script ? $script : $0);
7895
my $standalone = $script eq $0;
7996
my $help;
97+
my $delim = ',';
8098
if (!GetOptionsFromArray(\@_,
81-
("range:s" => \@range,
82-
'tla:s' => \@tla,
83-
'owner:s' => \@owner,
84-
'sha|cl:s' => \@sha,
85-
'help' => \$help)) ||
99+
("range:s" => \@range,
100+
'tla:s' => \@tla,
101+
'owner:s' => \@owner,
102+
'sha|cl:s' => \@sha,
103+
'separator:s' => \$delim,
104+
'help' => \$help)) ||
86105
$help ||
87106
(!$standalone && 0 != scalar(@_)) ||
88107
0 == scalar(@args) # expect at least one selection criteria
@@ -94,6 +113,7 @@ usage: $exe
94113
[--tla tla]*
95114
[--sha sha]*
96115
[--cl changelist]*
116+
[--separagor char]
97117
98118
Line is selected (return true) if any of the criteria match
99119
EOF
@@ -109,8 +129,9 @@ EOF
109129
join(' ', @args) . '"');
110130
}
111131
}
112-
@sha = split(',', join(',', @sha));
113-
@tla = split(',', join(',', @tla));
132+
@sha = split($delim, join($delim, @sha));
133+
@tla = split($delim, join($delim, @tla));
134+
@range = split($delim, join($delim, @range));
114135
foreach my $tla (@tla) {
115136
die("invalid tla '$tla' in \"$exe " . join(' ', @args) . '"')
116137
unless grep(/$tla/, keys(%lcovutil::tlaColor));
@@ -126,6 +147,34 @@ EOF
126147
unless $min <= $max;
127148
$range = [$min, $max];
128149
}
150+
# some error checking:
151+
# - can't look for date range, CL/SHA, or owner if there are no
152+
# annotations (so verify that there is an annotation script).
153+
# - without baseline data, there will be no coverage data other
154+
# than GNC, UNC.
155+
# - without 'diff' data, there will be no coverage data in
156+
# GNC, UNC, DUB, or DCB categories
157+
if (!@SourceFile::annotateScript && (@range || @owner || @sha)) {
158+
lcovutil::ignorable_error($lcovutil::ERROR_USAGE,
159+
"cannot select date/owner/SHA without '--annotate-script'");
160+
}
161+
my @intersect = intersect(['UBC', 'GBC', 'LBC', 'CBC', 'ECB', 'EUB',
162+
'GIC', 'UIC', 'DCB', 'DUB'
163+
],
164+
\@tla) unless @main::base_filenames;
165+
lcovutil::ignorable_error($lcovutil::ERROR_USAGE,
166+
"Will never see TLA other than 'UNC', 'GNC' without 'baseline' coverage data"
167+
) if (@intersect);
168+
169+
my @intersect2 = intersect(['GNC', 'UNC', 'DCB', 'DUB'], \@tla)
170+
unless $main::diff_filename;
171+
lcovutil::ignorable_error($lcovutil::ERROR_USAGE,
172+
"Will never see '" .
173+
join("', '", @intersect2) . "' " .
174+
($#intersect2 ? 'categories' : 'category') .
175+
' without --diff-file data')
176+
if (@intersect2);
177+
129178
my $self = [\@range, \@tla, \@owner, \@sha];
130179
return bless $self, $class;
131180
}

tests/gendiffcov/errs/msgtest.sh

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set +x
44
source ../../common.tst
55

66
rm -f test.cpp *.gcno *.gcda a.out *.info *.log *.json diff.txt loop*.rc markers.err* readThis.rc testing.rc
7-
rm -rf select criteria annotate empty unused_src scriptErr scriptFixed epoch inconsistent highlight etc mycache cacheFail expect subset context labels sortTables simplify_* simplify missingRestore
7+
rm -rf select criteria annotate empty unused_src scriptErr scriptFixed epoch inconsistent highlight etc mycache cacheFail expect subset context labels sortTables simplify_* simplify missingRestore selectErr1 selectErr2 selectErr3
88

99
clean_cover
1010

@@ -13,7 +13,7 @@ if [[ 1 == $CLEAN_ONLY ]] ; then
1313
fi
1414

1515
if ! type "${CXX}" >/dev/null 2>&1 ; then
16-
echo "Missing tool: $CXX" >&2
16+
echo "Missing CXX tool: $CXX" >&2
1717
exit 2
1818
fi
1919

@@ -341,8 +341,62 @@ if [ 0 != $? ] ; then
341341
fi
342342
fi
343343
344+
# test some 'select.pm' errors:
345+
# - --cl without annotate callback
346+
echo genhtml $DIFCOV_OPTS initial.info -o selectErr1 --select-script $SELECT_SCRIPT,--cl,123
347+
$COVER $GENHTML_TOOL $DIFFCOV_OPTS initial.info -o selectErr1 --select-script $SELECT_SCRIPT,--cl,123 2>&1 | tee selectErr1.log
348+
if [ 0 == ${PIPESTATUS[0]} ] ; then
349+
echo "ERROR: genhtml selectErr1 passed by accident"
350+
if [ 0 == $KEEP_GOING ] ; then
351+
exit 1
352+
fi
353+
fi
354+
grep "cannot select date/owner/" selectErr1.log
355+
if [ 0 != $? ] ; then
356+
echo "ERROR: missing script selectErr1 message"
357+
if [ 0 == $KEEP_GOING ] ; then
358+
exit 1
359+
fi
360+
fi
344361
345-
for arg in "--select-script $SELECT_SCRIPT,--range,0:10" \
362+
# - --tla LBC without baseline data
363+
echo genhtml $DIFCOV_OPTS initial.info -o selectErr2 --select-script $SELECT_SCRIPT,--tla,LBC
364+
$COVER $GENHTML_TOOL $DIFFCOV_OPTS initial.info -o selectErr2 --select-script $SELECT_SCRIPT,--tla,LBC 2>&1 | tee selectErr2.log
365+
if [ 0 == ${PIPESTATUS[0]} ] ; then
366+
echo "ERROR: genhtml selectErr2 passed by accident"
367+
if [ 0 == $KEEP_GOING ] ; then
368+
exit 1
369+
fi
370+
fi
371+
grep "Will never see TLA other than" selectErr2.log
372+
if [ 0 != $? ] ; then
373+
echo "ERROR: missing script selectErr2 message"
374+
if [ 0 == $KEEP_GOING ] ; then
375+
exit 1
376+
fi
377+
fi
378+
379+
# - --tla GNC without diff data
380+
echo genhtml $DIFCOV_OPTS --baseline-file initial.info build.info -o selectErr3 --select-script $SELECT_SCRIPT,--tla,GNC
381+
$COVER $GENHTML_TOOL $DIFFCOV_OPTS --baseline-file initial.info build.info -o selectErr3 --select-script $SELECT_SCRIPT,--tla,GNC 2>&1 | tee selectErr3.log
382+
if [ 0 == ${PIPESTATUS[0]} ] ; then
383+
echo "ERROR: genhtml selectErr3 passed by accident"
384+
if [ 0 == $KEEP_GOING ] ; then
385+
exit 1
386+
fi
387+
fi
388+
grep "Will never see 'GNC' category without --diff-file" selectErr3.log
389+
if [ 0 != $? ] ; then
390+
echo "ERROR: missing script selectErr3 message"
391+
if [ 0 == $KEEP_GOING ] ; then
392+
exit 1
393+
fi
394+
fi
395+
396+
397+
# note: select.pm checks that annotation happened (requires annotation
398+
# in order to check date range)
399+
for arg in "--annotate-script $ANNOTATE_SCRIPT --select-script $SELECT_SCRIPT,--range,0:10" \
346400
"--criteria-script $CRITERIA_SCRIPT,--signoff" \
347401
"--annotate-script $ANNOTATE_SCRIPT" \
348402
"--annotate-script $GITBLAME_SCRIPT,mediatek.com,--p4" \
@@ -500,6 +554,8 @@ if [ '' == $IGNORE_ANNOTATE ] ; then
500554
fi
501555
fi
502556
557+
558+
503559
# differential report with empty diff file
504560
touch diff.txt
505561
echo genhtml $DIFCOV_OPTS initial.info -o empty --diff diff.txt --annotate $ANNOTATE_SCTIPT --baseline-file initial.info

0 commit comments

Comments
 (0)