From d14dd5daf4cb5d98ffb2f83585d1f88571a8db64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Wed, 21 Feb 2024 08:23:14 +0100 Subject: [PATCH] test/cli/fuzz_test.py: added test for timeouts (#6011) --- test/cli/fuzz_test.py | 18 ++++++++++++++++++ test/cli/testutils.py | 4 ++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/test/cli/fuzz_test.py b/test/cli/fuzz_test.py index 91f1dc84a9f..67a1e237fec 100644 --- a/test/cli/fuzz_test.py +++ b/test/cli/fuzz_test.py @@ -1,4 +1,6 @@ import os +import subprocess + from testutils import cppcheck __script_dir = os.path.dirname(os.path.abspath(__file__)) @@ -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 == [] diff --git a/test/cli/testutils.py b/test/cli/testutils.py index 61fb482b0be..cef43267cae 100644 --- a/test/cli/testutils.py +++ b/test/cli/testutils.py @@ -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: