Commit 3f4220d8 authored by Faezeh KHORRAM's avatar Faezeh KHORRAM 💬
Browse files

update

parent 5b822533
......@@ -23,3 +23,6 @@ Require-Bundle: org.eclipse.xtend.lib;bundle-version="2.25.0",
org.apache.commons.lang3;bundle-version="3.1.0",
org.eclipse.gemoc.dsl.model,
org.eclipse.emf.ecore
Export-Package: org.imt.tdl.amplification,
org.imt.tdl.amplification.mutation,
org.imt.tdl.amplification.utilities
......@@ -47,6 +47,7 @@ public class TDLTestAmplifier {
scoreCalculator = new MutationScoreCalculator(tdlTestSuite);
initialNumOfKilledMutants = 0;
initialMutationScore = 0;
if (!scoreCalculator.noMutantsExists) {
String result = scoreCalculator.runTestSuiteOnOriginalModel();
if (result == TDLTestResultUtil.FAIL) {
......@@ -73,7 +74,7 @@ public class TDLTestAmplifier {
* Our stop-criterion is a combination of number of iteration and reaching to 100% mutation score
* at each iteration, the previously amplified tests are amplified
*/
while (numOfIteration<3 && scoreCalculator.getMutationScore()<1) {
while (numOfIteration<3 && scoreCalculator.getOverallMutationScore()<1) {
amplifyTestCases(iteration_ampTests.get(numOfIteration-1));
}
......@@ -183,8 +184,8 @@ public class TDLTestAmplifier {
sb.append("Total number of test cases improving mutation score: " + numNewTests + "\n");
sb.append("- number of mutants killed by improved test cases: " + (scoreCalculator.getNumOfKilledMutants()-initialNumOfKilledMutants)+ "\n");
sb.append("- total number of killed mutants: " + scoreCalculator.getNumOfKilledMutants() + "\n");
sb.append("- final mutation score : " + (scoreCalculator.getMutationScore() * 100) + "%" + "\n");
sb.append("=> improvement in the mutation score : " + (scoreCalculator.getMutationScore() - initialMutationScore)*100 + "%" + "\n");
sb.append("- final mutation score : " + (scoreCalculator.getOverallMutationScore() * 100) + "%" + "\n");
sb.append("=> improvement in the mutation score : " + (scoreCalculator.getOverallMutationScore() - initialMutationScore)*100 + "%" + "\n");
sb.append("--------------------------------------------------\n");
System.out.println(sb);
......
......@@ -97,14 +97,67 @@ public class MutationScoreCalculator {
public double calculateInitialMutationScore() {
System.out.println("\nCalculating the mutation score of the input test suite");
testCases.forEach(t -> runTestCaseOnMutants(t));
calculateMutationScore();
testCases.forEach(t -> runTestCaseOnAliveMutants(t));
calculateOverallMutationScore();
System.out.println("The mutation score of the input test suite is: " + mutationScore);
printMutationAnalysisResult();
return mutationScore;
}
@SuppressWarnings("unused")
private void runTestCaseOnAllMutants(TestDescription testCase) {
//using default values for timeout from pitest tool
//for timeoutConstant, it is calculated based on the waiting times used in the event manager:
//at the first of configuration and for each assertion 5000 waiting time
int timeoutConstant = testCase_numOfAssertions.get(testCase) * 5000 + 5000;
long timeout = (long) (testCase_executionTime.get(testCase) * timeoutFactor + timeoutConstant);
//run the test case only on alive mutants
for (String mutant:mutant_status.keySet()) {
String mutantPath = mutant.replace("\\", "/");
TDLTestCaseResult result = null;
final Runnable testRunner = new Thread() {
@Override
public void run() {
TestDescriptionAspect.executeTestCase(testCase, mutantPath);
}
};
private void runTestCaseOnMutants(TestDescription testCase) {
final ExecutorService executor = Executors.newSingleThreadExecutor();
@SuppressWarnings("rawtypes")
final Future future = executor.submit(testRunner);
executor.shutdown(); // This does not cancel the already-scheduled task.
try {
future.get(timeout, TimeUnit.MILLISECONDS);
//if there is no exception, get the result
result = TestDescriptionAspect.testCaseResult(testCase);
}
catch (InterruptedException ie) {
ie.printStackTrace();
}
catch (ExecutionException ee) {
ee.printStackTrace();
}
catch (TimeoutException te) {
//te.printStackTrace();
System.out.println("TimeoutException -> There is an infinite loop in the mutant");
future.cancel(true);
TestDescriptionAspect.launcher(testCase).disposeResources();
}
if (!executor.isTerminated()) {
executor.shutdownNow(); // If you want to stop the code that hasn't finished
}
if (result == null || result.getValue() == TDLTestResultUtil.FAIL) {
keepTestCaseKilledMutantMapping(testCase.getName(), mutant);
if (mutant_status.get(mutant) != KILLED) {
mutant_status.replace(mutant, KILLED);
numOfKilledMutants++;
}
}
}
}
public void runTestCaseOnAliveMutants(TestDescription testCase) {
Set<String> aliveMutants = new HashSet<>();
if (numOfKilledMutants == 0) {
aliveMutants = mutant_status.keySet();
......@@ -176,10 +229,10 @@ public class MutationScoreCalculator {
public boolean testCaseImprovesMutationScore (TestDescription testCase) {
int pastNumOfKilledMutants = numOfKilledMutants;
runTestCaseOnMutants(testCase);
runTestCaseOnAliveMutants(testCase);
if (numOfKilledMutants > pastNumOfKilledMutants) {
double previousScore = mutationScore;
calculateMutationScore();
calculateOverallMutationScore();
System.out.println("The test case " + testCase.getName() + " has improved the mutation score by: " + (mutationScore - previousScore));
System.out.println("- previous mutation score: " + previousScore);
System.out.println("- new mutation score: " + mutationScore + "\n");
......@@ -222,7 +275,7 @@ public class MutationScoreCalculator {
}
}
private void calculateMutationScore() {
public void calculateOverallMutationScore() {
mutationScore = (double) numOfKilledMutants/numOfMutants;
}
......@@ -275,7 +328,13 @@ public class MutationScoreCalculator {
return numOfKilledMutants;
}
public double getMutationScore() {
public double getOverallMutationScore() {
return mutationScore;
}
public double getTestCaseMutationScore(TestDescription testCase) {
int numOfKilledMutants = testCase_killedMutant.get(testCase).size();
double mutationScore = (double) numOfKilledMutants/numOfMutants;
return mutationScore;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment