Skip to content

Commit fa1e27f

Browse files
author
MarcoFalke
committed
fuzz: Generate rpc fuzz targets individually
1 parent 679f825 commit fa1e27f

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

test/fuzz/test_runner.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -198,29 +198,47 @@ def generate_corpus(*, fuzz_pool, src_dir, build_dir, corpus_dir, targets):
198198
{corpus_dir}.
199199
"""
200200
logging.info("Generating corpus to {}".format(corpus_dir))
201+
rpc_target = "rpc"
202+
has_rpc = rpc_target in targets
203+
if has_rpc:
204+
targets.remove(rpc_target)
205+
targets = [(t, {}) for t in targets]
206+
if has_rpc:
207+
lines = subprocess.run(
208+
["git", "grep", "--function-context", "RPC_COMMANDS_SAFE_FOR_FUZZING{", os.path.join(src_dir, "src", "test", "fuzz", "rpc.cpp")],
209+
check=True,
210+
stdout=subprocess.PIPE,
211+
text=True,
212+
).stdout.splitlines()
213+
lines = [l.split("\"", 1)[1].split("\"")[0] for l in lines if l.startswith("src/test/fuzz/rpc.cpp- \"")]
214+
targets += [(rpc_target, {"LIMIT_TO_RPC_COMMAND": r}) for r in lines]
201215

202-
def job(command, t):
203-
logging.debug("Running '{}'\n".format(" ".join(command)))
216+
def job(command, t, t_env):
217+
logging.debug(f"Running '{command}'")
204218
logging.debug("Command '{}' output:\n'{}'\n".format(
205-
' '.join(command),
219+
command,
206220
subprocess.run(
207221
command,
208-
env=get_fuzz_env(target=t, source_dir=src_dir),
222+
env={
223+
**t_env,
224+
**get_fuzz_env(target=t, source_dir=src_dir),
225+
},
209226
check=True,
210227
stderr=subprocess.PIPE,
211228
text=True,
212-
).stderr))
229+
).stderr,
230+
))
213231

214232
futures = []
215-
for target in targets:
216-
target_corpus_dir = os.path.join(corpus_dir, target)
233+
for target, t_env in targets:
234+
target_corpus_dir = corpus_dir / target
217235
os.makedirs(target_corpus_dir, exist_ok=True)
218236
command = [
219237
os.path.join(build_dir, 'src', 'test', 'fuzz', 'fuzz'),
220238
"-runs=100000",
221239
target_corpus_dir,
222240
]
223-
futures.append(fuzz_pool.submit(job, command, target))
241+
futures.append(fuzz_pool.submit(job, command, target, t_env))
224242

225243
for future in as_completed(futures):
226244
future.result()

0 commit comments

Comments
 (0)