Skip to content

Use page aligned memory sizes in the tests. #209

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

Merged
merged 1 commit into from Mar 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 0 additions & 1 deletion ml-proto/TestingTodo.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Misc semantics:
- test that too-big linear memory initial allocation fails
- test that function addresses are monotonic indices, and not actual addresses.
- ~~test that non-pagesize `grow_memory` fails~~
- test that non-pagesize initial linear memory allocation fails
- test that one can clobber the entire contents of the linear memory without corrupting: call stack, local variables, program execution.

Operator semantics:
Expand Down
12 changes: 6 additions & 6 deletions ml-proto/spec/check.ml
Original file line number Diff line number Diff line change
Expand Up @@ -299,22 +299,22 @@ let check_start c start =
"start function must not return anything";
) start

let check_segment size prev_end seg =
let check_segment pages prev_end seg =
let seg_len = Int64.of_int (String.length seg.it.Memory.data) in
let seg_end = Int64.add seg.it.Memory.addr seg_len in
require (seg.it.Memory.addr >= prev_end) seg.at
"data segment not disjoint and ordered";
require (size >= seg_end) seg.at
require (Int64.mul pages Memory.page_size >= seg_end) seg.at
"data segment does not fit memory";
seg_end

let check_memory memory =
let mem = memory.it in
require (mem.initial <= mem.max) memory.at
"initial memory size must be less than maximum";
require (mem.max <= 4294967296L) memory.at
"linear memory size must be less or equal to 4GiB";
ignore (List.fold_left (check_segment mem.initial) Int64.zero mem.segments)
"initial memory pages must be less than or equal to the maximum";
require (mem.max <= 65535L) memory.at
"linear memory pages must be less or equal to 65535 (4GiB)";
ignore (List.fold_left (check_segment mem.initial) 0L mem.segments)

let check_module m =
let {memory; types; funcs; start; imports; exports; table} = m.it in
Expand Down
2 changes: 1 addition & 1 deletion ml-proto/spec/eval.ml
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ and eval_hostop c hostop vs at =
* Since we currently only support i32, just test that. *)
if I64.gt_u new_size (Int64.of_int32 Int32.max_int) then
Trap.error at "memory size exceeds implementation limit";
Memory.grow mem delta;
Memory.grow mem (Int64.div delta Memory.page_size);
Copy link
Member

Choose a reason for hiding this comment

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

Hm, I wonder if we should adjust the grow_memory operator as well. But probably for a separate patch.

Some (Int32 (Int64.to_int32 old_size))

| _, _ ->
Expand Down
8 changes: 4 additions & 4 deletions ml-proto/spec/memory.ml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ let host_index_of_int64 a n =


let create' n =
let sz = host_size_of_int64 n in
let sz = host_size_of_int64 (Int64.mul n page_size) in
let mem = Array1.create Int8_unsigned C_layout sz in
Array1.fill mem 0;
mem
Expand All @@ -68,9 +68,9 @@ let init mem segs =
let size mem =
int64_of_host_size (Array1.dim !mem)

let grow mem n =
let old_size = size mem in
let new_size = Int64.add old_size n in
let grow mem pages =
let old_size = Int64.div (size mem) page_size in
let new_size = Int64.add old_size pages in
if I64.gt_u old_size new_size then raise SizeOverflow else
let after = create' new_size in
let host_old_size = host_size_of_int64 old_size in
Expand Down
8 changes: 4 additions & 4 deletions ml-proto/test/address.wast
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(module
(memory 1024 (segment 0 "abcdefghijklmnopqrstuvwxyz"))
(memory 1 (segment 0 "abcdefghijklmnopqrstuvwxyz"))
(import $print "spectest" "print" (param i32))

(func $good (param $i i32)
Expand All @@ -26,9 +26,9 @@
)

(invoke "good" (i32.const 0))
(invoke "good" (i32.const 995))
(assert_trap (invoke "good" (i32.const 996)) "out of bounds memory access")
(invoke "good" (i32.const 65507))
(assert_trap (invoke "good" (i32.const 65508)) "out of bounds memory access")
(assert_trap (invoke "bad2" (i32.const 0)) "out of bounds memory access")
(assert_trap (invoke "bad2" (i32.const 1)) "out of bounds memory access")

(assert_invalid (module (memory 1024) (func $bad1 (param $i i32) (i32.load offset=4294967296 (get_local $i))) ) "offset too large")
(assert_invalid (module (memory 1) (func $bad1 (param $i i32) (i32.load offset=4294967296 (get_local $i))) ) "offset too large")
2 changes: 1 addition & 1 deletion ml-proto/test/endianness.wast
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(module
(memory 8)
(memory 1)

;; Stores an i16 value in little-endian-format
(func $i16_store_little (param $address i32) (param $value i32)
Expand Down
4 changes: 2 additions & 2 deletions ml-proto/test/float_memory.wast
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
;; stores don't do this.

(module
(memory 4 4)
(memory 1 1)

(func $store_i32 (param $x i32) (result i32)
(i32.store (i32.const 0) (get_local $x)))
Expand Down Expand Up @@ -33,7 +33,7 @@
(assert_return (invoke "load_i32") (i32.const 0x80000000))

(module
(memory 8 8)
(memory 1 1)

(func $store_i64 (param $x i64) (result i64)
(i64.store (i32.const 0) (get_local $x)))
Expand Down
2 changes: 1 addition & 1 deletion ml-proto/test/left-to-right.wast
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(module
(memory 12)
(memory 1)

(type $i32_T (func (param i32 i32) (result i32)))
(type $i64_T (func (param i64 i64) (result i32)))
Expand Down
18 changes: 9 additions & 9 deletions ml-proto/test/memory.wast
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
;; Test memory section structure
(module (memory 0 0))
(module (memory 0 1))
(module (memory 4096 16777216))
(module (memory 1 256))
(module (memory 0 0 (segment 0 "")))
(module (memory 1 1 (segment 0 "a")))
(module (memory 100 1000 (segment 0 "a") (segment 99 "b")))
(module (memory 100 1000 (segment 0 "a") (segment 1 "b") (segment 2 "c")))
(module (memory 1 2 (segment 0 "a") (segment 65535 "b")))
(module (memory 1 2 (segment 0 "a") (segment 1 "b") (segment 2 "c")))

(assert_invalid
(module (memory 1 0))
"initial memory size must be less than maximum"
"initial memory pages must be less than or equal to the maximum"
)
(assert_invalid
(module (memory 0 0 (segment 0 "a")))
"data segment does not fit memory"
)
(assert_invalid
(module (memory 100 1000 (segment 0 "a") (segment 500 "b")))
(module (memory 1 2 (segment 0 "a") (segment 98304 "b")))
"data segment does not fit memory"
)
(assert_invalid
(module (memory 100 1000 (segment 0 "abc") (segment 0 "def")))
(module (memory 1 2 (segment 0 "abc") (segment 0 "def")))
"data segment not disjoint and ordered"
)
(assert_invalid
(module (memory 100 1000 (segment 3 "ab") (segment 0 "de")))
(module (memory 1 2 (segment 3 "ab") (segment 0 "de")))
"data segment not disjoint and ordered"
)
(assert_invalid
(module (memory 100 1000 (segment 0 "a") (segment 2 "b") (segment 1 "c")))
(module (memory 1 2 (segment 0 "a") (segment 2 "b") (segment 1 "c")))
"data segment not disjoint and ordered"
)

Expand Down Expand Up @@ -60,7 +60,7 @@
)

(module
(memory 1024 (segment 0 "ABC\a7D") (segment 20 "WASM"))
(memory 1 (segment 0 "ABC\a7D") (segment 20 "WASM"))

;; Data section
(func $data (result i32)
Expand Down
2 changes: 1 addition & 1 deletion ml-proto/test/memory_redundancy.wast
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;; and to non-identical addresses.

(module
(memory 16 16)
(memory 1 1)

(export "zero_everything" $zero_everything)
(func $zero_everything
Expand Down
2 changes: 1 addition & 1 deletion ml-proto/test/memory_trap.wast
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(module
(memory 100)
(memory 1)

(export "store" $store)
(func $store (param $i i32) (param $v i32) (result i32) (i32.store (i32.add (memory_size) (get_local $i)) (get_local $v)))
Expand Down
4 changes: 2 additions & 2 deletions ml-proto/test/start.wast
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"start function must be nullary"
)
(module
(memory 1024 (segment 0 "A"))
(memory 1 (segment 0 "A"))
(func $inc
(i32.store8
(i32.const 0)
Expand Down Expand Up @@ -46,7 +46,7 @@
(assert_return (invoke "get") (i32.const 70))

(module
(memory 1024 (segment 0 "A"))
(memory 1 (segment 0 "A"))
(func $inc
(i32.store8
(i32.const 0)
Expand Down
2 changes: 1 addition & 1 deletion ml-proto/test/store_retval.wast
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(module
(memory 100)
(memory 1)

(import $print_i32 "spectest" "print" (param i32))
(import $print_i64 "spectest" "print" (param i64))
Expand Down
10 changes: 5 additions & 5 deletions ml-proto/test/traps.wast
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
(assert_trap (invoke "no_dce.i64.trunc_u_f64" (f64.const nan)) "invalid conversion to integer")

(module
(memory 8)
(memory 1)

(export "no_dce.i32.load" $no_dce.i32.load)
(func $no_dce.i32.load (param $i i32) (i32.load (get_local $i)))
Expand All @@ -84,7 +84,7 @@
(func $no_dce.f64.load (param $i i32) (f64.load (get_local $i)))
)

(assert_trap (invoke "no_dce.i32.load" (i32.const 8)) "out of bounds memory access")
(assert_trap (invoke "no_dce.i64.load" (i32.const 8)) "out of bounds memory access")
(assert_trap (invoke "no_dce.f32.load" (i32.const 8)) "out of bounds memory access")
(assert_trap (invoke "no_dce.f64.load" (i32.const 8)) "out of bounds memory access")
(assert_trap (invoke "no_dce.i32.load" (i32.const 65536)) "out of bounds memory access")
(assert_trap (invoke "no_dce.i64.load" (i32.const 65536)) "out of bounds memory access")
(assert_trap (invoke "no_dce.f32.load" (i32.const 65536)) "out of bounds memory access")
(assert_trap (invoke "no_dce.f64.load" (i32.const 65536)) "out of bounds memory access")