Skip to content

Commit 3c92c15

Browse files
committed
Changes :
Fixes: - NPER_Writer was replacing statements with a list of statements instead of add all the statements in the list Modifications: - Moved method mujava.app.Console#killStillRunningJUnitTestcaseThreads() to mujava.app.Core as static public method - Added a call to mujava.app.Console#killStillRunningJUnitTestcaseThreads() after each test Additions: - mujava now also reports mutations score based only on compiling mutants - added a pushComplyType and popComplyType in mujava.op.PRVO#visit(AllocationExpression) before and after the call to unaryVisit - added a case for ThrowStatement in mujava.op.util.Mutator#getMutationsLeft(ParseTreeObject)
1 parent c06933e commit 3c92c15

8 files changed

Lines changed: 52 additions & 28 deletions

File tree

src/mujava/app/Console.java

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -363,27 +363,10 @@ public static void main(String[] args) {
363363
core.setMutationScore(ms);
364364
float mutationScoreResult = core.calculateMutationScore(testClasses, classToMutate);
365365
System.out.println(classToMutate + " scored : " + mutationScoreResult + " with tests : " + Arrays.asList(testClasses).toString());
366-
killStillRunningJUnitTestcaseThreads();
366+
Core.killStillRunningJUnitTestcaseThreads();
367367
}
368368
}
369369

370-
@SuppressWarnings("deprecation")
371-
private static void killStillRunningJUnitTestcaseThreads() {
372-
Set<Thread> threadSet = Thread.getAllStackTraces().keySet();
373-
for (Thread thread : threadSet) {
374-
if (!(thread.isDaemon())) {
375-
final StackTraceElement[] threadStackTrace = thread.getStackTrace();
376-
if (threadStackTrace.length > 1) {
377-
StackTraceElement firstMethodInvocation = threadStackTrace[threadStackTrace.length - 1];
378-
if (firstMethodInvocation.getClassName().startsWith("org.junit")) {
379-
// HACK: must use deprecated method
380-
thread.stop();
381-
}
382-
}
383-
}
384-
}
385-
}
386-
387370
private static void fullHelp() {
388371
System.out.println("Mujava++");
389372
System.out.println("Version : "+Core.mujavappVersion);

src/mujava/app/Core.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.util.HashMap;
1212
import java.util.LinkedList;
1313
import java.util.List;
14+
import java.util.Set;
1415
import java.util.Map.Entry;
1516

1617
import org.junit.runner.notification.Failure;
@@ -197,8 +198,25 @@ public float calculateMutationScore(String[] testClasses, String className) {
197198
if (killed) mutantsKilled++;
198199
}
199200
}
200-
System.out.println("Mutants : "+ mutants + " | didn't compile : " + failedToCompile + " | mutants killed by tests : "+ mutantsKilled + " | surviving mutants : " + (mutants-failedToCompile-mutantsKilled) + " | total tests that timedout : " + timedOut + " | mutation score : "+((mutantsKilled+failedToCompile)*100.0)/mutants+'\n');
201+
System.out.println("Mutants : "+ mutants + " | didn't compile : " + failedToCompile + " | mutants killed by tests : "+ mutantsKilled + " | surviving mutants : " + (mutants-failedToCompile-mutantsKilled) + " | total tests that timedout : " + timedOut + " | mutation score : "+((mutantsKilled+failedToCompile)*100.0)/mutants+ " | mutation score (only compiling mutants) : " + (mutantsKilled*100.0)/(mutants-failedToCompile) + '\n');
201202
return ((mutantsKilled+failedToCompile)*(float)100.0)/mutants;
202203
}
204+
205+
@SuppressWarnings("deprecation")
206+
public static void killStillRunningJUnitTestcaseThreads() {
207+
Set<Thread> threadSet = Thread.getAllStackTraces().keySet();
208+
for (Thread thread : threadSet) {
209+
if (!(thread.isDaemon())) {
210+
final StackTraceElement[] threadStackTrace = thread.getStackTrace();
211+
if (threadStackTrace.length > 1) {
212+
StackTraceElement firstMethodInvocation = threadStackTrace[threadStackTrace.length - 1];
213+
if (firstMethodInvocation.getClassName().startsWith("org.junit")) {
214+
// HACK: must use deprecated method
215+
thread.stop();
216+
}
217+
}
218+
}
219+
}
220+
}
203221

204222
}

src/mujava/app/MutationScore.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ public List<TestResult> runTestsWithMutants(List<String> testClasses, String pat
110110
testToRun = MutationScore.reloader.rloadClass(test, true);
111111
MuJavaJunitTestRunner mjTestRunner = new MuJavaJunitTestRunner(testToRun, MutationScore.quickDeath);
112112
Result testResult = mjTestRunner.run();
113+
Core.killStillRunningJUnitTestcaseThreads();
113114
testResults.add(new TestResult(testResult));
114115
if (!testResult.wasSuccessful() && MutationScore.quickDeath) {
115116
break;

src/mujava/generations/Generate.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ public class Generate {
2020
public static void main(String[] args) {
2121
String clazz = "pldi" + Core.SEPARATOR + "nodecachinglinkedlist" + Core.SEPARATOR + "NodeCachingLinkedList";
2222
//String[] methods = {"addFirstUglyCopy"};
23-
String[] methods = {"containsBis"};
23+
String[] methods = {"contains"};
2424
Mutant[] ops = {
25-
Mutant.PRVOL_SMART,
26-
Mutant.PRVOR_REFINED,
27-
Mutant.PRVOU_REFINED,
25+
// Mutant.PRVOL_SMART,
26+
// Mutant.PRVOR_REFINED,
27+
// Mutant.PRVOU_REFINED,
2828
// Mutant.AODS,
2929
// Mutant.AODU,
3030
// Mutant.AOIS,
@@ -40,7 +40,7 @@ public static void main(String[] args) {
4040
// Mutant.LOR,
4141
// Mutant.ROR,
4242
// Mutant.SOR
43-
// Mutant.NPER
43+
Mutant.NPER
4444
};
4545
String basePathOriginals = args[0]; //test/
4646
String basePathMutants = args[1]; //mutants/

src/mujava/op/NPER.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ public void visit(ForStatement p) throws ParseTreeException {
195195
ifStatements.add(whileStatement);
196196
IfStatement ifStatement = createIfStatement(ifStatements, new Variable(initBoolVarDecl.getVariable()));
197197
mutant.add(ifStatement);
198+
mutant.setParent(p.getParent());
198199
outputToFile(pCopy, mutant);
199200
}
200201
super.visit(p);
@@ -220,16 +221,18 @@ public void visit(WhileStatement p) throws ParseTreeException {
220221
whileStatements.add(conditionTryInside);
221222
WhileStatement newWhile = new WhileStatement(new Variable(condBoolVarDecl.getVariable()), whileStatements);
222223
mutant.add(newWhile);
224+
mutant.setParent(p.getParent());
223225
outputToFile(p, mutant);
224226
}
225227
super.visit(p);
226228
}
227229

228230

229231
public void visit(AssignmentExpression p) throws ParseTreeException {
230-
if (getMutationsLeft(p) > 0) {
232+
if (getMutationsLeft(p) > 0 && p.getParent() instanceof ExpressionStatement) {
231233
AssignmentExpression pCopy = (AssignmentExpression) p.makeRecursiveCopy_keepOriginalID();
232234
TryStatement catchedExpressionStatement = createNullPointerExceptionTryStatement(new StatementList(new ExpressionStatement(pCopy)), new StatementList(), "NPE detected");
235+
catchedExpressionStatement.setParent(p.getParent());
233236
outputToFile(p, catchedExpressionStatement);
234237
}
235238
super.visit(p);
@@ -247,6 +250,7 @@ public void visit(ReturnStatement p) throws ParseTreeException {
247250
ReturnStatement defaultReturn = new ReturnStatement(defaultValue);
248251
StatementList catchStatements = new StatementList(defaultReturn);
249252
TryStatement mutant = createNullPointerExceptionTryStatement(tryStatements, catchStatements, "NPE detected in return statement");
253+
mutant.setParent(p.getParent());
250254
outputToFile(p, mutant);
251255
} catch (OJClassNotFoundException e) {
252256
// TODO Auto-generated catch block
@@ -288,6 +292,7 @@ public void visit(IfStatement p) throws ParseTreeException {
288292
TryStatement tryStatement = createNullPointerExceptionTryStatement(tryStatements, catchStatements, "NPE detected in condition evaluation before if statement");
289293
mutant.add(tryStatement);
290294
mutant.add(modifiedIfStatement);
295+
mutant.setParent(p.getParent());
291296
outputToFile(p, mutant);
292297
}
293298
super.visit(p);

src/mujava/op/NPER_Writer.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ public void visit(ForStatement o) throws ParseTreeException {
6969
StatementList m = this.mutant_statements;
7070
this.original_for = null;
7171
this.mutant_statements = null;
72-
super.visit(m);
72+
for (int s = 0; s < m.size(); s++) {
73+
Statement st = m.get(s);
74+
super.visit(st);
75+
}
7376
}
7477
else throw new ParseTreeException("NPER_Writer is being called with a mutant that's not a statement or a statement list");
7578
// -------------------------------------------------------------
@@ -91,7 +94,10 @@ public void visit(WhileStatement o) throws ParseTreeException {
9194
StatementList m = this.mutant_statements;
9295
this.original_while = null;
9396
this.mutant_statement = null;
94-
super.visit(m);
97+
for (int s = 0; s < m.size(); s++) {
98+
Statement st = m.get(s);
99+
super.visit(st);
100+
}
95101
}
96102
else throw new ParseTreeException("NPER_Writer is being called with a mutant that's not a statement or a statement list");
97103
// -------------------------------------------------------------
@@ -140,7 +146,10 @@ public void visit(IfStatement p) throws ParseTreeException {
140146
StatementList m = this.mutant_statements;
141147
this.original_if = null;
142148
this.mutant_statements = null;
143-
super.visit(m);
149+
for (int s = 0; s < m.size(); s++) {
150+
Statement st = m.get(s);
151+
super.visit(st);
152+
}
144153
mutated_line = line_num;
145154
} else {
146155
super.visit(p);

src/mujava/op/PRVO.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,7 +1889,9 @@ public void visit(AllocationExpression p) throws ParseTreeException {
18891889
return;
18901890
}
18911891
if (!this.refinedMode || getMutationsLeft(p) <= 0) return;
1892+
pushComplyType(p, p);
18921893
unaryVisit(p, p, true);
1894+
popComplyType(p);
18931895
ExpressionList args = p.getArguments();
18941896
for (int a = 0; a < args.size(); a++) {
18951897
pushAllowNull(p, compatibleAssignType(getType(args.get(a)), null));

src/mujava/op/util/Mutator.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,12 @@ public static int getMutationsLeft(ParseTreeObject nl) {
352352
else
353353
return -1;
354354
}
355+
if (parent instanceof ThrowStatement) {
356+
if (((ThrowStatement) parent).hasMutGenLimit())
357+
return ((ThrowStatement) parent).getMutGenLimit();
358+
else
359+
return -1;
360+
}
355361
parent = parent.getParent();
356362
}
357363
return -1;

0 commit comments

Comments
 (0)