[tests] Add tests for AppDomainUnloadedException handling
authorVlad Brezae <brezaevlad@gmail.com>
Tue, 19 Sep 2017 22:39:38 +0000 (01:39 +0300)
committerVlad Brezae <brezaevlad@gmail.com>
Fri, 22 Sep 2017 19:14:42 +0000 (22:14 +0300)
As described on https://msdn.microsoft.com/en-us/library/system.appdomainunloadedexception(v=vs.110).aspx#Anchor_6

mono/tests/Makefile.am
mono/tests/appdomain-unload-exception.cs [new file with mode: 0644]
mono/tests/unhandled-exception-9.cs [new file with mode: 0644]

index 49e221628844a5486c061e4830cd4b740eedcc95..729b663f91ba9cfb66dbdee3e980641d7a843803 100755 (executable)
@@ -469,6 +469,7 @@ TESTS_CS_SRC=               \
        appdomain-unload-callback.cs    \
        appdomain-unload-doesnot-raise-pending-events.cs        \
        appdomain-unload-asmload.cs     \
+       appdomain-unload-exception.cs   \
        unload-appdomain-on-shutdown.cs \
        bug-47295.cs    \
        loader.cs       \
@@ -1907,7 +1908,8 @@ test-process-exit:
 
 # tests that expect a 1 exit code
 TESTS_UNHANDLED_EXCEPTION_1_SRC =      \
-       unhandled-exception-1.cs
+       unhandled-exception-1.cs        \
+       unhandled-exception-9.cs
 
 # tests that expect a 255 exit code
 TESTS_UNHANDLED_EXCEPTION_255_SRC =    \
diff --git a/mono/tests/appdomain-unload-exception.cs b/mono/tests/appdomain-unload-exception.cs
new file mode 100644 (file)
index 0000000..dc6bd38
--- /dev/null
@@ -0,0 +1,35 @@
+using System;
+using System.Diagnostics;
+using System.Threading;
+using System.Threading.Tasks;
+
+class Driver
+{
+       static void ThrowTP ()
+       {
+               ManualResetEvent mre = new ManualResetEvent (false);
+
+               ThreadPool.QueueUserWorkItem (_ => { try { throw new AppDomainUnloadedException (); } finally { mre.Set (); } });
+
+               if (!mre.WaitOne (5000))
+                       Environment.Exit (1);
+
+               /* Wait for exception unwinding */
+               Thread.Sleep (500);
+       }
+
+       static void ThrowThread ()
+       {
+               Thread thread = new Thread (_ => { throw new AppDomainUnloadedException (); });
+               thread.Start ();
+               thread.Join ();
+       }
+
+       static int Main (string[] args)
+       {
+               ThrowTP ();
+               ThrowThread ();
+
+               return 0;
+       }
+}
diff --git a/mono/tests/unhandled-exception-9.cs b/mono/tests/unhandled-exception-9.cs
new file mode 100644 (file)
index 0000000..7016b5d
--- /dev/null
@@ -0,0 +1,16 @@
+using System;
+using System.Diagnostics;
+using System.Threading;
+using System.Threading.Tasks;
+
+class Driver
+{
+       /* expected exit code: 1 */
+       static void Main (string[] args)
+       {
+               if (Environment.GetEnvironmentVariable ("TEST_UNHANDLED_EXCEPTION_HANDLER") != null)
+                       AppDomain.CurrentDomain.UnhandledException += (s, e) => {};
+
+               throw new AppDomainUnloadedException ();
+       }
+}