Commit 5b822533 authored by Faezeh KHORRAM's avatar Faezeh KHORRAM 💬
Browse files

create a project for the evaluation of the test amplification tool

parent 40feb6ea
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-16">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.imt.tdl.amplification.evaluation</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=16
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=16
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=16
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Evaluation
Bundle-SymbolicName: org.imt.tdl.amplification.evaluation;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-16
Automatic-Module-Name: org.imt.tdl.amplification.evaluation
Require-Bundle: org.imt.tdl.amplification;bundle-version="1.0.0",
org.eclipse.core.resources,
org.eclipse.emf.ecore,
org.etsi.mts.tdl.model;bundle-version="1.4.0",
org.imt.tdl.testResult;bundle-version="1.0.0",
org.eclipse.core.runtime;bundle-version="3.24.0",
org.eclipse.core.commands;bundle-version="3.10.100",
org.eclipse.jface;bundle-version="3.24.0",
org.eclipse.ui;bundle-version="3.200.0"
source.. = src/
bin.includes = META-INF/,\
.
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="popup:org.eclipse.ui.popup.any?after=additions">
<command
commandId="org.imt.tdl.amplification.evaluation.command"
label="Evaluate TDL Test Amplification Tool"
style="push">
</command>
</menuContribution>
</extension>
<extension
point="org.eclipse.ui.commands">
<command
defaultHandler="org.imt.tdl.amplification.evaluation.ui.CommandHandler"
id="org.imt.tdl.amplification.evaluation.command"
name="AmplificationEvaluator">
</command>
</extension>
</plugin>
package org.imt.tdl.amplification.evaluation;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.eclipse.core.resources.IFile;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.etsi.mts.tdl.Package;
import org.etsi.mts.tdl.TestDescription;
import org.imt.tdl.amplification.TDLTestAmplifier;
import org.imt.tdl.amplification.mutation.MutationRuntimeException;
import org.imt.tdl.amplification.mutation.MutationScoreCalculator;
import org.imt.tdl.amplification.utilities.PathHelper;
import org.imt.tdl.testResult.TDLTestResultUtil;
/*
* This class is an implementation of our evaluation for MODELS2022 paper
* The evaluation protocol is as follows:
* 1. Running the original test suite on the mutants
* 2. Removing test cases (if needed) to reach mutation score between 40% and 80%
* 3. Running the amplification on the selected test cases
*/
public class Evaluation4MODELSPaper {
Resource testSuiteRes;
Package tdlTestSuite;
MutationScoreCalculator scoreCalculator;
int initialNumOfKilledMutants;
double initialMutationScore;
int numOfIteration;
int numNewTests;
Map<Integer, List<TestDescription>> iteration_ampTests = new HashMap<>();
public void selectTestsForEvaluation(IFile testSuiteFile) throws MutationRuntimeException {
PathHelper.getInstance().setTestSuiteFile(testSuiteFile);
testSuiteRes = PathHelper.getInstance().getTestSuiteResource();
tdlTestSuite = PathHelper.getInstance().getTestSuite();
//calculating the mutation score of the manually-written test suite (i.e., the input test suite)
scoreCalculator = new MutationScoreCalculator(tdlTestSuite);
if (scoreCalculator.noMutantsExists) {
String message = "Amplification Stopped: There is no available mutant";
System.out.println(message);
throw (new MutationRuntimeException(message));
}
String result = scoreCalculator.runTestSuiteOnOriginalModel();
if (result == TDLTestResultUtil.FAIL) {
String message = "Amplification Stopped: The manually-written test suite is failed on the original model under test.";
System.out.println(message);
throw (new MutationRuntimeException(message));
}
List<TestDescription> testCases = new ArrayList<>();
testCases = tdlTestSuite.getPackagedElement().stream().filter(p -> p instanceof TestDescription).
map(p -> (TestDescription) p).collect(Collectors.toList());
int index = -1;
double mutationScore = 0;
for (int i=0; i<testCases.size(); i++) {
scoreCalculator.runTestCaseOnAliveMutants(testCases.get(i));
scoreCalculator.calculateOverallMutationScore();
mutationScore = scoreCalculator.getOverallMutationScore();
if (mutationScore > 0.8) {
index = i;
break;
}
}
IFile weakTestsFile = null;
//if the mutation score is less than 40%, it is not a good input for the experiment
if (mutationScore < 0.4) {
String message = "Amplification Stopped: The mutation score of the input test suite must be higher than 40%";
System.out.println(message);
throw (new MutationRuntimeException(message));
}
//if the mutation score is between 40% and 80%, there is no need to remove test cases
else if (mutationScore >= 0.4 && mutationScore <= 0.8) {
weakTestsFile = testSuiteFile;
}
else if (mutationScore > 0.8) {
//remove the test cases from the index to the end
for (int i=index; i<testCases.size(); i++) {
tdlTestSuite.getPackagedElement().remove(testCases.get(index));
}
weakTestsFile = saveSelectedTestCases();
}
//send it to the amplifier
TDLTestAmplifier testAmplifier = new TDLTestAmplifier();
testAmplifier.amplifyTestSuite(weakTestsFile);
}
private IFile saveSelectedTestCases() {
String sourcePath = testSuiteRes.getURI().toString();
String extension = ".tdlan2";
if (sourcePath.endsWith(".xmi")) {
extension = ".xmi";
}
String outputPath = sourcePath.substring(0, sourcePath.lastIndexOf("/")+1) + PathHelper.getInstance().getTestSuiteFileName() + "_selected" + extension;
Resource weakTestSuiteRes = (new ResourceSetImpl()).createResource(URI.createURI(outputPath));
//all the new elements are in the testSuiteRes
weakTestSuiteRes.getContents().addAll(EcoreUtil.copyAll(testSuiteRes.getContents()));
try {
weakTestSuiteRes.save(null);
} catch (IOException e) {
e.printStackTrace();
}
testSuiteRes.unload();
weakTestSuiteRes.unload();
File weakTestsFile = new File (outputPath);
return (IFile) weakTestsFile;
}
}
package org.imt.tdl.amplification.evaluation.ui;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import org.eclipse.core.commands.IHandlerListener;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.ICoreRunnable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.ui.handlers.HandlerUtil;
import org.imt.tdl.amplification.evaluation.Evaluation4MODELSPaper;
public class CommandHandler implements IHandler {
@Override
public void addHandlerListener(IHandlerListener handlerListener) {
}
@Override
public void dispose() {
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection();
if (!selection.isEmpty()) {
if (selection instanceof TreeSelection) {
Object element = ((TreeSelection) selection).getFirstElement();
if (element instanceof IFile) {
ICoreRunnable run = new ICoreRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
try {
Evaluation4MODELSPaper evaluator = new Evaluation4MODELSPaper();
evaluator.selectTestsForEvaluation((IFile) element);
} catch (Throwable t) {
throw new CoreException(Status.error("Error when running test amplifier", t));
}
}
};
Job job = Job.create("Test Amplifier", run);
job.schedule();
}
}
}
return null;
}
@Override
public boolean isEnabled() {
return true;
}
@Override
public boolean isHandled() {
return true;
}
@Override
public void removeHandlerListener(IHandlerListener handlerListener) {
}
}
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