Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit c6d9127

Browse files
authored
Merge pull request #46 from yamt/memory_copy1
memory_copy1.wast: add some tests
2 parents 4f6b8f5 + 15c1f92 commit c6d9127

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed
Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,40 @@
1-
;; TODO: test copy across different memories.
1+
;; test memory.copy across different memories.
2+
(module
3+
(memory $mem0 (data "\ff\11\44\ee"))
4+
(memory $mem1 (data "\ee\22\55\ff"))
5+
(memory $mem2 (data "\dd\33\66\00"))
6+
(memory $mem3 (data "\aa\bb\cc\dd"))
7+
8+
(func (export "copy") (param i32 i32 i32)
9+
(memory.copy $mem0 $mem3
10+
(local.get 0)
11+
(local.get 1)
12+
(local.get 2)))
13+
14+
(func (export "load8_u") (param i32) (result i32)
15+
(i32.load8_u $mem0 (local.get 0)))
16+
)
17+
18+
;; Non-overlapping copy.
19+
(invoke "copy" (i32.const 10) (i32.const 0) (i32.const 4))
20+
21+
(assert_return (invoke "load8_u" (i32.const 9)) (i32.const 0))
22+
(assert_return (invoke "load8_u" (i32.const 10)) (i32.const 0xaa))
23+
(assert_return (invoke "load8_u" (i32.const 11)) (i32.const 0xbb))
24+
(assert_return (invoke "load8_u" (i32.const 12)) (i32.const 0xcc))
25+
(assert_return (invoke "load8_u" (i32.const 13)) (i32.const 0xdd))
26+
(assert_return (invoke "load8_u" (i32.const 14)) (i32.const 0))
27+
28+
;; Copy ending at memory limit is ok.
29+
(invoke "copy" (i32.const 0xff00) (i32.const 0) (i32.const 0x100))
30+
(invoke "copy" (i32.const 0xfe00) (i32.const 0xff00) (i32.const 0x100))
31+
32+
;; Succeed when copying 0 bytes at the end of the region.
33+
(invoke "copy" (i32.const 0x10000) (i32.const 0) (i32.const 0))
34+
(invoke "copy" (i32.const 0) (i32.const 0x10000) (i32.const 0))
35+
36+
;; Copying 0 bytes outside the memory traps.
37+
(assert_trap (invoke "copy" (i32.const 0x10001) (i32.const 0) (i32.const 0))
38+
"out of bounds memory access")
39+
(assert_trap (invoke "copy" (i32.const 0) (i32.const 0x10001) (i32.const 0))
40+
"out of bounds memory access")

0 commit comments

Comments
 (0)