diff --git a/ml-proto/README.md b/ml-proto/README.md index 4aa5fd1514..53186d53ee 100644 --- a/ml-proto/README.md +++ b/ml-proto/README.md @@ -233,6 +233,7 @@ cmd: ;; define, validate, and initialize module ( invoke * ) ;; invoke export and print result ( asserteq (invoke * ) * ) ;; assert expected results of invocation + ( assertinvalid ) ;; assert invalid module with given failure string ``` Invocation is only possible after a module has been defined. diff --git a/ml-proto/src/lexer.mll b/ml-proto/src/lexer.mll index dfe7c318ef..accdf425be 100644 --- a/ml-proto/src/lexer.mll +++ b/ml-proto/src/lexer.mll @@ -251,7 +251,7 @@ rule token = parse | "export" { EXPORT } | "table" { TABLE } - | "invalid" { INVALID } + | "assertinvalid" { ASSERTINVALID } | "invoke" { INVOKE } | "asserteq" { ASSERTEQ } diff --git a/ml-proto/src/parser.mly b/ml-proto/src/parser.mly index 038ed63ece..2b6e5f5db4 100644 --- a/ml-proto/src/parser.mly +++ b/ml-proto/src/parser.mly @@ -98,7 +98,7 @@ let anon_label c = {c with labels = VarMap.map ((+) 1) c.labels} %token GETLOCAL SETLOCAL GETGLOBAL SETGLOBAL GETMEMORY SETMEMORY %token CONST UNARY BINARY COMPARE CONVERT %token FUNC PARAM RESULT LOCAL MODULE MEMORY SEGMENT GLOBAL IMPORT EXPORT TABLE -%token INVALID INVOKE ASSERTEQ +%token ASSERTINVALID INVOKE ASSERTEQ %token EOF %token INT @@ -308,11 +308,11 @@ modul : cmd : | modul { Define $1 @@ at() } - | LPAR INVALID modul TEXT RPAR { Invalid ($3, $4) @@ at() } + | LPAR ASSERTINVALID modul TEXT RPAR { AssertInvalid ($3, $4) @@ at() } | LPAR INVOKE TEXT expr_list RPAR { Invoke ($3, $4 (c0 ())) @@ at() } | LPAR ASSERTEQ LPAR INVOKE TEXT expr_list RPAR expr_list RPAR - { AssertEqInvoke ($5, $6 (c0 ()), $8 (c0 ())) @@ at() } + { AssertEq ($5, $6 (c0 ()), $8 (c0 ())) @@ at() } ; cmd_list : | /* empty */ { [] } diff --git a/ml-proto/src/script.ml b/ml-proto/src/script.ml index 5982a601df..92bcc602f7 100644 --- a/ml-proto/src/script.ml +++ b/ml-proto/src/script.ml @@ -9,9 +9,9 @@ open Source type command = command' phrase and command' = | Define of Ast.modul - | Invalid of Ast.modul * string + | AssertInvalid of Ast.modul * string | Invoke of string * Ast.expr list - | AssertEqInvoke of string * Ast.expr list * Ast.expr list + | AssertEq of string * Ast.expr list * Ast.expr list type script = command list @@ -34,14 +34,15 @@ let run_command cmd = trace "Initializing..."; current_module := Some (Eval.init m) - | Invalid (m, re) -> + | AssertInvalid (m, re) -> trace "Checking invalid..."; - (match try Check.check_module m; None with Error.Error (at, s) -> Some s with + (match try Check.check_module m; None with Error.Error (_, s) -> Some s with | None -> Error.error cmd.at "expected invalid module" | Some s -> if not (Str.string_match (Str.regexp re) s 0) then - Error.error cmd.at ("validation failure \"" ^ s ^ "\" does not match: " ^ re)) + Error.error cmd.at + ("validation failure \"" ^ s ^ "\" does not match: \"" ^ re ^ "\"")) | Invoke (name, es) -> trace "Invoking..."; @@ -53,7 +54,7 @@ let run_command cmd = let vs' = Eval.invoke m name vs in if vs' <> [] then Print.print_values vs' - | AssertEqInvoke (name, arg_es, expect_es) -> + | AssertEq (name, arg_es, expect_es) -> trace "Assert invoking..."; let m = match !current_module with | Some m -> m @@ -75,9 +76,9 @@ let dry_command cmd = | Define m -> Check.check_module m; if !Flags.print_sig then Print.print_module_sig m - | Invalid (m, re) -> () + | AssertInvalid _ -> () | Invoke _ -> () - | AssertEqInvoke _ -> () + | AssertEq _ -> () let run script = List.iter (if !Flags.dry then dry_command else run_command) script diff --git a/ml-proto/src/script.mli b/ml-proto/src/script.mli index ad90a649f2..e4ada117f7 100644 --- a/ml-proto/src/script.mli +++ b/ml-proto/src/script.mli @@ -5,9 +5,9 @@ type command = command' Source.phrase and command' = | Define of Ast.modul - | Invalid of Ast.modul * string + | AssertInvalid of Ast.modul * string | Invoke of string * Ast.expr list - | AssertEqInvoke of string * Ast.expr list * Ast.expr list + | AssertEq of string * Ast.expr list * Ast.expr list type script = command list diff --git a/ml-proto/test/exports.wasm b/ml-proto/test/exports.wasm index 620fb01008..c3eac40933 100644 --- a/ml-proto/test/exports.wasm +++ b/ml-proto/test/exports.wasm @@ -1,13 +1,13 @@ (module (func (const.i32 1)) (export "a" 0)) (module (func (const.i32 1)) (export "a" 0) (export "b" 0)) (module (func (const.i32 1)) (func (const.i32 2)) (export "a" 0) (export "b" 1)) -(invalid +(assertinvalid (module (func (const.i32 1)) (export "a" 1)) "unknown function 1") -(invalid +(assertinvalid (module (func (const.i32 1)) (func (const.i32 2)) (export "a" 0) (export "a" 1)) "duplicate export name") -(invalid +(assertinvalid (module (func (const.i32 1)) (export "a" 0) (export "a" 0)) "duplicate export name") diff --git a/ml-proto/test/memory.wasm b/ml-proto/test/memory.wasm index 73954c75f1..4c07f79b3b 100644 --- a/ml-proto/test/memory.wasm +++ b/ml-proto/test/memory.wasm @@ -7,22 +7,22 @@ (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"))) -(invalid +(assertinvalid (module (memory 1 0)) "initial memory size must be less than maximum") -(invalid +(assertinvalid (module (memory 0 0 (segment 0 "a"))) "data segment does not fit memory") -(invalid +(assertinvalid (module (memory 100 1000 (segment 0 "a") (segment 500 "b"))) "data segment does not fit memory") -(invalid +(assertinvalid (module (memory 100 1000 (segment 0 "abc") (segment 0 "def"))) "data segment not disjoint and ordered") -(invalid +(assertinvalid (module (memory 100 1000 (segment 3 "ab") (segment 0 "de"))) "data segment not disjoint and ordered") -(invalid +(assertinvalid (module (memory 100 1000 (segment 0 "a") (segment 2 "b") (segment 1 "c"))) "data segment not disjoint and ordered")