Search in sources :

Example 1 with MutationInstrumentation

use of org.evosuite.instrumentation.coverage.MutationInstrumentation in project evosuite by EvoSuite.

the class CFGMethodAdapter method visitEnd.

/**
 * {@inheritDoc}
 */
@Override
public void visitEnd() {
    logger.debug("Creating CFG of " + className + "." + methodName);
    boolean isExcludedMethod = excludeMethod || EXCLUDE.contains(methodName);
    boolean isMainMethod = plain_name.equals("main") && Modifier.isStatic(access);
    List<MethodInstrumentation> instrumentations = new ArrayList<MethodInstrumentation>();
    if (DependencyAnalysis.shouldInstrument(className, methodName)) {
        if (ArrayUtil.contains(Properties.CRITERION, Criterion.DEFUSE) || ArrayUtil.contains(Properties.CRITERION, Criterion.ALLDEFS)) {
            instrumentations.add(new BranchInstrumentation());
            instrumentations.add(new DefUseInstrumentation());
        } else if (ArrayUtil.contains(Properties.CRITERION, Criterion.MUTATION) || ArrayUtil.contains(Properties.CRITERION, Criterion.WEAKMUTATION) || ArrayUtil.contains(Properties.CRITERION, Criterion.ONLYMUTATION) || ArrayUtil.contains(Properties.CRITERION, Criterion.STRONGMUTATION)) {
            instrumentations.add(new BranchInstrumentation());
            instrumentations.add(new MutationInstrumentation());
        } else {
            instrumentations.add(new BranchInstrumentation());
        }
    } else {
    // instrumentations.add(new BranchInstrumentation());
    }
    boolean executeOnMain = false;
    boolean executeOnExcluded = false;
    for (MethodInstrumentation instrumentation : instrumentations) {
        executeOnMain = executeOnMain || instrumentation.executeOnMainMethod();
        executeOnExcluded = executeOnExcluded || instrumentation.executeOnExcludedMethods();
    }
    // super.visitEnd();
    // Generate CFG of method
    MethodNode mn = (AnnotatedMethodNode) mv;
    boolean checkForMain = false;
    if (Properties.CONSIDER_MAIN_METHODS) {
        checkForMain = true;
    } else {
        checkForMain = !isMainMethod || executeOnMain;
    }
    // MethodInstrumentation wants it anyway)
    if (checkForMain && (!isExcludedMethod || executeOnExcluded) && (access & Opcodes.ACC_ABSTRACT) == 0 && (access & Opcodes.ACC_NATIVE) == 0) {
        logger.info("Analyzing method " + methodName + " in class " + className);
        // MethodNode mn = new CFGMethodNode((MethodNode)mv);
        // System.out.println("Generating CFG for "+ className+"."+mn.name +
        // " ("+mn.desc +")");
        BytecodeAnalyzer bytecodeAnalyzer = new BytecodeAnalyzer();
        logger.info("Generating CFG for method " + methodName);
        try {
            bytecodeAnalyzer.analyze(classLoader, className, methodName, mn);
            logger.trace("Method graph for " + className + "." + methodName + " contains " + bytecodeAnalyzer.retrieveCFGGenerator().getRawGraph().vertexSet().size() + " nodes for " + bytecodeAnalyzer.getFrames().length + " instructions");
            // compute Raw and ActualCFG and put both into GraphPool
            bytecodeAnalyzer.retrieveCFGGenerator().registerCFGs();
            logger.info("Created CFG for method " + methodName);
            if (DependencyAnalysis.shouldInstrument(className, methodName)) {
                if (!methods.get(classLoader).containsKey(className))
                    methods.get(classLoader).put(className, new HashSet<String>());
                // add the actual instrumentation
                logger.info("Instrumenting method " + methodName + " in class " + className);
                for (MethodInstrumentation instrumentation : instrumentations) instrumentation.analyze(classLoader, mn, className, methodName, access);
                handleBranchlessMethods();
                String id = className + "." + methodName;
                if (isUsable()) {
                    methods.get(classLoader).get(className).add(id);
                    logger.debug("Counting: " + id);
                }
            }
        } catch (AnalyzerException e) {
            logger.error("Analyzer exception while analyzing " + className + "." + methodName + ": " + e);
            e.printStackTrace();
        }
    } else {
        logger.debug("NOT Creating CFG of " + className + "." + methodName + ": " + checkForMain + ", " + ((!isExcludedMethod || executeOnExcluded)) + ", " + ((access & Opcodes.ACC_ABSTRACT) == 0) + ", " + ((access & Opcodes.ACC_NATIVE) == 0));
        super.visitEnd();
    }
    mn.accept(next);
}
Also used : AnalyzerException(org.objectweb.asm.tree.analysis.AnalyzerException) ArrayList(java.util.ArrayList) MethodInstrumentation(org.evosuite.instrumentation.coverage.MethodInstrumentation) MutationInstrumentation(org.evosuite.instrumentation.coverage.MutationInstrumentation) MethodNode(org.objectweb.asm.tree.MethodNode) AnnotatedMethodNode(org.evosuite.runtime.instrumentation.AnnotatedMethodNode) BranchInstrumentation(org.evosuite.instrumentation.coverage.BranchInstrumentation) DefUseInstrumentation(org.evosuite.instrumentation.coverage.DefUseInstrumentation) AnnotatedMethodNode(org.evosuite.runtime.instrumentation.AnnotatedMethodNode) HashSet(java.util.HashSet)

Aggregations

ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 BranchInstrumentation (org.evosuite.instrumentation.coverage.BranchInstrumentation)1 DefUseInstrumentation (org.evosuite.instrumentation.coverage.DefUseInstrumentation)1 MethodInstrumentation (org.evosuite.instrumentation.coverage.MethodInstrumentation)1 MutationInstrumentation (org.evosuite.instrumentation.coverage.MutationInstrumentation)1 AnnotatedMethodNode (org.evosuite.runtime.instrumentation.AnnotatedMethodNode)1 MethodNode (org.objectweb.asm.tree.MethodNode)1 AnalyzerException (org.objectweb.asm.tree.analysis.AnalyzerException)1