Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[test] Add more custom-page-sizes tests #31

Merged
merged 3 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions test/core/custom-page-sizes/custom-page-sizes-invalid.wast
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down Expand Up @@ -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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making a suggested rewording to this comment because it took me a little bit to understand the subtleties of this set up.

Suggested change
;; Maximum memory sizes.
;; These modules are valid, but instantiating them would allocate
;; a huge memory, so test with `assert_unlinkable` + a missing import.
;; 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).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, since these modules are actually valid, it may make sense to remove these tests from this custom-page-sizes-invalid.wast file and move them to the custom-page-sizes.wast file (or alternatively to their own dedicated max-sized-memory.wast file).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sgtm -- done.


;; 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")
30 changes: 30 additions & 0 deletions test/core/custom-page-sizes/custom-page-sizes.wast
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Loading