use of org.evosuite.graphs.cdg.ControlDependenceGraph in project evosuite by EvoSuite.
the class ImplicitElseTransformer method transformVarInsnNode.
/* (non-Javadoc)
* @see org.evosuite.instrumentation.MethodNodeTransformer#transformVarInsnNode(org.objectweb.asm.tree.MethodNode, org.objectweb.asm.tree.VarInsnNode)
*/
@Override
protected AbstractInsnNode transformVarInsnNode(MethodNode mn, VarInsnNode varNode) {
if (varNode.getOpcode() == Opcodes.ISTORE && this.booleanTestabilityTransformation.isBooleanVariable(varNode.var, mn)) {
// Check if ICONST_0 or ICONST_1 are on the stack
ControlDependenceGraph cdg = GraphPool.getInstance(this.booleanTestabilityTransformation.classLoader).getCDG(this.booleanTestabilityTransformation.className.replace("/", "."), mn.name + mn.desc);
int index = mn.instructions.indexOf(varNode);
BytecodeInstruction insn = BytecodeInstructionPool.getInstance(this.booleanTestabilityTransformation.classLoader).getInstruction(this.booleanTestabilityTransformation.className.replace("/", "."), mn.name + mn.desc, index);
// varNode);
if (insn == null) {
// TODO: Debug this on org.exolab.jms.net.uri.URI
BooleanTestabilityTransformation.logger.info("WARNING: Instruction not found!");
return varNode;
}
if (insn.getASMNode().getOpcode() != varNode.getOpcode()) {
BooleanTestabilityTransformation.logger.info("Found wrong bytecode instruction at this index!");
insn = BytecodeInstructionPool.getInstance(this.booleanTestabilityTransformation.classLoader).getInstruction(this.booleanTestabilityTransformation.className, mn.name + mn.desc, varNode);
if (insn == null) {
// TODO: Debug this on org.exolab.jms.net.uri.URI
BooleanTestabilityTransformation.logger.info("WARNING: Instruction not found!");
return varNode;
}
}
Set<ControlDependency> dependencies = insn.getControlDependencies();
BooleanTestabilityTransformation.logger.info("Found flag assignment: " + insn + ", checking " + dependencies.size() + " control dependencies");
for (ControlDependency dep : dependencies) {
if (!addedNodes.contains(dep))
handleDependency(dep, cdg, mn, varNode, insn);
}
// Only do completion if there's only one dependency
// Not sure how other cases would look like
/*
//if (dependencies.size() > 1)
// return varNode;
//else
if (dependencies.isEmpty())
return varNode;
ControlDependency dep = dependencies.iterator().next();
if (!addedNodes.contains(dep))
handleDependency(dep, cdg, mn, varNode, insn);
*/
}
return varNode;
}
use of org.evosuite.graphs.cdg.ControlDependenceGraph in project evosuite by EvoSuite.
the class ImplicitElseTransformer method transformFieldInsnNode.
/* (non-Javadoc)
* @see org.evosuite.instrumentation.MethodNodeTransformer#transformFieldInsnNode(org.objectweb.asm.tree.MethodNode, org.objectweb.asm.tree.FieldInsnNode)
*/
@SuppressWarnings("unchecked")
@Override
protected AbstractInsnNode transformFieldInsnNode(MethodNode mn, FieldInsnNode fieldNode) {
if ((fieldNode.getOpcode() == Opcodes.PUTFIELD || fieldNode.getOpcode() == Opcodes.PUTSTATIC) && DescriptorMapping.getInstance().isTransformedOrBooleanField(fieldNode.owner, fieldNode.name, fieldNode.desc)) {
if (addedInsns.contains(fieldNode))
return fieldNode;
// whether we need to pop one or two words
if (fieldNode.getOpcode() == Opcodes.PUTFIELD) {
AbstractInsnNode previous = fieldNode.getPrevious();
while (previous instanceof LineNumberNode || previous instanceof FrameNode || previous.getOpcode() == Opcodes.ICONST_0 || previous.getOpcode() == Opcodes.ICONST_1) previous = previous.getPrevious();
if (previous.getOpcode() != Opcodes.ALOAD) {
BooleanTestabilityTransformation.logger.info("Can't handle case of " + previous);
return fieldNode;
}
VarInsnNode varNode = (VarInsnNode) previous;
if (varNode.var != 0) {
BooleanTestabilityTransformation.logger.info("Can't handle case of " + previous);
return fieldNode;
}
}
BooleanTestabilityTransformation.logger.info("Handling PUTFIELD case!");
// Check if ICONST_0 or ICONST_1 are on the stack
ControlDependenceGraph cdg = GraphPool.getInstance(this.booleanTestabilityTransformation.classLoader).getCDG(this.booleanTestabilityTransformation.className.replace("/", "."), mn.name + mn.desc);
int index = mn.instructions.indexOf(fieldNode);
BooleanTestabilityTransformation.logger.info("Getting bytecode instruction for " + fieldNode.name + "/" + ((FieldInsnNode) mn.instructions.get(index)).name);
InsnList nodes = mn.instructions;
ListIterator<AbstractInsnNode> it = nodes.iterator();
while (it.hasNext()) {
BytecodeInstruction in = new BytecodeInstruction(this.booleanTestabilityTransformation.classLoader, this.booleanTestabilityTransformation.className, mn.name, 0, 0, it.next());
BooleanTestabilityTransformation.logger.info(in.toString());
}
BytecodeInstruction insn = BytecodeInstructionPool.getInstance(this.booleanTestabilityTransformation.classLoader).getInstruction(this.booleanTestabilityTransformation.className.replace("/", "."), mn.name + mn.desc, index);
if (insn == null)
insn = BytecodeInstructionPool.getInstance(this.booleanTestabilityTransformation.classLoader).getInstruction(this.booleanTestabilityTransformation.className.replace("/", "."), mn.name + mn.desc, fieldNode);
// varNode);
if (insn == null) {
// TODO: Find out why
BooleanTestabilityTransformation.logger.info("ERROR: Could not find node");
return fieldNode;
}
if (insn.getASMNode().getOpcode() != fieldNode.getOpcode()) {
BooleanTestabilityTransformation.logger.info("Found wrong bytecode instruction at this index!");
BytecodeInstructionPool.getInstance(this.booleanTestabilityTransformation.classLoader).getInstruction(this.booleanTestabilityTransformation.className, mn.name + mn.desc, fieldNode);
}
if (insn.getBasicBlock() == null) {
BooleanTestabilityTransformation.logger.info("ERROR: Problematic node found");
return fieldNode;
}
Set<ControlDependency> dependencies = insn.getControlDependencies();
BooleanTestabilityTransformation.logger.info("Found flag assignment: " + insn + ", checking " + dependencies.size() + " control dependencies");
for (ControlDependency dep : dependencies) {
if (!addedNodes.contains(dep))
handleDependency(dep, cdg, mn, fieldNode, insn);
}
}
return fieldNode;
}
use of org.evosuite.graphs.cdg.ControlDependenceGraph in project evosuite by EvoSuite.
the class BasicBlock method getControlDependentBranchIds.
/**
* Returns all branchIds of Branches this instruction is directly control
* dependent on as determined by the ControlDependenceGraph for this
* instruction's method.
*
* If this instruction is control dependent on the root branch the id -1
* will be contained in this set
*
* @return a {@link java.util.Set} object.
*/
public Set<Integer> getControlDependentBranchIds() {
ControlDependenceGraph myDependence = getCDG();
if (controlDependentBranchIDs == null) {
controlDependentBranchIDs = myDependence.getControlDependentBranchIds(this);
// be sure we can iterate over it deterministically
controlDependentBranchIDs = controlDependentBranchIDs.stream().sorted().collect(Collectors.toCollection(LinkedHashSet::new));
}
return controlDependentBranchIDs;
}
use of org.evosuite.graphs.cdg.ControlDependenceGraph in project evosuite by EvoSuite.
the class GraphPool method createAndRegisterControlDependence.
private void createAndRegisterControlDependence(ActualControlFlowGraph cfg) {
ControlDependenceGraph cd = new ControlDependenceGraph(cfg);
String className = cd.getClassName();
String methodName = cd.getMethodName();
if (className == null || methodName == null)
throw new IllegalStateException("expect class and method name of CFGs to be set before entering the GraphPool");
if (!controlDependencies.containsKey(className))
controlDependencies.put(className, new HashMap<String, ControlDependenceGraph>());
Map<String, ControlDependenceGraph> cds = controlDependencies.get(className);
cds.put(methodName, cd);
if (Properties.WRITE_CFG)
cd.toDot();
}
Aggregations