[tests] Use test-runner to run unhandled-exception tests
authorLudovic Henry <ludovic@xamarin.com>
Mon, 26 Oct 2015 10:58:40 +0000 (10:58 +0000)
committerLudovic Henry <ludovic@xamarin.com>
Mon, 26 Oct 2015 10:58:51 +0000 (10:58 +0000)
mono/tests/Makefile.am
mono/tests/unhandled-exception-1.cs [new file with mode: 0644]
mono/tests/unhandled-exception-2.cs [new file with mode: 0644]
mono/tests/unhandled-exception-3.cs [new file with mode: 0644]
mono/tests/unhandled-exception-4.cs [new file with mode: 0644]
mono/tests/unhandled-exception-5.cs [new file with mode: 0644]
mono/tests/unhandled-exception-6.cs [new file with mode: 0644]
mono/tests/unhandled-exception-7.cs [new file with mode: 0644]
mono/tests/unhandled-exception-8.cs [new file with mode: 0644]
mono/tests/unhandled-exception.cs [deleted file]

index e3542e7e175fb2cb445c292780fffc8010eb8d61..7b744501947f24979545c61a4b4c05e3e09a3da4 100644 (file)
@@ -1368,15 +1368,25 @@ test-oom: $(OOM_TESTS)
 if HOST_WIN32
 test-unhandled-exception-2:
 else
-test-unhandled-exception-2: unhandled-exception.exe
-       @echo "Testing unhandled-exception_1 ..."; $(RUNTIME) $+ 1 1> unhandled-exception_1.exe.stdout 2> unhandled-exception_1.exe.stderr; if test "x$$?" != "x1";   then exit 1; fi;  \
-        echo "Testing unhandled-exception_2 ..."; $(RUNTIME) $+ 2 1> unhandled-exception_2.exe.stdout 2> unhandled-exception_2.exe.stderr; if test "x$$?" != "x0";   then exit 2; fi;  \
-        echo "Testing unhandled-exception_3 ..."; $(RUNTIME) $+ 3 1> unhandled-exception_3.exe.stdout 2> unhandled-exception_3.exe.stderr; if test "x$$?" != "x0";   then exit 3; fi;  \
-        echo "Testing unhandled-exception_4 ..."; $(RUNTIME) $+ 4 1> unhandled-exception_4.exe.stdout 2> unhandled-exception_4.exe.stderr; if test "x$$?" != "x0";   then exit 4; fi;  \
-        echo "Testing unhandled-exception_5 ..."; $(RUNTIME) $+ 5 1> unhandled-exception_5.exe.stdout 2> unhandled-exception_5.exe.stderr; if test "x$$?" != "x255"; then exit 5; fi;  \
-        echo "Testing unhandled-exception_6 ..."; $(RUNTIME) $+ 6 1> unhandled-exception_6.exe.stdout 2> unhandled-exception_6.exe.stderr; if test "x$$?" != "x0";   then exit 6; fi;  \
-        echo "Testing unhandled-exception_7 ..."; $(RUNTIME) $+ 7 1> unhandled-exception_7.exe.stdout 2> unhandled-exception_7.exe.stderr; if test "x$$?" != "x0";   then exit 7; fi;  \
-        echo "Testing unhandled-exception_8 ..."; $(RUNTIME) $+ 8 1> unhandled-exception_8.exe.stdout 2> unhandled-exception_8.exe.stderr; if test "x$$?" != "x3";   then exit 8; fi
+test-unhandled-exception-2: test-unhandled-exception-2-1 test-unhandled-exception-2-2 test-unhandled-exception-2-3 test-unhandled-exception-2-4        \
+                test-unhandled-exception-2-5 test-unhandled-exception-2-6 test-unhandled-exception-2-7 test-unhandled-exception-2-8
+
+test-unhandled-exception-2-1: unhandled-exception-1.exe test-runner.exe
+       @$(RUNTIME) ./test-runner.exe --expected-exit-code 1 $<
+test-unhandled-exception-2-2: unhandled-exception-2.exe test-runner.exe
+       @$(RUNTIME) ./test-runner.exe --expected-exit-code 0 $<
+test-unhandled-exception-2-3: unhandled-exception-3.exe test-runner.exe
+       @$(RUNTIME) ./test-runner.exe --expected-exit-code 255 $<
+test-unhandled-exception-2-4: unhandled-exception-4.exe test-runner.exe
+       @$(RUNTIME) ./test-runner.exe --expected-exit-code 0 $<
+test-unhandled-exception-2-5: unhandled-exception-5.exe test-runner.exe
+       @$(RUNTIME) ./test-runner.exe --expected-exit-code 255 $<
+test-unhandled-exception-2-6: unhandled-exception-6.exe test-runner.exe
+       @$(RUNTIME) ./test-runner.exe --expected-exit-code 0 $<
+test-unhandled-exception-2-7: unhandled-exception-7.exe test-runner.exe
+       @$(RUNTIME) ./test-runner.exe --expected-exit-code 0 $<
+test-unhandled-exception-2-8: unhandled-exception-8.exe test-runner.exe
+       @$(RUNTIME) ./test-runner.exe --expected-exit-code 3 $<
 endif
 
 EXTRA_DIST += appdomain-loader.cs appdomain-tester.cs
diff --git a/mono/tests/unhandled-exception-1.cs b/mono/tests/unhandled-exception-1.cs
new file mode 100644 (file)
index 0000000..2e89dcf
--- /dev/null
@@ -0,0 +1,27 @@
+using System;
+using System.Diagnostics;
+using System.Threading;
+using System.Threading.Tasks;
+
+class CustomException : Exception
+{
+}
+
+class Driver
+{
+       /* Expected exit code: 1 */
+       static void Main (string[] args)
+       {
+               ManualResetEvent mre = new ManualResetEvent (false);
+
+               var t = new Thread (new ThreadStart (() => { try { throw new CustomException (); } finally { mre.Set (); } }));
+               t.Start ();
+
+               if (!mre.WaitOne (5000))
+                       Environment.Exit (2);
+
+               t.Join ();
+
+               Environment.Exit (0);
+       }
+}
diff --git a/mono/tests/unhandled-exception-2.cs b/mono/tests/unhandled-exception-2.cs
new file mode 100644 (file)
index 0000000..7c9cc69
--- /dev/null
@@ -0,0 +1,34 @@
+using System;
+using System.Diagnostics;
+using System.Threading;
+using System.Threading.Tasks;
+
+class CustomException : Exception
+{
+}
+
+class Driver
+{
+       /* expected exit code: 0 */
+       static void Main (string[] args)
+       {
+               ManualResetEvent mre = new ManualResetEvent (false);
+
+               var a = new Action (() => { try { throw new CustomException (); } finally { mre.Set (); } });
+               var ares = a.BeginInvoke (null, null);
+
+               if (!mre.WaitOne (5000))
+                       Environment.Exit (2);
+
+               try {
+                       a.EndInvoke (ares);
+                       Environment.Exit (4);
+               } catch (CustomException) {
+               } catch (Exception ex) {
+                       Console.WriteLine (ex);
+                       Environment.Exit (3);
+               }
+
+               Environment.Exit (0);
+       }
+}
diff --git a/mono/tests/unhandled-exception-3.cs b/mono/tests/unhandled-exception-3.cs
new file mode 100644 (file)
index 0000000..5f4a4d3
--- /dev/null
@@ -0,0 +1,24 @@
+using System;
+using System.Diagnostics;
+using System.Threading;
+using System.Threading.Tasks;
+
+class CustomException : Exception
+{
+}
+
+class Driver
+{
+       /* expected exit code: 0 */
+       static void Main (string[] args)
+       {
+               ManualResetEvent mre = new ManualResetEvent (false);
+
+               ThreadPool.QueueUserWorkItem (_ => { try { throw new CustomException (); } finally { mre.Set (); } });
+
+               if (!mre.WaitOne (5000))
+                       Environment.Exit (2);
+
+               Environment.Exit (0);
+       }
+}
diff --git a/mono/tests/unhandled-exception-4.cs b/mono/tests/unhandled-exception-4.cs
new file mode 100644 (file)
index 0000000..9658316
--- /dev/null
@@ -0,0 +1,35 @@
+using System;
+using System.Diagnostics;
+using System.Threading;
+using System.Threading.Tasks;
+
+class CustomException : Exception
+{
+}
+
+class Driver
+{
+       /* expected exit code: 0 */
+       static void Main (string[] args)
+       {
+               ManualResetEvent mre = new ManualResetEvent (false);
+
+               var t = Task.Factory.StartNew (new Action (() => { try { throw new CustomException (); } finally { mre.Set (); } }));
+
+               if (!mre.WaitOne (5000))
+                       Environment.Exit (2);
+
+               try {
+                       t.Wait ();
+                       Environment.Exit (5);
+               } catch (AggregateException ae) {
+                       if (!(ae.InnerExceptions [0] is CustomException))
+                               Environment.Exit (4);
+               } catch (Exception ex) {
+                       Console.WriteLine (ex);
+                       Environment.Exit (3);
+               }
+
+               Environment.Exit (0);
+       }
+}
diff --git a/mono/tests/unhandled-exception-5.cs b/mono/tests/unhandled-exception-5.cs
new file mode 100644 (file)
index 0000000..33136b3
--- /dev/null
@@ -0,0 +1,39 @@
+using System;
+using System.Diagnostics;
+using System.Threading;
+using System.Threading.Tasks;
+
+class CustomException : Exception
+{
+}
+
+class Driver
+{
+       static ManualResetEvent mre = new ManualResetEvent (false);
+
+       class FinalizedClass
+       {
+               ~FinalizedClass ()
+               {
+                       try {
+                               throw new CustomException ();
+                       } finally {
+                               mre.Set ();
+                       }
+               }
+       }
+
+       /* expected exit code: 255 */
+       static void Main (string[] args)
+       {
+               new FinalizedClass();
+
+               GC.Collect ();
+               GC.WaitForPendingFinalizers ();
+
+               if (!mre.WaitOne (5000))
+                       Environment.Exit (2);
+
+               Environment.Exit (0);
+       }
+}
diff --git a/mono/tests/unhandled-exception-6.cs b/mono/tests/unhandled-exception-6.cs
new file mode 100644 (file)
index 0000000..b9c2549
--- /dev/null
@@ -0,0 +1,41 @@
+using System;
+using System.Diagnostics;
+using System.Threading;
+using System.Threading.Tasks;
+
+class CustomException : Exception
+{
+}
+
+class CustomException2 : Exception
+{
+}
+
+class Driver
+{
+       /* expected exit code: 0 */
+       static void Main (string[] args)
+       {
+               ManualResetEvent mre = new ManualResetEvent (false);
+               ManualResetEvent mre2 = new ManualResetEvent (false);
+
+               var a = new Action (() => { try { throw new CustomException (); } finally { mre.Set (); } });
+               var ares = a.BeginInvoke (_ => { mre2.Set (); throw new CustomException2 (); }, null);
+
+               if (!mre.WaitOne (5000))
+                       Environment.Exit (2);
+               if (!mre2.WaitOne (5000))
+                       Environment.Exit (22);
+
+               try {
+                       a.EndInvoke (ares);
+                       Environment.Exit (4);
+               } catch (CustomException) {
+               } catch (Exception ex) {
+                       Console.WriteLine (ex);
+                       Environment.Exit (3);
+               }
+
+               Environment.Exit (0);
+       }
+}
diff --git a/mono/tests/unhandled-exception-7.cs b/mono/tests/unhandled-exception-7.cs
new file mode 100644 (file)
index 0000000..d31fdf9
--- /dev/null
@@ -0,0 +1,55 @@
+using System;
+using System.Diagnostics;
+using System.Threading;
+using System.Threading.Tasks;
+
+class CustomException : Exception
+{
+}
+
+class CustomException2 : Exception
+{
+}
+
+class CrossDomain : MarshalByRefObject
+{
+       public Action NewDelegateWithTarget ()
+       {
+               return new Action (Bar);
+       }
+
+       public Action NewDelegateWithoutTarget ()
+       {
+               return () => { throw new CustomException (); };
+       }
+
+       public void Bar ()
+       {
+               throw new CustomException ();
+       }
+}
+
+class Driver
+{
+       /* expected exit code: 0 */
+       static void Main (string[] args)
+       {
+               ManualResetEvent mre = new ManualResetEvent (false);
+
+               var cd = (CrossDomain) AppDomain.CreateDomain ("ad").CreateInstanceAndUnwrap (typeof(CrossDomain).Assembly.FullName, "CrossDomain");
+
+               var a = cd.NewDelegateWithoutTarget ();
+               var ares = a.BeginInvoke (delegate { throw new CustomException2 (); }, null);
+
+               try {
+                       a.EndInvoke (ares);
+                       Environment.Exit (4);
+               } catch (CustomException) {
+               } catch (Exception ex) {
+                       Console.WriteLine (ex);
+                       Environment.Exit (3);
+               }
+
+               Environment.Exit (0);
+       }
+}
diff --git a/mono/tests/unhandled-exception-8.cs b/mono/tests/unhandled-exception-8.cs
new file mode 100644 (file)
index 0000000..d02896b
--- /dev/null
@@ -0,0 +1,55 @@
+using System;
+using System.Diagnostics;
+using System.Threading;
+using System.Threading.Tasks;
+
+class CustomException : Exception
+{
+}
+
+class CustomException2 : Exception
+{
+}
+
+class CrossDomain : MarshalByRefObject
+{
+       public Action NewDelegateWithTarget ()
+       {
+               return new Action (Bar);
+       }
+
+       public Action NewDelegateWithoutTarget ()
+       {
+               return () => { throw new CustomException (); };
+       }
+
+       public void Bar ()
+       {
+               throw new CustomException ();
+       }
+}
+
+class Driver
+{
+       /* expected exit code: 3 */
+       static void Main (string[] args)
+       {
+               ManualResetEvent mre = new ManualResetEvent (false);
+
+               var cd = (CrossDomain) AppDomain.CreateDomain ("ad").CreateInstanceAndUnwrap (typeof(CrossDomain).Assembly.FullName, "CrossDomain");
+
+               var a = cd.NewDelegateWithTarget ();
+               var ares = a.BeginInvoke (delegate { throw new CustomException2 (); }, null);
+
+               try {
+                       a.EndInvoke (ares);
+                       Environment.Exit (4);
+               } catch (CustomException) {
+               } catch (Exception ex) {
+                       Console.WriteLine (ex);
+                       Environment.Exit (3);
+               }
+
+               Environment.Exit (0);
+       }
+}
diff --git a/mono/tests/unhandled-exception.cs b/mono/tests/unhandled-exception.cs
deleted file mode 100644 (file)
index 7658e07..0000000
+++ /dev/null
@@ -1,193 +0,0 @@
-using System;
-using System.Diagnostics;
-using System.Threading;
-using System.Threading.Tasks;
-
-class CustomException : Exception
-{
-}
-
-class CustomException2 : Exception
-{
-}
-
-
-class CrossDomain : MarshalByRefObject
-{
-       public Action NewDelegateWithTarget ()
-       {
-               return new Action (Bar);
-       }
-
-       public Action NewDelegateWithoutTarget ()
-       {
-               return () => { throw new CustomException (); };
-       }
-
-       public void Bar ()
-       {
-               throw new CustomException ();
-       }
-}
-
-class Driver {
-       static ManualResetEvent mre = new ManualResetEvent (false);
-
-       static void DoTest1 ()
-       {
-               mre.Reset ();
-
-               var t = new Thread (new ThreadStart (() => { try { throw new CustomException (); } finally { mre.Set (); } }));
-               t.Start ();
-
-               if (!mre.WaitOne (5000))
-                       Environment.Exit (2);
-
-               t.Join ();
-       }
-
-       static void DoTest2 ()
-       {
-               mre.Reset ();
-
-               var a = new Action (() => { try { throw new CustomException (); } finally { mre.Set (); } });
-               var ares = a.BeginInvoke (null, null);
-
-               if (!mre.WaitOne (5000))
-                       Environment.Exit (2);
-
-               try {
-                       a.EndInvoke (ares);
-                       throw new Exception ();
-               } catch (CustomException) {                     
-               } catch (Exception) {
-                       Environment.Exit (3);
-               }
-       }
-
-       static void DoTest3 ()
-       {
-               mre.Reset ();
-
-               ThreadPool.QueueUserWorkItem (_ => { try { throw new CustomException (); } finally { mre.Set (); } });
-
-               if (!mre.WaitOne (5000))
-                       Environment.Exit (2);
-       }
-
-       static void DoTest4 ()
-       {
-               mre.Reset ();
-
-               var t = Task.Factory.StartNew (new Action (() => { try { throw new CustomException (); } finally { mre.Set (); } }));
-
-               if (!mre.WaitOne (5000))
-                       Environment.Exit (2);
-
-               try {
-                       t.Wait ();
-                       throw new Exception ();
-               } catch (AggregateException ae) {
-                       if (!(ae.InnerExceptions [0] is CustomException))
-                               Environment.Exit (4);
-               } catch (Exception) {
-                       Environment.Exit (3);
-               }
-       }
-       
-       class FinalizedClass
-       {
-               ~FinalizedClass ()
-               {
-                       try {
-                               throw new CustomException ();
-                       } finally {
-                               mre.Set ();
-                       }
-               }
-       }
-
-       static void DoTest5 ()
-       {
-               mre.Reset ();
-
-               new FinalizedClass();
-
-               GC.Collect ();
-               GC.WaitForPendingFinalizers ();
-
-               if (!mre.WaitOne (5000))
-                       Environment.Exit (2);
-       }
-
-       static void DoTest6 ()
-       {
-               ManualResetEvent mre2 = new ManualResetEvent (false);
-
-               mre.Reset ();
-
-               var a = new Action (() => { try { throw new CustomException (); } finally { mre.Set (); } });
-               var ares = a.BeginInvoke (_ => { mre2.Set (); throw new CustomException2 (); }, null);
-
-               if (!mre.WaitOne (5000))
-                       Environment.Exit (2);
-               if (!mre2.WaitOne (5000))
-                       Environment.Exit (22);
-
-               try {
-                       a.EndInvoke (ares);
-                       throw new Exception ();
-               } catch (CustomException) {
-               } catch (Exception) {
-                       Environment.Exit (3);
-               }
-       }
-
-       static void DoTest7 ()
-       {
-               var cd = (CrossDomain) AppDomain.CreateDomain ("ad").CreateInstanceAndUnwrap (typeof(CrossDomain).Assembly.FullName, "CrossDomain");
-
-               var a = cd.NewDelegateWithoutTarget ();
-               var ares = a.BeginInvoke (delegate { throw new CustomException2 (); }, null);
-
-               try {
-                       a.EndInvoke (ares);
-                       throw new Exception ();
-               } catch (CustomException) {
-               } catch (Exception) {
-                       Environment.Exit (3);
-               }
-       }
-
-       static void DoTest8 ()
-       {
-               var cd = (CrossDomain) AppDomain.CreateDomain ("ad").CreateInstanceAndUnwrap (typeof(CrossDomain).Assembly.FullName, "CrossDomain");
-
-               var a = cd.NewDelegateWithTarget ();
-               var ares = a.BeginInvoke (delegate { throw new CustomException2 (); }, null);
-
-               try {
-                       a.EndInvoke (ares);
-                       throw new Exception ();
-               } catch (CustomException) {
-               } catch (Exception) {
-                       Environment.Exit (3);
-               }
-       }
-
-       static void Main (string[] args)
-       {
-               switch (int.Parse (args [0])) {
-               case 1: DoTest1 (); break;
-               case 2: DoTest2 (); break;
-               case 3: DoTest3 (); break;
-               case 4: DoTest4 (); break;
-               case 5: DoTest5 (); break;
-               case 6: DoTest6 (); break;
-               case 7: DoTest7 (); break;
-               case 8: DoTest8 (); break;
-               default: throw new ArgumentOutOfRangeException ();
-               }
-               Environment.Exit (0);
-       }
-}