"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "mono/tests/merp-crash-test.cs" between
mono-6.8.0.105.tar.xz and mono-6.8.0.123.tar.xz

About:

merp-crash-test.cs  (mono-6.8.0.105.tar.xz):merp-crash-test.cs  (mono-6.8.0.123.tar.xz)
skipping to change at line 14 skipping to change at line 14
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Reflection; using System.Reflection;
using System.Web.Script.Serialization; using System.Web.Script.Serialization;
using Diag = System.Diagnostics; using Diag = System.Diagnostics;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
class C class C
{ {
class CrasherClass class CrasherClass
{ {
public static List<Tuple<String, Action>> Crashers; public struct Crasher {
public string Name {get;}
public Action Action {get; }
public Action<object> Validator {get; }
public Crasher (string name, Action action, Action<object
> validator = null)
{
Name = name;
Action = action;
Validator = validator;
}
}
public class ValidationException : Exception {
public ValidationException () : base () {}
public ValidationException (string msg) : base (msg) {}
public ValidationException (string msg, Exception inner)
: base (msg, inner) {}
}
public static List<Crasher> Crashers;
public static int StresserIndex; public static int StresserIndex;
static CrasherClass () static CrasherClass ()
{ {
Crashers = new List<Tuple<String, Action>> (); Crashers = new List<Crasher> ();
// Basic functionality // Basic functionality
Crashers.Add(new Tuple<String, Action> ("MerpCrashManaged ", MerpCrashManaged)); Crashers.Add(new Crasher ("MerpCrashManaged", MerpCrashMa naged));
// Run this test for stress tests // Run this test for stress tests
// //
// I've ran a burn-in with all of them of // I've ran a burn-in with all of them of
// 1,000 - 10,000 runs already. // 1,000 - 10,000 runs already.
// //
// Feel free to change by moving this line. // Feel free to change by moving this line.
StresserIndex = Crashers.Count - 1; StresserIndex = Crashers.Count - 1;
Crashers.Add(new Tuple<String, Action> ("MerpCrashMalloc" Crashers.Add(new Crasher ("MerpCrashMalloc", MerpCrashMal
, MerpCrashMalloc)); loc));
Crashers.Add(new Crasher ("MerpCrashFailFast", MerpCrashF
ailFast, ValidateFailFastMsg));
Crashers.Add(new Tuple<String, Action> ("MerpCrashNullFp" Crashers.Add(new Crasher ("MerpCrashNullFp", MerpCrashNul
, MerpCrashNullFp)); lFp));
Crashers.Add(new Tuple<String, Action> ("MerpCrashExcepti Crashers.Add(new Crasher ("MerpCrashExceptionHook", MerpC
onHook", MerpCrashUnhandledExceptionHook)); rashUnhandledExceptionHook));
// Specific Edge Cases // Specific Edge Cases
Crashers.Add(new Tuple<String, Action> ("MerpCrashDladdr" Crashers.Add(new Crasher ("MerpCrashDladdr", MerpCrashDla
, MerpCrashDladdr)); ddr));
Crashers.Add(new Tuple<String, Action> ("MerpCrashSnprint Crashers.Add(new Crasher ("MerpCrashSnprintf", MerpCrashS
f", MerpCrashSnprintf)); nprintf));
Crashers.Add(new Tuple<String, Action> ("MerpCrashDomainU Crashers.Add(new Crasher ("MerpCrashDomainUnload", MerpCr
nload", MerpCrashDomainUnload)); ashDomainUnload));
Crashers.Add(new Tuple<String, Action> ("MerpCrashUnbalan Crashers.Add(new Crasher ("MerpCrashUnbalancedGCSafe", Me
cedGCSafe", MerpCrashUnbalancedGCSafe)); rpCrashUnbalancedGCSafe));
} }
public static void public static void
MerpCrashManaged () MerpCrashManaged ()
{ {
unsafe { Console.WriteLine("{0}", *(int*) -1); } unsafe { Console.WriteLine("{0}", *(int*) -1); }
} }
const string failfastMsg = "abcd efgh";
public static void
MerpCrashFailFast ()
{
Environment.FailFast (failfastMsg);
}
public static void ValidateFailFastMsg (object json)
{
string s = jsonGetKeys (json, "payload", "failfast_messag
e") as string;
if (s != failfastMsg)
throw new ValidationException (String.Format ("in
correct fail fast message (expected: {0}, got: {1})", failfastMsg, s));
}
[DllImport("libtest")] [DllImport("libtest")]
public static extern void mono_test_MerpCrashSnprintf (); public static extern void mono_test_MerpCrashSnprintf ();
// This test tries to test the writer's reentrancy // This test tries to test the writer's reentrancy
public static void public static void
MerpCrashSnprintf () MerpCrashSnprintf ()
{ {
mono_test_MerpCrashSnprintf (); mono_test_MerpCrashSnprintf ();
} }
skipping to change at line 128 skipping to change at line 164
{ {
AppDomain.CurrentDomain.UnhandledException += new Unhandl edExceptionEventHandler(HandleException); AppDomain.CurrentDomain.UnhandledException += new Unhandl edExceptionEventHandler(HandleException);
throw new Exception ("This is Unhandled"); throw new Exception ("This is Unhandled");
} }
public static void HandleException (object sender, UnhandledExcep tionEventArgs e) public static void HandleException (object sender, UnhandledExcep tionEventArgs e)
{ {
Console.WriteLine ("And now to crash inside the hook"); Console.WriteLine ("And now to crash inside the hook");
mono_test_MerpCrashUnhandledExceptionHook (); mono_test_MerpCrashUnhandledExceptionHook ();
} }
private static object jsonGetKey (object o, string key) => (o as
Dictionary<string,object>)[key];
private static object jsonGetKeys (object o, params string[] keys
) {
try {
foreach (var key in keys) {
o = jsonGetKey (o, key);
}
return o;
} catch (KeyNotFoundException e) {
throw new ValidationException (String.Format ("{0
}, key not found, looking for key path [{1}]", e.ToString(), String.Join (", ",
keys)));
}
}
} }
static string configDir = "./merp-crash-test/"; static string configDir = "./merp-crash-test/";
public static void public static void
CrashWithMerp (int testNum) CrashWithMerp (int testNum)
{ {
SetupCrash (configDir); SetupCrash (configDir);
CrasherClass.Crashers [Convert.ToInt32 (testNum)].Item2 (); CrasherClass.Crashers [Convert.ToInt32 (testNum)].Action ();
} }
public static string env = Environment.GetEnvironmentVariable ("MONO_PATH "); public static string env = Environment.GetEnvironmentVariable ("MONO_PATH ");
public static string this_assembly_path = Path.GetDirectoryName (Assembly .GetExecutingAssembly ().Location); public static string this_assembly_path = Path.GetDirectoryName (Assembly .GetExecutingAssembly ().Location);
public static void public static void
SetupCrash (string configDir) SetupCrash (string configDir)
{ {
var monoType = Type.GetType ("Mono.Runtime", false); var monoType = Type.GetType ("Mono.Runtime", false);
var m = monoType.GetMethod("EnableMicrosoftTelemetry", BindingFla gs.NonPublic | BindingFlags.Static); var m = monoType.GetMethod("EnableMicrosoftTelemetry", BindingFla gs.NonPublic | BindingFlags.Static);
skipping to change at line 164 skipping to change at line 213
var eventType = "AppleAppCrash"; var eventType = "AppleAppCrash";
var appPath = "/where/mono/lives"; var appPath = "/where/mono/lives";
var m_params = new object[] { appBundleId, appSignature, appVersi on, merpGUIPath, eventType, appPath, configDir }; var m_params = new object[] { appBundleId, appSignature, appVersi on, merpGUIPath, eventType, appPath, configDir };
m.Invoke(null, m_params); m.Invoke(null, m_params);
DumpLogSet (); DumpLogSet ();
} }
public static void public static void
TestValidate (string configDir, bool silent) TestValidate (string configDir, bool silent, Action<object> validator = n ull)
{ {
DumpLogCheck (); DumpLogCheck ();
var xmlFilePath = String.Format("{0}CustomLogsMetadata.xml", conf igDir); var xmlFilePath = String.Format("{0}CustomLogsMetadata.xml", conf igDir);
var paramsFilePath = String.Format("{0}MERP.uploadparams.txt", co nfigDir); var paramsFilePath = String.Format("{0}MERP.uploadparams.txt", co nfigDir);
var crashFilePath = String.Format("{0}lastcrashlog.txt", configDi r); var crashFilePath = String.Format("{0}lastcrashlog.txt", configDi r);
// Fixme: Maybe parse these json files rather than // Fixme: Maybe parse these json files rather than
// just checking they exist // just checking they exist
var xmlFileExists = File.Exists (xmlFilePath); var xmlFileExists = File.Exists (xmlFilePath);
skipping to change at line 207 skipping to change at line 256
var crashFile = File.ReadAllText (crashFilePath); var crashFile = File.ReadAllText (crashFilePath);
File.Delete (crashFilePath); File.Delete (crashFilePath);
var checker = new JavaScriptSerializer (); var checker = new JavaScriptSerializer ();
// Throws if invalid json // Throws if invalid json
if (!silent) if (!silent)
Console.WriteLine("Validating: {0}", crashFile); Console.WriteLine("Validating: {0}", crashFile);
try { try {
var obj = checker.DeserializeObject (crashFile); var obj = checker.DeserializeObject (crashFile);
if (validator is object)
validator (obj);
} catch (CrasherClass.ValidationException e) {
throw new Exception (String.Format ("Validation f
ailed '{0}', json: {1}", e.Message, crashFile));
} catch (Exception e) { } catch (Exception e) {
throw new Exception (String.Format ("Invalid json : {0}", crashFile)); throw new Exception (String.Format ("Invalid json : {0}", crashFile));
} }
File.Delete (crashFilePath); File.Delete (crashFilePath);
// Assert it has the required merp fields // Assert it has the required merp fields
} else { } else {
Console.WriteLine ("Crash file {0} missing", crashFilePat h); Console.WriteLine ("Crash file {0} missing", crashFilePat h);
} }
skipping to change at line 273 skipping to change at line 326
SpawnCrashingRuntime (string runtime, int testNum, bool silent) SpawnCrashingRuntime (string runtime, int testNum, bool silent)
{ {
var asm = "merp-crash-test.exe"; var asm = "merp-crash-test.exe";
var pi = new Diag.ProcessStartInfo (); var pi = new Diag.ProcessStartInfo ();
pi.UseShellExecute = false; pi.UseShellExecute = false;
pi.FileName = runtime; pi.FileName = runtime;
pi.Arguments = String.Format ("{0} {1}", asm, testNum);; pi.Arguments = String.Format ("{0} {1}", asm, testNum);;
pi.Environment ["MONO_PATH"] = env; pi.Environment ["MONO_PATH"] = env;
if (!silent) { if (!silent) {
Console.WriteLine ("Running {0}", CrasherClass.Crashers [ testNum].Item1); Console.WriteLine ("Running {0}", CrasherClass.Crashers [ testNum].Name);
Console.WriteLine ("MONO_PATH={0} {1} {2} {3}", env, runt ime, asm, testNum); Console.WriteLine ("MONO_PATH={0} {1} {2} {3}", env, runt ime, asm, testNum);
} }
if (Directory.Exists (configDir)) { if (Directory.Exists (configDir)) {
Console.WriteLine ("Cleaning up left over configDir {0}", configDir); Console.WriteLine ("Cleaning up left over configDir {0}", configDir);
Cleanup (configDir); Cleanup (configDir);
} }
Directory.CreateDirectory (configDir); Directory.CreateDirectory (configDir);
try { try {
var process = Diag.Process.Start (pi); var process = Diag.Process.Start (pi);
process.WaitForExit (); process.WaitForExit ();
TestValidate (configDir, silent); TestValidate (configDir, silent, CrasherClass.Crashers [t estNum].Validator);
} finally { } finally {
Cleanup (configDir); Cleanup (configDir);
} }
} }
public static int Main (string [] args) public static int Main (string [] args)
{ {
if (args.Length == 0) { if (args.Length == 0) {
string processExe = Diag.Process.GetCurrentProcess ().Mai nModule.FileName; string processExe = Diag.Process.GetCurrentProcess ().Mai nModule.FileName;
if (processExe == null) if (processExe == null)
skipping to change at line 325 skipping to change at line 378
} }
} }
Console.WriteLine ("\n\n##################"); Console.WriteLine ("\n\n##################");
Console.WriteLine ("Merp Test Results:"); Console.WriteLine ("Merp Test Results:");
Console.WriteLine ("##################\n\n"); Console.WriteLine ("##################\n\n");
if (failure_count > 0) { if (failure_count > 0) {
for (int i=0; i < CrasherClass.Crashers.Count; i+ +) { for (int i=0; i < CrasherClass.Crashers.Count; i+ +) {
if (failures [i] != null) { if (failures [i] != null) {
Console.WriteLine ("Crash reporte r failed test {0}", CrasherClass.Crashers [i].Item1); Console.WriteLine ("Crash reporte r failed test {0}", CrasherClass.Crashers [i].Name);
Console.WriteLine ("Cause: {0}\n{ 1}\n", failures [i].Message, failures [i].StackTrace); Console.WriteLine ("Cause: {0}\n{ 1}\n", failures [i].Message, failures [i].StackTrace);
} }
} }
} }
if (failure_count > 0) if (failure_count > 0)
return 1; return 1;
Console.WriteLine ("\n\n##################"); Console.WriteLine ("\n\n##################");
Console.WriteLine ("Merp Stress Test:"); Console.WriteLine ("Merp Stress Test:");
 End of changes. 14 change blocks. 
22 lines changed or deleted 85 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)