Debian Codegraph @

js/src/jit-test/tests/wasm/spec/memory64/memory.wast.js

raw
1 /* Copyright 2021 Mozilla Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 // ./test/core/memory.wast
17
18 // ./test/core/memory.wast:3
19 let $0 = instantiate(`(module (memory 0))`);
20
21 // ./test/core/memory.wast:4
22 let $1 = instantiate(`(module (memory 1))`);
23
24 // ./test/core/memory.wast:5
25 let $2 = instantiate(`(module (memory 0 0))`);
26
27 // ./test/core/memory.wast:6
28 let $3 = instantiate(`(module (memory 0 1))`);
29
30 // ./test/core/memory.wast:7
31 let $4 = instantiate(`(module (memory 1 256))`);
32
33 // ./test/core/memory.wast:8
34 let _ = module(`(module (memory 65536))`);
35
36 // ./test/core/memory.wast:9
37 let $5 = instantiate(`(module (memory 0 65536))`);
38
39 // ./test/core/memory.wast:11
40 let $6 = instantiate(`(module (memory (data)) (func (export "memsize") (result i32) (memory.size)))`);
41
42 // ./test/core/memory.wast:12
43 assert_return(() => invoke($6, `memsize`, []), [value("i32", 0)]);
44
45 // ./test/core/memory.wast:13
46 let $7 = instantiate(`(module (memory (data "")) (func (export "memsize") (result i32) (memory.size)))`);
47
48 // ./test/core/memory.wast:14
49 assert_return(() => invoke($7, `memsize`, []), [value("i32", 0)]);
50
51 // ./test/core/memory.wast:15
52 let $8 = instantiate(`(module (memory (data "x")) (func (export "memsize") (result i32) (memory.size)))`);
53
54 // ./test/core/memory.wast:16
55 assert_return(() => invoke($8, `memsize`, []), [value("i32", 1)]);
56
57 // ./test/core/memory.wast:18
58 assert_invalid(() => instantiate(`(module (data (i32.const 0)))`), `unknown memory`);
59
60 // ./test/core/memory.wast:19
61 assert_invalid(() => instantiate(`(module (data (i32.const 0) ""))`), `unknown memory`);
62
63 // ./test/core/memory.wast:20
64 assert_invalid(() => instantiate(`(module (data (i32.const 0) "x"))`), `unknown memory`);
65
66 // ./test/core/memory.wast:22
67 assert_invalid(
68 () => instantiate(`(module (func (drop (f32.load (i32.const 0)))))`),
69 `unknown memory`,
70 );
71
72 // ./test/core/memory.wast:26
73 assert_invalid(
74 () => instantiate(`(module (func (f32.store (i32.const 0) (f32.const 0))))`),
75 `unknown memory`,
76 );
77
78 // ./test/core/memory.wast:30
79 assert_invalid(
80 () => instantiate(`(module (func (drop (i32.load8_s (i32.const 0)))))`),
81 `unknown memory`,
82 );
83
84 // ./test/core/memory.wast:34
85 assert_invalid(
86 () => instantiate(`(module (func (i32.store8 (i32.const 0) (i32.const 0))))`),
87 `unknown memory`,
88 );
89
90 // ./test/core/memory.wast:38
91 assert_invalid(
92 () => instantiate(`(module (func (drop (memory.size))))`),
93 `unknown memory`,
94 );
95
96 // ./test/core/memory.wast:42
97 assert_invalid(
98 () => instantiate(`(module (func (drop (memory.grow (i32.const 0)))))`),
99 `unknown memory`,
100 );
101
102 // ./test/core/memory.wast:48
103 assert_invalid(
104 () => instantiate(`(module (memory 1 0))`),
105 `size minimum must not be greater than maximum`,
106 );
107
108 // ./test/core/memory.wast:52
109 assert_invalid(() => instantiate(`(module (memory 65537))`), `memory size`);
110
111 // ./test/core/memory.wast:56
112 assert_invalid(() => instantiate(`(module (memory 2147483648))`), `memory size`);
113
114 // ./test/core/memory.wast:60
115 assert_invalid(() => instantiate(`(module (memory 4294967295))`), `memory size`);
116
117 // ./test/core/memory.wast:64
118 assert_invalid(() => instantiate(`(module (memory 0 65537))`), `memory size`);
119
120 // ./test/core/memory.wast:68
121 assert_invalid(() => instantiate(`(module (memory 0 2147483648))`), `memory size`);
122
123 // ./test/core/memory.wast:72
124 assert_invalid(() => instantiate(`(module (memory 0 4294967295))`), `memory size`);
125
126 // ./test/core/memory.wast:103
127 let $9 = instantiate(`(module
128 (memory 1)
129 (data (i32.const 0) "ABC\\a7D") (data (i32.const 20) "WASM")
130
131 ;; Data section
132 (func (export "data") (result i32)
133 (i32.and
134 (i32.and
135 (i32.and
136 (i32.eq (i32.load8_u (i32.const 0)) (i32.const 65))
137 (i32.eq (i32.load8_u (i32.const 3)) (i32.const 167))
138 )
139 (i32.and
140 (i32.eq (i32.load8_u (i32.const 6)) (i32.const 0))
141 (i32.eq (i32.load8_u (i32.const 19)) (i32.const 0))
142 )
143 )
144 (i32.and
145 (i32.and
146 (i32.eq (i32.load8_u (i32.const 20)) (i32.const 87))
147 (i32.eq (i32.load8_u (i32.const 23)) (i32.const 77))
148 )
149 (i32.and
150 (i32.eq (i32.load8_u (i32.const 24)) (i32.const 0))
151 (i32.eq (i32.load8_u (i32.const 1023)) (i32.const 0))
152 )
153 )
154 )
155 )
156
157 ;; Memory cast
158 (func (export "cast") (result f64)
159 (i64.store (i32.const 8) (i64.const -12345))
160 (if
161 (f64.eq
162 (f64.load (i32.const 8))
163 (f64.reinterpret_i64 (i64.const -12345))
164 )
165 (then (return (f64.const 0)))
166 )
167 (i64.store align=1 (i32.const 9) (i64.const 0))
168 (i32.store16 align=1 (i32.const 15) (i32.const 16453))
169 (f64.load align=1 (i32.const 9))
170 )
171
172 ;; Sign and zero extending memory loads
173 (func (export "i32_load8_s") (param $$i i32) (result i32)
174 (i32.store8 (i32.const 8) (local.get $$i))
175 (i32.load8_s (i32.const 8))
176 )
177 (func (export "i32_load8_u") (param $$i i32) (result i32)
178 (i32.store8 (i32.const 8) (local.get $$i))
179 (i32.load8_u (i32.const 8))
180 )
181 (func (export "i32_load16_s") (param $$i i32) (result i32)
182 (i32.store16 (i32.const 8) (local.get $$i))
183 (i32.load16_s (i32.const 8))
184 )
185 (func (export "i32_load16_u") (param $$i i32) (result i32)
186 (i32.store16 (i32.const 8) (local.get $$i))
187 (i32.load16_u (i32.const 8))
188 )
189 (func (export "i64_load8_s") (param $$i i64) (result i64)
190 (i64.store8 (i32.const 8) (local.get $$i))
191 (i64.load8_s (i32.const 8))
192 )
193 (func (export "i64_load8_u") (param $$i i64) (result i64)
194 (i64.store8 (i32.const 8) (local.get $$i))
195 (i64.load8_u (i32.const 8))
196 )
197 (func (export "i64_load16_s") (param $$i i64) (result i64)
198 (i64.store16 (i32.const 8) (local.get $$i))
199 (i64.load16_s (i32.const 8))
200 )
201 (func (export "i64_load16_u") (param $$i i64) (result i64)
202 (i64.store16 (i32.const 8) (local.get $$i))
203 (i64.load16_u (i32.const 8))
204 )
205 (func (export "i64_load32_s") (param $$i i64) (result i64)
206 (i64.store32 (i32.const 8) (local.get $$i))
207 (i64.load32_s (i32.const 8))
208 )
209 (func (export "i64_load32_u") (param $$i i64) (result i64)
210 (i64.store32 (i32.const 8) (local.get $$i))
211 (i64.load32_u (i32.const 8))
212 )
213 )`);
214
215 // ./test/core/memory.wast:191
216 assert_return(() => invoke($9, `data`, []), [value("i32", 1)]);
217
218 // ./test/core/memory.wast:192
219 assert_return(() => invoke($9, `cast`, []), [value("f64", 42)]);
220
221 // ./test/core/memory.wast:194
222 assert_return(() => invoke($9, `i32_load8_s`, [-1]), [value("i32", -1)]);
223
224 // ./test/core/memory.wast:195
225 assert_return(() => invoke($9, `i32_load8_u`, [-1]), [value("i32", 255)]);
226
227 // ./test/core/memory.wast:196
228 assert_return(() => invoke($9, `i32_load16_s`, [-1]), [value("i32", -1)]);
229
230 // ./test/core/memory.wast:197
231 assert_return(() => invoke($9, `i32_load16_u`, [-1]), [value("i32", 65535)]);
232
233 // ./test/core/memory.wast:199
234 assert_return(() => invoke($9, `i32_load8_s`, [100]), [value("i32", 100)]);
235
236 // ./test/core/memory.wast:200
237 assert_return(() => invoke($9, `i32_load8_u`, [200]), [value("i32", 200)]);
238
239 // ./test/core/memory.wast:201
240 assert_return(() => invoke($9, `i32_load16_s`, [20000]), [value("i32", 20000)]);
241
242 // ./test/core/memory.wast:202
243 assert_return(() => invoke($9, `i32_load16_u`, [40000]), [value("i32", 40000)]);
244
245 // ./test/core/memory.wast:204
246 assert_return(() => invoke($9, `i32_load8_s`, [-19110589]), [value("i32", 67)]);
247
248 // ./test/core/memory.wast:205
249 assert_return(() => invoke($9, `i32_load8_s`, [878104047]), [value("i32", -17)]);
250
251 // ./test/core/memory.wast:206
252 assert_return(() => invoke($9, `i32_load8_u`, [-19110589]), [value("i32", 67)]);
253
254 // ./test/core/memory.wast:207
255 assert_return(() => invoke($9, `i32_load8_u`, [878104047]), [value("i32", 239)]);
256
257 // ./test/core/memory.wast:208
258 assert_return(() => invoke($9, `i32_load16_s`, [-19110589]), [value("i32", 25923)]);
259
260 // ./test/core/memory.wast:209
261 assert_return(() => invoke($9, `i32_load16_s`, [878104047]), [value("i32", -12817)]);
262
263 // ./test/core/memory.wast:210
264 assert_return(() => invoke($9, `i32_load16_u`, [-19110589]), [value("i32", 25923)]);
265
266 // ./test/core/memory.wast:211
267 assert_return(() => invoke($9, `i32_load16_u`, [878104047]), [value("i32", 52719)]);
268
269 // ./test/core/memory.wast:213
270 assert_return(() => invoke($9, `i64_load8_s`, [-1n]), [value("i64", -1n)]);
271
272 // ./test/core/memory.wast:214
273 assert_return(() => invoke($9, `i64_load8_u`, [-1n]), [value("i64", 255n)]);
274
275 // ./test/core/memory.wast:215
276 assert_return(() => invoke($9, `i64_load16_s`, [-1n]), [value("i64", -1n)]);
277
278 // ./test/core/memory.wast:216
279 assert_return(() => invoke($9, `i64_load16_u`, [-1n]), [value("i64", 65535n)]);
280
281 // ./test/core/memory.wast:217
282 assert_return(() => invoke($9, `i64_load32_s`, [-1n]), [value("i64", -1n)]);
283
284 // ./test/core/memory.wast:218
285 assert_return(() => invoke($9, `i64_load32_u`, [-1n]), [value("i64", 4294967295n)]);
286
287 // ./test/core/memory.wast:220
288 assert_return(() => invoke($9, `i64_load8_s`, [100n]), [value("i64", 100n)]);
289
290 // ./test/core/memory.wast:221
291 assert_return(() => invoke($9, `i64_load8_u`, [200n]), [value("i64", 200n)]);
292
293 // ./test/core/memory.wast:222
294 assert_return(() => invoke($9, `i64_load16_s`, [20000n]), [value("i64", 20000n)]);
295
296 // ./test/core/memory.wast:223
297 assert_return(() => invoke($9, `i64_load16_u`, [40000n]), [value("i64", 40000n)]);
298
299 // ./test/core/memory.wast:224
300 assert_return(() => invoke($9, `i64_load32_s`, [20000n]), [value("i64", 20000n)]);
301
302 // ./test/core/memory.wast:225
303 assert_return(() => invoke($9, `i64_load32_u`, [40000n]), [value("i64", 40000n)]);
304
305 // ./test/core/memory.wast:227
306 assert_return(() => invoke($9, `i64_load8_s`, [-81985529755441853n]), [value("i64", 67n)]);
307
308 // ./test/core/memory.wast:228
309 assert_return(() => invoke($9, `i64_load8_s`, [3771275841602506223n]), [value("i64", -17n)]);
310
311 // ./test/core/memory.wast:229
312 assert_return(() => invoke($9, `i64_load8_u`, [-81985529755441853n]), [value("i64", 67n)]);
313
314 // ./test/core/memory.wast:230
315 assert_return(() => invoke($9, `i64_load8_u`, [3771275841602506223n]), [value("i64", 239n)]);
316
317 // ./test/core/memory.wast:231
318 assert_return(() => invoke($9, `i64_load16_s`, [-81985529755441853n]), [value("i64", 25923n)]);
319
320 // ./test/core/memory.wast:232
321 assert_return(() => invoke($9, `i64_load16_s`, [3771275841602506223n]), [value("i64", -12817n)]);
322
323 // ./test/core/memory.wast:233
324 assert_return(() => invoke($9, `i64_load16_u`, [-81985529755441853n]), [value("i64", 25923n)]);
325
326 // ./test/core/memory.wast:234
327 assert_return(() => invoke($9, `i64_load16_u`, [3771275841602506223n]), [value("i64", 52719n)]);
328
329 // ./test/core/memory.wast:235
330 assert_return(() => invoke($9, `i64_load32_s`, [-81985529755441853n]), [value("i64", 1446274371n)]);
331
332 // ./test/core/memory.wast:236
333 assert_return(() => invoke($9, `i64_load32_s`, [3771275841602506223n]), [value("i64", -1732588049n)]);
334
335 // ./test/core/memory.wast:237
336 assert_return(() => invoke($9, `i64_load32_u`, [-81985529755441853n]), [value("i64", 1446274371n)]);
337
338 // ./test/core/memory.wast:238
339 assert_return(() => invoke($9, `i64_load32_u`, [3771275841602506223n]), [value("i64", 2562379247n)]);
340
341 // ./test/core/memory.wast:242
342 assert_malformed(
343 () => instantiate(`(memory $$foo 1) (memory $$foo 1) `),
344 `duplicate memory`,
345 );
346
347 // ./test/core/memory.wast:246
348 assert_malformed(
349 () => instantiate(`(import "" "" (memory $$foo 1)) (memory $$foo 1) `),
350 `duplicate memory`,
351 );
352
353 // ./test/core/memory.wast:250
354 assert_malformed(
355 () => instantiate(`(import "" "" (memory $$foo 1)) (import "" "" (memory $$foo 1)) `),
356 `duplicate memory`,
357 );
358
359 // ./test/core/memory.wast:257
360 let $10 = instantiate(`(module
361 (memory (export "memory") 1 1)
362
363 ;; These should not change the behavior of memory accesses.
364 (global (export "__data_end") i32 (i32.const 10000))
365 (global (export "__stack_top") i32 (i32.const 10000))
366 (global (export "__heap_base") i32 (i32.const 10000))
367
368 (func (export "load") (param i32) (result i32)
369 (i32.load8_u (local.get 0))
370 )
371 )`);
372
373 // ./test/core/memory.wast:271
374 assert_return(() => invoke($10, `load`, [0]), [value("i32", 0)]);
375
376 // ./test/core/memory.wast:272
377 assert_return(() => invoke($10, `load`, [10000]), [value("i32", 0)]);
378
379 // ./test/core/memory.wast:273
380 assert_return(() => invoke($10, `load`, [20000]), [value("i32", 0)]);
381
382 // ./test/core/memory.wast:274
383 assert_return(() => invoke($10, `load`, [30000]), [value("i32", 0)]);
384
385 // ./test/core/memory.wast:275
386 assert_return(() => invoke($10, `load`, [40000]), [value("i32", 0)]);
387
388 // ./test/core/memory.wast:276
389 assert_return(() => invoke($10, `load`, [50000]), [value("i32", 0)]);
390
391 // ./test/core/memory.wast:277
392 assert_return(() => invoke($10, `load`, [60000]), [value("i32", 0)]);
393
394 // ./test/core/memory.wast:278
395 assert_return(() => invoke($10, `load`, [65535]), [value("i32", 0)]);