Skip to content

Commit b217eff

Browse files
authored
Fix features section handling in the fuzzer (#3980)
The features section is additive since #3960. For the fuzzer to know which features are used, it therefore needs to also scan the features section. To do this, run --print-features to get the total features used from both flags + the features section. A result of this is that we now have a list of enabled features instead of "enable all, then disable". This is actually clearer I think, but it does require inverting the logic in some places.
1 parent 2bdd9e2 commit b217eff

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

scripts/fuzz_opt.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,21 @@ def randomize_feature_opts():
117117
print('randomized feature opts:', ' '.join(FEATURE_OPTS))
118118

119119

120+
ALL_FEATURE_OPTS = ['--all-features', '-all', '--mvp-features', '-mvp']
121+
122+
123+
def update_feature_opts(wasm):
124+
global FEATURE_OPTS
125+
# we will re-compute the features; leave all other things as they are
126+
EXTRA = [x for x in FEATURE_OPTS if not x.startswith('--enable') and
127+
not x.startswith('--disable') and x not in ALL_FEATURE_OPTS]
128+
FEATURE_OPTS = run([in_bin('wasm-opt'), wasm] + FEATURE_OPTS + ['--print-features']).strip().split('\n')
129+
# filter out '', which can happen if no features are enabled
130+
FEATURE_OPTS = [x for x in FEATURE_OPTS if x]
131+
print(FEATURE_OPTS, EXTRA)
132+
FEATURE_OPTS += EXTRA
133+
134+
120135
def randomize_fuzz_settings():
121136
# a list of the optimizations to run on the wasm
122137
global FUZZ_OPTS
@@ -448,6 +463,10 @@ def run_d8_wasm(wasm, liftoff=True):
448463
return run_d8_js(in_binaryen('scripts', 'fuzz_shell.js'), [wasm], liftoff=liftoff)
449464

450465

466+
def all_disallowed(features):
467+
return not any(('--enable-' + x) in FEATURE_OPTS for x in features)
468+
469+
451470
class TestCaseHandler:
452471
# how frequent this handler will be run. 1 means always run it, 0.5 means half the
453472
# time
@@ -563,7 +582,7 @@ def can_run(self, wasm):
563582
if random.random() < 0.5:
564583
return False
565584
# wasm2c doesn't support most features
566-
return all([x in FEATURE_OPTS for x in ['--disable-exception-handling', '--disable-simd', '--disable-threads', '--disable-bulk-memory', '--disable-nontrapping-float-to-int', '--disable-tail-call', '--disable-sign-ext', '--disable-reference-types', '--disable-multivalue', '--disable-gc']])
585+
return all_disallowed(['exception-handling', 'simd', 'threads', 'bulk-memory', 'nontrapping-float-to-int', 'tail-call', 'sign-ext', 'reference-types', 'multivalue', 'gc'])
567586

568587
def run(self, wasm):
569588
run([in_bin('wasm-opt'), wasm, '--emit-wasm2c-wrapper=main.c'] + FEATURE_OPTS)
@@ -667,7 +686,7 @@ def compare_before_and_after(self, before, after):
667686
compare(before[vm], after[vm], 'CompareVMs between before and after: ' + vm.name)
668687

669688
def can_run_on_feature_opts(self, feature_opts):
670-
return all([x in feature_opts for x in ['--disable-simd', '--disable-exception-handling', '--disable-multivalue']])
689+
return all_disallowed(['simd', 'exception-handling', 'multivalue'])
671690

672691

673692
# Check for determinism - the same command must have the same output.
@@ -805,7 +824,7 @@ def can_run_on_feature_opts(self, feature_opts):
805824
# specifically for growth here
806825
if INITIAL_CONTENTS:
807826
return False
808-
return all([x in feature_opts for x in ['--disable-exception-handling', '--disable-simd', '--disable-threads', '--disable-bulk-memory', '--disable-nontrapping-float-to-int', '--disable-tail-call', '--disable-sign-ext', '--disable-reference-types', '--disable-multivalue', '--disable-gc']])
827+
return all_disallowed(['exception-handling', 'simd', 'threads', 'bulk-memory', 'nontrapping-float-to-int', 'tail-call', 'sign-ext', 'reference-types', 'multivalue', 'gc'])
809828

810829

811830
class Asyncify(TestCaseHandler):
@@ -859,7 +878,7 @@ def do_asyncify(wasm):
859878
compare(before, after_asyncify, 'Asyncify (before/after_asyncify)')
860879

861880
def can_run_on_feature_opts(self, feature_opts):
862-
return all([x in feature_opts for x in ['--disable-exception-handling', '--disable-simd', '--disable-tail-call', '--disable-reference-types', '--disable-multivalue', '--disable-gc']])
881+
return all_disallowed(['exception-handling', 'simd', 'tail-call', 'reference-types', 'multivalue', 'gc'])
863882

864883

865884
# Check that the text format round-trips without error.
@@ -925,6 +944,7 @@ def test_one(random_input, given_wasm):
925944
wasm_size = os.stat('a.wasm').st_size
926945
bytes = wasm_size
927946
print('pre wasm size:', wasm_size)
947+
update_feature_opts('a.wasm')
928948

929949
# create a second wasm for handlers that want to look at pairs.
930950
generate_command = [in_bin('wasm-opt'), 'a.wasm', '-o', 'b.wasm'] + opts + FUZZ_OPTS + FEATURE_OPTS
@@ -1043,10 +1063,10 @@ def randomize_opt_flags():
10431063
if has_flatten:
10441064
print('avoiding multiple --flatten in a single command, due to exponential overhead')
10451065
continue
1046-
if '--disable-exception-handling' not in FEATURE_OPTS:
1066+
if '--enable-exception-handling' in FEATURE_OPTS:
10471067
print('avoiding --flatten due to exception catching which does not support it yet')
10481068
continue
1049-
if '--disable-multivalue' not in FEATURE_OPTS and '--disable-reference-types' not in FEATURE_OPTS:
1069+
if '--enable-multivalue' in FEATURE_OPTS and '--enable-reference-types' in FEATURE_OPTS:
10501070
print('avoiding --flatten due to multivalue + reference types not supporting it (spilling of non-nullable tuples)')
10511071
continue
10521072
if '--gc' not in FEATURE_OPTS:

0 commit comments

Comments
 (0)