summaryrefslogtreecommitdiff
path: root/test/unit
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2019-06-21 14:48:06 -0700
committerGitHub <noreply@github.com>2019-06-21 14:48:06 -0700
commitcbc7e868d85a81e1a2f802b633d3cf323a14338f (patch)
treed59a65d99f4d10b281da4ffe6612ea25b8f6e820 /test/unit
parent3f797c82e49bb2a5e5f6bcd2393e369ef618a49b (diff)
downloadbinaryen-cbc7e868d85a81e1a2f802b633d3cf323a14338f.tar.gz
binaryen-cbc7e868d85a81e1a2f802b633d3cf323a14338f.tar.bz2
binaryen-cbc7e868d85a81e1a2f802b633d3cf323a14338f.zip
Bysyncify: Don't instrument functions that call bysyncify_* directly (#2179)
Those functions are assumed to be part of the runtime. Instrumenting them would mean nothing can work. With this fix, bysyncify is useful with pure wasm, and not just through imports.
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/input/bysyncify-pure.txt17
-rw-r--r--test/unit/input/bysyncify-pure.wast59
-rw-r--r--test/unit/test_bysyncify.py11
3 files changed, 85 insertions, 2 deletions
diff --git a/test/unit/input/bysyncify-pure.txt b/test/unit/input/bysyncify-pure.txt
new file mode 100644
index 000000000..1f85db1f1
--- /dev/null
+++ b/test/unit/input/bysyncify-pure.txt
@@ -0,0 +1,17 @@
+(i32.const 100)
+(i32.const 10)
+(i32.const 1)
+(i32.const 20)
+(i32.const 1000)
+(i32.const 2000)
+(i32.const 4000)
+(i32.const 200)
+(i32.const 300)
+(i32.const 400)
+(i32.const 1000)
+(i32.const 3000)
+(i32.const 4000)
+(i32.const 30)
+(i32.const 2)
+(i32.const 40)
+(i32.const 500)
diff --git a/test/unit/input/bysyncify-pure.wast b/test/unit/input/bysyncify-pure.wast
new file mode 100644
index 000000000..b79bfe2b0
--- /dev/null
+++ b/test/unit/input/bysyncify-pure.wast
@@ -0,0 +1,59 @@
+(module
+ (memory 1 1)
+ (import "spectest" "print" (func $print (param i32)))
+ (import "bysyncify" "start_unwind" (func $bysyncify_start_unwind (param i32)))
+ (import "bysyncify" "stop_unwind" (func $bysyncify_stop_unwind))
+ (import "bysyncify" "start_rewind" (func $bysyncify_start_rewind (param i32)))
+ (import "bysyncify" "stop_rewind" (func $bysyncify_stop_rewind))
+ (global $sleeping (mut i32) (i32.const 0))
+ (start $runtime)
+ (func $main
+ (call $print (i32.const 10))
+ (call $before)
+ (call $print (i32.const 20))
+ (call $sleep)
+ (call $print (i32.const 30))
+ (call $after)
+ (call $print (i32.const 40))
+ )
+ (func $before
+ (call $print (i32.const 1))
+ )
+ (func $sleep
+ (call $print (i32.const 1000))
+ (if
+ (i32.eqz (global.get $sleeping))
+ (block
+ (call $print (i32.const 2000))
+ (global.set $sleeping (i32.const 1))
+ (i32.store (i32.const 16) (i32.const 24))
+ (i32.store (i32.const 20) (i32.const 1024))
+ (call $bysyncify_start_unwind (i32.const 16))
+ )
+ (block
+ (call $print (i32.const 3000))
+ (call $bysyncify_stop_rewind)
+ (global.set $sleeping (i32.const 0))
+ )
+ )
+ (call $print (i32.const 4000))
+ )
+ (func $after
+ (call $print (i32.const 2))
+ )
+ (func $runtime
+ (call $print (i32.const 100))
+ ;; call main the first time, let the stack unwind
+ (call $main)
+ (call $print (i32.const 200))
+ (call $bysyncify_stop_unwind)
+ (call $print (i32.const 300))
+ ;; ...can do some async stuff around here...
+ ;; set the rewind in motion
+ (call $bysyncify_start_rewind (i32.const 16))
+ (call $print (i32.const 400))
+ (call $main)
+ (call $print (i32.const 500))
+ )
+)
+
diff --git a/test/unit/test_bysyncify.py b/test/unit/test_bysyncify.py
index 29a8ae7cb..8d5a780e8 100644
--- a/test/unit/test_bysyncify.py
+++ b/test/unit/test_bysyncify.py
@@ -1,11 +1,11 @@
import os
-from scripts.test.shared import WASM_OPT, NODEJS, run_process
+from scripts.test.shared import WASM_OPT, WASM_DIS, WASM_SHELL, NODEJS, run_process
from utils import BinaryenTestCase
class BysyncifyTest(BinaryenTestCase):
- def test_bysyncify(self):
+ def test_bysyncify_js(self):
def test(args):
print(args)
run_process(WASM_OPT + args + [self.input_path('bysyncify-sleep.wast'), '--bysyncify', '-o', 'a.wasm'])
@@ -19,3 +19,10 @@ class BysyncifyTest(BinaryenTestCase):
test(['--optimize-level=1'])
test(['-O3'])
test(['-Os', '-g'])
+
+ def test_bysyncify_pure_wasm(self):
+ run_process(WASM_OPT + [self.input_path('bysyncify-pure.wast'), '--bysyncify', '-o', 'a.wasm'])
+ run_process(WASM_DIS + ['a.wasm', '-o', 'a.wast'])
+ output = run_process(WASM_SHELL + ['a.wast'], capture_output=True).stdout
+ with open(self.input_path('bysyncify-pure.txt')) as f:
+ self.assertEqual(f.read(), output)