Skip to content

Commit da781b2

Browse files
committed
fix
1 parent ddd5098 commit da781b2

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

scripts/fuzz_opt.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2113,6 +2113,17 @@ class PreserveImportsExportsJS(TestCaseHandler):
21132113
frequency = 1
21142114

21152115
def handle_pair(self, input, before_wasm, after_wasm, opts):
2116+
try:
2117+
self.do_handle_pair(input, before_wasm, after_wasm, opts)
2118+
except Exception as e:
2119+
if not os.environ.get('BINARYEN_TRUST_GIVEN_WASM'):
2120+
# We errored, and we were not given a wasm file to trust as we
2121+
# reduce, so this is the first time we hit an error. Save the
2122+
# pre wasm file, the one we began with, as `before_wasm`, so
2123+
# that the reducer will make us proceed exactly from there.
2124+
shutil.copyfile(self.pre_wasm, before_wasm)
2125+
2126+
def do_handle_pair(self, input, before_wasm, after_wasm, opts):
21162127
# Some of the time use a custom input. The normal inputs the fuzzer
21172128
# generates are in range INPUT_SIZE_MIN-INPUT_SIZE_MAX, which is good
21182129
# for new testcases, but the more changes we make to js+wasm testcases,
@@ -2153,16 +2164,16 @@ def handle_pair(self, input, before_wasm, after_wasm, opts):
21532164
'-g',
21542165
])
21552166

2167+
# We successfully generated pre_wasm; stash it for possible reduction
2168+
# purposes later.
2169+
self.pre_wasm = pre_wasm
2170+
21562171
# If we were given a wasm file, use that instead of all the above. We
21572172
# do this now, after creating pre_wasm, because we still need to consume
21582173
# all the randomness normally.
21592174
if os.environ.get('BINARYEN_TRUST_GIVEN_WASM'):
21602175
print('using given wasm', before_wasm)
21612176
pre_wasm = before_wasm
2162-
else:
2163-
# Otherwise, overwrite before_wasm, so that if we end up reducing
2164-
# this, the fuzzer knows where to start.
2165-
shutil.copyfile(pre_wasm, before_wasm)
21662177

21672178
# Pick a vm and run before we optimize the wasm.
21682179
vms = [

0 commit comments

Comments
 (0)