Skip to content

Commit 6dc0bba

Browse files
committed
Additional error checking: callback scripts, data inconsistency
Signed-off-by: Henry Cox <[email protected]>
1 parent d9b3c6b commit 6dc0bba

File tree

9 files changed

+149
-79
lines changed

9 files changed

+149
-79
lines changed

bin/genhtml

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2642,8 +2642,25 @@ sub _categorizeLineCov
26422642
my $linedata = $lineDataMap->{$line};
26432643
my $tla;
26442644
if ($linedata->type() eq "insert") {
2645+
if (!$linedata->in_curr()) {
2646+
# can get here if the 'diff' file is wrong with respect to
2647+
# baseline vs. current coverage data - e.g., showing that
2648+
# an unchanged line has a difference
2649+
lcovutil::ignorable_error($lcovutil::ERROR_INCONSISTENT_DATA,
2650+
"$filename:$line: 'diff' data claims this line is inserted but it is not in 'current' coverage data"
2651+
);
2652+
next;
2653+
}
26452654
$tla = ($linedata->curr_count() > 0) ? "GNC" : "UNC";
26462655
} elsif ($linedata->type() eq "delete") {
2656+
if (!$linedata->in_base()) {
2657+
# similarly: can get here if the diff vs baseline/current data
2658+
# is inconsistent.
2659+
lcovutil::ignorable_error($lcovutil::ERROR_INCONSISTENT_DATA,
2660+
"$filename:$line: 'diff' data claims this line is deleted but it is not in 'baseline' coverage data"
2661+
);
2662+
next;
2663+
}
26472664
$tla = ($linedata->base_count() > 0) ? "DCB" : "DUB";
26482665
} else {
26492666
$linedata->type() eq "equal" or
@@ -2700,8 +2717,8 @@ sub _categorizeBranchCov
27002717
my $data;
27012718
if (!exists($lineDataMap->{$line})) {
27022719
# we expect the associated line to also have line coverage data
2703-
lcovutil::ignorable_error($lcovutil::ERROR_UNKNOWN_CATEGORY,
2704-
"line $line of $filename has branchcov but no linecov data");
2720+
lcovutil::ignorable_error($lcovutil::ERROR_INCONSISTENT_DATA,
2721+
"line $filename:$line has branchcov but no linecov data");
27052722
# maybe should skip this branch if no line data - rather
27062723
# than building fake data.
27072724
$data = LineData->new($type);
@@ -2746,7 +2763,8 @@ sub _categorizeBranchCov
27462763
my @baseBlocks = defined($base) ? $base->blocks() : ();
27472764

27482765
if ($type eq 'insert') {
2749-
lcovutil::ignorable_error($lcovutil::ERROR_INTERNAL,
2766+
# can get here if diff data vs baseline/current is not consistent
2767+
lcovutil::ignorable_error($lcovutil::ERROR_INCONSISTENT_DATA,
27502768
"baseline branch data should not be defined for inserted line $filename:$line"
27512769
) if defined($base);
27522770

@@ -2759,7 +2777,8 @@ sub _categorizeBranchCov
27592777
}
27602778
}
27612779
} elsif ($type eq 'delete') {
2762-
lcovutil::ignorable_error($lcovutil::ERROR_INTERNAL,
2780+
# similarly: get here if diff data vs baseline/current is not consistent
2781+
lcovutil::ignorable_error($lcovutil::ERROR_INCONSISTENT_DATA,
27632782
"current branch data should not be defined for deleted line $filename:$line"
27642783
) if defined($curr);
27652784

@@ -2916,8 +2935,8 @@ sub _categorizeFunctionCov
29162935
if (!defined($base)) {
29172936
# either this line was inserted or the line hasn't changed but
29182937
# wasn't recognized as a function before (e.g., unused template)
2919-
lcovutil::ignorable_error($lcovutil::ERROR_INTERNAL,
2920-
"unexpected undef baseline function data for deleted $filename:$line"
2938+
lcovutil::ignorable_error($lcovutil::ERROR_INCONSISTENT_DATA,
2939+
"$filename:$line: unexpected undef baseline function data for deleted $name"
29212940
) if $type eq 'delete';
29222941
my $hit = $curr->hit();
29232942
my $tla = ((0 == $hit) ? ($type eq 'insert' ? 'UNC' : 'UIC') :
@@ -2931,8 +2950,8 @@ sub _categorizeFunctionCov
29312950
$categorized->addAliasDifferential($alias, [$hit, $tla]);
29322951
}
29332952
} elsif (!defined($curr)) {
2934-
lcovutil::ignorable_error($lcovutil::ERROR_INTERNAL,
2935-
"unexpected undef current function data for inserted $filename:$line"
2953+
lcovutil::ignorable_error($lcovutil::ERROR_INCONSISTENT_DATA,
2954+
"$filename:$line: unexpected undef current function data for inserted $name"
29362955
) if $type eq 'insert';
29372956
my $hit = $base->hit();
29382957
my $tla = ((0 == $hit) ? ($type eq 'delete' ? 'DUB' : 'EUB') :

man/genhtml.1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2519,7 +2519,10 @@ Unexpected syntax found in .info file.
25192519
.IP inconsistent: 3
25202520
Files have been moved or repository history presented by
25212521
.B \-\-diff\-file
2522-
data is not consistent with coverage data; for example, an 'inserted' line has baseline coverage data. These issues are likely to be caused by inconsistent handling in the 'diff' and 'annotate' scripts.
2522+
data is not consistent with coverage data; for example, an 'inserted' line has baseline coverage data. These issues are likely to be caused by inconsistent handling in the 'diff' data compared to the 'baseline' and 'current' coverage data (e.g., using different source versions to collect the data but incorrectly annotating those differences), or by inconsistent treatment in the 'annotate' script.
2523+
Consider using a
2524+
.B \-\-version\-script
2525+
to guard against version mismatches.
25232526
.PP
25242527

25252528
.IP internal: 3

scripts/criteria

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ use JSON;
4747
my $obj = criteria->new($0, @ARGV);
4848

4949
my $signoff;
50-
if (!GetOptions('signoff' => \$signoff)) {
50+
if (!defined($obj) ||
51+
!GetOptions('signoff' => \$signoff)) {
5152
print(STDERR "usage: name type json-string [--signoff]\n");
5253
exit(1) if caller;
5354
return undef;

scripts/criteria.pm

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,18 @@ use constant {SIGNOFF => 0,};
4949

5050
sub new
5151
{
52-
my $class = shift;
53-
my $signoff = 0;
54-
my $script = shift;
52+
my $class = shift;
53+
my $signoff = 0;
54+
my $script = shift;
55+
my $standalone = $script eq $0;
56+
my @options = @_;
5557

56-
if (!GetOptionsFromArray(\@_, ('signoff' => \$signoff))) {
57-
print(STDERR "usage: name type json-string [--signoff]\n");
58-
exit(1) if ($script eq $0);
58+
if (!GetOptionsFromArray(\@_, ('signoff' => \$signoff)) ||
59+
(!$standalone && @_)) {
60+
print(STDERR "Error: unexpected option:\n " .
61+
join(' ', @options) .
62+
"\nusage: name type json-string [--signoff]\n");
63+
exit(1) if $standalone;
5964
return undef;
6065
}
6166

scripts/gitblame.pm

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,20 @@ sub new
6363
my $prefix;
6464
my @args = @_;
6565
my @abbrev;
66-
my $exe = basename($script ? $script : $0);
66+
my $exe = basename($script ? $script : $0);
67+
my $standalone = $script eq $0;
6768
my $help;
6869
if (!GetOptionsFromArray(\@_,
6970
("p4" => \$mapP4,
7071
"prefix:s" => \$prefix,
7172
'abbrev:s' => \@abbrev,
7273
'help' => \$help)) ||
74+
(scalar(@_) >= 2) ||
7375
$help
7476
) {
7577
print(STDERR
7678
"usage: $exe [--p4] [--abbrev regexp]* [domain] pathname\n");
77-
exit($help ? 0 : 1) if ($script eq $0);
79+
exit(scalar(@_) >= 2 && $help ? 0 : 1) if $standalone;
7880
return undef;
7981
}
8082
my $internal_domain = shift;

scripts/p4annotate.pm

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ sub new
6969
my $script = shift; # this should be 'me'
7070
#other arguments are as passed...
7171
my $logfile;
72-
my $verify = 0; # if set, check that we merged local changes correctly
73-
my $exe = basename($script ? $script : $0);
72+
my $verify = 0; # if set, check that we merged local changes correctly
73+
my $exe = basename($script ? $script : $0);
74+
my $standalone = $0 eq $script;
7475

7576
if (exists($ENV{LOG_P4ANNOTATE})) {
7677
$logfile = $ENV{LOG_P4ANNOTATE};
@@ -80,10 +81,11 @@ sub new
8081
("verify" => \$verify,
8182
"log=s" => \$logfile,
8283
'help' => \$help)) ||
84+
(!$standalone && scalar(@_)) ||
8385
$help
8486
) {
8587
print(STDERR "usage: $exe [--log logfile] [--verify] filename\n");
86-
exit($help ? 0 : 1) if $script eq $0;
88+
exit(scalar(@_) == 0 && $help ? 0 : 1) if $standalone;
8789
return undef;
8890
}
8991

scripts/select.pm

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,9 @@ sub new
7373
my $script = shift;
7474

7575
my (@range, @tla, @owner, @sha);
76-
my @args = @_;
77-
my $exe = basename($script ? $script : $0);
76+
my @args = @_;
77+
my $exe = basename($script ? $script : $0);
78+
my $standalone = $script eq $0;
7879
my $help;
7980
if (!GetOptionsFromArray(\@_,
8081
("range:s" => \@range,
@@ -83,6 +84,7 @@ sub new
8384
'sha|cl:s' => \@sha,
8485
'help' => \$help)) ||
8586
$help ||
87+
(!$standalone && 0 != scalar(@_)) ||
8688
0 == scalar(@args) # expect at least one selection criteria
8789
) {
8890
print(STDERR <<EOF);
@@ -96,7 +98,7 @@ usage: $exe
9698
Line is selected (return true) if any of the criteria match
9799
EOF
98100

99-
exit($help ? 0 : 1) if ($script eq $0);
101+
exit($help && 0 == scalar(@_) ? 0 : 1) if $standalone;
100102
return undef;
101103
}
102104
# precompile:
@@ -137,29 +139,23 @@ sub select
137139
# for a contiguous region of context lines (e.g., which are part
138140
# of some SHA) which are not code and thus have no data
139141
my $tla = $lineData->tla();
140-
return 1 if grep(/$tla/, @{$self->[TLA]});
142+
return 1 if grep({ $tla eq $_ } @{$self->[TLA]});
141143
}
142144

143145
if (defined($annotateData)) {
144146
my $age = $annotateData->age();
145-
foreach my $a (@{$self->[AGE]}) {
146-
return 1
147-
if ($age >= $a->[0] &&
148-
$age <= $a->[1]);
149-
}
150-
my $commit = $annotateData->commit();
151-
if (defined($commit) &&
152-
'' ne $commit) {
147+
return 1
148+
if grep({ $age >= $_->[0] && $age <= $_->[1] } @{$self->[AGE]});
153149

154-
foreach my $sha (@{$self->[SHA]}) {
155-
# match at head of commit ID string
156-
return 1 if $commit =~ /^$sha/;
157-
}
158-
}
150+
my $commit = $annotateData->commit();
151+
# match at head of commit ID string
152+
return 1
153+
if (defined($commit) &&
154+
'' ne $commit &&
155+
grep({ $commit =~ /^$_/ } @{$self->[SHA]}));
159156

160-
foreach my $re (@{$self->[OWNER]}) {
161-
return 1 if $annotateData->full_name() =~ $re;
162-
}
157+
my $fullname = $annotateData->full_name();
158+
return 1 if grep({ $fullname =~ $_ } @{$self->[OWNER]});
163159
}
164160
lcovutil::info(1,
165161
"drop "

tests/gendiffcov/errs/msgtest.sh

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ GET_VERSION=$SCRIPTS_DIR/getp4version
112112
SELECT_SCRIPT=$SCRIPTS_DIR/select.pm
113113
CRITERIA_SCRIPT=$SCRIPTS_DIR/criteria.pm
114114
ANNOTATE_SCRIPT=$SCRIPTS_DIR/p4annotate.pm
115+
GITBLAME_SCRIPT=$SCRIPTS_DIR/gitblame.pm
116+
GITVERSION_SCRIPT=$SCRIPTS_DIR/gitversion.pm
115117

116118

117119
# filter out the compiler-generated _GLOBAL__sub_... symbol
@@ -120,7 +122,7 @@ LCOV_OPTS="$LCOV_BASE"
120122
DIFFCOV_OPTS="--filter line,branch,function --function-coverage --branch-coverage --highlight --demangle-cpp --prefix $PARENT_VERSION $PROFILE "
121123

122124
rm -f test.cpp *.gcno *.gcda a.out *.info *.log *.json diff.txt
123-
rm -rf select criteria annotate empty unused_src
125+
rm -rf select criteria annotate empty unused_src scriptErr scriptFixed
124126

125127
if [ "x$COVER" != 'x' ] && [ 0 != $LOCAL_COVERAGE ] ; then
126128
cover -delete
@@ -315,9 +317,13 @@ if [ 0 != $? ] ; then
315317
fi
316318
fi
317319
318-
for arg in "--select-script $SELECT_SCRIPT" \
319-
"--criteria-script $CRITERIA_SCRIPT" \
320+
for arg in "--select-script $SELECT_SCRIPT,--range,0:10" \
321+
"--criteria-script $CRITERIA_SCRIPT,--signoff" \
320322
"--annotate-script $ANNOTATE_SCRIPT" \
323+
"--annotate-script $GITBLAME_SCRIPT,mediatek.com,--p4" \
324+
"--annotate-script $GITBLAME_SCRIPT,--p4" \
325+
"--annotate-script $GITBLAME_SCRIPT" \
326+
" --ignore version --version-script $GITVERSION_SCRIPT,--md5,--p4" \
321327
; do
322328
echo genhtml $DIFCOV_OPTS initial.info -o scriptErr ${arg},-x
323329
$COVER $GENHTML_TOOL $DIFFCOV_OPTS initial.info -o scriptErr ${arg},-x 2>&1 | tee script_err.log
@@ -334,6 +340,15 @@ for arg in "--select-script $SELECT_SCRIPT" \
334340
exit 1
335341
fi
336342
fi
343+
# run again without error
344+
echo genhtml $DIFCOV_OPTS initial.info -o scriptFixed ${arg}
345+
$COVER $GENHTML_TOOL $DIFFCOV_OPTS initial.info -o scriptFixed ${arg} --ignore annotate 2>&1 | tee script_err.log
346+
if [ 0 != ${PIPESTATUS[0]} ] ; then
347+
echo "ERROR: genhtml scriptFixed failed"
348+
if [ 0 == $KEEP_GOING ] ; then
349+
exit 1
350+
fi
351+
fi
337352
done
338353
339354
echo genhtml $DIFCOV_OPTS initial.info -o select --select-script ./select.sh --rc compute_file_version=1

0 commit comments

Comments
 (0)