diff options
author | MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> | 2023-06-27 16:13:05 +0200 |
---|---|---|
committer | MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> | 2023-06-28 17:50:45 +0200 |
commit | fa1e27fe8ec42764d0250c82a83d774c15798c4a (patch) | |
tree | 80f4ee70712e93ccdf035b2ee141c4683b61cd50 /test/fuzz | |
parent | 679f825ba3aae45af4476f357a67f8e6ec9483e2 (diff) | |
download | bitcoin-fa1e27fe8ec42764d0250c82a83d774c15798c4a.tar.xz |
fuzz: Generate rpc fuzz targets individually
Diffstat (limited to 'test/fuzz')
-rwxr-xr-x | test/fuzz/test_runner.py | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/test/fuzz/test_runner.py b/test/fuzz/test_runner.py index d953f48584..d427366d8a 100755 --- a/test/fuzz/test_runner.py +++ b/test/fuzz/test_runner.py @@ -198,29 +198,47 @@ def generate_corpus(*, fuzz_pool, src_dir, build_dir, corpus_dir, targets): {corpus_dir}. """ logging.info("Generating corpus to {}".format(corpus_dir)) + rpc_target = "rpc" + has_rpc = rpc_target in targets + if has_rpc: + targets.remove(rpc_target) + targets = [(t, {}) for t in targets] + if has_rpc: + lines = subprocess.run( + ["git", "grep", "--function-context", "RPC_COMMANDS_SAFE_FOR_FUZZING{", os.path.join(src_dir, "src", "test", "fuzz", "rpc.cpp")], + check=True, + stdout=subprocess.PIPE, + text=True, + ).stdout.splitlines() + lines = [l.split("\"", 1)[1].split("\"")[0] for l in lines if l.startswith("src/test/fuzz/rpc.cpp- \"")] + targets += [(rpc_target, {"LIMIT_TO_RPC_COMMAND": r}) for r in lines] - def job(command, t): - logging.debug("Running '{}'\n".format(" ".join(command))) + def job(command, t, t_env): + logging.debug(f"Running '{command}'") logging.debug("Command '{}' output:\n'{}'\n".format( - ' '.join(command), + command, subprocess.run( command, - env=get_fuzz_env(target=t, source_dir=src_dir), + env={ + **t_env, + **get_fuzz_env(target=t, source_dir=src_dir), + }, check=True, stderr=subprocess.PIPE, text=True, - ).stderr)) + ).stderr, + )) futures = [] - for target in targets: - target_corpus_dir = os.path.join(corpus_dir, target) + for target, t_env in targets: + target_corpus_dir = corpus_dir / target os.makedirs(target_corpus_dir, exist_ok=True) command = [ os.path.join(build_dir, 'src', 'test', 'fuzz', 'fuzz'), "-runs=100000", target_corpus_dir, ] - futures.append(fuzz_pool.submit(job, command, target)) + futures.append(fuzz_pool.submit(job, command, target, t_env)) for future in as_completed(futures): future.result() |