diff options
author | Alon Zakai <alonzakai@gmail.com> | 2019-01-10 19:31:20 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-10 19:31:20 -0800 |
commit | 45714b5fc6cf14c112bc4f188aca427464ab69d8 (patch) | |
tree | 11a85c5fce2dfaa36650e0e6766d4d3f8b0a2366 /test/passes/emit-js-wrapper=a.js.wast.js | |
parent | 4084d6e70922f8b1cc00c3a24bf5db41e03d5e79 (diff) | |
download | binaryen-45714b5fc6cf14c112bc4f188aca427464ab69d8.tar.gz binaryen-45714b5fc6cf14c112bc4f188aca427464ab69d8.tar.bz2 binaryen-45714b5fc6cf14c112bc4f188aca427464ab69d8.zip |
Compare binaryen fuzz-exec to JS VMs (#1856)
The main fuzz_opt.py script compares JS VMs, and separately runs binaryen's fuzz-exec that compares the binaryen interpreter to itself (before and after opts). This PR lets us directly compare binaryen's interpreter output to JS VMs. This found a bunch of minor things we can do better on both sides, giving more fuzz coverage.
To enable this, a bunch of tiny fixes were needed:
* Add --fuzz-exec-before which is like --fuzz-exec but just runs the code before opts are run, instead of before and after.
* Normalize double printing (so JS and C++ print comparable things). This includes negative zero in JS, which we never printed properly til now.
* Various improvements to how we print fuzz-exec logging - remove unuseful things, and normalize the others across JS and C++.
* Properly legalize the wasm when --emit-js-wrapper (i.e., we will run the code from JS), and use that in the JS wrapper code.
Diffstat (limited to 'test/passes/emit-js-wrapper=a.js.wast.js')
-rw-r--r-- | test/passes/emit-js-wrapper=a.js.wast.js | 53 |
1 files changed, 33 insertions, 20 deletions
diff --git a/test/passes/emit-js-wrapper=a.js.wast.js b/test/passes/emit-js-wrapper=a.js.wast.js index f2e828c2b..9e8578781 100644 --- a/test/passes/emit-js-wrapper=a.js.wast.js +++ b/test/passes/emit-js-wrapper=a.js.wast.js @@ -20,12 +20,26 @@ if (typeof process === 'object' && typeof require === 'function' /* node.js dete binary = read(args[0], 'binary'); } } +function literal(x, type) { + var ret = type + '.const '; + switch (type) { + case 'i32': ret += (x | 0); break; + case 'f32': + case 'f64': { + if (x == 0 && (1 / x) < 0) ret += '-'; + ret += x; + break; + } + default: throw 'what?'; + } + return ret; +} var instance = new WebAssembly.Instance(new WebAssembly.Module(binary), { 'fuzzing-support': { - 'log-i32': function(x) { console.log('i32: ' + x) }, - 'log-i64': function(x, y) { console.log('i64: ' + x + ', ' + y) }, - 'log-f32': function(x) { console.log('f32: ' + x) }, - 'log-f64': function(x) { console.log('f64: ' + x) } + '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 }, @@ -34,37 +48,36 @@ var instance = new WebAssembly.Instance(new WebAssembly.Module(binary), { }); if (instance.exports.hangLimitInitializer) instance.exports.hangLimitInitializer(); try { - console.log('calling: add'); - console.log(' result: ' + instance.exports.add(0, 0)); + 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); + console.log('exception: ' + e); } if (instance.exports.hangLimitInitializer) instance.exports.hangLimitInitializer(); try { - console.log('calling: no_return'); -instance.exports.no_return(0); + console.log('[fuzz-exec] calling $no_return'); + instance.exports.no_return(0); } catch (e) { - console.log(' exception: ' + e); + console.log('exception: ' + e); } if (instance.exports.hangLimitInitializer) instance.exports.hangLimitInitializer(); try { - console.log('calling: types'); -instance.exports.types(0, 0, 0, 0, 0); + console.log('[fuzz-exec] calling $types'); + instance.exports.types(0, 0, 0, 0, 0); } catch (e) { - console.log(' exception: ' + e); + console.log('exception: ' + e); } if (instance.exports.hangLimitInitializer) instance.exports.hangLimitInitializer(); try { - console.log('calling: types2'); -instance.exports.types2(0, 0, 0); + console.log('[fuzz-exec] calling $types2'); + instance.exports.types2(0, 0, 0); } catch (e) { - console.log(' exception: ' + e); + console.log('exception: ' + e); } if (instance.exports.hangLimitInitializer) instance.exports.hangLimitInitializer(); try { - console.log('calling: types3'); - console.log(' result: ' + instance.exports.types3(0, 0, 0)); + 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); + console.log('exception: ' + e); } -console.log('done.') |