From 8b959c6a57399c79dbb265b6c4a81cdd3c235cef Mon Sep 17 00:00:00 2001 From: Vlad Brezae Date: Wed, 20 Sep 2017 01:39:38 +0300 Subject: [PATCH] [tests] Add tests for AppDomainUnloadedException handling As described on https://msdn.microsoft.com/en-us/library/system.appdomainunloadedexception(v=vs.110).aspx#Anchor_6 --- mono/tests/Makefile.am | 4 +++- mono/tests/appdomain-unload-exception.cs | 35 ++++++++++++++++++++++++++++++++ mono/tests/unhandled-exception-9.cs | 16 +++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 mono/tests/appdomain-unload-exception.cs create mode 100644 mono/tests/unhandled-exception-9.cs diff --git a/mono/tests/Makefile.am b/mono/tests/Makefile.am index 49e22162884..729b663f91b 100755 --- a/mono/tests/Makefile.am +++ b/mono/tests/Makefile.am @@ -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 index 00000000000..dc6bd386538 --- /dev/null +++ b/mono/tests/appdomain-unload-exception.cs @@ -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 index 00000000000..7016b5dceb5 --- /dev/null +++ b/mono/tests/unhandled-exception-9.cs @@ -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 (); + } +} -- 2.11.4.GIT