Skip to content

Commit bebcdef

Browse files
authored
Add spec tests (#12)
* Wave 1 of spec tests * Remove unnecessary "unknown" import tests * Initial binary tests * Fix missing messages in assert_malformed * Fix up byte counts, etc. * Fix type signatures * Fix more fixatiously * More robust binary tests
1 parent 047d6ad commit bebcdef

File tree

3 files changed

+298
-24
lines changed

3 files changed

+298
-24
lines changed
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
;; Auxiliary modules to import
2+
3+
(module
4+
(func (export "b") (result i32) (i32.const 0x0f))
5+
(func (export "c") (result i32) (i32.const 0xf0))
6+
)
7+
(register "a")
8+
(module
9+
(func (export "") (result i32) (i32.const 0xab))
10+
)
11+
(register "")
12+
13+
14+
;; Valid compact encodings
15+
16+
(module binary
17+
"\00asm" "\01\00\00\00"
18+
"\01\05\01\60\00\01\7f" ;; Type section: (type (func (result i32)))
19+
"\02\0e" ;; Import section
20+
"\01" ;; 1 group
21+
"\01a" ;; "a"
22+
"\00" "\7f" ;; "" + 0x7f (compact encoding)
23+
"\02" ;; 2 items
24+
"\01b" "\00\00" ;; "b" (func (type 0))
25+
"\01c" "\00\00" ;; "c" (func (type 0))
26+
"\03\02" "\01" ;; Function section, 1 func
27+
"\00" ;; func 2: type 0
28+
"\07\08" "\01" ;; Export section, 1 export
29+
"\04test" "\00\02" ;; "test" func 2
30+
"\0a\09" "\01" ;; Code section, 1 func
31+
"\07" "\00" ;; len, 0 locals
32+
"\10\00" ;; call 0
33+
"\10\01" ;; call 1
34+
"\6a" ;; i32.add
35+
"\0b" ;; end
36+
)
37+
(assert_return (invoke "test") (i32.const 0xff))
38+
39+
(module binary
40+
"\00asm" "\01\00\00\00"
41+
"\01\05\01\60\00\01\7f" ;; Type section: (type (func (result i32)))
42+
"\02\0c" ;; Import section
43+
"\01" ;; 1 group
44+
"\01a" ;; "a"
45+
"\00" "\7e" ;; "" + 0x7e (compact encoding)
46+
"\00\00" ;; (func (type 0))
47+
"\02" ;; 2 items
48+
"\01b" ;; "b"
49+
"\01c" ;; "c"
50+
"\03\02" "\01" ;; Function section, 1 func
51+
"\00" ;; func 2: type 0
52+
"\07\08" "\01" ;; Export section, 1 export
53+
"\04test" "\00\02" ;; "test" func 2
54+
"\0a\09" "\01" ;; Code section, 1 func
55+
"\07" "\00" ;; len, 0 locals
56+
"\10\00" ;; call 0
57+
"\10\01" ;; call 1
58+
"\6a" ;; i32.add
59+
"\0b" ;; end
60+
)
61+
(assert_return (invoke "test") (i32.const 0xff))
62+
63+
64+
;; Overly-long empty name encodings are valid
65+
66+
(module binary
67+
"\00asm" "\01\00\00\00"
68+
"\01\05\01\60\00\01\7f" ;; Type section: (type (func (result i32)))
69+
"\02\11" ;; Import section
70+
"\01" ;; 1 group
71+
"\01a" ;; "a"
72+
"\80\80\80\00" "\7f" ;; "" (long encoding) + 0x7f
73+
"\02" ;; 2 items
74+
"\01b" "\00\00" ;; "b" (func (type 0))
75+
"\01c" "\00\00" ;; "c" (func (type 0))
76+
)
77+
(module binary
78+
"\00asm" "\01\00\00\00"
79+
"\01\05\01\60\00\01\7f" ;; Type section: (type (func (result i32)))
80+
"\02\0f" ;; Import section
81+
"\01" ;; 1 group
82+
"\01a" ;; "a"
83+
"\80\80\80\00" "\7e" ;; "" (long encoding) + 0x7e
84+
"\00\00" ;; (func (type 0))
85+
"\02" ;; 2 items
86+
"\01b" ;; "b"
87+
"\01c" ;; "c"
88+
)
89+
90+
91+
;; Discriminator is not valid except after empty names
92+
93+
(assert_malformed
94+
(module binary
95+
"\00asm" "\01\00\00\00"
96+
"\01\05\01\60\00\01\7f" ;; Type section: (type (func (result i32)))
97+
"\02\12" ;; Import section
98+
"\01" ;; 1 group
99+
"\01a" ;; "a"
100+
"\01b" "\7f" ;; "b" + 0x7f
101+
"\02" ;; 2 items
102+
"\01b" "\00\00" ;; "b" (func (type 0))
103+
"\01c" "\00\00" ;; "c" (func (type 0))
104+
)
105+
"malformed import kind"
106+
)
107+
(assert_malformed
108+
(module binary
109+
"\00asm" "\01\00\00\00"
110+
"\01\05\01\60\00\01\7f" ;; Type section: (type (func (result i32)))
111+
"\02\10" ;; Import section
112+
"\01" ;; 1 group
113+
"\01a" ;; "a"
114+
"\01b" "\7e" ;; "" + 0x7e (long encoding)
115+
"\00\00" ;; (func (type 0))
116+
"\02" ;; 2 items
117+
"\01b" ;; "b"
118+
"\01c" ;; "c"
119+
)
120+
"malformed import kind"
121+
)
122+
123+
124+
;; Discriminator is not to be interpreted as LEB128
125+
126+
(assert_malformed
127+
(module binary
128+
"\00asm" "\01\00\00\00"
129+
"\01\05\01\60\00\01\7f" ;; Type section: (type (func (result i32)))
130+
"\02\11" ;; Import section
131+
"\01" ;; 1 group
132+
"\01a" ;; "a"
133+
"\00\ff\80\80\00" ;; "" + 0x7f (long encoding)
134+
"\02" ;; 2 items
135+
"\01b" "\00\00" ;; "b" (func (type 0))
136+
"\01c" "\00\00" ;; "c" (func (type 0))
137+
)
138+
"malformed import kind"
139+
)
140+
(assert_malformed
141+
(module binary
142+
"\00asm" "\01\00\00\00"
143+
"\01\05\01\60\00\01\7f" ;; Type section: (type (func (result i32)))
144+
"\02\0f" ;; Import section
145+
"\01" ;; 1 group
146+
"\01a" ;; "a"
147+
"\00\fe\80\80\00" ;; "" + 0x7e (long encoding)
148+
"\00\00" ;; (func (type 0))
149+
"\02" ;; 2 items
150+
"\01b" ;; "b"
151+
"\01c" ;; "c"
152+
)
153+
"malformed import kind"
154+
)
155+
156+
157+
;; Empty names are still valid if not followed by a discriminator
158+
159+
(module binary
160+
"\00asm" "\01\00\00\00"
161+
"\01\05\01\60\00\01\7f" ;; Type section: (type (func (result i32)))
162+
"\02\05" ;; Import section
163+
"\01" ;; 1 group
164+
"\00\00\00\00" ;; "" "" (func (type 0))
165+
"\03\02" "\01" ;; Function section, 1 func
166+
"\00" ;; func 1: type 0
167+
"\07\08" "\01" ;; Export section, 1 export
168+
"\04test" "\00\01" ;; "test" func 1
169+
"\0a\06" "\01" ;; Code section, 1 func
170+
"\04" "\00" ;; len, 0 locals
171+
"\10\00" ;; call 0
172+
"\0b" ;; end
173+
)
174+
(assert_return (invoke "test") (i32.const 0xab))

test/core/compact-import-section/compact_imports.wast

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
;; Auxiliary module to import from
2+
3+
(module
4+
(func (export "func->11i") (result i32) (i32.const 11))
5+
(func (export "func->22f") (result f32) (f32.const 22))
6+
(global (export "global->1") i32 (i32.const 1))
7+
(global (export "global->20") i32 (i32.const 20))
8+
(global (export "global->300") i32 (i32.const 300))
9+
(global (export "global->4000") i32 (i32.const 4000))
10+
)
11+
(register "test")
12+
13+
14+
;; Basic behavior
15+
16+
(module
17+
(import "test"
18+
(item "func->11i" (func (result i32)))
19+
(item "func->22f" (func (result f32)))
20+
)
21+
(import "test"
22+
(item "global->1")
23+
(item "global->20")
24+
(item "global->300")
25+
(item "global->4000")
26+
(global i32)
27+
)
28+
29+
(global i32 (i32.const 50000))
30+
31+
(func (export "sum1") (result i32)
32+
(local i32)
33+
34+
call 0
35+
(i32.trunc_f32_s (call 1))
36+
i32.add
37+
)
38+
(func (export "sum2") (result i32)
39+
(local i32)
40+
41+
global.get 0
42+
global.get 1
43+
global.get 2
44+
global.get 3
45+
i32.add
46+
i32.add
47+
i32.add
48+
)
49+
50+
;; Tests that indices were tracked correctly
51+
(func (export "sum3") (result i32)
52+
call 2 ;; sum1
53+
call 3 ;; sum2
54+
i32.add
55+
56+
global.get 4
57+
i32.add
58+
)
59+
)
60+
61+
(assert_return (invoke "sum1") (i32.const 33))
62+
(assert_return (invoke "sum2") (i32.const 4321))
63+
(assert_return (invoke "sum3") (i32.const 54354))
64+
65+
(module (import "test" (item "func->11i" (func (result i32)))))
66+
(assert_unlinkable
67+
(module (import "test" (item "unknown" (func (result i32)))))
68+
"unknown import"
69+
)
70+
(assert_unlinkable
71+
(module (import "test" (item "func->11i" (func (result i32))) (item "unknown" (func (result i32)))))
72+
"unknown import"
73+
)
74+
75+
(module (import "test" (item "func->11i") (func (result i32))))
76+
(assert_unlinkable
77+
(module (import "test" (item "unknown") (func (result i32))))
78+
"unknown import"
79+
)
80+
(assert_unlinkable
81+
(module (import "test" (item "func->11i") (item "unknown") (func (result i32))))
82+
"unknown import"
83+
)
84+
85+
(assert_unlinkable
86+
(module (import "test" (item "func->11i" (func))))
87+
"incompatible import type"
88+
)
89+
(assert_unlinkable
90+
(module (import "test" (item "func->11i" (func (result i32))) (item "func->22f" (func))))
91+
"incompatible import type"
92+
)
93+
94+
(assert_unlinkable
95+
(module (import "test" (item "func->11i") (item "func->22f") (func (result i32))))
96+
"incompatible import type"
97+
)
98+
99+
100+
;; Identifiers
101+
102+
(module
103+
(import "test" "func->11i" (func $f11i (result i32)))
104+
(import "test"
105+
(item "global->1" (global $g1 i32))
106+
(item "global->20" (global $g20 i32))
107+
)
108+
;; Shared-type form does not allow identifiers
109+
110+
(func (export "sum") (result i32)
111+
call $f11i
112+
global.get $g1
113+
global.get $g20
114+
i32.add
115+
i32.add
116+
)
117+
)
118+
119+
(assert_return (invoke "sum") (i32.const 32))
120+
121+
(assert_malformed
122+
(module quote "(import \"test\" (item \"foo\") (func $foo))")
123+
"identifier not allowed"
124+
)

0 commit comments

Comments
 (0)