Add assert when dllmap is disabled and fix support build in netcore mode
[mono-project.git] / mono / tests / merp-json-valid.cs
blobe6f7f5558d314a6f62d26c9e51e638500d5968cf
1 using System;
2 using System.IO;
3 using System.Runtime.CompilerServices;
4 using System.Reflection;
5 using System.Web.Script.Serialization;
7 class C
9 public static void
10 JsonValidateState ()
12 var monoType = Type.GetType ("Mono.Runtime", false);
13 var convert = monoType.GetMethod("DumpStateSingle", BindingFlags.NonPublic | BindingFlags.Static);
14 var output = (Tuple<String, ulong, ulong>) convert.Invoke(null, Array.Empty<object> ());
15 var checker = new JavaScriptSerializer ();
17 Console.WriteLine ("Validating: {0}", output.Item1);
18 checker.DeserializeObject (output.Item1);
21 public static void
22 JsonValidateMerp (string configDir)
24 var monoType = Type.GetType ("Mono.Runtime", false);
25 var m = monoType.GetMethod("EnableMicrosoftTelemetry", BindingFlags.NonPublic | BindingFlags.Static);
27 // This leads to open -a /bin/cat, which errors out, but errors
28 // in invoking merp are only logged errors, not fatal assertions.
29 var merpGUIPath = "/bin/cat";
30 var appBundleId = "com.xam.Minimal";
31 var appSignature = "Test.Xam.Minimal";
32 var appVersion = "123456";
33 var eventType = "AppleAppCrash";
34 var appPath = "/where/mono/lives";
36 var m_params = new object[] { appBundleId, appSignature, appVersion, merpGUIPath, eventType, appPath, configDir };
38 m.Invoke(null, m_params);
40 var add_method = monoType.GetMethod("AnnotateMicrosoftTelemetry", BindingFlags.NonPublic | BindingFlags.Static);
41 var add_params = new object[] { "sessionId", "12345" };
42 add_method.Invoke(null, add_params);
44 try {
45 throw new Exception ("");
46 } catch (Exception exc) {
47 var send = monoType.GetMethod("SendExceptionToTelemetry", BindingFlags.NonPublic | BindingFlags.Static);
48 var send_params = new object[] {exc};
50 bool caught_expected_exception = false;
51 try {
52 send.Invoke(null, send_params);
53 } catch (Exception exc2) {
54 if (exc2.InnerException != null && exc2.InnerException.Message == "We were unable to start the Microsoft Error Reporting client.")
55 caught_expected_exception = true;
56 else
57 throw new Exception (String.Format ("Got exception from Merp icall with wrong message {0}", exc2.InnerException != null ? exc2.InnerException.Message : exc2.Message));
61 var xmlFilePath = String.Format("{0}CustomLogsMetadata.xml", configDir);
62 var paramsFilePath = String.Format("{0}MERP.uploadparams.txt", configDir);
63 var crashFilePath = String.Format("{0}lastcrashlog.txt", configDir);
65 var xmlFileExists = File.Exists (xmlFilePath);
66 var paramsFileExists = File.Exists (paramsFilePath);
67 var crashFileExists = File.Exists (crashFilePath);
69 if (xmlFileExists) {
70 File.ReadAllText (xmlFilePath);
71 File.Delete (xmlFilePath);
74 if (paramsFileExists) {
75 File.ReadAllText (paramsFilePath);
76 File.Delete (paramsFilePath);
79 if (crashFileExists) {
80 var crashFile = File.ReadAllText (crashFilePath);
81 File.Delete (crashFilePath);
83 var checker = new JavaScriptSerializer ();
85 // Throws if invalid json
86 Console.WriteLine("Validating: {0}", crashFile);
87 checker.DeserializeObject (crashFile);
90 if (!xmlFileExists)
91 throw new Exception (String.Format ("Did not produce {0}", xmlFilePath));
93 if (!paramsFileExists)
94 throw new Exception (String.Format ("Did not produce {0}", paramsFilePath));
96 if (!crashFileExists)
97 throw new Exception (String.Format ("Did not produce {0}", crashFilePath));
100 public static void Main ()
102 JsonValidateState ();
104 var configDir = "./merp-json-valid/";
105 Directory.CreateDirectory (configDir);
106 try {
107 JsonValidateMerp (configDir);
108 } finally {
109 Directory.Delete (configDir, true);