From b14c6cfcb113da0bf5678ed155eadb184ba453d6 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Tue, 28 Feb 2023 18:59:09 +0900 Subject: [PATCH 1/2] add a few test cases with fd_read a fix for toywasm: https://github.com/yamt/toywasm/commit/e9cc8ced70568930e526812f3706a0d7ef73953f wamr doesn't work as of writing this. it might be fixed when dev/interrupt_block_insn branch is done. --- .../wasi_threads_exit_main_wasi_read.json | 3 + .../wasi_threads_exit_main_wasi_read.wat | 58 +++++++++++++++++++ .../wasi_threads_exit_nonmain_wasi_read.json | 3 + .../wasi_threads_exit_nonmain_wasi_read.wat | 58 +++++++++++++++++++ 4 files changed, 122 insertions(+) create mode 100644 test/testsuite/wasi_threads_exit_main_wasi_read.json create mode 100644 test/testsuite/wasi_threads_exit_main_wasi_read.wat create mode 100644 test/testsuite/wasi_threads_exit_nonmain_wasi_read.json create mode 100644 test/testsuite/wasi_threads_exit_nonmain_wasi_read.wat 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..4f252e7 --- /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. (poll_oneoff) +;; +;; 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 + ) +) From e5f2137cccd4b5cb5252a3ca959fe6dadff99aa5 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Wed, 22 Mar 2023 19:42:18 +0900 Subject: [PATCH 2/2] fix a comment --- test/testsuite/wasi_threads_exit_main_wasi_read.wat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testsuite/wasi_threads_exit_main_wasi_read.wat b/test/testsuite/wasi_threads_exit_main_wasi_read.wat index 4f252e7..25f2bdf 100644 --- a/test/testsuite/wasi_threads_exit_main_wasi_read.wat +++ b/test/testsuite/wasi_threads_exit_main_wasi_read.wat @@ -1,5 +1,5 @@ ;; When the main thread calls proc_exit, it should terminate -;; a thread blocking in a WASI call. (poll_oneoff) +;; a thread blocking in a WASI call. (fd_read) ;; ;; assumption: read from FD 0 blocks. ;;