diff options
Diffstat (limited to 'test/unit')
-rw-r--r-- | test/unit/input/bysyncify-stackOverflow.wast | 22 | ||||
-rw-r--r-- | test/unit/input/bysyncify.js | 43 | ||||
-rw-r--r-- | test/unit/test_bysyncify.py | 1 |
3 files changed, 66 insertions, 0 deletions
diff --git a/test/unit/input/bysyncify-stackOverflow.wast b/test/unit/input/bysyncify-stackOverflow.wast new file mode 100644 index 000000000..a36a06b40 --- /dev/null +++ b/test/unit/input/bysyncify-stackOverflow.wast @@ -0,0 +1,22 @@ +(module + (memory 1 2) + (import "env" "sleep" (func $sleep)) + (export "memory" (memory 0)) + (func "many_locals" (param $x i32) (result i32) + (local $y i32) + (local $z i32) + (local.set $y + (i32.add (local.get $x) (i32.const 10)) + ) + (local.set $z + (i32.add (local.get $y) (i32.const 20)) + ) + (call $sleep) + (select + (local.get $y) + (local.get $z) + (local.get $x) + ) + ) +) + 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'); diff --git a/test/unit/test_bysyncify.py b/test/unit/test_bysyncify.py index 8d5a780e8..407f3f7f9 100644 --- a/test/unit/test_bysyncify.py +++ b/test/unit/test_bysyncify.py @@ -10,6 +10,7 @@ class BysyncifyTest(BinaryenTestCase): print(args) run_process(WASM_OPT + args + [self.input_path('bysyncify-sleep.wast'), '--bysyncify', '-o', 'a.wasm']) run_process(WASM_OPT + args + [self.input_path('bysyncify-coroutine.wast'), '--bysyncify', '-o', 'b.wasm']) + run_process(WASM_OPT + args + [self.input_path('bysyncify-stackOverflow.wast'), '--bysyncify', '-o', 'c.wasm']) print(' file size: %d' % os.path.getsize('a.wasm')) run_process([NODEJS, self.input_path('bysyncify.js')]) |