2020-05-01 12:20:33 +02:00
|
|
|
# Test if --bug-hunting works using cve tests
|
|
|
|
|
|
|
|
import glob
|
2020-07-13 11:18:51 +02:00
|
|
|
import logging
|
2020-05-01 12:20:33 +02:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
if sys.argv[0] in ('test/bug-hunting/cve.py', './test/bug-hunting/cve.py'):
|
|
|
|
CPPCHECK_PATH = './cppcheck'
|
|
|
|
TEST_SUITE = 'test/bug-hunting/cve'
|
|
|
|
else:
|
|
|
|
CPPCHECK_PATH = '../../cppcheck'
|
|
|
|
TEST_SUITE = 'cve'
|
|
|
|
|
2020-07-13 11:18:51 +02:00
|
|
|
slow = '--slow' in sys.argv
|
|
|
|
|
|
|
|
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)s %(message)s', datefmt='%H:%M:%S')
|
|
|
|
|
2020-05-02 21:57:36 +02:00
|
|
|
def test(test_folder):
|
2020-07-13 11:18:51 +02:00
|
|
|
logging.info(test_folder)
|
2020-05-02 21:57:36 +02:00
|
|
|
|
|
|
|
cmd_file = os.path.join(test_folder, 'cmd.txt')
|
|
|
|
expected_file = os.path.join(test_folder, 'expected.txt')
|
2020-05-01 12:20:33 +02:00
|
|
|
|
2020-07-13 11:18:51 +02:00
|
|
|
cmd = ['nice',
|
|
|
|
CPPCHECK_PATH,
|
2020-05-01 20:29:11 +02:00
|
|
|
'-D__GNUC__',
|
2020-05-01 12:20:33 +02:00
|
|
|
'--bug-hunting',
|
2020-05-01 14:27:18 +02:00
|
|
|
'--inconclusive',
|
2020-05-01 12:20:33 +02:00
|
|
|
'--platform=unix64',
|
2020-05-02 21:57:36 +02:00
|
|
|
'--template={file}:{line}:{id}',
|
2020-07-13 11:18:51 +02:00
|
|
|
'-rp=' + test_folder]
|
2020-05-02 21:57:36 +02:00
|
|
|
|
|
|
|
if os.path.isfile(cmd_file):
|
|
|
|
for line in open(cmd_file, 'rt'):
|
|
|
|
if len(line) > 1:
|
|
|
|
cmd.append(line.strip())
|
2020-05-01 12:20:33 +02:00
|
|
|
|
2020-07-13 11:18:51 +02:00
|
|
|
cmd.append(test_folder)
|
|
|
|
|
2020-05-01 12:20:33 +02:00
|
|
|
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-05-02 21:57:36 +02:00
|
|
|
with open(expected_file, 'rt') as f:
|
|
|
|
for expected in f.readlines():
|
|
|
|
if expected.strip() not in stderr.split('\n'):
|
|
|
|
print('FAILED. Expected result not found: ' + expected)
|
|
|
|
print('Command:')
|
|
|
|
print(' '.join(cmd))
|
|
|
|
print('Output:')
|
|
|
|
print(stderr)
|
|
|
|
sys.exit(1)
|
|
|
|
|
2020-07-13 11:18:51 +02:00
|
|
|
if (slow is False) and len(sys.argv) > 1:
|
2020-05-02 21:57:36 +02:00
|
|
|
test(sys.argv[1])
|
|
|
|
sys.exit(0)
|
2020-05-01 12:20:33 +02:00
|
|
|
|
2020-07-13 11:18:51 +02:00
|
|
|
SLOW = []
|
|
|
|
|
2020-05-02 21:57:36 +02:00
|
|
|
for test_folder in sorted(glob.glob(TEST_SUITE + '/CVE*')):
|
2020-07-13 11:18:51 +02:00
|
|
|
if slow is False:
|
|
|
|
check = False
|
|
|
|
for s in SLOW:
|
|
|
|
if s in test_folder:
|
|
|
|
check = True
|
|
|
|
if check is True:
|
|
|
|
logging.info('skipping %s', test_folder)
|
|
|
|
continue
|
2020-05-02 21:57:36 +02:00
|
|
|
test(test_folder)
|
2020-05-01 12:20:33 +02:00
|
|
|
|