@@ -1874,15 +1874,21 @@ def test_one(random_input, given_wasm):
1874
1874
print ()
1875
1875
1876
1876
if given_wasm :
1877
- # if given a wasm file we want to use it as is, but we also want to
1878
- # apply properties like not having any NaNs, which the original fuzz
1879
- # wasm had applied. that is, we need to preserve properties like not
1880
- # having nans through reduction.
1881
- try :
1882
- run ([in_bin ('wasm-opt' ), given_wasm , '-o' , abspath ('a.wasm' )] + GEN_ARGS + FEATURE_OPTS )
1883
- except Exception as e :
1884
- print ("Internal error in fuzzer! Could not run given wasm" )
1885
- raise e
1877
+ # We are given a wasm file to operate on. By default we modify it in the
1878
+ # usual ways, like running DeNAN on it, which is important in many cases
1879
+ # (imagine the reducer generates a NAN, then we need to restore the
1880
+ # property of not having any). However, in some cases we do need to
1881
+ # trust the wasm is correct, or it is simpler to debug things without
1882
+ # constant changes in each reduction cycle, so we have an env var to
1883
+ # control that, BINARYEN_TRUST_GIVEN_WASM.
1884
+ if os .environ .get ('BINARYEN_TRUST_GIVEN_WASM' ):
1885
+ shutil .copyfile (given_wasm , abspath ('a.wasm' ))
1886
+ else :
1887
+ try :
1888
+ run ([in_bin ('wasm-opt' ), given_wasm , '-o' , abspath ('a.wasm' )] + GEN_ARGS + FEATURE_OPTS )
1889
+ except Exception as e :
1890
+ print ("Internal error in fuzzer! Could not run given wasm" )
1891
+ raise e
1886
1892
else :
1887
1893
# emit the target features section so that reduction can work later,
1888
1894
# without needing to specify the features
@@ -2351,7 +2357,9 @@ def get_random_opts():
2351
2357
(If it does not, then one possible issue is that the fuzzer fails to write a
2352
2358
valid binary. If so, you can print the output of the fuzzer's first command
2353
2359
(using -ttf / --translate-to-fuzz) in text form and run the reduction from that,
2354
- passing --text to the reducer.)
2360
+ passing --text to the reducer. Another possible fix is to avoid re-processing
2361
+ the wasm for fuzzing in each iteration, by adding
2362
+ BINARYEN_TRUST_GIVEN_WASM=1 in the env.)
2355
2363
2356
2364
You can also read "%(reduce_sh)s" which has been filled out for you and includes
2357
2365
docs and suggestions.
0 commit comments