|
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