diff --git a/test/core/custom-page-sizes/custom-page-sizes-invalid.wast b/test/core/custom-page-sizes/custom-page-sizes-invalid.wast index 80cbcff..480d385 100644 --- a/test/core/custom-page-sizes/custom-page-sizes-invalid.wast +++ b/test/core/custom-page-sizes/custom-page-sizes-invalid.wast @@ -4,6 +4,11 @@ "invalid custom page size" ) +(assert_malformed + (module quote "(memory 0 (pagesize 0))") + "invalid custom page size" +) + ;; Power-of-two page sizes that are not 1 or 64KiB. (assert_invalid (module (memory 0 (pagesize 2))) diff --git a/test/core/custom-page-sizes/custom-page-sizes.wast b/test/core/custom-page-sizes/custom-page-sizes.wast index b312f1f..e7e8b68 100644 --- a/test/core/custom-page-sizes/custom-page-sizes.wast +++ b/test/core/custom-page-sizes/custom-page-sizes.wast @@ -106,3 +106,33 @@ (module (memory (import "m" "large-pages-memory") 0 (pagesize 65536)) ) + +;; Inline data segments + +;; pagesize 0 +(assert_malformed (module quote "(memory (pagesize 0) (data))") "invalid custom page size") + +;; pagesize 1 +(module + (memory (pagesize 1) (data "xyz")) + (func (export "size") (result i32) + memory.size) + (func (export "grow") (param i32) (result i32) + (memory.grow (local.get 0))) + (func (export "load") (param i32) (result i32) + (i32.load8_u (local.get 0)))) + +(assert_return (invoke "size") (i32.const 3)) +(assert_return (invoke "load" (i32.const 0)) (i32.const 120)) +(assert_return (invoke "load" (i32.const 1)) (i32.const 121)) +(assert_return (invoke "load" (i32.const 2)) (i32.const 122)) +(assert_trap (invoke "load" (i32.const 3)) "out of bounds") +(assert_return (invoke "grow" (i32.const 1)) (i32.const -1)) + +;; pagesize 65536 +(module + (memory (pagesize 65536) (data "xyz")) + (func (export "size") (result i32) + memory.size)) + +(assert_return (invoke "size") (i32.const 1)) diff --git a/test/core/custom-page-sizes/memory_max.wast b/test/core/custom-page-sizes/memory_max.wast new file mode 100644 index 0000000..7e0fdc0 --- /dev/null +++ b/test/core/custom-page-sizes/memory_max.wast @@ -0,0 +1,64 @@ +;; Maximum memory sizes. +;; +;; These modules are valid, but instantiating them is unnecessary +;; and would only allocate very large memories and slow down running +;; the spec tests. Therefore, add a missing import so that it cannot +;; be instantiated and use `assert_unlinkable`. This approach +;; enforces that the module itself is still valid, but that its +;; instantiation fails early (hopefully before any memories are +;; actually allocated). + +;; i32 (pagesize 1) +(assert_unlinkable + (module + (import "test" "unknown" (func)) + (memory 0xFFFF_FFFF (pagesize 1))) + "unknown import") + +;; i64 (pagesize 1) +(assert_unlinkable + (module + (import "test" "import" (func)) + (memory i64 0xFFFF_FFFF_FFFF_FFFF (pagesize 1))) + "unknown import") + +;; i32 (default pagesize) +(assert_unlinkable + (module + (import "test" "unknown" (func)) + (memory 65536 (pagesize 65536))) + "unknown import") + +;; i64 (default pagesize) +(assert_unlinkable + (module + (import "test" "unknown" (func)) + (memory i64 0x1_0000_0000_0000 (pagesize 65536))) + "unknown import") + +;; Memory size just over the maximum. +;; +;; These are malformed (for pagesize 1) +;; or invalid (for other pagesizes). + +;; i32 (pagesize 1) +(assert_malformed + (module quote "(memory 0x1_0000_0000 (pagesize 1))") + "constant out of range") + +;; i64 (pagesize 1) +(assert_malformed + (module quote "(memory i64 0x1_0000_0000_0000_0000 (pagesize 1))") + "constant out of range") + +;; i32 (default pagesize) +(assert_invalid + (module + (memory 65537 (pagesize 65536))) + "memory size must be at most") + +;; i64 (default pagesize) +(assert_invalid + (module + (memory i64 0x1_0000_0000_0001 (pagesize 65536))) + "memory size must be at most")