use of org.evosuite.graphs.cfg.BytecodeInstruction in project evosuite by EvoSuite.
the class AllUsesAnalysis method useStoredInformationForMethodCall.
private Set<Map<String, VariableDefinition>> useStoredInformationForMethodCall(CCFGMethodEntryNode investigatedMethod, CCFGMethodCallNode callNode, Set<Map<String, VariableDefinition>> activeDefMapsInCaller, Set<BytecodeInstruction> freeUses, Set<DefUseCoverageTestFitness> foundPairs, MethodCall call) {
//
Set<BytecodeInstruction> freeUsesInCalledMethod = determinedFreeUses.get(callNode.getCalledMethod());
for (BytecodeInstruction freeUseInCalledMethod : freeUsesInCalledMethod) {
for (Map<String, VariableDefinition> activeDefMap : activeDefMapsInCaller) {
VariableDefinition activeDef = activeDefMap.get(freeUseInCalledMethod.getVariableName());
if (activeDef == null) {
// there was a path to the calledMethod that did not define
// the variable of our freeUse, so it is still free
freeUses.add(freeUseInCalledMethod);
} else {
// inter-method pair
if (freeUseInCalledMethod.isFieldUse()) {
addNewGoalToFoundPairs(investigatedMethod, activeDef, freeUseInCalledMethod, DefUsePairType.INTER_METHOD, foundPairs);
}
}
}
}
Set<Map<String, BytecodeInstruction>> activeDefMapsInCallee = determinedActiveDefs.get(callNode.getCalledMethod());
Set<Map<String, VariableDefinition>> activeDefMapsAfterCurrentCall = new HashSet<Map<String, VariableDefinition>>();
long start = System.currentTimeMillis();
// mingle each of these maps with each of the currently active maps
for (Map<String, BytecodeInstruction> activeDefMapInCallee : activeDefMapsInCallee) {
for (Map<String, VariableDefinition> activeDefMapInCaller : activeDefMapsInCaller) {
Set<String> relevantVariables = new HashSet<String>(activeDefMapInCallee.keySet());
relevantVariables.addAll(activeDefMapInCaller.keySet());
// mingle both activeDefMaps from prior to the call and when
// returning from call to a new one that will be true after the
// call
Map<String, VariableDefinition> activeDefMapAfterCurrentCall = new HashMap<String, VariableDefinition>();
for (String variable : relevantVariables) {
BytecodeInstruction activeDefAfterCall = activeDefMapInCallee.get(variable);
VariableDefinition activeDefPriorToCall = activeDefMapInCaller.get(variable);
if (activeDefAfterCall == null) {
if (activeDefPriorToCall == null)
throw new IllegalStateException("expect activeDefMaps not to map to null values");
// variable was not overwritten in called
// method, so the activeDef prior to the call stays
// active
activeDefMapAfterCurrentCall.put(variable, activeDefPriorToCall);
} else {
// variable was overwritten in call, so we will make a
// new VariableDefinition and keep that active in the
// newly created map
VariableDefinition overwritingDefinition = new VariableDefinition(activeDefAfterCall, call);
activeDefMapAfterCurrentCall.put(variable, overwritingDefinition);
}
}
// System.out.println("mingled map:");
// printVDDefMap(activeDefMapAfterCurrentCall);
activeDefMapsAfterCurrentCall.add(activeDefMapAfterCurrentCall);
}
}
// System.out.println("Finished mingling. #Resulting-Maps: "+activeDefMapsAfterCurrentCall.size());
timeSpentMingling += System.currentTimeMillis() - start;
return activeDefMapsAfterCurrentCall;
}
use of org.evosuite.graphs.cfg.BytecodeInstruction in project evosuite by EvoSuite.
the class AllUsesAnalysis method createIntraClassPairsForFreeUse.
private Set<DefUseCoverageTestFitness> createIntraClassPairsForFreeUse(BytecodeInstruction freeUse) {
checkFreeUseSanity(freeUse);
Set<DefUseCoverageTestFitness> r = new HashSet<DefUseCoverageTestFitness>();
for (String method : determinedActiveDefs.keySet()) {
if (!ccfg.isPublicMethod(method)) {
continue;
}
Set<Map<String, BytecodeInstruction>> activeDefss = determinedActiveDefs.get(method);
for (Map<String, BytecodeInstruction> activeDefs : activeDefss) {
// checkActiveDefsSanity(activeDefs);
// if (activeDefs.get(freeUse.getDUVariableName()) == null)
// continue;
BytecodeInstruction activeDef = activeDefs.get(freeUse.getVariableName());
if (activeDef == null)
continue;
addNewGoalToFoundPairs(null, activeDef, freeUse, DefUsePairType.INTRA_CLASS, r);
}
}
return r;
}
use of org.evosuite.graphs.cfg.BytecodeInstruction in project evosuite by EvoSuite.
the class DefUseCoverageTestFitness method getInstructionsBeforeGoalUse.
/**
* Returns a set containing all CFGVertices in the goal use method that come
* before the goal use.
*
* Look at ControlFlowGraph.getPreviousInstructionInMethod() for details
*
* @return a {@link java.util.Set} object.
*/
public Set<BytecodeInstruction> getInstructionsBeforeGoalUse() {
RawControlFlowGraph cfg = GraphPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getRawCFG(goalUse.getClassName(), goalUse.getMethodName());
BytecodeInstruction useVertex = cfg.getInstruction(goalUse.getInstructionId());
Set<BytecodeInstruction> r = cfg.getPreviousInstructionsInMethod(useVertex);
// }
return r;
}
use of org.evosuite.graphs.cfg.BytecodeInstruction in project evosuite by EvoSuite.
the class DefUseExecutionTraceAnalyzer method getOverwritingDefinitionsIn.
/**
* Returns a Set containing all elements in the given vertex set that are
* overwriting definitions for the given targetDefinition
*
* @param targetDefinition
* a {@link org.evosuite.coverage.dataflow.Definition} object.
* @param vertices
* a {@link java.util.Collection} object.
* @return a {@link java.util.Set} object.
*/
public static Set<BytecodeInstruction> getOverwritingDefinitionsIn(Definition targetDefinition, Collection<BytecodeInstruction> vertices) {
Set<BytecodeInstruction> r = new HashSet<BytecodeInstruction>();
for (BytecodeInstruction vertex : vertices) {
if (!vertex.isDefinition())
continue;
BytecodeInstruction vertexInOtherGraph = GraphPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getRawCFG(vertex.getClassName(), vertex.getMethodName()).getInstruction(vertex.getInstructionId());
Definition currentDefinition = DefUseFactory.makeDefinition(vertexInOtherGraph);
if (isOverwritingDefinition(targetDefinition, currentDefinition))
r.add(vertex);
}
return r;
}
use of org.evosuite.graphs.cfg.BytecodeInstruction in project evosuite by EvoSuite.
the class LCSAJsInstrumentation method addInstrumentation.
@SuppressWarnings("unchecked")
private void addInstrumentation(ClassLoader classLoader, MethodNode mn, String className, String methodName) {
RawControlFlowGraph graph = GraphPool.getInstance(classLoader).getRawCFG(className, methodName);
Iterator<AbstractInsnNode> j = mn.instructions.iterator();
while (j.hasNext()) {
AbstractInsnNode in = j.next();
for (BytecodeInstruction v : graph.vertexSet()) {
// If this is in the CFG and it's a branch...
if (in.equals(v.getASMNode())) {
if (v.isForcedBranch()) {
LCSAJPool.addLCSAJBranch(BranchPool.getInstance(classLoader).getBranchForInstruction(v));
int branchId = BranchPool.getInstance(classLoader).getActualBranchIdForNormalBranchInstruction(v);
InsnList instrumentation = new InsnList();
instrumentation.add(new LdcInsnNode(v.getASMNode().getOpcode()));
instrumentation.add(new LdcInsnNode(branchId));
instrumentation.add(new LdcInsnNode(v.getInstructionId()));
instrumentation.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "org/evosuite/testcase/ExecutionTracer", "passedUnconditionalBranch", "(III)V"));
if (v.isLabel())
mn.instructions.insert(v.getASMNode(), instrumentation);
else
mn.instructions.insertBefore(v.getASMNode(), instrumentation);
}
}
}
}
}
Aggregations