diff options
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/fuzz_opt.py | 14 | ||||
-rw-r--r-- | scripts/test/shared.py | 41 | ||||
-rw-r--r-- | scripts/validation_shell.js | 28 |
3 files changed, 68 insertions, 15 deletions
diff --git a/scripts/fuzz_opt.py b/scripts/fuzz_opt.py index bea4635ac..ead591317 100644 --- a/scripts/fuzz_opt.py +++ b/scripts/fuzz_opt.py @@ -21,7 +21,7 @@ import re import shutil import time -from test.shared import options, NODEJS +from test.shared import options, NODEJS, V8_OPTS # parameters @@ -32,18 +32,6 @@ FEATURE_OPTS = [] # '--all-features' etc FUZZ_OPTS = [] -V8_OPTS = [ - '--experimental-wasm-eh', - '--experimental-wasm-mv', - '--experimental-wasm-sat-f2i-conversions', - '--experimental-wasm-se', - '--experimental-wasm-threads', - '--experimental-wasm-simd', - '--experimental-wasm-anyref', - '--experimental-wasm-bulk-memory', - '--experimental-wasm-return-call' -] - INPUT_SIZE_LIMIT = 150 * 1024 LOG_LIMIT = 125 diff --git a/scripts/test/shared.py b/scripts/test/shared.py index 9352f0b9d..37874e61e 100644 --- a/scripts/test/shared.py +++ b/scripts/test/shared.py @@ -157,6 +157,7 @@ NATIVEXX = (os.environ.get('CXX') or which('mingw32-g++') or which('g++') or which('clang++')) NODEJS = os.getenv('NODE', which('nodejs') or which('node')) MOZJS = which('mozjs') or which('spidermonkey') +V8 = which('v8') or which('d8') EMCC = which('emcc') BINARYEN_INSTALL_DIR = os.path.dirname(options.binaryen_bin) @@ -190,7 +191,13 @@ if options.valgrind: ASM2WASM = wrap_with_valgrind(ASM2WASM) WASM_SHELL = wrap_with_valgrind(WASM_SHELL) -os.environ['BINARYEN'] = os.getcwd() + +def in_binaryen(*args): + __rootpath__ = os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__)))) + return os.path.join(__rootpath__, *args) + + +os.environ['BINARYEN'] = in_binaryen() def get_platform(): @@ -204,6 +211,19 @@ def has_shell_timeout(): return get_platform() != 'windows' and os.system('timeout 1s pwd') == 0 +# Default options to pass to v8. These enable all features. +V8_OPTS = [ + '--experimental-wasm-eh', + '--experimental-wasm-mv', + '--experimental-wasm-sat-f2i-conversions', + '--experimental-wasm-se', + '--experimental-wasm-threads', + '--experimental-wasm-simd', + '--experimental-wasm-anyref', + '--experimental-wasm-bulk-memory', + '--experimental-wasm-return-call' +] + has_vanilla_llvm = False # external tools @@ -377,8 +397,18 @@ if not has_vanilla_emcc: # check utilities + +def validate_binary(wasm): + if V8: + cmd = [V8] + V8_OPTS + [in_binaryen('scripts', 'validation_shell.js'), '--', wasm] + print ' ', ' '.join(cmd) + subprocess.check_call(cmd, stdout=subprocess.PIPE) + else: + print '(skipping v8 binary validation)' + + def binary_format_check(wast, verify_final_result=True, wasm_as_args=['-g'], - binary_suffix='.fromBinary'): + binary_suffix='.fromBinary', original_wast=None): # checks we can convert the wast to binary and back print ' (binary format check)' @@ -389,6 +419,13 @@ def binary_format_check(wast, verify_final_result=True, wasm_as_args=['-g'], subprocess.check_call(cmd, stdout=subprocess.PIPE) assert os.path.exists('a.wasm') + # make sure it is a valid wasm, using a real wasm VM + if os.path.basename(original_wast or wast) not in [ + 'atomics.wast', # https://bugs.chromium.org/p/v8/issues/detail?id=9425 + 'simd.wast', # https://bugs.chromium.org/p/v8/issues/detail?id=8460 + ]: + validate_binary('a.wasm') + cmd = WASM_DIS + ['a.wasm', '-o', 'ab.wast'] print ' ', ' '.join(cmd) if os.path.exists('ab.wast'): diff --git a/scripts/validation_shell.js b/scripts/validation_shell.js new file mode 100644 index 000000000..3d1f76846 --- /dev/null +++ b/scripts/validation_shell.js @@ -0,0 +1,28 @@ +// Test a file is valid, by just loading it. + +// Shell integration. +if (typeof console === 'undefined') { + console = { log: print }; +} +var binary; +if (typeof process === 'object' && typeof require === 'function' /* node.js detection */) { + var args = process.argv.slice(2); + binary = require('fs').readFileSync(args[0]); + if (!binary.buffer) binary = new Uint8Array(binary); +} else { + var args; + if (typeof scriptArgs != 'undefined') { + args = scriptArgs; + } else if (typeof arguments != 'undefined') { + args = arguments; + } + if (typeof readbuffer === 'function') { + binary = new Uint8Array(readbuffer(args[0])); + } else { + binary = read(args[0], 'binary'); + } +} + +// Test the wasm for validity by compiling it. +new WebAssembly.Module(binary); + |