public void SelfCover() { Environment.SetEnvironmentVariable("BABOON_CFG", "testsubject.exe.covcfg"); var h = CoverHostFactory.CreateHost("self.exe.covdb", "covem.exe", "testsubject.exe"); h.Cover(null, null, "assembly:XR.Mono.Cover"); }
public static int Main(string[] vargs) { if (vargs.Length == 0) { return(Usage()); } if (Regex.IsMatch(vargs[0], "-h$|-help$")) { return(Usage()); } if (!System.IO.File.Exists(vargs[0])) { return(Usage()); } // the first thing is the mono EXE we are running, everything else are args passed to it // we do no argument processing at all. var program = vargs[0]; var args = vargs.Skip(1); var patterns = new List <string> (); // we look in BABOON_CFG for a config file var env = Environment.GetEnvironmentVariable("BABOON_CFG"); // else we look for a file in the same folder as the EXE named EXE.covcfg var cfgfile = program + ".covcfg"; if (!string.IsNullOrEmpty(env)) { cfgfile = env; } if (File.Exists(cfgfile)) { using (var f = File.OpenText(cfgfile)) { string l = null; do { l = f.ReadLine(); if (!string.IsNullOrWhiteSpace(l)) { patterns.Add(l); } } while (l != null); } } CoverHost.RenameBackupFile(cfgfile + ".covdb"); CoverHost.RenameBackupFile(cfgfile + ".covreport"); covertool = CoverHostFactory.CreateHost(cfgfile + ".covdb", program, args.ToArray()); covertool.DataStore.SaveMeta("config", cfgfile); debugee = covertool.VirtualMachine.Process; ThreadPool.QueueUserWorkItem((x) => SignalHandler(), null); ThreadPool.QueueUserWorkItem((x) => PumpStdin(x), null); covertool.Cover(patterns.ToArray()); covertool.Report(cfgfile + ".covreport"); return(covertool.VirtualMachine.Process.ExitCode); }
public static int Main(string[] vargs) { var attach = false; var index = 0; string invokeMethod = null; string invokeThread = null; string terminatorMethod = null; while (index < vargs.Length) { if (Regex.IsMatch(vargs[index], "-h$|-help$")) { return(Usage()); } if (!Regex.IsMatch(vargs[index], "-a$|-attach$")) { break; } attach = true; index++; } // the first thing is the mono EXE we are running, everything else are args passed to it // we do no argument processing at all. var program = vargs[index]; var patterns = new List <string> (); // we look in BABOON_CFG for a config file var env = Environment.GetEnvironmentVariable("BABOON_CFG"); // else we look for a file in the same folder as the EXE named EXE.covcfg var cfgfile = program + ".covcfg"; if (!string.IsNullOrEmpty(env)) { cfgfile = env; } bool hitCount = true; if (File.Exists(cfgfile)) { using (var f = File.OpenText(cfgfile)) { string l = null; do { l = f.ReadLine(); if (string.IsNullOrWhiteSpace(l)) { continue; } if (l.StartsWith("$HitCount=")) { l = l.Substring("$HitCount=".Length); bool.TryParse(l, out hitCount); continue; } if (l.StartsWith("$InvokeMethod=")) { invokeMethod = l.Substring("$InvokeMethod=".Length); continue; } if (l.StartsWith("$InvokeThread=")) { invokeThread = l.Substring("$InvokeThread=".Length); continue; } if (l.StartsWith("$TerminatorMethod=")) { terminatorMethod = l.Substring("$TerminatorMethod=".Length); continue; } patterns.Add(l); } while (l != null); } } CoverHost.RenameBackupFile(cfgfile + ".covdb"); CoverHost.RenameBackupFile(cfgfile + ".covreport"); CoverHost covertool; Timer timer; if (attach) { if (!IPAddress.TryParse(vargs[index + 1], out var ip)) { return(Usage()); } if (!int.TryParse(vargs[index + 2], out var port)) { return(Usage()); } covertool = CoverHostFactory.CreateHost(cfgfile + ".covdb", new IPEndPoint(ip, port)); } else { if (!System.IO.File.Exists(program)) { return(Usage()); } var args = vargs.Skip(index); covertool = CoverHostFactory.CreateHost(cfgfile + ".covdb", program, args.ToArray()); debugee = covertool.VirtualMachine.Process; ThreadPool.QueueUserWorkItem((x) => PumpStdin(x), null); } covertool.DataStore.SaveMeta("config", cfgfile); covertool.HitCount = hitCount; covertool.TerminatorMethod = terminatorMethod; MainClass.covertool = covertool; if (Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX) { ThreadPool.QueueUserWorkItem((x) => SignalHandler(), null); timer = null; } else { Console.CancelKeyPress += CancelEventHandler; timer = new Timer(state => MainClass.covertool?.SaveData(), null, 0, 1000); } try { covertool.Cover(invokeMethod, invokeThread, patterns.ToArray()); } finally { MainClass.covertool = null; if (timer != null) { timer.Dispose(); Console.CancelKeyPress -= CancelEventHandler; } } covertool.Report(cfgfile + ".covreport"); return(attach ? 0 : covertool.VirtualMachine.Process.ExitCode); }