From b958dcb50fb994f6375e04196df193ea5106c1d2 Mon Sep 17 00:00:00 2001 From: Yakov Olkhovskiy Date: Wed, 23 Oct 2024 14:36:27 +0000 Subject: [PATCH] reorganize command line, add CI.FUZZER_ARGS option --- tests/fuzz/clickhouse_fuzzer.options | 2 ++ tests/fuzz/runner.py | 24 +++++++++++++++--------- 2 files changed, 17 insertions(+), 9 deletions(-) create mode 100644 tests/fuzz/clickhouse_fuzzer.options diff --git a/tests/fuzz/clickhouse_fuzzer.options b/tests/fuzz/clickhouse_fuzzer.options new file mode 100644 index 00000000000..a22ba7b3b88 --- /dev/null +++ b/tests/fuzz/clickhouse_fuzzer.options @@ -0,0 +1,2 @@ +[CI] +FUZZER_ARGS = true diff --git a/tests/fuzz/runner.py b/tests/fuzz/runner.py index 2c1d57ce5eb..40b55700623 100644 --- a/tests/fuzz/runner.py +++ b/tests/fuzz/runner.py @@ -44,6 +44,7 @@ def run_fuzzer(fuzzer: str, timeout: int): options_file = f"{fuzzer}.options" custom_libfuzzer_options = "" fuzzer_arguments = "" + use_fuzzer_args = False with Path(options_file) as path: if path.exists() and path.is_file(): @@ -78,24 +79,28 @@ def run_fuzzer(fuzzer: str, timeout: int): for key, value in parser["fuzzer_arguments"].items() ) + use_fuzzer_args = parser.getboolean("CI", "FUZZER_ARGS", fallback=False) + exact_artifact_path = f"{OUTPUT}/{fuzzer}.unit" status_path = f"{OUTPUT}/{fuzzer}.status" out_path = f"{OUTPUT}/{fuzzer}.out" stdout_path = f"{OUTPUT}/{fuzzer}.stdout" - cmd_line = f"{DEBUGGER} ./{fuzzer} {active_corpus_dir} {seed_corpus_dir}" + if not "-dict=" in custom_libfuzzer_options and Path(f"{fuzzer}.dict").exists(): + custom_libfuzzer_options += f" -dict={fuzzer}.dict" + custom_libfuzzer_options += f" -exact_artifact_path={exact_artifact_path}" - cmd_line += f" -exact_artifact_path={exact_artifact_path}" + libfuzzer_corpora = f"{active_corpus_dir} {seed_corpus_dir}" - if custom_libfuzzer_options: - cmd_line += f" {custom_libfuzzer_options}" - if fuzzer_arguments: - cmd_line += f" {fuzzer_arguments}" + cmd_line = f"{DEBUGGER} ./{fuzzer} {fuzzer_arguments}" - if not "-dict=" in cmd_line and Path(f"{fuzzer}.dict").exists(): - cmd_line += f" -dict={fuzzer}.dict" + env = None + if use_fuzzer_args: + env = {"FUZZER_ARGS": f"{custom_libfuzzer_options} {libfuzzer_corpora}"} + else: + cmd_line += f" {custom_libfuzzer_options} {libfuzzer_corpora}" - logging.info("...will execute: %s", cmd_line) + logging.info("...will execute: %s%s", cmd_line, f" with FUZZER_ARGS {env["FUZZER_ARGS"]}" if use_fuzzer_args else "") stopwatch = Stopwatch() try: @@ -110,6 +115,7 @@ def run_fuzzer(fuzzer: str, timeout: int): shell=False, errors="replace", timeout=timeout, + env=env, ) except subprocess.CalledProcessError: logging.info("Fail running %s", fuzzer)