2007-07-03 Roderigo Kumpera <rkumpera@novell.com>
[mono.git] / mono / tests / verifier / TestRunner.cs
1 using System;
2 using System.IO;
3 using System.Reflection;
4
5 public class TestRunner : MarshalByRefObject
6 {
7         public void RunTest (String test) {
8                 Console.Write (test);
9
10                 Assembly a = Assembly.LoadFrom (test);
11
12                 MethodInfo mi = a.EntryPoint;
13
14                 if (mi == null) {
15                         Console.WriteLine (" FAILED (no entry point found)");
16                         return;
17                 }
18
19                 try {
20                         mi.Invoke (null, null);
21                         Console.WriteLine (" FAILED (silent success)");
22                 }
23                 catch (TargetInvocationException ex) {
24                         if (ex.InnerException is InvalidProgramException)
25                                 Console.WriteLine (" OK");
26                         else
27                                 Console.WriteLine (" FAILED -> " + ex.InnerException);
28                 }
29                 catch (Exception ex) {
30                         Console.WriteLine (" FAILED -> " + ex);
31                 }
32         }
33
34         public static void Main (String[] args) {
35                 if (args.Length < 1) {
36                         Console.WriteLine ("Usage: TestRunner <file pattern>");
37                         Environment.Exit (1);
38                         return;
39                 }
40
41                 String[] tests = Directory.GetFiles (".", args [0]);
42
43                 AppDomain domain = null;
44                 TestRunner runner = null;
45
46                 int count = 0;
47                 foreach (String test in tests) {
48                         /* 
49                          * Run each bunch of tests in a new appdomain, then unload it to 
50                          * avoid too many open files exceptions.
51                          */
52                         if ((count % 500) == 0) {
53                                 if (domain != null)
54                                         AppDomain.Unload (domain);
55                                 domain = AppDomain.CreateDomain ("domain-" + count);
56
57                                 runner = (TestRunner)domain.CreateInstanceAndUnwrap (typeof (TestRunner).Assembly.FullName, typeof (TestRunner).FullName);
58                         }
59
60                         runner.RunTest (test);
61
62                         count ++;
63                 }
64         }
65 }