| 1 |
#!/usr/bin/env perl |
| 2 |
|
| 3 |
# Copyright (c) MediaTek USA Inc., 2021-2023 |
| 4 |
# |
| 5 |
# This program is free software; you can redistribute it and/or modify |
| 6 |
# it under the terms of the GNU General Public License as published by |
| 7 |
# the Free Software Foundation; either version 2 of the License, or (at |
| 8 |
# your option) any later version. |
| 9 |
# |
| 10 |
# This program is distributed in the hope that it will be useful, but |
| 11 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
# General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU General Public License |
| 16 |
# along with this program; if not, see |
| 17 |
# <http://www.gnu.org/licenses/>. |
| 18 |
# |
| 19 |
# criteria |
| 20 |
# |
| 21 |
# This script is used as a genhtml "--criteria-script criteria" callback. |
| 22 |
# It is called by genhtml at each level of hierarchy - but ignores all but |
| 23 |
# the top level, and looks only at line coverage. |
| 24 |
# |
| 25 |
# Format of the JSON input is: |
| 26 |
# {"line":{"found":10,"hit:2,"UNC":2,..},"function":{...},"branch":{}" |
| 27 |
# Only non-zero elements are included. |
| 28 |
# See the 'criteria-script' section in "man genhtml" for details. |
| 29 |
# |
| 30 |
# The coverage criteria implemented here is "UNC + LBC + UIC == 0" |
| 31 |
# If the criterial is violated, then this script emits a single line message |
| 32 |
# to stdout and returns a non-zero exit code. |
| 33 |
# |
| 34 |
# If passed the "--suppress" flag, this script will exit with status 0, |
| 35 |
# even if the coverage criteria is not met. |
| 36 |
# genhtml --criteria-script 'path/criteria --signoff' .... |
| 37 |
# |
| 38 |
# It is not hard to envision much more complicated coverage criteria. |
| 39 |
|
| 40 |
use strict; |
| 41 |
use FindBin; |
| 42 |
use Getopt::Long; |
| 43 |
use lib "$FindBin::RealBin"; |
| 44 |
use criteria qw(new); |
| 45 |
|
| 46 |
use lib "$FindBin::RealBin/../lib"; |
| 47 |
use lib "$FindBin::RealBin/../../../lib"; # path from 'support-scripts' |
| 48 |
|
| 49 |
use lcovutil; |
| 50 |
|
| 51 |
my $obj = criteria->new($0, @ARGV); |
| 52 |
|
| 53 |
my $signoff; |
| 54 |
if (!defined($obj) || |
| 55 |
!GetOptions('signoff' => \$signoff)) { |
| 56 |
print(STDERR "usage: name type json-string [--signoff]\n"); |
| 57 |
exit(1) if caller; |
| 58 |
return undef; |
| 59 |
} |
| 60 |
my $json = pop(@ARGV); |
| 61 |
my $db = JsonSupport::decode($json); |
| 62 |
|
| 63 |
my ($status, $msgs) = $obj->check_criteria(@ARGV, $db); |
| 64 |
foreach my $m (@$msgs) { |
| 65 |
print($m, "\n"); |
| 66 |
} |
| 67 |
exit $status; |