use of org.evosuite.coverage.MethodNameMatcher in project evosuite by EvoSuite.
the class OnlyBranchCoverageFactory method getCoverageGoals.
/*
* (non-Javadoc)
*
* @see
* org.evosuite.coverage.TestCoverageFactory#getCoverageGoals()
*/
/**
* {@inheritDoc}
*/
@Override
public List<OnlyBranchCoverageTestFitness> getCoverageGoals() {
long start = System.currentTimeMillis();
List<OnlyBranchCoverageTestFitness> goals = new ArrayList<OnlyBranchCoverageTestFitness>();
// logger.info("Getting branches");
for (String className : BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).knownClasses()) {
if (!Properties.TARGET_CLASS.equals("") && !className.equals(Properties.TARGET_CLASS))
continue;
final MethodNameMatcher matcher = new MethodNameMatcher();
// Branches
for (String methodName : BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).knownMethods(className)) {
if (!matcher.methodMatches(methodName)) {
logger.info("Method " + methodName + " does not match criteria. ");
continue;
}
for (Branch b : BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).retrieveBranchesInMethod(className, methodName)) {
if (!b.isInstrumented()) {
goals.add(createOnlyBranchCoverageTestFitness(b, true));
// if (!b.isSwitchCaseBranch())
goals.add(createOnlyBranchCoverageTestFitness(b, false));
}
}
}
}
goalComputationTime = System.currentTimeMillis() - start;
return goals;
}
use of org.evosuite.coverage.MethodNameMatcher in project evosuite by EvoSuite.
the class TryCatchCoverageFactory method getCoverageGoals.
/*
* (non-Javadoc)
*
* @see
* org.evosuite.coverage.TestCoverageFactory#getCoverageGoals()
*/
/**
* {@inheritDoc}
*/
@Override
public List<TryCatchCoverageTestFitness> getCoverageGoals() {
List<TryCatchCoverageTestFitness> goals = new ArrayList<>();
// logger.info("Getting branches");
for (String className : BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).knownClasses()) {
final MethodNameMatcher matcher = new MethodNameMatcher();
// Branches
for (String methodName : BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).knownMethods(className)) {
if (!matcher.methodMatches(methodName)) {
logger.info("Method " + methodName + " does not match criteria. ");
continue;
}
for (Branch b : BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).retrieveBranchesInMethod(className, methodName)) {
if (b.isInstrumented()) {
goals.add(new TryCatchCoverageTestFitness(new BranchCoverageGoal(b, true, b.getClassName(), b.getMethodName())));
goals.add(new TryCatchCoverageTestFitness(new BranchCoverageGoal(b, false, b.getClassName(), b.getMethodName())));
}
}
}
}
return goals;
}
use of org.evosuite.coverage.MethodNameMatcher in project evosuite by EvoSuite.
the class OutputCoverageFactory method getCoverageGoals.
/*
* (non-Javadoc)
*
* @see
* org.evosuite.coverage.TestCoverageFactory#getCoverageGoals()
*/
/**
* {@inheritDoc}
*/
@Override
public List<OutputCoverageTestFitness> getCoverageGoals() {
List<OutputCoverageTestFitness> goals = new ArrayList<OutputCoverageTestFitness>();
long start = System.currentTimeMillis();
String targetClass = Properties.TARGET_CLASS;
final MethodNameMatcher matcher = new MethodNameMatcher();
for (String className : BytecodeInstructionPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).knownClasses()) {
if (!(targetClass.equals("") || className.endsWith(targetClass)))
continue;
for (Method method : TestClusterUtils.getClass(className).getDeclaredMethods()) {
String methodName = method.getName() + Type.getMethodDescriptor(method);
if (!TestUsageChecker.canUse(method) || !matcher.methodMatches(methodName) || methodName.equals("hashCode()I"))
continue;
logger.info("Adding goals for method " + className + "." + methodName);
Type returnType = Type.getReturnType(method);
switch(returnType.getSort()) {
case Type.BOOLEAN:
goals.add(createGoal(className, methodName, returnType, BOOL_TRUE));
goals.add(createGoal(className, methodName, returnType, BOOL_FALSE));
break;
case Type.CHAR:
goals.add(createGoal(className, methodName, returnType, CHAR_ALPHA));
goals.add(createGoal(className, methodName, returnType, CHAR_DIGIT));
goals.add(createGoal(className, methodName, returnType, CHAR_OTHER));
break;
case Type.BYTE:
case Type.SHORT:
case Type.INT:
case Type.FLOAT:
case Type.LONG:
case Type.DOUBLE:
goals.add(createGoal(className, methodName, returnType, NUM_NEGATIVE));
goals.add(createGoal(className, methodName, returnType, NUM_ZERO));
goals.add(createGoal(className, methodName, returnType, NUM_POSITIVE));
break;
case Type.ARRAY:
goals.add(createGoal(className, methodName, returnType, REF_NULL));
goals.add(createGoal(className, methodName, returnType, ARRAY_EMPTY));
goals.add(createGoal(className, methodName, returnType, ARRAY_NONEMPTY));
break;
case Type.OBJECT:
goals.add(createGoal(className, methodName, returnType, REF_NULL));
// goals.add(new OutputCoverageTestFitness(new OutputCoverageGoal(className, methodName, returnType.toString(), REF_NONNULL)));
if (returnType.getClassName().equals("java.lang.String")) {
goals.add(createGoal(className, methodName, returnType, STRING_EMPTY));
goals.add(createGoal(className, methodName, returnType, STRING_NONEMPTY));
break;
}
boolean observerGoalsAdded = false;
Class<?> returnClazz = method.getReturnType();
for (Inspector inspector : InspectorManager.getInstance().getInspectors(returnClazz)) {
String insp = inspector.getMethodCall() + Type.getMethodDescriptor(inspector.getMethod());
Type t = Type.getReturnType(inspector.getMethod());
if (t.getSort() == Type.BOOLEAN) {
goals.add(createGoal(className, methodName, returnType, REF_NONNULL + ":" + returnType.getClassName() + ":" + insp + ":" + BOOL_TRUE));
goals.add(createGoal(className, methodName, returnType, REF_NONNULL + ":" + returnType.getClassName() + ":" + insp + ":" + BOOL_FALSE));
observerGoalsAdded = true;
} else if (Arrays.asList(new Integer[] { Type.BYTE, Type.SHORT, Type.INT, Type.FLOAT, Type.LONG, Type.DOUBLE }).contains(t.getSort())) {
goals.add(createGoal(className, methodName, returnType, REF_NONNULL + ":" + returnType.getClassName() + ":" + insp + ":" + NUM_NEGATIVE));
goals.add(createGoal(className, methodName, returnType, REF_NONNULL + ":" + returnType.getClassName() + ":" + insp + ":" + NUM_ZERO));
goals.add(createGoal(className, methodName, returnType, REF_NONNULL + ":" + returnType.getClassName() + ":" + insp + ":" + NUM_POSITIVE));
observerGoalsAdded = true;
}
}
if (!observerGoalsAdded)
goals.add(createGoal(className, methodName, returnType, REF_NONNULL));
break;
default:
// TODO: what to do with the sort for METHOD?
break;
}
}
}
goalComputationTime = System.currentTimeMillis() - start;
return goals;
}
use of org.evosuite.coverage.MethodNameMatcher in project evosuite by EvoSuite.
the class StatementCoverageFactory method computeGoals.
private static void computeGoals() {
if (called)
return;
long start = System.currentTimeMillis();
String targetClass = Properties.TARGET_CLASS;
final MethodNameMatcher matcher = new MethodNameMatcher();
for (String className : BytecodeInstructionPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).knownClasses()) {
if (!(targetClass.equals("") || className.endsWith(targetClass)))
continue;
for (String methodName : BytecodeInstructionPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).knownMethods(className)) {
if (!matcher.methodMatches(methodName))
continue;
for (BytecodeInstruction ins : BytecodeInstructionPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getInstructionsIn(className, methodName)) if (isUsable(ins))
goals.add(new StatementCoverageTestFitness(ins));
}
}
long end = System.currentTimeMillis();
goalComputationTime = end - start;
called = true;
}
use of org.evosuite.coverage.MethodNameMatcher in project evosuite by EvoSuite.
the class InputCoverageFactory method getCoverageGoals.
/*
* (non-Javadoc)
*
* @see
* org.evosuite.coverage.TestCoverageFactory#getCoverageGoals()
*/
/**
* {@inheritDoc}
*/
@Override
public List<InputCoverageTestFitness> getCoverageGoals() {
List<InputCoverageTestFitness> goals = new ArrayList<InputCoverageTestFitness>();
long start = System.currentTimeMillis();
String targetClass = Properties.TARGET_CLASS;
final MethodNameMatcher matcher = new MethodNameMatcher();
for (String className : BytecodeInstructionPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).knownClasses()) {
if (!(targetClass.equals("") || className.endsWith(targetClass)))
continue;
for (Method method : TestClusterUtils.getClass(className).getDeclaredMethods()) {
String methodName = method.getName() + Type.getMethodDescriptor(method);
if (!TestUsageChecker.canUse(method) || !matcher.methodMatches(methodName))
continue;
logger.info("Adding input goals for method " + className + "." + methodName);
Type[] argumentTypes = Type.getArgumentTypes(method);
Class<?>[] argumentClasses = method.getParameterTypes();
for (int i = 0; i < argumentTypes.length; i++) {
Type argType = argumentTypes[i];
switch(argType.getSort()) {
case Type.BOOLEAN:
goals.add(createGoal(className, methodName, i, argType, BOOL_TRUE));
goals.add(createGoal(className, methodName, i, argType, BOOL_FALSE));
break;
case Type.CHAR:
goals.add(createGoal(className, methodName, i, argType, CHAR_ALPHA));
goals.add(createGoal(className, methodName, i, argType, CHAR_DIGIT));
goals.add(createGoal(className, methodName, i, argType, CHAR_OTHER));
break;
case Type.BYTE:
case Type.SHORT:
case Type.INT:
case Type.FLOAT:
case Type.LONG:
case Type.DOUBLE:
goals.add(createGoal(className, methodName, i, argType, NUM_NEGATIVE));
goals.add(createGoal(className, methodName, i, argType, NUM_ZERO));
goals.add(createGoal(className, methodName, i, argType, NUM_POSITIVE));
break;
case Type.ARRAY:
goals.add(createGoal(className, methodName, i, argType, REF_NULL));
goals.add(createGoal(className, methodName, i, argType, ARRAY_EMPTY));
goals.add(createGoal(className, methodName, i, argType, ARRAY_NONEMPTY));
break;
case Type.OBJECT:
goals.add(createGoal(className, methodName, i, argType, REF_NULL));
if (argType.getClassName().equals("java.lang.String")) {
goals.add(createGoal(className, methodName, i, argType, STRING_EMPTY));
goals.add(createGoal(className, methodName, i, argType, STRING_NONEMPTY));
} else if (List.class.isAssignableFrom(argumentClasses[i])) {
goals.add(createGoal(className, methodName, i, argType, LIST_EMPTY));
goals.add(createGoal(className, methodName, i, argType, LIST_NONEMPTY));
} else if (Set.class.isAssignableFrom(argumentClasses[i])) {
goals.add(createGoal(className, methodName, i, argType, SET_EMPTY));
goals.add(createGoal(className, methodName, i, argType, SET_NONEMPTY));
} else if (Map.class.isAssignableFrom(argumentClasses[i])) {
goals.add(createGoal(className, methodName, i, argType, MAP_EMPTY));
goals.add(createGoal(className, methodName, i, argType, MAP_NONEMPTY));
// TODO: Collection.class?
} else
goals.add(createGoal(className, methodName, i, argType, REF_NONNULL));
break;
default:
break;
}
}
}
}
goalComputationTime = System.currentTimeMillis() - start;
return goals;
}
Aggregations