Skip to content

Commit dd87733

Browse files
committed
Add some wasi-threads tests
``` (venv) spacetanuki% TOYWASM=~/git/toywasm/b/toywasm python3 test-runner/wasi_test_runner.py -t tests/wat/testsuite -r ~/git/toywasm/test/wasi-testsuite-adapter.py Test wasi_threads_exit_main_busy passed Test wasi_threads_exit_nonmain_busy passed Test wasi_threads_spawn passed Test wasi_threads_exit_main_block passed Test wasi_threads_exit_nonmain_block passed ===== Test results ===== Runtime: toywasm v0.0 Suite: WASI wat tests Total: 5 Passed: 5 Failed: 0 Test suites: 1 passed, 0 total Tests: 5 passed, 0 total (venv) spacetanuki% ```
1 parent 2b74496 commit dd87733

12 files changed

+221
-0
lines changed

tests/wat/build.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#! /bin/sh
2+
3+
WAT2WASM=${WAT2WASM:-wat2wasm}
4+
for wat in testsuite/*.wat; do
5+
${WAT2WASM} --enable-threads -o ${wat%%.wat}.wasm ${wat}
6+
done

tests/wat/testsuite/manifest.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"name": "WASI wat tests"
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"exit_code": 99
3+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
(module
2+
(func $thread_spawn (import "wasi" "thread_spawn") (param i32) (result i32))
3+
(func $proc_exit (import "wasi_snapshot_preview1" "proc_exit") (param i32))
4+
(func (export "wasi_thread_start") (param i32 i32)
5+
;; wait 500ms to ensure the other thread block
6+
i32.const 0
7+
i32.const 0
8+
i64.const 500_000_000
9+
memory.atomic.wait32
10+
;; assert a timeout
11+
i32.const 2
12+
i32.ne
13+
if
14+
unreachable
15+
end
16+
;; exit
17+
i32.const 99
18+
call $proc_exit
19+
unreachable
20+
)
21+
(func (export "_start")
22+
;; spawn a thread
23+
i32.const 0
24+
call $thread_spawn
25+
;; check error
26+
i32.const 0
27+
i32.le_s
28+
if
29+
unreachable
30+
end
31+
;; infinite wait
32+
i32.const 0
33+
i32.const 0
34+
i64.const -1
35+
memory.atomic.wait32
36+
unreachable
37+
)
38+
(memory 1 1 shared)
39+
)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"exit_code": 99
3+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
(module
2+
(func $thread_spawn (import "wasi" "thread_spawn") (param i32) (result i32))
3+
(func $proc_exit (import "wasi_snapshot_preview1" "proc_exit") (param i32))
4+
(func (export "wasi_thread_start") (param i32 i32)
5+
;; infinite loop
6+
loop
7+
br 0
8+
end
9+
unreachable
10+
)
11+
(func (export "_start")
12+
;; spawn a thread
13+
i32.const 0
14+
call $thread_spawn
15+
;; check error
16+
i32.const 0
17+
i32.le_s
18+
if
19+
unreachable
20+
end
21+
;; exit
22+
i32.const 99
23+
call $proc_exit
24+
unreachable
25+
)
26+
)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"exit_code": 99
3+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
(module
2+
(func $thread_spawn (import "wasi" "thread_spawn") (param i32) (result i32))
3+
(func $proc_exit (import "wasi_snapshot_preview1" "proc_exit") (param i32))
4+
(func (export "wasi_thread_start") (param i32 i32)
5+
;; infinite wait
6+
i32.const 0
7+
i32.const 0
8+
i64.const -1
9+
memory.atomic.wait32
10+
unreachable
11+
)
12+
(func (export "_start")
13+
;; spawn a thread
14+
i32.const 0
15+
call $thread_spawn
16+
;; check error
17+
i32.const 0
18+
i32.le_s
19+
if
20+
unreachable
21+
end
22+
;; wait 500ms to ensure the other thread block
23+
i32.const 0
24+
i32.const 0
25+
i64.const 500_000_000
26+
memory.atomic.wait32
27+
;; assert a timeout
28+
i32.const 2
29+
i32.ne
30+
if
31+
unreachable
32+
end
33+
;; exit
34+
i32.const 99
35+
call $proc_exit
36+
unreachable
37+
)
38+
(memory 1 1 shared)
39+
)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"exit_code": 99
3+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
(module
2+
(func $thread_spawn (import "wasi" "thread_spawn") (param i32) (result i32))
3+
(func $proc_exit (import "wasi_snapshot_preview1" "proc_exit") (param i32))
4+
(func (export "wasi_thread_start") (param i32 i32)
5+
;; exit
6+
i32.const 99
7+
call $proc_exit
8+
unreachable
9+
)
10+
(func (export "_start")
11+
;; spawn a thread
12+
i32.const 0
13+
call $thread_spawn
14+
;; check error
15+
i32.const 0
16+
i32.le_s
17+
if
18+
unreachable
19+
end
20+
;; infinite loop
21+
loop
22+
br 0
23+
end
24+
unreachable
25+
)
26+
)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"exit_code": 22
3+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
(module
2+
(func $thread_spawn (import "wasi" "thread_spawn") (param i32) (result i32))
3+
(func $proc_exit (import "wasi_snapshot_preview1" "proc_exit") (param i32))
4+
(func (export "wasi_thread_start") (param i32 i32)
5+
;; store tid
6+
i32.const 4
7+
local.get 0
8+
i32.store
9+
;; store user pointer
10+
i32.const 8
11+
local.get 1
12+
i32.store
13+
;; notify the main
14+
i32.const 0
15+
i32.const 1
16+
i32.atomic.store
17+
i32.const 0
18+
i32.const 1
19+
memory.atomic.notify
20+
drop
21+
;; returning from wasi_thread_start terminates only this thread
22+
)
23+
(func (export "_start") (local i32)
24+
;; spawn a thread
25+
i32.const 12345 ;; user pointer
26+
call $thread_spawn
27+
;; check error
28+
local.tee 0 ;; save the tid to check later
29+
i32.const 0
30+
i32.le_s
31+
if
32+
unreachable
33+
end
34+
;; wait for the spawned thread to run
35+
i32.const 0
36+
i32.const 0
37+
i64.const -1
38+
memory.atomic.wait32
39+
;; assert it was not a timeout
40+
i32.const 2
41+
i32.eq
42+
if
43+
unreachable
44+
end
45+
;; check the tid
46+
local.get 0
47+
i32.const 4
48+
i32.load
49+
i32.ne
50+
if
51+
unreachable
52+
end
53+
;; check the user pointer
54+
i32.const 8
55+
i32.load
56+
i32.const 12345
57+
i32.ne
58+
if
59+
unreachable
60+
end
61+
;; exit
62+
i32.const 22
63+
call $proc_exit
64+
unreachable
65+
)
66+
(memory 1 1 shared)
67+
)

0 commit comments

Comments
 (0)