From 6fbe3b58bb14df5063e193d4754a91b5a1a04b01 Mon Sep 17 00:00:00 2001 From: Keith Winstein Date: Fri, 8 Nov 2024 10:40:03 -0500 Subject: [PATCH 1/3] [test] Add more custom-page-sizes tests --- .../custom-page-sizes-invalid.wast | 64 +++++++++++++++++++ .../custom-page-sizes/custom-page-sizes.wast | 30 +++++++++ 2 files changed, 94 insertions(+) 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..c2fda83 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))) @@ -108,3 +113,62 @@ ) "memory types incompatible" ) + +;; Maximum memory sizes. +;; These modules are valid, but instantiating them would allocate +;; a huge memory, so test with `assert_unlinkable` + a missing import. + +;; 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") 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)) From b198b97eaf1cbe22e0510b286e3780535868e4ed Mon Sep 17 00:00:00 2001 From: Keith Winstein <208955+keithw@users.noreply.github.com> Date: Fri, 8 Nov 2024 12:03:10 -0800 Subject: [PATCH 2/3] Update test/core/custom-page-sizes/custom-page-sizes-invalid.wast Co-authored-by: Nick Fitzgerald --- .../custom-page-sizes/custom-page-sizes-invalid.wast | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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 c2fda83..5d30457 100644 --- a/test/core/custom-page-sizes/custom-page-sizes-invalid.wast +++ b/test/core/custom-page-sizes/custom-page-sizes-invalid.wast @@ -115,8 +115,14 @@ ) ;; Maximum memory sizes. -;; These modules are valid, but instantiating them would allocate -;; a huge memory, so test with `assert_unlinkable` + a missing import. +;; +;; 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 From e8ce6ec851321ab431315664ef27add8486b7c5d Mon Sep 17 00:00:00 2001 From: Keith Winstein Date: Fri, 8 Nov 2024 15:07:07 -0500 Subject: [PATCH 3/3] Move "memory max" tests to new file --- .../custom-page-sizes-invalid.wast | 65 ------------------- test/core/custom-page-sizes/memory_max.wast | 64 ++++++++++++++++++ 2 files changed, 64 insertions(+), 65 deletions(-) create mode 100644 test/core/custom-page-sizes/memory_max.wast 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 5d30457..480d385 100644 --- a/test/core/custom-page-sizes/custom-page-sizes-invalid.wast +++ b/test/core/custom-page-sizes/custom-page-sizes-invalid.wast @@ -113,68 +113,3 @@ ) "memory types incompatible" ) - -;; 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") 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")