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] introduce script scopes around expensive memory tests #1699

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
20 changes: 16 additions & 4 deletions interpreter/script/js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ let of_assertion mods ass =
| AssertExhaustion (act, _) ->
of_assertion' mods act "assert_exhaustion" [] None

let of_command mods cmd =
let rec of_command mods cmd =
"\n// " ^ Filename.basename cmd.at.left.file ^
":" ^ string_of_int cmd.at.left.line ^ "\n" ^
match cmd.it with
Expand All @@ -605,8 +605,20 @@ let of_command mods cmd =
of_assertion' mods act "run" [] None ^ "\n"
| Assertion ass ->
of_assertion mods ass ^ "\n"
| Meta _ -> assert false
| Meta meta ->
of_meta meta

let of_script scr =
(if !Flags.harness then harness else "") ^
and of_meta cmd =
match cmd.it with
| Script (_, scr) ->
"\n// " ^ Filename.basename cmd.at.left.file ^
":" ^ string_of_int cmd.at.left.line ^ "\n" ^
"{" ^ of_script' scr ^ "}\n"
| _ -> assert false

and of_script' scr =
String.concat "" (List.map (of_command (modules ())) scr)

and of_script scr =
(if !Flags.harness then harness else "") ^
of_script' scr
3 changes: 2 additions & 1 deletion interpreter/script/run.ml
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ let rec run_command cmd =
and run_meta cmd =
match cmd.it with
| Script (x_opt, script) ->
quote := (Meta cmd @@ cmd.at) :: !quote;
run_quote_script script;
bind scripts x_opt (lookup_script None cmd.at)

Expand Down Expand Up @@ -589,7 +590,7 @@ and run_quote_script script =
quote := [];
(try run_script script with exn -> quote := save_quote; raise exn);
bind scripts None (List.rev !quote);
quote := !quote @ save_quote
quote := save_quote

let run_file file = input_file file run_script
let run_string string = input_string string run_script
Expand Down
11 changes: 8 additions & 3 deletions interpreter/text/arrange.ml
Original file line number Diff line number Diff line change
Expand Up @@ -765,12 +765,17 @@ let assertion mode ass =
| AssertExhaustion (act, re) ->
[Node ("assert_exhaustion", [action mode act; Atom (string re)])]

let command mode cmd =
let rec command mode cmd =
match cmd.it with
| Module (x_opt, def) -> [definition mode x_opt def]
| Register (n, x_opt) -> [Node ("register " ^ name n ^ var_opt x_opt, [])]
| Action act -> [action mode act]
| Assertion ass -> assertion mode ass
| Meta _ -> assert false
| Meta met -> meta mode met

let script mode scr = Lib.List.concat_map (command mode) scr
and meta mode cmd =
match cmd.it with
| Script (x_opt, scr) -> [Node ("script" ^ var_opt x_opt, script mode scr)]
| _ -> assert false

and script mode scr = Lib.List.concat_map (command mode) scr
66 changes: 66 additions & 0 deletions test/core/memory_copy.wast
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
;; DO NOT EDIT THIS FILE. CHANGE THE SOURCE AND REGENERATE.
;;

(script
(module
(memory (export "memory0") 1 1)
(data (i32.const 2) "\03\01\04\01")
Expand Down Expand Up @@ -44,7 +45,9 @@
(assert_return (invoke "load8_u" (i32.const 27)) (i32.const 0))
(assert_return (invoke "load8_u" (i32.const 28)) (i32.const 0))
(assert_return (invoke "load8_u" (i32.const 29)) (i32.const 0))
)

(script
(module
(memory (export "memory0") 1 1)
(data (i32.const 2) "\03\01\04\01")
Expand Down Expand Up @@ -86,7 +89,9 @@
(assert_return (invoke "load8_u" (i32.const 27)) (i32.const 0))
(assert_return (invoke "load8_u" (i32.const 28)) (i32.const 0))
(assert_return (invoke "load8_u" (i32.const 29)) (i32.const 0))
)

(script
(module
(memory (export "memory0") 1 1)
(data (i32.const 2) "\03\01\04\01")
Expand Down Expand Up @@ -128,7 +133,9 @@
(assert_return (invoke "load8_u" (i32.const 27)) (i32.const 0))
(assert_return (invoke "load8_u" (i32.const 28)) (i32.const 0))
(assert_return (invoke "load8_u" (i32.const 29)) (i32.const 0))
)

(script
(module
(memory (export "memory0") 1 1)
(data (i32.const 2) "\03\01\04\01")
Expand Down Expand Up @@ -170,7 +177,9 @@
(assert_return (invoke "load8_u" (i32.const 27)) (i32.const 0))
(assert_return (invoke "load8_u" (i32.const 28)) (i32.const 0))
(assert_return (invoke "load8_u" (i32.const 29)) (i32.const 0))
)

(script
(module
(memory (export "memory0") 1 1)
(data (i32.const 2) "\03\01\04\01")
Expand Down Expand Up @@ -212,7 +221,9 @@
(assert_return (invoke "load8_u" (i32.const 27)) (i32.const 0))
(assert_return (invoke "load8_u" (i32.const 28)) (i32.const 0))
(assert_return (invoke "load8_u" (i32.const 29)) (i32.const 0))
)

(script
(module
(memory (export "memory0") 1 1)
(data (i32.const 2) "\03\01\04\01")
Expand Down Expand Up @@ -254,7 +265,9 @@
(assert_return (invoke "load8_u" (i32.const 27)) (i32.const 1))
(assert_return (invoke "load8_u" (i32.const 28)) (i32.const 0))
(assert_return (invoke "load8_u" (i32.const 29)) (i32.const 0))
)

(script
(module
(memory (export "memory0") 1 1)
(data (i32.const 2) "\03\01\04\01")
Expand Down Expand Up @@ -296,7 +309,9 @@
(assert_return (invoke "load8_u" (i32.const 27)) (i32.const 0))
(assert_return (invoke "load8_u" (i32.const 28)) (i32.const 0))
(assert_return (invoke "load8_u" (i32.const 29)) (i32.const 0))
)

(script
(module
(memory (export "memory0") 1 1)
(data (i32.const 2) "\03\01\04\01")
Expand Down Expand Up @@ -338,7 +353,9 @@
(assert_return (invoke "load8_u" (i32.const 27)) (i32.const 0))
(assert_return (invoke "load8_u" (i32.const 28)) (i32.const 0))
(assert_return (invoke "load8_u" (i32.const 29)) (i32.const 0))
)

(script
(module
(memory (export "mem") 1 1 )
(data (i32.const 0) "\00\01\02\03\04\05\06\07\08\09\0a\0b\0c\0d\0e\0f\10\11\12\13")
Expand Down Expand Up @@ -699,7 +716,9 @@
(assert_return (invoke "load8_u" (i32.const 65092)) (i32.const 0))
(assert_return (invoke "load8_u" (i32.const 65291)) (i32.const 0))
(assert_return (invoke "load8_u" (i32.const 65490)) (i32.const 0))
)

(script
(module
(memory (export "mem") 1 1 )
(data (i32.const 0) "\00\01\02\03\04\05\06\07\08\09\0a\0b\0c\0d\0e\0f\10\11\12\13\14")
Expand Down Expand Up @@ -1061,7 +1080,9 @@
(assert_return (invoke "load8_u" (i32.const 65093)) (i32.const 0))
(assert_return (invoke "load8_u" (i32.const 65292)) (i32.const 0))
(assert_return (invoke "load8_u" (i32.const 65491)) (i32.const 0))
)

(script
(module
(memory (export "mem") 1 1 )
(data (i32.const 65516) "\00\01\02\03\04\05\06\07\08\09\0a\0b\0c\0d\0e\0f\10\11\12\13")
Expand Down Expand Up @@ -1422,7 +1443,9 @@
(assert_return (invoke "load8_u" (i32.const 65533)) (i32.const 17))
(assert_return (invoke "load8_u" (i32.const 65534)) (i32.const 18))
(assert_return (invoke "load8_u" (i32.const 65535)) (i32.const 19))
)

(script
(module
(memory (export "mem") 1 1 )
(data (i32.const 65515) "\00\01\02\03\04\05\06\07\08\09\0a\0b\0c\0d\0e\0f\10\11\12\13\14")
Expand Down Expand Up @@ -1784,7 +1807,9 @@
(assert_return (invoke "load8_u" (i32.const 65533)) (i32.const 18))
(assert_return (invoke "load8_u" (i32.const 65534)) (i32.const 19))
(assert_return (invoke "load8_u" (i32.const 65535)) (i32.const 20))
)

(script
(module
(memory (export "mem") 1 1 )
(data (i32.const 65486) "\00\01\02\03\04\05\06\07\08\09\0a\0b\0c\0d\0e\0f\10\11\12\13")
Expand Down Expand Up @@ -2145,7 +2170,9 @@
(assert_return (invoke "load8_u" (i32.const 65503)) (i32.const 17))
(assert_return (invoke "load8_u" (i32.const 65504)) (i32.const 18))
(assert_return (invoke "load8_u" (i32.const 65505)) (i32.const 19))
)

(script
(module
(memory (export "mem") 1 1 )
(data (i32.const 65516) "\00\01\02\03\04\05\06\07\08\09\0a\0b\0c\0d\0e\0f\10\11\12\13")
Expand Down Expand Up @@ -2506,7 +2533,9 @@
(assert_return (invoke "load8_u" (i32.const 65533)) (i32.const 17))
(assert_return (invoke "load8_u" (i32.const 65534)) (i32.const 18))
(assert_return (invoke "load8_u" (i32.const 65535)) (i32.const 19))
)

(script
(module
(memory (export "mem") 1 1 )
(data (i32.const 65506) "\00\01\02\03\04\05\06\07\08\09\0a\0b\0c\0d\0e\0f\10\11\12\13")
Expand Down Expand Up @@ -2867,7 +2896,9 @@
(assert_return (invoke "load8_u" (i32.const 65523)) (i32.const 17))
(assert_return (invoke "load8_u" (i32.const 65524)) (i32.const 18))
(assert_return (invoke "load8_u" (i32.const 65525)) (i32.const 19))
)

(script
(module
(memory (export "mem") 1 1 )
(data (i32.const 65516) "\00\01\02\03\04\05\06\07\08\09\0a\0b\0c\0d\0e\0f\10\11\12\13")
Expand Down Expand Up @@ -3228,7 +3259,9 @@
(assert_return (invoke "load8_u" (i32.const 65533)) (i32.const 17))
(assert_return (invoke "load8_u" (i32.const 65534)) (i32.const 18))
(assert_return (invoke "load8_u" (i32.const 65535)) (i32.const 19))
)

(script
(module
(memory (export "mem") 1 1 )
(data (i32.const 65516) "\00\01\02\03\04\05\06\07\08\09\0a\0b\0c\0d\0e\0f\10\11\12\13")
Expand Down Expand Up @@ -3589,7 +3622,9 @@
(assert_return (invoke "load8_u" (i32.const 65533)) (i32.const 17))
(assert_return (invoke "load8_u" (i32.const 65534)) (i32.const 18))
(assert_return (invoke "load8_u" (i32.const 65535)) (i32.const 19))
)

(script
(module
(memory (export "mem") 1 )
(data (i32.const 65516) "\00\01\02\03\04\05\06\07\08\09\0a\0b\0c\0d\0e\0f\10\11\12\13")
Expand Down Expand Up @@ -3950,7 +3985,9 @@
(assert_return (invoke "load8_u" (i32.const 65533)) (i32.const 17))
(assert_return (invoke "load8_u" (i32.const 65534)) (i32.const 18))
(assert_return (invoke "load8_u" (i32.const 65535)) (i32.const 19))
)

(script
(module
(memory (export "mem") 1 1 )
(data (i32.const 61440) "\00\01\02\03\04\05\06\07\08\09\0a\0b\0c\0d\0e\0f\10\11\12\13")
Expand Down Expand Up @@ -4311,6 +4348,7 @@
(assert_return (invoke "load8_u" (i32.const 65092)) (i32.const 0))
(assert_return (invoke "load8_u" (i32.const 65291)) (i32.const 0))
(assert_return (invoke "load8_u" (i32.const 65490)) (i32.const 0))
)

(assert_invalid
(module
Expand Down Expand Up @@ -4760,6 +4798,7 @@
"type mismatch")


(script
(module
(memory 1 1)
(func (export "test")
Expand All @@ -4785,7 +4824,9 @@
(i32.const -1))
(assert_return (invoke "checkRange" (i32.const 20) (i32.const 65536) (i32.const 0))
(i32.const -1))
)

(script
(module
(memory 1 1)
(func (export "test")
Expand All @@ -4811,31 +4852,41 @@
(i32.const -1))
(assert_return (invoke "checkRange" (i32.const 21) (i32.const 65536) (i32.const 0))
(i32.const -1))
)

(script
(module
(memory 1 1)
(func (export "test")
(memory.copy (i32.const 0xFF00) (i32.const 0x8000) (i32.const 257))))
(assert_trap (invoke "test") "out of bounds memory access")
)

(script
(module
(memory 1 1)
(func (export "test")
(memory.copy (i32.const 0xFFFFFF00) (i32.const 0x4000) (i32.const 257))))
(assert_trap (invoke "test") "out of bounds memory access")
)

(script
(module
(memory 1 1)
(func (export "test")
(memory.copy (i32.const 0x8000) (i32.const 0xFF00) (i32.const 257))))
(assert_trap (invoke "test") "out of bounds memory access")
)

(script
(module
(memory 1 1)
(func (export "test")
(memory.copy (i32.const 0x4000) (i32.const 0xFFFFFF00) (i32.const 257))))
(assert_trap (invoke "test") "out of bounds memory access")
)

(script
(module
(memory 1 1)
(func (export "test")
Expand All @@ -4860,42 +4911,56 @@
(i32.const -1))
(assert_return (invoke "checkRange" (i32.const 32768) (i32.const 65536) (i32.const 170))
(i32.const -1))
)
(script
(module
(memory 1 1)
(func (export "test")
(memory.copy (i32.const 0x10000) (i32.const 0x7000) (i32.const 0))))
(invoke "test")
)

(script
(module
(memory 1 1)
(func (export "test")
(memory.copy (i32.const 0x20000) (i32.const 0x7000) (i32.const 0))))
(assert_trap (invoke "test") "out of bounds memory access")
)

(script
(module
(memory 1 1)
(func (export "test")
(memory.copy (i32.const 0x9000) (i32.const 0x10000) (i32.const 0))))
(invoke "test")
)

(script
(module
(memory 1 1)
(func (export "test")
(memory.copy (i32.const 0x9000) (i32.const 0x20000) (i32.const 0))))
(assert_trap (invoke "test") "out of bounds memory access")
)

(script
(module
(memory 1 1)
(func (export "test")
(memory.copy (i32.const 0x10000) (i32.const 0x10000) (i32.const 0))))
(invoke "test")
)

(script
(module
(memory 1 1)
(func (export "test")
(memory.copy (i32.const 0x20000) (i32.const 0x20000) (i32.const 0))))
(assert_trap (invoke "test") "out of bounds memory access")
)

(script
(module
(memory 1 1)
(func (export "test")
Expand Down Expand Up @@ -5576,3 +5641,4 @@
(i32.const -1))
(assert_return (invoke "checkRange" (i32.const 64834) (i32.const 65536) (i32.const 0))
(i32.const -1))
)
Loading
Loading