Permalink
Browse files

* unhandled-exception-test-runner.2.cs,

	unhandled-exception-test-case.2.cs,
	unhandled-exception-base-configuration.config,
	unhandled-exception-legacy-configuration.config,
	Makefile.am: added test for bug #82416.


svn path=/trunk/mono/; revision=85691
  • Loading branch information...
Massimiliano Mantione
Massimiliano Mantione committed Sep 12, 2007
1 parent 4944a63 commit ecea3dc17767f15728aa177a8bf345c5f9263aa7
View
@@ -1,3 +1,11 @@
+2007-09-12 Massimiliano Mantione <massi@ximian.com>
+
+ * unhandled-exception-test-runner.2.cs,
+ unhandled-exception-test-case.2.cs,
+ unhandled-exception-base-configuration.config,
+ unhandled-exception-legacy-configuration.config,
+ Makefile.am: added test for bug #82416.
+
2007-09-12 Marek Habersack <mhabersack@novell.com>
* assemblyresolve_event2.2.cs: added tests for assembly resolution
View
@@ -338,10 +338,11 @@ if POWERPC
test: testjit test-type-load test-inline-call-stack test-bug-80307 test-bug-81673 test-bug-81691 test-bug-81466
else
# Can't use mkbundle on win32 since there is no static build there
+# Can't run test-unhandled-exception on Windows because of all the debug popups...
if PLATFORM_WIN32
test: testjit test-type-load test-inline-call-stack test-bug-80307 test-bug-81673 test-bug-81691 test-bug-81466
else
-test: testjit testbundle test-type-load test-inline-call-stack test-iomap-regression test-bug-80307 test-bug-81673 test-bug-81691 test-bug-81466
+test: testjit testbundle test-type-load test-inline-call-stack test-iomap-regression test-bug-80307 test-bug-81673 test-bug-81691 test-bug-81466 test-unhandled-exception
endif
endif
@@ -519,6 +520,31 @@ test-inline-call-stack.exe: TestDriver.dll test-inline-call-stack-library.dll $(
test-inline-call-stack: TestDriver.dll test-inline-call-stack-library.dll test-inline-call-stack.exe
$(RUNTIME) test-inline-call-stack.exe
+
+EXTRA_DIST += unhandled-exception-base-configuration.config
+EXTRA_DIST += unhandled-exception-legacy-configuration.config
+EXTRA_DIST += unhandled-exception-test-case.2.cs
+EXTRA_DIST += unhandled-exception-test-runner.2.cs
+unhandled-exception-test-case.1.cs: unhandled-exception-test-case.2.cs
+ cp unhandled-exception-test-case.2.cs unhandled-exception-test-case.1.cs
+unhandled-exception-test-case-legacy.1.cs: unhandled-exception-test-case.1.cs
+ cp unhandled-exception-test-case.1.cs unhandled-exception-test-case-legacy.1.cs
+unhandled-exception-test-case-legacy.2.cs: unhandled-exception-test-case.2.cs
+ cp unhandled-exception-test-case.2.cs unhandled-exception-test-case-legacy.2.cs
+unhandled-exception-test-case.1.exe: unhandled-exception-test-case.1.cs
+ $(MCS) /debug unhandled-exception-test-case.1.cs
+unhandled-exception-test-case-legacy.1.exe: unhandled-exception-test-case-legacy.1.cs
+ $(MCS) /debug unhandled-exception-test-case-legacy.1.cs
+unhandled-exception-test-case.2.exe: unhandled-exception-test-case.2.cs
+ $(GMCS) /debug unhandled-exception-test-case.2.cs
+unhandled-exception-test-case-legacy.2.exe: unhandled-exception-test-case-legacy.2.cs
+ $(GMCS) /debug unhandled-exception-test-case-legacy.2.cs
+unhandled-exception-test-runner.2.exe: unhandled-exception-test-runner.2.cs
+ $(GMCS) /debug unhandled-exception-test-runner.2.cs
+
+test-unhandled-exception: unhandled-exception-test-runner.2.exe unhandled-exception-test-case.1.exe unhandled-exception-test-case-legacy.1.exe unhandled-exception-test-case.2.exe unhandled-exception-test-case-legacy.2.exe
+ $(RUNTIME) unhandled-exception-test-runner.2.exe RUNTIME:../mini/mono,GTC:F
+
EXTRA_DIST += bug-80307.cs
bug-80307.exe: $(srcdir)/bug-80307.cs
$(MCS) -r:System.Web -out:$@ $(srcdir)/bug-80307.cs
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+ <runtime>
+ <legacyUnhandledExceptionPolicy enabled="0"/>
+ </runtime>
+</configuration>
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+ <runtime>
+ <legacyUnhandledExceptionPolicy enabled="1"/>
+ </runtime>
+</configuration>
@@ -0,0 +1,226 @@
+using System;
+using System.Reflection;
+using System.Threading;
+
+namespace UnhandledExceptionTest
+{
+ class TestConfiguration {
+ private bool useDifferentThread = false;
+ public bool DT {
+ get {
+ return useDifferentThread;
+ }
+ }
+ private bool useDifferentApplicationDomain = false;
+ public bool DA {
+ get {
+ return useDifferentApplicationDomain;
+ }
+ }
+ private bool differentConfigurationIsLegacy;
+ public bool DCIL {
+ get {
+ return differentConfigurationIsLegacy;
+ }
+ }
+ private bool useDifferentThreadInDifferentApplicationDomain = false;
+ public bool DTDA {
+ get {
+ return useDifferentThreadInDifferentApplicationDomain;
+ }
+ }
+ private bool addHandlerToRootApplicationDomain = false;
+ public bool HRA {
+ get {
+ return addHandlerToRootApplicationDomain;
+ }
+ }
+ private bool addHandlerToDifferentApplicationDomain = false;
+ public bool HDA {
+ get {
+ return addHandlerToDifferentApplicationDomain;
+ }
+ }
+
+ private static bool ParseArgumentValue (string value) {
+ if ((value.Length == 1)) {
+ switch (value [0]) {
+ case 'T':
+ return true;
+ case 'F':
+ return false;
+ default:
+ Console.WriteLine ("Invalid argument value {0}", value);
+ throw new ApplicationException ("Invalid argument value " + value);
+ }
+ } else {
+ Console.WriteLine ("Invalid argument value {0}", value);
+ throw new ApplicationException ("Invalid argument value " + value);
+ }
+ }
+
+ public TestConfiguration (string configuration) {
+ string [] arguments = configuration.Split (',');
+ foreach (string argument in arguments) {
+ string [] components = argument.Split (':');
+ if (components.Length == 2) {
+ switch (components [0]) {
+ case "DT":
+ useDifferentThread = ParseArgumentValue (components [1]);
+ break;
+ case "DA":
+ useDifferentApplicationDomain = ParseArgumentValue (components [1]);
+ break;
+ case "DCIL":
+ differentConfigurationIsLegacy = ParseArgumentValue (components [1]);
+ break;
+ case "DTDA":
+ useDifferentThreadInDifferentApplicationDomain = ParseArgumentValue (components [1]);
+ break;
+ case "HRA":
+ addHandlerToRootApplicationDomain = ParseArgumentValue (components [1]);
+ break;
+ case "HDA":
+ addHandlerToDifferentApplicationDomain = ParseArgumentValue (components [1]);
+ break;
+ default:
+ Console.WriteLine ("Invalid argument {0}", argument);
+ throw new ApplicationException ("Invalid argument " + argument);
+ }
+ } else {
+ Console.WriteLine ("Invalid argument {0}", argument);
+ throw new ApplicationException ("Invalid argument " + argument);
+ }
+ }
+ }
+ private static string BoolToString (bool value) {
+ return value ? "T" : "F";
+ }
+ public void Print () {
+ Console.WriteLine ("Configuration: DT={0},DA={1},DCIL={2},DTDA={3},HRA={4},HDA={5}",
+ BoolToString (useDifferentThread),
+ BoolToString (useDifferentApplicationDomain),
+ BoolToString (differentConfigurationIsLegacy),
+ BoolToString (useDifferentThreadInDifferentApplicationDomain),
+ BoolToString (addHandlerToRootApplicationDomain),
+ BoolToString (addHandlerToDifferentApplicationDomain));
+ }
+ }
+
+ class Test {
+ private string configurationDescription;
+ private TestConfiguration configuration;
+ public Test (string configurationDescription) {
+ this.configurationDescription = configurationDescription;
+ this.configuration = new TestConfiguration (configurationDescription);
+ }
+
+ private AppDomain CreateDiffrentAppDomain () {
+ AppDomainSetup ads = new AppDomainSetup();
+ ads.ApplicationBase = System.Environment.CurrentDirectory;
+ ads.DisallowBindingRedirects = false;
+ ads.DisallowCodeDownload = true;
+ ads.ConfigurationFile = System.Environment.CurrentDirectory + System.IO.Path.DirectorySeparatorChar +
+ (configuration.DCIL ? "unhandled-exception-legacy-configuration.config" : "unhandled-exception-base-configuration.config");
+ return AppDomain.CreateDomain("DifferentAppDomain", null, ads);
+ }
+
+ public void RunTest () {
+ if (configuration.DA) {
+ AppDomain differentAppDomain = CreateDiffrentAppDomain ();
+ if (configuration.HDA) {
+ differentAppDomain.UnhandledException += new UnhandledExceptionEventHandler (DifferentDomainUnhandledExceptionHandler);
+ }
+ DifferentDomainActor dda = (DifferentDomainActor) differentAppDomain.CreateInstanceAndUnwrap (
+ Assembly.GetEntryAssembly().FullName, typeof (DifferentDomainActor).FullName);
+ dda.Act (configurationDescription);
+ } else {
+ if (configuration.DT) {
+ Console.WriteLine ("Throwing ApplicationException in different thread");
+ } else {
+ Console.WriteLine ("Throwing ApplicationException in main thread");
+ }
+ throw new ApplicationException ("This exception is unhandled");
+ }
+ if (configuration.DT) {
+ Console.WriteLine ("Continuing in different thread after the exception was thrown");
+ }
+ }
+
+ static void Main (string [] args) {
+ if (args.Length != 1) {
+ Console.WriteLine ("Invalid arguments (number of) {0}", args.Length);
+ throw new ApplicationException ("Invalid arguments (number of) " + args.Length);
+ }
+ Test test = new Test (args [0]);
+ test.Act ();
+ }
+ public void Act () {
+ configuration.Print ();
+ Console.WriteLine ("Running under version {0}", Environment.Version);
+
+ if (configuration.HRA) {
+ AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler (RootDomainUnhandledExceptionHandler);
+ }
+
+ if (configuration.DT) {
+ Thread thread = new Thread (new ThreadStart (this.RunTest));
+ thread.Start ();
+ thread.Join ();
+ } else {
+ RunTest ();
+ }
+
+ Console.WriteLine ("Continuing in main thread after the exception was thrown");
+ Console.WriteLine ("Continuing in root AppDomain after the exception was thrown");
+ Console.WriteLine ("MARKER-CONT");
+ }
+
+ public static void PrintUnhandledException (string caller, object sender, UnhandledExceptionEventArgs e) {
+ Exception ex = (Exception)e.ExceptionObject;
+
+ Console.WriteLine ("Running {0}", caller);
+ Console.WriteLine ("Handling exception type {0}", ex.GetType().Name);
+ Console.WriteLine ("Message is {0}", ex.Message);
+ Console.WriteLine ("IsTerminating is set to {0}", e.IsTerminating);
+ }
+ public static void RootDomainUnhandledExceptionHandler (object sender, UnhandledExceptionEventArgs e) {
+ Console.WriteLine ("MARKER-RDUE");
+ PrintUnhandledException ("RootDomainUnhandledExceptionHandler", sender, e);
+ }
+ public static void DifferentDomainUnhandledExceptionHandler (object sender, UnhandledExceptionEventArgs e) {
+ Console.WriteLine ("MARKER-DDUE");
+ PrintUnhandledException ("DifferentDomainUnhandledExceptionHandler", sender, e);
+ }
+ }
+
+ public class DifferentDomainActor : MarshalByRefObject {
+ //private string configurationDescription = null;
+ private TestConfiguration configuration = null;
+
+ public void RunTest () {
+ if (configuration.DTDA) {
+ Console.WriteLine ("Throwing ApplicationException in new thread (different appdomain)");
+ } else if (configuration.DT) {
+ Console.WriteLine ("Throwing ApplicationException in different thread (different appdomain)");
+ } else {
+ Console.WriteLine ("Throwing ApplicationException in main thread (different appdomain)");
+ }
+ throw new ApplicationException ("This exception is unhandled");
+ }
+
+ // Call this method via a proxy.
+ public void Act (string configurationDescription) {
+ //this.configurationDescription = configurationDescription;
+ this.configuration = new TestConfiguration (configurationDescription);
+
+ if (configuration.DTDA) {
+ Thread thread = new Thread (new ThreadStart (this.RunTest));
+ thread.Start ();
+ thread.Join ();
+ } else {
+ RunTest ();
+ }
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit ecea3dc

Please sign in to comment.