Skip to content

Commit

Permalink
[tests] Add tests for AppDomainUnloadedException handling
Browse files Browse the repository at this point in the history
  • Loading branch information
BrzVlad committed Sep 19, 2017
1 parent 8a643d5 commit 0ad9e8e
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
4 changes: 3 additions & 1 deletion mono/tests/Makefile.am
Expand Up @@ -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 \
Expand Down Expand Up @@ -1905,7 +1906,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 = \
Expand Down
35 changes: 35 additions & 0 deletions 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;
}
}
16 changes: 16 additions & 0 deletions 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: 255 */
static void Main (string[] args)
{
if (Environment.GetEnvironmentVariable ("TEST_UNHANDLED_EXCEPTION_HANDLER") != null)
AppDomain.CurrentDomain.UnhandledException += (s, e) => {};

throw new AppDomainUnloadedException ();
}
}

0 comments on commit 0ad9e8e

Please sign in to comment.