Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions addons/misra.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import argparse
import string
import copy
import junit_xml

try:
from itertools import izip as zip
Expand Down Expand Up @@ -1552,6 +1553,9 @@ def __init__(self, settings, stdversion="c89"):
self.ruleTexts = {}
self.ruleText_filename = None

self.junit_testcases = []
self.junit_filehandle = None

# Dictionary of dictionaries for rules to suppress
# Dict1 is keyed by rule number in the hundreds format of
# Major * 100 + minor. ie Rule 5.2 = (5*100) + 2
Expand Down Expand Up @@ -4540,6 +4544,11 @@ def reportError(self, location, num1, num2):
if this_violation not in self.existing_violations:
self.existing_violations.add(this_violation)
cppcheckdata.reportError(location, cppcheck_severity, errmsg, 'misra', errorId, misra_severity)
if self.junit_filehandle:
loc = '[%s:%i]' % (location.file, location.linenr)
tc = junit_xml.TestCase(loc, 'misra', 1.0)
tc.add_error_info(errmsg, loc, errorId)
self.junit_testcases.append(tc)

if misra_severity not in self.violations:
self.violations[misra_severity] = []
Expand Down Expand Up @@ -5075,6 +5084,7 @@ def get_args_parser():
parser.add_argument("-generate-table", help=argparse.SUPPRESS, action="store_true")
parser.add_argument("-verify", help=argparse.SUPPRESS, action="store_true")
parser.add_argument("--severity", type=str, help="Set a custom severity string, for example 'error' or 'warning'. ")
parser.add_argument("--junit-file-export", type=str, help="Filename to export report as JUnit XML")
return parser


Expand Down Expand Up @@ -5104,6 +5114,16 @@ def main():
print('Fatal error: file is not found: ' + filename)
sys.exit(1)

if args.junit_file_export:
filename = os.path.expanduser(args.junit_file_export)
filename = os.path.normpath(filename)
if os.path.isfile(filename):
print('JUnit file already exists and will be overwritten')
try:
checker.junit_filehandle = open(filename, 'w+')
except FileNotFoundError as e:
print(f'An error occurred: {e}')


if args.verify_rule_texts and not args.rule_texts:
print("Error: Please specify rule texts file with --rule-texts=<file>")
Expand Down Expand Up @@ -5181,6 +5201,10 @@ def main():

if args.show_suppressed_rules:
checker.showSuppressedRules()
if args.junit_file_export:
ts = junit_xml.TestSuite("MISRA2012_TS", checker.junit_testcases)
junit_xml.TestSuite.to_file(checker.junit_filehandle, [ts], prettyprint=True)
checker.junit_filehandle.close()


if __name__ == '__main__':
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pcre,pfultz2/pcre@8.45 -H sha256:d6f7182602a775a7d500a0cedca6449af0400c6493951513046d17615ed0bf11
junit-xml