public static void ApplyMapping(SourceCodeLocation stmt, ValueMapping vm) { IsSaving = false; CurrentStatement = stmt; AlternateMapping = vm; counts = new Dictionary<SourceCodeLocation, uint>(); }
public bool Contains(SourceCodeLocation other) { if(!String.Equals(FileName, other.FileName)) return false; var startsBefore = (StartLine < other.StartLine || (StartLine == other.StartLine && StartColumn <= other.StartColumn)); var endsAfter = (EndLine > other.EndLine || (EndLine == other.EndLine && EndColumn >= other.EndColumn)); return startsBefore && endsAfter; }
public static ValueMapping GetCurrentMapping(SourceCodeLocation stmt) { ValueProfile vp; if(!profiles.TryGetValue(stmt, out vp)) { return null; } return vp.GetMapping(CurrentTestName); }
public static IEnumerable<ValueMapping> GetAlternateMappings(SourceCodeLocation stmt) { ValueProfile vp; if(!profiles.TryGetValue(stmt, out vp)) { return Enumerable.Empty<ValueMapping>(); } return vp.AlternateMappings(CurrentTestName); }
private static void SaveValue(SourceCodeLocation stmt, int key, Type t, object value) { ValueProfile profile; if(!profiles.TryGetValue(stmt, out profile)) { profile = new ValueProfile(); profiles[stmt] = profile; } profile.AddValue(CurrentTestName, key, new Value{Type = t, Val = value}); }
public static IEnumerable<StatementSuspiciousnessInfo> BuildDiagnosisMatrix(IEnumerable<ExecutedTest> tests) { var testedLines = new Dictionary<SourceCodeLocation, StatementSuspiciousnessInfo>(); uint passed = 0; uint failed = 0; foreach(var test in tests) { Console.WriteLine(test); if(test.Result) passed++; else failed++; CoverageDS data = test.CoverageData; foreach(var line in test.Lines) { var location = new SourceCodeLocation(data.SourceFileNames.Where(s => s.SourceFileID == line.SourceFileID).Select(s => s.SourceFileName).First(), (int) line.LnStart, (int) line.LnEnd, (int) line.ColStart, (int) line.ColEnd); StatementSuspiciousnessInfo currentLine; if(!testedLines.TryGetValue(location, out currentLine)) { currentLine = new StatementSuspiciousnessInfo(location); testedLines.Add(location, currentLine); } currentLine.Tests.Add(test); } test.ClearCoverageData(); } return testedLines.Values; }
public StatementSuspiciousnessInfo(SourceCodeLocation id) { this.Id = id; Tests = new List<ExecutedTest>(); SuspiciousnessRatings = new Dictionary<ISuspiciousnessRater, float>(); }
public static object Instrument(object value, String FileName, int lineStart, int lineEnd, int colStart, int colEnd, int id) { SourceCodeLocation location = new SourceCodeLocation(FileName, lineStart, lineEnd, colStart, colEnd); if(counts.ContainsKey(location)) { counts[location]++; } else { counts[location] = 1; } if(counts[location] > 20000) { throw new Exception("Value Replacement infinite loop"); } if(counts[location] > 10000) { return value; } try { if(IsSaving || !CurrentStatement.Contains(location)) { if(IsSaving) SaveValue(location, id, value == null ? null : value.GetType(), value); return value; } else { Value saved; if(!AlternateMapping.TryGetValue(id, out saved)) { return value; } else { return saved.Val; } } } catch(Exception) { //if anything goes wrong just return the value return value; } }
public IVMP(SourceCodeLocation loc, ValueMapping s, ValueMapping f) { _location = loc; _succeedingProfile = s; _failingProfile = f; }