Search in sources :

Example 1 with BytecodeInstruction

use of org.evosuite.graphs.cfg.BytecodeInstruction in project evosuite by EvoSuite.

the class AllUsesAnalysis method handleFieldCallNode.

private void handleFieldCallNode(CCFGMethodEntryNode investigatedMethod, CCFGNode node, Stack<MethodCall> callStack, Set<Map<String, VariableDefinition>> activeDefs, Set<BytecodeInstruction> freeUses, Set<DefUseCoverageTestFitness> foundPairs) {
    BytecodeInstruction code = ((CCFGCodeNode) node).getCodeInstruction();
    // LoggingUtils.getEvoLogger().debug(
    // "Processing field call: " + node.toString());
    handleDefUse(investigatedMethod, code, callStack, activeDefs, freeUses, foundPairs);
}
Also used : CCFGCodeNode(org.evosuite.graphs.ccfg.CCFGCodeNode) BytecodeInstruction(org.evosuite.graphs.cfg.BytecodeInstruction)

Example 2 with BytecodeInstruction

use of org.evosuite.graphs.cfg.BytecodeInstruction in project evosuite by EvoSuite.

the class AllUsesAnalysis method handleCodeNode.

private void handleCodeNode(CCFGMethodEntryNode investigatedMethod, CCFGNode node, Stack<MethodCall> callStack, Set<Map<String, VariableDefinition>> activeDefs, Set<BytecodeInstruction> freeUses, Set<DefUseCoverageTestFitness> foundPairs) {
    BytecodeInstruction code = ((CCFGCodeNode) node).getCodeInstruction();
    handleDefUse(investigatedMethod, code, callStack, activeDefs, freeUses, foundPairs);
}
Also used : CCFGCodeNode(org.evosuite.graphs.ccfg.CCFGCodeNode) BytecodeInstruction(org.evosuite.graphs.cfg.BytecodeInstruction)

Example 3 with BytecodeInstruction

use of org.evosuite.graphs.cfg.BytecodeInstruction in project evosuite by EvoSuite.

the class DefUseCoverageFactory method categorizeFieldMethodCalls.

/**
 * Determines for all method calls on fields of the CUT whether the call is
 * to a pure or impure method. For these calls Uses and Definitions are
 * created respectively.
 *
 * Since purity analysis is used here and requires all classes along the
 * call tree to be completely analyzed this part of the CUT analysis can not
 * be done in the CFGMethodAdapter like the rest of it.
 */
private static void categorizeFieldMethodCalls() {
    Set<BytecodeInstruction> fieldMethodCalls = DefUsePool.retrieveFieldMethodCalls();
    LoggingUtils.getEvoLogger().info("Categorizing field method calls: " + fieldMethodCalls.size());
    for (BytecodeInstruction fieldMethodCall : fieldMethodCalls) {
        if (GraphPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).canMakeCCFGForClass(fieldMethodCall.getCalledMethodsClass())) {
            ClassControlFlowGraph ccfg = GraphPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getCCFG(fieldMethodCall.getCalledMethodsClass());
            if (ccfg.isPure(fieldMethodCall.getCalledMethod())) {
                if (!DefUsePool.addAsUse(fieldMethodCall))
                    throw new IllegalStateException("unable to register field method call as a use " + fieldMethodCall.toString());
            } else {
                if (!DefUsePool.addAsDefinition(fieldMethodCall))
                    throw new IllegalStateException("unable to register field method call as a definition " + fieldMethodCall.toString());
            }
        } else {
            String toAnalyze = fieldMethodCall.getCalledMethodsClass() + "." + fieldMethodCall.getCalledMethodName();
            if (toAnalyze != null && toAnalyze.startsWith("java.")) {
                Type[] parameters = org.objectweb.asm.Type.getArgumentTypes(fieldMethodCall.getMethodCallDescriptor());
                String newParams = "";
                if (parameters.length != 0) {
                    for (Type i : parameters) {
                        newParams = newParams + "," + i.getClassName();
                    }
                    newParams = newParams.substring(1, newParams.length());
                }
                toAnalyze = fieldMethodCall.getCalledMethodsClass() + "." + fieldMethodCall.getCalledMethodName() + "(" + newParams + ")";
                if (JdkPureMethodsList.instance.checkPurity(toAnalyze)) {
                    if (!DefUsePool.addAsUse(fieldMethodCall))
                        throw new IllegalStateException("unable to register field method call as a use " + fieldMethodCall.toString());
                } else {
                    if (!DefUsePool.addAsDefinition(fieldMethodCall))
                        throw new IllegalStateException("unable to register field method call as a definition " + fieldMethodCall.toString());
                }
            } else {
                if (!DefUsePool.addAsUse(fieldMethodCall))
                    throw new IllegalStateException("unable to register field method call as a use " + fieldMethodCall.toString());
            }
        }
    }
}
Also used : ClassControlFlowGraph(org.evosuite.graphs.ccfg.ClassControlFlowGraph) DefUsePairType(org.evosuite.coverage.dataflow.DefUseCoverageTestFitness.DefUsePairType) Type(org.objectweb.asm.Type) BytecodeInstruction(org.evosuite.graphs.cfg.BytecodeInstruction)

Example 4 with BytecodeInstruction

use of org.evosuite.graphs.cfg.BytecodeInstruction in project evosuite by EvoSuite.

the class DefUseCoverageTestFitness method getInstructionsAfterGoalDefinition.

/**
 * Returns a set containing all CFGVertices in the goal definition method
 * that come after the definition.
 *
 * Look at ControlFlowGraph.getLaterInstructionInMethod() for details
 *
 * @return a {@link java.util.Set} object.
 */
public Set<BytecodeInstruction> getInstructionsAfterGoalDefinition() {
    RawControlFlowGraph cfg = GraphPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getRawCFG(goalDefinition.getClassName(), goalDefinition.getMethodName());
    BytecodeInstruction defVertex = cfg.getInstruction(goalDefinition.getInstructionId());
    Set<BytecodeInstruction> r = cfg.getLaterInstructionsInMethod(defVertex);
    // }
    return r;
}
Also used : BytecodeInstruction(org.evosuite.graphs.cfg.BytecodeInstruction) RawControlFlowGraph(org.evosuite.graphs.cfg.RawControlFlowGraph)

Example 5 with BytecodeInstruction

use of org.evosuite.graphs.cfg.BytecodeInstruction in project evosuite by EvoSuite.

the class BooleanTestabilityTransformation method getBranchID.

private int getBranchID(MethodNode mn, JumpInsnNode jumpNode) {
    assert (mn.instructions.contains(jumpNode));
    BytecodeInstruction insn = getBytecodeInstruction(mn, jumpNode);
    logger.info("Found instruction: " + insn);
    Branch branch = BranchPool.getInstance(classLoader).getBranchForInstruction(insn);
    return branch.getActualBranchId();
}
Also used : Branch(org.evosuite.coverage.branch.Branch) BytecodeInstruction(org.evosuite.graphs.cfg.BytecodeInstruction)

Aggregations

BytecodeInstruction (org.evosuite.graphs.cfg.BytecodeInstruction)28 RawControlFlowGraph (org.evosuite.graphs.cfg.RawControlFlowGraph)10 AbstractInsnNode (org.objectweb.asm.tree.AbstractInsnNode)6 ControlDependency (org.evosuite.graphs.cfg.ControlDependency)5 InsnList (org.objectweb.asm.tree.InsnList)5 HashSet (java.util.HashSet)4 LabelNode (org.objectweb.asm.tree.LabelNode)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Branch (org.evosuite.coverage.branch.Branch)3 VarInsnNode (org.objectweb.asm.tree.VarInsnNode)3 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 CCFGCodeNode (org.evosuite.graphs.ccfg.CCFGCodeNode)2 ControlDependenceGraph (org.evosuite.graphs.cdg.ControlDependenceGraph)2 BasicBlock (org.evosuite.graphs.cfg.BasicBlock)2 ControlFlowEdge (org.evosuite.graphs.cfg.ControlFlowEdge)2 AnnotatedLabel (org.evosuite.runtime.instrumentation.AnnotatedLabel)2 Label (org.objectweb.asm.Label)2 FieldInsnNode (org.objectweb.asm.tree.FieldInsnNode)2