diff --git a/ci/cppcheck-misra.sh b/ci/cppcheck-misra.sh index 5e03305070946e0f42752e8ff34562e80cd023a7..2df953406f6af5996db82cb597b322d7e9f8c902 100755 --- a/ci/cppcheck-misra.sh +++ b/ci/cppcheck-misra.sh @@ -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 # generate dump files (XML representations of AST etc.) for all headers, source files etc. -#for file in $(find inc/ src/ -type f) -#do -# cppcheck --dump $file -#done +for file in $(find inc/ src/ -type f \( -iname "*.cpp" -or -iname "*.hpp" \)) +do + cppcheck --dump $file +done # run the MISRA checks against the dumps and send the results to a file for file in $(find inc/ src/ -type f -name "*.dump") @@ -25,7 +25,5 @@ do python misra.py $file >> ci/report.msr 2>&1 done -# clean up the report file from any useless info -sed -i -r 's/(.*Script.*)|(.*Checking.*)|(.*MISRA.*)//gm' ci/report.msr -sed -i -r '/(^$)/d' ci/report.msr -sed -i -r 's/(\s\(.*\)\s)//gm' ci/report.msr +# pre-process the generated report to remove all useless strings +sed -i -r 's/(.*Script.*)|(.*Checking.*)|(.*MISRA.*)//gm; /(^$)/d; s/(\s\(.*\)\s)//gm; s/(\]|\[)//gm; s/(misra-c2012-)//gm' ci/report.msr diff --git a/ci/summarizer.py b/ci/summarizer.py new file mode 100755 index 0000000000000000000000000000000000000000..68e62dc58a63b365cfa6f9e928b8a1d243ec549d --- /dev/null +++ b/ci/summarizer.py @@ -0,0 +1,51 @@ +#!/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) +