use of org.evosuite.instrumentation.coverage.DefUseInstrumentation 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);
}
Aggregations