Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mono / mini / TestHelpers.cs
1 using System;
2 using System.Threading;
3 using System.Reflection;
4
5 namespace MonoTests.Helpers {
6
7         public static class FinalizerHelpers {
8                 private static IntPtr aptr;
9
10                 private static unsafe void NoPinActionHelper (int depth, Action act)
11                 {
12                         // Avoid tail calls
13                         int* values = stackalloc int [20];
14                         aptr = new IntPtr (values);
15
16                         if (depth <= 0)
17                                 act ();
18                         else
19                                 NoPinActionHelper (depth - 1, act);
20                 }
21
22                 public static void PerformNoPinAction (Action act)
23                 {
24                         Thread thr = new Thread (() => NoPinActionHelper (1024, act));
25                         thr.Start ();
26                         thr.Join ();
27                 }
28         }
29
30         public static class OOMHelpers {
31                 public static void RunTest (string test)
32                 {
33                         Assembly asm = Assembly.Load (test);
34
35                         try {
36                                 // Support both (void) and (string[]) signatures
37                                 if (asm.EntryPoint.GetParameters ().Length == 1)
38                                         asm.EntryPoint.Invoke (null, new string[] { null });
39                                 else
40                                         asm.EntryPoint.Invoke (null, null);
41                         } catch (TargetInvocationException e) {
42                                 if (e.InnerException is OutOfMemoryException)
43                                         Console.WriteLine ("Catched oom");
44                                 else
45                                         throw;
46                         }
47                 }
48         }
49 }
50