Skip to content

Commit 50c4d7b

Browse files
kripkenradekdoulik
authored andcommitted
Fuzzer: Use a directory for important fuzz testcases (WebAssembly#6297)
Users can put files in ./fuzz and they will be fuzzed with high priority. Docs in source and https://github.com/WebAssembly/binaryen/wiki/Fuzzing#helper-scripts
1 parent f0ae708 commit 50c4d7b

File tree

2 files changed

+17
-23
lines changed

2 files changed

+17
-23
lines changed

fuzz/readme.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The wasm contents of this directory (*.wasm, *.wast, *.wat files) are treated as
2+
important contents by the fuzzer, which will test them with high frequency. This
3+
is useful when you have some local files you want the fuzzer to focus on.

scripts/fuzz_opt.py

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
1111
That will run forever or until it finds a problem.
1212
13+
You can put files in the local directory 'fuzz' (under the top level of the
14+
binaryen repo) and the fuzzer will treat them as important content to fuzz
15+
with high frequency.
16+
1317
Setup: Some tools are optional, like emcc and wasm2c. The v8 shell (d8),
1418
however, is used in various sub-fuzzers and so it is mandatory.
1519
@@ -200,24 +204,13 @@ def randomize_fuzz_settings():
200204

201205

202206
def init_important_initial_contents():
203-
FIXED_IMPORTANT_INITIAL_CONTENTS = [
204-
# Perenially-important passes
205-
os.path.join('lit', 'passes', 'optimize-instructions-mvp.wast'),
206-
os.path.join('passes', 'optimize-instructions_fuzz-exec.wast'),
207-
]
208-
MANUAL_RECENT_INITIAL_CONTENTS = [
209-
# Recently-added or modified passes. These can be added to and pruned
210-
# frequently.
211-
os.path.join('lit', 'passes', 'once-reduction.wast'),
212-
os.path.join('passes', 'remove-unused-brs_enable-multivalue.wast'),
213-
os.path.join('lit', 'passes', 'optimize-instructions-bulk-memory.wast'),
214-
os.path.join('lit', 'passes', 'optimize-instructions-ignore-traps.wast'),
215-
os.path.join('lit', 'passes', 'optimize-instructions-gc.wast'),
216-
os.path.join('lit', 'passes', 'optimize-instructions-gc-iit.wast'),
217-
os.path.join('lit', 'passes', 'optimize-instructions-call_ref.wast'),
218-
os.path.join('lit', 'passes', 'inlining_splitting.wast'),
219-
os.path.join('heap-types.wast'),
220-
]
207+
# Fuzz dir contents are always important to us.
208+
fuzz_dir = os.path.join(shared.options.binaryen_root, 'fuzz')
209+
fuzz_cases = shared.get_tests(fuzz_dir, test_suffixes, recursive=True)
210+
FIXED_IMPORTANT_INITIAL_CONTENTS = fuzz_cases
211+
212+
# If auto_initial_contents is set we'll also grab all test files that are
213+
# recent.
221214
RECENT_DAYS = 30
222215

223216
# Returns the list of test wast/wat files added or modified within the
@@ -258,7 +251,7 @@ def is_git_repo():
258251
'so not automatically selecting initial contents.')
259252
shared.options.auto_initial_contents = False
260253

261-
print('- Perenially-important initial contents:')
254+
print('- Important provided initial contents:')
262255
for test in FIXED_IMPORTANT_INITIAL_CONTENTS:
263256
print(' ' + test)
264257
print()
@@ -268,9 +261,6 @@ def is_git_repo():
268261
if shared.options.auto_initial_contents:
269262
print(f'(automatically selected: within last {RECENT_DAYS} days):')
270263
recent_contents += auto_select_recent_initial_contents()
271-
else:
272-
print('(manually selected):')
273-
recent_contents = MANUAL_RECENT_INITIAL_CONTENTS
274264
for test in recent_contents:
275265
print(' ' + test)
276266
print()
@@ -335,7 +325,7 @@ def pick_initial_contents():
335325
return
336326
# some of the time use initial contents that are known to be especially
337327
# important
338-
if random.random() < 0.5:
328+
if IMPORTANT_INITIAL_CONTENTS and random.random() < 0.5:
339329
test_name = random.choice(IMPORTANT_INITIAL_CONTENTS)
340330
else:
341331
test_name = random.choice(all_tests)
@@ -1393,6 +1383,7 @@ def handle(self, wasm):
13931383

13941384

13951385
test_suffixes = ['*.wasm', '*.wast', '*.wat']
1386+
13961387
core_tests = shared.get_tests(shared.get_test_dir('.'), test_suffixes)
13971388
passes_tests = shared.get_tests(shared.get_test_dir('passes'), test_suffixes)
13981389
spec_tests = shared.get_tests(shared.get_test_dir('spec'), test_suffixes)

0 commit comments

Comments
 (0)