Skip to content

Commit c92e3f0

Browse files
authored
add another set of tests to examine "return from _start" (#46)
* add another set of tests to examine "return from _start" a return from _start is an equivalent of proc_exit(0) and thus should terminate other threads. at least it's what wasi-libc as of today assumes. cf. #21 ``` (venv) spacetanuki% python3 test-runner/wasi_test_runner.py -t ../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_return_main_wasi passed Test wasi_threads_return_main_wasi_read passed Test wasi_threads_return_main_block passed Test wasi_threads_exit_main_wasi passed Test wasi_threads_return_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_wasi_read passed Test wasi_threads_exit_nonmain_block passed Test wasi_threads_exit_main_wasi_read passed ===== Test results ===== Runtime: toywasm v28.0.0 Suite: WASI threads proposal Total: 13 Passed: 13 Failed: 0 Skipped: 0 Test suites: 1 passed, 0 total Tests: 13 passed, 0 total (venv) spacetanuki% ``` * remove unused imports
1 parent e42f5e1 commit c92e3f0

4 files changed

+185
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
;; When the main thread returns from _start, it should terminate
2+
;; a thread blocking in `memory.atomic.wait32` opcode.
3+
;;
4+
;; linear memory usage:
5+
;; 0: notify/wait
6+
7+
(module
8+
(memory (export "memory") (import "foo" "bar") 1 1 shared)
9+
(func $thread_spawn (import "wasi" "thread-spawn") (param i32) (result i32))
10+
(func (export "wasi_thread_start") (param i32 i32)
11+
;; infinite wait
12+
i32.const 0
13+
i32.const 0
14+
i64.const -1
15+
memory.atomic.wait32
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+
;; note: return from _start is the same as proc_exit(0).
40+
)
41+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
;; When the main thread returns from _start, it should terminate
2+
;; a busy-looping thread.
3+
;;
4+
;; linear memory usage:
5+
;; 0: wait
6+
7+
(module
8+
(memory (export "memory") (import "foo" "bar") 1 1 shared)
9+
(func $thread_spawn (import "wasi" "thread-spawn") (param i32) (result i32))
10+
(func (export "wasi_thread_start") (param i32 i32)
11+
;; infinite loop
12+
loop
13+
br 0
14+
end
15+
unreachable
16+
)
17+
(func (export "_start")
18+
;; spawn a thread
19+
i32.const 0
20+
call $thread_spawn
21+
;; check error
22+
i32.const 0
23+
i32.le_s
24+
if
25+
unreachable
26+
end
27+
;; wait 500ms to ensure the other thread to enter the busy loop
28+
i32.const 0
29+
i32.const 0
30+
i64.const 500_000_000
31+
memory.atomic.wait32
32+
;; assert a timeout
33+
i32.const 2
34+
i32.ne
35+
if
36+
unreachable
37+
end
38+
;; note: return from _start is the same as proc_exit(0).
39+
)
40+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
;; When the main thread returns from _start, it should terminate
2+
;; a thread blocking in a WASI call. (poll_oneoff)
3+
;;
4+
;; linear memory usage:
5+
;; 0: wait
6+
;; 0x100: poll_oneoff subscription
7+
;; 0x200: poll_oneoff event
8+
;; 0x300: poll_oneoff return value
9+
10+
(module
11+
(memory (export "memory") (import "foo" "bar") 1 1 shared)
12+
(func $thread_spawn (import "wasi" "thread-spawn") (param i32) (result i32))
13+
(func $poll_oneoff (import "wasi_snapshot_preview1" "poll_oneoff") (param i32 i32 i32 i32) (result i32))
14+
(func (export "wasi_thread_start") (param i32 i32)
15+
;; long enough block
16+
;; clock_realtime, !abstime (zeros)
17+
i32.const 0x118 ;; 0x100 + offsetof(subscription, timeout)
18+
i64.const 1_000_000_000 ;; 1s
19+
i64.store
20+
i32.const 0x100 ;; subscription
21+
i32.const 0x200 ;; event (out)
22+
i32.const 1 ;; nsubscriptions
23+
i32.const 0x300 ;; retp (out)
24+
call $poll_oneoff
25+
unreachable
26+
)
27+
(func (export "_start")
28+
;; spawn a thread
29+
i32.const 0
30+
call $thread_spawn
31+
;; check error
32+
i32.const 0
33+
i32.le_s
34+
if
35+
unreachable
36+
end
37+
;; wait 500ms to ensure the other thread block
38+
i32.const 0
39+
i32.const 0
40+
i64.const 500_000_000
41+
memory.atomic.wait32
42+
;; assert a timeout
43+
i32.const 2
44+
i32.ne
45+
if
46+
unreachable
47+
end
48+
;; note: return from _start is the same as proc_exit(0).
49+
)
50+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
;; When the main thread returns from _start, it should terminate
2+
;; a thread blocking in a WASI call. (fd_read)
3+
;;
4+
;; assumption: read from FD 0 blocks.
5+
;;
6+
;; linear memory usage:
7+
;; 0: wait
8+
;; 100: fd_read iovec
9+
;; 200: buffer
10+
;; 300: result
11+
12+
(module
13+
(memory (export "memory") (import "foo" "bar") 1 1 shared)
14+
(func $thread_spawn (import "wasi" "thread-spawn") (param i32) (result i32))
15+
(func $fd_read (import "wasi_snapshot_preview1" "fd_read") (param i32 i32 i32 i32) (result i32))
16+
(func (export "wasi_thread_start") (param i32 i32)
17+
;; read from FD 0
18+
i32.const 100 ;; iov_base
19+
i32.const 200 ;; buffer
20+
i32.store
21+
i32.const 104 ;; iov_len
22+
i32.const 1
23+
i32.store
24+
i32.const 0 ;; fd 0
25+
i32.const 100 ;; iov_base
26+
i32.const 1 ;; iov count
27+
i32.const 300 ;; retp (out)
28+
call $fd_read
29+
unreachable
30+
)
31+
(func (export "_start")
32+
;; spawn a thread
33+
i32.const 0
34+
call $thread_spawn
35+
;; check error
36+
i32.const 0
37+
i32.le_s
38+
if
39+
unreachable
40+
end
41+
;; wait 500ms to ensure the other thread block
42+
i32.const 0
43+
i32.const 0
44+
i64.const 500_000_000
45+
memory.atomic.wait32
46+
;; assert a timeout
47+
i32.const 2
48+
i32.ne
49+
if
50+
unreachable
51+
end
52+
;; note: return from _start is the same as proc_exit(0).
53+
)
54+
)

0 commit comments

Comments
 (0)