diff options
author | Sam Clegg <sbc@chromium.org> | 2024-05-10 16:33:38 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-10 23:33:38 +0000 |
commit | abc430b617385f3e989f85e7bd1c2a9d838fd217 (patch) | |
tree | 5a7869083ae64cc59a04cb5512b3f175fade02d5 /test/spec | |
parent | 9975b56614d4a5560b35f009be20d51e360b69dc (diff) | |
download | binaryen-abc430b617385f3e989f85e7bd1c2a9d838fd217.tar.gz binaryen-abc430b617385f3e989f85e7bd1c2a9d838fd217.tar.bz2 binaryen-abc430b617385f3e989f85e7bd1c2a9d838fd217.zip |
[memory64] Add table64 to existing memory64 support (#6577)
Tests is still very limited. Hopefully we can use the upstream spec
tests soon and avoid having to write our own tests for
`.set/.set/.fill/etc`.
See https://github.com/WebAssembly/memory64/issues/51
Diffstat (limited to 'test/spec')
-rw-r--r-- | test/spec/table.wast | 68 | ||||
-rw-r--r-- | test/spec/table_fill.wast | 193 | ||||
-rw-r--r-- | test/spec/table_get.wast | 25 | ||||
-rw-r--r-- | test/spec/table_set.wast | 12 | ||||
-rw-r--r-- | test/spec/table_size.wast | 5 |
5 files changed, 203 insertions, 100 deletions
diff --git a/test/spec/table.wast b/test/spec/table.wast index 54281a03e..d61a7d1b7 100644 --- a/test/spec/table.wast +++ b/test/spec/table.wast @@ -1,24 +1,76 @@ - ;; Test table section structure (module (table 0 funcref)) -(module (table 0 (ref null func))) (module (table 1 funcref)) (module (table 0 0 funcref)) (module (table 0 1 funcref)) -(module (table 0 1 (ref null func))) (module (table 1 256 funcref)) -(module (table 0 65536 externref)) -;; (module (table 0 0xffff_ffff funcref)) +(module (table 0 65536 funcref)) +(module (table 0 0xffff_ffff funcref)) (module (table 0 funcref) (table 0 funcref)) (module (table (import "spectest" "table") 0 funcref) (table 0 funcref)) -(assert_invalid (module (elem (i32.const 0))) "unknown table") -(assert_invalid (module (elem (i32.const 0) $f) (func $f)) "unknown table") +(assert_invalid + (module (table 1 0 funcref)) + "size minimum must not be greater than maximum" +) +(assert_invalid + (module (table 0xffff_ffff 0 funcref)) + "size minimum must not be greater than maximum" +) +(assert_invalid + (module quote "(table 0x1_0000_0000 funcref)") + "table size must be at most 2^32-1" +) +(assert_invalid + (module quote "(table 0x1_0000_0000 0x1_0000_0000 funcref)") + "table size must be at most 2^32-1" +) +(assert_invalid + (module quote "(table 0 0x1_0000_0000 funcref)") + "table size must be at most 2^32-1" +) + +;; Same as above but with i64 index types + +(module (table i64 0 funcref)) +(module (table i64 1 funcref)) +(module (table i64 0 0 funcref)) +(module (table i64 0 1 funcref)) +(module (table i64 1 256 funcref)) +(module (table i64 0 65536 funcref)) +(module (table i64 0 0xffff_ffff funcref)) + +(module (table i64 0 funcref) (table i64 0 funcref)) +(module (table (import "spectest" "table64") i64 0 funcref) (table i64 0 funcref)) (assert_invalid - (module (table 1 0 funcref)) + (module (table i64 1 0 funcref)) + "size minimum must not be greater than maximum" +) +(assert_invalid + (module (table i64 0xffff_ffff 0 funcref)) "size minimum must not be greater than maximum" ) + +;; Elem segments with no table + +(assert_invalid (module (elem (i32.const 0))) "unknown table") +(assert_invalid (module (elem (i32.const 0) $f) (func $f)) "unknown table") + +;; Duplicate table identifiers + +(assert_malformed (module quote + "(table $foo 1 funcref)" + "(table $foo 1 funcref)") + "duplicate table") +(assert_malformed (module quote + "(import \"\" \"\" (table $foo 1 funcref))" + "(table $foo 1 funcref)") + "duplicate table") +(assert_malformed (module quote + "(import \"\" \"\" (table $foo 1 funcref))" + "(import \"\" \"\" (table $foo 1 funcref))") + "duplicate table") diff --git a/test/spec/table_fill.wast b/test/spec/table_fill.wast index 79b5a6a83..5471e2e23 100644 --- a/test/spec/table_fill.wast +++ b/test/spec/table_fill.wast @@ -1,115 +1,138 @@ (module - (type $f (func (result i32))) + (table $t 10 externref) - (table $t 10 funcref) - - (func $0 (result i32) - (i32.const 0) - ) - - (func $1 (result i32) - (i32.const 1) - ) - - (func $2 (result i32) - (i32.const 2) - ) - - (func $3 (result i32) - (i32.const 3) - ) - - (func $4 (result i32) - (i32.const 4) - ) - - (func (export "fill-0") (param $i i32) (param $n i32) - (table.fill $t (local.get $i) (ref.func $0) (local.get $n)) - ) - - (func (export "fill-1") (param $i i32) (param $n i32) - (table.fill $t (local.get $i) (ref.func $1) (local.get $n)) + (func (export "fill") (param $i i32) (param $r externref) (param $n i32) + (table.fill $t (local.get $i) (local.get $r) (local.get $n)) ) - (func (export "fill-2") (param $i i32) (param $n i32) - (table.fill $t (local.get $i) (ref.func $2) (local.get $n)) + (func (export "fill-abbrev") (param $i i32) (param $r externref) (param $n i32) + (table.fill (local.get $i) (local.get $r) (local.get $n)) ) - (func (export "fill-3") (param $i i32) (param $n i32) - (table.fill $t (local.get $i) (ref.func $3) (local.get $n)) + (func (export "get") (param $i i32) (result externref) + (table.get $t (local.get $i)) ) - (func (export "fill-4") (param $i i32) (param $n i32) - (table.fill $t (local.get $i) (ref.func $4) (local.get $n)) - ) + (table $t64 i64 10 externref) - (func (export "fill-null") (param $i i32) (param $n i32) - (table.fill $t (local.get $i) (ref.null func) (local.get $n)) + (func (export "fill-t64") (param $i i64) (param $r externref) (param $n i64) + (table.fill $t64 (local.get $i) (local.get $r) (local.get $n)) ) - (func (export "get-null") (param $i i32) (result funcref) - (table.get $t (local.get $i)) - ) - - (func (export "get") (param $i i32) (result i32) - (call_indirect $t (type $f) (local.get $i)) + (func (export "get-t64") (param $i i64) (result externref) + (table.get $t64 (local.get $i)) ) ) -(assert_return (invoke "get-null" (i32.const 1)) (ref.null func)) -(assert_return (invoke "get-null" (i32.const 2)) (ref.null func)) -(assert_return (invoke "get-null" (i32.const 3)) (ref.null func)) -(assert_return (invoke "get-null" (i32.const 4)) (ref.null func)) -(assert_return (invoke "get-null" (i32.const 5)) (ref.null func)) - -(assert_return (invoke "fill-1" (i32.const 2) (i32.const 3))) -(assert_return (invoke "get-null" (i32.const 1)) (ref.null func)) -(assert_return (invoke "get" (i32.const 2)) (i32.const 1)) -(assert_return (invoke "get" (i32.const 3)) (i32.const 1)) -(assert_return (invoke "get" (i32.const 4)) (i32.const 1)) -(assert_return (invoke "get-null" (i32.const 5)) (ref.null func)) - -(assert_return (invoke "fill-2" (i32.const 4) (i32.const 2))) -(assert_return (invoke "get" (i32.const 3)) (i32.const 1)) -(assert_return (invoke "get" (i32.const 4)) (i32.const 2)) -(assert_return (invoke "get" (i32.const 5)) (i32.const 2)) -(assert_return (invoke "get-null" (i32.const 6)) (ref.null func)) - -(assert_return (invoke "fill-3" (i32.const 4) (i32.const 0))) -(assert_return (invoke "get" (i32.const 3)) (i32.const 1)) -(assert_return (invoke "get" (i32.const 4)) (i32.const 2)) -(assert_return (invoke "get" (i32.const 5)) (i32.const 2)) - -(assert_return (invoke "fill-4" (i32.const 8) (i32.const 2))) -(assert_return (invoke "get-null" (i32.const 7)) (ref.null func)) -(assert_return (invoke "get" (i32.const 8)) (i32.const 4)) -(assert_return (invoke "get" (i32.const 9)) (i32.const 4)) - -(assert_return (invoke "fill-null" (i32.const 9) (i32.const 1))) -(assert_return (invoke "get" (i32.const 8)) (i32.const 4)) -(assert_return (invoke "get-null" (i32.const 9)) (ref.null func)) - -(assert_return (invoke "fill-1" (i32.const 10) (i32.const 0))) -(assert_return (invoke "get-null" (i32.const 9)) (ref.null func)) +(assert_return (invoke "get" (i32.const 1)) (ref.null extern)) +(assert_return (invoke "get" (i32.const 2)) (ref.null extern)) +(assert_return (invoke "get" (i32.const 3)) (ref.null extern)) +(assert_return (invoke "get" (i32.const 4)) (ref.null extern)) +(assert_return (invoke "get" (i32.const 5)) (ref.null extern)) + +;; (assert_return (invoke "fill" (i32.const 2) (ref.extern 1) (i32.const 3))) +(assert_return (invoke "get" (i32.const 1)) (ref.null extern)) +;; (assert_return (invoke "get" (i32.const 2)) (ref.extern 1)) +;; (assert_return (invoke "get" (i32.const 3)) (ref.extern 1)) +;; (assert_return (invoke "get" (i32.const 4)) (ref.extern 1)) +(assert_return (invoke "get" (i32.const 5)) (ref.null extern)) + +;; (assert_return (invoke "fill" (i32.const 4) (ref.extern 2) (i32.const 2))) +;; (assert_return (invoke "get" (i32.const 3)) (ref.extern 1)) +;; (assert_return (invoke "get" (i32.const 4)) (ref.extern 2)) +;; (assert_return (invoke "get" (i32.const 5)) (ref.extern 2)) +(assert_return (invoke "get" (i32.const 6)) (ref.null extern)) + +;; (assert_return (invoke "fill" (i32.const 4) (ref.extern 3) (i32.const 0))) +;; (assert_return (invoke "get" (i32.const 3)) (ref.extern 1)) +;; (assert_return (invoke "get" (i32.const 4)) (ref.extern 2)) +;; (assert_return (invoke "get" (i32.const 5)) (ref.extern 2)) + +;; (assert_return (invoke "fill" (i32.const 8) (ref.extern 4) (i32.const 2))) +(assert_return (invoke "get" (i32.const 7)) (ref.null extern)) +;; (assert_return (invoke "get" (i32.const 8)) (ref.extern 4)) +;; (assert_return (invoke "get" (i32.const 9)) (ref.extern 4)) + +(assert_return (invoke "fill-abbrev" (i32.const 9) (ref.null extern) (i32.const 1))) +;; (assert_return (invoke "get" (i32.const 8)) (ref.extern 4)) +(assert_return (invoke "get" (i32.const 9)) (ref.null extern)) + +;; (assert_return (invoke "fill" (i32.const 10) (ref.extern 5) (i32.const 0))) +(assert_return (invoke "get" (i32.const 9)) (ref.null extern)) + +;; (assert_trap +;; (invoke "fill" (i32.const 8) (ref.extern 6) (i32.const 3)) +;; "out of bounds table access" +;;) +(assert_return (invoke "get" (i32.const 7)) (ref.null extern)) +;;(assert_return (invoke "get" (i32.const 8)) (ref.extern 4)) +(assert_return (invoke "get" (i32.const 9)) (ref.null extern)) (assert_trap - (invoke "fill-2" (i32.const 8) (i32.const 3)) + (invoke "fill" (i32.const 11) (ref.null extern) (i32.const 0)) "out of bounds table access" ) -(assert_return (invoke "get-null" (i32.const 7)) (ref.null func)) -(assert_return (invoke "get" (i32.const 8)) (i32.const 4)) -(assert_return (invoke "get-null" (i32.const 9)) (ref.null func)) (assert_trap - (invoke "fill" (i32.const 11) (ref.null extern) (i32.const 0)) + (invoke "fill" (i32.const 11) (ref.null extern) (i32.const 10)) "out of bounds table access" ) +;; Same as above but for t64 + +(assert_return (invoke "get-t64" (i64.const 1)) (ref.null extern)) +(assert_return (invoke "get-t64" (i64.const 2)) (ref.null extern)) +(assert_return (invoke "get-t64" (i64.const 3)) (ref.null extern)) +(assert_return (invoke "get-t64" (i64.const 4)) (ref.null extern)) +(assert_return (invoke "get-t64" (i64.const 5)) (ref.null extern)) + +;; (assert_return (invoke "fill-t64" (i64.const 2) (ref.extern 1) (i64.const 3))) +(assert_return (invoke "get-t64" (i64.const 1)) (ref.null extern)) +;; (assert_return (invoke "get-t64" (i64.const 2)) (ref.extern 1)) +;; (assert_return (invoke "get-t64" (i64.const 3)) (ref.extern 1)) +;; (assert_return (invoke "get-t64" (i64.const 4)) (ref.extern 1)) +(assert_return (invoke "get-t64" (i64.const 5)) (ref.null extern)) + +;; (assert_return (invoke "fill-t64" (i64.const 4) (ref.extern 2) (i64.const 2))) +;; (assert_return (invoke "get-t64" (i64.const 3)) (ref.extern 1)) +;; (assert_return (invoke "get-t64" (i64.const 4)) (ref.extern 2)) +;; (assert_return (invoke "get-t64" (i64.const 5)) (ref.extern 2)) +(assert_return (invoke "get-t64" (i64.const 6)) (ref.null extern)) + +;; (assert_return (invoke "fill-t64" (i64.const 4) (ref.extern 3) (i64.const 0))) +;; (assert_return (invoke "get-t64" (i64.const 3)) (ref.extern 1)) +;; (assert_return (invoke "get-t64" (i64.const 4)) (ref.extern 2)) +;; (assert_return (invoke "get-t64" (i64.const 5)) (ref.extern 2)) + +;; (assert_return (invoke "fill-t64" (i64.const 8) (ref.extern 4) (i64.const 2))) +(assert_return (invoke "get-t64" (i64.const 7)) (ref.null extern)) +;; (assert_return (invoke "get-t64" (i64.const 8)) (ref.extern 4)) +;; (assert_return (invoke "get-t64" (i64.const 9)) (ref.extern 4)) + +(assert_return (invoke "fill-t64" (i64.const 9) (ref.null extern) (i64.const 1))) +;; (assert_return (invoke "get-t64" (i64.const 8)) (ref.extern 4)) +(assert_return (invoke "get-t64" (i64.const 9)) (ref.null extern)) + +;; (assert_return (invoke "fill-t64" (i64.const 10) (ref.extern 5) (i64.const 0))) +(assert_return (invoke "get-t64" (i64.const 9)) (ref.null extern)) + +;; (assert_trap +;; (invoke "fill-t64" (i64.const 8) (ref.extern 6) (i64.const 3)) +;; "out of bounds table access" +;; ) +(assert_return (invoke "get-t64" (i64.const 7)) (ref.null extern)) +;; (assert_return (invoke "get-t64" (i64.const 8)) (ref.extern 4)) +(assert_return (invoke "get-t64" (i64.const 9)) (ref.null extern)) + (assert_trap - (invoke "fill" (i32.const 11) (ref.null extern) (i32.const 10)) + (invoke "fill-t64" (i64.const 11) (ref.null extern) (i64.const 0)) "out of bounds table access" ) +(assert_trap + (invoke "fill-t64" (i64.const 11) (ref.null extern) (i64.const 10)) + "out of bounds table access" +) ;; Type errors diff --git a/test/spec/table_get.wast b/test/spec/table_get.wast index de5f6622a..cc24ba3ec 100644 --- a/test/spec/table_get.wast +++ b/test/spec/table_get.wast @@ -1,30 +1,45 @@ (module (table $t2 2 externref) (table $t3 3 funcref) + (table $t64 i64 3 funcref) (elem (table $t3) (i32.const 1) func $dummy) (func $dummy) + (func (export "init") + ;; (table.set $t2 (i32.const 1) (local.get $r)) + (table.set $t3 (i32.const 2) (table.get $t3 (i32.const 1))) + ) + (func (export "get-externref") (param $i i32) (result externref) - (table.get $t2 (local.get $i)) + (table.get (local.get $i)) ) (func $f3 (export "get-funcref") (param $i i32) (result funcref) (table.get $t3 (local.get $i)) ) + (func $f4 (export "get-funcref-t64") (param $i i64) (result funcref) + (table.get $t64 (local.get $i)) + ) (func (export "is_null-funcref") (param $i i32) (result i32) (ref.is_null (call $f3 (local.get $i))) ) ) +;; (invoke "init" (ref.extern 1)) +(invoke "init") + (assert_return (invoke "get-externref" (i32.const 0)) (ref.null extern)) +;; (assert_return (invoke "get-externref" (i32.const 1)) (ref.extern 1)) (assert_return (invoke "get-funcref" (i32.const 0)) (ref.null func)) +(assert_return (invoke "get-funcref-t64" (i64.const 0)) (ref.null func)) (assert_return (invoke "is_null-funcref" (i32.const 1)) (i32.const 0)) +(assert_return (invoke "is_null-funcref" (i32.const 2)) (i32.const 0)) -(assert_trap (invoke "get-externref" (i32.const 2)) "out of bounds") -(assert_trap (invoke "get-funcref" (i32.const 3)) "out of bounds") -(assert_trap (invoke "get-externref" (i32.const -1)) "out of bounds") -(assert_trap (invoke "get-funcref" (i32.const -1)) "out of bounds") +(assert_trap (invoke "get-externref" (i32.const 2)) "out of bounds table access") +(assert_trap (invoke "get-funcref" (i32.const 3)) "out of bounds table access") +(assert_trap (invoke "get-externref" (i32.const -1)) "out of bounds table access") +(assert_trap (invoke "get-funcref" (i32.const -1)) "out of bounds table access") ;; Type errors diff --git a/test/spec/table_set.wast b/test/spec/table_set.wast index 6034f146f..7ec3fc6c2 100644 --- a/test/spec/table_set.wast +++ b/test/spec/table_set.wast @@ -1,6 +1,7 @@ (module (table $t2 1 externref) (table $t3 2 funcref) + (table $t64 i64 2 funcref) (elem (table $t3) (i32.const 1) func $dummy) (func $dummy) @@ -10,9 +11,12 @@ (func $f3 (export "get-funcref") (param $i i32) (result funcref) (table.get $t3 (local.get $i)) ) + (func $f4 (export "get-funcref-t64") (param $i i64) (result funcref) + (table.get $t64 (local.get $i)) + ) (func (export "set-externref") (param $i i32) (param $r externref) - (table.set $t2 (local.get $i) (local.get $r)) + (table.set (local.get $i) (local.get $r)) ) (func (export "set-funcref") (param $i i32) (param $r funcref) (table.set $t3 (local.get $i) (local.get $r)) @@ -20,6 +24,9 @@ (func (export "set-funcref-from") (param $i i32) (param $j i32) (table.set $t3 (local.get $i) (table.get $t3 (local.get $j))) ) + (func (export "set-funcref-t64") (param $i i64) (param $r funcref) + (table.set $t64 (local.get $i) (local.get $r)) + ) (func (export "is_null-funcref") (param $i i32) (result i32) (ref.is_null (call $f3 (local.get $i))) @@ -32,6 +39,9 @@ (assert_return (invoke "set-externref" (i32.const 0) (ref.null extern))) (assert_return (invoke "get-externref" (i32.const 0)) (ref.null extern)) +(assert_return (invoke "set-funcref-t64" (i64.const 0) (ref.null func))) +(assert_return (invoke "get-funcref-t64" (i64.const 0)) (ref.null func)) + (assert_return (invoke "get-funcref" (i32.const 0)) (ref.null func)) (assert_return (invoke "set-funcref-from" (i32.const 0) (i32.const 1))) (assert_return (invoke "is_null-funcref" (i32.const 0)) (i32.const 0)) diff --git a/test/spec/table_size.wast b/test/spec/table_size.wast index ad293b5ee..71081d7e6 100644 --- a/test/spec/table_size.wast +++ b/test/spec/table_size.wast @@ -3,11 +3,13 @@ (table $t1 1 externref) (table $t2 0 2 externref) (table $t3 3 8 externref) + (table $t64 i64 42 42 externref) - (func (export "size-t0") (result i32) (table.size $t0)) + (func (export "size-t0") (result i32) table.size) (func (export "size-t1") (result i32) (table.size $t1)) (func (export "size-t2") (result i32) (table.size $t2)) (func (export "size-t3") (result i32) (table.size $t3)) + (func (export "size-t64") (result i64) (table.size $t64)) (func (export "grow-t0") (param $sz i32) (drop (table.grow $t0 (ref.null extern) (local.get $sz))) @@ -63,6 +65,7 @@ (assert_return (invoke "grow-t3" (i32.const 1))) (assert_return (invoke "size-t3") (i32.const 8)) +(assert_return (invoke "size-t64") (i64.const 42)) ;; Type errors |