Permalink
Browse files

No commit message

  • Loading branch information...
1 parent 6b14665 commit f3e0d0e2049e31b52459bf6242e3a0df36b49d42 schuler committed Oct 2, 2007
View
@@ -125,4 +125,13 @@
</java>
</target>
+ <target name="showMutationResults" description="prints all mutation results to console">
+ <java classname="org.softevo.mutation.run.PrintResults" maxmemory="1024m" fork="true">
+ <classpath>
+ <path refid="mutation.classpath" />
+ <path location="target/classes" />
+ </classpath>
+ </java>
+ </target>
+
</project>
@@ -14,11 +14,23 @@
*/
public class BytecodeTasks {
- boolean insertNoops;
+ private static final boolean PRINT_STATEMENTS_ENABLED = true;
private BytecodeTasks() {
}
+ /**
+ * Inserts a mutation. The inserted code is like this:
+ * <code>if(System.getProperty(mutationID)){
+ * execute mutated code
+ * }
+ * else{
+ * execute unmutated code
+ * }
+ * @param mv MethodVisitor where the code is inserted.
+ * @param unMutated code that should be used when no mutation is applied.
+ * @param mutations code that should be used when one of the mutations is applied.
+ */
public static void insertIfElse(MethodVisitor mv, MutationCode unMutated,
MutationCode[] mutations) {
RicMethodAdapter.mutationForLine++;
@@ -35,14 +47,11 @@ public static void insertIfElse(MethodVisitor mv, MutationCode unMutated,
mv.visitJumpInsn(Opcodes.IFNULL, l1);
Label l2 = new Label();
mv.visitLabel(l2);
- BytecodeTasks.insertPrintStatements(mv, "Mutation "
- + mutation.getMutationVariable() + " - "
- + mutation.getMutationType() + " is enabled");
+ insertMutationTouchedCode(mv, mutation);
mutationCode.insertCodeBlock(mv);
mv.visitJumpInsn(Opcodes.GOTO, endLabel);
mv.visitLabel(l1);
}
-
Label mutationEndLabel = new Label();
mutationEndLabel.info = new MutationMarker(false);
mv.visitLabel(mutationEndLabel);
@@ -51,6 +60,27 @@ public static void insertIfElse(MethodVisitor mv, MutationCode unMutated,
}
+ private static void insertMutationTouchedCode(MethodVisitor mv,
+ Mutation mutation) {
+ if (PRINT_STATEMENTS_ENABLED) {
+ BytecodeTasks.insertPrintStatements(mv, "Mutation "
+ + mutation.getMutationVariable() + " - "
+ + mutation.getMutationType() + " is enabled");
+ }
+ mv.visitLdcInsn(mutation.getId());
+ mv.visitMethodInsn(Opcodes.INVOKESTATIC,
+ "org/softevo/mutation/testsuite/ResultReporter", "touch",
+ "(I)V");
+ }
+
+ /**
+ * Inserts bytecode that prints the given message.
+ *
+ * @param mv
+ * The MethodVisitor for which teh code is added.
+ * @param message
+ * The text to be printed to System.out .
+ */
public static void insertPrintStatements(MethodVisitor mv, String message) {
mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "err",
"Ljava/io/PrintStream;");
@@ -59,6 +89,4 @@ public static void insertPrintStatements(MethodVisitor mv, String message) {
"println", "(Ljava/lang/String;)V");
}
-
-
}
@@ -11,13 +11,18 @@
public class MutationTransformer extends BytecodeTransformer {
+ private static final boolean DEBUG = false;
+
private static Logger logger = Logger.getLogger(MutationTransformer.class);
@Override
protected ClassVisitor classVisitorFactory(ClassWriter cw) {
- ClassVisitor cc = new CheckClassAdapter(cw);
+ ClassVisitor cv = new CheckClassAdapter(cw);
logger.info("Mutation Transformer");
- return new MutationsClassAdapter(new TraceClassVisitor(cc, new PrintWriter(System.out)));
+ if (DEBUG) {
+ cv = new TraceClassVisitor(cv, new PrintWriter(System.out));
+ }
+ return new MutationsClassAdapter(cv);
}
}
@@ -3,6 +3,8 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
+import java.util.Map;
+import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
@@ -27,6 +29,11 @@
private int runs;
+ /**
+ * True if the mutation was touched by at least one TestCase;
+ */
+ boolean touched;
+
@OneToMany(cascade = CascadeType.ALL)
@OrderBy("testCaseName")
@IndexColumn(name = "failure_list_id")
@@ -36,30 +43,56 @@
@JoinTable(name = "SINGLETESTRESULT_ERRORS", joinColumns = { @JoinColumn(name = "singletestresult_id") }, inverseJoinColumns = @JoinColumn(name = "testmessage_id"))
private List<TestMessage> errors = new ArrayList<TestMessage>();
+ @OneToMany(cascade = CascadeType.ALL)
+ @JoinTable(name = "SINGLETESTRESULT_PASSING", joinColumns = { @JoinColumn(name = "singletestresult_id") }, inverseJoinColumns = @JoinColumn(name = "testmessage_id"))
+ private List<TestMessage> passing = new ArrayList<TestMessage>();
+
private SingleTestResult() {
}
public SingleTestResult(TestResult mutationTestResult,
- MutationTestListener mutationTestListener) {
+ MutationTestListener mutationTestListener,
+ Set<String> touchingTestCases) {
this.runs = mutationTestResult.runCount();
this.failures = mutationTestListener.getFailureMessages();
this.errors = mutationTestListener.getErrorMessages();
+ this.passing = mutationTestListener.getPassingMessages();
+ if (touchingTestCases != null && touchingTestCases.size() > 0) {
+ updateTouched(touchingTestCases, failures);
+ updateTouched(touchingTestCases, errors);
+ updateTimes(mutationTestListener.getDurations());
+ touched = true;
+ }
+ }
+
+ private void updateTimes(Map<String, Long> durations) {
+ // TODO
+ }
+
+ private static void updateTouched(Set<String> touchingTestCases,
+ List<TestMessage> testMessages) {
+ for (TestMessage tm : testMessages) {
+ if (touchingTestCases.contains(tm.getTestCaseName())) {
+ tm.setHasTouched(true);
+ }
+ }
}
@Override
public String toString() {
- StringBuilder sb = new StringBuilder( String.format("Runs: %d Failures: %d Errors: %d", runs,
- failures.size(), errors.size()));
- if(failures.size() >0){
+ StringBuilder sb = new StringBuilder(String.format(
+ "Runs: %d Failures: %d Errors: %d LineTouched: %s", runs, failures.size(),
+ errors.size(), touched ? "yes" : "no "));
+ if (failures.size() > 0) {
sb.append("Failures:\n");
- for(TestMessage tm : failures){
+ for (TestMessage tm : failures) {
sb.append(tm);
sb.append('\n');
}
}
- if(errors.size() >0){
+ if (errors.size() > 0) {
sb.append("Errors:\n");
- for(TestMessage tm : errors){
+ for (TestMessage tm : errors) {
sb.append(tm);
sb.append('\n');
}
@@ -135,5 +168,18 @@ public void setFailures(List<TestMessage> failures) {
this.failures = failures;
}
+ /**
+ * @return the passing
+ */
+ public List<TestMessage> getPassing() {
+ return passing;
+ }
+
+ /**
+ * @param passing the passing to set
+ */
+ public void setPassing(List<TestMessage> passing) {
+ this.passing = passing;
+ }
}
@@ -4,23 +4,53 @@
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
+/**
+ *
+ * Class that holds the result of one single TestCase.
+ *
+ * @author David Schuler
+ *
+ */
@Entity
public class TestMessage {
@Id
@GeneratedValue
private Long id;
+ /**
+ * name of the TestCases
+ */
private String testCaseName;
+ /**
+ * Failure or error message of the TestCase.
+ */
private String message;
+ /**
+ * True, if test case has touched the mutation.
+ */
+ private boolean hasTouched;
+
+ /**
+ * Time a testCase needed to execute.
+ */
+ private long duration;
+
public TestMessage(String testCaseName, String message) {
super();
this.testCaseName = testCaseName;
this.message = message;
}
+ public TestMessage(String testCaseName, String message, long duration) {
+ super();
+ this.testCaseName = testCaseName;
+ this.message = message;
+ this.duration = duration;
+ }
+
public TestMessage() {
}
@@ -71,6 +101,37 @@ public void setTestCaseName(String testCaseName) {
@Override
public String toString() {
- return String.format("TestCase: %s Reason: %s",testCaseName, message);
+ return String.format("TestCase: %s Touched: %s Reason: %s",
+ testCaseName, hasTouched ? "yes" : "no", message);
+ }
+
+ /**
+ * @return the hasTouched
+ */
+ public boolean isHasTouched() {
+ return hasTouched;
+ }
+
+ /**
+ * @param hasTouched
+ * the hasTouched to set
+ */
+ public void setHasTouched(boolean hasTouched) {
+ this.hasTouched = hasTouched;
+ }
+
+ /**
+ * @return the duration
+ */
+ public long getDuration() {
+ return duration;
+ }
+
+ /**
+ * @param duration
+ * the duration to set
+ */
+ public void setDuration(long duration) {
+ this.duration = duration;
}
}
@@ -64,10 +64,8 @@ public static void updateMutation(Mutation mutation,
session.save(tm);
}
session.save(mutationTestResult);
+ logger.info("mutation updated " + m2);
m2.setMutationResult(mutationTestResult);
- // logger.info("ID" + mutation.getId());
- // logger.info(mutationTestResult);
- // session.update(m2);
tx.commit();
session.close();
}
@@ -77,6 +77,7 @@ public void switchOn() {
+ actualMutation.getLineNumber() + " - "
+ actualMutation.toString());
System.setProperty(actualMutation.getMutationVariable(), "1");
+ ResultReporter.setActualMutation(actualMutation);
}
}
@@ -85,6 +86,7 @@ public void switchOff() {
System.clearProperty(actualMutation.getMutationVariable());
logger.info("disabling mutation: "
+ actualMutation.getMutationVariable());
+ ResultReporter.setActualMutation(null);
}
}
Oops, something went wrong.

0 comments on commit f3e0d0e

Please sign in to comment.