Skip to content

Add some wasi-threads tests #37

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

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 6 additions & 0 deletions tests/wat/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#! /bin/sh

WAT2WASM=${WAT2WASM:-wat2wasm}
for wat in testsuite/*.wat; do
${WAT2WASM} --enable-threads -o ${wat%%.wat}.wasm ${wat}
done
3 changes: 3 additions & 0 deletions tests/wat/testsuite/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "WASI wat tests"
}
3 changes: 3 additions & 0 deletions tests/wat/testsuite/wasi_threads_exit_main_block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"exit_code": 99
}
39 changes: 39 additions & 0 deletions tests/wat/testsuite/wasi_threads_exit_main_block.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
(module
(func $thread_spawn (import "wasi" "thread_spawn") (param i32) (result i32))
(func $proc_exit (import "wasi_snapshot_preview1" "proc_exit") (param 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
;; exit
i32.const 99
call $proc_exit
unreachable
)
(memory 1 1 shared)
)
3 changes: 3 additions & 0 deletions tests/wat/testsuite/wasi_threads_exit_main_busy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"exit_code": 99
}
38 changes: 38 additions & 0 deletions tests/wat/testsuite/wasi_threads_exit_main_busy.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
(module
(func $thread_spawn (import "wasi" "thread_spawn") (param i32) (result i32))
(func $proc_exit (import "wasi_snapshot_preview1" "proc_exit") (param 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
;; exit
i32.const 99
call $proc_exit
unreachable
)
(memory 1 1 shared)
)
3 changes: 3 additions & 0 deletions tests/wat/testsuite/wasi_threads_exit_main_wasi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"exit_code": 99
}
45 changes: 45 additions & 0 deletions tests/wat/testsuite/wasi_threads_exit_main_wasi.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
(module
(func $thread_spawn (import "wasi" "thread_spawn") (param i32) (result i32))
(func $proc_exit (import "wasi_snapshot_preview1" "proc_exit") (param 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 124 ;; 100 + offsetof(subscription, timeout)
i64.const 1_000_000_000 ;; 1s
i64.store
i32.const 100 ;; subscription
i32.const 200 ;; event (out)
i32.const 1 ;; nsubscriptions
i32.const 300 ;; 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
;; exit
i32.const 99
call $proc_exit
unreachable
)
(memory 1 1 shared)
)
3 changes: 3 additions & 0 deletions tests/wat/testsuite/wasi_threads_exit_nonmain_block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"exit_code": 99
}
39 changes: 39 additions & 0 deletions tests/wat/testsuite/wasi_threads_exit_nonmain_block.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
(module
(func $thread_spawn (import "wasi" "thread_spawn") (param i32) (result i32))
(func $proc_exit (import "wasi_snapshot_preview1" "proc_exit") (param 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
;; infinite wait
i32.const 0
i32.const 0
i64.const -1
memory.atomic.wait32
unreachable
)
(memory 1 1 shared)
)
3 changes: 3 additions & 0 deletions tests/wat/testsuite/wasi_threads_exit_nonmain_busy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"exit_code": 99
}
38 changes: 38 additions & 0 deletions tests/wat/testsuite/wasi_threads_exit_nonmain_busy.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
(module
(func $thread_spawn (import "wasi" "thread_spawn") (param i32) (result i32))
(func $proc_exit (import "wasi_snapshot_preview1" "proc_exit") (param i32))
(func (export "wasi_thread_start") (param i32 i32)
;; 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
;; 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
;; infinite loop
loop
br 0
end
unreachable
)
(memory 1 1 shared)
)
3 changes: 3 additions & 0 deletions tests/wat/testsuite/wasi_threads_exit_nonmain_wasi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"exit_code": 99
}
45 changes: 45 additions & 0 deletions tests/wat/testsuite/wasi_threads_exit_nonmain_wasi.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
(module
(func $thread_spawn (import "wasi" "thread_spawn") (param i32) (result i32))
(func $proc_exit (import "wasi_snapshot_preview1" "proc_exit") (param 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)
;; 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
;; long enough block
;; clock_realtime, !abstime (zeros)
i32.const 124 ;; 100 + offsetof(subscription, timeout)
i64.const 1_000_000_000 ;; 1s
i64.store
i32.const 100 ;; subscription
i32.const 200 ;; event (out)
i32.const 1 ;; nsubscriptions
i32.const 300 ;; retp (out)
call $poll_oneoff
unreachable
)
(memory 1 1 shared)
)
3 changes: 3 additions & 0 deletions tests/wat/testsuite/wasi_threads_spawn.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"exit_code": 22
}
67 changes: 67 additions & 0 deletions tests/wat/testsuite/wasi_threads_spawn.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
(module
(func $thread_spawn (import "wasi" "thread_spawn") (param i32) (result i32))
(func $proc_exit (import "wasi_snapshot_preview1" "proc_exit") (param i32))
(func (export "wasi_thread_start") (param i32 i32)
;; store tid
i32.const 4
local.get 0
i32.store
;; store user pointer
i32.const 8
local.get 1
i32.store
;; notify the main
i32.const 0
i32.const 1
i32.atomic.store
i32.const 0
i32.const 1
memory.atomic.notify
drop
;; returning from wasi_thread_start terminates only this thread
)
(func (export "_start") (local i32)
;; spawn a thread
i32.const 12345 ;; user pointer
call $thread_spawn
;; check error
local.tee 0 ;; save the tid to check later
i32.const 0
i32.le_s
if
unreachable
end
;; wait for the spawned thread to run
i32.const 0
i32.const 0
i64.const -1
memory.atomic.wait32
;; assert it was not a timeout
i32.const 2
i32.eq
if
unreachable
end
;; check the tid
local.get 0
i32.const 4
i32.load
i32.ne
if
unreachable
end
;; check the user pointer
i32.const 8
i32.load
i32.const 12345
i32.ne
if
unreachable
end
;; exit
i32.const 22
call $proc_exit
unreachable
)
(memory 1 1 shared)
)