diff options
author | Gerald Combs <gerald@wireshark.org> | 2018-09-18 10:09:31 -0700 |
---|---|---|
committer | Peter Wu <peter@lekensteyn.nl> | 2018-09-19 16:07:03 +0000 |
commit | 8f08a4e74ea8aa56284e6035017adf1c423c4f09 (patch) | |
tree | 030955437d3e8b2a2b5ebdcb3e0f9ba77ab42ef9 /tools | |
parent | ca8304249ee986f947b30eaea1d830207165c65e (diff) |
Try to discourage the use of APIs via counting.
Add the ability to specify maximum function counts for each group to
checkAPIs. Add maximum counts for the "termoutput" and "abort" groups
where needed. Show summaries in various checkAPI targets.
Switch uses of ws_g_warning back to plain g_warning.
Change-Id: I5cbddc8c671729e424eed8551f69116d16491976
Reviewed-on: https://code.wireshark.org/review/29721
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/checkAPIs.pl | 52 |
1 files changed, 44 insertions, 8 deletions
diff --git a/tools/checkAPIs.pl b/tools/checkAPIs.pl index 60818a5fa9..9a597b6055 100755 --- a/tools/checkAPIs.pl +++ b/tools/checkAPIs.pl @@ -890,8 +890,8 @@ sub check_pref_var_dupes($$) sub print_usage { - print "Usage: checkAPIs.pl [-M] [-h] [-g group1] [-g group2] ... \n"; - print " [--build] [-s group1] [-s group2] ... \n"; + print "Usage: checkAPIs.pl [-M] [-h] [-g group1[:count]] [-g group2] ... \n"; + print " [--build] [-summary-group group1] [-summary-group group2] ... \n"; print " [--sourcedir=srcdir] \n"; print " [--nocheck-value-string-array] \n"; print " [--nocheck-addtext] [--nocheck-hf] [--debug]\n"; @@ -903,7 +903,8 @@ sub print_usage print " -h: help, print usage message\n"; print " -g <group>: Check input files for use of APIs in <group>\n"; print " (in addition to the default groups)\n"; - print " -s <group>: Output summary (count) for each API in <group>\n"; + print " Maximum uses can be specified with <group>:<count>\n"; + print " -summary-group <group>: Output summary (count) for each API in <group>\n"; print " (-g <group> also req'd)\n"; print " ---nocheck-value-string-array: UNDOCUMENTED\n"; print " ---nocheck-addtext: UNDOCUMENTED\n"; @@ -1078,6 +1079,11 @@ for my $apiGroup (keys %APIs) { $APIs{$apiGroup}->{function_counts} = {}; @{$APIs{$apiGroup}->{function_counts}}{@functions} = (); # Add fcn names as keys to the anonymous hash + $APIs{$apiGroup}->{max_function_count} = -1; + if ($APIs{$apiGroup}->{count_errors}) { + $APIs{$apiGroup}->{max_function_count} = 0; + } + $APIs{$apiGroup}->{cur_function_count} = 0; } my @filelist; @@ -1219,12 +1225,36 @@ while ($_ = pop @filelist) # Check and count APIs - for my $apiGroup (@apiGroups) { + for my $groupArg (@apiGroups) { my $pfx = "Warning"; @foundAPIs = (); + my @groupParts = split(/:/, $groupArg); + my $apiGroup = $groupParts[0]; + my $curFuncCount = 0; + + if (scalar @groupParts > 1) { + $APIs{$apiGroup}->{max_function_count} = $groupParts[1]; + } findAPIinFile($APIs{$apiGroup}, \$fileContents, \@foundAPIs); + for my $api (keys %{$APIs{$apiGroup}->{function_counts}} ) { + $curFuncCount += $APIs{$apiGroup}{function_counts}{$api}; + } + + # If we have a max function count and we've exceeded it, treat it + # as an error. + if (!$APIs{$apiGroup}->{count_errors} && $APIs{$apiGroup}->{max_function_count} >= 0) { + if ($curFuncCount > $APIs{$apiGroup}->{max_function_count}) { + print STDERR $pfx . ": " . $apiGroup . " exceeds maximum function count: " . $APIs{$apiGroup}->{max_function_count} . "\n"; + $APIs{$apiGroup}->{count_errors} = 1; + } + } + + if ($curFuncCount <= $APIs{$apiGroup}->{max_function_count}) { + next; + } + if ($APIs{$apiGroup}->{count_errors}) { # the use of "prohibited" APIs is an error, increment the error count $errorCount += @foundAPIs; @@ -1244,10 +1274,16 @@ while ($_ = pop @filelist) # Summary: Print Use Counts of each API in each requested summary group -for my $apiGroup (@apiSummaryGroups) { - printf "\n\nUse Counts\n"; - for my $api (sort {"\L$a" cmp "\L$b"} (keys %{$APIs{$apiGroup}->{function_counts}} )) { - printf "%-20.20s %5d %-40.40s\n", $apiGroup . ':', $APIs{$apiGroup}{function_counts}{$api}, $api; +if (scalar @apiSummaryGroups > 0) { + my $fileline = join(", ", @ARGV); + printf "\nSummary for " . substr($fileline, 0, 65) . "…\n"; + + for my $apiGroup (@apiSummaryGroups) { + printf "\nUse counts for %s (maximum allowed total is %d)\n", $apiGroup, $APIs{$apiGroup}->{max_function_count}; + for my $api (sort {"\L$a" cmp "\L$b"} (keys %{$APIs{$apiGroup}->{function_counts}} )) { + if ($APIs{$apiGroup}{function_counts}{$api} < 1) { next; } + printf "%5d %-40.40s\n", $APIs{$apiGroup}{function_counts}{$api}, $api; + } } } |