Initial set of Ward sgen annotations (#5705)
[mono.git] / mono / tests / gc-altstack.cs
index 89eb310c73ee7a78a49b73a8606027fa1537f032..4b3f431467fad705d9afb10b9e7370f6387efea6 100644 (file)
@@ -1,38 +1,64 @@
 using System;
 using System.Threading;
-using System.Collections;
-
-class T {
+using System.Linq;
 
+public class Tests
+{
        static bool finished = false;
 
-       static void segv () {
-               while (true) {
-                       if (finished)
-                               break;
+       static void fault () {
+               while (!finished) {
+                       object o = null;
                        try {
-                               object o = null;
                                o.ToString ();
-                       } catch (NullReferenceException) {
+                       } catch {
                        }
                }
        }
 
-       static void Main (string[] args) {
-               /* Test for running a GC while executing a SIGSEGV handler on an altstack */
-               Thread t = new Thread (delegate () { 
-                               segv ();
-                       });
+       static void gc (int niter) {
+               int i = 0;
+               while (i < niter) {
+                       i ++;
+                       if (i % 100 == 0)
+                               Console.Write (".");
+                       GC.Collect ();
+               }
+               finished = true;
+               Console.WriteLine ();
+       }
+
+       static void test (bool main, int niter) {
+               finished = false;
 
-               t.Start ();
+               if (main) {
+                       var t = new Thread (delegate () {
+                                       gc (niter);
+                               });
+                       t.Start ();
 
-               for (int i = 0; i < 100000; ++i) {
-                       new ArrayList ();
+                       fault ();
+               } else {
+                       var t = new Thread (delegate () {
+                                       fault ();
+                               });
+                       t.Start ();
+
+                       gc (niter);
                }
+       }
 
-               finished = true;
+       public static void Main (String[] args) {
+               /* Test for running a GC while executing a SIGSEGV handler on an altstack */
+               int niter;
+
+               if (args.Length > 0)
+                       niter = Int32.Parse (args [0]);
+               else
+                       niter = 1000;
 
-               t.Join ();
+               test (false, niter);
+               test (true, niter);
        }
 }