Skip to content

Commit

Permalink
test/cli/fuzz_test.py: added test for timeouts (#6011)
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Feb 21, 2024
1 parent 6e635cd commit d14dd5d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
18 changes: 18 additions & 0 deletions test/cli/fuzz_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import os
import subprocess

from testutils import cppcheck

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

assert failures == {}


def test_fuzz_timeout():
failures = []

fuzz_timeout_dir = os.path.join(__script_dir, 'fuzz-timeout')
# TODO: remove check if we have test data
if not os.path.exists(fuzz_timeout_dir):
return
for f in os.listdir(fuzz_timeout_dir):
try:
ret, stdout, _ = cppcheck(['-q', '--enable=all', '--inconclusive', f], cwd=fuzz_timeout_dir, timeout=5)
except subprocess.TimeoutExpired:
failures.append(f)

assert failures == []
4 changes: 2 additions & 2 deletions test/cli/testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ def __lookup_cppcheck_exe():


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

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

0 comments on commit d14dd5d

Please sign in to comment.