Skip to content

Commit

Permalink
Add command to test invalid modules
Browse files Browse the repository at this point in the history
  • Loading branch information
lukewagner committed Aug 25, 2015
1 parent 4021931 commit d321c0a
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ml-proto/runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def find_interpreter(path):
def rebuild_interpreter(path):
print("// building %s" % path)
sys.stdout.flush()
exitCode = subprocess.call(["ocamlbuild", "-libs", "bigarray", "main.native"], cwd=os.path.abspath("src"))
exitCode = subprocess.call(["ocamlbuild", "-libs", "bigarray, str", "main.native"], cwd=os.path.abspath("src"))
if (exitCode != 0):
raise Exception("ocamlbuild failed with exit code %i" % exitCode)
if not os.path.exists(path):
Expand Down
2 changes: 1 addition & 1 deletion ml-proto/src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ MODULES = \
NOMLI = flags types values ast sexpr main
PARSERS = parser
LEXERS = lexer
LIBRARIES = bigarray
LIBRARIES = bigarray str
SAMPLES =
TEXTS =

Expand Down
1 change: 1 addition & 0 deletions ml-proto/src/lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ rule token = parse
| "export" { EXPORT }
| "table" { TABLE }

| "invalid" { INVALID }
| "invoke" { INVOKE }
| "asserteq" { ASSERTEQ }

Expand Down
3 changes: 2 additions & 1 deletion ml-proto/src/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -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 INVOKE ASSERTEQ
%token INVALID INVOKE ASSERTEQ
%token EOF

%token<string> INT
Expand Down Expand Up @@ -308,6 +308,7 @@ modul :
cmd :
| modul { Define $1 @@ at() }
| LPAR INVALID modul TEXT RPAR { Invalid ($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
Expand Down
11 changes: 11 additions & 0 deletions ml-proto/src/script.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ open Source
type command = command' phrase
and command' =
| Define of Ast.modul
| Invalid of Ast.modul * string
| Invoke of string * Ast.expr list
| AssertEqInvoke of string * Ast.expr list * Ast.expr list

Expand All @@ -33,6 +34,15 @@ let run_command cmd =
trace "Initializing...";
current_module := Some (Eval.init m)

| Invalid (m, re) ->
trace "Checking invalid...";
(match try Check.check_module m; None with Error.Error (at, 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))

| Invoke (name, es) ->
trace "Invoking...";
let m = match !current_module with
Expand Down Expand Up @@ -65,6 +75,7 @@ let dry_command cmd =
| Define m ->
Check.check_module m;
if !Flags.print_sig then Print.print_module_sig m
| Invalid (m, re) -> ()
| Invoke _ -> ()
| AssertEqInvoke _ -> ()

Expand Down
1 change: 1 addition & 0 deletions ml-proto/src/script.mli
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
type command = command' Source.phrase
and command' =
| Define of Ast.modul
| Invalid of Ast.modul * string
| Invoke of string * Ast.expr list
| AssertEqInvoke of string * Ast.expr list * Ast.expr list

Expand Down
26 changes: 26 additions & 0 deletions ml-proto/test/memory.wasm
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
;; (c) 2015 Andreas Rossberg

(module (memory 0 0))
(module (memory 0 1))
(module (memory 4096 16777216))
(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")))
(invalid
(module (memory 1 0))
"initial memory size must be less than maximum")
(invalid
(module (memory 0 0 (segment 0 "a")))
"data segment does not fit memory")
(invalid
(module (memory 100 1000 (segment 0 "a") (segment 500 "b")))
"data segment does not fit memory")
(invalid
(module (memory 100 1000 (segment 0 "abc") (segment 0 "def")))
"data segment not disjoint and ordered")
(invalid
(module (memory 100 1000 (segment 3 "ab") (segment 0 "de")))
"data segment not disjoint and ordered")
(invalid
(module (memory 100 1000 (segment 0 "a") (segment 2 "b") (segment 1 "c")))
"data segment not disjoint and ordered")

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

Expand Down
2 changes: 1 addition & 1 deletion ml-proto/travis/build-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ rm -f lexer.ml
rm -f parser.ml
rm -f parser.mli

ocamlbuild -libs bigarray main.native
ocamlbuild -libs bigarray str main.native

This comment has been minimized.

Copy link
@rossberg

rossberg Aug 25, 2015

Member

Seems like this is not quite the right syntax, as the travis build keeps barfing on it.

make

cd ..
Expand Down

0 comments on commit d321c0a

Please sign in to comment.