diff --git a/ml-proto/README.md b/ml-proto/README.md index 3d9267620a..0fedba1f8d 100644 --- a/ml-proto/README.md +++ b/ml-proto/README.md @@ -235,7 +235,7 @@ cmd: ;; define, validate, and initialize module ( invoke * ) ;; invoke export and print result ( assert_eq (invoke * ) ) ;; assert expected results of invocation - ( assert_fault (invoke * ) ) ;; assert invocation faults with given failure string + ( assert_trap (invoke * ) ) ;; assert invocation traps with given failure string ( assert_invalid ) ;; assert invalid module with given failure string ``` diff --git a/ml-proto/src/host/lexer.mll b/ml-proto/src/host/lexer.mll index 28602a104b..68f9e3e5e5 100644 --- a/ml-proto/src/host/lexer.mll +++ b/ml-proto/src/host/lexer.mll @@ -249,7 +249,7 @@ rule token = parse | "assert_invalid" { ASSERTINVALID } | "assert_eq" { ASSERTEQ } - | "assert_fault" { ASSERTFAULT } + | "assert_trap" { ASSERTTRAP } | "invoke" { INVOKE } | name as s { VAR s } diff --git a/ml-proto/src/host/parser.mly b/ml-proto/src/host/parser.mly index d1fe224f17..20afa22434 100644 --- a/ml-proto/src/host/parser.mly +++ b/ml-proto/src/host/parser.mly @@ -99,7 +99,7 @@ let anon_label c = {c with labels = VarMap.map ((+) 1) c.labels} %token CONST UNARY BINARY COMPARE CONVERT %token FUNC PARAM RESULT LOCAL MODULE MEMORY SEGMENT IMPORT EXPORT TABLE %token PAGESIZE MEMORYSIZE RESIZEMEMORY -%token ASSERTINVALID ASSERTEQ ASSERTFAULT INVOKE +%token ASSERTINVALID ASSERTEQ ASSERTTRAP INVOKE %token EOF %token INT @@ -339,8 +339,8 @@ cmd : { Invoke ($3, $4 (c0 ())) @@ at() } | LPAR ASSERTEQ LPAR INVOKE TEXT expr_list RPAR expr RPAR { AssertEq ($5, $6 (c0 ()), $8 (c0 ())) @@ at() } - | LPAR ASSERTFAULT LPAR INVOKE TEXT expr_list RPAR TEXT RPAR - { AssertFault ($5, $6 (c0 ()), $8) @@ at() } + | LPAR ASSERTTRAP LPAR INVOKE TEXT expr_list RPAR TEXT RPAR + { AssertTrap ($5, $6 (c0 ()), $8) @@ at() } ; cmd_list : | /* empty */ { [] } diff --git a/ml-proto/src/host/script.ml b/ml-proto/src/host/script.ml index 3c94a69487..8e4e12be67 100644 --- a/ml-proto/src/host/script.ml +++ b/ml-proto/src/host/script.ml @@ -12,7 +12,7 @@ and command' = | AssertInvalid of Ast.modul * string | Invoke of string * Ast.expr list | AssertEq of string * Ast.expr list * Ast.expr - | AssertFault of string * Ast.expr list * string + | AssertTrap of string * Ast.expr list * string type script = command list @@ -83,14 +83,14 @@ let run_command cmd = Error.error cmd.at "assertion failed" end - | AssertFault (name, es, re) -> - trace "Assert fault invoking..."; + | AssertTrap (name, es, re) -> + trace "Assert trap invoking..."; let m = match !current_module with | Some m -> m | None -> Error.error cmd.at "no module defined to invoke" in let vs = eval_args es cmd.at in - assert_error (fun () -> Eval.invoke m name vs) "fault" re cmd.at + assert_error (fun () -> Eval.invoke m name vs) "trap" re cmd.at let dry_command cmd = match cmd.it with @@ -100,7 +100,7 @@ let dry_command cmd = | AssertInvalid _ -> () | Invoke _ -> () | AssertEq _ -> () - | AssertFault _ -> () + | AssertTrap _ -> () let run script = List.iter (if !Flags.dry then dry_command else run_command) script diff --git a/ml-proto/src/host/script.mli b/ml-proto/src/host/script.mli index 7967d23b8d..dd4e5ab181 100644 --- a/ml-proto/src/host/script.mli +++ b/ml-proto/src/host/script.mli @@ -8,7 +8,7 @@ and command' = | AssertInvalid of Ast.modul * string | Invoke of string * Ast.expr list | AssertEq of string * Ast.expr list * Ast.expr - | AssertFault of string * Ast.expr list * string + | AssertTrap of string * Ast.expr list * string type script = command list diff --git a/ml-proto/test/memory_fault.wasm b/ml-proto/test/memory_fault.wasm deleted file mode 100644 index 1c85b373b1..0000000000 --- a/ml-proto/test/memory_fault.wasm +++ /dev/null @@ -1,18 +0,0 @@ -(module - (memory 100) - - (export "store" $store) - (func $store (param $i i32) (param $v i32) (i32.store (get_local $i) (get_local $v))) - - (export "load" $load) - (func $load (param $i i32) (result i32) (i32.load (get_local $i))) -) - -(invoke "store" (i32.const 96) (i32.const 42)) -(assert_eq (invoke "load" (i32.const 96)) (i32.const 42)) -(assert_fault (invoke "store" (i32.const 97) (i32.const 13)) "runtime: out of bounds memory access") -(assert_fault (invoke "load" (i32.const 97)) "runtime: out of bounds memory access") -(assert_fault (invoke "store" (i32.const 98) (i32.const 13)) "runtime: out of bounds memory access") -(assert_fault (invoke "load" (i32.const 98)) "runtime: out of bounds memory access") -(assert_fault (invoke "store" (i32.const 99) (i32.const 13)) "runtime: out of bounds memory access") -(assert_fault (invoke "load" (i32.const 99)) "runtime: out of bounds memory access") diff --git a/ml-proto/test/memory_trap.wasm b/ml-proto/test/memory_trap.wasm new file mode 100644 index 0000000000..ca00f5a9dd --- /dev/null +++ b/ml-proto/test/memory_trap.wasm @@ -0,0 +1,18 @@ +(module + (memory 100) + + (export "store" $store) + (func $store (param $i i32) (param $v i32) (i32.store (get_local $i) (get_local $v))) + + (export "load" $load) + (func $load (param $i i32) (result i32) (i32.load (get_local $i))) +) + +(invoke "store" (i32.const 96) (i32.const 42)) +(assert_eq (invoke "load" (i32.const 96)) (i32.const 42)) +(assert_trap (invoke "store" (i32.const 97) (i32.const 13)) "runtime: out of bounds memory access") +(assert_trap (invoke "load" (i32.const 97)) "runtime: out of bounds memory access") +(assert_trap (invoke "store" (i32.const 98) (i32.const 13)) "runtime: out of bounds memory access") +(assert_trap (invoke "load" (i32.const 98)) "runtime: out of bounds memory access") +(assert_trap (invoke "store" (i32.const 99) (i32.const 13)) "runtime: out of bounds memory access") +(assert_trap (invoke "load" (i32.const 99)) "runtime: out of bounds memory access") diff --git a/ml-proto/test/resizing.wasm b/ml-proto/test/resizing.wasm index 7a350371f2..63e53cc041 100644 --- a/ml-proto/test/resizing.wasm +++ b/ml-proto/test/resizing.wasm @@ -17,8 +17,8 @@ (assert_eq (invoke "size") (i32.const 4096)) (invoke "store" (i32.const 0) (i32.const 42)) (assert_eq (invoke "load" (i32.const 0)) (i32.const 42)) -(assert_fault (invoke "store" (i32.const 4096) (i32.const 42)) "runtime: out of bounds memory access") -(assert_fault (invoke "load" (i32.const 4096)) "runtime: out of bounds memory access") +(assert_trap (invoke "store" (i32.const 4096) (i32.const 42)) "runtime: out of bounds memory access") +(assert_trap (invoke "load" (i32.const 4096)) "runtime: out of bounds memory access") (invoke "resize" (i32.const 8192)) (assert_eq (invoke "size") (i32.const 8192)) (assert_eq (invoke "load" (i32.const 0)) (i32.const 42)) @@ -28,5 +28,5 @@ (invoke "resize" (i32.const 4096)) (assert_eq (invoke "size") (i32.const 4096)) (assert_eq (invoke "load" (i32.const 0)) (i32.const 42)) -(assert_fault (invoke "store" (i32.const 4096) (i32.const 42)) "runtime: out of bounds memory access") -(assert_fault (invoke "load" (i32.const 4096)) "runtime: out of bounds memory access") +(assert_trap (invoke "store" (i32.const 4096) (i32.const 42)) "runtime: out of bounds memory access") +(assert_trap (invoke "load" (i32.const 4096)) "runtime: out of bounds memory access")