Skip to content

Fix features section handling in the fuzzer #3980

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 13, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions scripts/fuzz_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,21 @@ def randomize_feature_opts():
print('randomized feature opts:', ' '.join(FEATURE_OPTS))


ALL_FEATURE_OPTS = ['--all-features', '-all', '--mvp-features', '-mvp']


def update_feature_opts(wasm):
global FEATURE_OPTS
# we will re-compute the features; leave all other things as they are
EXTRA = [x for x in FEATURE_OPTS if not x.startswith('--enable') and
not x.startswith('--disable') and x not in ALL_FEATURE_OPTS]
FEATURE_OPTS = run([in_bin('wasm-opt'), wasm] + FEATURE_OPTS + ['--print-features']).strip().split('\n')
# filter out '', which can happen if no features are enabled
FEATURE_OPTS = [x for x in FEATURE_OPTS if x]
print(FEATURE_OPTS, EXTRA)
FEATURE_OPTS += EXTRA


def randomize_fuzz_settings():
# a list of the optimizations to run on the wasm
global FUZZ_OPTS
Expand Down Expand Up @@ -448,6 +463,10 @@ def run_d8_wasm(wasm, liftoff=True):
return run_d8_js(in_binaryen('scripts', 'fuzz_shell.js'), [wasm], liftoff=liftoff)


def all_disallowed(features):
return not any(('--enable-' + x) in FEATURE_OPTS for x in features)


class TestCaseHandler:
# how frequent this handler will be run. 1 means always run it, 0.5 means half the
# time
Expand Down Expand Up @@ -563,7 +582,7 @@ def can_run(self, wasm):
if random.random() < 0.5:
return False
# wasm2c doesn't support most features
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']])
return all_disallowed(['exception-handling', 'simd', 'threads', 'bulk-memory', 'nontrapping-float-to-int', 'tail-call', 'sign-ext', 'reference-types', 'multivalue', 'gc'])

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

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


# Check for determinism - the same command must have the same output.
Expand Down Expand Up @@ -805,7 +824,7 @@ def can_run_on_feature_opts(self, feature_opts):
# specifically for growth here
if INITIAL_CONTENTS:
return False
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']])
return all_disallowed(['exception-handling', 'simd', 'threads', 'bulk-memory', 'nontrapping-float-to-int', 'tail-call', 'sign-ext', 'reference-types', 'multivalue', 'gc'])


class Asyncify(TestCaseHandler):
Expand Down Expand Up @@ -859,7 +878,7 @@ def do_asyncify(wasm):
compare(before, after_asyncify, 'Asyncify (before/after_asyncify)')

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


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

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