Skip to content

Commit c7e9271

Browse files
authored
[fuzzing] Give each testcase handler a list of feature flags it requires. (#2225)
That way we can still test new flags on modes that do support them (e.g. FuzzExec runs on everything)
1 parent 774fdbb commit c7e9271

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

scripts/fuzz_opt.py

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,15 @@
2828

2929
NANS = True
3030

31+
# feature options that are always passed to the tools.
3132
# exceptions: https://github.com/WebAssembly/binaryen/issues/2195
3233
# simd: known issues with d8
3334
# atomics, bulk memory: doesn't work in wasm2js
3435
# truncsat: https://github.com/WebAssembly/binaryen/issues/2198
35-
FEATURE_OPTS = ['--all-features', '--disable-exception-handling', '--disable-simd', '--disable-threads', '--disable-bulk-memory', '--disable-nontrapping-float-to-int']
36+
CONSTANT_FEATURE_OPTS = ['--all-features']
37+
38+
# possible feature options that are sometimes passed to the tools.
39+
POSSIBLE_FEATURE_OPTS = ['--disable-exception-handling', '--disable-simd', '--disable-threads', '--disable-bulk-memory', '--disable-nontrapping-float-to-int']
3640

3741
FUZZ_OPTS = []
3842

@@ -75,6 +79,21 @@ def randomize_pass_debug():
7579
del os.environ['BINARYEN_PASS_DEBUG']
7680

7781

82+
def randomize_feature_opts():
83+
global FEATURE_OPTS
84+
FEATURE_OPTS = CONSTANT_FEATURE_OPTS[:]
85+
# half the time apply all the possible opts. this lets all test runners work at max
86+
# capacity at least half the time, as otherwise if they need almost all the opts, the
87+
# chance of getting them is exponentially small.
88+
if random.random() < 0.5:
89+
FEATURE_OPTS += POSSIBLE_FEATURE_OPTS
90+
else:
91+
for possible in POSSIBLE_FEATURE_OPTS:
92+
if random.random() < 0.5:
93+
FEATURE_OPTS.append(possible)
94+
print('feature opts:', ' '.join(FEATURE_OPTS))
95+
96+
7897
# Test outputs we want to ignore are marked this way.
7998
IGNORE = '[binaryen-fuzzer-ignore]'
8099

@@ -145,7 +164,7 @@ def run_bynterp(wasm, args):
145164

146165

147166
def run_d8(wasm):
148-
return run_vm(['d8', in_binaryen('scripts', 'fuzz_shell.js'), '--', wasm])
167+
return run_vm(['d8'] + V8_OPTS + [in_binaryen('scripts', 'fuzz_shell.js'), '--', wasm])
149168

150169

151170
# Each test case handler receives two wasm files, one before and one after some changes
@@ -159,6 +178,9 @@ def handle_pair(self, before_wasm, after_wasm, opts):
159178
self.handle(before_wasm)
160179
self.handle(after_wasm)
161180

181+
def can_run_on_feature_opts(self, feature_opts):
182+
return True
183+
162184

163185
# Run VMs and compare results
164186
class CompareVMs(TestCaseHandler):
@@ -199,6 +221,9 @@ def compare_vs(self, before, after):
199221
if NANS:
200222
break
201223

224+
def can_run_on_feature_opts(self, feature_opts):
225+
return all([x in feature_opts for x in ['--disable-simd']])
226+
202227

203228
# Fuzz the interpreter with --fuzz-exec. This tests everything in a single command (no
204229
# two separate binaries) so it's easy to reproduce.
@@ -244,6 +269,9 @@ def run(self, wasm):
244269
out = IGNORE
245270
return out
246271

272+
def can_run_on_feature_opts(self, feature_opts):
273+
return all([x in feature_opts for x in ['--disable-exception-handling', '--disable-simd', '--disable-threads', '--disable-bulk-memory', '--disable-nontrapping-float-to-int']])
274+
247275

248276
class Asyncify(TestCaseHandler):
249277
def handle_pair(self, before_wasm, after_wasm, opts):
@@ -286,6 +314,9 @@ def do_asyncify(wasm):
286314
compare(before, before_asyncify, 'Asyncify (before/before_asyncify)')
287315
compare(before, after_asyncify, 'Asyncify (before/after_asyncify)')
288316

317+
def can_run_on_feature_opts(self, feature_opts):
318+
return all([x in feature_opts for x in ['--disable-exception-handling', '--disable-simd']])
319+
289320

290321
# The global list of all test case handlers
291322
testcase_handlers = [
@@ -300,6 +331,7 @@ def do_asyncify(wasm):
300331
# Do one test, given an input file for -ttf and some optimizations to run
301332
def test_one(random_input, opts):
302333
randomize_pass_debug()
334+
randomize_feature_opts()
303335

304336
bytes = 0
305337

@@ -319,7 +351,9 @@ def test_one(random_input, opts):
319351
shutil.copyfile('a.js', 'b.js')
320352

321353
for testcase_handler in testcase_handlers:
322-
testcase_handler.handle_pair(before_wasm='a.wasm', after_wasm='b.wasm', opts=opts + FUZZ_OPTS + FEATURE_OPTS)
354+
print('running testcase handler:', testcase_handler.__class__.__name__)
355+
if testcase_handler.can_run_on_feature_opts(FEATURE_OPTS):
356+
testcase_handler.handle_pair(before_wasm='a.wasm', after_wasm='b.wasm', opts=opts + FUZZ_OPTS + FEATURE_OPTS)
323357

324358
return bytes
325359

0 commit comments

Comments
 (0)