Search in sources :

Example 1 with Mutation

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;
}
Also used : MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) InsnNode(org.objectweb.asm.tree.InsnNode) Type(org.objectweb.asm.Type) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) Mutation(org.evosuite.coverage.mutation.Mutation) InsnList(org.objectweb.asm.tree.InsnList) LinkedList(java.util.LinkedList)

Example 2 with Mutation

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;
}
Also used : MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) VarInsnNode(org.objectweb.asm.tree.VarInsnNode) InsnNode(org.objectweb.asm.tree.InsnNode) Mutation(org.evosuite.coverage.mutation.Mutation) LinkedList(java.util.LinkedList)

Example 3 with Mutation

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;
}
Also used : FieldInsnNode(org.objectweb.asm.tree.FieldInsnNode) LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) InsnNode(org.objectweb.asm.tree.InsnNode) Type(org.objectweb.asm.Type) FieldInsnNode(org.objectweb.asm.tree.FieldInsnNode) Mutation(org.evosuite.coverage.mutation.Mutation) InsnList(org.objectweb.asm.tree.InsnList) LinkedList(java.util.LinkedList)

Example 4 with Mutation

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;
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) JumpInsnNode(org.objectweb.asm.tree.JumpInsnNode) Mutation(org.evosuite.coverage.mutation.Mutation) LinkedList(java.util.LinkedList)

Example 5 with Mutation

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));
    }
}
Also used : Branch(org.evosuite.coverage.branch.Branch) Mutation(org.evosuite.coverage.mutation.Mutation)

Aggregations

Mutation (org.evosuite.coverage.mutation.Mutation)20 LinkedList (java.util.LinkedList)10 LdcInsnNode (org.objectweb.asm.tree.LdcInsnNode)7 AbstractInsnNode (org.objectweb.asm.tree.AbstractInsnNode)6 InsnList (org.objectweb.asm.tree.InsnList)6 InsnNode (org.objectweb.asm.tree.InsnNode)6 MethodInsnNode (org.objectweb.asm.tree.MethodInsnNode)6 HashSet (java.util.HashSet)4 Type (org.objectweb.asm.Type)4 LabelNode (org.objectweb.asm.tree.LabelNode)4 FieldInsnNode (org.objectweb.asm.tree.FieldInsnNode)3 JumpInsnNode (org.objectweb.asm.tree.JumpInsnNode)3 VarInsnNode (org.objectweb.asm.tree.VarInsnNode)3 LinkedHashSet (java.util.LinkedHashSet)2 Branch (org.evosuite.coverage.branch.Branch)2 ExecutionResult (org.evosuite.testcase.execution.ExecutionResult)2 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1