diff --git a/test/testsuite/wasi_threads_exit_main_wasi_read.json b/test/testsuite/wasi_threads_exit_main_wasi_read.json new file mode 100644 index 0000000..e8a2acf --- /dev/null +++ b/test/testsuite/wasi_threads_exit_main_wasi_read.json @@ -0,0 +1,3 @@ +{ + "exit_code": 99 +} diff --git a/test/testsuite/wasi_threads_exit_main_wasi_read.wat b/test/testsuite/wasi_threads_exit_main_wasi_read.wat new file mode 100644 index 0000000..25f2bdf --- /dev/null +++ b/test/testsuite/wasi_threads_exit_main_wasi_read.wat @@ -0,0 +1,58 @@ +;; When the main thread calls proc_exit, 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 $proc_exit (import "wasi_snapshot_preview1" "proc_exit") (param 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 + ;; exit + i32.const 99 + call $proc_exit + unreachable + ) +) diff --git a/test/testsuite/wasi_threads_exit_nonmain_wasi_read.json b/test/testsuite/wasi_threads_exit_nonmain_wasi_read.json new file mode 100644 index 0000000..e8a2acf --- /dev/null +++ b/test/testsuite/wasi_threads_exit_nonmain_wasi_read.json @@ -0,0 +1,3 @@ +{ + "exit_code": 99 +} diff --git a/test/testsuite/wasi_threads_exit_nonmain_wasi_read.wat b/test/testsuite/wasi_threads_exit_nonmain_wasi_read.wat new file mode 100644 index 0000000..39f6957 --- /dev/null +++ b/test/testsuite/wasi_threads_exit_nonmain_wasi_read.wat @@ -0,0 +1,58 @@ +;; When a non-main thread calls proc_exit, it should terminate +;; the main thread which is 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 $proc_exit (import "wasi_snapshot_preview1" "proc_exit") (param 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) + ;; 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 + ;; exit + i32.const 99 + call $proc_exit + unreachable + ) + (func (export "_start") + ;; spawn a thread + i32.const 0 + call $thread_spawn + ;; check error + i32.const 0 + i32.le_s + if + unreachable + end + ;; 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 + ) +)