Skip to content

Commit 9a720a9

Browse files
committed
Add some low level tests
``` (venv) spacetanuki% TOYWASM=~/git/toywasm/b/toywasm python3 test-runner/wasi_test_runner.py -t ~/git/wasm/wasi-threads/test/testsuite -r ~/git/toywasm/test/wasi-testsuite-adapter.py Test wasi_threads_exit_nonmain_wasi passed Test wasi_threads_exit_main_busy passed Test wasi_threads_exit_main_wasi 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 threads proposal Total: 7 Passed: 7 Failed: 0 Test suites: 1 passed, 0 total Tests: 7 passed, 0 total (venv) spacetanuki% ```
1 parent a4f92e1 commit 9a720a9

15 files changed

+338
-0
lines changed

test/build-wat.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
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: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
;; wait 500ms to ensure the other thread to enter the busy loop
22+
i32.const 0
23+
i32.const 0
24+
i64.const 500_000_000
25+
memory.atomic.wait32
26+
;; assert a timeout
27+
i32.const 2
28+
i32.ne
29+
if
30+
unreachable
31+
end
32+
;; exit
33+
i32.const 99
34+
call $proc_exit
35+
unreachable
36+
)
37+
(memory 1 1 shared)
38+
)
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: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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 $poll_oneoff (import "wasi_snapshot_preview1" "poll_oneoff") (param i32 i32 i32 i32) (result i32))
5+
(func (export "wasi_thread_start") (param i32 i32)
6+
;; long enough block
7+
;; clock_realtime, !abstime (zeros)
8+
i32.const 124 ;; 100 + offsetof(subscription, timeout)
9+
i64.const 1_000_000_000 ;; 1s
10+
i64.store
11+
i32.const 100 ;; subscription
12+
i32.const 200 ;; event (out)
13+
i32.const 1 ;; nsubscriptions
14+
i32.const 300 ;; retp (out)
15+
call $poll_oneoff
16+
unreachable
17+
)
18+
(func (export "_start")
19+
;; spawn a thread
20+
i32.const 0
21+
call $thread_spawn
22+
;; check error
23+
i32.const 0
24+
i32.le_s
25+
if
26+
unreachable
27+
end
28+
;; wait 500ms to ensure the other thread block
29+
i32.const 0
30+
i32.const 0
31+
i64.const 500_000_000
32+
memory.atomic.wait32
33+
;; assert a timeout
34+
i32.const 2
35+
i32.ne
36+
if
37+
unreachable
38+
end
39+
;; exit
40+
i32.const 99
41+
call $proc_exit
42+
unreachable
43+
)
44+
(memory 1 1 shared)
45+
)
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+
}

0 commit comments

Comments
 (0)