Skip to content

Commit f348ec7

Browse files
committed
Merge bitcoin/bitcoin#29821: fuzz: Some test/fuzz/test_runner.py improvements
47cedee fuzz: Introduce `BITCOINFUZZ` environment variable (Hennadii Stepanov) 1573e9a fuzz, refactor: Deduplicate fuzz binary path creation (Hennadii Stepanov) Pull request description: These changes are split from bitcoin/bitcoin#29774 and can be beneficial on their own. The new `BITCOINFUZZ` environment variable complements the already existing set of variables used by tests: https://github.com/bitcoin/bitcoin/blob/b5d21182e5a66110ce2796c2c99da39c8ebf0d72/test/functional/test_framework/test_framework.py#L238-L243 ACKs for top commit: maflcko: lgtm ACK 47cedee davidgumberg: utACK bitcoin/bitcoin@47cedee Tree-SHA512: 45809cfd13dc4a45c44cc433184352e84726cb95bea80fd8f581c59a0b8b0a5495260ff66922f9c57c38adbdbdd102439238f370fd49d6ea27a241a5e6249895
2 parents 3834573 + 47cedee commit f348ec7

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

test/fuzz/test_runner.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,11 @@ def main():
104104
logging.error("Must have fuzz executable built")
105105
sys.exit(1)
106106

107+
fuzz_bin=os.getenv("BITCOINFUZZ", default=os.path.join(config["environment"]["BUILDDIR"], 'src', 'test', 'fuzz', 'fuzz'))
108+
107109
# Build list of tests
108110
test_list_all = parse_test_list(
109-
fuzz_bin=os.path.join(config["environment"]["BUILDDIR"], 'src', 'test', 'fuzz', 'fuzz'),
111+
fuzz_bin=fuzz_bin,
110112
source_dir=config['environment']['SRCDIR'],
111113
)
112114

@@ -151,7 +153,7 @@ def main():
151153
try:
152154
help_output = subprocess.run(
153155
args=[
154-
os.path.join(config["environment"]["BUILDDIR"], 'src', 'test', 'fuzz', 'fuzz'),
156+
fuzz_bin,
155157
'-help=1',
156158
],
157159
env=get_fuzz_env(target=test_list_selection[0], source_dir=config['environment']['SRCDIR']),
@@ -173,7 +175,7 @@ def main():
173175
return generate_corpus(
174176
fuzz_pool=fuzz_pool,
175177
src_dir=config['environment']['SRCDIR'],
176-
build_dir=config["environment"]["BUILDDIR"],
178+
fuzz_bin=fuzz_bin,
177179
corpus_dir=args.corpus_dir,
178180
targets=test_list_selection,
179181
)
@@ -184,7 +186,7 @@ def main():
184186
corpus=args.corpus_dir,
185187
test_list=test_list_selection,
186188
src_dir=config['environment']['SRCDIR'],
187-
build_dir=config["environment"]["BUILDDIR"],
189+
fuzz_bin=fuzz_bin,
188190
merge_dirs=[Path(m_dir) for m_dir in args.m_dir],
189191
)
190192
return
@@ -194,7 +196,7 @@ def main():
194196
corpus=args.corpus_dir,
195197
test_list=test_list_selection,
196198
src_dir=config['environment']['SRCDIR'],
197-
build_dir=config["environment"]["BUILDDIR"],
199+
fuzz_bin=fuzz_bin,
198200
using_libfuzzer=using_libfuzzer,
199201
use_valgrind=args.valgrind,
200202
empty_min_time=args.empty_min_time,
@@ -237,7 +239,7 @@ def transform_rpc_target(targets, src_dir):
237239
return targets
238240

239241

240-
def generate_corpus(*, fuzz_pool, src_dir, build_dir, corpus_dir, targets):
242+
def generate_corpus(*, fuzz_pool, src_dir, fuzz_bin, corpus_dir, targets):
241243
"""Generates new corpus.
242244
243245
Run {targets} without input, and outputs the generated corpus to
@@ -270,7 +272,7 @@ def job(command, t, t_env):
270272
os.makedirs(target_corpus_dir, exist_ok=True)
271273
use_value_profile = int(random.random() < .3)
272274
command = [
273-
os.path.join(build_dir, 'src', 'test', 'fuzz', 'fuzz'),
275+
fuzz_bin,
274276
"-rss_limit_mb=8000",
275277
"-max_total_time=6000",
276278
"-reload=0",
@@ -283,12 +285,12 @@ def job(command, t, t_env):
283285
future.result()
284286

285287

286-
def merge_inputs(*, fuzz_pool, corpus, test_list, src_dir, build_dir, merge_dirs):
288+
def merge_inputs(*, fuzz_pool, corpus, test_list, src_dir, fuzz_bin, merge_dirs):
287289
logging.info(f"Merge the inputs from the passed dir into the corpus_dir. Passed dirs {merge_dirs}")
288290
jobs = []
289291
for t in test_list:
290292
args = [
291-
os.path.join(build_dir, 'src', 'test', 'fuzz', 'fuzz'),
293+
fuzz_bin,
292294
'-rss_limit_mb=8000',
293295
'-set_cover_merge=1',
294296
# set_cover_merge is used instead of -merge=1 to reduce the overall
@@ -325,13 +327,13 @@ def job(t, args):
325327
future.result()
326328

327329

328-
def run_once(*, fuzz_pool, corpus, test_list, src_dir, build_dir, using_libfuzzer, use_valgrind, empty_min_time):
330+
def run_once(*, fuzz_pool, corpus, test_list, src_dir, fuzz_bin, using_libfuzzer, use_valgrind, empty_min_time):
329331
jobs = []
330332
for t in test_list:
331333
corpus_path = corpus / t
332334
os.makedirs(corpus_path, exist_ok=True)
333335
args = [
334-
os.path.join(build_dir, 'src', 'test', 'fuzz', 'fuzz'),
336+
fuzz_bin,
335337
]
336338
empty_dir = not any(corpus_path.iterdir())
337339
if using_libfuzzer:

0 commit comments

Comments
 (0)