Skip to content
Snippets Groups Projects
Commit e7db0a75 authored by Grigoris Pavlakis's avatar Grigoris Pavlakis Committed by kongr45gpen
Browse files

Start work on report parsing and prettyprinting

Finish report pre-processing

Commit before full final test of pipeline
parent 428f0d3b
No related branches found
No related tags found
No related merge requests found
...@@ -14,10 +14,10 @@ curl https://raw.githubusercontent.com/danmar/cppcheck/f4b5b156d720c712f6ce99f6e ...@@ -14,10 +14,10 @@ curl https://raw.githubusercontent.com/danmar/cppcheck/f4b5b156d720c712f6ce99f6e
curl https://raw.githubusercontent.com/danmar/cppcheck/f4b5b156d720c712f6ce99f6e01d8c1b3f800d52/addons/cppcheckdata.py > cppcheckdata.py curl https://raw.githubusercontent.com/danmar/cppcheck/f4b5b156d720c712f6ce99f6e01d8c1b3f800d52/addons/cppcheckdata.py > cppcheckdata.py
# generate dump files (XML representations of AST etc.) for all headers, source files etc. # generate dump files (XML representations of AST etc.) for all headers, source files etc.
#for file in $(find inc/ src/ -type f) for file in $(find inc/ src/ -type f \( -iname "*.cpp" -or -iname "*.hpp" \))
#do do
# cppcheck --dump $file cppcheck --dump $file
#done done
# run the MISRA checks against the dumps and send the results to a file # run the MISRA checks against the dumps and send the results to a file
for file in $(find inc/ src/ -type f -name "*.dump") for file in $(find inc/ src/ -type f -name "*.dump")
...@@ -25,7 +25,5 @@ do ...@@ -25,7 +25,5 @@ do
python misra.py $file >> ci/report.msr 2>&1 python misra.py $file >> ci/report.msr 2>&1
done done
# clean up the report file from any useless info # pre-process the generated report to remove all useless strings
sed -i -r 's/(.*Script.*)|(.*Checking.*)|(.*MISRA.*)//gm' ci/report.msr sed -i -r 's/(.*Script.*)|(.*Checking.*)|(.*MISRA.*)//gm; /(^$)/d; s/(\s\(.*\)\s)//gm; s/(\]|\[)//gm; s/(misra-c2012-)//gm' ci/report.msr
sed -i -r '/(^$)/d' ci/report.msr
sed -i -r 's/(\s\(.*\)\s)//gm' ci/report.msr
#!/bin/env python3
from sys import argv
from collections import Counter
script, reportfile = argv
def analyze():
errorsMap = {}
file = open(reportfile, 'r')
fileLines = file.readlines()
cppcheckNumOfErrors = len(fileLines)
linesSeen = set()
for line in fileLines: # remove duplicate lines
if line not in linesSeen:
linesSeen.add(line)
for line in linesSeen:
lineContents = line.split(':')
fileName = lineContents[0]
error = (lineContents[1], lineContents[2].strip('\n'))
if fileName not in errorsMap.keys():
errorsMap[fileName] = list()
errorsMap[fileName].append(error)
else:
errorsMap[fileName].append(error)
return errorsMap
def prettyprint(errors):
print("\033[1m\033[91m=================================================\n")
print("\033[1m Static analysis results: Error Summary \n")
for key in errors:
for error in errors[key]:
print("\033[1mFile \033[93m{0}\033[91m violates rule \033[93m#{1}\033[91m of the MISRA C 2012 standard at line \033[93m{2}\033[91m".format(key, error[1], error[0]))
print()
print("\033[1m=================================================\033[0m\n")
if __name__ == "__main__":
errors = analyze()
if len(errors) == 0:
print("\033[1m\033[92mStatic analysis for MISRA compliance complete. No errors found.")
exit(0)
else:
prettyprint(errors)
exit(1)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment