Commit 9276a11f authored by Faezeh KHORRAM's avatar Faezeh KHORRAM 💬
Browse files

application of DSL Specific Coverage rules

parent bd374721
...@@ -4,14 +4,19 @@ import java.math.BigDecimal; ...@@ -4,14 +4,19 @@ import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.TreeIterator; import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.gemoc.trace.commons.model.trace.SequentialStep; import org.eclipse.gemoc.trace.commons.model.trace.SequentialStep;
import org.eclipse.gemoc.trace.commons.model.trace.Step; import org.eclipse.gemoc.trace.commons.model.trace.Step;
import org.eclipse.gemoc.trace.commons.model.trace.Trace; import org.eclipse.gemoc.trace.commons.model.trace.Trace;
import org.etsi.mts.tdl.TestDescription; import org.etsi.mts.tdl.TestDescription;
import org.imt.tdl.coverage.dslSpecific.DSLSpecificCoverageRule;
public class TDLTestCaseCoverage { public class TDLTestCaseCoverage {
...@@ -19,6 +24,8 @@ public class TDLTestCaseCoverage { ...@@ -19,6 +24,8 @@ public class TDLTestCaseCoverage {
private Resource MUTResource; private Resource MUTResource;
private Trace<?, ?, ?> trace; private Trace<?, ?, ?> trace;
private EList<DSLSpecificCoverageRule> dslSpecificCoverageRules;
private List<EObject> modelObjects; private List<EObject> modelObjects;
private List<String> tcObjectCoverageStatus; private List<String> tcObjectCoverageStatus;
...@@ -32,14 +39,13 @@ public class TDLTestCaseCoverage { ...@@ -32,14 +39,13 @@ public class TDLTestCaseCoverage {
numOfCoveredObjs= 0 ; numOfCoveredObjs= 0 ;
numOfNotCoverableElements = 0; numOfNotCoverableElements = 0;
} }
//calculating the coverage of the test case based on the model execution trace //calculating the coverage of the test case based on the model execution trace and dsl-specific coverage rules
public void calculateTCCoverage () { public void calculateTCCoverage () {
//find coverable objects using the MUTResource of the test case //find coverable objects using the MUTResource of the test case
findNotCoverableObjects(); findNotCoverableObjects();
Step<?> rootStep = trace.getRootStep(); Step<?> rootStep = trace.getRootStep();
calculateObjectCoverage(rootStep); calculateObjectCoverage(rootStep);
changeCoverable2notCovered(); changeCoverable2notCovered();
//checkContainmentRelations(this.modelObjects.get(0));
} }
private void findNotCoverableObjects() { private void findNotCoverableObjects() {
...@@ -47,7 +53,7 @@ public class TDLTestCaseCoverage { ...@@ -47,7 +53,7 @@ public class TDLTestCaseCoverage {
while (modelContents.hasNext()) { while (modelContents.hasNext()) {
EObject modelObject = modelContents.next(); EObject modelObject = modelContents.next();
modelObjects.add(modelObject); modelObjects.add(modelObject);
if (TDLCoverageUtil.getInstance().coverableClasses.contains(modelObject.eClass().getName())) { if (TDLCoverageUtil.getInstance().isClassCoverable(modelObject.eClass())) {
tcObjectCoverageStatus.add(TDLCoverageUtil.COVERABLE); tcObjectCoverageStatus.add(TDLCoverageUtil.COVERABLE);
} }
else { else {
...@@ -66,6 +72,10 @@ public class TDLTestCaseCoverage { ...@@ -66,6 +72,10 @@ public class TDLTestCaseCoverage {
String objectCoverage = tcObjectCoverageStatus.get(objectIndex); String objectCoverage = tcObjectCoverageStatus.get(objectIndex);
if (objectCoverage != TDLCoverageUtil.COVERED && objectCoverage != TDLCoverageUtil.NOT_COVERABLE) { if (objectCoverage != TDLCoverageUtil.COVERED && objectCoverage != TDLCoverageUtil.NOT_COVERABLE) {
tcObjectCoverageStatus.set(objectIndex, TDLCoverageUtil.COVERED); tcObjectCoverageStatus.set(objectIndex, TDLCoverageUtil.COVERED);
if (dslSpecificCoverageRules != null &&
dslSpecificCoverageRules.stream().filter(r -> r.getContext().equals(object.eClass())).count()>0) {
applyDSLSpecificCoverageRules(object);
}
} }
} }
} }
...@@ -77,6 +87,39 @@ public class TDLTestCaseCoverage { ...@@ -77,6 +87,39 @@ public class TDLTestCaseCoverage {
} }
} }
private void applyDSLSpecificCoverageRules(EObject object) {
List<DSLSpecificCoverageRule> relatedRules = dslSpecificCoverageRules.stream().
filter(r -> r.getContext().equals(object.eClass())).collect(Collectors.toList());
for (DSLSpecificCoverageRule rule:relatedRules) {
for (EReference eRefrence : rule.getImpliesReferenceCoverage()) {
Object referencedObject = object.eGet(eRefrence);
if (referencedObject != null) {
if (referencedObject instanceof EObject) {
checkCoverage4referencedObject((EObject) referencedObject);
}
else if (referencedObject instanceof EObjectContainmentEList<?>) {
((EObjectContainmentEList<?>) referencedObject).forEach(o -> checkCoverage4referencedObject((EObject) o));
}
}
}
}
}
private void checkCoverage4referencedObject(EObject refrencedObject) {
int refrencedObjectIndex = modelObjects.indexOf(refrencedObject);
if (refrencedObjectIndex != -1){
String refrencedObjectCoverage = tcObjectCoverageStatus.get(refrencedObjectIndex);
if (refrencedObjectCoverage != TDLCoverageUtil.COVERED &&
refrencedObjectCoverage != TDLCoverageUtil.NOT_COVERABLE) {
tcObjectCoverageStatus.set(refrencedObjectIndex, TDLCoverageUtil.COVERED);
if (dslSpecificCoverageRules != null &&
dslSpecificCoverageRules.stream().filter(r -> r.getContext().equals(refrencedObject.eClass())).count()>0) {
applyDSLSpecificCoverageRules(refrencedObject);
}
}
}
}
private void changeCoverable2notCovered() { private void changeCoverable2notCovered() {
for (int i=0; i<this.tcObjectCoverageStatus.size(); i++) { for (int i=0; i<this.tcObjectCoverageStatus.size(); i++) {
if (this.tcObjectCoverageStatus.get(i) == TDLCoverageUtil.COVERABLE) { if (this.tcObjectCoverageStatus.get(i) == TDLCoverageUtil.COVERABLE) {
...@@ -165,6 +208,12 @@ public class TDLTestCaseCoverage { ...@@ -165,6 +208,12 @@ public class TDLTestCaseCoverage {
return testCase; return testCase;
} }
public EList<DSLSpecificCoverageRule> getDslSpecificCoverageRules() {
return dslSpecificCoverageRules;
}
public void setDslSpecificCoverageRules(EList<DSLSpecificCoverageRule> dslSpecificCoverageRules) {
this.dslSpecificCoverageRules = dslSpecificCoverageRules;
}
public void setTestCase(TestDescription testCase) { public void setTestCase(TestDescription testCase) {
this.testCase = testCase; this.testCase = testCase;
} }
......
...@@ -5,9 +5,12 @@ import java.math.RoundingMode; ...@@ -5,9 +5,12 @@ import java.math.RoundingMode;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.eclipse.emf.common.util.ECollections;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EObject;
import org.etsi.mts.tdl.Package; import org.etsi.mts.tdl.Package;
import org.imt.tdl.coverage.dslSpecific.DSLSpecificCoverageHandler; import org.imt.tdl.coverage.dslSpecific.DSLSpecificCoverageHandler;
import org.imt.tdl.coverage.dslSpecific.DSLSpecificCoverageRule;
import org.imt.tdl.coverage.dslSpecific.IDSLSpecificCoverage; import org.imt.tdl.coverage.dslSpecific.IDSLSpecificCoverage;
public class TDLTestSuiteCoverage { public class TDLTestSuiteCoverage {
...@@ -18,6 +21,9 @@ public class TDLTestSuiteCoverage { ...@@ -18,6 +21,9 @@ public class TDLTestSuiteCoverage {
private List<EObject> modelObjects; private List<EObject> modelObjects;
private List<String> tsObjectCoverageStatus; private List<String> tsObjectCoverageStatus;
private IDSLSpecificCoverage dslSpecificCoverageExtension;
private EList<DSLSpecificCoverageRule> dslSpecificCoverageRules;
double tsCoveragePercentage; double tsCoveragePercentage;
int numOfCoveredObjs; int numOfCoveredObjs;
int numOfNotCoverableElements; int numOfNotCoverableElements;
...@@ -45,47 +51,53 @@ public class TDLTestSuiteCoverage { ...@@ -45,47 +51,53 @@ public class TDLTestSuiteCoverage {
//Calculating coverage of the test suite based on its test cases coverage //Calculating coverage of the test suite based on its test cases coverage
public void calculateTSCoverage() { public void calculateTSCoverage() {
DSLSpecificCoverageHandler dslSpecificCoverageHandler = new DSLSpecificCoverageHandler(); findDSLSpecificCoverageExtension();
IDSLSpecificCoverage dslSpecificCoverage = dslSpecificCoverageHandler.getDSLSpecificCoverage(); //check inheritance relationships between coverable and not-coverable classes
if (dslSpecificCoverage != null) { TDLCoverageUtil.getInstance().checkInheritanceOfNotCoverableClasses();
TDLCoverageUtil.getInstance().updateCoverableClasses(dslSpecificCoverage.getNewCoverableClasses());
} //for each test case, calculate coverage using the generic tool
//System.out.println("Number of Coverable Classes: " + TDLCoverageUtil.getInstance().coverableClasses.size()); //if the DSL provides a dsl-specific coverage tool, call its methods: ignoring model objects, retrieving coverage rules
//for each test case, first calculate coverage using the generic tool
//then, if the DSL provides a dsl-specific coverage tool, specialize the coverage based on it
for (TDLTestCaseCoverage tcCoverageObj : this.tcCoverages) { for (TDLTestCaseCoverage tcCoverageObj : this.tcCoverages) {
if (dslSpecificCoverage != null) { if (dslSpecificCoverageExtension != null) {
dslSpecificCoverage.ignoreModelObjects(tcCoverageObj.getMUTResource()); dslSpecificCoverageExtension.ignoreModelObjects(tcCoverageObj.getMUTResource());
tcCoverageObj.calculateTCCoverage(); tcCoverageObj.setDslSpecificCoverageRules(dslSpecificCoverageRules);
dslSpecificCoverage.specializeCoverage(tcCoverageObj);
}
else {
tcCoverageObj.calculateTCCoverage();
} }
tcCoverageObj.calculateTCCoverage();
tcCoverageObj.countNumOfElements(); tcCoverageObj.countNumOfElements();
tcCoverageObj.calculateCoveragePercentage(); tcCoverageObj.calculateCoveragePercentage();
this.overallResult.getCoverage().add(tcCoverageObj.getTcCoveragePercentage() + ""); overallResult.getCoverage().add(tcCoverageObj.getTcCoveragePercentage() + "");
//if it is the first test case, copy the whole test case object coverage status for the test suite //if it is the first test case, copy the whole test case object coverage status for the test suite
if (this.tsObjectCoverageStatus.size() == 0) { if (tsObjectCoverageStatus.size() == 0) {
this.modelObjects.addAll(tcCoverageObj.getModelObjects()); modelObjects.addAll(tcCoverageObj.getModelObjects());
this.tsObjectCoverageStatus.addAll(tcCoverageObj.getTcObjectCoverageStatus()); tsObjectCoverageStatus.addAll(tcCoverageObj.getTcObjectCoverageStatus());
}else { }else {
for (int i=0; i<tcCoverageObj.getTcObjectCoverageStatus().size(); i++) { for (int i=0; i<tcCoverageObj.getTcObjectCoverageStatus().size(); i++) {
String tcCoverage = tcCoverageObj.getTcObjectCoverageStatus().get(i); String tcCoverage = tcCoverageObj.getTcObjectCoverageStatus().get(i);
if (tcCoverage == TDLCoverageUtil.COVERED & this.tsObjectCoverageStatus.get(i) != TDLCoverageUtil.COVERED) { if (tcCoverage == TDLCoverageUtil.COVERED & tsObjectCoverageStatus.get(i) != TDLCoverageUtil.COVERED) {
this.tsObjectCoverageStatus.set(i, TDLCoverageUtil.COVERED); tsObjectCoverageStatus.set(i, TDLCoverageUtil.COVERED);
} }
} }
} }
} }
if (this.tsObjectCoverageStatus.size() != 0) { if (tsObjectCoverageStatus.size() != 0) {
countNumOfElements(); countNumOfElements();
//System.out.println("\n" + "Model size (n. of EObjects): " + this.modelObjects.size() + "\n"); //System.out.println("\n" + "Model size (n. of EObjects): " + this.modelObjects.size() + "\n");
calculateCoveragePercentage(); calculateCoveragePercentage();
} }
} }
@SuppressWarnings("unchecked")
private void findDSLSpecificCoverageExtension() {
//check if there is a DSL-Specific coverage extension
DSLSpecificCoverageHandler dslSpecificCoverageHandler = new DSLSpecificCoverageHandler();
dslSpecificCoverageExtension = dslSpecificCoverageHandler.getDSLSpecificCoverage();
dslSpecificCoverageRules = ECollections.newBasicEList();
if (dslSpecificCoverageExtension != null) {
dslSpecificCoverageRules.addAll(dslSpecificCoverageExtension.getDSLSpecificCoverageRules());
}
}
private void countNumOfElements() { private void countNumOfElements() {
this.numOfCoveredObjs = 0; this.numOfCoveredObjs = 0;
this.numOfNotCoverableElements = 0; this.numOfNotCoverableElements = 0;
......
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