use of org.evosuite.coverage.mutation.Mutation in project evosuite by EvoSuite.
the class DeleteStatement method apply.
/* (non-Javadoc)
* @see org.evosuite.cfg.instrumentation.MutationOperator#apply(org.objectweb.asm.tree.MethodNode, java.lang.String, java.lang.String, org.evosuite.cfg.BytecodeInstruction)
*/
/**
* {@inheritDoc}
*/
@Override
public List<Mutation> apply(MethodNode mn, String className, String methodName, BytecodeInstruction instruction, Frame frame) {
List<Mutation> mutations = new LinkedList<Mutation>();
MethodInsnNode node = (MethodInsnNode) instruction.getASMNode();
Type returnType = Type.getReturnType(node.desc);
// insert mutation into bytecode with conditional
InsnList mutation = new InsnList();
logger.info("Mutation deletestatement for statement " + node.name + node.desc);
for (Type argType : Type.getArgumentTypes(node.desc)) {
if (argType.getSize() == 0)
logger.info("Ignoring parameter of type " + argType);
else if (argType.getSize() == 2) {
mutation.insert(new InsnNode(Opcodes.POP2));
logger.debug("Deleting parameter of 2 type " + argType);
} else {
logger.debug("Deleting parameter of 1 type " + argType);
mutation.insert(new InsnNode(Opcodes.POP));
}
}
if (node.getOpcode() == Opcodes.INVOKEVIRTUAL) {
logger.debug("Deleting callee of type " + node.owner);
mutation.add(new InsnNode(Opcodes.POP));
} else if (node.getOpcode() == Opcodes.INVOKEINTERFACE) {
boolean isStatic = false;
try {
Class<?> clazz = Class.forName(node.owner.replace('/', '.'), false, DeleteStatement.class.getClassLoader());
for (java.lang.reflect.Method method : clazz.getMethods()) {
if (method.getName().equals(node.name)) {
if (Type.getMethodDescriptor(method).equals(node.desc)) {
if (Modifier.isStatic(method.getModifiers()))
isStatic = true;
}
}
}
} catch (ClassNotFoundException e) {
logger.warn("Could not find class: " + node.owner + ", this is likely a severe problem");
}
if (!isStatic) {
logger.info("Deleting callee of type " + node.owner);
mutation.add(new InsnNode(Opcodes.POP));
}
}
mutation.add(getDefault(returnType));
// insert mutation into pool
Mutation mutationObject = MutationPool.addMutation(className, methodName, NAME + " " + node.name + node.desc, instruction, mutation, Mutation.getDefaultInfectionDistance());
mutations.add(mutationObject);
return mutations;
}
use of org.evosuite.coverage.mutation.Mutation in project evosuite by EvoSuite.
the class ReplaceArithmeticOperator method apply.
/* (non-Javadoc)
* @see org.evosuite.cfg.instrumentation.MutationOperator#apply(org.objectweb.asm.tree.MethodNode, java.lang.String, java.lang.String, org.evosuite.cfg.BytecodeInstruction)
*/
/**
* {@inheritDoc}
*/
@Override
public List<Mutation> apply(MethodNode mn, String className, String methodName, BytecodeInstruction instruction, Frame frame) {
numVariable = getNextIndex(mn);
List<Mutation> mutations = new LinkedList<Mutation>();
InsnNode node = (InsnNode) instruction.getASMNode();
for (int opcode : getMutations(node.getOpcode())) {
InsnNode mutation = new InsnNode(opcode);
// insert mutation into pool
Mutation mutationObject = MutationPool.addMutation(className, methodName, NAME + " " + getOp(node.getOpcode()) + " -> " + getOp(opcode), instruction, mutation, getInfectionDistance(node.getOpcode(), opcode));
mutations.add(mutationObject);
}
return mutations;
}
use of org.evosuite.coverage.mutation.Mutation in project evosuite by EvoSuite.
the class DeleteField method apply.
/* (non-Javadoc)
* @see org.evosuite.cfg.instrumentation.mutation.MutationOperator#apply(org.objectweb.asm.tree.MethodNode, java.lang.String, java.lang.String, org.evosuite.cfg.BytecodeInstruction)
*/
/**
* {@inheritDoc}
*/
@Override
public List<Mutation> apply(MethodNode mn, String className, String methodName, BytecodeInstruction instruction, Frame frame) {
List<Mutation> mutations = new LinkedList<Mutation>();
FieldInsnNode node = (FieldInsnNode) instruction.getASMNode();
Type fieldType = Type.getType(node.desc);
// insert mutation into bytecode with conditional
InsnList mutation = new InsnList();
logger.debug("Mutation deletefield for statement " + node.name + node.desc);
if (node.getOpcode() == Opcodes.GETFIELD) {
logger.debug("Deleting source of type " + node.owner);
mutation.add(new InsnNode(Opcodes.POP));
}
mutation.add(getDefault(fieldType));
// insert mutation into pool
Mutation mutationObject = MutationPool.addMutation(className, methodName, NAME + " " + node.name + node.desc, instruction, mutation, getInfectionDistance(node, mutation));
mutations.add(mutationObject);
return mutations;
}
use of org.evosuite.coverage.mutation.Mutation in project evosuite by EvoSuite.
the class NegateCondition method apply.
/* (non-Javadoc)
* @see org.evosuite.cfg.instrumentation.MutationOperator#apply(org.objectweb.asm.tree.MethodNode, java.lang.String, java.lang.String, org.evosuite.cfg.BytecodeInstruction)
*/
/**
* {@inheritDoc}
*/
@Override
public List<Mutation> apply(MethodNode mn, String className, String methodName, BytecodeInstruction instruction, Frame frame) {
List<Mutation> mutations = new LinkedList<Mutation>();
JumpInsnNode node = (JumpInsnNode) instruction.getASMNode();
LabelNode target = node.label;
// insert mutation into bytecode with conditional
JumpInsnNode mutation = new JumpInsnNode(getOpposite(node.getOpcode()), target);
// insert mutation into pool
Mutation mutationObject = MutationPool.addMutation(className, methodName, NAME, instruction, mutation, Mutation.getDefaultInfectionDistance());
mutations.add(mutationObject);
return mutations;
}
use of org.evosuite.coverage.mutation.Mutation in project evosuite by EvoSuite.
the class TestGenerationResultBuilder method resetTestData.
private void resetTestData() {
code = "";
ga = null;
testCode.clear();
testCases.clear();
contractViolations.clear();
uncoveredLines = LinePool.getAllLines();
for (Branch b : BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getAllBranches()) {
uncoveredBranches.add(new BranchInfo(b, true));
uncoveredBranches.add(new BranchInfo(b, false));
}
for (Mutation m : MutationPool.getMutants()) {
uncoveredMutants.add(new MutationInfo(m));
}
}
Aggregations