Enforce limit on issues found in static analysis
Implements new script (count-bugs.py) for peeking inside clang static analyzer's report and print just a summary. If number of detected bugs goes beyond the limit, script will return with error code 1, thus failing the CI run. The upper limit is set to 113, which is current result of static analysis in our CI environment (local run is likely to indicate different number); upper limit will be updated in time, as issues get fixed or new compiler (detecting more bugs) will be introduced. This commit includes also slight modifictaions to count-warnings.py script, to keep the both scripts outputting in similar format.
This commit is contained in:
parent
4c5b4faf2f
commit
9310258c57
3 changed files with 99 additions and 12 deletions
29
scripts/count-warnings.py
Normal file → Executable file
29
scripts/count-warnings.py
Normal file → Executable file
|
@ -1,8 +1,9 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
# Copyright (c) 2019 Patryk Obara
|
||||
# Copyright (c) 2019 Patryk Obara <patryk.obara@gmail.com>
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
# This script counts and all warnings and prints a summary.
|
||||
# This script counts all compiler warnings and prints a summary.
|
||||
#
|
||||
# Usage: ./count-warnings.py build.log
|
||||
# Usage: cat "*.log" | ./count-warnings.py -
|
||||
|
@ -18,11 +19,11 @@ import os
|
|||
import re
|
||||
import sys
|
||||
|
||||
# Maximum allowed number of warnings; if build will include more warnings,
|
||||
# Maximum allowed number of issues; if build will include more warnings,
|
||||
# then script will return with status 1. Simply change this line if you
|
||||
# want to set a different limit.
|
||||
#
|
||||
MAX_WARNINGS = 357
|
||||
MAX_ISSUES = 357
|
||||
|
||||
# For recognizing warnings in GCC format in stderr:
|
||||
#
|
||||
|
@ -63,11 +64,16 @@ def get_input_lines(name):
|
|||
return logs.readlines()
|
||||
|
||||
|
||||
def print_summary(warning_types):
|
||||
print("Warnings grouped by type:\n")
|
||||
summary = list(warning_types.items())
|
||||
def find_longest_name_length(names):
|
||||
return max(len(x) for x in names)
|
||||
|
||||
|
||||
def print_summary(issues):
|
||||
summary = list(issues.items())
|
||||
size = find_longest_name_length(issues.keys()) + 1
|
||||
for warning, count in sorted(summary, key=lambda x: -x[1]):
|
||||
print(' {:28s}: {}'.format(warning, count))
|
||||
print(' {text:{field_size}s}: {count}'.format(
|
||||
text=warning, count=count, field_size=size))
|
||||
print()
|
||||
|
||||
|
||||
|
@ -77,10 +83,11 @@ def main():
|
|||
for line in get_input_lines(sys.argv[1]):
|
||||
total += count_warning(line, warning_types)
|
||||
if warning_types:
|
||||
print("Warnings grouped by type:\n")
|
||||
print_summary(warning_types)
|
||||
print('Total: {} warnings\n'.format(total))
|
||||
if total > MAX_WARNINGS:
|
||||
print('Error: upper limit of warnings is', MAX_WARNINGS)
|
||||
print('Total: {} warnings (out of {} allowed)\n'.format(total, MAX_ISSUES))
|
||||
if total > MAX_ISSUES:
|
||||
print('Error: upper limit of allowed warnings is', MAX_ISSUES)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue