Skip to content

Commit eb6c79d

Browse files
authored
[NFC] Fuzzer: Add a run_js() method (#8588)
This refactors the code a bit to allow the VM classes in the fuzzer to run JS. The function also allows running it in a checked (Python exception on a non-0 return code) or unchecked way. A future fuzzer will use this `run_js` method.
1 parent f7b08ed commit eb6c79d

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

scripts/fuzz_opt.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ def note_ignored_vm_run(reason, extra_text='', amount=1):
606606

607607

608608
# Run a VM command, and filter out known issues.
609-
def run_vm(cmd):
609+
def run_vm(cmd, checked=True):
610610
def filter_known_issues(output):
611611
known_issues = [
612612
# can be caused by flatten, ssa, etc. passes
@@ -649,7 +649,11 @@ def filter_known_issues(output):
649649

650650
try:
651651
# some known issues do not cause the entire process to fail
652-
return filter_known_issues(run(cmd))
652+
if checked:
653+
ret = run(cmd)
654+
else:
655+
ret = run_unchecked(cmd)
656+
return filter_known_issues(ret)
653657
except subprocess.CalledProcessError:
654658
# other known issues do make it fail, so re-run without checking for
655659
# success and see if we should ignore it
@@ -696,6 +700,7 @@ def get_v8_extra_flags():
696700

697701

698702
V8_LIFTOFF_ARGS = ['--liftoff']
703+
V8_NO_LIFTOFF_ARGS = ['--no-liftoff']
699704

700705

701706
# Default to running with liftoff enabled, because we need to pick either
@@ -831,8 +836,13 @@ def can_compare_to_other(self, other):
831836
class D8:
832837
name = 'd8'
833838

834-
def run(self, wasm, extra_d8_flags=[]):
835-
return run_vm([shared.V8, get_fuzz_shell_js()] + shared.V8_OPTS + get_v8_extra_flags() + extra_d8_flags + ['--', wasm])
839+
extra_d8_flags = []
840+
841+
def run_js(self, js, wasm, checked=True):
842+
return run_vm([shared.V8, js] + shared.V8_OPTS + get_v8_extra_flags() + self.extra_d8_flags + ['--', wasm], checked=checked)
843+
844+
def run(self, wasm):
845+
return self.run_js(js=get_fuzz_shell_js(), wasm=wasm)
836846

837847
def can_run(self, wasm):
838848
return all_disallowed(DISALLOWED_FEATURES_IN_V8)
@@ -856,16 +866,13 @@ def can_compare_to_other(self, other):
856866
class D8Liftoff(D8):
857867
name = 'd8_liftoff'
858868

859-
def run(self, wasm):
860-
return super().run(wasm, extra_d8_flags=V8_LIFTOFF_ARGS)
869+
extra_d8_flags = V8_LIFTOFF_ARGS
861870

862871

863872
class D8Turboshaft(D8):
864873
name = 'd8_turboshaft'
865874

866-
def run(self, wasm):
867-
flags = ['--no-liftoff']
868-
return super().run(wasm, extra_d8_flags=flags)
875+
extra_d8_flags = V8_NO_LIFTOFF_ARGS
869876

870877

871878
class Wasm2C:

0 commit comments

Comments
 (0)