Make sure x86 ATOMIC_CAS doesn't overwrite its own operands.
[mono-debugger.git] / mono / mini / TestDriver.cs
blob58f59b97d502b27336c296f64b44ef153002ca8a
1 using System;
2 using System.Reflection;
3 using System.Collections.Generic;
5 public class TestDriver {
7 static public int RunTests (Type type, string[] args) {
8 int failed = 0, ran = 0;
9 int result, expected, elen;
10 int i, j, iterations;
11 string name;
12 MethodInfo[] methods;
13 bool do_timings = false;
14 bool verbose = false;
15 int tms = 0;
16 DateTime start, end = DateTime.Now;
18 iterations = 1;
20 List<string> new_args = new List<string> ();
21 if (args != null && args.Length > 0) {
22 for (j = 0; j < args.Length; j++) {
23 bool found = false;
24 if (args [j] == "--time") {
25 do_timings = true;
26 found = true;
27 j ++;
28 } else if (args [j] == "--iter") {
29 iterations = Int32.Parse (args [j + 1]);
30 j += 2;
31 found = true;
32 } else if ((args [j] == "-v") || (args [j] == "--verbose")) {
33 verbose = true;
34 found = true;
35 } else {
36 new_args.Add (args [j]);
40 methods = type.GetMethods (BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.Static);
41 for (int iter = 0; iter < iterations; ++iter) {
42 for (i = 0; i < methods.Length; ++i) {
43 name = methods [i].Name;
44 if (!name.StartsWith ("test_"))
45 continue;
46 if (new_args.Count > 0) {
47 bool found = false;
48 for (j = 0; j < new_args.Count; j++) {
49 if (name.EndsWith (new_args [j])) {
50 found = true;
51 break;
54 if (!found)
55 continue;
57 for (j = 5; j < name.Length; ++j)
58 if (!Char.IsDigit (name [j]))
59 break;
60 if (verbose)
61 Console.WriteLine ("Running '{0}' ...", name);
62 expected = Int32.Parse (name.Substring (5, j - 5));
63 start = DateTime.Now;
64 result = (int)methods [i].Invoke (null, null);
65 if (do_timings) {
66 end = DateTime.Now;
67 long tdiff = end.Ticks - start.Ticks;
68 int mdiff = (int)tdiff/10000;
69 tms += mdiff;
70 Console.WriteLine ("{0} took {1} ms", name, mdiff);
72 ran++;
73 if (result != expected) {
74 failed++;
75 Console.WriteLine ("{0} failed: got {1}, expected {2}", name, result, expected);
79 if (do_timings) {
80 Console.WriteLine ("Total ms: {0}", tms);
82 Console.WriteLine ("Regression tests: {0} ran, {1} failed in {2}", ran, failed, type);
85 //Console.WriteLine ("Regression tests: {0} ran, {1} failed in [{2}]{3}", ran, failed, type.Assembly.GetName().Name, type);
86 return failed;
88 static public int RunTests (Type type) {
89 return RunTests (type, null);