2019-10-24 21:48:34 +02:00
|
|
|
# Test if --verify works using the itc testsuite
|
|
|
|
# The itc test suite can be downloaded here:
|
|
|
|
# https://github.com/regehr/itc-benchmarks
|
|
|
|
|
|
|
|
|
|
|
|
import glob
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
import subprocess
|
|
|
|
|
2019-10-25 21:46:02 +02:00
|
|
|
if sys.argv[0] in ('test/verify/itc.py', './test/verify/itc.py'):
|
2019-10-24 21:48:34 +02:00
|
|
|
CPPCHECK_PATH = './cppcheck'
|
|
|
|
else:
|
|
|
|
CPPCHECK_PATH = '../../cppcheck'
|
|
|
|
|
2019-12-23 11:23:56 +01:00
|
|
|
if len(sys.argv) == 2:
|
|
|
|
TESTFILE = sys.argv[1]
|
|
|
|
if not os.path.isfile(TESTFILE):
|
|
|
|
print(f'ERROR: {TESTFILE} is not a file')
|
|
|
|
sys.exit(1)
|
|
|
|
else:
|
|
|
|
TESTFILE = os.path.expanduser('~/itc/01.w_Defects/zero_division.c')
|
|
|
|
|
2019-10-24 21:48:34 +02:00
|
|
|
def get_error_lines(filename):
|
|
|
|
ret = []
|
|
|
|
f = open(filename, 'rt')
|
|
|
|
lines = f.readlines()
|
|
|
|
for linenr, line in enumerate(lines):
|
2020-01-12 10:28:48 +01:00
|
|
|
if line.find('/* ERROR:') > 0 or line.find('/*ERROR:') > 0:
|
2019-10-24 21:48:34 +02:00
|
|
|
ret.append(linenr+1)
|
|
|
|
return ret
|
|
|
|
|
|
|
|
def check(filename):
|
|
|
|
cmd = [CPPCHECK_PATH,
|
|
|
|
'--verify',
|
|
|
|
'--platform=unix64',
|
|
|
|
filename]
|
|
|
|
print(' '.join(cmd))
|
|
|
|
|
|
|
|
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
|
comm = p.communicate()
|
|
|
|
stdout = comm[0].decode(encoding='utf-8', errors='ignore')
|
|
|
|
stderr = comm[1].decode(encoding='utf-8', errors='ignore')
|
|
|
|
|
2020-01-12 10:28:48 +01:00
|
|
|
w = r'.*zero_division.c:([0-9]+):[0-9]+: error: There is division.*'
|
|
|
|
if TESTFILE.find('uninit_') > 0:
|
|
|
|
w = r'.*c:([0-9]+):[0-9]+: error: .*verificationUninit.*'
|
|
|
|
|
2019-10-24 21:48:34 +02:00
|
|
|
ret = []
|
|
|
|
for line in stderr.split('\n'):
|
2020-01-12 10:28:48 +01:00
|
|
|
res = re.match(w, line)
|
2019-10-24 21:48:34 +02:00
|
|
|
if res is None:
|
|
|
|
continue
|
2020-01-12 10:53:44 +01:00
|
|
|
linenr = int(res.group(1))
|
|
|
|
if linenr not in ret:
|
|
|
|
ret.append(linenr)
|
2019-10-24 21:48:34 +02:00
|
|
|
return ret
|
|
|
|
|
2019-12-23 11:23:56 +01:00
|
|
|
wanted = get_error_lines(TESTFILE)
|
|
|
|
actual = check(TESTFILE)
|
2019-10-24 21:48:34 +02:00
|
|
|
print('wanted:' + str(wanted))
|
|
|
|
print('actual:' + str(actual))
|
|
|
|
missing = []
|
|
|
|
for w in wanted:
|
|
|
|
if w not in actual:
|
|
|
|
missing.append(w);
|
|
|
|
print('missing:' + str(missing))
|
|
|
|
|
|
|
|
|
|
|
|
|