cppcheck/test/bug-hunting/cve.py

46 lines
1.1 KiB
Python
Raw Normal View History

2020-05-01 12:20:33 +02:00
# Test if --bug-hunting works using cve tests
import glob
import os
import re
import shutil
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'
RUN_CLANG = ('--clang' in sys.argv)
def check():
cmd = [CPPCHECK_PATH,
'-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',
'--inline-suppr',
2020-05-01 13:59:17 +02:00
'--enable=information',
2020-05-01 12:20:33 +02:00
TEST_SUITE]
if RUN_CLANG:
cmd.append('--clang')
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')
# Ensure there are no unmatched suppressions
if '[unmatchedSuppression]' in stderr:
print('FAILED: There are unmatched suppressions')
2020-05-01 13:59:17 +02:00
sys.exit(1)
2020-05-01 12:20:33 +02:00
else:
print('SUCCESS')
check()