Skip to content

Commit 9b47cc3

Browse files
authored
Merge pull request #1 from wasmi-labs/rf-add-new-wast-tests-from-wasmi
Add `.wast` tests from the Wasmi repo
2 parents 1e2409d + 00333ab commit 9b47cc3

17 files changed

+2491
-0
lines changed

audit.wast

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
;; Failing test cases found during the 2nd Wasmi audit.
2+
3+
(module
4+
(func $return-10-20-30-40 (result i32 i32 i32 i32)
5+
i32.const 10
6+
i32.const 20
7+
i32.const 30
8+
i32.const 40
9+
)
10+
;; Audit found a function that returned an incorrect result.
11+
(func (export "audit.0") (result i32 i32 i32 i32)
12+
(block (result i32 i32 i32 i32)
13+
(i32.const 0)
14+
(call $return-10-20-30-40)
15+
(br_table 0 1 1)
16+
)
17+
)
18+
)
19+
20+
(assert_return
21+
(invoke "audit.0")
22+
(i32.const 0) (i32.const 10) (i32.const 20) (i32.const 30)
23+
)
24+
25+
(module
26+
;; Audit found a hang on `main` branch instead of a trap.
27+
(func (export "audit.1") (result i32 i32)
28+
(local i32)
29+
(i32.const 0)
30+
(block (result i32)
31+
local.get 0
32+
(block
33+
;; The next two instructions together cause an integer-overflow trap.
34+
(drop
35+
(i32.trunc_f64_u (f64.const -inf))
36+
)
37+
)
38+
)
39+
)
40+
)
41+
42+
(assert_trap
43+
(invoke "audit.1")
44+
"integer overflow"
45+
)
46+
47+
(module
48+
;; Audit found different results on Wasmi compared to Wasmtime.
49+
(func (export "audit.2") (param i32) (result i32 i32 i32 i32)
50+
(local.get 0)
51+
(local.get 0)
52+
(block (param i32 i32)
53+
local.tee 0
54+
(block (param i32 i32)
55+
(local.get 0)
56+
(local.get 0)
57+
(br 2) ;; returns
58+
)
59+
)
60+
(unreachable)
61+
)
62+
)
63+
64+
(assert_return
65+
(invoke "audit.2" (i32.const 1))
66+
(i32.const 1) (i32.const 1) (i32.const 1) (i32.const 1)
67+
)
68+
69+
(module
70+
(func (export "regression.0") (param i32) (result i32 i32 i32)
71+
local.get 0
72+
local.get 0
73+
local.get 0
74+
local.get 0
75+
br_if 0 ;; conditional return
76+
)
77+
)
78+
79+
(assert_return
80+
(invoke "regression.0" (i32.const 0))
81+
(i32.const 0) (i32.const 0) (i32.const 0)
82+
)
83+
(assert_return
84+
(invoke "regression.0" (i32.const 1))
85+
(i32.const 1) (i32.const 1) (i32.const 1)
86+
)
87+
(assert_return
88+
(invoke "regression.0" (i32.const -1))
89+
(i32.const -1) (i32.const -1) (i32.const -1)
90+
)
91+
92+
(module
93+
(func (export "regression.1") (param i64) (result f32)
94+
(block (result f32) ;; label = @1
95+
(block (result f32) ;; label = @2
96+
(block (result f32) ;; label = @3
97+
(f32.const 10)
98+
(local.get 0)
99+
(i32.wrap_i64)
100+
(br_table 0 3 0)
101+
)
102+
(unreachable)
103+
)
104+
)
105+
(unreachable)
106+
)
107+
)
108+
109+
(assert_trap
110+
(invoke "regression.1" (i64.const 0))
111+
"unreachable"
112+
)
113+
(assert_return
114+
(invoke "regression.1" (i64.const 1))
115+
(f32.const 10.0)
116+
)
117+
(assert_trap
118+
(invoke "regression.1" (i64.const 2))
119+
"unreachable"
120+
)

copy-span.wast

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
(module
2+
(func (export "copy-many.local") (param $c i32) (param i32 i32 i32 i32) (result i32 i32 i32 i32)
3+
(block (result i32 i32 i32 i32)
4+
(local.get 1)
5+
(local.get 2)
6+
(local.get 3)
7+
(local.get 4)
8+
(br_if 0 (local.get $c)) ;; triggers a copy
9+
)
10+
)
11+
)
12+
13+
(assert_return
14+
(invoke "copy-many.local" (i32.const 0) (i32.const 0) (i32.const 0) (i32.const 0) (i32.const 0))
15+
(i32.const 0) (i32.const 0) (i32.const 0) (i32.const 0)
16+
)
17+
(assert_return
18+
(invoke "copy-many.local" (i32.const 1) (i32.const 0) (i32.const 0) (i32.const 0) (i32.const 0))
19+
(i32.const 0) (i32.const 0) (i32.const 0) (i32.const 0)
20+
)
21+
(assert_return
22+
(invoke "copy-many.local" (i32.const 0) (i32.const 1) (i32.const 2) (i32.const 3) (i32.const 4))
23+
(i32.const 1) (i32.const 2) (i32.const 3) (i32.const 4)
24+
)
25+
(assert_return
26+
(invoke "copy-many.local" (i32.const 1) (i32.const 1) (i32.const 2) (i32.const 3) (i32.const 4))
27+
(i32.const 1) (i32.const 2) (i32.const 3) (i32.const 4)
28+
)
29+
30+
(module
31+
(func (export "copy-many.temp") (param $c i32) (param i64 i64 i64 i64) (result i32 i32 i32 i32)
32+
(block (result i32 i32 i32 i32)
33+
(i32.wrap_i64 (local.get 1))
34+
(i32.wrap_i64 (local.get 2))
35+
(i32.wrap_i64 (local.get 3))
36+
(i32.wrap_i64 (local.get 4))
37+
(br_if 0 (local.get $c)) ;; triggers a copy
38+
)
39+
)
40+
)
41+
42+
(assert_return
43+
(invoke "copy-many.temp" (i32.const 0) (i64.const 0) (i64.const 0) (i64.const 0) (i64.const 0))
44+
(i32.const 0) (i32.const 0) (i32.const 0) (i32.const 0)
45+
)
46+
(assert_return
47+
(invoke "copy-many.temp" (i32.const 1) (i64.const 0) (i64.const 0) (i64.const 0) (i64.const 0))
48+
(i32.const 0) (i32.const 0) (i32.const 0) (i32.const 0)
49+
)
50+
(assert_return
51+
(invoke "copy-many.temp" (i32.const 0) (i64.const 1) (i64.const 2) (i64.const 3) (i64.const 4))
52+
(i32.const 1) (i32.const 2) (i32.const 3) (i32.const 4)
53+
)
54+
(assert_return
55+
(invoke "copy-many.temp" (i32.const 1) (i64.const 1) (i64.const 2) (i64.const 3) (i64.const 4))
56+
(i32.const 1) (i32.const 2) (i32.const 3) (i32.const 4)
57+
)
58+
59+
(module
60+
(func (export "copy-many.across-stack-spaces") (param $c i32) (param i64 i64) (result i32 i64 i64 i32)
61+
(block (result i32 i64 i64 i32)
62+
(i32.wrap_i64 (local.get 1))
63+
(local.get 1)
64+
(local.get 2)
65+
(i32.wrap_i64 (local.get 2))
66+
(br_if 0 (local.get $c)) ;; triggers a copy
67+
)
68+
)
69+
)
70+
71+
(assert_return
72+
(invoke "copy-many.across-stack-spaces" (i32.const 0) (i64.const 0) (i64.const 0))
73+
(i32.const 0) (i64.const 0) (i64.const 0) (i32.const 0)
74+
)
75+
(assert_return
76+
(invoke "copy-many.across-stack-spaces" (i32.const 0) (i64.const 0) (i64.const 1))
77+
(i32.const 0) (i64.const 0) (i64.const 1) (i32.const 1)
78+
)
79+
(assert_return
80+
(invoke "copy-many.across-stack-spaces" (i32.const 0) (i64.const 1) (i64.const 0))
81+
(i32.const 1) (i64.const 1) (i64.const 0) (i32.const 0)
82+
)
83+
(assert_return
84+
(invoke "copy-many.across-stack-spaces" (i32.const 0) (i64.const 1) (i64.const 2))
85+
(i32.const 1) (i64.const 1) (i64.const 2) (i32.const 2)
86+
)
87+
(assert_return
88+
(invoke "copy-many.across-stack-spaces" (i32.const 1) (i64.const 0) (i64.const 0))
89+
(i32.const 0) (i64.const 0) (i64.const 0) (i32.const 0)
90+
)
91+
(assert_return
92+
(invoke "copy-many.across-stack-spaces" (i32.const 1) (i64.const 0) (i64.const 1))
93+
(i32.const 0) (i64.const 0) (i64.const 1) (i32.const 1)
94+
)
95+
(assert_return
96+
(invoke "copy-many.across-stack-spaces" (i32.const 1) (i64.const 1) (i64.const 0))
97+
(i32.const 1) (i64.const 1) (i64.const 0) (i32.const 0)
98+
)
99+
(assert_return
100+
(invoke "copy-many.across-stack-spaces" (i32.const 1) (i64.const 1) (i64.const 2))
101+
(i32.const 1) (i64.const 1) (i64.const 2) (i32.const 2)
102+
)
103+
104+
(module
105+
(func (export "copy-many.across-stack-spaces.2") (param $c i32) (param i64 i64) (result i64 i32 i32 i64)
106+
(block (result i64 i32 i32 i64)
107+
(local.get 1)
108+
(i32.wrap_i64 (local.get 1))
109+
(i32.wrap_i64 (local.get 2))
110+
(local.get 2)
111+
(br_if 0 (local.get $c)) ;; triggers a copy
112+
)
113+
)
114+
)
115+
116+
(assert_return
117+
(invoke "copy-many.across-stack-spaces.2" (i32.const 0) (i64.const 0) (i64.const 0))
118+
(i64.const 0) (i32.const 0) (i32.const 0) (i64.const 0)
119+
)
120+
(assert_return
121+
(invoke "copy-many.across-stack-spaces.2" (i32.const 0) (i64.const 0) (i64.const 1))
122+
(i64.const 0) (i32.const 0) (i32.const 1) (i64.const 1)
123+
)
124+
(assert_return
125+
(invoke "copy-many.across-stack-spaces.2" (i32.const 0) (i64.const 1) (i64.const 0))
126+
(i64.const 1) (i32.const 1) (i32.const 0) (i64.const 0)
127+
)
128+
(assert_return
129+
(invoke "copy-many.across-stack-spaces.2" (i32.const 0) (i64.const 1) (i64.const 2))
130+
(i64.const 1) (i32.const 1) (i32.const 2) (i64.const 2)
131+
)
132+
(assert_return
133+
(invoke "copy-many.across-stack-spaces.2" (i32.const 1) (i64.const 0) (i64.const 0))
134+
(i64.const 0) (i32.const 0) (i32.const 0) (i64.const 0)
135+
)
136+
(assert_return
137+
(invoke "copy-many.across-stack-spaces.2" (i32.const 1) (i64.const 0) (i64.const 1))
138+
(i64.const 0) (i32.const 0) (i32.const 1) (i64.const 1)
139+
)
140+
(assert_return
141+
(invoke "copy-many.across-stack-spaces.2" (i32.const 1) (i64.const 1) (i64.const 0))
142+
(i64.const 1) (i32.const 1) (i32.const 0) (i64.const 0)
143+
)
144+
(assert_return
145+
(invoke "copy-many.across-stack-spaces.2" (i32.const 1) (i64.const 1) (i64.const 2))
146+
(i64.const 1) (i32.const 1) (i32.const 2) (i64.const 2)
147+
)

0 commit comments

Comments
 (0)