1
2(* load the neccessary SML libraries *)
3Meta.load "../emit/regexEMCML";
4Meta.load "../lib/regex";
5Meta.load "../lib/regexRef";
6Meta.load "../lib/regexExe";
7Meta.load "../lib/regexExeM";
8Meta.load "../lib/regexExeMC";
9Meta.load "regexTest";
10
11
12
13(* performance test flag, set to true to run additional tests *)
14val runPerformanceTests = true;
15
16
17exception TestCaseException of (string * int);
18
19(* create a test template as a functor *)
20functor regexTestRunner (regexM:regex) =
21struct
22
23  fun test name tests =
24       let
25         open regexTest;
26
27         fun execTestCase (id, b, r, s) =
28                if b = (regexM.match r s) then ()
29                else raise TestCaseException (name, id);
30
31         val () = print ("Starting test of \"" ^ name ^ "\"\n");
32         val lasttimer = start_time();
33
34         val () = foldl (fn (t, ()) => execTestCase t) () tests;
35
36         val () = end_time lasttimer;
37         val () = print "Tests ended all successful.\n\n";
38
39       in
40         ()
41       end
42
43end;
44
45
46fun runTestFun testFun name tests =
47       (testFun name tests; true)
48       handle TestCaseException(_, id) => (
49         print ("Test with id '" ^ (Int.toString id) ^ "' failed.\n\n");
50         false
51       );
52
53
54
55
56(* create 4 instances using the functor *)
57structure regexTestRunner1 = regexTestRunner (regexRef);
58structure regexTestRunner2 = regexTestRunner (regexExe);
59structure regexTestRunner3 = regexTestRunner (regexExeM);
60structure regexTestRunner4 = regexTestRunner (regexExeMC);
61
62
63val () = print "\n\n\n";
64
65(* run the test template functor for all 4 instances *)
66local
67  val tests = regexTest.getTests();
68in
69  val res1 = runTestFun regexTestRunner1.test "IMPL_ref" tests;
70  val res2 = runTestFun regexTestRunner2.test "IMPL_exec" tests;
71  val res3 = runTestFun regexTestRunner3.test "IMPL_exec_marked" tests;
72  val res4 = runTestFun regexTestRunner4.test "IMPL_exec_mark_cache" tests;
73end
74
75(* throw an exception if at least one of the instances fails *)
76val () = if (res1 andalso res2 andalso res3 andalso res4) then ()
77         else OS.Process.terminate OS.Process.failure;
78
79
80
81
82
83
84(* additional performance tests *)
85val () = if runPerformanceTests then ()
86         else OS.Process.terminate OS.Process.success;
87
88val () = print "\n\n\n";
89val () = print "And now the performance tests.\n";
90
91
92
93
94val () = print "\n\n\n";
95local
96  val () = print "Loading random test data with 6..\n";
97  val tests = regexTest.getPerformanceTests "/dev/urandom" (6);
98in
99  val true = runTestFun regexTestRunner1.test "IMPL_ref_perf" tests;
100  val true = runTestFun regexTestRunner2.test "IMPL_exec_perf" tests;
101  val true = runTestFun regexTestRunner3.test "IMPL_exec_marked_perf" tests;
102  val true = runTestFun regexTestRunner4.test "IMPL_exec_mark_cache_perf" tests;
103end
104
105
106(* test/data/gen.py 10000000 12 > test/data/test12 *)
107val () = print "\n\n\n";
108local
109  val () = print "Loading test data with 100000..\n";
110  val tests = regexTest.getPerformanceTests "./test/data/test12" (100000);
111in
112  val true = runTestFun regexTestRunner1.test "IMPL_ref_perf" tests;
113(*  val true = runTestFun regexTestRunner2.test "IMPL_exec_perf" tests;*)
114  val true = runTestFun regexTestRunner3.test "IMPL_exec_marked_perf" tests;
115  val true = runTestFun regexTestRunner4.test "IMPL_exec_mark_cache_perf" tests;
116end
117
118
119(* test/data/gen.py 10000000 12 > test/data/test12 *)
120val () = print "\n\n\n";
121local
122  val () = print "Loading test data with 10000, regex size 600..\n";
123  val tests = regexTest.getPerformanceTestsRegexSize "./test/data/test12" (10000) (600);
124in
125  val true = runTestFun regexTestRunner1.test "IMPL_ref_perf" tests;
126(*  val true = runTestFun regexTestRunner2.test "IMPL_exec_perf" tests;*)
127  val true = runTestFun regexTestRunner3.test "IMPL_exec_marked_perf" tests;
128  val true = runTestFun regexTestRunner4.test "IMPL_exec_mark_cache_perf" tests;
129end
130
131
132(* test/data/gen.py 10000000 12 > test/data/test12 *)
133val () = print "\n\n\n";
134local
135  val () = print "Loading test data with 100000, regex size 10000..\n";
136  val tests = regexTest.getPerformanceTestsRegexSize "./test/data/test12" (100000) (10000);
137in
138(*  val true = runTestFun regexTestRunner1.test "IMPL_ref_perf" tests;*)
139(*  val true = runTestFun regexTestRunner2.test "IMPL_exec_perf" tests;*)
140  val true = runTestFun regexTestRunner3.test "IMPL_exec_marked_perf" tests;
141  val true = runTestFun regexTestRunner4.test "IMPL_exec_mark_cache_perf" tests;
142end
143
144
145
146