summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2024-02-20 15:22:28 -0800
committerGitHub <noreply@github.com>2024-02-20 15:22:28 -0800
commit60b2daea5467e419899e9201a342cc817d6fd68e (patch)
treeb4bcdbc5f1fa99b58f9edc5726bc44f9e2e5949b /test
parent403153868b936250c52d150ef158419a1d67bf55 (diff)
downloadbinaryen-60b2daea5467e419899e9201a342cc817d6fd68e.tar.gz
binaryen-60b2daea5467e419899e9201a342cc817d6fd68e.tar.bz2
binaryen-60b2daea5467e419899e9201a342cc817d6fd68e.zip
Fuzzer: Remove --emit-js-shell logic and reuse fuzz_shell.js instead (#6310)
We had two JS files that could run a wasm file for fuzzing purposes: * --emit-js-shell, which emitted a custom JS file that runs the wasm. * scripts/fuzz_shell.js, which was a generic file that did the same. Both of those load the wasm and then call the exports in order and print out logging as it goes of their return values (if any), exceptions, etc. Then the fuzzer compares that output to running the same wasm in another VM, etc. The difference is that one was custom for the wasm file, and one was generic. Aside from that they are similar and duplicated a bunch of code. This PR improves things by removing 1 and using 2 in all places, that is, we now use the generic file everywhere. I believe we added 1 because we thought a generic file can't do all the things we need, like know the order of exports and the types of return values, but in practice there are ways to do those things: The exports are in fact in the proper order (JS order of iteration is deterministic, thankfully), and for the type we don't want to print type internals anyhow since that would limit fuzzing --closed-world. We do need to be careful with types in JS (see notes in the PR about the type of null) but it's not too bad. As for the types of params, it's fine to pass in null for them all anyhow (null converts to a number or a reference without error).
Diffstat (limited to 'test')
-rw-r--r--test/lit/exec/no-compare-refs.wast4
-rw-r--r--test/lit/help/wasm-opt.test4
-rw-r--r--test/lit/unicode-filenames.wast2
-rw-r--r--test/passes/emit-js-wrapper=a.js.txt84
-rw-r--r--test/passes/emit-js-wrapper=a.js.wast37
-rw-r--r--test/passes/emit-js-wrapper=a.js.wast.js79
-rw-r--r--test/passes/fuzz-exec_all-features.txt4
-rw-r--r--test/passes/simplify-globals_all-features_fuzz-exec.txt4
8 files changed, 7 insertions, 211 deletions
diff --git a/test/lit/exec/no-compare-refs.wast b/test/lit/exec/no-compare-refs.wast
index bfa317a53..646ec1550 100644
--- a/test/lit/exec/no-compare-refs.wast
+++ b/test/lit/exec/no-compare-refs.wast
@@ -12,11 +12,11 @@
;; The type of the reference this function returns will change as a result of
;; signature pruning. The fuzzer should not complain about this.
;; CHECK: [fuzz-exec] calling return-ref
- ;; CHECK-NEXT: [fuzz-exec] note result: return-ref => funcref
+ ;; CHECK-NEXT: [fuzz-exec] note result: return-ref => function
(func $return-ref (export "return-ref") (result funcref)
(ref.func $no-use-param)
)
)
;; CHECK: [fuzz-exec] calling return-ref
-;; CHECK-NEXT: [fuzz-exec] note result: return-ref => funcref
+;; CHECK-NEXT: [fuzz-exec] note result: return-ref => function
;; CHECK-NEXT: [fuzz-exec] comparing return-ref
diff --git a/test/lit/help/wasm-opt.test b/test/lit/help/wasm-opt.test
index be5924cf7..5e3a322ed 100644
--- a/test/lit/help/wasm-opt.test
+++ b/test/lit/help/wasm-opt.test
@@ -53,10 +53,6 @@
;; CHECK-NEXT: loads/stores/indirect calls when
;; CHECK-NEXT: fuzzing
;; CHECK-NEXT:
-;; CHECK-NEXT: --emit-js-wrapper,-ejw Emit a JavaScript wrapper file
-;; CHECK-NEXT: that can run the wasm with some
-;; CHECK-NEXT: test values, useful for fuzzing
-;; CHECK-NEXT:
;; CHECK-NEXT: --emit-spec-wrapper,-esw Emit a wasm spec interpreter
;; CHECK-NEXT: wrapper file that can run the
;; CHECK-NEXT: wasm with some test values,
diff --git a/test/lit/unicode-filenames.wast b/test/lit/unicode-filenames.wast
index f30ad9c09..a3fbabed0 100644
--- a/test/lit/unicode-filenames.wast
+++ b/test/lit/unicode-filenames.wast
@@ -1,6 +1,6 @@
;; RUN: wasm-as %s -o %t-❤.wasm --source-map %t-🗺️.map
;; RUN: cat %t-🗺️.map | filecheck %s --check-prefix SOURCEMAP
-;; RUN: wasm-opt %t-❤.wasm -o %t-🤬.wasm --emit-js-wrapper %t-❤.js --input-source-map %t-🗺️.map --output-source-map %t-🗺️.out.map
+;; RUN: wasm-opt %t-❤.wasm -o %t-🤬.wasm --emit-spec-wrapper %t-❤.js --input-source-map %t-🗺️.map --output-source-map %t-🗺️.out.map
;; RUN: cat %t-🗺️.out.map | filecheck %s --check-prefix SOURCEMAP
;; RUN: wasm-dis %t-🤬.wasm | filecheck %s --check-prefix MODULE
diff --git a/test/passes/emit-js-wrapper=a.js.txt b/test/passes/emit-js-wrapper=a.js.txt
deleted file mode 100644
index 4a72da8eb..000000000
--- a/test/passes/emit-js-wrapper=a.js.txt
+++ /dev/null
@@ -1,84 +0,0 @@
-(module
- (type $0 (func (param i32 i32) (result i32)))
- (type $1 (func (param i32)))
- (type $2 (func (param i32 i64 f32 f64)))
- (type $3 (func (param i32 f32 f64)))
- (type $4 (func (param i32 f32 f64) (result i64)))
- (type $5 (func (param i32 i32 i32 f32 f64)))
- (type $6 (func (param i32 f32 f64) (result i32)))
- (import "env" "setTempRet0" (func $setTempRet0 (param i32)))
- (memory $0 256 256)
- (export "add" (func $add))
- (export "no_return" (func $no-return))
- (export "types" (func $legalstub$types))
- (export "types2" (func $types2))
- (export "types3" (func $legalstub$types3))
- (func $add (param $x i32) (param $y i32) (result i32)
- (i32.add
- (local.get $x)
- (local.get $y)
- )
- )
- (func $unexported (param $x i32) (param $y i32) (result i32)
- (i32.add
- (local.get $x)
- (local.get $y)
- )
- )
- (func $no-return (param $x i32)
- (drop
- (i32.add
- (local.get $x)
- (local.get $x)
- )
- )
- )
- (func $types (param $x i32) (param $y i64) (param $z f32) (param $w f64)
- (nop)
- )
- (func $types2 (param $x i32) (param $z f32) (param $w f64)
- (nop)
- )
- (func $types3 (param $x i32) (param $z f32) (param $w f64) (result i64)
- (i64.const 1)
- )
- (func $legalstub$types (param $0 i32) (param $1 i32) (param $2 i32) (param $3 f32) (param $4 f64)
- (call $types
- (local.get $0)
- (i64.or
- (i64.extend_i32_u
- (local.get $1)
- )
- (i64.shl
- (i64.extend_i32_u
- (local.get $2)
- )
- (i64.const 32)
- )
- )
- (local.get $3)
- (local.get $4)
- )
- )
- (func $legalstub$types3 (param $0 i32) (param $1 f32) (param $2 f64) (result i32)
- (local $3 i64)
- (local.set $3
- (call $types3
- (local.get $0)
- (local.get $1)
- (local.get $2)
- )
- )
- (call $setTempRet0
- (i32.wrap_i64
- (i64.shr_u
- (local.get $3)
- (i64.const 32)
- )
- )
- )
- (i32.wrap_i64
- (local.get $3)
- )
- )
-)
diff --git a/test/passes/emit-js-wrapper=a.js.wast b/test/passes/emit-js-wrapper=a.js.wast
deleted file mode 100644
index 8ebd83b0b..000000000
--- a/test/passes/emit-js-wrapper=a.js.wast
+++ /dev/null
@@ -1,37 +0,0 @@
-(module
- (memory $0 256 256)
- (export "add" (func $add))
- (export "no_return" (func $no-return)) ;; note exported name is slightly different
- (export "types" (func $types))
- (export "types2" (func $types2))
- (export "types3" (func $types3))
- (func $add (param $x i32) (param $y i32) (result i32)
- (i32.add
- (local.get $x)
- (local.get $y)
- )
- )
- (func $unexported (param $x i32) (param $y i32) (result i32)
- (i32.add
- (local.get $x)
- (local.get $y)
- )
- )
- (func $no-return (param $x i32)
- (drop
- (i32.add
- (local.get $x)
- (local.get $x)
- )
- )
- )
- (func $types (param $x i32) (param $y i64) (param $z f32) (param $w f64)
- (nop)
- )
- (func $types2 (param $x i32) (param $z f32) (param $w f64)
- (nop)
- )
- (func $types3 (param $x i32) (param $z f32) (param $w f64) (result i64)
- (i64.const 1)
- )
-)
diff --git a/test/passes/emit-js-wrapper=a.js.wast.js b/test/passes/emit-js-wrapper=a.js.wast.js
deleted file mode 100644
index 916f029f5..000000000
--- a/test/passes/emit-js-wrapper=a.js.wast.js
+++ /dev/null
@@ -1,79 +0,0 @@
-if (typeof console === 'undefined') {
- console = { log: print };
-}
-var tempRet0;
-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');
- }
-}
-function literal(x, type) {
- var ret = '';
- switch (type) {
- case 'i32': ret += (x | 0); break;
- case 'f32':
- case 'f64': {
- if (x == 0 && (1 / x) < 0) ret += '-';
- ret += Number(x).toString();
- break;
- }
- // For anything else, just print the type.
- default: ret += type; break;
- }
- return ret;
-}
-var instance = new WebAssembly.Instance(new WebAssembly.Module(binary), {
- 'fuzzing-support': {
- 'log-i32': function(x) { console.log('[LoggingExternalInterface logging ' + literal(x, 'i32') + ']') },
- 'log-i64': function(x, y) { console.log('[LoggingExternalInterface logging ' + literal(x, 'i32') + ' ' + literal(y, 'i32') + ']') },
- 'log-f32': function(x) { console.log('[LoggingExternalInterface logging ' + literal(x, 'f64') + ']') },
- 'log-f64': function(x) { console.log('[LoggingExternalInterface logging ' + literal(x, 'f64') + ']') },
- },
- 'env': {
- 'setTempRet0': function(x) { tempRet0 = x },
- 'getTempRet0': function() { return tempRet0 },
- },
-});
-try {
- console.log('[fuzz-exec] calling add');
- console.log('[fuzz-exec] note result: add => ' + literal(instance.exports.add(0, 0), 'i32'));
-} catch (e) {
- console.log('exception!' /* + e */);
-}
-try {
- console.log('[fuzz-exec] calling no_return');
- instance.exports.no_return(0);
-} catch (e) {
- console.log('exception!' /* + e */);
-}
-try {
- console.log('[fuzz-exec] calling types');
- instance.exports.types(0, 0, 0, 0, 0);
-} catch (e) {
- console.log('exception!' /* + e */);
-}
-try {
- console.log('[fuzz-exec] calling types2');
- instance.exports.types2(0, 0, 0);
-} catch (e) {
- console.log('exception!' /* + e */);
-}
-try {
- console.log('[fuzz-exec] calling types3');
- console.log('[fuzz-exec] note result: types3 => ' + literal(instance.exports.types3(0, 0, 0), 'i32'));
-} catch (e) {
- console.log('exception!' /* + e */);
-}
diff --git a/test/passes/fuzz-exec_all-features.txt b/test/passes/fuzz-exec_all-features.txt
index 22ea5f06a..fcb8e8a3c 100644
--- a/test/passes/fuzz-exec_all-features.txt
+++ b/test/passes/fuzz-exec_all-features.txt
@@ -212,7 +212,7 @@
[LoggingExternalInterface logging 214]
[fuzz-exec] comparing rmw-reads-modifies-and-writes-asymmetrical
[fuzz-exec] calling func
-[fuzz-exec] note result: func => funcref
+[fuzz-exec] note result: func => function
(module
(type $0 (func (result funcref)))
(elem declare func $func)
@@ -222,5 +222,5 @@
)
)
[fuzz-exec] calling func
-[fuzz-exec] note result: func => funcref
+[fuzz-exec] note result: func => function
[fuzz-exec] comparing func
diff --git a/test/passes/simplify-globals_all-features_fuzz-exec.txt b/test/passes/simplify-globals_all-features_fuzz-exec.txt
index fbbcc30c4..cb097d587 100644
--- a/test/passes/simplify-globals_all-features_fuzz-exec.txt
+++ b/test/passes/simplify-globals_all-features_fuzz-exec.txt
@@ -1,5 +1,5 @@
[fuzz-exec] calling export
-[fuzz-exec] note result: export => funcref
+[fuzz-exec] note result: export => function
(module
(type $0 (func (param f32 i31ref i64 f64 funcref)))
(type $1 (func (result funcref)))
@@ -17,5 +17,5 @@
)
)
[fuzz-exec] calling export
-[fuzz-exec] note result: export => funcref
+[fuzz-exec] note result: export => function
[fuzz-exec] comparing export