-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from WebAssembly/add-spec-tests
Add spec tests for the custom-page-sizes proposal
- Loading branch information
Showing
3 changed files
with
224 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
test/core/custom-page-sizes/custom-page-sizes-invalid.wast
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
;; Page size that is not a power of two. | ||
(assert_malformed | ||
(module quote "(memory 0 (pagesize 3))") | ||
"invalid custom page size" | ||
) | ||
|
||
;; Power-of-two page sizes that are not 1 or 64KiB. | ||
(assert_invalid | ||
(module (memory 0 (pagesize 2))) | ||
"invalid custom page size" | ||
) | ||
(assert_invalid | ||
(module (memory 0 (pagesize 4))) | ||
"invalid custom page size" | ||
) | ||
(assert_invalid | ||
(module (memory 0 (pagesize 8))) | ||
"invalid custom page size" | ||
) | ||
(assert_invalid | ||
(module (memory 0 (pagesize 16))) | ||
"invalid custom page size" | ||
) | ||
(assert_invalid | ||
(module (memory 0 (pagesize 32))) | ||
"invalid custom page size" | ||
) | ||
(assert_invalid | ||
(module (memory 0 (pagesize 64))) | ||
"invalid custom page size" | ||
) | ||
(assert_invalid | ||
(module (memory 0 (pagesize 128))) | ||
"invalid custom page size" | ||
) | ||
(assert_invalid | ||
(module (memory 0 (pagesize 256))) | ||
"invalid custom page size" | ||
) | ||
(assert_invalid | ||
(module (memory 0 (pagesize 512))) | ||
"invalid custom page size" | ||
) | ||
(assert_invalid | ||
(module (memory 0 (pagesize 1024))) | ||
"invalid custom page size" | ||
) | ||
(assert_invalid | ||
(module (memory 0 (pagesize 2048))) | ||
"invalid custom page size" | ||
) | ||
(assert_invalid | ||
(module (memory 0 (pagesize 4096))) | ||
"invalid custom page size" | ||
) | ||
(assert_invalid | ||
(module (memory 0 (pagesize 8192))) | ||
"invalid custom page size" | ||
) | ||
(assert_invalid | ||
(module (memory 0 (pagesize 16384))) | ||
"invalid custom page size" | ||
) | ||
(assert_invalid | ||
(module (memory 0 (pagesize 32768))) | ||
"invalid custom page size" | ||
) | ||
|
||
;; Power-of-two page size that is larger than 64KiB. | ||
(assert_invalid | ||
(module (memory 0 (pagesize 0x20000))) | ||
"invalid custom page size" | ||
) | ||
|
||
;; Power of two page size that cannot fit in a u64 to exercise checks against | ||
;; shift overflow. | ||
(assert_malformed | ||
(module binary | ||
"\00asm" "\01\00\00\00" | ||
"\05\04\01" ;; Memory section | ||
|
||
;; memory 0 | ||
"\08" ;; flags w/ custom page size | ||
"\00" ;; minimum = 0 | ||
"\41" ;; pagesize = 2**65 | ||
) | ||
"invalid custom page size" | ||
) | ||
|
||
;; Importing a memory with the wrong page size. | ||
|
||
(module $m | ||
(memory (export "small-pages-memory") 0 (pagesize 1)) | ||
(memory (export "large-pages-memory") 0 (pagesize 65536)) | ||
) | ||
(register "m" $m) | ||
|
||
(assert_unlinkable | ||
(module | ||
(memory (import "m" "small-pages-memory") 0 (pagesize 65536)) | ||
) | ||
"memory types incompatible" | ||
) | ||
|
||
(assert_unlinkable | ||
(module | ||
(memory (import "m" "large-pages-memory") 0 (pagesize 1)) | ||
) | ||
"memory types incompatible" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
;; Check all the valid custom page sizes. | ||
(module (memory 1 (pagesize 1))) | ||
(module (memory 1 (pagesize 65536))) | ||
|
||
;; Check them all again with maximums specified. | ||
(module (memory 1 2 (pagesize 1))) | ||
(module (memory 1 2 (pagesize 65536))) | ||
|
||
;; Check the behavior of memories with page size 1. | ||
(module | ||
(memory 0 (pagesize 1)) | ||
(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)) | ||
) | ||
(func (export "store") (param i32 i32) | ||
(i32.store8 (local.get 0) (local.get 1)) | ||
) | ||
) | ||
|
||
(assert_return (invoke "size") (i32.const 0)) | ||
(assert_trap (invoke "load" (i32.const 0)) "out of bounds memory access") | ||
|
||
(assert_return (invoke "grow" (i32.const 65536)) (i32.const 0)) | ||
(assert_return (invoke "size") (i32.const 65536)) | ||
(assert_return (invoke "load" (i32.const 65535)) (i32.const 0)) | ||
(assert_return (invoke "store" (i32.const 65535) (i32.const 1))) | ||
(assert_return (invoke "load" (i32.const 65535)) (i32.const 1)) | ||
(assert_trap (invoke "load" (i32.const 65536)) "out of bounds memory access") | ||
|
||
(assert_return (invoke "grow" (i32.const 65536)) (i32.const 65536)) | ||
(assert_return (invoke "size") (i32.const 131072)) | ||
(assert_return (invoke "load" (i32.const 131071)) (i32.const 0)) | ||
(assert_return (invoke "store" (i32.const 131071) (i32.const 1))) | ||
(assert_return (invoke "load" (i32.const 131071)) (i32.const 1)) | ||
(assert_trap (invoke "load" (i32.const 131072)) "out of bounds memory access") | ||
|
||
;; Although smaller page sizes let us get to memories larger than 2**16 pages, | ||
;; we can't do that with the default page size, even if we explicitly state it | ||
;; as a custom page size. | ||
(module | ||
(memory 0 (pagesize 65536)) | ||
(func (export "size") (result i32) | ||
memory.size | ||
) | ||
(func (export "grow") (param i32) (result i32) | ||
(memory.grow (local.get 0)) | ||
) | ||
) | ||
(assert_return (invoke "size") (i32.const 0)) | ||
(assert_return (invoke "grow" (i32.const 65537)) (i32.const -1)) | ||
(assert_return (invoke "size") (i32.const 0)) | ||
|
||
;; Can copy between memories of different page sizes. | ||
(module | ||
(memory $small 10 (pagesize 1)) | ||
(memory $large 1 (pagesize 65536)) | ||
|
||
(data (memory $small) (i32.const 0) "\11\22\33\44") | ||
(data (memory $large) (i32.const 0) "\55\66\77\88") | ||
|
||
(func (export "copy-small-to-large") (param i32 i32 i32) | ||
(memory.copy $large $small (local.get 0) (local.get 1) (local.get 2)) | ||
) | ||
|
||
(func (export "copy-large-to-small") (param i32 i32 i32) | ||
(memory.copy $small $large (local.get 0) (local.get 1) (local.get 2)) | ||
) | ||
|
||
(func (export "load8-small") (param i32) (result i32) | ||
(i32.load8_u $small (local.get 0)) | ||
) | ||
|
||
(func (export "load8-large") (param i32) (result i32) | ||
(i32.load8_u $large (local.get 0)) | ||
) | ||
) | ||
|
||
(assert_return (invoke "copy-small-to-large" (i32.const 6) (i32.const 0) (i32.const 2))) | ||
(assert_return (invoke "load8-large" (i32.const 6)) (i32.const 0x11)) | ||
(assert_return (invoke "load8-large" (i32.const 7)) (i32.const 0x22)) | ||
|
||
(assert_return (invoke "copy-large-to-small" (i32.const 4) (i32.const 1) (i32.const 3))) | ||
(assert_return (invoke "load8-small" (i32.const 4)) (i32.const 0x66)) | ||
(assert_return (invoke "load8-small" (i32.const 5)) (i32.const 0x77)) | ||
(assert_return (invoke "load8-small" (i32.const 6)) (i32.const 0x88)) | ||
|
||
;; Can link together modules that export and import memories with custom page | ||
;; sizes. | ||
|
||
(module $m | ||
(memory (export "small-pages-memory") 0 (pagesize 1)) | ||
(memory (export "large-pages-memory") 0 (pagesize 65536)) | ||
) | ||
(register "m" $m) | ||
|
||
(module | ||
(memory (import "m" "small-pages-memory") 0 (pagesize 1)) | ||
) | ||
|
||
(module | ||
(memory (import "m" "large-pages-memory") 0 (pagesize 65536)) | ||
) |