Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiplemutants #313

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,22 @@
*/
package org.evosuite.coverage.mutation;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

/**
* <p>MutationObserver class.</p>
*
* @author Gordon Fraser
*/
public class MutationObserver {

/** Constant <code>activeMutation=-1</code> */
public static int activeMutation = -1;
public static Set<Integer> activeMutations = new HashSet<Integer>();

public static boolean isActive(int mutationId) {
return activeMutations.contains(mutationId);
}

/**
* <p>mutationTouched</p>
Expand All @@ -47,8 +54,7 @@ public static void mutationTouched(int mutationID) {
* @param mutation a {@link org.evosuite.coverage.mutation.Mutation} object.
*/
public static void activateMutation(Mutation mutation) {
if (mutation != null)
activeMutation = mutation.getId();
activeMutations.add(mutation.getId());
}

/**
Expand All @@ -57,14 +63,14 @@ public static void activateMutation(Mutation mutation) {
* @param id a int.
*/
public static void activateMutation(int id) {
activeMutation = id;
activeMutations.add(id);
}

/**
* <p>deactivateMutation</p>
*/
public static void deactivateMutation() {
activeMutation = -1;
activeMutations.clear();
}

/**
Expand All @@ -73,7 +79,14 @@ public static void deactivateMutation() {
* @param mutation a {@link org.evosuite.coverage.mutation.Mutation} object.
*/
public static void deactivateMutation(Mutation mutation) {
activeMutation = -1;
activeMutations.clear();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine, just wondering whether you intended to do activeMutations.remove(mutation.getId()) or something like that rather than deactivating all mutants? Otherwise we should maybe drop the parameter and rename the method to deactivateMutations() ?

}

public static void activateMutations(Collection<Mutation> mutations) {
for (Mutation mutation : mutations) {
activeMutations.add(mutation.getId());
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
package org.evosuite.instrumentation.coverage;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
Expand Down Expand Up @@ -294,13 +296,22 @@ protected void addInstrumentation(MethodNode mn, AbstractInsnNode original,
LabelNode nextLabel = new LabelNode();

LdcInsnNode mutationId = new LdcInsnNode(mutation.getId());
MethodInsnNode isActive = new MethodInsnNode(Opcodes.INVOKESTATIC,
Type.getInternalName(MutationObserver.class), "isActive",
Type.getMethodDescriptor(Type.BOOLEAN_TYPE, Type.INT_TYPE), false);

// Invoke the static class method MutationObserver.isActive() with mutationId in
// question as the operand.
instructions.add(mutationId);
FieldInsnNode activeId = new FieldInsnNode(Opcodes.GETSTATIC,
Type.getInternalName(MutationObserver.class), "activeMutation", "I");
instructions.add(activeId);
instructions.add(new JumpInsnNode(Opcodes.IF_ICMPNE, nextLabel));
instructions.add(isActive);

// Operand is now True iff the mutation is active, False iff not and we should jump
// to nextLabel to avoid running the mutated instruction.
instructions.add(new JumpInsnNode(Opcodes.IFEQ, nextLabel));

instructions.add(mutation.getMutation());
instructions.add(new JumpInsnNode(Opcodes.GOTO, endLabel));

instructions.add(nextLabel);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private void resetClass(String className) {
// className.__STATIC_RESET() exists
logger.debug("Resetting class " + className);

int mutationActive = MutationObserver.activeMutation;
int mutationActive = MutationObserver.activeMutations.iterator().next();
MutationObserver.deactivateMutation();

// execute __STATIC_RESET()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,15 @@ public void testDseWithReset1() throws SecurityException,
NoSuchMethodException {
DefaultTestCase tc = buildTestCaseWithReset();
List<BranchCondition> branch_conditions = executeTest(tc);
assertEquals(1, branch_conditions.size());
assertEquals(0, branch_conditions.size());
}

@Test
public void testDseWithReset2() throws SecurityException,
NoSuchMethodException {
DefaultTestCase tc = buildTestCaseWithReset();
List<BranchCondition> branch_conditions = executeTest(tc);
assertEquals(1, branch_conditions.size());
assertEquals(0, branch_conditions.size());
}

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ public void test6() throws SecurityException, NoSuchMethodException, NoSuchField
List<BranchCondition> branch_conditions = pc.getBranchConditions();

printConstraints(branch_conditions);
assertEquals(1, branch_conditions.size());
assertEquals(0, branch_conditions.size());
}

private static void test_input7() {
Expand Down