Misra: Added verification code in the script to simplify testing
This commit is contained in:
parent
174bcc8d34
commit
9c8fc6253a
|
@ -1,7 +1,5 @@
|
||||||
/*
|
// To test:
|
||||||
~/cppcheck/cppcheck --dump misra-test.c
|
// ~/cppcheck/cppcheck --dump misra-test.c && python misra.py -verify misra-test.c.dump
|
||||||
python misra.py misra-test.c.dump
|
|
||||||
*/
|
|
||||||
|
|
||||||
typedef unsigned char u8;
|
typedef unsigned char u8;
|
||||||
|
|
||||||
|
|
|
@ -15,9 +15,15 @@ import cppcheckdata
|
||||||
import sys
|
import sys
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
VERIFY = False
|
||||||
|
VERIFY_EXPECTED = []
|
||||||
|
VERIFY_ACTUAL = []
|
||||||
|
|
||||||
def reportError(token, num1, num2):
|
def reportError(token, num1, num2):
|
||||||
sys.stderr.write(
|
if VERIFY:
|
||||||
'[' + token.file + ':' + str(token.linenr) + '] misra ' + str(num1) + '.' + str(num2) + ' violation\n')
|
VERIFY_ACTUAL.append(str(token.linenr) + ':' + str(num1) + '.' + str(num2))
|
||||||
|
else:
|
||||||
|
sys.stderr.write('[' + token.file + ':' + str(token.linenr) + '] misra ' + str(num1) + '.' + str(num2) + ' violation\n')
|
||||||
|
|
||||||
# Platform
|
# Platform
|
||||||
# TODO get this from dump
|
# TODO get this from dump
|
||||||
|
@ -439,10 +445,26 @@ def misra_16_3(rawTokens):
|
||||||
elif token.str == 'case' and state != 2:
|
elif token.str == 'case' and state != 2:
|
||||||
reportError(token, 16, 3)
|
reportError(token, 16, 3)
|
||||||
|
|
||||||
|
if '-verify' in sys.argv[1:]:
|
||||||
|
VERIFY = True
|
||||||
|
|
||||||
for arg in sys.argv[1:]:
|
for arg in sys.argv[1:]:
|
||||||
print('Checking ' + arg + '...')
|
if not arg.endswith('.dump'):
|
||||||
|
continue
|
||||||
|
|
||||||
data = cppcheckdata.parsedump(arg)
|
data = cppcheckdata.parsedump(arg)
|
||||||
|
|
||||||
|
if VERIFY:
|
||||||
|
VERIFY_ACTUAL = []
|
||||||
|
VERIFY_EXPECTED = []
|
||||||
|
for tok in data.rawTokens:
|
||||||
|
if tok.str.startswith('//') and tok.str.find('TODO')<0:
|
||||||
|
for word in tok.str[2:].split(' '):
|
||||||
|
if re.match(r'[0-9]+\.[0-9]+', word):
|
||||||
|
VERIFY_EXPECTED.append(str(tok.linenr) + ':' + word)
|
||||||
|
else:
|
||||||
|
print('Checking ' + arg + '...')
|
||||||
|
|
||||||
cfgNumber = 0
|
cfgNumber = 0
|
||||||
|
|
||||||
for cfg in data.configurations:
|
for cfg in data.configurations:
|
||||||
|
@ -478,3 +500,12 @@ for arg in sys.argv[1:]:
|
||||||
if cfgNumber == 1:
|
if cfgNumber == 1:
|
||||||
misra_16_3(data.rawTokens)
|
misra_16_3(data.rawTokens)
|
||||||
|
|
||||||
|
if VERIFY:
|
||||||
|
for expected in VERIFY_EXPECTED:
|
||||||
|
if not expected in VERIFY_ACTUAL:
|
||||||
|
print('Expected but not seen: ' + expected)
|
||||||
|
sys.exit(1)
|
||||||
|
for actual in VERIFY_ACTUAL:
|
||||||
|
if not actual in VERIFY_EXPECTED:
|
||||||
|
print('Not expected: ' + actual)
|
||||||
|
sys.exit(1)
|
||||||
|
|
Loading…
Reference in New Issue