Skip to content

Commit 044d107

Browse files
yamtloganek
authored andcommitted
add a few test cases with fd_read
a fix for toywasm: yamt/toywasm@e9cc8ce wamr doesn't work as of writing this. it might be fixed when dev/interrupt_block_insn branch is done.
1 parent deee235 commit 044d107

4 files changed

+122
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"exit_code": 99
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
;; When the main thread calls proc_exit, it should terminate
2+
;; a thread blocking in a WASI call. (poll_oneoff)
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 $proc_exit (import "wasi_snapshot_preview1" "proc_exit") (param i32))
16+
(func $fd_read (import "wasi_snapshot_preview1" "fd_read") (param i32 i32 i32 i32) (result i32))
17+
(func (export "wasi_thread_start") (param i32 i32)
18+
;; read from FD 0
19+
i32.const 100 ;; iov_base
20+
i32.const 200 ;; buffer
21+
i32.store
22+
i32.const 104 ;; iov_len
23+
i32.const 1
24+
i32.store
25+
i32.const 0 ;; fd 0
26+
i32.const 100 ;; iov_base
27+
i32.const 1 ;; iov count
28+
i32.const 300 ;; retp (out)
29+
call $fd_read
30+
unreachable
31+
)
32+
(func (export "_start")
33+
;; spawn a thread
34+
i32.const 0
35+
call $thread_spawn
36+
;; check error
37+
i32.const 0
38+
i32.le_s
39+
if
40+
unreachable
41+
end
42+
;; wait 500ms to ensure the other thread block
43+
i32.const 0
44+
i32.const 0
45+
i64.const 500_000_000
46+
memory.atomic.wait32
47+
;; assert a timeout
48+
i32.const 2
49+
i32.ne
50+
if
51+
unreachable
52+
end
53+
;; exit
54+
i32.const 99
55+
call $proc_exit
56+
unreachable
57+
)
58+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"exit_code": 99
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
;; When a non-main thread calls proc_exit, it should terminate
2+
;; the main thread which is 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 $proc_exit (import "wasi_snapshot_preview1" "proc_exit") (param i32))
16+
(func $fd_read (import "wasi_snapshot_preview1" "fd_read") (param i32 i32 i32 i32) (result i32))
17+
(func (export "wasi_thread_start") (param i32 i32)
18+
;; wait 500ms to ensure the other thread block
19+
i32.const 0
20+
i32.const 0
21+
i64.const 500_000_000
22+
memory.atomic.wait32
23+
;; assert a timeout
24+
i32.const 2
25+
i32.ne
26+
if
27+
unreachable
28+
end
29+
;; exit
30+
i32.const 99
31+
call $proc_exit
32+
unreachable
33+
)
34+
(func (export "_start")
35+
;; spawn a thread
36+
i32.const 0
37+
call $thread_spawn
38+
;; check error
39+
i32.const 0
40+
i32.le_s
41+
if
42+
unreachable
43+
end
44+
;; read from FD 0
45+
i32.const 100 ;; iov_base
46+
i32.const 200 ;; buffer
47+
i32.store
48+
i32.const 104 ;; iov_len
49+
i32.const 1
50+
i32.store
51+
i32.const 0 ;; fd 0
52+
i32.const 100 ;; iov_base
53+
i32.const 1 ;; iov count
54+
i32.const 300 ;; retp (out)
55+
call $fd_read
56+
unreachable
57+
)
58+
)

0 commit comments

Comments
 (0)