Permalink
Browse files

touch for mutation works

  • Loading branch information...
1 parent f3e0d0e commit faaf7c28992678c087eede4b0c328c2d49b6b391 schuler committed Oct 9, 2007
View
@@ -25,5 +25,6 @@
<classpathentry kind="var" path="M2_REPO/javax/transaction/jta/1.0.1B/jta-1.0.1B.jar"/>
<classpathentry kind="var" path="M2_REPO/net/sf/ehcache/ehcache/1.2.3/ehcache-1.2.3.jar" sourcepath="M2_REPO/net/sf/ehcache/ehcache/1.2.3/ehcache-1.2.3-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/log4j/log4j/1.2.9/log4j-1.2.9.jar" sourcepath="M2_REPO/log4j/log4j/1.2.9/log4j-1.2.9-sources.jar"/>
+ <classpathentry kind="lib" path="target/mutationTest-1.0-SNAPSHOT-dist.dir/lib/mysql-connector-java-5.0.3.jar"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
View
@@ -17,6 +17,7 @@
<include name="**/*.jar" />
<include name="**/*.zip" />
</fileset>
+ <pathelement location="target/mutationTest-1.0-SNAPSHOT-dist.dir/lib/mysql-connector-java-5.0.3.jar"/>
</path>
<path id="mutation.classpath">
@@ -68,7 +69,16 @@
<!-- Export the database schema -->
<target name="schemaexport" depends="" description="Exports a generated schema to DB and file">
<hibernatetool destdir="${basedir}">
- <classpath path="target/classes/" />
+ <classpath>
+ <pathelement path="target/classes/" />
+ <pathelement location="target/mutationTest-1.0-SNAPSHOT-dist.dir/lib/mysql-connector-java-5.0.3.jar"/>
+
+ <!--
+ <fileset dir="target/mutationTest-1.0-SNAPSHOT-dist.dir/lib">
+ <include name="*.jar"/>
+ </fileset>
+ -->
+ </classpath>
<annotationconfiguration configurationfile="src/main/resources/hibernate.cfg.xml" />
<hbm2ddl drop="true" create="true" export="true" outputfilename="${proj.shortname}-ddl.sql" delimiter=";" format="true" />
</hibernatetool>
@@ -117,7 +127,7 @@
<target name="generateCoverageEntries" description="generate the coverage entries for aspectj">
- <java classname="org.softevo.mutation.coverageResults.TestSuiteCoverageResult" maxmemory="3072m" fork="true">
+ <java classname="org.softevo.mutation.coverageResults.TestSuiteCoverageResult" maxmemory="1536m" fork="true">
<classpath>
<path refid="mutation.classpath" />
<path location="target/classes" />
@@ -134,4 +144,13 @@
</java>
</target>
+ <target name="runThreaded" description="run mutation tests multithreaded">
+ <java classname="org.softevo.mutation.run.ThreadPool" maxmemory="1024m" fork="true">
+ <classpath>
+ <path refid="mutation.classpath" />
+ <path location="target/classes" />
+ </classpath>
+ </java>
+ </target>
+
</project>
View
@@ -271,6 +271,10 @@
<artifactId>staticTransformer</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
-
+ <dependency>
+ <groupId>mysql</groupId>
+ <artifactId>mysql-connector-java</artifactId>
+ <version>5.0.3</version>
+ </dependency>
</dependencies>
</project>
@@ -14,7 +14,7 @@
*/
public class BytecodeTasks {
- private static final boolean PRINT_STATEMENTS_ENABLED = true;
+ private static final boolean PRINT_STATEMENTS_ENABLED = false;
private BytecodeTasks() {
}
@@ -47,6 +47,7 @@ public static void insertIfElse(MethodVisitor mv, MutationCode unMutated,
mv.visitJumpInsn(Opcodes.IFNULL, l1);
Label l2 = new Label();
mv.visitLabel(l2);
+ insertPrintStatements(mv, "Mutation touched: " + mutation.getId());
insertMutationTouchedCode(mv, mutation);
mutationCode.insertCodeBlock(mv);
mv.visitJumpInsn(Opcodes.GOTO, endLabel);
@@ -70,14 +71,14 @@ private static void insertMutationTouchedCode(MethodVisitor mv,
mv.visitLdcInsn(mutation.getId());
mv.visitMethodInsn(Opcodes.INVOKESTATIC,
"org/softevo/mutation/testsuite/ResultReporter", "touch",
- "(I)V");
+ "(J)V");
}
/**
* Inserts bytecode that prints the given message.
*
* @param mv
- * The MethodVisitor for which teh code is added.
+ * The MethodVisitor for which the code is added.
* @param message
* The text to be printed to System.out .
*/
@@ -1,42 +0,0 @@
-package org.softevo.mutation.bytecodeMutations;
-
-import org.objectweb.asm.AnnotationVisitor;
-import org.objectweb.asm.Attribute;
-import org.objectweb.asm.MethodVisitor;
-
-public class MutationGuardMethodAdapter extends AbstractMutationAdapter {
-
- public MutationGuardMethodAdapter(MethodVisitor mv, String className, String methodName) {
- super(mv, className, methodName);
- }
-
-
- @Override
- public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
- // TODO Auto-generated method stub
- return super.visitAnnotation(desc, visible);
- }
-
- @Override
- public void visitAttribute(Attribute attr) {
- // TODO Auto-generated method stub
- super.visitAttribute(attr);
- }
-
- @Override
- public AnnotationVisitor visitAnnotationDefault() {
- // TODO Auto-generated method stub
- return super.visitAnnotationDefault();
- }
- @Override
- public void visitCode() {
- // TODO Auto-generated method stub
- super.visitCode();
- }
- @Override
- public void visitEnd() {
- // TODO Auto-generated method stub
- super.visitEnd();
- }
-
-}
@@ -63,7 +63,12 @@ public RicMethodAdapter(MethodVisitor mv, String className,
}
+ @Override
public void visitInsn(int opcode) {
+ if (mutationCode) {
+ super.visitInsn(opcode);
+ return;
+ }
switch (opcode) {
case Opcodes.ICONST_M1:
intConstant(-1);
@@ -116,6 +121,10 @@ public void visitInsn(int opcode) {
@Override
public void visitLdcInsn(Object cst) {
+ if (mutationCode) {
+ super.visitLdcInsn(cst);
+ return;
+ }
if (cst instanceof Integer) {
Integer integerConstant = (Integer) cst;
intConstant(integerConstant);
@@ -129,8 +138,7 @@ public void visitLdcInsn(Object cst) {
} else if (cst instanceof Double) {
Double doubleConstant = (Double) cst;
doubleConstant(doubleConstant);
- }
- else{
+ } else {
mv.visitLdcInsn(cst);
}
}
@@ -257,14 +265,14 @@ public void insertCodeBlock(MethodVisitor mv) {
logger.info("Applying no mutations for line: " + getLineNumber());
} else {
- logger.info("Applying no mutation for line: " + getLineNumber());
- super.visitLdcInsn(new Long(longConstant));
- }
+ logger.info("Applying no mutation for line: " + getLineNumber());
+ super.visitLdcInsn(new Long(longConstant));
+ }
}
-// private void insertPrintStatements(String message) {
-// insertPrintStatements(mv, message);
-// }
+ // private void insertPrintStatements(String message) {
+ // insertPrintStatements(mv, message);
+ // }
@Override
public void visitLineNumber(int line, Label start) {
@@ -274,6 +282,10 @@ public void visitLineNumber(int line, Label start) {
@Override
public void visitIntInsn(int opcode, int operand) {
+ if (mutationCode) {
+ super.visitIntInsn(opcode, operand);
+ return;
+ }
if (opcode == Opcodes.BIPUSH || opcode == Opcodes.SIPUSH) {
intConstant(operand);
} else {
@@ -290,11 +302,13 @@ private void intConstant(final int i) {
Mutation mutationZero = new Mutation(className, getLineNumber(),
mutationForLine, MutationType.RIC_ZERO);
-
if (MutationManager.shouldApplyMutation(mutationPlus1)) {
- Mutation mutationPlus1FromDB = QueryManager.getMutation(mutationPlus1);
- Mutation mutationMinus1FromDB = QueryManager.getMutation(mutationMinus);
- Mutation mutationZeroFromDB = QueryManager.getMutation(mutationZero);
+ Mutation mutationPlus1FromDB = QueryManager
+ .getMutation(mutationPlus1);
+ Mutation mutationMinus1FromDB = QueryManager
+ .getMutation(mutationMinus);
+ Mutation mutationZeroFromDB = QueryManager
+ .getMutation(mutationZero);
BytecodeTasks.insertIfElse(mv, new MutationCode(null) {
@@ -347,6 +361,4 @@ private static ConstantMutations getConstantMutations(String className,
return new ConstantMutations(mutationPlus1FromDB, mutationMinus1FromDB,
mutationZeroFromDB);
}
-
-
}
@@ -14,7 +14,7 @@
public static void writeFile(String content, File file){
try {
-
+ logger.info("Start writing: " + file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(new FileWriter(file));
bw.write(content);
bw.close();
@@ -1,6 +1,12 @@
package org.softevo.mutation.javaagent;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
@@ -25,13 +31,15 @@
* http://en.wikipedia.org/wiki/Initialization_on_demand_holder_idiom
*/
private static class SingletonHolder {
- private final static MutationForRun INSTANCE = new MutationForRun();
+ private static MutationForRun INSTANCE = new MutationForRun();
}
private static final int MAX_MUTATIONS = getMaxMutations();
private static final String MUTATIONS_PER_RUN_KEY = "mutationsPerRun";
+ private static final boolean NON_RANDOM = true;
+
public static MutationForRun getInstance() {
return SingletonHolder.INSTANCE;
}
@@ -48,7 +56,7 @@ private static int getMaxMutations() {
private List<Mutation> mutations;
private MutationForRun() {
- mutations = getMutationsFromDB();
+ mutations = getMutationsForRun();
logger.info("Aplying " + mutations.size() + " mutations");
}
@@ -64,12 +72,37 @@ private MutationForRun() {
return Collections.unmodifiableList(mutations);
}
+ private static List<Mutation> getMutationsForRun() {
+ if (System.getProperty("mutation.file") != null) {
+ logger.info("Found Property mutation.file");
+ String filename = System.getProperty("mutation.file");
+
+ if (!filename.equals("")) {
+ logger.info("Value of mutation file: " + filename);
+ File file = new File(filename);
+ if (file.exists()) {
+ logger.info("Location of mutation.file: " + file.getAbsolutePath());
+ return getMutationsByFile(file);
+ }else{
+ logger.info("Mutation file does not exist" + file);
+ }
+ }
+ } else {
+ logger.info("Property not found: mutation.file");
+ // throw new RuntimeException("property not found");
+ }
+ if (NON_RANDOM) {
+ return getMutationsFromDB();
+ }
+ return null;
+ }
+
private static List<Mutation> getMutationsFromDB() {
Session session = HibernateUtil.getSessionFactory().openSession();
Transaction tx = session.beginTransaction();
Query query = session
.createSQLQuery(
- "SELECT m.* FROM Mutation m JOIN TestCoverageClassResult tccr ON m.classname = tccr.classname JOIN TESTCOVERAGECLASSRESULT_TESTCOVERAGELINERESULT AS class_line ON class_line.testcoverageclassresult_id = tccr.id JOIN TESTCOVERAGELINERESULT AS tclr ON tclr.id = class_line.lineresults_id WHERE m.mutationresult_id IS NULL AND m.linenumber = tclr.linenumber")
+ "SELECT m.* FROM Mutation m JOIN TestCoverageClassResult tccr ON m.classname = tccr.classname JOIN TestCoverageClassResult_TestCoverageLineResult AS class_line ON class_line.testcoverageclassresult_id = tccr.id JOIN TestCoverageLineResult AS tclr ON tclr.id = class_line.lineresults_id WHERE m.mutationresult_id IS NULL AND m.linenumber = tclr.linenumber")
.addEntity(Mutation.class);
query.setMaxResults(MAX_MUTATIONS);
List results = query.list();
@@ -81,4 +114,47 @@ private MutationForRun() {
session.close();
return mutationList;
}
+
+ private static List<Mutation> getMutationsByFile(File file) {
+ List<Long> idList = getIDsFromFile(file);
+ return getMutationsFromDbByID(idList.toArray(new Long[0]));
+ }
+
+ private static List<Long> getIDsFromFile(File file) {
+ List<Long> idList = new ArrayList<Long>();
+ try {
+ BufferedReader br = new BufferedReader(new FileReader(file));
+ while(br.ready()){
+ String id = br.readLine();
+ idList.add(Long.valueOf(id));
+ }
+ br.close();
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return idList;
+ }
+
+ private static List<Mutation> getMutationsFromDbByID(Long[] ids) {
+ Session session = HibernateUtil.getSessionFactory().openSession();
+ Transaction tx = session.beginTransaction();
+ Query query = session
+ .createQuery("FROM Mutation m WHERE m.id IN (:ids)");
+ query.setParameterList("ids", ids);
+ List results = query.list();
+ List<Mutation> mutationList = new ArrayList<Mutation>();
+ for (Object m : results) {
+ mutationList.add((Mutation) m);
+ }
+ tx.commit();
+ session.close();
+ return mutationList;
+ }
+
+ public void reinit(){
+ mutations = getMutationsForRun();
+ logger.info("Got " +mutations.size() + " mutations");
+ }
}
@@ -69,7 +69,10 @@ public Object size() {
public void updateDB() {
logger.info("Collected " + possibilities.size() + "mutation possibilities");
+ int counter = 0;
for (Mutation mutation : possibilities) {
+ counter++;
+ logger.info(counter + ": Trying to save mutation :" + mutation);
QueryManager.saveMutation(mutation);
}
}
@@ -111,6 +111,7 @@ public static void saveMutation(Mutation mutation) {
+ mutation);
assert mutationInDb.equals(mutation);
} else {
+ logger.info("Saving Mutation" + mutation);
save(mutation);
}
}
Oops, something went wrong.

0 comments on commit faaf7c2

Please sign in to comment.