Skip to content

Commit d14dd5d

Browse files
authored
test/cli/fuzz_test.py: added test for timeouts (#6011)
1 parent 6e635cd commit d14dd5d

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

test/cli/fuzz_test.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import os
2+
import subprocess
3+
24
from testutils import cppcheck
35

46
__script_dir = os.path.dirname(os.path.abspath(__file__))
@@ -14,3 +16,19 @@ def test_fuzz_crash():
1416
failures[f] = stdout
1517

1618
assert failures == {}
19+
20+
21+
def test_fuzz_timeout():
22+
failures = []
23+
24+
fuzz_timeout_dir = os.path.join(__script_dir, 'fuzz-timeout')
25+
# TODO: remove check if we have test data
26+
if not os.path.exists(fuzz_timeout_dir):
27+
return
28+
for f in os.listdir(fuzz_timeout_dir):
29+
try:
30+
ret, stdout, _ = cppcheck(['-q', '--enable=all', '--inconclusive', f], cwd=fuzz_timeout_dir, timeout=5)
31+
except subprocess.TimeoutExpired:
32+
failures.append(f)
33+
34+
assert failures == []

test/cli/testutils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ def __lookup_cppcheck_exe():
7272

7373

7474
# Run Cppcheck with args
75-
def cppcheck(args, env=None, remove_checkers_report=True, cwd=None, cppcheck_exe=None):
75+
def cppcheck(args, env=None, remove_checkers_report=True, cwd=None, cppcheck_exe=None, timeout=None):
7676
exe = cppcheck_exe if cppcheck_exe else __lookup_cppcheck_exe()
7777
assert exe is not None, 'no cppcheck binary found'
7878

7979
logging.info(exe + ' ' + ' '.join(args))
8080
p = subprocess.Popen([exe] + args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env, cwd=cwd)
81-
comm = p.communicate()
81+
comm = p.communicate(timeout=timeout)
8282
stdout = comm[0].decode(encoding='utf-8', errors='ignore').replace('\r\n', '\n')
8383
stderr = comm[1].decode(encoding='utf-8', errors='ignore').replace('\r\n', '\n')
8484
if remove_checkers_report:

0 commit comments

Comments
 (0)