Skip to content

Commit d321c0a

Browse files
committed
Add command to test invalid modules
1 parent 4021931 commit d321c0a

File tree

8 files changed

+44
-4
lines changed

8 files changed

+44
-4
lines changed

ml-proto/runtests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def find_interpreter(path):
5151
def rebuild_interpreter(path):
5252
print("// building %s" % path)
5353
sys.stdout.flush()
54-
exitCode = subprocess.call(["ocamlbuild", "-libs", "bigarray", "main.native"], cwd=os.path.abspath("src"))
54+
exitCode = subprocess.call(["ocamlbuild", "-libs", "bigarray, str", "main.native"], cwd=os.path.abspath("src"))
5555
if (exitCode != 0):
5656
raise Exception("ocamlbuild failed with exit code %i" % exitCode)
5757
if not os.path.exists(path):

ml-proto/src/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ MODULES = \
1212
NOMLI = flags types values ast sexpr main
1313
PARSERS = parser
1414
LEXERS = lexer
15-
LIBRARIES = bigarray
15+
LIBRARIES = bigarray str
1616
SAMPLES =
1717
TEXTS =
1818

ml-proto/src/lexer.mll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ rule token = parse
251251
| "export" { EXPORT }
252252
| "table" { TABLE }
253253

254+
| "invalid" { INVALID }
254255
| "invoke" { INVOKE }
255256
| "asserteq" { ASSERTEQ }
256257

ml-proto/src/parser.mly

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ let anon_label c = {c with labels = VarMap.map ((+) 1) c.labels}
9898
%token GETLOCAL SETLOCAL GETGLOBAL SETGLOBAL GETMEMORY SETMEMORY
9999
%token CONST UNARY BINARY COMPARE CONVERT
100100
%token FUNC PARAM RESULT LOCAL MODULE MEMORY SEGMENT GLOBAL IMPORT EXPORT TABLE
101-
%token INVOKE ASSERTEQ
101+
%token INVALID INVOKE ASSERTEQ
102102
%token EOF
103103

104104
%token<string> INT
@@ -308,6 +308,7 @@ modul :
308308
309309
cmd :
310310
| modul { Define $1 @@ at() }
311+
| LPAR INVALID modul TEXT RPAR { Invalid ($3, $4) @@ at() }
311312
| LPAR INVOKE TEXT expr_list RPAR
312313
{ Invoke ($3, $4 (c0 ())) @@ at() }
313314
| LPAR ASSERTEQ LPAR INVOKE TEXT expr_list RPAR expr_list RPAR

ml-proto/src/script.ml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ open Source
99
type command = command' phrase
1010
and command' =
1111
| Define of Ast.modul
12+
| Invalid of Ast.modul * string
1213
| Invoke of string * Ast.expr list
1314
| AssertEqInvoke of string * Ast.expr list * Ast.expr list
1415

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

37+
| Invalid (m, re) ->
38+
trace "Checking invalid...";
39+
(match try Check.check_module m; None with Error.Error (at, s) -> Some s with
40+
| None ->
41+
Error.error cmd.at "expected invalid module"
42+
| Some s ->
43+
if not (Str.string_match (Str.regexp re) s 0) then
44+
Error.error cmd.at ("validation failure \"" ^ s ^ "\" does not match: " ^ re))
45+
3646
| Invoke (name, es) ->
3747
trace "Invoking...";
3848
let m = match !current_module with
@@ -65,6 +75,7 @@ let dry_command cmd =
6575
| Define m ->
6676
Check.check_module m;
6777
if !Flags.print_sig then Print.print_module_sig m
78+
| Invalid (m, re) -> ()
6879
| Invoke _ -> ()
6980
| AssertEqInvoke _ -> ()
7081

ml-proto/src/script.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
type command = command' Source.phrase
66
and command' =
77
| Define of Ast.modul
8+
| Invalid of Ast.modul * string
89
| Invoke of string * Ast.expr list
910
| AssertEqInvoke of string * Ast.expr list * Ast.expr list
1011

ml-proto/test/memory.wasm

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
11
;; (c) 2015 Andreas Rossberg
22

3+
(module (memory 0 0))
4+
(module (memory 0 1))
5+
(module (memory 4096 16777216))
6+
(module (memory 0 0 (segment 0 "")))
7+
(module (memory 1 1 (segment 0 "a")))
8+
(module (memory 100 1000 (segment 0 "a") (segment 99 "b")))
9+
(module (memory 100 1000 (segment 0 "a") (segment 1 "b") (segment 2 "c")))
10+
(invalid
11+
(module (memory 1 0))
12+
"initial memory size must be less than maximum")
13+
(invalid
14+
(module (memory 0 0 (segment 0 "a")))
15+
"data segment does not fit memory")
16+
(invalid
17+
(module (memory 100 1000 (segment 0 "a") (segment 500 "b")))
18+
"data segment does not fit memory")
19+
(invalid
20+
(module (memory 100 1000 (segment 0 "abc") (segment 0 "def")))
21+
"data segment not disjoint and ordered")
22+
(invalid
23+
(module (memory 100 1000 (segment 3 "ab") (segment 0 "de")))
24+
"data segment not disjoint and ordered")
25+
(invalid
26+
(module (memory 100 1000 (segment 0 "a") (segment 2 "b") (segment 1 "c")))
27+
"data segment not disjoint and ordered")
28+
329
(module
430
(memory 1024 (segment 0 "ABC\a7D") (segment 20 "WASM"))
531

ml-proto/travis/build-test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ rm -f lexer.ml
1616
rm -f parser.ml
1717
rm -f parser.mli
1818

19-
ocamlbuild -libs bigarray main.native
19+
ocamlbuild -libs bigarray str main.native
2020
make
2121

2222
cd ..

0 commit comments

Comments
 (0)