Skip to content

Commit 5d2ff1f

Browse files
committed
Enhance 'criteria.pm' callback to check for unexercised
function/branch/mcdc coverpoints. Signed-off-by: Henry Cox <henry.cox@mediatek.com>
1 parent 8faf493 commit 5d2ff1f

File tree

1 file changed

+36
-13
lines changed

1 file changed

+36
-13
lines changed

scripts/criteria.pm

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
#
2121
# This script is used as a genhtml "--criteria-script criteria" callback.
2222
# It is called by genhtml at each level of hierarchy - but ignores all but
23-
# the top level, and looks only at line coverage.
23+
# the top level, and looks at line coverage and zero or more of function,
24+
# branch, and MC/DC coverage.
2425
#
2526
# Format of the JSON input is:
2627
# {"line":{"found":10,"hit:2,"UNC":2,..},"function":{...},"branch":{}"
@@ -33,9 +34,11 @@
3334
#
3435
# If passed the "--suppress" flag, this script will exit with status 0,
3536
# even if the coverage criteria is not met.
36-
# genhtml --criteria-script 'path/criteria --signoff' ....
37+
# genhtml --criteria-script \
38+
# 'path/criteria --signoff [--function] [--branch] [--mcdc]' ....
3739
#
3840
# It is not hard to envision much more complicated coverage criteria.
41+
3942
package criteria;
4043

4144
use strict;
@@ -44,7 +47,8 @@ use Getopt::Long qw(GetOptionsFromArray);
4447
our @ISA = qw(Exporter);
4548
our @EXPORT_OK = qw(new);
4649

47-
use constant {SIGNOFF => 0,};
50+
use constant {SIGNOFF => 0,
51+
TYPES =>1,};
4852

4953
sub new
5054
{
@@ -53,17 +57,29 @@ sub new
5357
my $script = shift;
5458
my $standalone = $script eq $0;
5559
my @options = @_;
60+
my $function = 0;
61+
my $branch = 0;
62+
my $mcdc = 0;
5663

57-
if (!GetOptionsFromArray(\@_, ('signoff' => \$signoff)) ||
64+
if (!GetOptionsFromArray(\@_, ('signoff' => \$signoff,
65+
'function' => \$function,
66+
'branch' => \$branch,
67+
'mcdc' => \$mcdc,
68+
)) ||
5869
(!$standalone && @_)) {
5970
print(STDERR "Error: unexpected option:\n " .
6071
join(' ', @options) .
61-
"\nusage: name type json-string [--signoff]\n");
72+
"\nusage: name type json-string [--signoff] [--branch] [--mcdc] [--function]\n");
6273
exit(1) if $standalone;
6374
return undef;
6475
}
65-
66-
my $self = [$signoff];
76+
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+
}
82+
my $self = [$signoff, \@types];
6783
return bless $self, $class;
6884
}
6985

@@ -76,28 +92,35 @@ sub check_criteria
7692
if ($type eq 'top') {
7793
# for the moment - only worry about the top-level coverage
7894

79-
if (exists($db->{'line'})) {
95+
my $s = '';
96+
foreach my $t (@{$self->[TYPES]}) {
97+
next unless exists($db->{$t});
98+
8099
# our criteria is LBC + UNC + UIC == 0
81100
my $sep = '';
82101
my $sum = 0;
83102
my $msg = '';
84103
my $counts = '';
85-
my $lines = $db->{'line'};
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+
86109
foreach my $tla ('UNC', 'LBC', 'UIC') {
87110
$msg .= $sep . $tla;
88111
$counts .= $sep;
89-
if (exists $lines->{$tla}) {
90-
my $count = $lines->{$tla};
112+
if (exists $data->{$tla}) {
113+
my $count = $data->{$tla};
91114
$sum += $count;
92115
$counts .= "$count";
93116
} else {
94117
$counts .= "0";
95118
}
96119
$sep = ' + ';
97120
}
98-
$fail = $sum != 0;
121+
$fail ||= $sum != 0;
99122
push(@messages, $msg . " != 0: " . $counts . "\n")
100-
if $fail;
123+
if $sum != 0;
101124
}
102125
}
103126

0 commit comments

Comments
 (0)