Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add another set of tests to examine "return from _start" #46

Merged
merged 2 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions test/testsuite/wasi_threads_return_main_block.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
;; When the main thread returns from _start, it should terminate
;; a thread blocking in `memory.atomic.wait32` opcode.
;;
;; linear memory usage:
;; 0: notify/wait

(module
(memory (export "memory") (import "foo" "bar") 1 1 shared)
(func $thread_spawn (import "wasi" "thread-spawn") (param i32) (result i32))
(func (export "wasi_thread_start") (param i32 i32)
;; infinite wait
i32.const 0
i32.const 0
i64.const -1
memory.atomic.wait32
unreachable
)
(func (export "_start")
;; spawn a thread
i32.const 0
call $thread_spawn
;; check error
i32.const 0
i32.le_s
if
unreachable
end
;; wait 500ms to ensure the other thread block
i32.const 0
i32.const 0
i64.const 500_000_000
memory.atomic.wait32
;; assert a timeout
i32.const 2
i32.ne
if
unreachable
end
;; note: return from _start is the same as proc_exit(0).
)
)
40 changes: 40 additions & 0 deletions test/testsuite/wasi_threads_return_main_busy.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
;; When the main thread returns from _start, it should terminate
;; a busy-looping thread.
;;
;; linear memory usage:
;; 0: wait

(module
(memory (export "memory") (import "foo" "bar") 1 1 shared)
(func $thread_spawn (import "wasi" "thread-spawn") (param i32) (result i32))
(func (export "wasi_thread_start") (param i32 i32)
;; infinite loop
loop
br 0
end
unreachable
)
(func (export "_start")
;; spawn a thread
i32.const 0
call $thread_spawn
;; check error
i32.const 0
i32.le_s
if
unreachable
end
;; wait 500ms to ensure the other thread to enter the busy loop
i32.const 0
i32.const 0
i64.const 500_000_000
memory.atomic.wait32
;; assert a timeout
i32.const 2
i32.ne
if
unreachable
end
;; note: return from _start is the same as proc_exit(0).
)
)
50 changes: 50 additions & 0 deletions test/testsuite/wasi_threads_return_main_wasi.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
;; When the main thread returns from _start, it should terminate
;; a thread blocking in a WASI call. (poll_oneoff)
;;
;; linear memory usage:
;; 0: wait
;; 0x100: poll_oneoff subscription
;; 0x200: poll_oneoff event
;; 0x300: poll_oneoff return value

(module
(memory (export "memory") (import "foo" "bar") 1 1 shared)
(func $thread_spawn (import "wasi" "thread-spawn") (param i32) (result i32))
(func $poll_oneoff (import "wasi_snapshot_preview1" "poll_oneoff") (param i32 i32 i32 i32) (result i32))
(func (export "wasi_thread_start") (param i32 i32)
;; long enough block
;; clock_realtime, !abstime (zeros)
i32.const 0x118 ;; 0x100 + offsetof(subscription, timeout)
i64.const 1_000_000_000 ;; 1s
i64.store
i32.const 0x100 ;; subscription
i32.const 0x200 ;; event (out)
i32.const 1 ;; nsubscriptions
i32.const 0x300 ;; retp (out)
call $poll_oneoff
unreachable
)
(func (export "_start")
;; spawn a thread
i32.const 0
call $thread_spawn
;; check error
i32.const 0
i32.le_s
if
unreachable
end
;; wait 500ms to ensure the other thread block
i32.const 0
i32.const 0
i64.const 500_000_000
memory.atomic.wait32
;; assert a timeout
i32.const 2
i32.ne
if
unreachable
end
;; note: return from _start is the same as proc_exit(0).
)
)
54 changes: 54 additions & 0 deletions test/testsuite/wasi_threads_return_main_wasi_read.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
;; When the main thread returns from _start, it should terminate
;; a thread blocking in a WASI call. (fd_read)
;;
;; assumption: read from FD 0 blocks.
;;
;; linear memory usage:
;; 0: wait
;; 100: fd_read iovec
;; 200: buffer
;; 300: result

(module
(memory (export "memory") (import "foo" "bar") 1 1 shared)
(func $thread_spawn (import "wasi" "thread-spawn") (param i32) (result i32))
(func $fd_read (import "wasi_snapshot_preview1" "fd_read") (param i32 i32 i32 i32) (result i32))
(func (export "wasi_thread_start") (param i32 i32)
;; read from FD 0
i32.const 100 ;; iov_base
i32.const 200 ;; buffer
i32.store
i32.const 104 ;; iov_len
i32.const 1
i32.store
i32.const 0 ;; fd 0
i32.const 100 ;; iov_base
i32.const 1 ;; iov count
i32.const 300 ;; retp (out)
call $fd_read
unreachable
)
(func (export "_start")
;; spawn a thread
i32.const 0
call $thread_spawn
;; check error
i32.const 0
i32.le_s
if
unreachable
end
;; wait 500ms to ensure the other thread block
i32.const 0
i32.const 0
i64.const 500_000_000
memory.atomic.wait32
;; assert a timeout
i32.const 2
i32.ne
if
unreachable
end
;; note: return from _start is the same as proc_exit(0).
)
)