Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
[test] Minor cleanup to generated output (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
binji committed Mar 5, 2019
1 parent a1c04b5 commit 6c802fa
Show file tree
Hide file tree
Showing 11 changed files with 2,195 additions and 2,340 deletions.
550 changes: 240 additions & 310 deletions test/core/memory_copy.wast

Large diffs are not rendered by default.

256 changes: 90 additions & 166 deletions test/core/memory_fill.wast

Large diffs are not rendered by default.

964 changes: 482 additions & 482 deletions test/core/memory_init.wast

Large diffs are not rendered by default.

575 changes: 298 additions & 277 deletions test/core/table_copy.wast

Large diffs are not rendered by default.

1,469 changes: 732 additions & 737 deletions test/core/table_init.wast

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions test/meta/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ function print_origin(origin) {
function checkRangeCode() {
return `
(func (export "checkRange") (param $from i32) (param $to i32) (param $expected i32) (result i32)
(loop $cont
(if (i32.eq (local.get $from) (local.get $to))
(then
(return (i32.const -1))))
(if (i32.eq (i32.load8_u (local.get $from)) (local.get $expected))
(then
(local.set $from (i32.add (local.get $from) (i32.const 1)))
(br $cont))))
(return (local.get $from)))
(loop $cont
(if (i32.eq (local.get $from) (local.get $to))
(then
(return (i32.const -1))))
(if (i32.eq (i32.load8_u (local.get $from)) (local.get $expected))
(then
(local.set $from (i32.add (local.get $from) (i32.const 1)))
(br $cont))))
(return (local.get $from)))
`;
}

Expand Down
432 changes: 212 additions & 220 deletions test/meta/generate_memory_copy.js

Large diffs are not rendered by default.

25 changes: 9 additions & 16 deletions test/meta/generate_memory_fill.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

print_origin("generate_memory_fill.js");

let PREAMBLE = `
(memory 1 1)
let PREAMBLE =
`(memory 1 1)
${checkRangeCode()}`;

// Range valid
Expand All @@ -21,8 +21,7 @@ checkRange(0x0FF00, 0x10000, 0x55)

// Range invalid
print(
`
(module
`(module
${PREAMBLE}
(func (export "test")
(memory.fill (i32.const 0xFF00) (i32.const 0x55) (i32.const 257))))
Expand All @@ -31,8 +30,7 @@ print(

// Wraparound the end of 32-bit offset space
print(
`
(module
`(module
${PREAMBLE}
(func (export "test")
(memory.fill (i32.const 0xFFFFFF00) (i32.const 0x55) (i32.const 257))))
Expand All @@ -41,8 +39,7 @@ print(

// Zero len with offset in-bounds is a no-op
print(
`
(module
`(module
${PREAMBLE}
(func (export "test")
(memory.fill (i32.const 0x12) (i32.const 0x55) (i32.const 0))))
Expand All @@ -52,8 +49,7 @@ checkRange(0x00000, 0x10000, 0x00);

// Zero len with offset out-of-bounds at the end of memory is allowed
print(
`
(module
`(module
${PREAMBLE}
(func (export "test")
(memory.fill (i32.const 0x10000) (i32.const 0x55) (i32.const 0))))
Expand All @@ -62,8 +58,7 @@ print(

// Very large range
print(
`
(module
`(module
${PREAMBLE}
(func (export "test")
(memory.fill (i32.const 0x1) (i32.const 0xAA) (i32.const 0xFFFE))))
Expand Down Expand Up @@ -93,8 +88,7 @@ checkRange(0x12+10, 0x10000, 0x00);

// Module doesn't have a memory.
print(
`
(assert_invalid
`(assert_invalid
(module
(func (export "testfn")
(memory.fill (i32.const 10) (i32.const 20) (i32.const 30))))
Expand All @@ -110,8 +104,7 @@ print(
if (ty1 == 'i32' && ty2 == 'i32' && ty3 == 'i32')
continue; // this is the only valid case
print(
`
(assert_invalid
`(assert_invalid
(module
(memory 1 1)
(func (export "testfn")
Expand Down
40 changes: 20 additions & 20 deletions test/meta/generate_memory_init.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const e = 0;

// This just gives the initial state of the memory, with its active
// initialisers applied.
mem_test("nop",
mem_test("(nop)",
[e,e,3,1,4, 1,e,e,e,e, e,e,7,5,2, 3,6,e,e,e, e,e,e,e,e, e,e,e,e,e]);

// Passive init that overwrites all-zero entries
Expand All @@ -42,22 +42,22 @@ mem_test("(memory.init 3 (i32.const 15) (i32.const 1) (i32.const 3))",
[e,e,3,1,4, 1,e,e,e,e, e,e,7,5,2, 9,2,7,e,e, e,e,e,e,e, e,e,e,e,e]);

// Perform active and passive initialisation and then multiple copies
mem_test("(memory.init 1 (i32.const 7) (i32.const 0) (i32.const 4)) \n" +
"data.drop 1 \n" +
"(memory.init 3 (i32.const 15) (i32.const 1) (i32.const 3)) \n" +
"data.drop 3 \n" +
"(memory.copy (i32.const 20) (i32.const 15) (i32.const 5)) \n" +
"(memory.copy (i32.const 21) (i32.const 29) (i32.const 1)) \n" +
"(memory.copy (i32.const 24) (i32.const 10) (i32.const 1)) \n" +
"(memory.copy (i32.const 13) (i32.const 11) (i32.const 4)) \n" +
"(memory.copy (i32.const 19) (i32.const 20) (i32.const 5))",
mem_test(`(memory.init 1 (i32.const 7) (i32.const 0) (i32.const 4))
(data.drop 1)
(memory.init 3 (i32.const 15) (i32.const 1) (i32.const 3))
(data.drop 3)
(memory.copy (i32.const 20) (i32.const 15) (i32.const 5))
(memory.copy (i32.const 21) (i32.const 29) (i32.const 1))
(memory.copy (i32.const 24) (i32.const 10) (i32.const 1))
(memory.copy (i32.const 13) (i32.const 11) (i32.const 4))
(memory.copy (i32.const 19) (i32.const 20) (i32.const 5))`,
[e,e,3,1,4, 1,e,2,7,1, 8,e,7,e,7, 5,2,7,e,9, e,7,e,8,8, e,e,e,e,e]);

// Miscellaneous

let PREAMBLE =
`(memory 1)
(data passive "\\37")`;
(data passive "\\37")`;

// drop with no memory
print(
Expand Down Expand Up @@ -193,11 +193,11 @@ print(
continue; // this is the only valid case
print(
`(assert_invalid
(module
${PREAMBLE}
(func (export "test")
(memory.init 0 (${ty1}.const 1) (${ty2}.const 1) (${ty3}.const 1))))
"type mismatch")
(module
${PREAMBLE}
(func (export "test")
(memory.init 0 (${ty1}.const 1) (${ty2}.const 1) (${ty3}.const 1))))
"type mismatch")
`);
}}}
}
Expand All @@ -214,11 +214,11 @@ const mem_init_len = 16;
function mem_init(min, max, shared, backup, write) {
print(
`(module
(memory ${min} ${max} ${shared})
(data passive "\\42\\42\\42\\42\\42\\42\\42\\42\\42\\42\\42\\42\\42\\42\\42\\42")
(memory ${min} ${max} ${shared})
(data passive "\\42\\42\\42\\42\\42\\42\\42\\42\\42\\42\\42\\42\\42\\42\\42\\42")
${checkRangeCode()}
(func (export "run") (param $offs i32) (param $len i32)
(memory.init 0 (local.get $offs) (i32.const 0) (local.get $len))))
(func (export "run") (param $offs i32) (param $len i32)
(memory.init 0 (local.get $offs) (i32.const 0) (local.get $len))))
`);
// A fill writing past the end of the memory should throw *and* have filled
// all the way up to the end.
Expand Down
69 changes: 35 additions & 34 deletions test/meta/generate_table_copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ function emit_a() {
(func (export "ef3") (result i32) (i32.const 3))
(func (export "ef4") (result i32) (i32.const 4))
)
(register "a")
`);
(register "a")`);
}

// ... and this one imports those 5 functions. It adds 5 of its own, creates a
Expand Down Expand Up @@ -81,7 +80,7 @@ let e = undefined;

// This just gives the initial state of the table, with its active
// initialisers applied
tab_test("nop",
tab_test("(nop)",
[e,e,3,1,4, 1,e,e,e,e, e,e,7,5,2, 3,6,e,e,e, e,e,e,e,e, e,e,e,e,e]);

// Copy non-null over non-null
Expand Down Expand Up @@ -221,41 +220,43 @@ function tbl_copy(min, max, srcOffs, targetOffs, len, copyDown=false) {
let srcLim = srcOffs + Math.min(len, targetAvail, srcAvail);

print(
`(module
(type (func (result i32)))
(table ${min} ${max} funcref)
(elem (i32.const ${srcOffs})
${(function () {
var s = "";
for (let i=srcOffs, j=0; i < srcLim; i++, j++)
s += " $f" + j;
return s;
})()})
(func $f0 (export "f0") (result i32) (i32.const 0))
(func $f1 (export "f1") (result i32) (i32.const 1))
(func $f2 (export "f2") (result i32) (i32.const 2))
(func $f3 (export "f3") (result i32) (i32.const 3))
(func $f4 (export "f4") (result i32) (i32.const 4))
(func $f5 (export "f5") (result i32) (i32.const 5))
(func $f6 (export "f6") (result i32) (i32.const 6))
(func $f7 (export "f7") (result i32) (i32.const 7))
(func $f8 (export "f8") (result i32) (i32.const 8))
(func $f9 (export "f9") (result i32) (i32.const 9))
(func $f10 (export "f10") (result i32) (i32.const 10))
(func $f11 (export "f11") (result i32) (i32.const 11))
(func $f12 (export "f12") (result i32) (i32.const 12))
(func $f13 (export "f13") (result i32) (i32.const 13))
(func $f14 (export "f14") (result i32) (i32.const 14))
(func $f15 (export "f15") (result i32) (i32.const 15))
(func (export "test") (param $n i32) (result i32)
(call_indirect (type 0) (local.get $n)))
(func (export "run") (param $targetOffs i32) (param $srcOffs i32) (param $len i32)
(table.copy (local.get $targetOffs) (local.get $srcOffs) (local.get $len))))`);
`
(module
(type (func (result i32)))
(table ${min} ${max} funcref)
(elem (i32.const ${srcOffs})
${(function () {
var s = "";
for (let i=srcOffs, j=0; i < srcLim; i++, j++)
s += " $f" + j;
return s;
})()})
(func $f0 (export "f0") (result i32) (i32.const 0))
(func $f1 (export "f1") (result i32) (i32.const 1))
(func $f2 (export "f2") (result i32) (i32.const 2))
(func $f3 (export "f3") (result i32) (i32.const 3))
(func $f4 (export "f4") (result i32) (i32.const 4))
(func $f5 (export "f5") (result i32) (i32.const 5))
(func $f6 (export "f6") (result i32) (i32.const 6))
(func $f7 (export "f7") (result i32) (i32.const 7))
(func $f8 (export "f8") (result i32) (i32.const 8))
(func $f9 (export "f9") (result i32) (i32.const 9))
(func $f10 (export "f10") (result i32) (i32.const 10))
(func $f11 (export "f11") (result i32) (i32.const 11))
(func $f12 (export "f12") (result i32) (i32.const 12))
(func $f13 (export "f13") (result i32) (i32.const 13))
(func $f14 (export "f14") (result i32) (i32.const 14))
(func $f15 (export "f15") (result i32) (i32.const 15))
(func (export "test") (param $n i32) (result i32)
(call_indirect (type 0) (local.get $n)))
(func (export "run") (param $targetOffs i32) (param $srcOffs i32) (param $len i32)
(table.copy (local.get $targetOffs) (local.get $srcOffs) (local.get $len))))
`);

let immediateOOB = copyDown && (srcOffs + len > tblLength || targetOffs + len > tblLength);

print(`(assert_trap (invoke "run" (i32.const ${targetOffs}) (i32.const ${srcOffs}) (i32.const ${len}))
"out of bounds")`);
"out of bounds")`);

var t = 0;
var s = 0;
Expand Down
Loading

0 comments on commit 6c802fa

Please sign in to comment.