diff options
author | Alon Zakai <azakai@google.com> | 2019-07-01 19:23:52 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-01 19:23:52 -0700 |
commit | f154364c01603b0b8cfd0055951e8283f20fabd7 (patch) | |
tree | 85e5add66cefc3ce338ef52bb4733b7091cf4dd4 /test/unit/input/bysyncify.js | |
parent | c3e45d4e5272486fae1ffb353c56e4d117fe4a21 (diff) | |
download | binaryen-f154364c01603b0b8cfd0055951e8283f20fabd7.tar.gz binaryen-f154364c01603b0b8cfd0055951e8283f20fabd7.tar.bz2 binaryen-f154364c01603b0b8cfd0055951e8283f20fabd7.zip |
Bysyncify: Assertion improvements (#2193)
Add assertions on stack overflow in all 4 Bysyncify API calls (previously only 2 did it).
Also add a check that those assertions are hit.
Diffstat (limited to 'test/unit/input/bysyncify.js')
-rw-r--r-- | test/unit/input/bysyncify.js | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/test/unit/input/bysyncify.js b/test/unit/input/bysyncify.js index 2e1bb4895..be6d32903 100644 --- a/test/unit/input/bysyncify.js +++ b/test/unit/input/bysyncify.js @@ -252,10 +252,53 @@ function coroutineTests() { ]), 'check yielded values') } +function stackOverflowAssertTests() { + console.log('\nstack overflow assertion tests\n\n'); + + // Get and compile the wasm. + + var binary = fs.readFileSync('c.wasm'); + + var module = new WebAssembly.Module(binary); + + var DATA_ADDR = 4; + + var instance = new WebAssembly.Instance(module, { + env: { + sleep: function() { + console.log('sleep...'); + exports.bysyncify_start_unwind(DATA_ADDR); + view[DATA_ADDR >> 2] = DATA_ADDR + 8; + // The end of the stack will be reached as the stack is tiny. + view[DATA_ADDR + 4 >> 2] = view[DATA_ADDR >> 2] + 1; + } + } + }); + + var exports = instance.exports; + var view = new Int32Array(exports.memory.buffer); + exports.many_locals(); + assert(view[DATA_ADDR >> 2] > view[DATA_ADDR + 4 >> 2], 'should have wrote past the end of the stack'); + // All API calls should now fail, since we wrote past the end of the + // stack + var fails = 0; + ['bysyncify_stop_unwind', 'bysyncify_start_rewind', 'bysyncify_stop_rewind', 'bysyncify_start_unwind'].forEach(function(name) { + try { + exports[name](DATA_ADDR); + console.log('no fail on', name); + } catch (e) { + console.log('expected fail on', name); + fails++; + } + }); + assert(fails == 4, 'all 4 should have failed'); +} + // Main sleepTests(); coroutineTests(); +stackOverflowAssertTests(); console.log('\ntests completed successfully'); |