Skip to content

Commit

Permalink
[spec/interpreter/test] Land bulk instructions & reference types prop…
Browse files Browse the repository at this point in the history
…osals (WebAssembly#1287)
  • Loading branch information
gumb0 committed Apr 20, 2021
1 parent 5ed9d56 commit 2039b65
Show file tree
Hide file tree
Showing 7 changed files with 252 additions and 170 deletions.
58 changes: 48 additions & 10 deletions test/core/binary.wast
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,44 @@
(assert_malformed (module binary "\00asm" "\01\00\00\00" "\ff\00\01\00") "malformed section id")


(module binary
"\00asm" "\01\00\00\00"
"\05\03\01" ;; Memory section with 1 entry
"\00\00" ;; no max, minimum 0
"\0b\06\01" ;; Data section with 1 entry
"\00" ;; Memory index 0
"\41\00\0b\00" ;; (i32.const 0) with contents ""
)

(module binary
"\00asm" "\01\00\00\00"
"\04\04\01" ;; Table section with 1 entry
"\70\00\00" ;; no max, minimum 0, funcref
"\09\06\01" ;; Element section with 1 entry
"\00" ;; Table index 0
"\41\00\0b\00" ;; (i32.const 0) with no elements
)

;; Data segment memory index can have non-minimal length
(module binary
"\00asm" "\01\00\00\00"
"\05\03\01" ;; Memory section with 1 entry
"\00\00" ;; no max, minimum 0
"\0b\07\01" ;; Data section with 1 entry
"\80\00" ;; Memory index 0, encoded with 2 bytes
"\41\00\0b\00" ;; (i32.const 0) with contents ""
)

;; Element segment table index can have non-minimal length
(module binary
"\00asm" "\01\00\00\00"
"\04\04\01" ;; Table section with 1 entry
"\70\00\00" ;; no max, minimum 0, funcref
"\09\09\01" ;; Element section with 1 entry
"\02\80\00" ;; Table index 0, encoded with 2 bytes
"\41\00\0b\00\00" ;; (i32.const 0) with no elements
)

;; Type section with signed LEB128 encoded type
(assert_malformed
(module binary
Expand Down Expand Up @@ -176,7 +214,7 @@
"\1a" ;; drop
"\0b" ;; end
)
"zero flag expected"
"zero byte expected"
)

;; memory.grow reserved byte should not be a "long" LEB128 zero.
Expand All @@ -196,7 +234,7 @@
"\1a" ;; drop
"\0b" ;; end
)
"zero flag expected"
"zero byte expected"
)

;; Same as above for 3, 4, and 5-byte zero encodings.
Expand All @@ -216,7 +254,7 @@
"\1a" ;; drop
"\0b" ;; end
)
"zero flag expected"
"zero byte expected"
)

(assert_malformed
Expand All @@ -235,7 +273,7 @@
"\1a" ;; drop
"\0b" ;; end
)
"zero flag expected"
"zero byte expected"
)

(assert_malformed
Expand All @@ -254,7 +292,7 @@
"\1a" ;; drop
"\0b" ;; end
)
"zero flag expected"
"zero byte expected"
)

;; memory.size reserved byte equal to zero.
Expand All @@ -273,7 +311,7 @@
"\1a" ;; drop
"\0b" ;; end
)
"zero flag expected"
"zero byte expected"
)

;; memory.size reserved byte should not be a "long" LEB128 zero.
Expand All @@ -292,7 +330,7 @@
"\1a" ;; drop
"\0b" ;; end
)
"zero flag expected"
"zero byte expected"
)

;; Same as above for 3, 4, and 5-byte zero encodings.
Expand All @@ -311,7 +349,7 @@
"\1a" ;; drop
"\0b" ;; end
)
"zero flag expected"
"zero byte expected"
)

(assert_malformed
Expand All @@ -329,7 +367,7 @@
"\1a" ;; drop
"\0b" ;; end
)
"zero flag expected"
"zero byte expected"
)

(assert_malformed
Expand All @@ -347,7 +385,7 @@
"\1a" ;; drop
"\0b" ;; end
)
"zero flag expected"
"zero byte expected"
)

;; Local number is unsigned 32 bit
Expand Down
88 changes: 49 additions & 39 deletions test/core/data.wast
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,26 @@
(data (i32.const 1) "a" "" "bcd")
(data (offset (i32.const 0)))
(data (offset (i32.const 0)) "" "a" "bc" "")
(data 0 (i32.const 0))
(data 0x0 (i32.const 1) "a" "" "bcd")
(data 0x000 (offset (i32.const 0)))
(data 0 (offset (i32.const 0)) "" "a" "bc" "")
(data $m (i32.const 0))
(data $m (i32.const 1) "a" "" "bcd")
(data $m (offset (i32.const 0)))
(data $m (offset (i32.const 0)) "" "a" "bc" "")
(data (memory 0) (i32.const 0))
(data (memory 0x0) (i32.const 1) "a" "" "bcd")
(data (memory 0x000) (offset (i32.const 0)))
(data (memory 0) (offset (i32.const 0)) "" "a" "bc" "")
(data (memory $m) (i32.const 0))
(data (memory $m) (i32.const 1) "a" "" "bcd")
(data (memory $m) (offset (i32.const 0)))
(data (memory $m) (offset (i32.const 0)) "" "a" "bc" "")
(data $d1 (i32.const 0))
(data $d2 (i32.const 1) "a" "" "bcd")
(data $d3 (offset (i32.const 0)))
(data $d4 (offset (i32.const 0)) "" "a" "bc" "")
(data $d5 (memory 0) (i32.const 0))
(data $d6 (memory 0x0) (i32.const 1) "a" "" "bcd")
(data $d7 (memory 0x000) (offset (i32.const 0)))
(data $d8 (memory 0) (offset (i32.const 0)) "" "a" "bc" "")
(data $d9 (memory $m) (i32.const 0))
(data $d10 (memory $m) (i32.const 1) "a" "" "bcd")
(data $d11 (memory $m) (offset (i32.const 0)))
(data $d12 (memory $m) (offset (i32.const 0)) "" "a" "bc" "")
)

;; Basic use
Expand Down Expand Up @@ -158,44 +170,42 @@

;; Invalid bounds for data

(assert_unlinkable
(assert_trap
(module
(memory 0)
(data (i32.const 0) "a")
)
"data segment does not fit"
"out of bounds memory access"
)

(assert_unlinkable
(assert_trap
(module
(memory 0 0)
(data (i32.const 0) "a")
)
"data segment does not fit"
"out of bounds memory access"
)

(assert_unlinkable
(assert_trap
(module
(memory 0 1)
(data (i32.const 0) "a")
)
"data segment does not fit"
"out of bounds memory access"
)

(assert_unlinkable
(assert_trap
(module
(memory 0)
(data (i32.const 1))
)
"data segment does not fit"
"out of bounds memory access"
)

(assert_unlinkable
(assert_trap
(module
(memory 0 1)
(data (i32.const 1))
)
"data segment does not fit"
"out of bounds memory access"
)

;; This seems to cause a time-out on Travis.
Expand All @@ -204,77 +214,77 @@
(memory 0x10000)
(data (i32.const 0xffffffff) "ab")
)
"" ;; either out of memory or segment does not fit
"" ;; either out of memory or out of bounds
;)

(assert_unlinkable
(assert_trap
(module
(global (import "spectest" "global_i32") i32)
(memory 0)
(data (global.get 0) "a")
)
"data segment does not fit"
"out of bounds memory access"
)

(assert_unlinkable
(assert_trap
(module
(memory 1 2)
(data (i32.const 0x1_0000) "a")
)
"data segment does not fit"
"out of bounds memory access"
)
(assert_unlinkable
(assert_trap
(module
(import "spectest" "memory" (memory 1))
(data (i32.const 0x1_0000) "a")
)
"data segment does not fit"
"out of bounds memory access"
)

(assert_unlinkable
(assert_trap
(module
(memory 2)
(data (i32.const 0x2_0000) "a")
)
"data segment does not fit"
"out of bounds memory access"
)

(assert_unlinkable
(assert_trap
(module
(memory 2 3)
(data (i32.const 0x2_0000) "a")
)
"data segment does not fit"
"out of bounds memory access"
)

(assert_unlinkable
(assert_trap
(module
(memory 1)
(data (i32.const -1) "a")
)
"data segment does not fit"
"out of bounds memory access"
)
(assert_unlinkable
(assert_trap
(module
(import "spectest" "memory" (memory 1))
(data (i32.const -1) "a")
)
"data segment does not fit"
"out of bounds memory access"
)

(assert_unlinkable
(assert_trap
(module
(memory 2)
(data (i32.const -100) "a")
)
"data segment does not fit"
"out of bounds memory access"
)
(assert_unlinkable
(assert_trap
(module
(import "spectest" "memory" (memory 1))
(data (i32.const -100) "a")
)
"data segment does not fit"
"out of bounds memory access"
)

;; Data without memory
Expand Down
Loading

0 comments on commit 2039b65

Please sign in to comment.