private static int NumTimesOffsetCovered(int offset, MethodDefinitionBodyInstrumentationInfo info, int[] hits) { int coveredBranchesCount = 0; foreach (var outgoingBranchLabel in info.GetOutgoingBranchLabels(offset)) { //check whether any of the branches of this location are not covered //Here outgoing branch labels are again offsets only. if (outgoingBranchLabel < hits.Length && hits[outgoingBranchLabel] > 0) { coveredBranchesCount++; } } return(coveredBranchesCount); }
private void ReadInstructionCov(MethodDefinition method, int[] hits, MethodDefinitionBodyInstrumentationInfo info) { Instruction instruction; Method instantiate = null; bool logInstruction = false; if (method.FullName.StartsWith("System") || method.FullName.StartsWith("Microsoft.Pex.Framework")) { return; } try { instantiate = method.Instantiate(TypeEx.NoTypes, TypeEx.NoTypes); MethodBodyEx body; if (instantiate.TryGetBody(out body)) { foreach (var i in info.BasicBlockStartOffsets) { if (!basicBlockOffsets.ContainsKey(method.FullName)) { basicBlockOffsets[method.FullName] = new HashSet <int>(); } basicBlockOffsets[method.FullName].Add(i); } body.TryGetInstruction(0, out instruction); Converter <int, int> covConverter = info.GetInstructionCoverage(hits); int coveredTimes = covConverter.Invoke(0); int nextOffset = instruction.NextOffset; if (logInstruction) { Log.AppendLine("instruction: " + instruction.Offset.ToString("x") + " code: " + instruction.OpCode + " covered " + coveredTimes + " times " + " next: " + nextOffset.ToString("x")); } if (!instructionCov.ContainsKey(method.FullName)) { instructionCov[method.FullName] = new Dictionary <int, int>(); instructionCov[method.FullName][0] = coveredTimes; } else { instructionCov[method.FullName][0] = coveredTimes; } while (body.TryGetInstruction(nextOffset, out instruction)) { nextOffset = instruction.NextOffset; coveredTimes = covConverter.Invoke(nextOffset); if (logInstruction) { Log.AppendLine("instruction: " + instruction.Offset.ToString("x") + " code: " + instruction.OpCode + " covered " + coveredTimes + " times " + " next: " + nextOffset.ToString("x")); } instructionCov[method.FullName][instruction.Offset] = coveredTimes; } } } catch (Exception ex) { ErrorLog.AppendLine("error in ReadInstructionCov of method: " + method + "\n" + ex); return; } }
private void ReadInstructionCov(MethodDefinition method, int[] hits, MethodDefinitionBodyInstrumentationInfo info) { Instruction instruction; Method instantiate = null; bool logInstruction = false; if (method.FullName.StartsWith("System") || method.FullName.StartsWith("Microsoft.Pex.Framework")) { return; } try { instantiate = method.Instantiate(TypeEx.NoTypes, TypeEx.NoTypes); MethodBodyEx body; if (instantiate.TryGetBody(out body)) { foreach (var i in info.BasicBlockStartOffsets) { if (!basicBlockOffsets.ContainsKey(method.FullName)) { basicBlockOffsets[method.FullName] = new HashSet<int>(); } basicBlockOffsets[method.FullName].Add(i); } body.TryGetInstruction(0, out instruction); Converter<int, int> covConverter = info.GetInstructionCoverage(hits); int coveredTimes = covConverter.Invoke(0); int nextOffset = instruction.NextOffset; if (logInstruction) { Log.AppendLine("instruction: " + instruction.Offset.ToString("x") + " code: " + instruction.OpCode + " covered " + coveredTimes + " times " + " next: " + nextOffset.ToString("x")); } if (!instructionCov.ContainsKey(method.FullName)) { instructionCov[method.FullName] = new Dictionary<int, int>(); instructionCov[method.FullName][0] = coveredTimes; } else { instructionCov[method.FullName][0] = coveredTimes; } while (body.TryGetInstruction(nextOffset, out instruction)) { nextOffset = instruction.NextOffset; coveredTimes = covConverter.Invoke(nextOffset); if (logInstruction) { Log.AppendLine("instruction: " + instruction.Offset.ToString("x") + " code: " + instruction.OpCode + " covered " + coveredTimes + " times " + " next: " + nextOffset.ToString("x")); } instructionCov[method.FullName][instruction.Offset] = coveredTimes; } } } catch (Exception ex) { ErrorLog.AppendLine("error in ReadInstructionCov of method: " + method + "\n" + ex); return; } }
private static int NumTimesOffsetCovered(int offset, MethodDefinitionBodyInstrumentationInfo info, int[] hits) { int coveredBranchesCount = 0; foreach (var outgoingBranchLabel in info.GetOutgoingBranchLabels(offset)) { //check whether any of the branches of this location are not covered //Here outgoing branch labels are again offsets only. if (outgoingBranchLabel < hits.Length && hits[outgoingBranchLabel] > 0) { coveredBranchesCount++; } } return coveredBranchesCount; }