diff options
author | monojenkins <jo.shields+jenkins@xamarin.com> | 2020-06-16 01:09:15 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-16 01:09:15 +0300 |
commit | bc1dd071a71cbba2fd7b8d8307ec737cdce2daaa (patch) | |
tree | 51455a1cfd1ebe7feae2c07cdd203234dab1f624 | |
parent | 87ef5557017a8d822ae31587846a54fcd66daf1b (diff) |
[merp] Add a test for Mono.Runtime.SendExceptionToTelemetry() (#19966)
Co-authored-by: Alexis Christoforides <alexis@thenull.net>
-rw-r--r-- | mono/tests/merp-crash-test.cs | 55 |
1 files changed, 47 insertions, 8 deletions
diff --git a/mono/tests/merp-crash-test.cs b/mono/tests/merp-crash-test.cs index b5e255b46ec..93e1beb142e 100644 --- a/mono/tests/merp-crash-test.cs +++ b/mono/tests/merp-crash-test.cs @@ -213,7 +213,7 @@ class C public static void TestValidate (string configDir, bool silent, Action<object> validator = null) { - DumpLogCheck (); + DumpLogCheck (expected_level: "MerpInvoke"); // we are expecting merp invoke to fail var xmlFilePath = String.Format("{0}CustomLogsMetadata.xml", configDir); var paramsFilePath = String.Format("{0}MERP.uploadparams.txt", configDir); @@ -298,7 +298,7 @@ class C convert.Invoke(null, new object[] { null }); } - static void DumpLogCheck () + static void DumpLogCheck (string expected_level = "Done") { var monoType = Type.GetType ("Mono.Runtime", false); var convert = monoType.GetMethod("CheckCrashReportLog", BindingFlags.NonPublic | BindingFlags.Static); @@ -306,11 +306,8 @@ class C // Value of enum string [] levels = new string [] { "None", "Setup", "SuspendHandshake", "UnmanagedStacks", "ManagedStacks", "StateWriter", "StateWriterDone", "MerpWriter", "MerpInvoke", "Cleanup", "Done", "DoubleFault" }; - if ("MerpInvoke" == levels [result]) { - Console.WriteLine ("Merp invoke command failed, expected failure?"); - } else if ("Done" != levels [result]) { - throw new Exception (String.Format ("Crash level not done, failed in stage: {0}", levels [result])); - } + if (expected_level != levels [result]) + throw new Exception (String.Format ("Crash level {0} does not match expected {1}", levels [result], expected_level)); } @@ -346,6 +343,40 @@ class C } } + public static void TestManagedException () + { + if (Directory.Exists (configDir)) { + Console.WriteLine ("Cleaning up left over configDir {0}", configDir); + Cleanup (configDir); + } + Directory.CreateDirectory (configDir); + + SetupCrash (configDir); + var monoType = Type.GetType ("Mono.Runtime", false); + var m = monoType.GetMethod ("ExceptionToState", BindingFlags.NonPublic | BindingFlags.Static); + var exception = new Exception ("test managed exception"); + var m_params = new object[] { exception }; + + var result = m.Invoke (null, m_params) as Tuple<String, ulong, ulong>; + DumpLogCheck (expected_level: "StateWriterDone"); + Cleanup (configDir); + } + + public static Exception RunManagedExceptionTest () + { + Console.WriteLine ("Testing ExceptionToState()..."); + Exception exception_test_failure = null; + + try { + TestManagedException(); + } + catch (Exception e) + { + return e; + } + return null; + } + public static int Main (string [] args) { if (args.Length == 0) { @@ -370,10 +401,18 @@ class C } } + // Also test sending a managed exception + Exception exception_test_failure = RunManagedExceptionTest (); + Console.WriteLine ("\n\n##################"); Console.WriteLine ("Merp Test Results:"); Console.WriteLine ("##################\n\n"); + if (exception_test_failure != null) + { + Console.WriteLine ("Sending managed exception to MERP failed: {0}\n{1}\n", exception_test_failure.Message, exception_test_failure.StackTrace); + } + if (failure_count > 0) { for (int i=0; i < CrasherClass.Crashers.Count; i++) { if (failures [i] != null) { @@ -383,7 +422,7 @@ class C } } - if (failure_count > 0) + if (failure_count > 0 || exception_test_failure != null) return 1; Console.WriteLine ("\n\n##################"); |